Skip to content

Commit

Permalink
Sdk update (#68)
Browse files Browse the repository at this point in the history
* Update code style.

* Minor updates.

* Update CLI to use current SDK.
  • Loading branch information
SebastianStehle authored Mar 22, 2023
1 parent ec66616 commit b1f5071
Show file tree
Hide file tree
Showing 66 changed files with 1,767 additions and 3,614 deletions.
2 changes: 1 addition & 1 deletion cli/Squidex.CLI/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
<PackageTags>Squidex HeadlessCMS</PackageTags>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<Version>9.6</Version>
<Version>10.0</Version>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// ==========================================================================

using Squidex.ClientLibrary;
using Squidex.ClientLibrary.Management;

namespace Squidex.CLI.Commands.Implementation;

Expand All @@ -22,17 +21,5 @@ public interface ISession

DirectoryInfo WorkingDirectory { get; }

IAppsClient Apps { get; }

IAssetsClient Assets { get; }

IBackupsClient Backups { get; }

ISchemasClient Schemas { get; }

IExtendableRulesClient Rules { get; }

IContentsClient<TEntity, TData> Contents<TEntity, TData>(string schemaName) where TEntity : Content<TData> where TData : class, new();

IContentsClient<DynamicContent, DynamicData> Contents(string schemaName);
ISquidexClient Client { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static async Task ExportAsync(this ISession session, IExportSettings sett
{
var ctx = QueryContext.Default.Unpublished(settings.Unpublished);

var contents = session.Contents(settings.Schema);
var contents = session.Client.DynamicContents(settings.Schema);

var total = 0L;
var totalRead = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static class ImportHelper
{
public static async Task ImportAsync(this ISession session, IImportSettings setting, ILogger log, IEnumerable<DynamicData> datas)
{
var contents = session.Contents(setting.Schema);
var contents = session.Client.DynamicContents(setting.Schema);

var totalWritten = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public async Task ExportAsync(ISyncService sync, SyncOptions options, ISession s

await log.DoSafeAsync("Exporting clients", async () =>
{
var clients = await session.Apps.GetClientsAsync(session.App);
var clients = await session.Client.Apps.GetClientsAsync();

model.Clients = new Dictionary<string, AppClientModel>();

Expand All @@ -51,7 +51,7 @@ await log.DoSafeAsync("Exporting clients", async () =>

await log.DoSafeAsync("Exporting languages", async () =>
{
var languages = await session.Apps.GetLanguagesAsync(session.App);
var languages = await session.Client.Apps.GetLanguagesAsync();

model.Languages = new Dictionary<string, UpdateLanguageDto>();

Expand All @@ -63,7 +63,7 @@ await log.DoSafeAsync("Exporting languages", async () =>

await log.DoSafeAsync("Exporting Roles", async () =>
{
var roles = await session.Apps.GetRolesAsync(session.App);
var roles = await session.Client.Apps.GetRolesAsync();

model.Roles = new Dictionary<string, AppRoleModel>();

Expand All @@ -75,7 +75,7 @@ await log.DoSafeAsync("Exporting Roles", async () =>

await log.DoSafeAsync("Exporting asset scripts", async () =>
{
var assetScripts = await session.Apps.GetAssetScriptsAsync(session.App);
var assetScripts = await session.Client.Apps.GetAssetScriptsAsync();

model.AssetScripts = assetScripts.ToModel();
});
Expand Down Expand Up @@ -160,14 +160,14 @@ await log.DoSafeAsync($"Contributor '{email}' creating", async () =>
{
var request = new AssignContributorDto { ContributorId = email, Role = value.Role, Invite = true };

await session.Apps.PostContributorAsync(session.App, request);
await session.Client.Apps.PostContributorAsync(request);
});
}
}

private async Task SynchronizeClientsAsync(AppModel model, SyncOptions options, ISession session)
{
var current = await session.Apps.GetClientsAsync(session.App);
var current = await session.Client.Apps.GetClientsAsync();

if (options.Delete)
{
Expand All @@ -182,7 +182,7 @@ private async Task SynchronizeClientsAsync(AppModel model, SyncOptions options,

await log.DoSafeAsync($"Client '{client.Id}' deleting", async () =>
{
await session.Apps.DeleteClientAsync(session.App, client.Id);
await session.Client.Apps.DeleteClientAsync(client.Id);
});
}
}
Expand All @@ -200,7 +200,7 @@ await log.DoSafeAsync($"Client '{clientId}' creating", async () =>
{
var request = new CreateClientDto { Id = clientId };

current = await session.Apps.PostClientAsync(session.App, request);
current = await session.Client.Apps.PostClientAsync(request);
});
}

Expand All @@ -222,14 +222,14 @@ await log.DoSafeAsync($"Client '{clientId}' updating", async () =>
{
var request = client.ToUpdate();

await session.Apps.PutClientAsync(session.App, clientId, request);
await session.Client.Apps.PutClientAsync(clientId, request);
});
}
}

private async Task SynchronizeLanguagesAsync(AppModel model, SyncOptions options, ISession session)
{
var current = await session.Apps.GetLanguagesAsync(session.App);
var current = await session.Client.Apps.GetLanguagesAsync();

if (options.Delete)
{
Expand All @@ -242,7 +242,7 @@ private async Task SynchronizeLanguagesAsync(AppModel model, SyncOptions options

await log.DoSafeAsync($"Language '{language.Iso2Code}' deleting", async () =>
{
await session.Apps.DeleteLanguageAsync(session.App, language.Iso2Code);
await session.Client.Apps.DeleteLanguageAsync(language.Iso2Code);
});
}
}
Expand All @@ -260,7 +260,7 @@ await log.DoSafeAsync($"Language '{isoCode}' creating", async () =>
{
var request = new AddLanguageDto { Language = isoCode };

current = await session.Apps.PostLanguageAsync(session.App, request);
current = await session.Client.Apps.PostLanguageAsync(request);
});
}

Expand All @@ -275,14 +275,14 @@ await log.DoSafeAsync($"Language '{isoCode}' creating", async () =>

await log.DoSafeAsync($"Language '{isoCode}' updating", async () =>
{
await session.Apps.PutLanguageAsync(session.App, isoCode, language);
await session.Client.Apps.PutLanguageAsync(isoCode, language);
});
}
}

private async Task SynchronizeRolesAsync(AppModel model, SyncOptions options, ISession session)
{
var current = await session.Apps.GetRolesAsync(session.App);
var current = await session.Client.Apps.GetRolesAsync();

if (options.Delete)
{
Expand All @@ -298,7 +298,7 @@ private async Task SynchronizeRolesAsync(AppModel model, SyncOptions options, IS

await log.DoSafeAsync($"Role '{role.Name}' deleting", async () =>
{
await session.Apps.DeleteRoleAsync(session.App, role.Name);
await session.Client.Apps.DeleteRoleAsync(role.Name);
});
}
}
Expand All @@ -316,7 +316,7 @@ await log.DoSafeAsync($"Role '{roleName}' creating", async () =>
{
var request = new AddRoleDto { Name = roleName };

current = await session.Apps.PostRoleAsync(session.App, request);
current = await session.Client.Apps.PostRoleAsync(request);
});
}

Expand All @@ -333,7 +333,7 @@ await log.DoSafeAsync($"Role '{roleName}' updating", async () =>
{
var request = role.ToUpdate();

await session.Apps.PutRoleAsync(session.App, roleName, request);
await session.Client.Apps.PutRoleAsync(roleName, request);
});
}
}
Expand All @@ -349,7 +349,7 @@ await log.DoSafeAsync("Asset scripts updating", async () =>
{
var request = model.AssetScripts?.ToUpdate() ?? new UpdateAssetScriptsDto();

await session.Apps.PutAssetScriptsAsync(session.App, request);
await session.Client.Apps.PutAssetScriptsAsync(request);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ await log.DoSafeAsync($"Exporting Assets ({assetBatch})", async () =>
});
}

await session.Assets.GetAllAsync(session.App, async asset =>
await session.Client.Assets.GetAllAsync(async asset =>
{
var model = asset.ToModel();

Expand Down Expand Up @@ -143,7 +143,7 @@ public async Task ImportAsync(ISyncService sync, SyncOptions options, ISession s

var assetIndex = 0;

var results = await session.Assets.BulkUpdateAssetsAsync(session.App, request);
var results = await session.Client.Assets.BulkUpdateAssetsAsync(request);

foreach (var asset in model.Assets)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public DownloadPipeline(ISession session, ILogger log, IFileSystem fs)

if (assetHash == null || !string.Equals(asset.FileHash, assetHash, StringComparison.Ordinal))
{
var response = await session.Assets.GetAssetContentBySlugAsync(session.App, asset.Id, string.Empty);
var response = await session.Client.Assets.GetAssetContentBySlugAsync(asset.Id, string.Empty);

await using (response.Stream)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal sealed class UploadPipeline

public UploadPipeline(ISession session, ILogger log, IFileSystem fs)
{
var tree = new AssetFolderTree(session.Assets, session.App);
var tree = new AssetFolderTree(session.Client.Assets);

var fileNameStep = new TransformBlock<AssetModel, (AssetModel, FilePath)>(async asset =>
{
Expand Down Expand Up @@ -68,7 +68,7 @@ public UploadPipeline(ISession session, ILogger log, IFileSystem fs)
{
var file = new FileParameter(stream, asset.FileName, asset.MimeType);

var result = await session.Assets.PostUpsertAssetAsync(session.App, asset.Id, null, true, file);
var result = await session.Client.Assets.PostUpsertAssetAsync(asset.Id, null, true, file);

log.ProcessCompleted(process);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ public Task CleanupAsync(IFileSystem fs)

public async Task ExportAsync(ISyncService sync, SyncOptions options, ISession session)
{
var schemas = await session.Schemas.GetSchemasAsync(session.App);
var schemas = await session.Client.Schemas.GetSchemasAsync();
var schemaMap = schemas.Items.ToDictionary(x => x.Id, x => x.Name);

var context = QueryContext.Default.Unpublished().IgnoreFallback();

foreach (var schema in schemas.Items)
{
var client = session.Contents(schema.Name);
var client = session.Client.DynamicContents(schema.Name);

var contents = new List<ContentModel>();
var contentBatch = 0;
Expand Down Expand Up @@ -114,7 +114,7 @@ public async Task ImportAsync(ISyncService sync, SyncOptions options, ISession s
GetFiles(sync.FileSystem)
.Select(x => (x, sync.Read<ContentsModel>(x, log)));

var schemas = await session.Schemas.GetSchemasAsync(session.App);
var schemas = await session.Client.Schemas.GetSchemasAsync();
var schemaMap = schemas.Items.ToDictionary(x => x.Name, x => x.Id);

var mapper = new Extensions.Mapper(session.Url, session.App, options.Languages);
Expand All @@ -125,7 +125,7 @@ public async Task ImportAsync(ISyncService sync, SyncOptions options, ISession s
{
mapper.Map(model);

var client = session.Contents(model.Contents[0].Schema);
var client = session.Client.DynamicContents(model.Contents[0].Schema);

var request = new BulkUpdate
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public Task CleanupAsync(IFileSystem fs)

public async Task ExportAsync(ISyncService sync, SyncOptions options, ISession session)
{
var current = await session.Rules.GetRulesAsync();
var current = await session.Client.ExtendableRules.GetRulesAsync();

await MapSchemaIdsToNamesAsync(session, current);

Expand Down Expand Up @@ -90,7 +90,7 @@ public async Task ImportAsync(ISyncService sync, SyncOptions options, ISession s
return;
}

var current = await session.Rules.GetRulesAsync();
var current = await session.Client.ExtendableRules.GetRulesAsync();

if (!current.Items.HasDistinctNames(x => x.Name))
{
Expand All @@ -108,7 +108,7 @@ public async Task ImportAsync(ISyncService sync, SyncOptions options, ISession s
{
await log.DoSafeAsync($"Rule '{name}' deleting", async () =>
{
await session.Rules.DeleteRuleAsync(rule.Id);
await session.Client.ExtendableRules.DeleteRuleAsync(rule.Id);

rulesByName.Remove(name);
});
Expand All @@ -134,7 +134,7 @@ await log.DoSafeAsync($"Rule '{newRule.Name}' creating", async () =>

var request = newRule.ToCreate();

var created = await session.Rules.CreateRuleAsync(request);
var created = await session.Client.ExtendableRules.CreateRuleAsync(request);

rulesByName[newRule.Name] = created;
});
Expand All @@ -153,7 +153,7 @@ await log.DoVersionedAsync($"Rule '{newRule.Name}' updating", rule.Version, asyn
{
var request = newRule.ToUpdate();

rule = await session.Rules.UpdateRuleAsync(rule.Id, request);
rule = await session.Client.ExtendableRules.UpdateRuleAsync(rule.Id, request);

return rule.Version;
});
Expand All @@ -164,7 +164,7 @@ await log.DoVersionedAsync($"Rule '{newRule.Name}' updating", rule.Version, asyn
{
await log.DoVersionedAsync($"Rule '{newRule.Name}' enabling", rule.Version, async () =>
{
var result = await session.Rules.EnableRuleAsync(rule.Id);
var result = await session.Client.ExtendableRules.EnableRuleAsync(rule.Id);

return result.Version;
});
Expand All @@ -173,7 +173,7 @@ await log.DoVersionedAsync($"Rule '{newRule.Name}' enabling", rule.Version, asyn
{
await log.DoVersionedAsync($"Rule '{newRule.Name}' disabling", rule.Version, async () =>
{
var result = await session.Rules.DisableRuleAsync(rule.Id);
var result = await session.Client.ExtendableRules.DisableRuleAsync(rule.Id);

return result.Version;
});
Expand All @@ -184,7 +184,7 @@ await log.DoVersionedAsync($"Rule '{newRule.Name}' disabling", rule.Version, asy

private async Task MapSchemaIdsToNamesAsync(ISession session, ExtendableRules current)
{
var schemas = await session.Schemas.GetSchemasAsync(session.App);
var schemas = await session.Client.Schemas.GetSchemasAsync();

var map = schemas.Items.ToDictionary(x => x.Id, x => x.Name);

Expand All @@ -200,7 +200,7 @@ private async Task MapSchemaIdsToNamesAsync(ISession session, ExtendableRules cu

private async Task MapSchemaNamesToIdsAsync(ISession session, List<RuleModel> models)
{
var schemas = await session.Schemas.GetSchemasAsync(session.App);
var schemas = await session.Client.Schemas.GetSchemasAsync();

var map = schemas.Items.ToDictionary(x => x.Name, x => x.Id);

Expand Down
Loading

0 comments on commit b1f5071

Please sign in to comment.