Skip to content

Commit fbe6fe5

Browse files
committed
Removed property tracker implementation
1 parent 1dd63e6 commit fbe6fe5

File tree

3 files changed

+4
-111
lines changed

3 files changed

+4
-111
lines changed

config/ModuleMetadata.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@
2727
"versions": {
2828
"authentication": {
2929
"prerelease": "",
30-
"version": "2.27.8"
30+
"version": "2.28.2"
3131
},
3232
"beta": {
3333
"prerelease": "",
34-
"version": "2.27.8"
34+
"version": "2.28.2"
3535
},
3636
"v1.0": {
3737
"prerelease": "",
38-
"version": "2.27.8"
38+
"version": "2.28.2"
3939
}
4040
}
4141
}

config/ModulesMapping.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
// "Reports": "^reports\\.|^auditLogs\\.|^deviceManagement.deviceManagementReports$|^admin.adminReportSetting",
3535
// "SchemaExtensions": "^schemaExtensions\\.",
3636
// "Search": "^search\\.|^external\\.",
37-
// "Security": "^security\\.|^users.security$",
37+
"Security": "^security\\.|^users.security$",
3838
// "Sites": "^sites.baseSitePage$|^sites.site$|^sites.itemAnalytics$|^sites.columnDefinition$|^sites.contentType$|^sites.drive$|^sites.list$|^sites.sitePage$|^sites.permission$|^sites.store$|^users.site$|^groups.site$|^sites.*.Functions$|^sites.*.Actions$|^sites.richLongRunningOperation$|^termStore.sets.ListChildren$|^admin.sharepoint$",
3939
// "Teams": "^teams\\.|^chats\\.|^users.chat$|^appCatalogs.teamsApp$|^users.userTeamwork$|^teamwork\\.|^users.team$|^groups.team$",
4040
"Users": "^users.user$|^users.directoryObject$|^users.licenseDetails$|^users.mailboxSettings|^users.notification$|^users.outlookUser$|^users.profilePhoto$|^users.userSettings$|^users.extension$|^users.oAuth2PermissionGrant$|^users.todo$|^users.itemInsights$|^users.servicePrincipal$",

src/readme.graph.md

Lines changed: 0 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -334,25 +334,6 @@ directive:
334334
let dateTimeToJsonRegex = /(\.Json\.JsonString\()(.*)\?(\.ToString\(@"yyyy'-'MM'-'dd'T'HH':'mm':'ss\.fffffffK")/gm
335335
$ = $.replace(dateTimeToJsonRegex, '$1System.DateTime.SpecifyKind($2.Value.ToUniversalTime(), System.DateTimeKind.Utc)$3');
336336
337-
//The following regex below adds a property tracker to ensure that users can also pass $Null as an alternative to the current "null" string which gets inferred to null.
338-
339-
const regexP = /AddIf\(\s*null\s*!=\s*\(\(\(object\)this\._(\w+).*?(\(Microsoft.*.PowerShell\.Runtime\.Json\.JsonNode\)).*?"(\w+)".*?container\.Add\s*\);/gm
340-
$ = $.replace(regexP, (match, p1, p2, p3) => {
341-
let capitalizedP1 = p1.charAt(0).toUpperCase() + p1.slice(1); // Capitalize first letter
342-
return `if(this.IsPropertySet("${p1}"))\n\t\t{\n\t\t\tvar propertyInfo = this.GetType().GetProperty("${capitalizedP1}");\n\t\t\tif (propertyInfo != null)\n\t\t\t{\n\t\t\tSystem.Type propertyType = propertyInfo.PropertyType;\n\t\t\t\t\tAddIf(${p2}PropertyTracker.ConvertToJsonNode(propertyType, this._${p1}),"${p1}",container.Add);\n\t\t\t}\n\t\t}`;
343-
});
344-
345-
$ = $.replace(/if\s*\(\s*null\s*!=\s*this\._(\w+)\s*\)/gm, 'if(this.IsPropertySet("$1"))')
346-
347-
let nameSpacePrefixRegex = /(Microsoft(?:\.\w+)*?\.PowerShell)/gm
348-
let nameSpacePrefix = 'Microsoft.Graph.PowerShell';
349-
if($.match(nameSpacePrefixRegex)){
350-
let prefixMatch = nameSpacePrefixRegex.exec($);
351-
nameSpacePrefix = prefixMatch[1];
352-
}
353-
$ = $.replace(/container\.Add\("(\w+)",\s*(__\w+)\);/gm, 'var nullFlag = ('+nameSpacePrefix+'.Runtime.Json.JsonNode)new '+nameSpacePrefix+'.Runtime.Json.JsonString("nullarray");\n\t\tif($2.Count == 0)\n\t\t{\n\t\t\t$2.Add(nullFlag);\n\t\t}\n\t\tcontainer.Add("$1", $2);');
354-
355-
$ =$.replace(/AddIf\(\s+null\s+!=\s+(this\._\w+)\s+\?\s+\((Microsoft\.Graph\..*?)\)\s+this\._(\w+)\.ToJson\(null,serializationMode\)\s+:\s+null,\s+"\w+"\s+,container.Add\s+\);/gm, 'if (this.IsPropertySet("$3")) \n{\n if ($1 != null)\n{\n container.Add("$3", ($2)$1.ToJson(null, serializationMode)); \n}\nelse\n{\n container.Add("$3", "null"); \n}\n}');
356337
357338
return $;
358339
}
@@ -419,28 +400,6 @@ directive:
419400
if($.match(additionalPropertiesRegex)) {
420401
$ = $.replace(additionalPropertiesRegex, '$1$2 new $3');
421402
}
422-
//The following regex below adds a property tracker to ensure that users can also pass $Null as an alternative to the current "null" string which gets inferred to null.
423-
$ = $.replace(/\bpublic\s+(\w+\??)\s+(\w+)\s*{\s*get\s*=>\s*this\.(\w+);\s*set\s*=>\s*this\.\3\s*=\s*value;\s*}/gmi,'public $1 $2\n\t{\n\t\tget=>this.$3;\n\t\tset\n\t\t{\n\t\t\tthis.$3=SanitizeValue<$1>(value);\n\t\t\tTrackProperty(nameof($2));\n\t\t}\n\t}')
424-
425-
$ = $.replace(/\bpublic\s+(\w+\[\])\s+(\w+)\s*{\s*get\s*=>\s*this\.(\w+);\s*set\s*=>\s*this\.\3\s*=\s*value;\s*}/gm,'public $1 $2\n\t{\n\t\tget=>this.$3;\n\t\tset\n\t\t{\n\t\t\tthis.$3=value;\n\t\t\tTrackProperty(nameof($2));\n\t\t}\n\t}')
426-
427-
$ = $.replace(/\bpublic\s+(Microsoft\.Graph\.[\w.]+\[\])\s+(\w+)\s*{\s*get\s*=>\s*this\.(\w+);\s*set\s*=>\s*this\.\3\s*=\s*value;\s*}/gm,'public $1 $2\n\t{\n\t\tget=>this.$3;\n\t\tset\n\t\t{\n\t\t\tthis.$3=value;\n\t\t\tTrackProperty(nameof($2));\n\t\t}\n\t}')
428-
429-
const match = $documentPath.match(/generated%2Fapi%2FModels%2F([\w]*[\w\d]*)\.cs/gm);
430-
if (match) {
431-
let fileName = match[0];
432-
fileName = fileName.replace('generated%2Fapi%2FModels%2F','')
433-
fileName = fileName.replace('.cs','')
434-
const interfaceName = 'I'+fileName
435-
$ = $.replace('interface '+interfaceName+' :', 'interface '+interfaceName+' : IPropertyTracker,')
436-
const className = fileName
437-
const regexP = new RegExp(`public\\s+partial\\s+class\\s+${className}\\s*:\\s*[\\s\\S]*?{`, "gm");
438-
var matches = regexP.exec($);
439-
let originalMatch = matches[0];
440-
$ = $.replace(regexP, originalMatch+'\n\t\tprivate readonly PropertyTracker _propertyTracker = new PropertyTracker();\n\t\tpublic void TrackProperty(string propertyName) => _propertyTracker.TrackProperty(propertyName);\n\t\tpublic bool IsPropertySet(string propertyName) =>_propertyTracker.IsPropertySet(propertyName);\n\t\tpublic T SanitizeValue<T>(object value) => PropertyTracker.SanitizeValue<T>(value);');
441-
}
442-
443-
$ = $.replace(/public\s+(Microsoft\.Graph\..*?)\s+(\w+)\s+{\s+get\s+=>\s+\(\s*this\.(\w+)\s+=\s*this\.\3\s+\?\?\s+new\s+(Microsoft\.Graph\..*?)\s+set\s+=>\s+this._\w+\s+=\s+value;\s+}/gm, 'public $1 $2 { \n get => (this.$3 = this.$3 ?? new $4\n set\n {\n this.$3 = value;\n TrackProperty(nameof($2));\n }\n}')
444403
445404
return $;
446405
@@ -495,62 +454,6 @@ directive:
495454
}
496455
});
497456
}
498-
499-
let nameSpacePrefixRegex = /(Microsoft(?:\.\w+)*?\.PowerShell)/gm
500-
let nameSpacePrefix = 'Microsoft.Graph.PowerShell';
501-
if($.match(nameSpacePrefixRegex)){
502-
let prefixMatch = nameSpacePrefixRegex.exec($);
503-
nameSpacePrefix = prefixMatch[1];
504-
}
505-
506-
$ = $.replace(
507-
/await this\.Client\.(\w+)\(\s*Headers\s*,\s*(BodyParameter|_body)\b([^;]+);/g,
508-
(match, methodName, bodyParam, rest) => {
509-
let ensureCall = '';
510-
511-
if (bodyParam === 'BodyParameter') {
512-
ensureCall = `
513-
if (BodyParameter != null)
514-
{
515-
foreach (var prop in BodyParameter.GetType().GetProperties())
516-
{
517-
// Skip indexer properties
518-
if (prop.GetIndexParameters().Length == 0)
519-
{
520-
try
521-
{
522-
var val = prop.GetValue(BodyParameter); // force materialization
523-
}
524-
catch
525-
{}
526-
}
527-
}
528-
await ${nameSpacePrefix}.ModelExtensions.ModelExtensions.EnsurePropertiesAreReady(BodyParameter, failOnExplicitNulls: false);
529-
}`;
530-
} else if (bodyParam === '_body') {
531-
ensureCall = `
532-
if (_body != null)
533-
{
534-
foreach (var prop in _body.GetType().GetProperties())
535-
{
536-
// Skip indexer properties
537-
if (prop.GetIndexParameters().Length == 0)
538-
{
539-
try
540-
{
541-
var val = prop.GetValue(_body); // force materialization
542-
}
543-
catch
544-
{}
545-
}
546-
}
547-
await ${nameSpacePrefix}.ModelExtensions.ModelExtensions.EnsurePropertiesAreReady(_body, failOnExplicitNulls: false);
548-
}`;
549-
}
550-
551-
return `${ensureCall}\nawait this.Client.${methodName}(Headers, ${bodyParam}${rest};`;
552-
}
553-
);
554457
555458
return $;
556459
}
@@ -754,16 +657,6 @@ directive:
754657
755658
$ = $.replace(/cleanedBody = Microsoft.*.ReplaceAndRemoveSlashes\(cleanedBody\);/gm,'')
756659
757-
let nameSpacePrefixRegex = /(Microsoft(?:\.\w+)*?\.PowerShell)/gm
758-
let nameSpacePrefix = 'Microsoft.Graph.PowerShell';
759-
if($.match(nameSpacePrefixRegex)){
760-
let prefixMatch = nameSpacePrefixRegex.exec($);
761-
nameSpacePrefix = prefixMatch[1];
762-
}
763-
$ = $.replace(/cleanedBody\s*=\s*body\.ToJson\(null\)\.ToString\(\);/g,'await '+nameSpacePrefix+'.ModelExtensions.ModelExtensions.EnsurePropertiesAreReady(body, failOnExplicitNulls: false);\n cleanedBody = body.ToJson(null).ToString();'
764-
);
765-
$ = $.replace(/(^\s*)cleanedBody\s*=\s*Microsoft\.Graph\.(?:Beta\.)?PowerShell\.JsonUtilities\.JsonExtensions\.RemoveDefaultNullProperties\s*\(\s*jsonObject\s*\)\s*;/gm,'$1// cleanedBody = Microsoft.Graph.$2PowerShell.JsonUtilities.JsonExtensions.RemoveDefaultNullProperties(jsonObject);'
766-
);
767660
return $
768661
}
769662

0 commit comments

Comments
 (0)