Skip to content

Commit 94a5c4c

Browse files
authored
Merge branch 'master' into feat-8925-realtime-session-web-sdk
2 parents 2eb9b58 + 85f51dc commit 94a5c4c

File tree

4 files changed

+38
-12
lines changed

4 files changed

+38
-12
lines changed

templates/cli/lib/commands/generic.js.twig

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,11 @@ const deleteSession = async (accountId) => {
172172
parseOutput: false,
173173
sdk: client
174174
})
175-
176-
globalConfig.removeSession(accountId);
177175
} catch (e) {
178176
error('Unable to log out, removing locally saved session information')
177+
} finally {
178+
globalConfig.removeSession(accountId);
179179
}
180-
globalConfig.removeSession(accountId);
181180
}
182181

183182
const logout = new Command("logout")
@@ -195,6 +194,7 @@ const logout = new Command("logout")
195194
}
196195
if (sessions.length === 1) {
197196
await deleteSession(current);
197+
globalConfig.setCurrentSession('');
198198
success("Logging out");
199199

200200
return;
@@ -216,6 +216,8 @@ const logout = new Command("logout")
216216
globalConfig.setCurrentSession(accountId);
217217

218218
success(`Current account is ${accountId}`);
219+
} else if (remainingSessions.length === 0) {
220+
globalConfig.setCurrentSession('');
219221
}
220222

221223
success("Logging out");

templates/cli/lib/config.js.twig

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -681,15 +681,25 @@ class Global extends Config {
681681

682682
getSessions() {
683683
const sessions = Object.keys(this.data).filter((key) => !Global.IGNORE_ATTRIBUTES.includes(key))
684+
const current = this.getCurrentSession();
684685

685-
return sessions.map((session) => {
686-
687-
return {
688-
id: session,
689-
endpoint: this.data[session][Global.PREFERENCE_ENDPOINT],
690-
email: this.data[session][Global.PREFERENCE_EMAIL]
686+
const sessionMap = new Map();
687+
688+
sessions.forEach((sessionId) => {
689+
const email = this.data[sessionId][Global.PREFERENCE_EMAIL];
690+
const endpoint = this.data[sessionId][Global.PREFERENCE_ENDPOINT];
691+
const key = `${email}|${endpoint}`;
692+
693+
if (sessionId === current || !sessionMap.has(key)) {
694+
sessionMap.set(key, {
695+
id: sessionId,
696+
endpoint: this.data[sessionId][Global.PREFERENCE_ENDPOINT],
697+
email: this.data[sessionId][Global.PREFERENCE_EMAIL]
698+
});
691699
}
692-
})
700+
});
701+
702+
return Array.from(sessionMap.values());
693703
}
694704

695705
addSession(session, data) {

templates/dotnet/Package/Extensions/Extensions.cs.twig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections;
33
using System.Collections.Generic;
4+
using System.Linq;
45
using System.Text.Json;
56

67
namespace {{ spec.title | caseUcfirst }}.Extensions
@@ -12,6 +13,18 @@ namespace {{ spec.title | caseUcfirst }}.Extensions
1213
return JsonSerializer.Serialize(dict, Client.SerializerOptions);
1314
}
1415

16+
public static List<T> ConvertToList<T>(this object value)
17+
{
18+
return value switch
19+
{
20+
JsonElement jsonElement => jsonElement.Deserialize<List<T>>() ?? throw new InvalidCastException($"Cannot deserialize {jsonElement} to List<{typeof(T)}>."),
21+
object[] objArray => objArray.Cast<T>().ToList(),
22+
List<T> list => list,
23+
IEnumerable<T> enumerable => enumerable.ToList(),
24+
_ => throw new InvalidCastException($"Cannot convert {value.GetType()} to List<{typeof(T)}>")
25+
};
26+
}
27+
1528
public static string ToQueryString(this Dictionary<string, object?> parameters)
1629
{
1730
var query = new List<string>();

templates/dotnet/Package/Models/Model.cs.twig

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ using System.Collections.Generic;
55
using System.Text.Json;
66
using System.Text.Json.Serialization;
77
using {{ spec.title | caseUcfirst }}.Enums;
8+
using {{ spec.title | caseUcfirst }}.Extensions;
89

910
namespace {{ spec.title | caseUcfirst }}.Models
1011
{
@@ -41,7 +42,7 @@ namespace {{ spec.title | caseUcfirst }}.Models
4142
{{ property.name | caseCamel | escapeKeyword | removeDollarSign }}:{{' '}}
4243
{%- if property.sub_schema %}
4344
{%- if property.type == 'array' -%}
44-
map["{{ property.name }}"] is JsonElement jsonArray{{ loop.index }} ? jsonArray{{ loop.index }}.Deserialize<List<Dictionary<string, object>>>()!.Select(it => {{ property.sub_schema | caseUcfirst | overrideIdentifier }}.From(map: it)).ToList() : ((IEnumerable<Dictionary<string, object>>)map["{{ property.name }}"]).Select(it => {{ property.sub_schema | caseUcfirst | overrideIdentifier }}.From(map: it)).ToList()
45+
map["{{ property.name }}"].ConvertToList<Dictionary<string, object>>().Select(it => {{ property.sub_schema | caseUcfirst | overrideIdentifier }}.From(map: it)).ToList()
4546
{%- else -%}
4647
{{ property.sub_schema | caseUcfirst | overrideIdentifier }}.From(map: map["{{ property.name }}"] is JsonElement jsonObj{{ loop.index }} ? jsonObj{{ loop.index }}.Deserialize<Dictionary<string, object>>()! : (Dictionary<string, object>)map["{{ property.name }}"])
4748
{%- endif %}
@@ -58,7 +59,7 @@ namespace {{ spec.title | caseUcfirst }}.Models
5859
{%- endif %}
5960
{%- else %}
6061
{%- if property.type == 'array' -%}
61-
map["{{ property.name }}"] is JsonElement jsonArrayProp{{ loop.index }} ? jsonArrayProp{{ loop.index }}.Deserialize<{{ property | typeName }}>()! : ({{ property | typeName }})map["{{ property.name }}"]
62+
map["{{ property.name }}"].ConvertToList<{{ property | typeName | replace({'List<': '', '>': ''}) }}>()
6263
{%- else %}
6364
{%- if property.type == "integer" or property.type == "number" %}
6465
{%- if not property.required -%}map["{{ property.name }}"] == null ? null :{% endif %}Convert.To{% if property.type == "integer" %}Int64{% else %}Double{% endif %}(map["{{ property.name }}"])

0 commit comments

Comments
 (0)