From e12b15f8c874c585ef90b6ff001dab8138b23d87 Mon Sep 17 00:00:00 2001 From: Patrick Stewart Date: Sun, 22 Sep 2024 18:45:52 -0700 Subject: [PATCH] add(angel3): adding re-branded angel3 model package --- packages/model/.gitignore | 71 ++++++++++++++++++++++++ packages/model/AUTHORS.md | 12 ++++ packages/model/CHANGELOG.md | 77 ++++++++++++++++++++++++++ packages/model/LICENSE | 29 ++++++++++ packages/model/README.md | 19 +++++++ packages/model/analysis_options.yaml | 2 + packages/model/example/main.dart | 19 +++++++ packages/model/lib/platform_model.dart | 35 ++++++++++++ packages/model/pubspec.yaml | 9 +++ 9 files changed, 273 insertions(+) create mode 100644 packages/model/.gitignore create mode 100644 packages/model/AUTHORS.md create mode 100644 packages/model/CHANGELOG.md create mode 100644 packages/model/LICENSE create mode 100644 packages/model/README.md create mode 100644 packages/model/analysis_options.yaml create mode 100644 packages/model/example/main.dart create mode 100644 packages/model/lib/platform_model.dart create mode 100644 packages/model/pubspec.yaml diff --git a/packages/model/.gitignore b/packages/model/.gitignore new file mode 100644 index 0000000..24d6831 --- /dev/null +++ b/packages/model/.gitignore @@ -0,0 +1,71 @@ +# See https://www.dartlang.org/tools/private-files.html + +# Files and directories created by pub +.dart_tool +.packages +.pub/ +build/ + +# If you're building an application, you may want to check-in your pubspec.lock +pubspec.lock + +# Directory created by dartdoc +# If you don't generate documentation locally you can remove this line. +doc/api/ + +### Dart template +# See https://www.dartlang.org/tools/private-files.html + +# Files and directories created by pub + +# SDK 1.20 and later (no longer creates packages directories) + +# Older SDK versions +# (Include if the minimum SDK version specified in pubsepc.yaml is earlier than 1.20) +.project +.buildlog +**/packages/ + + +# Files created by dart2js +# (Most Dart developers will use pub build to compile Dart, use/modify these +# rules if you intend to use dart2js directly +# Convention is to use extension '.dart.js' for Dart compiled to Javascript to +# differentiate from explicit Javascript files) +*.dart.js +*.part.js +*.js.deps +*.js.map +*.info.json + +# Directory created by dartdoc + +# Don't commit pubspec lock file +# (Library packages only! Remove pattern if developing an application package) +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff: + +## VsCode +.vscode/ + +## File-based project format: +*.iws + +## Plugin-specific files: + +# IntelliJ +.idea/ +/out/ +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties diff --git a/packages/model/AUTHORS.md b/packages/model/AUTHORS.md new file mode 100644 index 0000000..ac95ab5 --- /dev/null +++ b/packages/model/AUTHORS.md @@ -0,0 +1,12 @@ +Primary Authors +=============== + +* __[Thomas Hii](dukefirehawk.apps@gmail.com)__ + + Thomas is the current maintainer of the code base. He has refactored and migrated the + code base to support NNBD. + +* __[Tobe O](thosakwe@gmail.com)__ + + Tobe has written much of the original code prior to NNBD migration. He has moved on and + is no longer involved with the project. diff --git a/packages/model/CHANGELOG.md b/packages/model/CHANGELOG.md new file mode 100644 index 0000000..86374d8 --- /dev/null +++ b/packages/model/CHANGELOG.md @@ -0,0 +1,77 @@ +# Change Log + +## 8.1.1 + +* Updated repository link + +## 8.1.0 + +* Updated `lints` to 3.0.0 +* Fixed analyser warnings + +## 8.0.0 + +* Require Dart >= 3.0 + +## 7.1.0 + +* Return -1 instead of throwing exception when id is null +* Added `idAsString` to return id or "" if null +* Added `AuditableModel` + +## 7.0.0 + +* Require Dart >= 2.17 + +## 6.0.0 + +* Require Dart >= 2.16 + +## 5.0.0 + +* Skipped release + +## 4.0.0 + +* Skipped release + +## 3.1.1 + +* Removed `error` + +## 3.1.0 + +* Updated linter to `package:lints` + +## 3.0.2 + +* Updated README +* Updated `idAsInt` to return `-1` instead of `null` for invalid id + +## 3.0.1 + +* Updated README + +## 3.0.0 + +* Migrated to support Dart >= 2.12 NNBD + +## 2.0.0 + +* Migrated to work with Dart >= 2.12 Non NNBD + +## 1.0.3 + +* `idAsInt` returns `null` when `id` is `null`. + +## 1.0.2 + +* `idAsInt` now uses `int.tryParse`. + +## 1.0.1 + +* Add `idAsInt`. + +## 1.0.0+1 + +* Update constraint to work with Dart 2. diff --git a/packages/model/LICENSE b/packages/model/LICENSE new file mode 100644 index 0000000..df5e063 --- /dev/null +++ b/packages/model/LICENSE @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2021, dukefirehawk.com +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/packages/model/README.md b/packages/model/README.md new file mode 100644 index 0000000..3315f1a --- /dev/null +++ b/packages/model/README.md @@ -0,0 +1,19 @@ +# Angel3 Data Model + +![Pub Version (including pre-releases)](https://img.shields.io/pub/v/angel3_model?include_prereleases) +[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety) +[![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion) +[![License](https://img.shields.io/github/license/dart-backend/angel)](https://github.com/dart-backend/angel/tree/master/packages/model/LICENSE) + +The basic data models for Angel3 framework. + +```dart +import 'package:angel3_model/angel3_model.dart'; +``` + +The available data models are: + +* `Model` class + * A basic data model +* `AuditableModel` class + * A basic data model with audit log feature diff --git a/packages/model/analysis_options.yaml b/packages/model/analysis_options.yaml new file mode 100644 index 0000000..4a50340 --- /dev/null +++ b/packages/model/analysis_options.yaml @@ -0,0 +1,2 @@ + +include: package:lints/recommended.yaml \ No newline at end of file diff --git a/packages/model/example/main.dart b/packages/model/example/main.dart new file mode 100644 index 0000000..fec85b1 --- /dev/null +++ b/packages/model/example/main.dart @@ -0,0 +1,19 @@ +import 'package:platform_model/platform_model.dart'; + +void main() { + var todo = Todo(id: '34', isComplete: false); + print(todo.idAsInt == 34); +} + +class Todo extends Model { + String? text; + + bool isComplete; + + Todo( + {required String super.id, + this.text, + this.isComplete = false, + super.createdAt, + super.updatedAt}); +} diff --git a/packages/model/lib/platform_model.dart b/packages/model/lib/platform_model.dart new file mode 100644 index 0000000..0ee8fab --- /dev/null +++ b/packages/model/lib/platform_model.dart @@ -0,0 +1,35 @@ +/// Represents a generic data model with an ID and timestamps. +class Model { + /// A unique identifier corresponding to this item. + String? id; + + /// The time at which this item was created. + DateTime? createdAt; + + /// The last time at which this item was updated. + DateTime? updatedAt; + + Model({this.id, this.createdAt, this.updatedAt}); + + /// Returns the [id], parsed as an [int]. + int get idAsInt => id != null ? int.tryParse(id ?? "-1") ?? -1 : -1; + + /// Returns the [id] or "" if null. + String get idAsString => id ?? ""; +} + +/// Represents a generic data model with audit log feature. +class AuditableModel extends Model { + /// The authorized user who created the record. + String? createdBy; + + /// The user who updated the record last time. + String? updatedBy; + + AuditableModel( + {super.id, + super.createdAt, + this.createdBy, + super.updatedAt, + this.updatedBy}); +} diff --git a/packages/model/pubspec.yaml b/packages/model/pubspec.yaml new file mode 100644 index 0000000..d1f4ebc --- /dev/null +++ b/packages/model/pubspec.yaml @@ -0,0 +1,9 @@ +name: platform_model +version: 9.0.0 +description: Angel3 basic data model class, no longer with the added weight of the whole framework. +homepage: https://angel3-framework.web.app/ +repository: https://github.com/dart-backend/angel/tree/master/packages/model +environment: + sdk: '>=3.3.0 <4.0.0' +dev_dependencies: + lints: ^4.0.0