Skip to content

Commit

Permalink
feat: make stream's filter optional (#558)
Browse files Browse the repository at this point in the history
When stream is defined and the template is not VE, if filter isn't set,
it'll error in build

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
asanehisa and github-actions[bot] authored Dec 3, 2024
1 parent d8c3adf commit cb34773
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/pages/docs/api/pages.stream.filter.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The filter to apply to the stream
**Signature:**

```typescript
filter: {
filter?: {
entityIds?: string[];
entityTypes?: string[];
savedFilterIds?: string[];
Expand Down
4 changes: 2 additions & 2 deletions packages/pages/docs/api/pages.stream.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ The fields to apply to the stream
</td></tr>
<tr><td>

[filter](./pages.stream.filter.md)
[filter?](./pages.stream.filter.md)

</td><td>

Expand All @@ -73,7 +73,7 @@ The fields to apply to the stream

</td><td>

The filter to apply to the stream
_(Optional)_ The filter to apply to the stream

</td></tr>
<tr><td>
Expand Down
2 changes: 1 addition & 1 deletion packages/pages/etc/pages.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ export interface StaticTemplateConfig {
export interface Stream {
$id: string;
fields: string[];
filter: {
filter?: {
entityIds?: string[];
entityTypes?: string[];
savedFilterIds?: string[];
Expand Down
12 changes: 11 additions & 1 deletion packages/pages/src/common/src/feature/stream.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { TemplateConfigInternal } from "../template/internal/types.js";
import { RedirectConfigInternal } from "../redirect/internal/types.js";
import { logErrorAndExit } from "../../../util/logError.js";

/**
* The shape of data that represents a stream configuration.
Expand All @@ -14,7 +15,7 @@ export interface StreamConfig {
/** The fields to apply to the stream */
fields: string[];
/** The filter to apply to the stream */
filter: {
filter?: {
/** The entity IDs to apply to the stream */
entityIds?: string[];
/** The entity types to apply to the stream */
Expand Down Expand Up @@ -48,6 +49,15 @@ export const convertTemplateConfigToStreamConfig = (
if (!config) {
return;
}

if (
config.stream &&
!config.stream.filter &&
!config.additionalProperties?.isVETemplate
) {
logErrorAndExit("Filter is required in StreamConfig for templates.");
}

if (config.stream) {
return {
...config.stream,
Expand Down
2 changes: 1 addition & 1 deletion packages/pages/src/common/src/template/internal/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export interface StreamInternal {
/** The fields to apply to the stream */
fields: string[];
/** The filter to apply to the stream */
filter: {
filter?: {
/** The entity IDs to apply to the stream */
entityIds?: string[];
/** The entity types to apply to the stream */
Expand Down
2 changes: 1 addition & 1 deletion packages/pages/src/common/src/template/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export interface Stream {
/** The fields to apply to the stream */
fields: string[];
/** The filter to apply to the stream */
filter: {
filter?: {
/** The entity IDs to apply to the stream */
entityIds?: string[];
/** The entity types to apply to the stream */
Expand Down

0 comments on commit cb34773

Please sign in to comment.