diff --git a/packages/un_model/lib/src/ungraph/edge_spec/edge_spec.dart b/packages/un_model/lib/src/ungraph/edge_spec/edge_spec.dart index b032ab074..8a28caf5d 100644 --- a/packages/un_model/lib/src/ungraph/edge_spec/edge_spec.dart +++ b/packages/un_model/lib/src/ungraph/edge_spec/edge_spec.dart @@ -15,10 +15,11 @@ class EdgeSpec with _$EdgeSpec implements IEdgeSpec { String? id, String? slugged, required String name, + required String description, required String type, required String sourceNodeSpecId, required String targetNodeSpecId, - required List propSpecs, + required List jsonSpecs, }) = _EdgeSpec; factory EdgeSpec.fromJson(Map json) => diff --git a/packages/un_model/lib/src/ungraph/edge_spec/edge_spec.freezed.dart b/packages/un_model/lib/src/ungraph/edge_spec/edge_spec.freezed.dart index a32ea2c6c..f04786f02 100644 --- a/packages/un_model/lib/src/ungraph/edge_spec/edge_spec.freezed.dart +++ b/packages/un_model/lib/src/ungraph/edge_spec/edge_spec.freezed.dart @@ -23,10 +23,11 @@ mixin _$EdgeSpec { String? get id => throw _privateConstructorUsedError; String? get slugged => throw _privateConstructorUsedError; String get name => throw _privateConstructorUsedError; + String get description => throw _privateConstructorUsedError; String get type => throw _privateConstructorUsedError; String get sourceNodeSpecId => throw _privateConstructorUsedError; String get targetNodeSpecId => throw _privateConstructorUsedError; - List get propSpecs => throw _privateConstructorUsedError; + List get jsonSpecs => throw _privateConstructorUsedError; Map toJson() => throw _privateConstructorUsedError; @JsonKey(ignore: true) @@ -43,10 +44,11 @@ abstract class $EdgeSpecCopyWith<$Res> { {String? id, String? slugged, String name, + String description, String type, String sourceNodeSpecId, String targetNodeSpecId, - List propSpecs}); + List jsonSpecs}); } /// @nodoc @@ -65,10 +67,11 @@ class _$EdgeSpecCopyWithImpl<$Res, $Val extends EdgeSpec> Object? id = freezed, Object? slugged = freezed, Object? name = null, + Object? description = null, Object? type = null, Object? sourceNodeSpecId = null, Object? targetNodeSpecId = null, - Object? propSpecs = null, + Object? jsonSpecs = null, }) { return _then(_value.copyWith( id: freezed == id @@ -83,6 +86,10 @@ class _$EdgeSpecCopyWithImpl<$Res, $Val extends EdgeSpec> ? _value.name : name // ignore: cast_nullable_to_non_nullable as String, + description: null == description + ? _value.description + : description // ignore: cast_nullable_to_non_nullable + as String, type: null == type ? _value.type : type // ignore: cast_nullable_to_non_nullable @@ -95,10 +102,10 @@ class _$EdgeSpecCopyWithImpl<$Res, $Val extends EdgeSpec> ? _value.targetNodeSpecId : targetNodeSpecId // ignore: cast_nullable_to_non_nullable as String, - propSpecs: null == propSpecs - ? _value.propSpecs - : propSpecs // ignore: cast_nullable_to_non_nullable - as List, + jsonSpecs: null == jsonSpecs + ? _value.jsonSpecs + : jsonSpecs // ignore: cast_nullable_to_non_nullable + as List, ) as $Val); } } @@ -114,10 +121,11 @@ abstract class _$$_EdgeSpecCopyWith<$Res> implements $EdgeSpecCopyWith<$Res> { {String? id, String? slugged, String name, + String description, String type, String sourceNodeSpecId, String targetNodeSpecId, - List propSpecs}); + List jsonSpecs}); } /// @nodoc @@ -134,10 +142,11 @@ class __$$_EdgeSpecCopyWithImpl<$Res> Object? id = freezed, Object? slugged = freezed, Object? name = null, + Object? description = null, Object? type = null, Object? sourceNodeSpecId = null, Object? targetNodeSpecId = null, - Object? propSpecs = null, + Object? jsonSpecs = null, }) { return _then(_$_EdgeSpec( id: freezed == id @@ -152,6 +161,10 @@ class __$$_EdgeSpecCopyWithImpl<$Res> ? _value.name : name // ignore: cast_nullable_to_non_nullable as String, + description: null == description + ? _value.description + : description // ignore: cast_nullable_to_non_nullable + as String, type: null == type ? _value.type : type // ignore: cast_nullable_to_non_nullable @@ -164,10 +177,10 @@ class __$$_EdgeSpecCopyWithImpl<$Res> ? _value.targetNodeSpecId : targetNodeSpecId // ignore: cast_nullable_to_non_nullable as String, - propSpecs: null == propSpecs - ? _value._propSpecs - : propSpecs // ignore: cast_nullable_to_non_nullable - as List, + jsonSpecs: null == jsonSpecs + ? _value._jsonSpecs + : jsonSpecs // ignore: cast_nullable_to_non_nullable + as List, )); } } @@ -179,11 +192,12 @@ class _$_EdgeSpec extends _EdgeSpec { {this.id, this.slugged, required this.name, + required this.description, required this.type, required this.sourceNodeSpecId, required this.targetNodeSpecId, - required final List propSpecs}) - : _propSpecs = propSpecs, + required final List jsonSpecs}) + : _jsonSpecs = jsonSpecs, super._(); factory _$_EdgeSpec.fromJson(Map json) => @@ -196,22 +210,24 @@ class _$_EdgeSpec extends _EdgeSpec { @override final String name; @override + final String description; + @override final String type; @override final String sourceNodeSpecId; @override final String targetNodeSpecId; - final List _propSpecs; + final List _jsonSpecs; @override - List get propSpecs { - if (_propSpecs is EqualUnmodifiableListView) return _propSpecs; + List get jsonSpecs { + if (_jsonSpecs is EqualUnmodifiableListView) return _jsonSpecs; // ignore: implicit_dynamic_type - return EqualUnmodifiableListView(_propSpecs); + return EqualUnmodifiableListView(_jsonSpecs); } @override String toString() { - return 'EdgeSpec(id: $id, slugged: $slugged, name: $name, type: $type, sourceNodeSpecId: $sourceNodeSpecId, targetNodeSpecId: $targetNodeSpecId, propSpecs: $propSpecs)'; + return 'EdgeSpec(id: $id, slugged: $slugged, name: $name, description: $description, type: $type, sourceNodeSpecId: $sourceNodeSpecId, targetNodeSpecId: $targetNodeSpecId, jsonSpecs: $jsonSpecs)'; } @override @@ -222,13 +238,15 @@ class _$_EdgeSpec extends _EdgeSpec { (identical(other.id, id) || other.id == id) && (identical(other.slugged, slugged) || other.slugged == slugged) && (identical(other.name, name) || other.name == name) && + (identical(other.description, description) || + other.description == description) && (identical(other.type, type) || other.type == type) && (identical(other.sourceNodeSpecId, sourceNodeSpecId) || other.sourceNodeSpecId == sourceNodeSpecId) && (identical(other.targetNodeSpecId, targetNodeSpecId) || other.targetNodeSpecId == targetNodeSpecId) && const DeepCollectionEquality() - .equals(other._propSpecs, _propSpecs)); + .equals(other._jsonSpecs, _jsonSpecs)); } @JsonKey(ignore: true) @@ -238,10 +256,11 @@ class _$_EdgeSpec extends _EdgeSpec { id, slugged, name, + description, type, sourceNodeSpecId, targetNodeSpecId, - const DeepCollectionEquality().hash(_propSpecs)); + const DeepCollectionEquality().hash(_jsonSpecs)); @JsonKey(ignore: true) @override @@ -262,10 +281,11 @@ abstract class _EdgeSpec extends EdgeSpec { {final String? id, final String? slugged, required final String name, + required final String description, required final String type, required final String sourceNodeSpecId, required final String targetNodeSpecId, - required final List propSpecs}) = _$_EdgeSpec; + required final List jsonSpecs}) = _$_EdgeSpec; const _EdgeSpec._() : super._(); factory _EdgeSpec.fromJson(Map json) = _$_EdgeSpec.fromJson; @@ -277,13 +297,15 @@ abstract class _EdgeSpec extends EdgeSpec { @override String get name; @override + String get description; + @override String get type; @override String get sourceNodeSpecId; @override String get targetNodeSpecId; @override - List get propSpecs; + List get jsonSpecs; @override @JsonKey(ignore: true) _$$_EdgeSpecCopyWith<_$_EdgeSpec> get copyWith => diff --git a/packages/un_model/lib/src/ungraph/edge_spec/edge_spec.g.dart b/packages/un_model/lib/src/ungraph/edge_spec/edge_spec.g.dart index 491f3e2dd..2d7cd8baf 100644 --- a/packages/un_model/lib/src/ungraph/edge_spec/edge_spec.g.dart +++ b/packages/un_model/lib/src/ungraph/edge_spec/edge_spec.g.dart @@ -10,11 +10,12 @@ _$_EdgeSpec _$$_EdgeSpecFromJson(Map json) => _$_EdgeSpec( id: json['id'] as String?, slugged: json['slugged'] as String?, name: json['name'] as String, + description: json['description'] as String, type: json['type'] as String, sourceNodeSpecId: json['sourceNodeSpecId'] as String, targetNodeSpecId: json['targetNodeSpecId'] as String, - propSpecs: (json['propSpecs'] as List) - .map((e) => PropSpec.fromJson(e as Map)) + jsonSpecs: (json['jsonSpecs'] as List) + .map((e) => JsonSpec.fromJson(e as Map)) .toList(), ); @@ -30,9 +31,10 @@ Map _$$_EdgeSpecToJson(_$_EdgeSpec instance) { writeNotNull('id', instance.id); writeNotNull('slugged', instance.slugged); val['name'] = instance.name; + val['description'] = instance.description; val['type'] = instance.type; val['sourceNodeSpecId'] = instance.sourceNodeSpecId; val['targetNodeSpecId'] = instance.targetNodeSpecId; - val['propSpecs'] = instance.propSpecs.map((e) => e.toJson()).toList(); + val['jsonSpecs'] = instance.jsonSpecs.map((e) => e.toJson()).toList(); return val; } diff --git a/packages/un_model/lib/src/ungraph/json_spec/json_spec.dart b/packages/un_model/lib/src/ungraph/json_spec/json_spec.dart new file mode 100644 index 000000000..839e13535 --- /dev/null +++ b/packages/un_model/lib/src/ungraph/json_spec/json_spec.dart @@ -0,0 +1,21 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:slugify/slugify.dart'; + +part 'json_spec.freezed.dart'; +part 'json_spec.g.dart'; + +@freezed +class JsonSpec with _$JsonSpec { + const JsonSpec._(); + + const factory JsonSpec({ + required String name, + required String description, + required String type, + }) = _JsonSpec; + + String get slug => slugify(name, delimiter: '_'); + + factory JsonSpec.fromJson(Map json) => + _$JsonSpecFromJson(json); +} diff --git a/packages/un_model/lib/src/ungraph/prop_spec/prop_spec.freezed.dart b/packages/un_model/lib/src/ungraph/json_spec/json_spec.freezed.dart similarity index 71% rename from packages/un_model/lib/src/ungraph/prop_spec/prop_spec.freezed.dart rename to packages/un_model/lib/src/ungraph/json_spec/json_spec.freezed.dart index 6cc9593e4..07224ae6a 100644 --- a/packages/un_model/lib/src/ungraph/prop_spec/prop_spec.freezed.dart +++ b/packages/un_model/lib/src/ungraph/json_spec/json_spec.freezed.dart @@ -3,7 +3,7 @@ // ignore_for_file: type=lint // ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark -part of 'prop_spec.dart'; +part of 'json_spec.dart'; // ************************************************************************** // FreezedGenerator @@ -14,34 +14,34 @@ T _$identity(T value) => value; final _privateConstructorUsedError = UnsupportedError( 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); -PropSpec _$PropSpecFromJson(Map json) { - return _PropSpec.fromJson(json); +JsonSpec _$JsonSpecFromJson(Map json) { + return _JsonSpec.fromJson(json); } /// @nodoc -mixin _$PropSpec { +mixin _$JsonSpec { String get name => throw _privateConstructorUsedError; String get description => throw _privateConstructorUsedError; String get type => throw _privateConstructorUsedError; Map toJson() => throw _privateConstructorUsedError; @JsonKey(ignore: true) - $PropSpecCopyWith get copyWith => + $JsonSpecCopyWith get copyWith => throw _privateConstructorUsedError; } /// @nodoc -abstract class $PropSpecCopyWith<$Res> { - factory $PropSpecCopyWith(PropSpec value, $Res Function(PropSpec) then) = - _$PropSpecCopyWithImpl<$Res, PropSpec>; +abstract class $JsonSpecCopyWith<$Res> { + factory $JsonSpecCopyWith(JsonSpec value, $Res Function(JsonSpec) then) = + _$JsonSpecCopyWithImpl<$Res, JsonSpec>; @useResult $Res call({String name, String description, String type}); } /// @nodoc -class _$PropSpecCopyWithImpl<$Res, $Val extends PropSpec> - implements $PropSpecCopyWith<$Res> { - _$PropSpecCopyWithImpl(this._value, this._then); +class _$JsonSpecCopyWithImpl<$Res, $Val extends JsonSpec> + implements $JsonSpecCopyWith<$Res> { + _$JsonSpecCopyWithImpl(this._value, this._then); // ignore: unused_field final $Val _value; @@ -73,21 +73,21 @@ class _$PropSpecCopyWithImpl<$Res, $Val extends PropSpec> } /// @nodoc -abstract class _$$_PropSpecCopyWith<$Res> implements $PropSpecCopyWith<$Res> { - factory _$$_PropSpecCopyWith( - _$_PropSpec value, $Res Function(_$_PropSpec) then) = - __$$_PropSpecCopyWithImpl<$Res>; +abstract class _$$_JsonSpecCopyWith<$Res> implements $JsonSpecCopyWith<$Res> { + factory _$$_JsonSpecCopyWith( + _$_JsonSpec value, $Res Function(_$_JsonSpec) then) = + __$$_JsonSpecCopyWithImpl<$Res>; @override @useResult $Res call({String name, String description, String type}); } /// @nodoc -class __$$_PropSpecCopyWithImpl<$Res> - extends _$PropSpecCopyWithImpl<$Res, _$_PropSpec> - implements _$$_PropSpecCopyWith<$Res> { - __$$_PropSpecCopyWithImpl( - _$_PropSpec _value, $Res Function(_$_PropSpec) _then) +class __$$_JsonSpecCopyWithImpl<$Res> + extends _$JsonSpecCopyWithImpl<$Res, _$_JsonSpec> + implements _$$_JsonSpecCopyWith<$Res> { + __$$_JsonSpecCopyWithImpl( + _$_JsonSpec _value, $Res Function(_$_JsonSpec) _then) : super(_value, _then); @pragma('vm:prefer-inline') @@ -97,7 +97,7 @@ class __$$_PropSpecCopyWithImpl<$Res> Object? description = null, Object? type = null, }) { - return _then(_$_PropSpec( + return _then(_$_JsonSpec( name: null == name ? _value.name : name // ignore: cast_nullable_to_non_nullable @@ -116,12 +116,13 @@ class __$$_PropSpecCopyWithImpl<$Res> /// @nodoc @JsonSerializable() -class _$_PropSpec implements _PropSpec { - const _$_PropSpec( - {required this.name, required this.description, required this.type}); +class _$_JsonSpec extends _JsonSpec { + const _$_JsonSpec( + {required this.name, required this.description, required this.type}) + : super._(); - factory _$_PropSpec.fromJson(Map json) => - _$$_PropSpecFromJson(json); + factory _$_JsonSpec.fromJson(Map json) => + _$$_JsonSpecFromJson(json); @override final String name; @@ -132,14 +133,14 @@ class _$_PropSpec implements _PropSpec { @override String toString() { - return 'PropSpec(name: $name, description: $description, type: $type)'; + return 'JsonSpec(name: $name, description: $description, type: $type)'; } @override bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _$_PropSpec && + other is _$_JsonSpec && (identical(other.name, name) || other.name == name) && (identical(other.description, description) || other.description == description) && @@ -153,24 +154,25 @@ class _$_PropSpec implements _PropSpec { @JsonKey(ignore: true) @override @pragma('vm:prefer-inline') - _$$_PropSpecCopyWith<_$_PropSpec> get copyWith => - __$$_PropSpecCopyWithImpl<_$_PropSpec>(this, _$identity); + _$$_JsonSpecCopyWith<_$_JsonSpec> get copyWith => + __$$_JsonSpecCopyWithImpl<_$_JsonSpec>(this, _$identity); @override Map toJson() { - return _$$_PropSpecToJson( + return _$$_JsonSpecToJson( this, ); } } -abstract class _PropSpec implements PropSpec { - const factory _PropSpec( +abstract class _JsonSpec extends JsonSpec { + const factory _JsonSpec( {required final String name, required final String description, - required final String type}) = _$_PropSpec; + required final String type}) = _$_JsonSpec; + const _JsonSpec._() : super._(); - factory _PropSpec.fromJson(Map json) = _$_PropSpec.fromJson; + factory _JsonSpec.fromJson(Map json) = _$_JsonSpec.fromJson; @override String get name; @@ -180,6 +182,6 @@ abstract class _PropSpec implements PropSpec { String get type; @override @JsonKey(ignore: true) - _$$_PropSpecCopyWith<_$_PropSpec> get copyWith => + _$$_JsonSpecCopyWith<_$_JsonSpec> get copyWith => throw _privateConstructorUsedError; } diff --git a/packages/un_model/lib/src/ungraph/prop_spec/prop_spec.g.dart b/packages/un_model/lib/src/ungraph/json_spec/json_spec.g.dart similarity index 74% rename from packages/un_model/lib/src/ungraph/prop_spec/prop_spec.g.dart rename to packages/un_model/lib/src/ungraph/json_spec/json_spec.g.dart index b42d82382..446a153c5 100644 --- a/packages/un_model/lib/src/ungraph/prop_spec/prop_spec.g.dart +++ b/packages/un_model/lib/src/ungraph/json_spec/json_spec.g.dart @@ -1,18 +1,18 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -part of 'prop_spec.dart'; +part of 'json_spec.dart'; // ************************************************************************** // JsonSerializableGenerator // ************************************************************************** -_$_PropSpec _$$_PropSpecFromJson(Map json) => _$_PropSpec( +_$_JsonSpec _$$_JsonSpecFromJson(Map json) => _$_JsonSpec( name: json['name'] as String, description: json['description'] as String, type: json['type'] as String, ); -Map _$$_PropSpecToJson(_$_PropSpec instance) => +Map _$$_JsonSpecToJson(_$_JsonSpec instance) => { 'name': instance.name, 'description': instance.description, diff --git a/packages/un_model/lib/src/ungraph/node_spec/node_spec.dart b/packages/un_model/lib/src/ungraph/node_spec/node_spec.dart index 782eddcc2..29e79cfaf 100644 --- a/packages/un_model/lib/src/ungraph/node_spec/node_spec.dart +++ b/packages/un_model/lib/src/ungraph/node_spec/node_spec.dart @@ -15,7 +15,8 @@ class NodeSpec with _$NodeSpec implements INodeSpec { String? id, String? slugged, required String name, - required List propSpecs, + required String description, + required List jsonSpecs, }) = _NodeSpec; factory NodeSpec.fromJson(Map json) => diff --git a/packages/un_model/lib/src/ungraph/node_spec/node_spec.freezed.dart b/packages/un_model/lib/src/ungraph/node_spec/node_spec.freezed.dart index 017521aee..7485295a1 100644 --- a/packages/un_model/lib/src/ungraph/node_spec/node_spec.freezed.dart +++ b/packages/un_model/lib/src/ungraph/node_spec/node_spec.freezed.dart @@ -23,7 +23,8 @@ mixin _$NodeSpec { String? get id => throw _privateConstructorUsedError; String? get slugged => throw _privateConstructorUsedError; String get name => throw _privateConstructorUsedError; - List get propSpecs => throw _privateConstructorUsedError; + String get description => throw _privateConstructorUsedError; + List get jsonSpecs => throw _privateConstructorUsedError; Map toJson() => throw _privateConstructorUsedError; @JsonKey(ignore: true) @@ -37,7 +38,11 @@ abstract class $NodeSpecCopyWith<$Res> { _$NodeSpecCopyWithImpl<$Res, NodeSpec>; @useResult $Res call( - {String? id, String? slugged, String name, List propSpecs}); + {String? id, + String? slugged, + String name, + String description, + List jsonSpecs}); } /// @nodoc @@ -56,7 +61,8 @@ class _$NodeSpecCopyWithImpl<$Res, $Val extends NodeSpec> Object? id = freezed, Object? slugged = freezed, Object? name = null, - Object? propSpecs = null, + Object? description = null, + Object? jsonSpecs = null, }) { return _then(_value.copyWith( id: freezed == id @@ -71,10 +77,14 @@ class _$NodeSpecCopyWithImpl<$Res, $Val extends NodeSpec> ? _value.name : name // ignore: cast_nullable_to_non_nullable as String, - propSpecs: null == propSpecs - ? _value.propSpecs - : propSpecs // ignore: cast_nullable_to_non_nullable - as List, + description: null == description + ? _value.description + : description // ignore: cast_nullable_to_non_nullable + as String, + jsonSpecs: null == jsonSpecs + ? _value.jsonSpecs + : jsonSpecs // ignore: cast_nullable_to_non_nullable + as List, ) as $Val); } } @@ -87,7 +97,11 @@ abstract class _$$_NodeSpecCopyWith<$Res> implements $NodeSpecCopyWith<$Res> { @override @useResult $Res call( - {String? id, String? slugged, String name, List propSpecs}); + {String? id, + String? slugged, + String name, + String description, + List jsonSpecs}); } /// @nodoc @@ -104,7 +118,8 @@ class __$$_NodeSpecCopyWithImpl<$Res> Object? id = freezed, Object? slugged = freezed, Object? name = null, - Object? propSpecs = null, + Object? description = null, + Object? jsonSpecs = null, }) { return _then(_$_NodeSpec( id: freezed == id @@ -119,10 +134,14 @@ class __$$_NodeSpecCopyWithImpl<$Res> ? _value.name : name // ignore: cast_nullable_to_non_nullable as String, - propSpecs: null == propSpecs - ? _value._propSpecs - : propSpecs // ignore: cast_nullable_to_non_nullable - as List, + description: null == description + ? _value.description + : description // ignore: cast_nullable_to_non_nullable + as String, + jsonSpecs: null == jsonSpecs + ? _value._jsonSpecs + : jsonSpecs // ignore: cast_nullable_to_non_nullable + as List, )); } } @@ -134,8 +153,9 @@ class _$_NodeSpec extends _NodeSpec { {this.id, this.slugged, required this.name, - required final List propSpecs}) - : _propSpecs = propSpecs, + required this.description, + required final List jsonSpecs}) + : _jsonSpecs = jsonSpecs, super._(); factory _$_NodeSpec.fromJson(Map json) => @@ -147,17 +167,19 @@ class _$_NodeSpec extends _NodeSpec { final String? slugged; @override final String name; - final List _propSpecs; @override - List get propSpecs { - if (_propSpecs is EqualUnmodifiableListView) return _propSpecs; + final String description; + final List _jsonSpecs; + @override + List get jsonSpecs { + if (_jsonSpecs is EqualUnmodifiableListView) return _jsonSpecs; // ignore: implicit_dynamic_type - return EqualUnmodifiableListView(_propSpecs); + return EqualUnmodifiableListView(_jsonSpecs); } @override String toString() { - return 'NodeSpec(id: $id, slugged: $slugged, name: $name, propSpecs: $propSpecs)'; + return 'NodeSpec(id: $id, slugged: $slugged, name: $name, description: $description, jsonSpecs: $jsonSpecs)'; } @override @@ -168,14 +190,16 @@ class _$_NodeSpec extends _NodeSpec { (identical(other.id, id) || other.id == id) && (identical(other.slugged, slugged) || other.slugged == slugged) && (identical(other.name, name) || other.name == name) && + (identical(other.description, description) || + other.description == description) && const DeepCollectionEquality() - .equals(other._propSpecs, _propSpecs)); + .equals(other._jsonSpecs, _jsonSpecs)); } @JsonKey(ignore: true) @override - int get hashCode => Object.hash(runtimeType, id, slugged, name, - const DeepCollectionEquality().hash(_propSpecs)); + int get hashCode => Object.hash(runtimeType, id, slugged, name, description, + const DeepCollectionEquality().hash(_jsonSpecs)); @JsonKey(ignore: true) @override @@ -196,7 +220,8 @@ abstract class _NodeSpec extends NodeSpec { {final String? id, final String? slugged, required final String name, - required final List propSpecs}) = _$_NodeSpec; + required final String description, + required final List jsonSpecs}) = _$_NodeSpec; const _NodeSpec._() : super._(); factory _NodeSpec.fromJson(Map json) = _$_NodeSpec.fromJson; @@ -208,7 +233,9 @@ abstract class _NodeSpec extends NodeSpec { @override String get name; @override - List get propSpecs; + String get description; + @override + List get jsonSpecs; @override @JsonKey(ignore: true) _$$_NodeSpecCopyWith<_$_NodeSpec> get copyWith => diff --git a/packages/un_model/lib/src/ungraph/node_spec/node_spec.g.dart b/packages/un_model/lib/src/ungraph/node_spec/node_spec.g.dart index 8ef82460a..f5986a413 100644 --- a/packages/un_model/lib/src/ungraph/node_spec/node_spec.g.dart +++ b/packages/un_model/lib/src/ungraph/node_spec/node_spec.g.dart @@ -10,8 +10,9 @@ _$_NodeSpec _$$_NodeSpecFromJson(Map json) => _$_NodeSpec( id: json['id'] as String?, slugged: json['slugged'] as String?, name: json['name'] as String, - propSpecs: (json['propSpecs'] as List) - .map((e) => PropSpec.fromJson(e as Map)) + description: json['description'] as String, + jsonSpecs: (json['jsonSpecs'] as List) + .map((e) => JsonSpec.fromJson(e as Map)) .toList(), ); @@ -27,6 +28,7 @@ Map _$$_NodeSpecToJson(_$_NodeSpec instance) { writeNotNull('id', instance.id); writeNotNull('slugged', instance.slugged); val['name'] = instance.name; - val['propSpecs'] = instance.propSpecs.map((e) => e.toJson()).toList(); + val['description'] = instance.description; + val['jsonSpecs'] = instance.jsonSpecs.map((e) => e.toJson()).toList(); return val; } diff --git a/packages/un_model/lib/src/ungraph/prop_spec/prop_spec.dart b/packages/un_model/lib/src/ungraph/prop_spec/prop_spec.dart deleted file mode 100644 index de9ce9f0b..000000000 --- a/packages/un_model/lib/src/ungraph/prop_spec/prop_spec.dart +++ /dev/null @@ -1,16 +0,0 @@ -import 'package:freezed_annotation/freezed_annotation.dart'; - -part 'prop_spec.freezed.dart'; -part 'prop_spec.g.dart'; - -@freezed -class PropSpec with _$PropSpec { - const factory PropSpec({ - required String name, - required String description, - required String type, - }) = _PropSpec; - - factory PropSpec.fromJson(Map json) => - _$PropSpecFromJson(json); -} diff --git a/packages/un_model/lib/src/ungraph/ungraph.dart b/packages/un_model/lib/src/ungraph/ungraph.dart index 6d5c9b4f4..f466b7333 100644 --- a/packages/un_model/lib/src/ungraph/ungraph.dart +++ b/packages/un_model/lib/src/ungraph/ungraph.dart @@ -1,5 +1,5 @@ export 'edge/edge.dart'; export 'edge_spec/edge_spec.dart'; -export 'prop_spec/prop_spec.dart'; +export 'json_spec/json_spec.dart'; export 'node/node.dart'; export 'node_spec/node_spec.dart'; diff --git a/packages/ungraph/lib/src/edge_service/edge_service.dart b/packages/ungraph/lib/src/edge_service/edge_service.dart index f5e89579c..b85cb640c 100644 --- a/packages/ungraph/lib/src/edge_service/edge_service.dart +++ b/packages/ungraph/lib/src/edge_service/edge_service.dart @@ -3,6 +3,7 @@ import 'package:ungraph_repository/ungraph_repository.dart'; part 'iedge_service.dart'; class EdgeService extends IEdgeService { + // ignore: unused_field final EdgeRepository _repo; EdgeService(this._repo); diff --git a/packages/ungraph/lib/src/node_service/inode_service.dart b/packages/ungraph/lib/src/node_service/inode_service.dart index 433cbd43c..d96423bbc 100644 --- a/packages/ungraph/lib/src/node_service/inode_service.dart +++ b/packages/ungraph/lib/src/node_service/inode_service.dart @@ -3,6 +3,6 @@ part of 'node_service.dart'; abstract class INodeService { const INodeService(); - List get properties; + List get json; Set get edges; } diff --git a/packages/ungraph/lib/src/node_service/node_service.dart b/packages/ungraph/lib/src/node_service/node_service.dart index b707e3be0..3be1851c9 100644 --- a/packages/ungraph/lib/src/node_service/node_service.dart +++ b/packages/ungraph/lib/src/node_service/node_service.dart @@ -12,7 +12,7 @@ class NodeService extends INodeService { NodeService(this._repo, this.edges); @override - List get properties => _repo.spec.propSpecs; + List get json => _repo.spec.jsonSpecs; Future> getAll() => _repo.getAll(); diff --git a/packages/ungraph/lib/src/ungraph_service.dart b/packages/ungraph/lib/src/ungraph_service.dart index 72bf47459..846d197c2 100644 --- a/packages/ungraph/lib/src/ungraph_service.dart +++ b/packages/ungraph/lib/src/ungraph_service.dart @@ -32,6 +32,9 @@ class UngraphService implements IUngraphService { Future registerNode(NodeSpec spec) async => await _repo.registerNode(spec); + Future registerAllNodes(Iterable specs) async => + await Future.wait(specs.map(registerNode)); + Future registerEdge(EdgeSpec spec) async => await _repo.registerEdge(spec); diff --git a/packages/ungraph/test/sample_data.dart b/packages/ungraph/test/sample_data.dart index e966df7c6..ff83515d6 100644 --- a/packages/ungraph/test/sample_data.dart +++ b/packages/ungraph/test/sample_data.dart @@ -2,18 +2,20 @@ import 'package:un_model/un_model.dart'; const nsPost = NodeSpec( name: 'Facebook Posts', - propSpecs: [ - PropSpec(name: 'name', description: 'description', type: 'string') + description: '', + jsonSpecs: [ + JsonSpec(name: 'name', description: 'description', type: 'string') ], ); final esComment = EdgeSpec( name: 'Facebook Comments', + description: '', type: '', sourceNodeSpecId: nsPost.slug, targetNodeSpecId: nsPost.slug, - propSpecs: const [ - PropSpec(name: 'name', description: 'description', type: 'string') + jsonSpecs: const [ + JsonSpec(name: 'name', description: 'description', type: 'string') ], ); diff --git a/packages/ungraph_database/lib/src/dynamic/dynamic.dart b/packages/ungraph_database/lib/src/dynamic/dynamic.dart index 12f65d67f..32ce9479a 100644 --- a/packages/ungraph_database/lib/src/dynamic/dynamic.dart +++ b/packages/ungraph_database/lib/src/dynamic/dynamic.dart @@ -2,4 +2,5 @@ export 'dynamic_column.dart'; export 'dynamic_dao.dart'; export 'dynamic_data.dart'; export 'dynamic_database.dart'; +export 'dynamic_json.dart'; export 'dynamic_table.dart'; diff --git a/packages/ungraph_database/lib/src/dynamic/dynamic_data.dart b/packages/ungraph_database/lib/src/dynamic/dynamic_data.dart index fefb52002..b3eaa39db 100644 --- a/packages/ungraph_database/lib/src/dynamic/dynamic_data.dart +++ b/packages/ungraph_database/lib/src/dynamic/dynamic_data.dart @@ -1,5 +1,6 @@ +import 'dart:convert'; + import 'package:drift/drift.dart'; -import 'package:ungraph_database/ungraph_database.dart'; class DynamicData extends DataClass implements Insertable { DynamicData(this.data); @@ -7,9 +8,9 @@ class DynamicData extends DataClass implements Insertable { final Map data; @override - Map> toColumns(bool nullToAbsent) => - data.map((k, v) => MapEntry(k, Variable(v))) - ..putIfAbsent('id', () => Variable(Slugid.nice().toString())); + Map> toColumns(bool nullToAbsent) => { + 'json': Variable(jsonEncode(data)), + }; @override // TODO: implement toJson diff --git a/packages/ungraph_database/lib/src/dynamic/dynamic_json.dart b/packages/ungraph_database/lib/src/dynamic/dynamic_json.dart new file mode 100644 index 000000000..dd644a75f --- /dev/null +++ b/packages/ungraph_database/lib/src/dynamic/dynamic_json.dart @@ -0,0 +1,57 @@ +import 'package:drift/drift.dart'; +import 'package:drift/extensions/json1.dart'; + +final jsonColumn = DynamicJson._( + 'json', + '', + false, + generatedAs: null, + type: DriftSqlType.string, +); + +class DynamicJson extends GeneratedColumn { + DynamicJson._( + super.$name, + super.tableName, + super.$nullable, { + super.defaultConstraints, + super.generatedAs, + required super.type, + }); + + factory DynamicJson( + String name, + String tableName, + bool nullable, { + String? path, + bool? stored, + DriftSqlType? type, + }) => + DynamicJson._( + name, + tableName, + nullable, + generatedAs: GeneratedAs( + jsonColumn.jsonExtract(path ?? '\$.$name'), + stored ?? false, + ), + type: type ?? DriftSqlType.forType(), + ); + + static fromString( + String name, + String tableName, + bool nullable, { + String? path, + bool stored = false, + required String type, + }) => + DynamicJson( + name, + tableName, + nullable, + path: path, + stored: stored, + type: DriftSqlType.values.singleWhere((e) => e.name == type), + ); +} diff --git a/packages/ungraph_database/lib/src/table/edge_spec.dart b/packages/ungraph_database/lib/src/table/edge_spec.dart index 481214148..540535a8d 100644 --- a/packages/ungraph_database/lib/src/table/edge_spec.dart +++ b/packages/ungraph_database/lib/src/table/edge_spec.dart @@ -4,9 +4,10 @@ import 'package:ungraph_database/ungraph_database.dart'; @DataClassName('EdgeSpecData') class EdgeSpec extends Table with PrimaryUuid { TextColumn get name => text()(); + TextColumn get description => text()(); TextColumn get slug => text().unique()(); TextColumn get type => text()(); - TextColumn get propSpecs => text()(); + TextColumn get jsonSpecs => text()(); TextColumn get sourceNodeSpecId => text().references(NodeSpec, #slug)(); TextColumn get targetNodeSpecId => text().references(NodeSpec, #slug)(); } diff --git a/packages/ungraph_database/lib/src/table/node_spec.dart b/packages/ungraph_database/lib/src/table/node_spec.dart index eb00dd1ae..ce0a89df4 100644 --- a/packages/ungraph_database/lib/src/table/node_spec.dart +++ b/packages/ungraph_database/lib/src/table/node_spec.dart @@ -4,7 +4,8 @@ import 'package:ungraph_database/ungraph_database.dart'; @DataClassName('NodeSpecData') class NodeSpec extends Table with PrimaryUuid { TextColumn get name => text()(); + TextColumn get description => text()(); TextColumn get slug => text().unique()(); TextColumn get labels => text()(); - TextColumn get propSpecs => text()(); + TextColumn get jsonSpecs => text()(); } diff --git a/packages/ungraph_database/lib/src/ungraph_database.g.dart b/packages/ungraph_database/lib/src/ungraph_database.g.dart index 541b17953..0a45c303c 100644 --- a/packages/ungraph_database/lib/src/ungraph_database.g.dart +++ b/packages/ungraph_database/lib/src/ungraph_database.g.dart @@ -661,6 +661,12 @@ class $NodeSpecTable extends NodeSpec late final GeneratedColumn name = GeneratedColumn( 'name', aliasedName, false, type: DriftSqlType.string, requiredDuringInsert: true); + static const VerificationMeta _descriptionMeta = + const VerificationMeta('description'); + @override + late final GeneratedColumn description = GeneratedColumn( + 'description', aliasedName, false, + type: DriftSqlType.string, requiredDuringInsert: true); static const VerificationMeta _slugMeta = const VerificationMeta('slug'); @override late final GeneratedColumn slug = GeneratedColumn( @@ -673,14 +679,15 @@ class $NodeSpecTable extends NodeSpec late final GeneratedColumn labels = GeneratedColumn( 'labels', aliasedName, false, type: DriftSqlType.string, requiredDuringInsert: true); - static const VerificationMeta _propSpecsMeta = - const VerificationMeta('propSpecs'); + static const VerificationMeta _jsonSpecsMeta = + const VerificationMeta('jsonSpecs'); @override - late final GeneratedColumn propSpecs = GeneratedColumn( - 'prop_specs', aliasedName, false, + late final GeneratedColumn jsonSpecs = GeneratedColumn( + 'json_specs', aliasedName, false, type: DriftSqlType.string, requiredDuringInsert: true); @override - List get $columns => [id, name, slug, labels, propSpecs]; + List get $columns => + [id, name, description, slug, labels, jsonSpecs]; @override String get aliasedName => _alias ?? 'node_spec'; @override @@ -699,6 +706,14 @@ class $NodeSpecTable extends NodeSpec } else if (isInserting) { context.missing(_nameMeta); } + if (data.containsKey('description')) { + context.handle( + _descriptionMeta, + description.isAcceptableOrUnknown( + data['description']!, _descriptionMeta)); + } else if (isInserting) { + context.missing(_descriptionMeta); + } if (data.containsKey('slug')) { context.handle( _slugMeta, slug.isAcceptableOrUnknown(data['slug']!, _slugMeta)); @@ -711,11 +726,11 @@ class $NodeSpecTable extends NodeSpec } else if (isInserting) { context.missing(_labelsMeta); } - if (data.containsKey('prop_specs')) { - context.handle(_propSpecsMeta, - propSpecs.isAcceptableOrUnknown(data['prop_specs']!, _propSpecsMeta)); + if (data.containsKey('json_specs')) { + context.handle(_jsonSpecsMeta, + jsonSpecs.isAcceptableOrUnknown(data['json_specs']!, _jsonSpecsMeta)); } else if (isInserting) { - context.missing(_propSpecsMeta); + context.missing(_jsonSpecsMeta); } return context; } @@ -730,12 +745,14 @@ class $NodeSpecTable extends NodeSpec .read(DriftSqlType.string, data['${effectivePrefix}id'])!, name: attachedDatabase.typeMapping .read(DriftSqlType.string, data['${effectivePrefix}name'])!, + description: attachedDatabase.typeMapping + .read(DriftSqlType.string, data['${effectivePrefix}description'])!, slug: attachedDatabase.typeMapping .read(DriftSqlType.string, data['${effectivePrefix}slug'])!, labels: attachedDatabase.typeMapping .read(DriftSqlType.string, data['${effectivePrefix}labels'])!, - propSpecs: attachedDatabase.typeMapping - .read(DriftSqlType.string, data['${effectivePrefix}prop_specs'])!, + jsonSpecs: attachedDatabase.typeMapping + .read(DriftSqlType.string, data['${effectivePrefix}json_specs'])!, ); } @@ -748,23 +765,26 @@ class $NodeSpecTable extends NodeSpec class NodeSpecData extends DataClass implements Insertable { final String id; final String name; + final String description; final String slug; final String labels; - final String propSpecs; + final String jsonSpecs; const NodeSpecData( {required this.id, required this.name, + required this.description, required this.slug, required this.labels, - required this.propSpecs}); + required this.jsonSpecs}); @override Map toColumns(bool nullToAbsent) { final map = {}; map['id'] = Variable(id); map['name'] = Variable(name); + map['description'] = Variable(description); map['slug'] = Variable(slug); map['labels'] = Variable(labels); - map['prop_specs'] = Variable(propSpecs); + map['json_specs'] = Variable(jsonSpecs); return map; } @@ -772,9 +792,10 @@ class NodeSpecData extends DataClass implements Insertable { return NodeSpecCompanion( id: Value(id), name: Value(name), + description: Value(description), slug: Value(slug), labels: Value(labels), - propSpecs: Value(propSpecs), + jsonSpecs: Value(jsonSpecs), ); } @@ -784,9 +805,10 @@ class NodeSpecData extends DataClass implements Insertable { return NodeSpecData( id: serializer.fromJson(json['id']), name: serializer.fromJson(json['name']), + description: serializer.fromJson(json['description']), slug: serializer.fromJson(json['slug']), labels: serializer.fromJson(json['labels']), - propSpecs: serializer.fromJson(json['propSpecs']), + jsonSpecs: serializer.fromJson(json['jsonSpecs']), ); } @override @@ -795,90 +817,102 @@ class NodeSpecData extends DataClass implements Insertable { return { 'id': serializer.toJson(id), 'name': serializer.toJson(name), + 'description': serializer.toJson(description), 'slug': serializer.toJson(slug), 'labels': serializer.toJson(labels), - 'propSpecs': serializer.toJson(propSpecs), + 'jsonSpecs': serializer.toJson(jsonSpecs), }; } NodeSpecData copyWith( {String? id, String? name, + String? description, String? slug, String? labels, - String? propSpecs}) => + String? jsonSpecs}) => NodeSpecData( id: id ?? this.id, name: name ?? this.name, + description: description ?? this.description, slug: slug ?? this.slug, labels: labels ?? this.labels, - propSpecs: propSpecs ?? this.propSpecs, + jsonSpecs: jsonSpecs ?? this.jsonSpecs, ); @override String toString() { return (StringBuffer('NodeSpecData(') ..write('id: $id, ') ..write('name: $name, ') + ..write('description: $description, ') ..write('slug: $slug, ') ..write('labels: $labels, ') - ..write('propSpecs: $propSpecs') + ..write('jsonSpecs: $jsonSpecs') ..write(')')) .toString(); } @override - int get hashCode => Object.hash(id, name, slug, labels, propSpecs); + int get hashCode => + Object.hash(id, name, description, slug, labels, jsonSpecs); @override bool operator ==(Object other) => identical(this, other) || (other is NodeSpecData && other.id == this.id && other.name == this.name && + other.description == this.description && other.slug == this.slug && other.labels == this.labels && - other.propSpecs == this.propSpecs); + other.jsonSpecs == this.jsonSpecs); } class NodeSpecCompanion extends UpdateCompanion { final Value id; final Value name; + final Value description; final Value slug; final Value labels; - final Value propSpecs; + final Value jsonSpecs; final Value rowid; const NodeSpecCompanion({ this.id = const Value.absent(), this.name = const Value.absent(), + this.description = const Value.absent(), this.slug = const Value.absent(), this.labels = const Value.absent(), - this.propSpecs = const Value.absent(), + this.jsonSpecs = const Value.absent(), this.rowid = const Value.absent(), }); NodeSpecCompanion.insert({ this.id = const Value.absent(), required String name, + required String description, required String slug, required String labels, - required String propSpecs, + required String jsonSpecs, this.rowid = const Value.absent(), }) : name = Value(name), + description = Value(description), slug = Value(slug), labels = Value(labels), - propSpecs = Value(propSpecs); + jsonSpecs = Value(jsonSpecs); static Insertable custom({ Expression? id, Expression? name, + Expression? description, Expression? slug, Expression? labels, - Expression? propSpecs, + Expression? jsonSpecs, Expression? rowid, }) { return RawValuesInsertable({ if (id != null) 'id': id, if (name != null) 'name': name, + if (description != null) 'description': description, if (slug != null) 'slug': slug, if (labels != null) 'labels': labels, - if (propSpecs != null) 'prop_specs': propSpecs, + if (jsonSpecs != null) 'json_specs': jsonSpecs, if (rowid != null) 'rowid': rowid, }); } @@ -886,16 +920,18 @@ class NodeSpecCompanion extends UpdateCompanion { NodeSpecCompanion copyWith( {Value? id, Value? name, + Value? description, Value? slug, Value? labels, - Value? propSpecs, + Value? jsonSpecs, Value? rowid}) { return NodeSpecCompanion( id: id ?? this.id, name: name ?? this.name, + description: description ?? this.description, slug: slug ?? this.slug, labels: labels ?? this.labels, - propSpecs: propSpecs ?? this.propSpecs, + jsonSpecs: jsonSpecs ?? this.jsonSpecs, rowid: rowid ?? this.rowid, ); } @@ -909,14 +945,17 @@ class NodeSpecCompanion extends UpdateCompanion { if (name.present) { map['name'] = Variable(name.value); } + if (description.present) { + map['description'] = Variable(description.value); + } if (slug.present) { map['slug'] = Variable(slug.value); } if (labels.present) { map['labels'] = Variable(labels.value); } - if (propSpecs.present) { - map['prop_specs'] = Variable(propSpecs.value); + if (jsonSpecs.present) { + map['json_specs'] = Variable(jsonSpecs.value); } if (rowid.present) { map['rowid'] = Variable(rowid.value); @@ -929,9 +968,10 @@ class NodeSpecCompanion extends UpdateCompanion { return (StringBuffer('NodeSpecCompanion(') ..write('id: $id, ') ..write('name: $name, ') + ..write('description: $description, ') ..write('slug: $slug, ') ..write('labels: $labels, ') - ..write('propSpecs: $propSpecs, ') + ..write('jsonSpecs: $jsonSpecs, ') ..write('rowid: $rowid') ..write(')')) .toString(); @@ -956,6 +996,12 @@ class $EdgeSpecTable extends EdgeSpec late final GeneratedColumn name = GeneratedColumn( 'name', aliasedName, false, type: DriftSqlType.string, requiredDuringInsert: true); + static const VerificationMeta _descriptionMeta = + const VerificationMeta('description'); + @override + late final GeneratedColumn description = GeneratedColumn( + 'description', aliasedName, false, + type: DriftSqlType.string, requiredDuringInsert: true); static const VerificationMeta _slugMeta = const VerificationMeta('slug'); @override late final GeneratedColumn slug = GeneratedColumn( @@ -968,11 +1014,11 @@ class $EdgeSpecTable extends EdgeSpec late final GeneratedColumn type = GeneratedColumn( 'type', aliasedName, false, type: DriftSqlType.string, requiredDuringInsert: true); - static const VerificationMeta _propSpecsMeta = - const VerificationMeta('propSpecs'); + static const VerificationMeta _jsonSpecsMeta = + const VerificationMeta('jsonSpecs'); @override - late final GeneratedColumn propSpecs = GeneratedColumn( - 'prop_specs', aliasedName, false, + late final GeneratedColumn jsonSpecs = GeneratedColumn( + 'json_specs', aliasedName, false, type: DriftSqlType.string, requiredDuringInsert: true); static const VerificationMeta _sourceNodeSpecIdMeta = const VerificationMeta('sourceNodeSpecId'); @@ -993,8 +1039,16 @@ class $EdgeSpecTable extends EdgeSpec defaultConstraints: GeneratedColumn.constraintIsAlways('REFERENCES node_spec (slug)')); @override - List get $columns => - [id, name, slug, type, propSpecs, sourceNodeSpecId, targetNodeSpecId]; + List get $columns => [ + id, + name, + description, + slug, + type, + jsonSpecs, + sourceNodeSpecId, + targetNodeSpecId + ]; @override String get aliasedName => _alias ?? 'edge_spec'; @override @@ -1013,6 +1067,14 @@ class $EdgeSpecTable extends EdgeSpec } else if (isInserting) { context.missing(_nameMeta); } + if (data.containsKey('description')) { + context.handle( + _descriptionMeta, + description.isAcceptableOrUnknown( + data['description']!, _descriptionMeta)); + } else if (isInserting) { + context.missing(_descriptionMeta); + } if (data.containsKey('slug')) { context.handle( _slugMeta, slug.isAcceptableOrUnknown(data['slug']!, _slugMeta)); @@ -1025,11 +1087,11 @@ class $EdgeSpecTable extends EdgeSpec } else if (isInserting) { context.missing(_typeMeta); } - if (data.containsKey('prop_specs')) { - context.handle(_propSpecsMeta, - propSpecs.isAcceptableOrUnknown(data['prop_specs']!, _propSpecsMeta)); + if (data.containsKey('json_specs')) { + context.handle(_jsonSpecsMeta, + jsonSpecs.isAcceptableOrUnknown(data['json_specs']!, _jsonSpecsMeta)); } else if (isInserting) { - context.missing(_propSpecsMeta); + context.missing(_jsonSpecsMeta); } if (data.containsKey('source_node_spec_id')) { context.handle( @@ -1060,12 +1122,14 @@ class $EdgeSpecTable extends EdgeSpec .read(DriftSqlType.string, data['${effectivePrefix}id'])!, name: attachedDatabase.typeMapping .read(DriftSqlType.string, data['${effectivePrefix}name'])!, + description: attachedDatabase.typeMapping + .read(DriftSqlType.string, data['${effectivePrefix}description'])!, slug: attachedDatabase.typeMapping .read(DriftSqlType.string, data['${effectivePrefix}slug'])!, type: attachedDatabase.typeMapping .read(DriftSqlType.string, data['${effectivePrefix}type'])!, - propSpecs: attachedDatabase.typeMapping - .read(DriftSqlType.string, data['${effectivePrefix}prop_specs'])!, + jsonSpecs: attachedDatabase.typeMapping + .read(DriftSqlType.string, data['${effectivePrefix}json_specs'])!, sourceNodeSpecId: attachedDatabase.typeMapping.read( DriftSqlType.string, data['${effectivePrefix}source_node_spec_id'])!, targetNodeSpecId: attachedDatabase.typeMapping.read( @@ -1082,17 +1146,19 @@ class $EdgeSpecTable extends EdgeSpec class EdgeSpecData extends DataClass implements Insertable { final String id; final String name; + final String description; final String slug; final String type; - final String propSpecs; + final String jsonSpecs; final String sourceNodeSpecId; final String targetNodeSpecId; const EdgeSpecData( {required this.id, required this.name, + required this.description, required this.slug, required this.type, - required this.propSpecs, + required this.jsonSpecs, required this.sourceNodeSpecId, required this.targetNodeSpecId}); @override @@ -1100,9 +1166,10 @@ class EdgeSpecData extends DataClass implements Insertable { final map = {}; map['id'] = Variable(id); map['name'] = Variable(name); + map['description'] = Variable(description); map['slug'] = Variable(slug); map['type'] = Variable(type); - map['prop_specs'] = Variable(propSpecs); + map['json_specs'] = Variable(jsonSpecs); map['source_node_spec_id'] = Variable(sourceNodeSpecId); map['target_node_spec_id'] = Variable(targetNodeSpecId); return map; @@ -1112,9 +1179,10 @@ class EdgeSpecData extends DataClass implements Insertable { return EdgeSpecCompanion( id: Value(id), name: Value(name), + description: Value(description), slug: Value(slug), type: Value(type), - propSpecs: Value(propSpecs), + jsonSpecs: Value(jsonSpecs), sourceNodeSpecId: Value(sourceNodeSpecId), targetNodeSpecId: Value(targetNodeSpecId), ); @@ -1126,9 +1194,10 @@ class EdgeSpecData extends DataClass implements Insertable { return EdgeSpecData( id: serializer.fromJson(json['id']), name: serializer.fromJson(json['name']), + description: serializer.fromJson(json['description']), slug: serializer.fromJson(json['slug']), type: serializer.fromJson(json['type']), - propSpecs: serializer.fromJson(json['propSpecs']), + jsonSpecs: serializer.fromJson(json['jsonSpecs']), sourceNodeSpecId: serializer.fromJson(json['sourceNodeSpecId']), targetNodeSpecId: serializer.fromJson(json['targetNodeSpecId']), ); @@ -1139,9 +1208,10 @@ class EdgeSpecData extends DataClass implements Insertable { return { 'id': serializer.toJson(id), 'name': serializer.toJson(name), + 'description': serializer.toJson(description), 'slug': serializer.toJson(slug), 'type': serializer.toJson(type), - 'propSpecs': serializer.toJson(propSpecs), + 'jsonSpecs': serializer.toJson(jsonSpecs), 'sourceNodeSpecId': serializer.toJson(sourceNodeSpecId), 'targetNodeSpecId': serializer.toJson(targetNodeSpecId), }; @@ -1150,17 +1220,19 @@ class EdgeSpecData extends DataClass implements Insertable { EdgeSpecData copyWith( {String? id, String? name, + String? description, String? slug, String? type, - String? propSpecs, + String? jsonSpecs, String? sourceNodeSpecId, String? targetNodeSpecId}) => EdgeSpecData( id: id ?? this.id, name: name ?? this.name, + description: description ?? this.description, slug: slug ?? this.slug, type: type ?? this.type, - propSpecs: propSpecs ?? this.propSpecs, + jsonSpecs: jsonSpecs ?? this.jsonSpecs, sourceNodeSpecId: sourceNodeSpecId ?? this.sourceNodeSpecId, targetNodeSpecId: targetNodeSpecId ?? this.targetNodeSpecId, ); @@ -1169,9 +1241,10 @@ class EdgeSpecData extends DataClass implements Insertable { return (StringBuffer('EdgeSpecData(') ..write('id: $id, ') ..write('name: $name, ') + ..write('description: $description, ') ..write('slug: $slug, ') ..write('type: $type, ') - ..write('propSpecs: $propSpecs, ') + ..write('jsonSpecs: $jsonSpecs, ') ..write('sourceNodeSpecId: $sourceNodeSpecId, ') ..write('targetNodeSpecId: $targetNodeSpecId') ..write(')')) @@ -1179,17 +1252,18 @@ class EdgeSpecData extends DataClass implements Insertable { } @override - int get hashCode => Object.hash( - id, name, slug, type, propSpecs, sourceNodeSpecId, targetNodeSpecId); + int get hashCode => Object.hash(id, name, description, slug, type, jsonSpecs, + sourceNodeSpecId, targetNodeSpecId); @override bool operator ==(Object other) => identical(this, other) || (other is EdgeSpecData && other.id == this.id && other.name == this.name && + other.description == this.description && other.slug == this.slug && other.type == this.type && - other.propSpecs == this.propSpecs && + other.jsonSpecs == this.jsonSpecs && other.sourceNodeSpecId == this.sourceNodeSpecId && other.targetNodeSpecId == this.targetNodeSpecId); } @@ -1197,18 +1271,20 @@ class EdgeSpecData extends DataClass implements Insertable { class EdgeSpecCompanion extends UpdateCompanion { final Value id; final Value name; + final Value description; final Value slug; final Value type; - final Value propSpecs; + final Value jsonSpecs; final Value sourceNodeSpecId; final Value targetNodeSpecId; final Value rowid; const EdgeSpecCompanion({ this.id = const Value.absent(), this.name = const Value.absent(), + this.description = const Value.absent(), this.slug = const Value.absent(), this.type = const Value.absent(), - this.propSpecs = const Value.absent(), + this.jsonSpecs = const Value.absent(), this.sourceNodeSpecId = const Value.absent(), this.targetNodeSpecId = const Value.absent(), this.rowid = const Value.absent(), @@ -1216,24 +1292,27 @@ class EdgeSpecCompanion extends UpdateCompanion { EdgeSpecCompanion.insert({ this.id = const Value.absent(), required String name, + required String description, required String slug, required String type, - required String propSpecs, + required String jsonSpecs, required String sourceNodeSpecId, required String targetNodeSpecId, this.rowid = const Value.absent(), }) : name = Value(name), + description = Value(description), slug = Value(slug), type = Value(type), - propSpecs = Value(propSpecs), + jsonSpecs = Value(jsonSpecs), sourceNodeSpecId = Value(sourceNodeSpecId), targetNodeSpecId = Value(targetNodeSpecId); static Insertable custom({ Expression? id, Expression? name, + Expression? description, Expression? slug, Expression? type, - Expression? propSpecs, + Expression? jsonSpecs, Expression? sourceNodeSpecId, Expression? targetNodeSpecId, Expression? rowid, @@ -1241,9 +1320,10 @@ class EdgeSpecCompanion extends UpdateCompanion { return RawValuesInsertable({ if (id != null) 'id': id, if (name != null) 'name': name, + if (description != null) 'description': description, if (slug != null) 'slug': slug, if (type != null) 'type': type, - if (propSpecs != null) 'prop_specs': propSpecs, + if (jsonSpecs != null) 'json_specs': jsonSpecs, if (sourceNodeSpecId != null) 'source_node_spec_id': sourceNodeSpecId, if (targetNodeSpecId != null) 'target_node_spec_id': targetNodeSpecId, if (rowid != null) 'rowid': rowid, @@ -1253,18 +1333,20 @@ class EdgeSpecCompanion extends UpdateCompanion { EdgeSpecCompanion copyWith( {Value? id, Value? name, + Value? description, Value? slug, Value? type, - Value? propSpecs, + Value? jsonSpecs, Value? sourceNodeSpecId, Value? targetNodeSpecId, Value? rowid}) { return EdgeSpecCompanion( id: id ?? this.id, name: name ?? this.name, + description: description ?? this.description, slug: slug ?? this.slug, type: type ?? this.type, - propSpecs: propSpecs ?? this.propSpecs, + jsonSpecs: jsonSpecs ?? this.jsonSpecs, sourceNodeSpecId: sourceNodeSpecId ?? this.sourceNodeSpecId, targetNodeSpecId: targetNodeSpecId ?? this.targetNodeSpecId, rowid: rowid ?? this.rowid, @@ -1280,14 +1362,17 @@ class EdgeSpecCompanion extends UpdateCompanion { if (name.present) { map['name'] = Variable(name.value); } + if (description.present) { + map['description'] = Variable(description.value); + } if (slug.present) { map['slug'] = Variable(slug.value); } if (type.present) { map['type'] = Variable(type.value); } - if (propSpecs.present) { - map['prop_specs'] = Variable(propSpecs.value); + if (jsonSpecs.present) { + map['json_specs'] = Variable(jsonSpecs.value); } if (sourceNodeSpecId.present) { map['source_node_spec_id'] = Variable(sourceNodeSpecId.value); @@ -1306,9 +1391,10 @@ class EdgeSpecCompanion extends UpdateCompanion { return (StringBuffer('EdgeSpecCompanion(') ..write('id: $id, ') ..write('name: $name, ') + ..write('description: $description, ') ..write('slug: $slug, ') ..write('type: $type, ') - ..write('propSpecs: $propSpecs, ') + ..write('jsonSpecs: $jsonSpecs, ') ..write('sourceNodeSpecId: $sourceNodeSpecId, ') ..write('targetNodeSpecId: $targetNodeSpecId, ') ..write('rowid: $rowid') diff --git a/packages/ungraph_database/test/dynamic/dynamic_json_test.dart b/packages/ungraph_database/test/dynamic/dynamic_json_test.dart new file mode 100644 index 000000000..918ff8123 --- /dev/null +++ b/packages/ungraph_database/test/dynamic/dynamic_json_test.dart @@ -0,0 +1,71 @@ +// ignore_for_file: avoid_print + +import 'package:drift/native.dart'; +import 'package:ungraph_database/ungraph_database.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('EdgeTable', () { + late UngraphDatabase database; + + setUp(() { + database = UngraphDatabase( + NativeDatabase.memory(logStatements: true), + ); + }); + + tearDown(() async { + await database.close(); + }); + + test('ensure inital table context', () async { + expect(await database.dynamic.realTables(), isNotEmpty); + expect(await database.dynamic.tables(), isEmpty); + }); + + test('create dynamic table', () async { + expect(await database.dynamic.tables(), isEmpty); + + final dyJson = DynamicJson( + 'dynamic', + 'spec_slug', + false, + ); + + final table = EdgeTable('specId', 'spec_slug', [ + jsonColumn, + dyJson, + ]) + ..attach(database) + ..createTable(); + + final tables = await database.dynamic.tables(); + expect(tables, contains('spec_slug')); + + final data = DynamicData({ + // 'id': 'fuck', + 'dynamic': 'value', + }); + + await database.into(table).insert(data); + + final q = database.select(table)..where((_) => dyJson.equals('value')); + await q.get(); + // final result = await q.get(); + + // expect(result, [ + // EdgeData( + // 'spec_slug', + // { + // 'json': { + // 'dynamic': 'value', + // }, + // 'dynamic': 'value', + // }, + // ) + // ]); + }); + + // TODO: Test insert and get dynamic data with jsons + }); +} diff --git a/packages/ungraph_database/test/table/edge_table_test.dart b/packages/ungraph_database/test/table/edge_table_test.dart index 6be41aedd..896111dc2 100644 --- a/packages/ungraph_database/test/table/edge_table_test.dart +++ b/packages/ungraph_database/test/table/edge_table_test.dart @@ -24,24 +24,6 @@ void main() { expect(await database.dynamic.tables(), isEmpty); }); - test('create dynamic table', () async { - expect(await database.dynamic.tables(), isEmpty); - - EdgeTable('specId', 'spec_slug', [ - GeneratedColumn( - 'id', - 'spec_slug', - false, - type: DriftSqlType.int, - ), - ]) - ..attach(database) - ..createTable(); - - final tables = await database.dynamic.tables(); - expect(tables, contains('spec_slug')); - }); - test('insert and get dynamic data', () async { expect(await database.dynamic.tables(), isEmpty); @@ -74,6 +56,6 @@ void main() { final result = await database.select(testTable).get(); expect(result.first.data, data.data); - }); + }, skip: true); }); } diff --git a/packages/ungraph_repository/lib/src/mapper/edge_spec.dart b/packages/ungraph_repository/lib/src/mapper/edge_spec.dart index 38cd37265..752474a67 100644 --- a/packages/ungraph_repository/lib/src/mapper/edge_spec.dart +++ b/packages/ungraph_repository/lib/src/mapper/edge_spec.dart @@ -9,7 +9,8 @@ import 'package:ungraph_database/ungraph_database.dart' EdgeSpecData, EdgeTable, UngraphDatabase, - Value; + Value, + jsonColumn; class EdgeSpecMapper { const EdgeSpecMapper._(); @@ -19,28 +20,32 @@ class EdgeSpecMapper { id: model.id != null ? Value(model.id!) : const Value.absent(), slug: model.slug, name: model.name, + description: model.description, type: model.type, sourceNodeSpecId: model.sourceNodeSpecId, targetNodeSpecId: model.targetNodeSpecId, - propSpecs: jsonEncode(model.propSpecs), + jsonSpecs: jsonEncode(model.jsonSpecs), ); static EdgeSpec entityToModel(EdgeSpecData data) => EdgeSpec( id: data.id, slugged: data.slug, name: data.name, + description: data.description, type: data.type, sourceNodeSpecId: data.sourceNodeSpecId, targetNodeSpecId: data.targetNodeSpecId, - propSpecs: (jsonDecode(data.propSpecs) as List) - .map((_) => PropSpec.fromJson(_)) + jsonSpecs: (jsonDecode(data.jsonSpecs) as List) + .map((_) => JsonSpec.fromJson(_)) .toList(), ); static EdgeTable modelToTable(EdgeSpec model) => EdgeTable( model.id!, model.slug, - model.propSpecs.map(PropSpecMapper.modelToColumn).toList(), + model.jsonSpecs + .map((_) => JsonSpecMapper.modelToJson(model.slug, _)) + .followedBy([jsonColumn]).toList(), ); static EdgeDao modelToDao(EdgeSpec model, [UngraphDatabase? db]) => diff --git a/packages/ungraph_repository/lib/src/mapper/json_spec.dart b/packages/ungraph_repository/lib/src/mapper/json_spec.dart new file mode 100644 index 000000000..5334a5614 --- /dev/null +++ b/packages/ungraph_repository/lib/src/mapper/json_spec.dart @@ -0,0 +1,22 @@ +import 'package:ungraph_database/ungraph_database.dart'; +import 'package:un_model/un_model.dart'; + +class JsonSpecMapper { + const JsonSpecMapper._(); + + // static DynamicColumn modelToColumn(String tableName, PropSpec model) => + // DynamicColumn.fromString( + // model.name, + // 'test_table', + // false, + // type: model.type, + // ); + + static DynamicJson modelToJson(String tableName, JsonSpec model) => + DynamicJson.fromString( + model.name, + 'test_table', + false, + type: model.type, + ); +} diff --git a/packages/ungraph_repository/lib/src/mapper/mapper.dart b/packages/ungraph_repository/lib/src/mapper/mapper.dart index a81f96454..37e267ff4 100644 --- a/packages/ungraph_repository/lib/src/mapper/mapper.dart +++ b/packages/ungraph_repository/lib/src/mapper/mapper.dart @@ -2,4 +2,4 @@ export 'edge_spec.dart'; export 'edge.dart'; export 'node_spec.dart'; export 'node.dart'; -export 'prop_spec.dart'; +export 'json_spec.dart'; diff --git a/packages/ungraph_repository/lib/src/mapper/node_spec.dart b/packages/ungraph_repository/lib/src/mapper/node_spec.dart index c78237dca..50b7b282c 100644 --- a/packages/ungraph_repository/lib/src/mapper/node_spec.dart +++ b/packages/ungraph_repository/lib/src/mapper/node_spec.dart @@ -4,12 +4,13 @@ import 'package:ungraph_repository/ungraph_repository.dart'; import 'package:un_model/un_model.dart'; import 'package:ungraph_database/ungraph_database.dart' show - UngraphDatabase, NodeDao, NodeSpecCompanion, NodeSpecData, NodeTable, - Value; + UngraphDatabase, + Value, + jsonColumn; class NodeSpecMapper { const NodeSpecMapper._(); @@ -19,23 +20,27 @@ class NodeSpecMapper { id: model.id != null ? Value(model.id!) : const Value.absent(), slug: model.slug, name: model.name, + description: model.description, labels: jsonEncode(model.labels), - propSpecs: jsonEncode(model.propSpecs), + jsonSpecs: jsonEncode(model.jsonSpecs), ); static NodeSpec entityToModel(NodeSpecData data) => NodeSpec( id: data.id, slugged: data.slug, name: data.name, - propSpecs: (jsonDecode(data.propSpecs) as List) - .map((_) => PropSpec.fromJson(_)) + description: data.description, + jsonSpecs: (jsonDecode(data.jsonSpecs) as List) + .map((_) => JsonSpec.fromJson(_)) .toList(), ); static NodeTable modelToTable(NodeSpec model) => NodeTable( model.id!, model.slug, - model.propSpecs.map(PropSpecMapper.modelToColumn).toList(), + model.jsonSpecs + .map((_) => JsonSpecMapper.modelToJson(model.slug, _)) + .followedBy([jsonColumn]).toList(), ); static NodeDao modelToDao(NodeSpec model, [UngraphDatabase? db]) => diff --git a/packages/ungraph_repository/lib/src/mapper/prop_spec.dart b/packages/ungraph_repository/lib/src/mapper/prop_spec.dart deleted file mode 100644 index 0da3420fa..000000000 --- a/packages/ungraph_repository/lib/src/mapper/prop_spec.dart +++ /dev/null @@ -1,14 +0,0 @@ -import 'package:ungraph_database/ungraph_database.dart'; -import 'package:un_model/un_model.dart'; - -class PropSpecMapper { - const PropSpecMapper._(); - - static DynamicColumn modelToColumn(PropSpec model) => - DynamicColumn.fromString( - 'id', - 'test_table', - false, - type: model.type, - ); -} diff --git a/packages/ungraph_repository/test/src/unpack_repository_test.dart b/packages/ungraph_repository/test/src/unpack_repository_test.dart index 847f82031..730a190b6 100644 --- a/packages/ungraph_repository/test/src/unpack_repository_test.dart +++ b/packages/ungraph_repository/test/src/unpack_repository_test.dart @@ -30,7 +30,7 @@ void main() { // test('init nodespec', () async { // const ns = NodeSpec( // name: 'node spec', - // propSpecs: [ + // jsonSpecs: [ // PropSpec( // name: 'id', // description: 'Just an identifier', diff --git a/packages/ungraph_spec/.gitignore b/packages/ungraph_spec/.gitignore new file mode 100644 index 000000000..d61303516 --- /dev/null +++ b/packages/ungraph_spec/.gitignore @@ -0,0 +1,39 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# VSCode related +.vscode/ + +# Flutter/Dart/Pub related +**/doc/api/ +**/ios/Flutter/.last_build_id +.dart_tool/ +.flutter-plugins +.flutter-plugins-dependencies +.packages +.pub-cache/ +.pub/ +/build/ + +# Web related +lib/generated_plugin_registrant.dart + +# Symbolication related +app.*.symbols + +# Obfuscation related +app.*.map.json diff --git a/packages/ungraph_spec/README.md b/packages/ungraph_spec/README.md new file mode 100644 index 000000000..e673f2a0a --- /dev/null +++ b/packages/ungraph_spec/README.md @@ -0,0 +1,3 @@ +# unpack_provider + +Add your README.md diff --git a/packages/ungraph_spec/analysis_options.yaml b/packages/ungraph_spec/analysis_options.yaml new file mode 100644 index 000000000..e82f0cb91 --- /dev/null +++ b/packages/ungraph_spec/analysis_options.yaml @@ -0,0 +1 @@ +include: package:un_analysis/un_analysis.yaml \ No newline at end of file diff --git a/packages/ungraph_spec/lib/src/app/app.dart b/packages/ungraph_spec/lib/src/app/app.dart new file mode 100644 index 000000000..f0948ef98 --- /dev/null +++ b/packages/ungraph_spec/lib/src/app/app.dart @@ -0,0 +1,2 @@ +export 'app_node.dart'; +export 'app_edge.dart'; diff --git a/packages/ungraph_spec/lib/src/app/app_edge.dart b/packages/ungraph_spec/lib/src/app/app_edge.dart new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/packages/ungraph_spec/lib/src/app/app_edge.dart @@ -0,0 +1 @@ + diff --git a/packages/ungraph_spec/lib/src/app/app_node.dart b/packages/ungraph_spec/lib/src/app/app_node.dart new file mode 100644 index 000000000..9b0ea2d65 --- /dev/null +++ b/packages/ungraph_spec/lib/src/app/app_node.dart @@ -0,0 +1,10 @@ +import 'package:un_model/un_model.dart'; + +const appSlug = 'app'; + +const appNode = NodeSpec( + slugged: appSlug, + name: 'App', + description: 'Apps or Websites', + jsonSpecs: [], +); diff --git a/packages/ungraph_spec/lib/src/contact/contact.dart b/packages/ungraph_spec/lib/src/contact/contact.dart new file mode 100644 index 000000000..c6ce07110 --- /dev/null +++ b/packages/ungraph_spec/lib/src/contact/contact.dart @@ -0,0 +1,2 @@ +export 'contact_node.dart'; +export 'contact_edge.dart'; diff --git a/packages/ungraph_spec/lib/src/contact/contact_edge.dart b/packages/ungraph_spec/lib/src/contact/contact_edge.dart new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/packages/ungraph_spec/lib/src/contact/contact_edge.dart @@ -0,0 +1 @@ + diff --git a/packages/ungraph_spec/lib/src/contact/contact_node.dart b/packages/ungraph_spec/lib/src/contact/contact_node.dart new file mode 100644 index 000000000..bd16885d4 --- /dev/null +++ b/packages/ungraph_spec/lib/src/contact/contact_node.dart @@ -0,0 +1,16 @@ +import 'package:un_model/un_model.dart'; + +const contactSlug = 'contact'; + +const contactNode = NodeSpec( + slugged: contactSlug, + name: 'Contact', + description: 'A contact imported from an app by the user.', + jsonSpecs: [ + JsonSpec( + name: 'name', + description: 'description', + type: 'string', + ) + ], +); diff --git a/packages/ungraph_spec/lib/src/person/person.dart b/packages/ungraph_spec/lib/src/person/person.dart new file mode 100644 index 000000000..e963887a6 --- /dev/null +++ b/packages/ungraph_spec/lib/src/person/person.dart @@ -0,0 +1,2 @@ +export 'person_node.dart'; +export 'person_edge.dart'; diff --git a/packages/ungraph_spec/lib/src/person/person_edge.dart b/packages/ungraph_spec/lib/src/person/person_edge.dart new file mode 100644 index 000000000..dfbd7eb82 --- /dev/null +++ b/packages/ungraph_spec/lib/src/person/person_edge.dart @@ -0,0 +1,11 @@ +import 'package:un_model/un_model.dart'; +import 'package:ungraph_spec/ungraph_spec.dart'; + +const personUser = EdgeSpec( + name: 'Person User', + description: 'User for the person.', + type: '', + sourceNodeSpecId: personSlug, + targetNodeSpecId: userSlug, + jsonSpecs: [], +); diff --git a/packages/ungraph_spec/lib/src/person/person_node.dart b/packages/ungraph_spec/lib/src/person/person_node.dart new file mode 100644 index 000000000..e75500a5d --- /dev/null +++ b/packages/ungraph_spec/lib/src/person/person_node.dart @@ -0,0 +1,10 @@ +import 'package:un_model/un_model.dart'; + +const personSlug = 'person'; + +const personNode = NodeSpec( + slugged: personSlug, + name: 'Person', + description: 'An aggregation of user identity and contacts across apps.', + jsonSpecs: [], +); diff --git a/packages/ungraph_spec/lib/src/profile/profile.dart b/packages/ungraph_spec/lib/src/profile/profile.dart new file mode 100644 index 000000000..f81667370 --- /dev/null +++ b/packages/ungraph_spec/lib/src/profile/profile.dart @@ -0,0 +1,2 @@ +export 'profile_node.dart'; +export 'profile_edge.dart'; diff --git a/packages/ungraph_spec/lib/src/profile/profile_edge.dart b/packages/ungraph_spec/lib/src/profile/profile_edge.dart new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/packages/ungraph_spec/lib/src/profile/profile_edge.dart @@ -0,0 +1 @@ + diff --git a/packages/ungraph_spec/lib/src/profile/profile_node.dart b/packages/ungraph_spec/lib/src/profile/profile_node.dart new file mode 100644 index 000000000..11189a40f --- /dev/null +++ b/packages/ungraph_spec/lib/src/profile/profile_node.dart @@ -0,0 +1,36 @@ +import 'package:un_model/un_model.dart'; + +const profileSlug = 'profile'; + +const profileNode = NodeSpec( + slugged: profileSlug, + name: 'Profile', + description: 'Profiles or Websites', + jsonSpecs: [ + JsonSpec( + name: 'First Name', + description: 'The user\'s first name', + type: 'string', + ), + JsonSpec( + name: 'Last Name', + description: 'The user\'s last name', + type: 'string', + ), + JsonSpec( + name: 'Name', + description: 'Full name of the user.', + type: 'string', + ), + JsonSpec( + name: 'Gender', + description: 'User\'s gender', + type: 'string', + ), + JsonSpec( + name: 'Birthday', + description: 'User\'s date of birth.', + type: 'dateTime', + ), + ], +); diff --git a/packages/ungraph_spec/lib/src/ungraph_spec.dart b/packages/ungraph_spec/lib/src/ungraph_spec.dart new file mode 100644 index 000000000..21f1b2475 --- /dev/null +++ b/packages/ungraph_spec/lib/src/ungraph_spec.dart @@ -0,0 +1,5 @@ +export 'app/app.dart'; +export 'contact/contact.dart'; +export 'person/person.dart'; +export 'profile/profile.dart'; +export 'user/user.dart'; diff --git a/packages/ungraph_spec/lib/src/user/user.dart b/packages/ungraph_spec/lib/src/user/user.dart new file mode 100644 index 000000000..d9683046b --- /dev/null +++ b/packages/ungraph_spec/lib/src/user/user.dart @@ -0,0 +1,2 @@ +export 'user_node.dart'; +export 'user_edge.dart'; diff --git a/packages/ungraph_spec/lib/src/user/user_edge.dart b/packages/ungraph_spec/lib/src/user/user_edge.dart new file mode 100644 index 000000000..bb07c0ea2 --- /dev/null +++ b/packages/ungraph_spec/lib/src/user/user_edge.dart @@ -0,0 +1,25 @@ +import 'package:un_model/un_model.dart'; +import 'package:ungraph_spec/ungraph_spec.dart'; + +const userEdge = [ + userApp, + userProfile, +]; + +const userApp = EdgeSpec( + name: 'User App', + description: 'The app of the user account.', + type: '', + sourceNodeSpecId: userSlug, + targetNodeSpecId: appSlug, + jsonSpecs: [], +); + +const userProfile = EdgeSpec( + name: 'User Profile', + description: 'Profile information of the given user.', + type: '', + sourceNodeSpecId: userSlug, + targetNodeSpecId: profileSlug, + jsonSpecs: [], +); diff --git a/packages/ungraph_spec/lib/src/user/user_node.dart b/packages/ungraph_spec/lib/src/user/user_node.dart new file mode 100644 index 000000000..4f5f5642f --- /dev/null +++ b/packages/ungraph_spec/lib/src/user/user_node.dart @@ -0,0 +1,16 @@ +import 'package:un_model/un_model.dart'; + +const userSlug = 'user'; + +const userNode = NodeSpec( + slugged: userSlug, + name: 'User', + description: 'Individual account or identify across apps.', + jsonSpecs: [ + JsonSpec( + name: 'name', + description: 'description', + type: 'string', + ) + ], +); diff --git a/packages/ungraph_spec/lib/ungraph_spec.dart b/packages/ungraph_spec/lib/ungraph_spec.dart new file mode 100644 index 000000000..33fee75c9 --- /dev/null +++ b/packages/ungraph_spec/lib/ungraph_spec.dart @@ -0,0 +1,3 @@ +library ungraph_spec; + +export 'src/ungraph_spec.dart'; diff --git a/packages/ungraph_spec/pubspec.yaml b/packages/ungraph_spec/pubspec.yaml new file mode 100644 index 000000000..9d3fe60c9 --- /dev/null +++ b/packages/ungraph_spec/pubspec.yaml @@ -0,0 +1,31 @@ +name: ungraph_spec +description: Data providers for ungraph archive data service. + +publish_to: "none" +version: 1.0.0+1 + +environment: + sdk: ">=2.18.6 <3.0.0" + +dependencies: + flutter: + sdk: flutter + + un_model: + +dev_dependencies: + # Code Quality + + un_analysis: + dart_code_metrics: ^5.4.0 + dependency_validator: ^3.2.2 + + # Testing + + flutter_test: + sdk: flutter + + # bloc_test: ^9.1.0 + # mocktail: ^0.3.0 + + ungraph: diff --git a/packages/ungraph_spec/pubspec_overrides.yaml b/packages/ungraph_spec/pubspec_overrides.yaml new file mode 100644 index 000000000..a69244c5c --- /dev/null +++ b/packages/ungraph_spec/pubspec_overrides.yaml @@ -0,0 +1,20 @@ +# melos_managed_dependency_overrides: un_analysis,un_database,un_file,un_model,ungraph,ungraph_database,ungraph_repository,unpack,unpack_repository +dependency_overrides: + un_analysis: + path: ../un_analysis + un_database: + path: ../un_database + un_file: + path: ../un_file + un_model: + path: ../un_model + ungraph: + path: ../ungraph + ungraph_database: + path: ../ungraph_database + ungraph_repository: + path: ../ungraph_repository + unpack: + path: ../unpack + unpack_repository: + path: ../unpack_repository diff --git a/packages/ungraph_spec/test/sample_data.dart b/packages/ungraph_spec/test/sample_data.dart new file mode 100644 index 000000000..c6dea5d7c --- /dev/null +++ b/packages/ungraph_spec/test/sample_data.dart @@ -0,0 +1,5 @@ +// ignore_for_file: depend_on_referenced_packages + +import 'package:un_file/un_file.dart'; + +final facebookSampleData = XFile('sample_data/facebook/facebook_2301.zip'); diff --git a/packages/ungraph_spec/test/src/profile_spec_test.dart b/packages/ungraph_spec/test/src/profile_spec_test.dart new file mode 100644 index 000000000..bc844e810 --- /dev/null +++ b/packages/ungraph_spec/test/src/profile_spec_test.dart @@ -0,0 +1,47 @@ +// ignore_for_file: depend_on_referenced_packages, avoid_print, unused_local_variable + +import 'package:drift/native.dart'; +import 'package:ungraph_database/ungraph_database.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:ungraph/ungraph.dart'; +import 'package:ungraph_spec/ungraph_spec.dart'; +import 'package:ungraph_repository/ungraph_repository.dart'; + +void main() { + group('Ungraph Service', () { + late UngraphDatabase database; + late UngraphRepository repo; + late UngraphService ungraph; + + setUp(() { + database = UngraphDatabase( + NativeDatabase.memory(logStatements: true), + ); + repo = UngraphRepository(database); + ungraph = UngraphService(repository: repo); + }); + + tearDown(() async { + await ungraph.clear(); + await database.close(); + }); + + test('can be instantiated in memory', () { + expect(database, isNotNull); + expect(repo, isNotNull); + expect(ungraph, isNotNull); + }); + + test('register and init for nodes and edges', () async { + await ungraph.registerAllNodes([ + userNode, + profileNode, + ]); + await ungraph.registerEdge(userProfile); + + final u = await ungraph.node(userSlug); + final p = await ungraph.node(profileSlug); + final up = await ungraph.edge(userProfile.slug); + }); + }); +}