Update to beta2 of doc lib

This commit is contained in:
Daniel J. Summers 2024-06-25 15:55:14 -04:00
parent 5beeee4819
commit 61127676a2
5 changed files with 32 additions and 93 deletions

View File

@ -6,7 +6,6 @@
"ext-pdo": "*",
"ext-sqlite3": "*",
"bit-badger/pdo-document": "^1",
"visus/cuid2": "^4",
"guzzlehttp/guzzle": "^7.8",
"guzzlehttp/psr7": "^2.6",
"http-interop/http-factory-guzzle": "^1.2",

72
src/composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "d19a824cbca9da75d5b5dafbc9fa1367",
"content-hash": "d03cca0e9df6892b1154d46aa43ddfe9",
"packages": [
{
"name": "auth0/auth0-php",
@ -107,16 +107,17 @@
},
{
"name": "bit-badger/pdo-document",
"version": "v1.0.0-beta1",
"version": "v1.0.0-beta2",
"source": {
"type": "git",
"url": "https://git.bitbadger.solutions/bit-badger/pdo-document",
"reference": "124426fa12069aa93e75f7e2946eb2c5ff83a591"
"reference": "50854275a8b39074966cf00370f30b3e68edc6e7"
},
"require": {
"ext-pdo": "*",
"netresearch/jsonmapper": "^4",
"php": ">=8.2"
"php": ">=8.2",
"phpoption/phpoption": "^1.9"
},
"require-dev": {
"phpunit/phpunit": "^11"
@ -141,11 +142,12 @@
"role": "Developer"
}
],
"description": "Treat SQLite (and soon PostgreSQL) as a document store",
"description": "Treat SQLite and PostgreSQL as document stores",
"keywords": [
"database",
"document",
"pdo",
"postgresql",
"sqlite"
],
"support": {
@ -153,7 +155,7 @@
"rss": "https://git.bitbadger.solutions/bit-badger/pdo-document.rss",
"source": "https://git.bitbadger.solutions/bit-badger/pdo-document"
},
"time": "2024-06-21T13:46:41+00:00"
"time": "2024-06-25T14:42:26+00:00"
},
{
"name": "composer/semver",
@ -2244,64 +2246,6 @@
],
"time": "2024-05-31T15:07:36+00:00"
},
{
"name": "visus/cuid2",
"version": "4.1.0",
"source": {
"type": "git",
"url": "https://github.com/visus-io/php-cuid2.git",
"reference": "17c9b3098d556bb2556a084c948211333cc19c79"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/visus-io/php-cuid2/zipball/17c9b3098d556bb2556a084c948211333cc19c79",
"reference": "17c9b3098d556bb2556a084c948211333cc19c79",
"shasum": ""
},
"require": {
"php": "^8.1"
},
"require-dev": {
"ergebnis/composer-normalize": "^2.29",
"ext-ctype": "*",
"phpstan/phpstan": "^1.9",
"phpunit/phpunit": "^10.0",
"squizlabs/php_codesniffer": "^3.7",
"vimeo/psalm": "^5.4"
},
"suggest": {
"ext-gmp": "*"
},
"type": "library",
"autoload": {
"files": [
"src/compat.php"
],
"psr-4": {
"Visus\\Cuid2\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Alan Brault",
"email": "alan.brault@visus.io"
}
],
"description": "A PHP library for generating collision-resistant ids (CUIDs).",
"keywords": [
"cuid",
"identifier"
],
"support": {
"issues": "https://github.com/visus-io/php-cuid2/issues",
"source": "https://github.com/visus-io/php-cuid2/tree/4.1.0"
},
"time": "2024-05-14T13:23:35+00:00"
},
{
"name": "vlucas/phpdotenv",
"version": "v5.6.0",

View File

@ -1,6 +1,6 @@
<?php declare(strict_types=1);
use BitBadger\PDODocument\{Configuration, Custom, Definition, Document, Mode};
use BitBadger\PDODocument\{AutoId, Configuration, Custom, Definition, Document, Mode};
use BitBadger\PDODocument\Mapper\ArrayMapper;
use MyPrayerJournal\Domain\{History, Note, Recurrence, RecurrencePeriod, Request, RequestAction};
use MyPrayerJournal\Table;
@ -16,8 +16,10 @@ $reqs = Custom::array('SELECT data FROM mpj.request', [], new ArrayMapper());
echo 'Found ' . sizeof($reqs) . ' requests; migrating to v4...' . PHP_EOL;
Configuration::resetPDO();
Configuration::$mode = Mode::SQLite;
Configuration::$pdoDSN = 'sqlite:./data/mpj.db';
Configuration::$mode = Mode::SQLite;
Configuration::$pdoDSN = 'sqlite:./data/mpj.db';
Configuration::$autoId = AutoId::RandomString;
Configuration::$idStringLength = 12;
Definition::ensureTable(Table::REQUEST);
@ -28,30 +30,27 @@ function convertDate(string $date): string
}
foreach ($reqs as $reqJson) {
$req = json_decode($reqJson['data']);
$notes = array_map(fn(stdClass $note) => new Note(convertDate($note->asOf), $note->notes), $req->notes ?? []);
$history = array_map(fn(stdClass $hist) =>
new History(
asOf: convertDate($hist->asOf),
action: RequestAction::from($hist->status),
text: property_exists($hist, 'text') ? $hist->text : null),
$req->history);
$req = json_decode($reqJson['data']);
$recurParts = explode(' ', $req->recurrence);
$recurPeriod = RecurrencePeriod::from(end($recurParts));
$recur = match ($recurPeriod) {
RecurrencePeriod::Immediate => new Recurrence(RecurrencePeriod::Immediate),
default => new Recurrence($recurPeriod, (int)$recurParts[0])
};
$v4Req = new Request(
id: $req->id,
Document::insert(Table::REQUEST, new Request(
enteredOn: convertDate($req->enteredOn),
userId: $req->userId,
snoozedUntil: property_exists($req, 'snoozedUntil') ? convertDate($req->snoozedUntil) : null,
showAfter: property_exists($req, 'showAfter') ? convertDate($req->showAfter) : null,
recurrence: $recur,
history: $history,
notes: $notes);
Document::insert(Table::REQUEST, $v4Req);
history: array_map(fn(stdClass $hist) =>
new History(
asOf: convertDate($hist->asOf),
action: RequestAction::from($hist->status),
text: property_exists($hist, 'text') ? $hist->text : null),
$req->history),
notes: array_map(fn(stdClass $note) =>
new Note(convertDate($note->asOf), $note->notes), $req->notes ?? [])));
}
echo PHP_EOL . 'done' . PHP_EOL;

View File

@ -8,8 +8,7 @@ use DateTimeImmutable;
use Exception;
use JsonSerializable;
use MyPrayerJournal\Table;
use PhpOption\{None, Option, Some};
use Visus\Cuid2\Cuid2;
use PhpOption\{None, Option};
/**
* A prayer request
@ -30,12 +29,7 @@ class Request implements JsonSerializable
public function __construct(public string $id = '', public string $enteredOn = '', public string $userId = '',
public ?string $snoozedUntil = null, public ?string $showAfter = null,
public Recurrence $recurrence = new Recurrence(RecurrencePeriod::Immediate),
public array $history = [], public array $notes = [])
{
if ($id == '') {
$this->id = (new Cuid2())->toString();
}
}
public array $history = [], public array $notes = []) { }
/**
* Get the current text for this request
@ -118,7 +112,7 @@ class Request implements JsonSerializable
public static function byId(string $id): Option
{
$req = Find::byId(Table::REQUEST, $id, self::class);
return ($req && $req->userId == $_SESSION['user_id']) ? Some::create($req) : None::create();
return ($req->getOrElse(new Request('x'))->userId == $_SESSION['user_id']) ? $req : None::create();
}
/**

View File

@ -1,7 +1,7 @@
<?php declare(strict_types=1);
use Auth0\SDK\Exception\ConfigurationException;
use BitBadger\PDODocument\{Configuration, Definition, DocumentException, Mode};
use BitBadger\PDODocument\{AutoId, Configuration, Definition, DocumentException, Mode};
use Dotenv\Dotenv;
use MyPrayerJournal\{Auth, Table};
use MyPrayerJournal\Domain\Request;
@ -24,8 +24,11 @@ if (php_sapi_name() != 'cli') {
$_REQUEST['time_zone'] = $_SERVER['HTTP_X_TIME_ZONE'] ?? 'Etc/UTC';
}
Configuration::$pdoDSN = 'sqlite:' . implode(DIRECTORY_SEPARATOR, [__DIR__, 'data', 'mpj.db']);
Configuration::$mode = Mode::SQLite;
Configuration::$pdoDSN = 'sqlite:' . implode(DIRECTORY_SEPARATOR, [__DIR__, 'data', 'mpj.db']);
Configuration::$mode = Mode::SQLite;
Configuration::$autoId = AutoId::RandomString;
Configuration::$idStringLength = 12;
Definition::ensureTable(Table::REQUEST);
Definition::ensureFieldIndex(Table::REQUEST, 'user', ['userId']);