Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ferry_hive_ce_store): inital commit #624

Merged
merged 4 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/ferry_hive_ce_store/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Dart
.dart_tool
.packages
pubspec.lock

# Documentation
doc/api

build/

test/__hive_data__
3 changes: 3 additions & 0 deletions packages/ferry_hive_ce_store/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.0.1

- Initial release. Copy of ferry_hive_store but with dependency to hive_ce
21 changes: 21 additions & 0 deletions packages/ferry_hive_ce_store/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2020 Sat Mandir Khalsa

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
32 changes: 32 additions & 0 deletions packages/ferry_hive_ce_store/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[![MIT License][license-badge]][license-link]
[![PRs Welcome][prs-badge]][prs-link]
[![Watch on GitHub][github-watch-badge]][github-watch-link]
[![Star on GitHub][github-star-badge]][github-star-link]
[![Watch on GitHub][github-forks-badge]][github-forks-link]
[![Discord][discord-badge]][discord-link]

[license-badge]: https://img.shields.io/github/license/gql-dart/ferry.svg?style=for-the-badge

[license-link]: https://github.com/gql-dart/ferry/blob/master/LICENSE

[prs-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=for-the-badge

[prs-link]: https://github.com/gql-dart/ferry/issues

[github-watch-badge]: https://img.shields.io/github/watchers/gql-dart/ferry.svg?style=for-the-badge&logo=github&logoColor=ffffff

[github-watch-link]: https://github.com/gql-dart/ferry/watchers

[github-star-badge]: https://img.shields.io/github/stars/gql-dart/ferry.svg?style=for-the-badge&logo=github&logoColor=ffffff

[github-star-link]: https://github.com/gql-dart/ferry/stargazers

[github-forks-badge]: https://img.shields.io/github/forks/gql-dart/ferry.svg?style=for-the-badge&logo=github&logoColor=ffffff

[github-forks-link]: https://github.com/gql-dart/ferry/network/members

[discord-badge]: https://img.shields.io/discord/559455668810153989.svg?style=for-the-badge&logo=discord&logoColor=ffffff

[discord-link]: https://discord.gg/YBFCTXNbwY

A Store implementation that uses `hive_ce` to persist data.
7 changes: 7 additions & 0 deletions packages/ferry_hive_ce_store/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
include: package:lints/recommended.yaml

analyzer:
language:
strict-raw-types: true
strict-inference: true
strict-casts: true
3 changes: 3 additions & 0 deletions packages/ferry_hive_ce_store/lib/ferry_hive_store.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export 'package:ferry_store/ferry_store.dart';

export './src/hive_store.dart';
59 changes: 59 additions & 0 deletions packages/ferry_hive_ce_store/lib/src/hive_store.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import 'dart:async';
import 'package:rxdart/rxdart.dart';
import 'package:hive_ce/hive.dart';
import 'package:ferry_store/ferry_store.dart';

class HiveStore extends Store {
final Box<dynamic> box;
final JsonEquals _jsonEquals;

HiveStore(this.box, [JsonEquals? jsonEquals])
: _jsonEquals = jsonEquals ?? jsonMapEquals;

@override
Iterable<String> get keys => List.from(box.keys);

@override
Stream<Map<String, dynamic>?> watch(String dataId, {bool distinct = true}) {
final stream = box
.watch(key: dataId)
.map<Map<String, dynamic>?>((event) =>
event.value == null ? null : Map.from(event.value as Map))
.startWith(get(dataId));

if (distinct) {
return stream.distinct(_jsonEquals);
}
return stream;
}

@override
Map<String, dynamic>? get(String dataId) {
final value = box.get(dataId);
return value == null ? null : Map.from(value as Map);
}

@override
void put(String dataId, Map<String, dynamic>? value) =>
box.put(dataId, value);

@override
void putAll(Map<String, Map<String, dynamic>?> data) => box.putAll(data);

@override
void delete(String dataId) => box.delete(dataId);

@override
void deleteAll(Iterable<String> dataIds) => box.deleteAll(dataIds);

// NOTE: we can't currently use box.clear since it isn't synchronous
// https://github.com/hivedb/hive/issues/219
@override
void clear() => box.deleteAll(keys);

@override
Future<void> dispose() => box.close();

@override
Future<void> flush() => box.flush();
}
21 changes: 21 additions & 0 deletions packages/ferry_hive_ce_store/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: ferry_hive_ce_store
version: 0.0.1
homepage: https://ferry.gql-dart.dev
description: Hive-based Store implementation for Ferry GraphQL client
repository: https://github.com/gql-dart/ferry
environment:
sdk: '>=3.0.0 <4.0.0'
topics:
- graphql
- gql
- ferry
- hive_ce
- hive
dependencies:
hive_ce: ^2.0.0
ferry_store: ^0.6.1
rxdart: ^0.28.0
collection: ^1.15.0
dev_dependencies:
test: ^1.16.8
lints: ^5.0.0
Loading