@memberjunction/core 0.9.166 → 0.9.167

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 (66) hide show
  1. package/dist/generic/interfaces.d.ts +0 -2
  2. package/dist/generic/interfaces.js.map +1 -1
  3. package/dist/generic/providerBase.d.ts +0 -7
  4. package/dist/generic/providerBase.js +1 -11
  5. package/dist/generic/providerBase.js.map +1 -1
  6. package/package.json +1 -1
  7. package/dist/MJCore/src/generic/applicationInfo.d.ts +0 -26
  8. package/dist/MJCore/src/generic/applicationInfo.js +0 -57
  9. package/dist/MJCore/src/generic/applicationInfo.js.map +0 -1
  10. package/dist/MJCore/src/generic/baseEntity.d.ts +0 -195
  11. package/dist/MJCore/src/generic/baseEntity.js +0 -674
  12. package/dist/MJCore/src/generic/baseEntity.js.map +0 -1
  13. package/dist/MJCore/src/generic/baseInfo.d.ts +0 -8
  14. package/dist/MJCore/src/generic/baseInfo.js +0 -38
  15. package/dist/MJCore/src/generic/baseInfo.js.map +0 -1
  16. package/dist/MJCore/src/generic/entityInfo.d.ts +0 -520
  17. package/dist/MJCore/src/generic/entityInfo.js +0 -801
  18. package/dist/MJCore/src/generic/entityInfo.js.map +0 -1
  19. package/dist/MJCore/src/generic/interfaces.d.ts +0 -288
  20. package/dist/MJCore/src/generic/interfaces.js +0 -50
  21. package/dist/MJCore/src/generic/interfaces.js.map +0 -1
  22. package/dist/MJCore/src/generic/logging.d.ts +0 -4
  23. package/dist/MJCore/src/generic/logging.js +0 -69
  24. package/dist/MJCore/src/generic/logging.js.map +0 -1
  25. package/dist/MJCore/src/generic/metadata.d.ts +0 -201
  26. package/dist/MJCore/src/generic/metadata.js +0 -312
  27. package/dist/MJCore/src/generic/metadata.js.map +0 -1
  28. package/dist/MJCore/src/generic/providerBase.d.ts +0 -183
  29. package/dist/MJCore/src/generic/providerBase.js +0 -640
  30. package/dist/MJCore/src/generic/providerBase.js.map +0 -1
  31. package/dist/MJCore/src/generic/queryInfo.d.ts +0 -64
  32. package/dist/MJCore/src/generic/queryInfo.js +0 -124
  33. package/dist/MJCore/src/generic/queryInfo.js.map +0 -1
  34. package/dist/MJCore/src/generic/runQuery.d.ts +0 -11
  35. package/dist/MJCore/src/generic/runQuery.js +0 -26
  36. package/dist/MJCore/src/generic/runQuery.js.map +0 -1
  37. package/dist/MJCore/src/generic/runReport.d.ts +0 -11
  38. package/dist/MJCore/src/generic/runReport.js +0 -27
  39. package/dist/MJCore/src/generic/runReport.js.map +0 -1
  40. package/dist/MJCore/src/generic/securityInfo.d.ts +0 -100
  41. package/dist/MJCore/src/generic/securityInfo.js +0 -194
  42. package/dist/MJCore/src/generic/securityInfo.js.map +0 -1
  43. package/dist/MJCore/src/generic/transactionGroup.d.ts +0 -24
  44. package/dist/MJCore/src/generic/transactionGroup.js +0 -79
  45. package/dist/MJCore/src/generic/transactionGroup.js.map +0 -1
  46. package/dist/MJCore/src/generic/util.d.ts +0 -16
  47. package/dist/MJCore/src/generic/util.js +0 -151
  48. package/dist/MJCore/src/generic/util.js.map +0 -1
  49. package/dist/MJCore/src/index.d.ts +0 -16
  50. package/dist/MJCore/src/index.js +0 -44
  51. package/dist/MJCore/src/index.js.map +0 -1
  52. package/dist/MJCore/src/views/runView.d.ts +0 -112
  53. package/dist/MJCore/src/views/runView.js +0 -63
  54. package/dist/MJCore/src/views/runView.js.map +0 -1
  55. package/dist/MJCore/src/views/viewInfo.d.ts +0 -59
  56. package/dist/MJCore/src/views/viewInfo.js +0 -121
  57. package/dist/MJCore/src/views/viewInfo.js.map +0 -1
  58. package/dist/MJGlobal/src/ObjectCache.d.ts +0 -26
  59. package/dist/MJGlobal/src/ObjectCache.js +0 -55
  60. package/dist/MJGlobal/src/ObjectCache.js.map +0 -1
  61. package/dist/generic/objectCache.d.ts +0 -26
  62. package/dist/generic/objectCache.js +0 -55
  63. package/dist/generic/objectCache.js.map +0 -1
  64. package/dist/generic/viewInfo.d.ts +0 -59
  65. package/dist/generic/viewInfo.js +0 -121
  66. package/dist/generic/viewInfo.js.map +0 -1
@@ -1,801 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RecordMergeResult = exports.RecordMergeDetailResult = exports.RecordMergeRequest = exports.RecordDependency = exports.EntityDependency = exports.ValidationResult = exports.ValidationErrorInfo = exports.ValidationErrorType = exports.EntityInfo = exports.PrimaryKeyValue = exports.EntityFieldInfo = exports.GeneratedFormSectionType = exports.EntityFieldValueInfo = exports.EntityFieldValueListType = exports.EntityFieldGraphQLType = exports.EntityFieldTSType = exports.EntityPermissionInfo = exports.EntityUserPermissionInfo = exports.EntityPermissionType = exports.EntityRelationshipInfo = exports.RecordChange = exports.RecordChangeStatus = void 0;
4
- const baseInfo_1 = require("./baseInfo");
5
- const metadata_1 = require("./metadata");
6
- const util_1 = require("./util");
7
- const logging_1 = require("./logging");
8
- /**
9
- * The possible status values for a record change
10
- */
11
- exports.RecordChangeStatus = {
12
- Pending: 'Pending',
13
- Complete: 'Complete',
14
- Error: 'Error',
15
- };
16
- /**
17
- * Record Change object has information on a change to a record in the Record Changes entity
18
- */
19
- class RecordChange extends baseInfo_1.BaseInfo {
20
- get StatusValue() {
21
- return exports.RecordChangeStatus[this.Status?.trim()];
22
- }
23
- get Changes() {
24
- return JSON.parse(this.ChangesJSON);
25
- }
26
- get FullRecord() {
27
- return JSON.parse(this.FullRecordJSON);
28
- }
29
- constructor(initData) {
30
- super();
31
- this.EntityID = null;
32
- this.RecordID = null;
33
- this.ChangedAt = null;
34
- this.ChangesJSON = null;
35
- this.ChangesDescription = null;
36
- this.FullRecordJSON = null;
37
- this.Status = null;
38
- this.copyInitData(initData);
39
- }
40
- }
41
- exports.RecordChange = RecordChange;
42
- /**
43
- * Information about the Entity Relationship between the Entity and the Related Entity - this class
44
- * maps to information in the Entity Relationships metadata entity.
45
- */
46
- class EntityRelationshipInfo extends baseInfo_1.BaseInfo {
47
- constructor(initData) {
48
- super();
49
- this.EntityID = null;
50
- this.RelatedEntityID = null;
51
- this.BundleInAPI = null;
52
- this.IncludeInParentAllQuery = null;
53
- this.Type = null;
54
- this.EntityKeyField = null;
55
- this.RelatedEntityJoinField = null;
56
- this.JoinView = null;
57
- this.JoinEntityJoinField = null;
58
- this.JoinEntityInverseJoinField = null;
59
- this.DisplayInForm = null;
60
- this.DisplayName = null;
61
- this.DisplayUserViewGUID = null;
62
- this.CreatedAt = null;
63
- this.UpdatedAt = null;
64
- // virtual fields - returned by the database VIEW
65
- this.Entity = null;
66
- this.EntityBaseTable = null;
67
- this.EntityBaseView = null;
68
- this.RelatedEntity = null;
69
- this.RelatedEntityBaseTable = null;
70
- this.RelatedEntityBaseView = null;
71
- this.RelatedEntityCodeName = null;
72
- this.RelatedEntityClassName = null;
73
- this.RelatedEntityBaseTableCodeName = null;
74
- this.DisplayUserViewName = null;
75
- this.DisplayUserViewID = null;
76
- this.copyInitData(initData);
77
- }
78
- }
79
- exports.EntityRelationshipInfo = EntityRelationshipInfo;
80
- exports.EntityPermissionType = {
81
- Read: 'Read',
82
- Create: 'Create',
83
- Update: 'Update',
84
- Delete: 'Delete',
85
- };
86
- class EntityUserPermissionInfo {
87
- }
88
- exports.EntityUserPermissionInfo = EntityUserPermissionInfo;
89
- class EntityPermissionInfo extends baseInfo_1.BaseInfo {
90
- get CreateRLSFilterObject() {
91
- return this.RLSFilter(exports.EntityPermissionType.Create);
92
- }
93
- get ReadRLSFilterObject() {
94
- return this.RLSFilter(exports.EntityPermissionType.Read);
95
- }
96
- get UpdateRLSFilterObject() {
97
- return this.RLSFilter(exports.EntityPermissionType.Update);
98
- }
99
- get DeleteRLSFilterObject() {
100
- return this.RLSFilter(exports.EntityPermissionType.Delete);
101
- }
102
- RLSFilter(type) {
103
- let fID = 0;
104
- switch (type) {
105
- case exports.EntityPermissionType.Read:
106
- fID = this.ReadRLSFilterID;
107
- break;
108
- case exports.EntityPermissionType.Create:
109
- fID = this.CreateRLSFilterID;
110
- break;
111
- case exports.EntityPermissionType.Update:
112
- fID = this.UpdateRLSFilterID;
113
- break;
114
- case exports.EntityPermissionType.Delete:
115
- fID = this.DeleteRLSFilterID;
116
- break;
117
- }
118
- if (fID > 0)
119
- return metadata_1.Metadata.Provider.RowLevelSecurityFilters.find(f => f.ID === fID);
120
- }
121
- constructor(initData) {
122
- super();
123
- this.EntityID = null;
124
- this.RoleName = null;
125
- this.CanCreate = null;
126
- this.CanRead = null;
127
- this.CanUpdate = null;
128
- this.CanDelete = null;
129
- this.ReadRLSFilterID = null;
130
- this.CreateRLSFilterID = null;
131
- this.UpdateRLSFilterID = null;
132
- this.DeleteRLSFilterID = null;
133
- this.CreatedAt = null;
134
- this.UpdatedAt = null;
135
- // virtual fields - returned by the database VIEW
136
- this.Entity = null;
137
- this.RoleSQLName = null;
138
- this.ReadRLSFilter = null;
139
- this.CreateRLSFilter = null;
140
- this.UpdateRLSFilter = null;
141
- this.DeleteRLSFilter = null;
142
- this.copyInitData(initData);
143
- }
144
- }
145
- exports.EntityPermissionInfo = EntityPermissionInfo;
146
- exports.EntityFieldTSType = {
147
- String: 'string',
148
- Number: 'number',
149
- Date: 'Date',
150
- Boolean: 'boolean',
151
- };
152
- exports.EntityFieldGraphQLType = {
153
- Int: 'Int',
154
- Float: 'Float',
155
- String: 'String',
156
- Boolean: 'Boolean',
157
- Timestamp: 'Timestamp',
158
- };
159
- exports.EntityFieldValueListType = {
160
- None: 'None',
161
- List: 'List',
162
- ListOrUserEntry: 'ListOrUserEntry',
163
- };
164
- class EntityFieldValueInfo extends baseInfo_1.BaseInfo {
165
- constructor(initData) {
166
- super();
167
- this.EntityID = null;
168
- this.EntityFieldName = null;
169
- this.Sequence = null;
170
- this.Value = null;
171
- this.Code = null;
172
- this.Description = null;
173
- this.CreatedAt = null;
174
- this.UpdatedAt = null;
175
- this.copyInitData(initData);
176
- }
177
- }
178
- exports.EntityFieldValueInfo = EntityFieldValueInfo;
179
- exports.GeneratedFormSectionType = {
180
- Top: 'Top',
181
- Details: 'Details',
182
- Category: 'Category',
183
- };
184
- /**
185
- * Field information within an entity - object models data from the Entity Fields entity in the metadata
186
- */
187
- class EntityFieldInfo extends baseInfo_1.BaseInfo {
188
- get EntityFieldValues() {
189
- return this._EntityFieldValues;
190
- }
191
- /**
192
- * Returns the ValueListType using the EntityFieldValueListType enum.
193
- */
194
- get ValueListTypeEnum() {
195
- if (this.ValueListType == null)
196
- return exports.EntityFieldValueListType.None;
197
- else {
198
- // iterate through list of possibilities from enum and compare lcase
199
- for (let enumMember in exports.EntityFieldValueListType) {
200
- if (typeof exports.EntityFieldValueListType[enumMember] === 'string' &&
201
- enumMember.toLowerCase().trim() === this.ValueListType.toLowerCase().trim()) {
202
- return exports.EntityFieldValueListType[enumMember];
203
- }
204
- }
205
- }
206
- }
207
- get GeneratedFormSectionType() {
208
- return exports.GeneratedFormSectionType[this.GeneratedFormSection];
209
- }
210
- /**
211
- * Provides the TypeScript type for a given Entity Field. This is useful to map
212
- * a wide array of database types to a narrower set of TypeScript types.
213
- */
214
- get TSType() {
215
- switch ((0, util_1.TypeScriptTypeFromSQLType)(this.Type).toLowerCase()) {
216
- case "number":
217
- return exports.EntityFieldTSType.Number;
218
- case "boolean":
219
- return exports.EntityFieldTSType.Boolean;
220
- case "date":
221
- return exports.EntityFieldTSType.Date;
222
- default:
223
- return exports.EntityFieldTSType.String;
224
- }
225
- }
226
- get IsBinaryFieldType() {
227
- switch (this.Type.trim().toLowerCase()) {
228
- case 'binary':
229
- case 'varbinary':
230
- case 'image':
231
- return true;
232
- default:
233
- return false;
234
- }
235
- }
236
- /**
237
- * Returns true if the field type requires quotes around the value when used in a SQL statement
238
- */
239
- get NeedsQuotes() {
240
- switch (this.TSType) {
241
- case exports.EntityFieldTSType.Number:
242
- case exports.EntityFieldTSType.Boolean:
243
- return false;
244
- default:
245
- return true;
246
- }
247
- }
248
- /**
249
- * For fields in the database that have spaces in them, we need to replace the spaces with _ in order to create variables for stored procedures. This property returns a consistent CodeName you can use everywhere to refer to the field when generated variable names
250
- */
251
- get CodeName() {
252
- // the code below replaces spaces with _
253
- return this.Name.replace(/\s/g, "_");
254
- }
255
- get GraphQLType() {
256
- switch ((0, util_1.TypeScriptTypeFromSQLType)(this.Type).toLowerCase()) {
257
- case "number":
258
- // either an int or float if not an int
259
- switch (this.Type.toLowerCase().trim()) {
260
- case "int":
261
- case "smallint":
262
- case "tinyint":
263
- case "bigint":
264
- return exports.EntityFieldGraphQLType.Int;
265
- default:
266
- return exports.EntityFieldGraphQLType.Float;
267
- }
268
- case "boolean":
269
- return exports.EntityFieldGraphQLType.Boolean;
270
- case "date":
271
- return exports.EntityFieldGraphQLType.Timestamp;
272
- default:
273
- return exports.EntityFieldGraphQLType.String;
274
- }
275
- }
276
- /**
277
- * Returns a string with the full SQL data type that combines, as appropriate, Type, Length, Precision and Scale where these attributes are relevant to the Type
278
- */
279
- get SQLFullType() {
280
- return (0, util_1.SQLFullType)(this.Type, this.Length, this.Precision, this.Scale);
281
- }
282
- get MaxLength() {
283
- return (0, util_1.SQLMaxLength)(this.Type, this.Length);
284
- }
285
- get ReadOnly() {
286
- return this.IsVirtual || !this.AllowUpdateAPI || this.IsPrimaryKey || this.Type.toLowerCase() === 'uniqueidentifier';
287
- }
288
- /**
289
- * Returns true if the field is a "special" field (see list below) and is handled inside the DB layer and should be ignored in validation by the BaseEntity architecture
290
- * Special fields are: CreatedAt, UpdatedAt, ID
291
- * Also, we skip validation if we have a field that is:
292
- * - the primary key
293
- * - a uniqueidentifier
294
- * - an autoincrement field
295
- * - the field is virtual
296
- * - the field is readonly
297
- */
298
- get SkipValidation() {
299
- const name = this.Name.toLowerCase().trim();
300
- return name === 'createdat' ||
301
- name === 'updatedat' ||
302
- this.IsPrimaryKey ||
303
- this.Type.trim().toLowerCase() === 'uniqueidentifier' ||
304
- this.AutoIncrement === true ||
305
- this.IsVirtual === true ||
306
- this.ReadOnly === true;
307
- }
308
- /**
309
- * Returns the DisplayName if it exists, otherwise returns the Name.
310
- */
311
- get DisplayNameOrName() {
312
- return this.DisplayName ? this.DisplayName : this.Name;
313
- }
314
- /**
315
- * Formats a value based on the parameters passed in. This is a wrapper utility method that already know the SQL type from the entity field definition and simply calls the generic FormatValue() function that is also exported by @memberjunction/core
316
- * @param value - Value to format
317
- * @param decimals Number of decimals to show, defaults to 2
318
- * @param currency Currency to use when formatting, defaults to USD
319
- * @param maxLength Maximum length of the string to return, if the formatted value is longer than this length then the string will be truncated and the trailingChars will be appended to the end of the string
320
- * @param trailingChars Only used if maxLength is > 0 and the string being formatted is > maxLength, this is the string that will be appended to the end of the string to indicate that it was truncated, defaults to "..."
321
- * @returns either the original string value or a formatted version. If the format cannot be applied an an exception occurs it is captured and the error is put to the log, and the original value is returned
322
- */
323
- FormatValue(value, decimals = 2, currency = 'USD', maxLength = 0, trailingChars = "...") {
324
- return (0, util_1.FormatValue)(this.Type, value, decimals, currency, maxLength, trailingChars);
325
- }
326
- constructor(initData = null) {
327
- super();
328
- /**
329
- * Foreign key to the Entities entity.
330
- */
331
- this.EntityID = null;
332
- /**
333
- * The sequence of the field within the entity, typically the intended display order
334
- */
335
- this.Sequence = null;
336
- this.Name = null;
337
- /**
338
- * Optional property that provides the display name for the field, if null, use the Name property.
339
- * The DisplayNameOrName() method is a helper function that does this for you with a single method call.
340
- */
341
- this.DisplayName = null;
342
- this.Description = null;
343
- /**
344
- * If true, the field is the primary key for the entity. There must be one primary key field per entity.
345
- */
346
- this.IsPrimaryKey = null;
347
- /**
348
- * If true, the field is a unique key for the entity. There can be zero to many unique key fields per entity.
349
- */
350
- this.IsUnique = null;
351
- this.Category = null;
352
- this.Type = null;
353
- this.Length = null;
354
- this.Precision = null;
355
- this.Scale = null;
356
- this.AllowsNull = null;
357
- this.DefaultValue = null;
358
- this.AutoIncrement = null;
359
- this.ValueListType = null;
360
- this.ExtendedType = null;
361
- this.DefaultInView = null;
362
- this.ViewCellTemplate = null;
363
- this.DefaultColumnWidth = null;
364
- this.AllowUpdateAPI = null;
365
- this.AllowUpdateInView = null;
366
- this.IncludeInUserSearchAPI = null;
367
- this.FullTextSearchEnabled = false;
368
- this.UserSearchParamFormatAPI = null;
369
- this.IncludeInGeneratedForm = null;
370
- this.GeneratedFormSection = null;
371
- this.IsVirtual = null;
372
- this.IsNameField = null;
373
- this.RelatedEntityID = null;
374
- this.RelatedEntityFieldName = null;
375
- this.IncludeRelatedEntityNameFieldInBaseView = null;
376
- this.RelatedEntityNameFieldMap = null;
377
- this.CreatedAt = null;
378
- this.UpdatedAt = null;
379
- // virtual fields - returned by the database VIEW
380
- this.Entity = null;
381
- this.SchemaName = null;
382
- this.BaseTable = null;
383
- this.BaseView = null;
384
- this.EntityCodeName = null;
385
- this.EntityClassName = null;
386
- this.RelatedEntity = null;
387
- this.RelatedEntitySchemaName = null;
388
- this.RelatedEntityBaseTable = null;
389
- this.RelatedEntityBaseView = null;
390
- this.RelatedEntityCodeName = null;
391
- this.RelatedEntityClassName = null;
392
- if (initData) {
393
- this.copyInitData(initData);
394
- // do some special handling to create class instances instead of just data objects
395
- // copy the Entity Field Values
396
- this._EntityFieldValues = [];
397
- const efv = initData.EntityFieldValues || initData._EntityFieldValues;
398
- if (efv) {
399
- for (let j = 0; j < efv.length; j++) {
400
- this._EntityFieldValues.push(new EntityFieldValueInfo(efv[j]));
401
- }
402
- }
403
- }
404
- }
405
- }
406
- exports.EntityFieldInfo = EntityFieldInfo;
407
- /**
408
- * Primary Key Value object is used to pass in a primary key field/value pairs to BaseEntity.Load() and other methods that need to load a record by primary key
409
- */
410
- class PrimaryKeyValue {
411
- }
412
- exports.PrimaryKeyValue = PrimaryKeyValue;
413
- /**
414
- * Metadata about an entity
415
- */
416
- class EntityInfo extends baseInfo_1.BaseInfo {
417
- /**
418
- * Returns the primary key for the entity. For entities with a composite primary key, use the PrimaryKeys property which returns all.
419
- * In the case of a composite primary key, the PrimaryKey property will return the first field in the sequence of the primary key fields.
420
- */
421
- get PrimaryKey() {
422
- return this.Fields.find((f) => f.IsPrimaryKey);
423
- }
424
- /**
425
- * Returns an array of all fields that are part of the primary key for the entity. If the entity has a single primary key, the array will have a single element.
426
- */
427
- get PrimaryKeys() {
428
- return this.Fields.filter((f) => f.IsPrimaryKey);
429
- }
430
- get UniqueKeys() {
431
- return this.Fields.filter((f) => f.IsUnique);
432
- }
433
- get ForeignKeys() {
434
- return this.Fields.filter((f) => f.RelatedEntityID > 0);
435
- }
436
- get Fields() {
437
- return this._Fields;
438
- }
439
- get RelatedEntities() {
440
- return this._RelatedEntities;
441
- }
442
- get Permissions() {
443
- return this._Permissions;
444
- }
445
- /**
446
- * Returns the EntityField object for the Field that has IsNameField set to true. If multiple fields have IsNameField on, the function will return the first field (by sequence) that matches. If no fields match, null is returned
447
- */
448
- get NameField() {
449
- for (let j = 0; j < this.Fields.length; j++) {
450
- const ef = this.Fields[j];
451
- if (ef.IsNameField)
452
- return ef;
453
- }
454
- return null;
455
- }
456
- /**
457
- * Returns the Permissions for this entity for a given user, based on the roles the user is part of
458
- * @param user
459
- * @returns
460
- */
461
- GetUserPermisions(user) {
462
- try {
463
- const permissionList = [];
464
- for (let j = 0; j < this.Permissions.length; j++) {
465
- const ep = this.Permissions[j];
466
- const roleMatch = user.UserRoles.find((r) => r.RoleName.trim().toLowerCase() === ep.RoleName.trim().toLowerCase());
467
- if (roleMatch) // user has this role
468
- permissionList.push(ep);
469
- }
470
- // now that we have matched any number of EntityPermissions to the current user, aggregate the permissions
471
- const userPermission = new EntityUserPermissionInfo();
472
- userPermission.CanCreate = false;
473
- userPermission.CanDelete = false;
474
- userPermission.CanRead = false;
475
- userPermission.CanUpdate = false;
476
- for (let j = 0; j < permissionList.length; j++) {
477
- const ep = permissionList[j];
478
- userPermission.CanCreate = userPermission.CanCreate || ep.CanCreate;
479
- userPermission.CanRead = userPermission.CanRead || ep.CanRead;
480
- userPermission.CanUpdate = userPermission.CanUpdate || ep.CanUpdate;
481
- userPermission.CanDelete = userPermission.CanDelete || ep.CanDelete;
482
- }
483
- userPermission.Entity = this;
484
- userPermission.User = user;
485
- return userPermission;
486
- }
487
- catch (err) {
488
- console.log(err);
489
- return null;
490
- }
491
- }
492
- /**
493
- * Determines if a given user, for a given permission type, is exempt from RowLevelSecurity or not
494
- * @param user
495
- * @param type
496
- * @returns
497
- */
498
- UserExemptFromRowLevelSecurity(user, type) {
499
- for (let j = 0; j < this.Permissions.length; j++) {
500
- const ep = this.Permissions[j];
501
- const roleMatch = user.UserRoles.find((r) => r.RoleName.trim().toLowerCase() === ep.RoleName.trim().toLowerCase());
502
- if (roleMatch) { // user has this role
503
- switch (type) {
504
- case exports.EntityPermissionType.Create:
505
- if (!ep.CreateRLSFilterID)
506
- return true;
507
- break;
508
- case exports.EntityPermissionType.Read:
509
- if (!ep.ReadRLSFilterID)
510
- return true;
511
- break;
512
- case exports.EntityPermissionType.Update:
513
- if (!ep.UpdateRLSFilterID)
514
- return true;
515
- break;
516
- case exports.EntityPermissionType.Delete:
517
- if (!ep.DeleteRLSFilterID)
518
- return true;
519
- break;
520
- }
521
- }
522
- }
523
- return false; // if we get here, the user is NOT exempt from RLS for this Permission Type
524
- }
525
- /**
526
- * Returns RLS security info attributes for a given user and permission type
527
- * @param user
528
- * @param type
529
- * @returns
530
- */
531
- GetUserRowLevelSecurityInfo(user, type) {
532
- const rlsList = [];
533
- for (let j = 0; j < this.Permissions.length; j++) {
534
- const ep = this.Permissions[j];
535
- const roleMatch = user.UserRoles.find((r) => r.RoleName.trim().toLowerCase() === ep.RoleName.trim().toLowerCase());
536
- if (roleMatch) { // user has this role
537
- let matchObject = null;
538
- switch (type) {
539
- case exports.EntityPermissionType.Create:
540
- if (ep.CreateRLSFilterID)
541
- matchObject = ep.CreateRLSFilterObject;
542
- break;
543
- case exports.EntityPermissionType.Read:
544
- if (ep.ReadRLSFilterID)
545
- matchObject = ep.ReadRLSFilterObject;
546
- break;
547
- case exports.EntityPermissionType.Update:
548
- if (ep.UpdateRLSFilterID)
549
- matchObject = ep.UpdateRLSFilterObject;
550
- break;
551
- case exports.EntityPermissionType.Delete:
552
- if (ep.DeleteRLSFilterID)
553
- matchObject = ep.DeleteRLSFilterObject;
554
- break;
555
- }
556
- if (matchObject) {
557
- // we have a match, so add it to the list if it isn't already there
558
- const existingMatch = rlsList.find((r) => r.ID === matchObject.ID);
559
- if (!existingMatch)
560
- rlsList.push(matchObject);
561
- }
562
- }
563
- }
564
- return rlsList;
565
- }
566
- /**
567
- * Generates a where clause for SQL filtering for a given entity for a given user and permission type. If there is no RLS for a given entity or the user is exempt from RLS for the entity, a blank string is returned.
568
- * @param user
569
- * @param type
570
- * @param returnPrefix
571
- * @returns
572
- */
573
- GetUserRowLevelSecurityWhereClause(user, type, returnPrefix) {
574
- const userRLS = this.GetUserRowLevelSecurityInfo(user, type);
575
- if (userRLS && userRLS.length > 0) {
576
- // userRLS has all of the objects that apply to this user. The user is NOT exempt from RLS, so we need to OR together all of the RLS object filters
577
- let sRLSSQL = '';
578
- userRLS.forEach((rls) => {
579
- if (sRLSSQL.length > 0)
580
- sRLSSQL += ' OR ';
581
- sRLSSQL += `(${rls.MarkupFilterText(user)})`;
582
- });
583
- return sRLSSQL.length > 0 ? `${returnPrefix && returnPrefix.length > 0 ? returnPrefix + ' ' : ''}${sRLSSQL}` : '';
584
- }
585
- else
586
- return '';
587
- }
588
- /**
589
- * Returns a RunViewParams object that is setup to filter the related entity for the provided record
590
- * @param record
591
- * @param relationship
592
- * @param filter
593
- * @returns
594
- */
595
- static BuildRelationshipViewParams(record, relationship, filter) {
596
- const params = {};
597
- let quotes = '';
598
- let keyValue = '';
599
- if (relationship.EntityKeyField && relationship.EntityKeyField.length > 0) {
600
- keyValue = record.Get(relationship.EntityKeyField);
601
- quotes = record.EntityInfo.Fields.find((f) => f.Name.trim().toLowerCase() === relationship.EntityKeyField.trim().toLowerCase()).NeedsQuotes ? "'" : '';
602
- }
603
- else {
604
- keyValue = record.PrimaryKey.Value;
605
- quotes = record.PrimaryKey.NeedsQuotes ? "'" : '';
606
- }
607
- if (relationship.Type.trim().toLowerCase() === 'one to many') {
608
- // one to many
609
- params.ExtraFilter = relationship.RelatedEntityJoinField + ' = ' + quotes + keyValue + quotes;
610
- }
611
- else {
612
- // many to many
613
- params.ExtraFilter = `${relationship.RelatedEntityJoinField} IN (SELECT ${relationship.JoinEntityInverseJoinField} FROM ${relationship.JoinView} WHERE ${relationship.JoinEntityJoinField} = ${quotes}${keyValue}${quotes})`;
614
- }
615
- if (filter && filter.length > 0)
616
- params.ExtraFilter = `(${params.ExtraFilter}) AND (${filter})`; // caller provided their own filter, so AND it in with the relationship filter we have here
617
- if (relationship.DisplayUserViewGUID && relationship.DisplayUserViewGUID.length > 0) {
618
- // we have been given a specific view to run, use it
619
- params.ViewID = relationship.DisplayUserViewID; // virtual field - the durable key is the GUID, but the base view for entityrelationship brings in view name and ID
620
- }
621
- else {
622
- // no view specified, so specify the entity instead
623
- params.EntityName = relationship.RelatedEntity;
624
- }
625
- return params;
626
- }
627
- constructor(initData = null) {
628
- super();
629
- /**
630
- * Reserved for future use
631
- */
632
- this.ParentID = null;
633
- /**
634
- * Unique name of the entity
635
- */
636
- this.Name = null;
637
- this.Description = null;
638
- this.BaseTable = null;
639
- this.BaseView = null;
640
- this.BaseViewGenerated = null;
641
- this.SchemaName = null;
642
- this.VirtualEntity = null;
643
- this.TrackRecordChanges = null;
644
- this.AuditRecordAccess = null;
645
- this.AuditViewRuns = null;
646
- this.IncludeInAPI = false;
647
- this.AllowAllRowsAPI = false;
648
- this.AllowUpdateAPI = false;
649
- this.AllowCreateAPI = false;
650
- this.AllowDeleteAPI = false;
651
- this.CustomResolverAPI = false;
652
- this.AllowUserSearchAPI = false;
653
- this.FullTextSearchEnabled = false;
654
- this.FullTextCatalog = null;
655
- this.FullTextCatalogGenerated = true;
656
- this.FullTextIndex = null;
657
- this.FullTextIndexGenerated = true;
658
- this.FullTextSearchFunction = null;
659
- this.FullTextSearchFunctionGenerated = true;
660
- this.UserViewMaxRows = null;
661
- this.spCreate = null;
662
- this.spUpdate = null;
663
- this.spDelete = null;
664
- this.spCreateGenerated = null;
665
- this.spUpdateGenerated = null;
666
- this.spDeleteGenerated = null;
667
- this.CascadeDeletes = null;
668
- this.UserFormGenerated = null;
669
- this.EntityObjectSubclassName = null;
670
- this.EntityObjectSubclassImport = null;
671
- this.CreatedAt = null;
672
- this.UpdatedAt = null;
673
- // virtual fields - returned by the database VIEW
674
- /**
675
- * CodeName is a unique name that can be used for various programatic purposes, singular version of the entity name but modified from entity name in some cases to remove whitespace and prefix with _ in the event that the entity name begins with a number or other non-alpha character
676
- */
677
- this.CodeName = null;
678
- this.ClassName = null;
679
- this.BaseTableCodeName = null;
680
- this.ParentEntity = null;
681
- this.ParentBaseTable = null;
682
- this.ParentBaseView = null;
683
- this._hasIdField = false;
684
- this._virtualCount = 0;
685
- this._manyToManyCount = 0;
686
- this._oneToManyCount = 0;
687
- this._floatCount = 0;
688
- if (initData) {
689
- this.copyInitData(initData);
690
- // do some special handling to create class instances instead of just data objects
691
- // copy the Entity Fields
692
- this._Fields = [];
693
- const ef = initData.EntityFields || initData._Fields;
694
- if (ef) {
695
- for (let j = 0; j < ef.length; j++) {
696
- this._Fields.push(new EntityFieldInfo(ef[j]));
697
- }
698
- }
699
- // copy the Entity Permissions
700
- this._Permissions = [];
701
- const ep = initData.EntityPermissions || initData._Permissions;
702
- if (ep) {
703
- for (let j = 0; j < ep.length; j++) {
704
- this._Permissions.push(new EntityPermissionInfo(ep[j]));
705
- }
706
- }
707
- // copy the Related Entities
708
- this._RelatedEntities = [];
709
- const er = initData.EntityRelationships || initData._RelatedEntities;
710
- if (er) {
711
- for (let j = 0; j < er.length; j++) {
712
- this._RelatedEntities.push(new EntityRelationshipInfo(er[j]));
713
- }
714
- }
715
- this.prepareSpecialFields();
716
- }
717
- }
718
- prepareSpecialFields() {
719
- try {
720
- let virtualCount = 0;
721
- let manyToManyCount = 0;
722
- let oneToManyCount = 0;
723
- let floatCount = 0;
724
- let hasIdField = false;
725
- for (let j = 0; j < this.Fields.length; ++j) {
726
- const f = this.Fields[j];
727
- if (f.Name.trim().toUpperCase() === 'ID')
728
- hasIdField = true;
729
- virtualCount += f.IsVirtual ? 1 : 0;
730
- floatCount += f.IsFloat ? 1 : 0;
731
- }
732
- this._hasIdField = hasIdField;
733
- this._floatCount = floatCount;
734
- this._virtualCount = virtualCount;
735
- // now see if there are any relationships and count the one to many and many to many
736
- for (let j = 0; j < this.RelatedEntities.length; ++j) {
737
- const r = this.RelatedEntities[j];
738
- if (r.Type.trim().toUpperCase() === 'ONE TO MANY')
739
- oneToManyCount++;
740
- else
741
- manyToManyCount++;
742
- }
743
- this._manyToManyCount = manyToManyCount;
744
- this._oneToManyCount = oneToManyCount;
745
- }
746
- catch (e) {
747
- (0, logging_1.LogError)(e);
748
- }
749
- }
750
- }
751
- exports.EntityInfo = EntityInfo;
752
- exports.ValidationErrorType = {
753
- Failure: 'Failure',
754
- Warning: 'Warning',
755
- };
756
- class ValidationErrorInfo {
757
- constructor(Source, Message, Value, Type = exports.ValidationErrorType.Failure) {
758
- this.Source = Source;
759
- this.Message = Message;
760
- this.Value = Value;
761
- this.Type = Type;
762
- }
763
- }
764
- exports.ValidationErrorInfo = ValidationErrorInfo;
765
- class ValidationResult {
766
- constructor() {
767
- this.Errors = [];
768
- }
769
- }
770
- exports.ValidationResult = ValidationResult;
771
- /**
772
- * Information about the link between two entities
773
- */
774
- class EntityDependency {
775
- }
776
- exports.EntityDependency = EntityDependency;
777
- /**
778
- * Information about the link between two records
779
- */
780
- class RecordDependency {
781
- }
782
- exports.RecordDependency = RecordDependency;
783
- /**
784
- * Information about a merge request including the entity, the surviving record and the records to merge into the surviving record. Additionally, there is an optional field map that can be used to override field values in the surviving record to values specified.
785
- */
786
- class RecordMergeRequest {
787
- }
788
- exports.RecordMergeRequest = RecordMergeRequest;
789
- /**
790
- * The result of a merge request for a single record
791
- */
792
- class RecordMergeDetailResult {
793
- }
794
- exports.RecordMergeDetailResult = RecordMergeDetailResult;
795
- /**
796
- * The result of a merge request
797
- */
798
- class RecordMergeResult {
799
- }
800
- exports.RecordMergeResult = RecordMergeResult;
801
- //# sourceMappingURL=entityInfo.js.map