Skip to content

Commit 6edd15e

Browse files
authored
Merge pull request #39 from alxsabo/v5.2
rdbc-669
2 parents 176755b + d02d121 commit 6edd15e

File tree

53 files changed

+4886
-3033
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+4886
-3033
lines changed

src/Documents/Indexes/IndexDefinitionHelper.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use RavenDB\Exceptions\IllegalArgumentException;
66
use RavenDB\Utils\StringUtils;
77

8-
// !status: DONE
98
class IndexDefinitionHelper
109
{
1110
public static function detectStaticIndexType(string $map, ?string $reduce): IndexType
@@ -61,7 +60,6 @@ public static function detectStaticIndexSourceType(?string $map): IndexSourceTyp
6160
if (str_starts_with($map, "from")) {
6261
// detect `from ts in timeseries` or `from ts in timeseries.Users.HeartRate`
6362

64-
// @todo: following five lines of code should be tested
6563
$tokens = [];
6664
foreach (explode(' ', $mapLower) as $item) {
6765
if (StringUtils::isNotEmpty($item)) {
@@ -83,17 +81,13 @@ public static function detectStaticIndexSourceType(?string $map): IndexSourceTyp
8381
return IndexSourceType::documents();
8482
}
8583

86-
// @todo: implement and this code should be tested
8784
private static function stripComments(string $input): string
8885
{
89-
return $input;
90-
// return trim(preg_replace("(?:/\\*(?:[^*]|(?:\\*+[^*/]))*\\*+/)|(?://.*)","", $input));
86+
return trim(preg_replace('~(?:/\\*(?:[^*]|(?:\\*+[^*/]))*\\*+/)|(?://.*)~',"", $input));
9187
}
9288

93-
// @todo: implement and this code should be tested
9489
private static function unifyWhiteSpace(string $input): string
9590
{
96-
return $input;
97-
// return preg_replace("\\s+", " ", $input);
91+
return preg_replace("/\s+/", " ", $input);
9892
}
9993
}

src/Documents/Operations/TimeSeries/AbstractTimeSeriesRange.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
// !status = DONE
66
abstract class AbstractTimeSeriesRange
77
{
8-
private string $name = '';
8+
private ?string $name = '';
99

10-
public function getName(): string
10+
public function getName(): ?string
1111
{
1212
return $this->name;
1313
}
1414

15-
public function setName(string $name): void
15+
public function setName(?string $name): void
1616
{
1717
$this->name = $name;
1818
}

src/Documents/Operations/TimeSeries/AppendOperation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function setTag(?string $tag): void
4343
$this->tag = $tag;
4444
}
4545

46-
public function __construct(?DateTimeInterface $timestamp, array $values, ?string $tag = null)
46+
public function __construct(?DateTimeInterface $timestamp = null, ?array $values = null, ?string $tag = null)
4747
{
4848
$this->timestamp = $timestamp;
4949
$this->values = $values;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace RavenDB\Documents\Operations\TimeSeries;
4+
5+
class ConfigureRawTimeSeriesPolicyOperation extends ConfigureTimeSeriesPolicyOperation
6+
{
7+
public function __construct(?string $collection, ?RawTimeSeriesPolicy $config) {
8+
parent::__construct($collection, $config);
9+
}
10+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
namespace RavenDB\Documents\Operations\TimeSeries;
4+
5+
use RavenDB\Exceptions\IllegalArgumentException;
6+
use RavenDB\Http\HttpRequest;
7+
use RavenDB\Http\HttpRequestInterface;
8+
use RavenDB\Http\RaftCommandInterface;
9+
use RavenDB\Http\RavenCommand;
10+
use RavenDB\Http\ServerNode;
11+
use RavenDB\Utils\RaftIdGenerator;
12+
13+
class ConfigureTimeSeriesPolicyCommand extends RavenCommand implements RaftCommandInterface
14+
{
15+
private ?string $collection = null;
16+
private ?TimeSeriesPolicy $configuration = null;
17+
18+
public function __construct(?string $collection, ?TimeSeriesPolicy $configuration)
19+
{
20+
parent::__construct(ConfigureTimeSeriesOperationResult::class);
21+
22+
if ($configuration == null) {
23+
throw new IllegalArgumentException("Configuration cannot be null");
24+
}
25+
26+
if ($collection == null) {
27+
throw new IllegalArgumentException("Collection cannot be null");
28+
}
29+
30+
$this->collection = $collection;
31+
$this->configuration = $configuration;
32+
}
33+
34+
public function getRaftUniqueRequestId(): string
35+
{
36+
return RaftIdGenerator::newId();
37+
}
38+
39+
public function isReadRequest(): bool
40+
{
41+
return false;
42+
}
43+
44+
public function createUrl(ServerNode $serverNode): string
45+
{
46+
return $serverNode->getUrl() . "/databases/" . $serverNode->getDatabase() . "/admin/timeseries/policy?collection=" . urlEncode($this->collection);
47+
}
48+
49+
public function createRequest(ServerNode $serverNode): HttpRequestInterface
50+
{
51+
$options = [
52+
'json' => $this->getMapper()->normalize($this->configuration),
53+
'headers' => [
54+
'Content-Type' => 'application/json'
55+
]
56+
];
57+
58+
return new HttpRequest($this->createUrl($serverNode), HttpRequest::PUT, $options);
59+
}
60+
61+
public function setResponse(?string $response, bool $fromCache): void
62+
{
63+
if ($response == null) {
64+
$this->throwInvalidResponse();
65+
}
66+
67+
$this->result = $this->getMapper()->deserialize($response, $this->resultClass, 'json');
68+
}
69+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace RavenDB\Documents\Operations\TimeSeries;
4+
5+
use RavenDB\Documents\Conventions\DocumentConventions;
6+
use RavenDB\Documents\Operations\MaintenanceOperationInterface;
7+
use RavenDB\Http\RavenCommand;
8+
9+
class ConfigureTimeSeriesPolicyOperation implements MaintenanceOperationInterface
10+
{
11+
private ?string $collection = null;
12+
private ?TimeSeriesPolicy $config = null;
13+
14+
public function __construct(?string $collection, ?TimeSeriesPolicy $config)
15+
{
16+
$this->collection = $collection;
17+
$this->config = $config;
18+
}
19+
20+
public function getCommand(DocumentConventions $conventions): RavenCommand
21+
{
22+
return new ConfigureTimeSeriesPolicyCommand($this->collection, $this->config);
23+
}
24+
}

src/Documents/Operations/TimeSeries/ConfigureTimeSeriesValueNamesParameters.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ public function getValueNames(): ?StringArray
5959
return $this->valueNames;
6060
}
6161

62-
public function setValueNames(?StringArray $valueNames): void
62+
public function setValueNames(null|array|StringArray $valueNames): void
6363
{
64-
$this->valueNames = $valueNames;
64+
$this->valueNames = is_array($valueNames) ? StringArray::fromArray($valueNames) : $valueNames;
6565
}
6666

6767
public function isUpdate(): bool
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<?php
2+
3+
namespace RavenDB\Documents\Operations\TimeSeries;
4+
5+
use Closure;
6+
use RavenDB\Constants\PhpClient;
7+
use RavenDB\Exceptions\IllegalArgumentException;
8+
use RavenDB\Http\HttpRequest;
9+
use RavenDB\Http\HttpRequestInterface;
10+
use RavenDB\Http\RavenCommand;
11+
use RavenDB\Http\ServerNode;
12+
use RavenDB\Primitives\NetISO8601Utils;
13+
use RavenDB\Utils\StringBuilder;
14+
use RavenDB\Utils\StringUtils;
15+
16+
class GetMultipleTimeSeriesCommand extends RavenCommand
17+
{
18+
private ?string $docId = null;
19+
private ?TimeSeriesRangeList $ranges = null;
20+
private ?int $start = null;
21+
private ?int $pageSize = null;
22+
private ?Closure $includes = null;
23+
24+
public function __construct(?string $docId, null|TimeSeriesRangeList|array $ranges, int $start, int $pageSize, ?Closure $includes = null)
25+
{
26+
parent::__construct(TimeSeriesDetails::class);
27+
28+
if ($docId == null) {
29+
throw new IllegalArgumentException("DocId cannot be null");
30+
}
31+
32+
$this->docId = $docId;
33+
if ($ranges != null) {
34+
$this->ranges = TimeSeriesRangeList::ensure($ranges);
35+
}
36+
$this->start = $start;
37+
$this->pageSize = $pageSize;
38+
$this->includes = $includes;
39+
}
40+
41+
public function createUrl(ServerNode $serverNode): string
42+
{
43+
$pathBuilder = new StringBuilder($serverNode->getUrl());
44+
45+
$pathBuilder
46+
->append("/databases/")
47+
->append($serverNode->getDatabase())
48+
->append("/timeseries/ranges")
49+
->append("?docId=")
50+
->append(urlEncode($this->docId));
51+
52+
if ($this->start > 0) {
53+
$pathBuilder
54+
->append("&start=")
55+
->append($this->start);
56+
}
57+
58+
if ($this->pageSize < PhpClient::INT_MAX_VALUE) {
59+
$pathBuilder
60+
->append("&pageSize=")
61+
->append($this->pageSize);
62+
}
63+
64+
if (empty($this->ranges)) {
65+
throw new IllegalArgumentException("Ranges cannot be null or empty");
66+
}
67+
68+
foreach ($this->ranges as $range) {
69+
if (StringUtils::isEmpty($range->getName())) {
70+
throw new IllegalArgumentException("Missing name argument in TimeSeriesRange. Name cannot be null or empty");
71+
}
72+
73+
$pathBuilder
74+
->append("&name=")
75+
->append($range->getName() ?? "")
76+
->append("&from=")
77+
->append($range->getFrom() == null ? "" : NetISO8601Utils::format($range->getFrom(), true))
78+
->append("&to=")
79+
->append($range->getTo() == null ? "" : NetISO8601Utils::format($range->getTo(), true));
80+
}
81+
82+
if ($this->includes != null) {
83+
$pathBuilder->append(GetTimeSeriesCommand::addIncludesToRequest($this->includes));
84+
}
85+
86+
return $pathBuilder->__toString();
87+
}
88+
89+
public function createRequest(ServerNode $serverNode): HttpRequestInterface
90+
{
91+
return new HttpRequest($this->createUrl($serverNode), HttpRequest::GET);
92+
}
93+
94+
public function setResponse(?string $response, bool $fromCache): void
95+
{
96+
if ($response == null) {
97+
return;
98+
}
99+
100+
$this->result = $this->getMapper()->deserialize($response, $this->resultClass, 'json');
101+
}
102+
103+
public function isReadRequest(): bool
104+
{
105+
return true;
106+
}
107+
108+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace RavenDB\Documents\Operations\TimeSeries;
4+
5+
use Closure;
6+
use RavenDB\Constants\PhpClient;
7+
use RavenDB\Documents\Conventions\DocumentConventions;
8+
use RavenDB\Documents\DocumentStoreInterface;
9+
use RavenDB\Documents\Operations\OperationInterface;
10+
use RavenDB\Exceptions\IllegalArgumentException;
11+
use RavenDB\Http\HttpCache;
12+
use RavenDB\Http\RavenCommand;
13+
use RavenDB\Utils\StringUtils;
14+
15+
class GetMultipleTimeSeriesOperation implements OperationInterface
16+
{
17+
private ?string $docId = null;
18+
private ?TimeSeriesRangeList $ranges = null;
19+
private ?int $start = null;
20+
private ?int $pageSize = null;
21+
private ?Closure $includes = null;
22+
23+
public function __construct(?string $docId, null|TimeSeriesRangeList|array $ranges, int $start = 0, int $pageSize = PhpClient::INT_MAX_VALUE, ?Closure $includes = null)
24+
{
25+
if (empty($ranges)) {
26+
throw new IllegalArgumentException("Ranges cannot be null");
27+
}
28+
29+
if (is_array($ranges)) {
30+
$ranges = TimeSeriesRangeList::fromArray($ranges);
31+
}
32+
33+
$this->init($docId, $start, $pageSize, $includes);
34+
35+
$this->ranges = $ranges;
36+
}
37+
38+
private function init(?string $docId, int $start, int $pageSize, ?Closure $includes): void
39+
{
40+
if (StringUtils::isEmpty($docId)) {
41+
throw new IllegalArgumentException("DocId cannot be null or empty");
42+
}
43+
44+
$this->docId = $docId;
45+
$this->start = $start;
46+
$this->pageSize = $pageSize;
47+
$this->includes = $includes;
48+
}
49+
50+
public function getCommand(?DocumentStoreInterface $store, ?DocumentConventions $conventions, ?HttpCache $cache, bool $returnDebugInformation = false, bool $test = false): RavenCommand
51+
{
52+
return new GetMultipleTimeSeriesCommand($this->docId, $this->ranges, $this->start, $this->pageSize, $this->includes);
53+
}
54+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace RavenDB\Documents\Operations\TimeSeries;
4+
5+
use RavenDB\Http\HttpRequest;
6+
use RavenDB\Http\HttpRequestInterface;
7+
use RavenDB\Http\RaftCommandInterface;
8+
use RavenDB\Http\RavenCommand;
9+
use RavenDB\Http\ServerNode;
10+
use RavenDB\Utils\RaftIdGenerator;
11+
12+
class RemoveTimeSeriesPolicyCommand extends RavenCommand implements RaftCommandInterface
13+
{
14+
private ?string $collection = null;
15+
private ?string $name = null;
16+
17+
public function __construct(?string $collection, ?string $name)
18+
{
19+
parent::__construct(ConfigureTimeSeriesOperationResult::class);
20+
21+
$this->collection = $collection;
22+
$this->name = $name;
23+
}
24+
public function getRaftUniqueRequestId(): string
25+
{
26+
return RaftIdGenerator::newId();
27+
}
28+
29+
public function isReadRequest(): bool
30+
{
31+
return false;
32+
}
33+
34+
public function createUrl(ServerNode $serverNode): string
35+
{
36+
return $serverNode->getUrl() . "/databases/" . $serverNode->getDatabase()
37+
. "/admin/timeseries/policy?collection=" . urlEncode($this->collection) . "&name=" . urlEncode($this->name);
38+
}
39+
40+
public function createRequest(ServerNode $serverNode): HttpRequestInterface
41+
{
42+
return new HttpRequest($this->createUrl($serverNode), HttpRequest::DELETE);
43+
}
44+
45+
public function setResponse(?string $response, bool $fromCache): void
46+
{
47+
if ($response == null) {
48+
$this->throwInvalidResponse();
49+
}
50+
51+
$this->result = $this->getMapper()->deserialize($response,$this->resultClass, 'json');
52+
}
53+
}

0 commit comments

Comments
 (0)