Skip to content

Commit 2dae09d

Browse files
committed
page size handling
1 parent ecdd157 commit 2dae09d

File tree

7 files changed

+340
-9
lines changed

7 files changed

+340
-9
lines changed

src/SDK/Requests/Actions/BlockChildren.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function resolveEndpoint(): string
1919

2020
public function __construct(
2121
protected string $id,
22-
protected ?string $pageSize = null,
22+
protected ?int $pageSize = null,
2323
) {}
2424

2525
public function defaultQuery(): array

src/SDK/Requests/Actions/QueryDataSource.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,17 @@ public function resolveEndpoint(): string
2020
public function __construct(
2121
protected string $dataSourceId,
2222
protected ?array $filter = null,
23+
protected ?int $pageSize = null,
2324
) {}
2425

26+
protected function defaultBody(): array
27+
{
28+
return array_filter([
29+
'filter' => $this->filter,
30+
'page_size' => $this->pageSize,
31+
]);
32+
}
33+
2534
// Potentially it can have a filter object in the body
2635
// @todo create separate request with filter, use this to fetch all items
2736
}

src/SDK/Resource/Actions.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function getPage(string $id): Response
1818
return $this->connector->send(new Page($id));
1919
}
2020

21-
public function getBlockChildren(string $id, ?string $pageSize): Response
21+
public function getBlockChildren(string $id, ?int $pageSize = null): Response
2222
{
2323
return $this->connector->send(new BlockChildren($id, $pageSize));
2424
}
@@ -38,8 +38,8 @@ public function listComments(?string $blockId): Response
3838
return $this->connector->send(new ListComments($blockId));
3939
}
4040

41-
public function queryDataSource(string $dataSourceId, ?array $filter = null): Response
41+
public function queryDataSource(string $dataSourceId, ?array $filter = null, ?int $pageSize = null): Response
4242
{
43-
return $this->connector->send(new QueryDataSource($dataSourceId, $filter));
43+
return $this->connector->send(new QueryDataSource($dataSourceId, $filter, $pageSize));
4444
}
4545
}

src/Services/DatabaseReader.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,26 @@ public function __construct(
1818
* Read database content and build complete Database object
1919
*
2020
* @param string $databaseId The Notion database ID
21+
* @param int|null $pageSize Optional page size for data source query (uses config default if null)
2122
* @return Database The database object with all content and items
2223
*/
23-
public function read(string $databaseId): Database
24+
public function read(string $databaseId, ?int $pageSize = null): Database
2425
{
2526
// Get database details and build initial Database object
2627
$databaseResponse = $this->sdk->act()->getDatabase($databaseId);
2728
$databaseData = $databaseResponse->json();
2829
$database = Database::from($databaseData);
2930

31+
// Resolve page size from argument or config default
32+
$resolvedPageSize = $pageSize ?? config('md-notion.default_page_size');
33+
3034
// Query database data source only once
3135
if (isset($databaseData['data_sources']) && is_array($databaseData['data_sources'])) {
3236
foreach ($databaseData['data_sources'] as $dataSource) {
3337
$dataSourceId = $dataSource['id'] ?? null;
3438
if ($dataSourceId) {
3539
// Query the data source to get its content
36-
$queryResponse = $this->sdk->act()->queryDataSource($dataSourceId, null);
40+
$queryResponse = $this->sdk->act()->queryDataSource($dataSourceId, null, $resolvedPageSize);
3741
$queryData = $queryResponse->json();
3842
// Convert query data to markdown table
3943
$tableContent = $this->databaseTable->convertQueryToMarkdownTable($queryData);

src/Services/PageReader.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,19 @@ public function __construct(
1717
* Read page content and build complete Page object
1818
*
1919
* @param string $pageId The Notion page ID
20+
* @param int|null $pageSize Optional page size for block children (uses config default if null)
2021
* @return Page The page object with all content and children
2122
*/
22-
public function read(string $pageId): Page
23+
public function read(string $pageId, ?int $pageSize = null): Page
2324
{
2425
// Get page details and build initial Page object
2526
$pageResponse = $this->sdk->act()->getPage($pageId);
2627
$pageData = $pageResponse->json();
2728
$page = Page::from($pageData);
2829

2930
// Get block children only once
30-
$blocksResponse = $this->sdk->act()->getBlockChildren($pageId, null);
31+
$resolvedPageSize = $pageSize ?? config('md-notion.default_page_size');
32+
$blocksResponse = $this->sdk->act()->getBlockChildren($pageId, $resolvedPageSize);
3133
$blocks = $blocksResponse->json()['results'] ?? [];
3234

3335
// Process blocks to extract different types of content

tests/SDK/Requests/BlockChildrenRequestTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
test('it can set page size query parameter', function () {
2626
$blockId = '263d9316-605a-8057-b12e-f880bc565fcb';
27-
$pageSize = '25';
27+
$pageSize = 25;
2828
$request = new BlockChildren($blockId, $pageSize);
2929

3030
expect($request->query()->all())->toBe(['page_size' => $pageSize]);

0 commit comments

Comments
 (0)