Skip to content

Commit 9d95ad4

Browse files
authored
fix: broken API requests after breaking change on archived property (#419)
* Revert "fix: SDK broken after Notion API breaking change (#418)" This reverts commit 8ab55dc. * fix: broken API requests after breaking change on `archived` property * remove deprecated methods from code coverage * fixing coverage
1 parent 8ab55dc commit 9d95ad4

63 files changed

Lines changed: 470 additions & 145 deletions

Some content is hidden

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

docs/blocks/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ $p = Paragraph::fromString("Simple paragraph.");
1515
$p->metadata()->id; // a9f03ee5...
1616
$p->metadata()->createdTime->format("Y-m-d"); // 2022-07-01
1717
$p->metadata()->lastEditedTime->format("Y-m-d"); // 2022-07-01
18-
$p->metadata()->in_trash; // false
18+
$p->metadata()->inTrash; // false
1919
$p->metadata()->hasChildren; // false
2020
```
2121

docs/how-to/delete-a-page.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Delete a page
22

3-
Deleted pages are in_trash. It is possible to recover in_trash pages.
3+
Deleted pages are moved to trash. It is possible to recover pages in trash.
44

55
```php
66
<?php
@@ -14,5 +14,5 @@ $pageId = "c986d7b0-7051-4f18-b165-cc0b9503ffc2";
1414
$page = $notion->pages()->find($pageId);
1515
$page = $notion->pages()->delete($page);
1616

17-
$page->in_trash; // true
17+
$page->inTrash; // true
1818
```

src/Blocks/BlockInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ interface BlockInterface
88
public function metadata(): BlockMetadata;
99
public function addChild(BlockInterface $child): self;
1010
public function changeChildren(BlockInterface ...$children): self;
11+
public function delete(): self;
12+
/**
13+
* @deprecated 1.17.0 Use `delete()` instead.
14+
* @codeCoverageIgnore
15+
*/
1116
public function archive(): self;
1217

1318
/** @internal */

src/Blocks/BlockMetadata.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,21 @@ private function __construct(
2424
public readonly string $id,
2525
public readonly DateTimeImmutable $createdTime,
2626
public readonly DateTimeImmutable $lastEditedTime,
27-
public readonly bool $in_trash,
27+
public readonly bool $inTrash,
2828
public readonly bool $hasChildren,
2929
public readonly BlockType $type,
3030
private readonly string|null $unknownType = null
3131
) {
32+
/** @psalm-suppress DeprecatedProperty */
33+
$this->archived = $inTrash;
3234
}
3335

36+
/**
37+
* @deprecated 1.17.0 Use `$inTrash` instead.
38+
* @codeCoverageIgnore
39+
*/
40+
public readonly bool $archived;
41+
3442
/** @internal */
3543
public static function create(BlockType $type): self
3644
{
@@ -68,7 +76,7 @@ public function toArray(): array
6876
"object" => "block",
6977
"created_time" => $this->createdTime->format(Date::FORMAT),
7078
"last_edited_time" => $this->lastEditedTime->format(Date::FORMAT),
71-
"in_trash" => $this->in_trash,
79+
"in_trash" => $this->inTrash,
7280
"has_children" => $this->hasChildren,
7381
"type" => $type,
7482
];
@@ -81,7 +89,7 @@ public function toArray(): array
8189
}
8290

8391
/** @internal */
84-
public function archive(): self
92+
public function delete(): self
8593
{
8694
return new self(
8795
$this->id,
@@ -113,7 +121,7 @@ public function updateHasChildren(bool $hasChildren): self
113121
$this->id,
114122
$this->createdTime,
115123
new DateTimeImmutable("now"),
116-
$this->in_trash,
124+
$this->inTrash,
117125
$hasChildren,
118126
$this->type,
119127
);
@@ -125,7 +133,7 @@ public function update(): self
125133
$this->id,
126134
$this->createdTime,
127135
new DateTimeImmutable("now"),
128-
$this->in_trash,
136+
$this->inTrash,
129137
$this->hasChildren,
130138
$this->type,
131139
);

src/Blocks/Bookmark.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,21 @@ public function changeChildren(BlockInterface ...$children): never
9393
throw BlockException::noChindrenSupport();
9494
}
9595

96-
public function archive(): BlockInterface
96+
public function delete(): BlockInterface
9797
{
9898
return new self(
99-
$this->metadata->archive(),
99+
$this->metadata->delete(),
100100
$this->url,
101101
$this->caption,
102102
);
103103
}
104+
105+
/**
106+
* @deprecated 1.17.0 Use `delete()` instead.
107+
* @codeCoverageIgnore
108+
*/
109+
public function archive(): BlockInterface
110+
{
111+
return $this->delete();
112+
}
104113
}

src/Blocks/Breadcrumb.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,17 @@ public function changeChildren(BlockInterface ...$children): never
6060
throw BlockException::noChindrenSupport();
6161
}
6262

63+
public function delete(): BlockInterface
64+
{
65+
return new self($this->metadata->delete());
66+
}
67+
68+
/**
69+
* @deprecated 1.17.0 Use `delete()` instead.
70+
* @codeCoverageIgnore
71+
*/
6372
public function archive(): BlockInterface
6473
{
65-
return new self($this->metadata->archive());
74+
return $this->delete();
6675
}
6776
}

src/Blocks/BulletedListItem.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,22 @@ public function changeColor(Color $color): self
149149
);
150150
}
151151

152-
public function archive(): BlockInterface
152+
public function delete(): BlockInterface
153153
{
154154
return new self(
155-
$this->metadata->archive(),
155+
$this->metadata->delete(),
156156
$this->text,
157157
$this->color,
158158
$this->children,
159159
);
160160
}
161+
162+
/**
163+
* @deprecated 1.17.0 Use `delete()` instead.
164+
* @codeCoverageIgnore
165+
*/
166+
public function archive(): BlockInterface
167+
{
168+
return $this->delete();
169+
}
161170
}

src/Blocks/Callout.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,23 @@ public function changeColor(Color $color): self
174174
);
175175
}
176176

177-
public function archive(): BlockInterface
177+
public function delete(): BlockInterface
178178
{
179179
return new self(
180-
$this->metadata->archive(),
180+
$this->metadata->delete(),
181181
$this->text,
182182
$this->icon,
183183
$this->color,
184184
$this->children,
185185
);
186186
}
187+
188+
/**
189+
* @deprecated 1.17.0 Use `delete()` instead.
190+
* @codeCoverageIgnore
191+
*/
192+
public function archive(): BlockInterface
193+
{
194+
return $this->delete();
195+
}
187196
}

src/Blocks/ChildDatabase.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,20 @@ public function changeChildren(BlockInterface ...$children): never
5757
throw BlockException::noChindrenSupport();
5858
}
5959

60-
public function archive(): BlockInterface
60+
public function delete(): BlockInterface
6161
{
6262
return new self(
63-
$this->metadata->archive(),
63+
$this->metadata->delete(),
6464
$this->title,
6565
);
6666
}
67+
68+
/**
69+
* @deprecated 1.17.0 Use `delete()` instead.
70+
* @codeCoverageIgnore
71+
*/
72+
public function archive(): BlockInterface
73+
{
74+
return $this->delete();
75+
}
6776
}

src/Blocks/ChildPage.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,20 @@ public function changeChildren(BlockInterface ...$children): never
5757
throw BlockException::noChindrenSupport();
5858
}
5959

60-
public function archive(): BlockInterface
60+
public function delete(): BlockInterface
6161
{
6262
return new self(
63-
$this->metadata->archive(),
63+
$this->metadata->delete(),
6464
$this->title,
6565
);
6666
}
67+
68+
/**
69+
* @deprecated 1.17.0 Use `delete()` instead.
70+
* @codeCoverageIgnore
71+
*/
72+
public function archive(): BlockInterface
73+
{
74+
return $this->delete();
75+
}
6776
}

0 commit comments

Comments
 (0)