mirror of https://github.com/Squidex/squidex.git
committed by
GitHub
230 changed files with 3415 additions and 2854 deletions
@ -0,0 +1,15 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Entities.Backup |
||||
|
{ |
||||
|
public enum BackupVersion |
||||
|
{ |
||||
|
V2, |
||||
|
V1 |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,116 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using Newtonsoft.Json; |
||||
|
using Newtonsoft.Json.Linq; |
||||
|
using Squidex.Infrastructure.EventSourcing; |
||||
|
|
||||
|
#pragma warning disable SA1401 // Fields must be private
|
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Entities.Backup.Model |
||||
|
{ |
||||
|
public sealed class CompatibleStoredEvent |
||||
|
{ |
||||
|
[JsonProperty("n")] |
||||
|
public NewEvent NewEvent; |
||||
|
|
||||
|
[JsonProperty] |
||||
|
public string StreamName; |
||||
|
|
||||
|
[JsonProperty] |
||||
|
public string EventPosition; |
||||
|
|
||||
|
[JsonProperty] |
||||
|
public long EventStreamNumber; |
||||
|
|
||||
|
[JsonProperty] |
||||
|
public CompatibleEventData Data; |
||||
|
|
||||
|
public static CompatibleStoredEvent V1(StoredEvent stored) |
||||
|
{ |
||||
|
return new CompatibleStoredEvent |
||||
|
{ |
||||
|
Data = CompatibleEventData.V1(stored.Data), |
||||
|
EventPosition = stored.EventPosition, |
||||
|
EventStreamNumber = stored.EventStreamNumber, |
||||
|
StreamName = stored.StreamName |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
public static CompatibleStoredEvent V2(StoredEvent stored) |
||||
|
{ |
||||
|
return new CompatibleStoredEvent { NewEvent = NewEvent.V2(stored) }; |
||||
|
} |
||||
|
|
||||
|
public (string Stream, EventData Data) ToEvent() |
||||
|
{ |
||||
|
if (NewEvent != null) |
||||
|
{ |
||||
|
return NewEvent.ToEvent(); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
return (StreamName, Data.ToData()); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public sealed class CompatibleEventData |
||||
|
{ |
||||
|
[JsonProperty] |
||||
|
public string Type; |
||||
|
|
||||
|
[JsonProperty] |
||||
|
public JRaw Payload; |
||||
|
|
||||
|
[JsonProperty] |
||||
|
public EnvelopeHeaders Metadata; |
||||
|
|
||||
|
public static CompatibleEventData V1(EventData data) |
||||
|
{ |
||||
|
var payload = new JRaw(data.Payload); |
||||
|
|
||||
|
return new CompatibleEventData { Type = data.Type, Payload = payload, Metadata = data.Headers }; |
||||
|
} |
||||
|
|
||||
|
public EventData ToData() |
||||
|
{ |
||||
|
return new EventData(Type, Metadata, Payload.ToString()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public sealed class NewEvent |
||||
|
{ |
||||
|
[JsonProperty("t")] |
||||
|
public string EventType; |
||||
|
|
||||
|
[JsonProperty("s")] |
||||
|
public string StreamName; |
||||
|
|
||||
|
[JsonProperty("p")] |
||||
|
public string EventPayload; |
||||
|
|
||||
|
[JsonProperty("h")] |
||||
|
public EnvelopeHeaders EventHeaders; |
||||
|
|
||||
|
public static NewEvent V2(StoredEvent stored) |
||||
|
{ |
||||
|
return new NewEvent |
||||
|
{ |
||||
|
EventType = stored.Data.Type, |
||||
|
EventHeaders = stored.Data.Headers, |
||||
|
EventPayload = stored.Data.Payload, |
||||
|
StreamName = stored.StreamName |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
public (string Stream, EventData Data) ToEvent() |
||||
|
{ |
||||
|
return (StreamName, new EventData(EventType, EventHeaders, EventPayload)); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,41 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using GraphQL.Language.AST; |
||||
|
using GraphQL.Types; |
||||
|
using NodaTime.Text; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Utils |
||||
|
{ |
||||
|
public sealed class InstantGraphType : DateGraphType |
||||
|
{ |
||||
|
public override object Serialize(object value) |
||||
|
{ |
||||
|
return ParseValue(value); |
||||
|
} |
||||
|
|
||||
|
public override object ParseValue(object value) |
||||
|
{ |
||||
|
return InstantPattern.General.Parse(value.ToString()).Value; |
||||
|
} |
||||
|
|
||||
|
public override object ParseLiteral(IValue value) |
||||
|
{ |
||||
|
if (value is InstantValue timeValue) |
||||
|
{ |
||||
|
return ParseValue(timeValue.Value); |
||||
|
} |
||||
|
|
||||
|
if (value is StringValue stringValue) |
||||
|
{ |
||||
|
return ParseValue(stringValue.Value); |
||||
|
} |
||||
|
|
||||
|
return null; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,25 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using GraphQL.Language.AST; |
||||
|
using NodaTime; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Utils |
||||
|
{ |
||||
|
public sealed class InstantValue : ValueNode<Instant> |
||||
|
{ |
||||
|
public InstantValue(Instant value) |
||||
|
{ |
||||
|
Value = value; |
||||
|
} |
||||
|
|
||||
|
protected override bool Equals(ValueNode<Instant> node) |
||||
|
{ |
||||
|
return Value.Equals(node.Value); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,155 +0,0 @@ |
|||||
// ==========================================================================
|
|
||||
// Squidex Headless CMS
|
|
||||
// ==========================================================================
|
|
||||
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|
||||
// All rights reserved. Licensed under the MIT license.
|
|
||||
// ==========================================================================
|
|
||||
|
|
||||
using System; |
|
||||
using System.Globalization; |
|
||||
using MongoDB.Bson; |
|
||||
using Newtonsoft.Json.Linq; |
|
||||
|
|
||||
namespace Squidex.Infrastructure.MongoDb |
|
||||
{ |
|
||||
public static class BsonJsonConverter |
|
||||
{ |
|
||||
public static BsonDocument ToBson(this JObject source) |
|
||||
{ |
|
||||
var result = new BsonDocument(); |
|
||||
|
|
||||
foreach (var property in source) |
|
||||
{ |
|
||||
result.Add(property.Key.EscapeJson(), property.Value.ToBson()); |
|
||||
} |
|
||||
|
|
||||
return result; |
|
||||
} |
|
||||
|
|
||||
public static JObject ToJson(this BsonDocument source) |
|
||||
{ |
|
||||
var result = new JObject(); |
|
||||
|
|
||||
foreach (var property in source) |
|
||||
{ |
|
||||
result.Add(property.Name.UnescapeBson(), property.Value.ToJson()); |
|
||||
} |
|
||||
|
|
||||
return result; |
|
||||
} |
|
||||
|
|
||||
public static BsonArray ToBson(this JArray source) |
|
||||
{ |
|
||||
var result = new BsonArray(); |
|
||||
|
|
||||
foreach (var item in source) |
|
||||
{ |
|
||||
result.Add(item.ToBson()); |
|
||||
} |
|
||||
|
|
||||
return result; |
|
||||
} |
|
||||
|
|
||||
public static JArray ToJson(this BsonArray source) |
|
||||
{ |
|
||||
var result = new JArray(); |
|
||||
|
|
||||
foreach (var item in source) |
|
||||
{ |
|
||||
result.Add(item.ToJson()); |
|
||||
} |
|
||||
|
|
||||
return result; |
|
||||
} |
|
||||
|
|
||||
public static BsonValue ToBson(this JToken source) |
|
||||
{ |
|
||||
switch (source.Type) |
|
||||
{ |
|
||||
case JTokenType.Object: |
|
||||
return ((JObject)source).ToBson(); |
|
||||
case JTokenType.Array: |
|
||||
return ((JArray)source).ToBson(); |
|
||||
case JTokenType.Integer: |
|
||||
return BsonValue.Create(((JValue)source).Value); |
|
||||
case JTokenType.Float: |
|
||||
return BsonValue.Create(((JValue)source).Value); |
|
||||
case JTokenType.String: |
|
||||
return BsonValue.Create(((JValue)source).Value); |
|
||||
case JTokenType.Boolean: |
|
||||
return BsonValue.Create(((JValue)source).Value); |
|
||||
case JTokenType.Null: |
|
||||
return BsonNull.Value; |
|
||||
case JTokenType.Undefined: |
|
||||
return BsonUndefined.Value; |
|
||||
case JTokenType.Bytes: |
|
||||
return BsonValue.Create(((JValue)source).Value); |
|
||||
case JTokenType.Guid: |
|
||||
return BsonValue.Create(((JValue)source).ToString(CultureInfo.InvariantCulture)); |
|
||||
case JTokenType.Uri: |
|
||||
return BsonValue.Create(((JValue)source).ToString(CultureInfo.InvariantCulture)); |
|
||||
case JTokenType.TimeSpan: |
|
||||
return BsonValue.Create(((JValue)source).ToString(CultureInfo.InvariantCulture)); |
|
||||
case JTokenType.Date: |
|
||||
{ |
|
||||
var value = ((JValue)source).Value; |
|
||||
|
|
||||
if (value is DateTime dateTime) |
|
||||
{ |
|
||||
return dateTime.ToString("yyyy-MM-ddTHH:mm:ssK", CultureInfo.InvariantCulture); |
|
||||
} |
|
||||
else if (value is DateTimeOffset dateTimeOffset) |
|
||||
{ |
|
||||
if (dateTimeOffset.Offset == TimeSpan.Zero) |
|
||||
{ |
|
||||
return dateTimeOffset.UtcDateTime.ToString("yyyy-MM-ddTHH:mm:ssK", CultureInfo.InvariantCulture); |
|
||||
} |
|
||||
else |
|
||||
{ |
|
||||
return dateTimeOffset.ToString("yyyy-MM-ddTHH:mm:ssK", CultureInfo.InvariantCulture); |
|
||||
} |
|
||||
} |
|
||||
else |
|
||||
{ |
|
||||
return value.ToString(); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
throw new NotSupportedException($"Cannot convert {source.GetType()} to Bson."); |
|
||||
} |
|
||||
|
|
||||
public static JToken ToJson(this BsonValue source) |
|
||||
{ |
|
||||
switch (source.BsonType) |
|
||||
{ |
|
||||
case BsonType.Document: |
|
||||
return source.AsBsonDocument.ToJson(); |
|
||||
case BsonType.Array: |
|
||||
return source.AsBsonArray.ToJson(); |
|
||||
case BsonType.Double: |
|
||||
return new JValue(source.AsDouble); |
|
||||
case BsonType.String: |
|
||||
return new JValue(source.AsString); |
|
||||
case BsonType.Boolean: |
|
||||
return new JValue(source.AsBoolean); |
|
||||
case BsonType.DateTime: |
|
||||
return new JValue(source.ToUniversalTime()); |
|
||||
case BsonType.Int32: |
|
||||
return new JValue(source.AsInt32); |
|
||||
case BsonType.Int64: |
|
||||
return new JValue(source.AsInt64); |
|
||||
case BsonType.Decimal128: |
|
||||
return new JValue(source.AsDecimal); |
|
||||
case BsonType.Binary: |
|
||||
return new JValue(source.AsBsonBinaryData.Bytes); |
|
||||
case BsonType.Null: |
|
||||
return JValue.CreateNull(); |
|
||||
case BsonType.Undefined: |
|
||||
return JValue.CreateUndefined(); |
|
||||
} |
|
||||
|
|
||||
throw new NotSupportedException($"Cannot convert {source.GetType()} to Json."); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue