Skip to content

Commit 8c45d4c

Browse files
committed
ref(store): SurrealDB
1 parent 4f83f33 commit 8c45d4c

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

src/store/src/Bridge/SurrealDb/Store.php

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ public function query(Vector $vector, array $options = []): array
7575

7676
public function drop(): void
7777
{
78+
$this->authenticate();
79+
7880
$this->request('DELETE', \sprintf('key/%s', $this->table), []);
7981
}
8082

@@ -87,25 +89,32 @@ private function request(string $method, string $endpoint, array|string $payload
8789
{
8890
$url = \sprintf('%s/%s', $this->endpointUrl, $endpoint);
8991

90-
$finalPayload = [
91-
'json' => $payload,
92-
];
92+
$finalPayload = [];
93+
94+
if (\is_array($payload) && [] !== $payload) {
95+
$finalPayload = [
96+
'body' => $payload,
97+
];
98+
}
9399

94100
if (\is_string($payload)) {
95101
$finalPayload = [
96102
'body' => $payload,
97103
];
98104
}
99105

100-
$response = $this->httpClient->request($method, $url, array_merge($finalPayload, [
101-
'headers' => [
102-
'Accept' => 'application/json',
103-
'Content-Type' => 'application/json',
104-
'Surreal-NS' => $this->namespace,
105-
'Surreal-DB' => $this->database,
106-
'Authorization' => \sprintf('Bearer %s', $this->authenticationToken),
106+
$response = $this->httpClient->request($method, $url, [
107+
...$finalPayload,
108+
...[
109+
'headers' => [
110+
'Accept' => 'application/json',
111+
'Content-Type' => 'application/json',
112+
'Surreal-NS' => $this->namespace,
113+
'Surreal-DB' => $this->database,
114+
'Authorization' => \sprintf('Bearer %s', $this->authenticationToken),
115+
],
107116
],
108-
]));
117+
]);
109118

110119
return $response->toArray();
111120
}

src/store/tests/Bridge/SurrealDb/StoreTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,13 @@ public function testStoreCanSetupOnValidAuthenticationAndIndexResponse()
9797
public function testStoreCannotDropOnInvalidResponse()
9898
{
9999
$httpClient = new MockHttpClient([
100+
new JsonMockResponse([
101+
'code' => 200,
102+
'details' => 'Authentication succeeded.',
103+
'token' => 'bar',
104+
], [
105+
'http_code' => 200,
106+
]),
100107
new JsonMockResponse([], [
101108
'http_code' => 400,
102109
]),
@@ -129,6 +136,13 @@ public function testStoreCanDrop()
129136
], [
130137
'http_code' => 200,
131138
]),
139+
new JsonMockResponse([
140+
'code' => 200,
141+
'details' => 'Authentication succeeded.',
142+
'token' => 'bar',
143+
], [
144+
'http_code' => 200,
145+
]),
132146
new JsonMockResponse([], [
133147
'http_code' => 200,
134148
]),

0 commit comments

Comments
 (0)