Skip to content

Commit b121b84

Browse files
committed
chore: package rename
1 parent d5da2d7 commit b121b84

File tree

11 files changed

+90
-125
lines changed

11 files changed

+90
-125
lines changed

.github/dependabot.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ updates:
1010
schedule:
1111
interval: "weekly"
1212
ignore:
13-
- dependency-name: "ht_*"
13+
- dependency-name: "data_client"
14+
- dependency-name: "core"

.github/workflows/main.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: ci
1+
name: main
22

33
concurrency:
44
group: ${{ github.workflow }}-${{ github.ref }}

README.md

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,65 @@
1-
# ht_data_mongodb
1+
# data_mongodb
22

33
![coverage: 95%](https://img.shields.io/badge/coverage-95-green)
44
[![style: very good analysis](https://img.shields.io/badge/style-very_good_analysis-B22C89.svg)](https://pub.dev/packages/very_good_analysis)
55
[![License: PolyForm Free Trial](https://img.shields.io/badge/License-PolyForm%20Free%20Trial-blue)](https://polyformproject.org/licenses/free-trial/1.0.0)
66

7-
A production-ready MongoDB implementation of the `HtDataClient` interface, designed to connect Dart and Flutter applications to a MongoDB backend. This package is part of the Headlines Toolkit (HT) ecosystem.
7+
A production-ready MongoDB implementation of the `DataClient` interface, designed to connect Dart and Flutter applications to a MongoDB backend. This package is part of the [**Flutter News App - Full Source Code Toolkit**](https://github.com/flutter-news-app-full-source-code).
88

99
## Description
1010

11-
`HtDataMongodb` provides a robust, concrete implementation of the `HtDataClient` interface using the `mongo_dart` package. It acts as the bridge between your application's repositories and a MongoDB database.
11+
`DataMongodb` provides a robust, concrete implementation of the `DataClient` interface using the `mongo_dart` package. It acts as the bridge between your application's repositories and a MongoDB database.
1212

13-
It translates the abstract, high-level data requests from the `HtDataClient` interface—including rich filters, multi-field sorting, and cursor-based pagination—into native, efficient MongoDB queries.
13+
It translates the abstract, high-level data requests from the `DataClient` interface—including rich filters, multi-field sorting, and cursor-based pagination—into native, efficient MongoDB queries.
1414

15-
A key feature of this implementation is its **ID management strategy**. It ensures that the application layer remains the source of truth for a document's ID by mapping the model's `id` string to the database's `_id` field. This is crucial for correctly handling both global documents (like headlines) and user-owned documents (like settings), where the document's `_id` must match the user's ID. For a deeper explanation, see the documentation within the `HtDataMongodb` class.
15+
A key feature of this implementation is its **ID management strategy**. It ensures that the application layer remains the source of truth for a document's ID by mapping the model's `id` string to the database's `_id` field. This is crucial for correctly handling both global documents (like headlines) and user-owned documents (like settings), where the document's `_id` must match the user's ID. For a deeper explanation, see the documentation within the `DataMongodb` class.
1616

1717
## Getting Started
1818

1919
This package is intended to be used as a dependency in backend services (like a Dart Frog API) or applications that connect directly to MongoDB.
2020

21-
To use this package, add `ht_data_mongodb` and its peer dependencies to your `pubspec.yaml`.
21+
To use this package, add `data_mongodb` and its peer dependencies to your `pubspec.yaml`.
2222

2323
```yaml
2424
dependencies:
25-
# ht_data_client defines the interface this package implements.
26-
ht_data_client:
25+
# data_client defines the interface this package implements.
26+
data_client:
2727
git:
28-
url: https://github.com/headlines-toolkit/ht-data-client.git
28+
url: https://github.com/flutter-news-app-full-source-code/data-client.git
2929
# ref: <specific_commit_or_tag>
30-
# ht_shared is needed for models and exceptions.
31-
ht_shared:
30+
# core is needed for models and exceptions.
31+
core:
3232
git:
33-
url: https://github.com/headlines-toolkit/ht-shared.git
33+
url: https://github.com/flutter-news-app-full-source-code/core.git
3434
# ref: <specific_commit_or_tag>
35-
ht_data_mongodb:
35+
data_mongodb:
3636
git:
37-
url: https://github.com/headlines-toolkit/ht-data-mongodb.git
37+
url: https://github.com/flutter-news-app-full-source-code/data-mongodb.git
3838
# ref: <specific_commit_or_tag>
3939
```
4040

4141
Then run `dart pub get` or `flutter pub get`.
4242

4343
## Features
4444

45-
- Implements the `HtDataClient<T>` interface from `package:ht_data_client`.
45+
- Implements the `DataClient<T>` interface from `package:data_client`.
4646
- Includes `MongoDbConnectionManager` for robust connection lifecycle management.
4747
- Translates `readAll` parameters (`filter`, `sort`, `pagination`) into native MongoDB queries.
4848
- **Handles ID Management**: Faithfully maps the application-level `id` string to the database `_id`, preserving data integrity for all document types.
4949
- **Supports Multiple Data Models**: Correctly handles both global documents (e.g., `Headline`) and user-owned documents (e.g., `UserAppSettings`) where the document `_id` serves as the foreign key to the user.
50-
- Throws standard exceptions from `package:ht_shared` for consistent error handling.
50+
- Throws standard exceptions from `package:core` for consistent error handling.
5151
- Implements `count` for efficient document counting.
5252
- Implements `aggregate` to execute powerful, server-side aggregation pipelines.
5353
- **Partial Text Search**: Translates a `q` filter parameter into a case-insensitive (`$regex`) across designated searchable fields.
5454

5555
## Usage
5656

57-
Here's a basic example of how to use `HtDataMongodb` with a simple `Product` model.
57+
Here's a basic example of how to use `DataMongodb` with a simple `Product` model.
5858

5959
```dart
60-
import 'package:ht_data_client/ht_data_client.dart';
61-
import 'package:ht_data_mongodb/ht_data_mongodb.dart';
62-
import 'package:ht_shared/ht_shared.dart';
60+
import 'package:data_client/data_client.dart';
61+
import 'package:data_mongodb/data_mongodb.dart';
62+
import 'package:core/core.dart';
6363
6464
// 1. Define your model.
6565
class Product {
@@ -89,7 +89,7 @@ void main() async {
8989
await connectionManager.init(connectionString);
9090
9191
// 4. Instantiate the client for your model.
92-
final client = HtDataMongodb<Product>(
92+
final client = DataMongodb<Product>(
9393
connectionManager: connectionManager,
9494
modelName: 'products', // The name of the MongoDB collection.
9595
fromJson: Product.fromJson,
@@ -143,7 +143,7 @@ void main() async {
143143
'Average product price: \$${aggregateResponse.data.first['averagePrice']}',
144144
);
145145
}
146-
} on HtHttpException catch (e) {
146+
} on HttpException catch (e) {
147147
print('An error occurred: ${e.message}');
148148
} finally {
149149
// 6. Always close the connection.
@@ -152,6 +152,9 @@ void main() async {
152152
}
153153
```
154154

155-
## License
156155

157-
This package is licensed under the [PolyForm Free Trial 1.0.0](/LICENSE). Please review the terms before use.
156+
## 🔑 Licensing
157+
158+
This package is source-available and licensed under the [PolyForm Free Trial 1.0.0](LICENSE). Please review the terms before use.
159+
160+
For commercial licensing options that grant the right to build and distribute unlimited applications, please visit the main [**Flutter News App - Full Source Code Toolkit**](https://github.com/flutter-news-app-full-source-code) organization.

coverage/lcov.info

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ DA:37,0
1111
LF:9
1212
LH:0
1313
end_of_record
14-
SF:lib/src/ht_data_mongodb.dart
14+
SF:lib/src/data_mongodb.dart
1515
DA:16,1
1616
DA:26,2
1717
DA:36,5

coverage_badge.svg

Lines changed: 0 additions & 20 deletions
This file was deleted.

lib/data_mongodb.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// A production-ready MongoDB implementation of the `DataClient` interface.
2+
library;
3+
4+
export 'src/data_mongodb.dart';
5+
export 'src/mongo_db_connection_manager.dart';

lib/ht_data_mongodb.dart

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 37 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
// ignore_for_file: cascade_invocations
1+
// ignore_for_file: cascade_invocations, public_member_api_docs
22

3-
import 'package:ht_data_client/ht_data_client.dart';
4-
import 'package:ht_data_mongodb/src/mongo_db_connection_manager.dart';
5-
import 'package:ht_shared/ht_shared.dart';
3+
import 'package:core/core.dart';
4+
import 'package:data_client/data_client.dart';
5+
import 'package:data_mongodb/src/mongo_db_connection_manager.dart';
66
import 'package:logging/logging.dart';
77
import 'package:mongo_dart/mongo_dart.dart';
88
import 'package:uuid/uuid.dart';
99

10-
/// {@template ht_data_mongodb}
11-
/// A MongoDB implementation of the [HtDataClient] interface.
10+
/// {@template data_mongodb}
11+
/// A MongoDB implementation of the [DataClient] interface.
1212
///
1313
/// This client interacts with a MongoDB database to perform CRUD operations,
1414
/// translating the generic data client requests into native MongoDB queries.
@@ -43,7 +43,7 @@ import 'package:uuid/uuid.dart';
4343
///
4444
/// ### The `userId` Parameter: A Critical Clarification
4545
///
46-
/// The [HtDataClient] interface, being generic, includes an optional `userId`
46+
/// The [DataClient] interface, being generic, includes an optional `userId`
4747
/// parameter on its methods (e.g., `create({required T item, String? userId})`).
4848
/// This is to support data schemas where documents might have a `userId` field.
4949
///
@@ -61,20 +61,20 @@ import 'package:uuid/uuid.dart';
6161
/// is to faithfully execute the resulting database operation (e.g., "fetch the
6262
/// document with this `_id`").
6363
/// {@endtemplate}
64-
class HtDataMongodb<T> implements HtDataClient<T> {
65-
/// {@macro ht_data_mongodb}
66-
HtDataMongodb({
64+
class DataMongodb<T> implements DataClient<T> {
65+
/// {@macro data_mongodb}
66+
DataMongodb({
6767
required MongoDbConnectionManager connectionManager,
6868
required String modelName,
6969
required FromJson<T> fromJson,
7070
required ToJson<T> toJson,
7171
this.searchableFields,
7272
Logger? logger,
73-
}) : _connectionManager = connectionManager,
74-
_modelName = modelName,
75-
_fromJson = fromJson,
76-
_toJson = toJson,
77-
_logger = logger ?? Logger('HtDataMongodb<$T>');
73+
}) : _connectionManager = connectionManager,
74+
_modelName = modelName,
75+
_fromJson = fromJson,
76+
_toJson = toJson,
77+
_logger = logger ?? Logger('DataMongodb<$T>');
7878

7979
final MongoDbConnectionManager _connectionManager;
8080
final List<String>? searchableFields;
@@ -117,7 +117,9 @@ class HtDataMongodb<T> implements HtDataClient<T> {
117117

118118
if (id == null || id.isEmpty) {
119119
// This should not happen if models are validated correctly upstream.
120-
throw const BadRequestException('Model is missing a required "id" field.');
120+
throw const BadRequestException(
121+
'Model is missing a required "id" field.',
122+
);
121123
}
122124

123125
// Ensure the ID is a valid hex string for ObjectId conversion.
@@ -174,7 +176,7 @@ class HtDataMongodb<T> implements HtDataClient<T> {
174176
processedFilter.clear();
175177
processedFilter[r'$and'] = [
176178
otherFilters,
177-
{r'$or': searchConditions}
179+
{r'$or': searchConditions},
178180
];
179181
}
180182
} else if (processedFilter.containsKey('q')) {
@@ -296,11 +298,11 @@ class HtDataMongodb<T> implements HtDataClient<T> {
296298
'Failed to create item: ${writeResult.writeError?.errmsg}',
297299
);
298300
}
299-
_logger..finer('insertOne successful for _id: ${doc['_id']}')
300-
301-
// Best Practice: After insertion, fetch the canonical document from the
302-
// database to ensure the returned data is exactly what was stored.
303-
..finer('Fetching newly created document for verification...');
301+
_logger
302+
..finer('insertOne successful for _id: ${doc['_id']}')
303+
// Best Practice: After insertion, fetch the canonical document from the
304+
// database to ensure the returned data is exactly what was stored.
305+
..finer('Fetching newly created document for verification...');
304306
final createdDoc = await _collection.findOne({'_id': doc['_id']});
305307
if (createdDoc == null) {
306308
_logger.severe(
@@ -320,7 +322,7 @@ class HtDataMongodb<T> implements HtDataClient<T> {
320322
timestamp: DateTime.now(),
321323
),
322324
);
323-
} on HtHttpException {
325+
} on HttpException {
324326
rethrow;
325327
} on Exception catch (e, s) {
326328
_logger.severe('Error during create in $_modelName', e, s);
@@ -338,9 +340,7 @@ class HtDataMongodb<T> implements HtDataClient<T> {
338340
throw BadRequestException('Invalid ID format: "$id"');
339341
}
340342

341-
final selector = <String, dynamic>{
342-
'_id': ObjectId.fromHexString(id),
343-
};
343+
final selector = <String, dynamic>{'_id': ObjectId.fromHexString(id)};
344344
_logger.finer('Using delete selector: $selector');
345345

346346
final writeResult = await _collection.deleteOne(selector);
@@ -355,7 +355,7 @@ class HtDataMongodb<T> implements HtDataClient<T> {
355355
}
356356
_logger.fine('Successfully deleted document with id: $id');
357357
// No return value on success
358-
} on HtHttpException {
358+
} on HttpException {
359359
rethrow;
360360
} on Exception catch (e, s) {
361361
_logger.severe('Error during delete in $_modelName', e, s);
@@ -377,9 +377,7 @@ class HtDataMongodb<T> implements HtDataClient<T> {
377377
throw BadRequestException('Invalid ID format: "$id"');
378378
}
379379

380-
final selector = <String, dynamic>{
381-
'_id': ObjectId.fromHexString(id),
382-
};
380+
final selector = <String, dynamic>{'_id': ObjectId.fromHexString(id)};
383381
_logger.finer('Using read selector: $selector');
384382

385383
final doc = await _collection.findOne(selector);
@@ -388,9 +386,7 @@ class HtDataMongodb<T> implements HtDataClient<T> {
388386
_logger.warning(
389387
'Read FAILED: Item with id "$id" not found in $_modelName.',
390388
);
391-
throw NotFoundException(
392-
'Item with ID "$id" not found in $_modelName.',
393-
);
389+
throw NotFoundException('Item with ID "$id" not found in $_modelName.');
394390
}
395391
_logger.fine('Successfully read document with id: $id');
396392

@@ -402,7 +398,7 @@ class HtDataMongodb<T> implements HtDataClient<T> {
402398
timestamp: DateTime.now(),
403399
),
404400
);
405-
} on HtHttpException {
401+
} on HttpException {
406402
rethrow;
407403
} on Exception catch (e, s) {
408404
_logger.severe('Error during read in $_modelName', e, s);
@@ -432,11 +428,7 @@ class HtDataMongodb<T> implements HtDataClient<T> {
432428

433429
// Fetch one extra item to determine if there are more pages.
434430
final findResult = await _collection
435-
.modernFind(
436-
filter: selector,
437-
sort: sortBuilder,
438-
limit: limit + 1,
439-
)
431+
.modernFind(filter: selector, sort: sortBuilder, limit: limit + 1)
440432
.toList();
441433

442434
final hasMore = findResult.length > limit;
@@ -466,7 +458,7 @@ class HtDataMongodb<T> implements HtDataClient<T> {
466458
timestamp: DateTime.now(),
467459
),
468460
);
469-
} on HtHttpException {
461+
} on HttpException {
470462
rethrow;
471463
} on Exception catch (e, s) {
472464
_logger.severe('Error during readAll in $_modelName', e, s);
@@ -488,9 +480,7 @@ class HtDataMongodb<T> implements HtDataClient<T> {
488480
throw BadRequestException('Invalid ID format: "$id"');
489481
}
490482

491-
final selector = <String, dynamic>{
492-
'_id': ObjectId.fromHexString(id),
493-
};
483+
final selector = <String, dynamic>{'_id': ObjectId.fromHexString(id)};
494484
_logger.finer('Using update selector: $selector');
495485

496486
// Prepare the document for update. Note that the `_id` from the item
@@ -523,7 +513,7 @@ class HtDataMongodb<T> implements HtDataClient<T> {
523513
timestamp: DateTime.now(),
524514
),
525515
);
526-
} on HtHttpException {
516+
} on HttpException {
527517
rethrow;
528518
} on Exception catch (e, s) {
529519
_logger.severe('Error during update in $_modelName', e, s);
@@ -575,8 +565,9 @@ class HtDataMongodb<T> implements HtDataClient<T> {
575565
// to a specific user-owned document) or other fields directly in the
576566
// provided pipeline by the caller.
577567

578-
final results =
579-
await _collection.aggregateToStream(finalPipeline).toList();
568+
final results = await _collection
569+
.aggregateToStream(finalPipeline)
570+
.toList();
580571

581572
return SuccessApiResponse(
582573
data: results,

lib/src/mongo_db_connection_manager.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'package:ht_shared/ht_shared.dart';
1+
import 'package:core/core.dart';
22
import 'package:mongo_dart/mongo_dart.dart';
33

44
/// Manages the connection to a MongoDB database.

0 commit comments

Comments
 (0)