From cb34773dc9f39ada44fc4c3cc4ca45aeb40d058c Mon Sep 17 00:00:00 2001
From: Alexis Sanehisa <106991746+asanehisa@users.noreply.github.com>
Date: Tue, 3 Dec 2024 11:39:22 -0500
Subject: [PATCH] feat: make stream's filter optional (#558)
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>
---
packages/pages/docs/api/pages.stream.filter.md | 2 +-
packages/pages/docs/api/pages.stream.md | 4 ++--
packages/pages/etc/pages.api.md | 2 +-
packages/pages/src/common/src/feature/stream.ts | 12 +++++++++++-
.../pages/src/common/src/template/internal/types.ts | 2 +-
packages/pages/src/common/src/template/types.ts | 2 +-
6 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/packages/pages/docs/api/pages.stream.filter.md b/packages/pages/docs/api/pages.stream.filter.md
index b1e8c38c5..76f3fc8d7 100644
--- a/packages/pages/docs/api/pages.stream.filter.md
+++ b/packages/pages/docs/api/pages.stream.filter.md
@@ -9,7 +9,7 @@ The filter to apply to the stream
**Signature:**
```typescript
-filter: {
+filter?: {
entityIds?: string[];
entityTypes?: string[];
savedFilterIds?: string[];
diff --git a/packages/pages/docs/api/pages.stream.md b/packages/pages/docs/api/pages.stream.md
index 9bb95aa69..78e3523c3 100644
--- a/packages/pages/docs/api/pages.stream.md
+++ b/packages/pages/docs/api/pages.stream.md
@@ -63,7 +63,7 @@ The fields to apply to the stream
-[filter](./pages.stream.filter.md)
+[filter?](./pages.stream.filter.md)
|
@@ -73,7 +73,7 @@ The fields to apply to the stream
|
-The filter to apply to the stream
+_(Optional)_ The filter to apply to the stream
|
diff --git a/packages/pages/etc/pages.api.md b/packages/pages/etc/pages.api.md
index 35a81fdc7..61b7a2f3b 100644
--- a/packages/pages/etc/pages.api.md
+++ b/packages/pages/etc/pages.api.md
@@ -289,7 +289,7 @@ export interface StaticTemplateConfig {
export interface Stream {
$id: string;
fields: string[];
- filter: {
+ filter?: {
entityIds?: string[];
entityTypes?: string[];
savedFilterIds?: string[];
diff --git a/packages/pages/src/common/src/feature/stream.ts b/packages/pages/src/common/src/feature/stream.ts
index 4aa2b5b1f..0a69e3e41 100644
--- a/packages/pages/src/common/src/feature/stream.ts
+++ b/packages/pages/src/common/src/feature/stream.ts
@@ -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.
@@ -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 */
@@ -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,
diff --git a/packages/pages/src/common/src/template/internal/types.ts b/packages/pages/src/common/src/template/internal/types.ts
index 05b7ab1f1..c9c75df1a 100644
--- a/packages/pages/src/common/src/template/internal/types.ts
+++ b/packages/pages/src/common/src/template/internal/types.ts
@@ -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 */
diff --git a/packages/pages/src/common/src/template/types.ts b/packages/pages/src/common/src/template/types.ts
index 9685030b6..d98ecb19a 100644
--- a/packages/pages/src/common/src/template/types.ts
+++ b/packages/pages/src/common/src/template/types.ts
@@ -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 */
|