@notionhq/custom-blocks 0.1.33 → 0.1.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bridge/SandboxBridge.d.ts +3 -1
- package/dist/bridge/SandboxBridge.d.ts.map +1 -1
- package/dist/bridge/SandboxBridge.js +55 -47
- package/dist/bridge/dataSources/query.d.ts +27 -0
- package/dist/bridge/dataSources/query.d.ts.map +1 -0
- package/dist/bridge/dataSources/query.js +512 -0
- package/dist/bridge/hostState.d.ts +4 -3
- package/dist/bridge/hostState.d.ts.map +1 -1
- package/dist/bridge/hostState.js +7 -3
- package/dist/bridge/sandboxClient.d.ts +4 -2
- package/dist/bridge/sandboxClient.d.ts.map +1 -1
- package/dist/bridge/sandboxClient.js +10 -4
- package/dist/protocol/dataSources/propertySchema.d.ts +7 -0
- package/dist/protocol/dataSources/propertySchema.d.ts.map +1 -1
- package/dist/protocol/dataSources/propertySchema.js +17 -0
- package/dist/protocol/messages/queryDataSource.d.ts +970 -0
- package/dist/protocol/messages/queryDataSource.d.ts.map +1 -1
- package/dist/protocol/messages/queryDataSource.js +108 -0
- package/dist/protocol/messages/queryDataSourceResult.d.ts +1 -1
- package/dist/protocol/messages/queryDataSourceResult.d.ts.map +1 -1
- package/dist/protocol/messages/sandboxToHost.d.ts +353 -0
- package/dist/protocol/messages/sandboxToHost.d.ts.map +1 -1
- package/dist/react/useDataSource.d.ts +1 -1
- package/dist/react/useDataSource.d.ts.map +1 -1
- package/dist/react/useDataSource.js +11 -6
- package/dist/types.d.ts +52 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/docs/data-sources.md +51 -3
- package/package.json +1 -1
- package/src/bridge/SandboxBridge.ts +66 -57
- package/src/bridge/dataSources/query.ts +694 -0
- package/src/bridge/hostState.ts +11 -3
- package/src/bridge/sandboxClient.ts +20 -4
- package/src/react/useDataSource.ts +17 -6
- package/src/types.ts +55 -0
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,4DAA4D,CAAA;AACxG,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iEAAiE,CAAA;AAC5G,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gEAAgE,CAAA;AAC1G,OAAO,KAAK,EACX,kBAAkB,EAClB,YAAY,EACZ,MAAM,yCAAyC,CAAA;AAChD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oDAAoD,CAAA;AAC9F,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,yDAAyD,CAAA;AACvG,OAAO,KAAK,EACX,uBAAuB,EACvB,8BAA8B,EAC9B,MAAM,+DAA+D,CAAA;AACtE,OAAO,KAAK,EACX,2BAA2B,EAC3B,oBAAoB,EACpB,MAAM,sDAAsD,CAAA;AAC7D,OAAO,KAAK,EACX,2BAA2B,EAC3B,oBAAoB,EACpB,MAAM,sDAAsD,CAAA;AAC7D,OAAO,KAAK,EACX,6BAA6B,EAC7B,gBAAgB,EAChB,sBAAsB,EACtB,MAAM,wDAAwD,CAAA;AAC/D,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,oEAAoE,CAAA;AAC7H,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yDAAyD,CAAA;AAChG,OAAO,KAAK,EACX,8BAA8B,EAC9B,uBAAuB,EACvB,MAAM,+DAA+D,CAAA;AACtE,OAAO,KAAK,EACX,eAAe,EACf,cAAc,EACd,uBAAuB,EACvB,MAAM,gDAAgD,CAAA;AAEvD,YAAY,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAA;AACtF,YAAY,EACX,kBAAkB,EAClB,aAAa,GACb,MAAM,yCAAyC,CAAA;AAChD,YAAY,EACX,UAAU,EACV,YAAY,EAC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AM,MAAM,mBAAmB,GAAG;IACjC,KAAK,EAAE,oBAAoB,EAAE,CAAA;IAC7B;;;OAGG;IACH,gBAAgB,CAAC,EAAE,sBAAsB,CAAA;IACzC;;;OAGG;IACH,mBAAmB,EAAE;QAAE,CAAC,UAAU,EAAE,MAAM,GAAG,oBAAoB,CAAA;KAAE,CAAA;IACnE;;;OAGG;IACH,gBAAgB,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;KAAE,CAAA;IACvD;;;;OAIG;IACH,oBAAoB,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,oBAAoB,GAAG,SAAS,CAAA;KAAE,CAAA;IACzE,SAAS,EAAE,OAAO,CAAA;IAClB,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,CAAC,EAAE,mCAAmC,CAAA;CAC3C,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG;IAClC;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,4DAA4D,CAAA;AACxG,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iEAAiE,CAAA;AAC5G,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gEAAgE,CAAA;AAC1G,OAAO,KAAK,EACX,kBAAkB,EAClB,YAAY,EACZ,MAAM,yCAAyC,CAAA;AAChD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oDAAoD,CAAA;AAC9F,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,yDAAyD,CAAA;AACvG,OAAO,KAAK,EACX,uBAAuB,EACvB,8BAA8B,EAC9B,MAAM,+DAA+D,CAAA;AACtE,OAAO,KAAK,EACX,2BAA2B,EAC3B,oBAAoB,EACpB,MAAM,sDAA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GAAG,WAAW,CAAC,CAAA;AAExE;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG,aAAa,CAAA;AAE1C,MAAM,MAAM,eAAe,GAAG,oBAAoB,CACjD,sBAAsB,EACtB,6BAA6B,CAC7B,CAAA;AAED,MAAM,MAAM,aAAa,GAAG,oBAAoB,CAC/C,oBAAoB,EACpB,2BAA2B,CAC3B,CAAA"}
|
package/dist/version.js
CHANGED
package/docs/data-sources.md
CHANGED
|
@@ -41,7 +41,11 @@ Use `row.update(...)` whenever you already have a row in hand. For pages you don
|
|
|
41
41
|
```ts
|
|
42
42
|
function useDataSource(
|
|
43
43
|
key: string,
|
|
44
|
-
options?: {
|
|
44
|
+
options?: {
|
|
45
|
+
limit?: number;
|
|
46
|
+
filter?: NotionDataSourceFilter;
|
|
47
|
+
sorts?: NotionDataSourceSort[];
|
|
48
|
+
},
|
|
45
49
|
): UseDataSourceResult;
|
|
46
50
|
|
|
47
51
|
type UseDataSourceResult = {
|
|
@@ -56,7 +60,46 @@ type UseDataSourceResult = {
|
|
|
56
60
|
};
|
|
57
61
|
```
|
|
58
62
|
|
|
59
|
-
Reads the data source mapped to `key`. `limit`
|
|
63
|
+
Reads the data source mapped to `key`. The SDK uses a default `limit` of 20 and caps it at 999. To request more rows, store the limit in component state and pass it to `useDataSource` again. Each request is bounded. The hook does not provide cursor pagination.
|
|
64
|
+
|
|
65
|
+
`filter` accepts one property condition or one shallow `and` group. Use `key` for a semantic property key. Use `propertyId` for a raw Notion property ID. The SDK resolves semantic keys before it sends the bridge request. The SDK reports local errors for unknown or unbound keys, property-type mismatches, unsupported filter fields, invalid operators, and invalid values.
|
|
66
|
+
|
|
67
|
+
```tsx
|
|
68
|
+
const query = useDataSource("tasks", {
|
|
69
|
+
filter: {
|
|
70
|
+
and: [
|
|
71
|
+
{ key: "title", title: { contains: "launch" } },
|
|
72
|
+
{ key: "done", checkbox: { equals: false } },
|
|
73
|
+
],
|
|
74
|
+
},
|
|
75
|
+
sorts: [{ key: "due", direction: "ascending" }],
|
|
76
|
+
limit: 50,
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Filters support these property types:
|
|
81
|
+
|
|
82
|
+
- Text properties: `title`, `rich_text`, `url`, `email`, and `phone_number`. They support `equals`, `does_not_equal`, `contains`, `does_not_contain`, `starts_with`, `ends_with`, `is_empty`, and `is_not_empty`.
|
|
83
|
+
- `number`: `equals`, `does_not_equal`, `greater_than`, `less_than`, `greater_than_or_equal_to`, `less_than_or_equal_to`, `is_empty`, and `is_not_empty`.
|
|
84
|
+
- `checkbox`: `equals` and `does_not_equal`.
|
|
85
|
+
- `select` and `status`: `equals`, `does_not_equal`, `is_empty`, and `is_not_empty`.
|
|
86
|
+
- `multi_select`: `contains`, `contains_all`, `does_not_contain`, `is_empty`, and `is_not_empty`.
|
|
87
|
+
- `date`: `equals`, `before`, `after`, `on_or_before`, `on_or_after`, `is_empty`, and `is_not_empty`.
|
|
88
|
+
|
|
89
|
+
Select, multi-select, and status values can be one option name or an array of option names. For multi-select properties, `contains` matches any supplied option and `contains_all` requires every supplied option. Empty checks use `{ is_empty: true }` or `{ is_not_empty: true }`. Date comparisons accept ISO dates or ISO timestamps.
|
|
90
|
+
|
|
91
|
+
The `and` group can contain up to 25 conditions. An empty group is valid. Nested groups and `or` groups are not supported.
|
|
92
|
+
|
|
93
|
+
`sorts` accepts a list of property addresses and directions. Use `key` for a
|
|
94
|
+
semantic property key or `propertyId` for a raw Notion property ID. The SDK
|
|
95
|
+
resolves semantic keys before it sends the bridge request. The host applies
|
|
96
|
+
sorts in array order. The first sort has the highest priority. The list can
|
|
97
|
+
contain up to ten unique properties. Empty values sort last in either
|
|
98
|
+
direction. Sorts currently support title, rich text, number, checkbox, URL,
|
|
99
|
+
email, phone number, date, created time, and last edited time properties.
|
|
100
|
+
Other property types are rejected until their sort values are supported.
|
|
101
|
+
|
|
102
|
+
`propertyIdsByKey` maps manifest property keys to raw Notion property IDs; unbound keys map to `undefined`. `propertySchemasByKey` exposes the corresponding schemas and is likewise `undefined` for declared-but-unbound slots.
|
|
60
103
|
|
|
61
104
|
Query failures follow the SDK's [error-handling contract](./errors.md).
|
|
62
105
|
|
|
@@ -161,7 +204,12 @@ export function ScoreList() {
|
|
|
161
204
|
- `NotionDataSourcePageUpdateArgs` / `UpdatePageResult` — arguments and result for the per-page `update` helper.
|
|
162
205
|
- `NotionDataSourcePageUpdateInput` — deprecated alias for `NotionDataSourcePageUpdateArgs`.
|
|
163
206
|
- `NotionDataSourcePageUpdateResult` — deprecated alias for `UpdatePageResult`.
|
|
164
|
-
- `UseDataSourceOptions` — options accepted by `useDataSource
|
|
207
|
+
- `UseDataSourceOptions` — options accepted by `useDataSource`: `limit?: number`, `filter?: NotionDataSourceFilter`, and `sorts?: NotionDataSourceSort[]`.
|
|
208
|
+
- `NotionDataSourceFilter` — one property condition or one shallow `and` group.
|
|
209
|
+
- `NotionDataSourcePropertyFilter` — one property address combined with a type-specific operator.
|
|
210
|
+
- `NotionDataSourcePropertyAddress` — either a semantic property `key` or a raw `propertyId`.
|
|
211
|
+
- `NotionDataSourceSort` — a property address with an `ascending` or `descending` direction.
|
|
212
|
+
- `NotionDataSourceTextFilterOperator`, `NotionDataSourceNumberFilterOperator`, `NotionDataSourceCheckboxFilterOperator`, `NotionDataSourceOptionFilterOperator`, `NotionDataSourceContainsFilterOperator`, and `NotionDataSourceDateFilterOperator` — the operators accepted for each property type.
|
|
165
213
|
|
|
166
214
|
### Property schemas
|
|
167
215
|
|
package/package.json
CHANGED
|
@@ -52,6 +52,7 @@ import {
|
|
|
52
52
|
NOTION_DARK_BACKGROUND_BASE,
|
|
53
53
|
NOTION_LIGHT_BACKGROUND_BASE,
|
|
54
54
|
} from "./appearance.js"
|
|
55
|
+
import { resolveDataSourceQuery } from "./dataSources/query.js"
|
|
55
56
|
import { resolveDataSources } from "./dataSources/resolve.js"
|
|
56
57
|
import { resolvePropertyWriteMapForDataSource } from "./dataSources/resolveProperty.js"
|
|
57
58
|
import {
|
|
@@ -393,12 +394,14 @@ export class SandboxBridge {
|
|
|
393
394
|
nextBindings,
|
|
394
395
|
})
|
|
395
396
|
this.latestDataSourceBindings = nextBindings
|
|
396
|
-
// Drop cached query state for
|
|
397
|
+
// Drop cached query state for subscriptions whose key no longer exists.
|
|
397
398
|
const nextKeys = new Set(dataSources.map(s => s.key))
|
|
398
399
|
const prunedState: Record<string, DataSourceQueryState> = {}
|
|
399
|
-
for (const [
|
|
400
|
-
|
|
401
|
-
|
|
400
|
+
for (const [subscriptionId, state] of Object.entries(
|
|
401
|
+
hostState.dataSourceState,
|
|
402
|
+
)) {
|
|
403
|
+
if (nextKeys.has(state.dataSourceKey)) {
|
|
404
|
+
prunedState[subscriptionId] = state
|
|
402
405
|
}
|
|
403
406
|
}
|
|
404
407
|
this.hostState = {
|
|
@@ -476,13 +479,10 @@ export class SandboxBridge {
|
|
|
476
479
|
}
|
|
477
480
|
|
|
478
481
|
case "queryDataSourceResult": {
|
|
479
|
-
const
|
|
480
|
-
|
|
481
|
-
)
|
|
482
|
-
if (queryEntry === undefined) {
|
|
482
|
+
const currentState = hostState.dataSourceState[message.subscriptionId]
|
|
483
|
+
if (currentState === undefined) {
|
|
483
484
|
return
|
|
484
485
|
}
|
|
485
|
-
const [key, currentState] = queryEntry
|
|
486
486
|
const queryResult =
|
|
487
487
|
message.status === "error"
|
|
488
488
|
? {
|
|
@@ -499,13 +499,14 @@ export class SandboxBridge {
|
|
|
499
499
|
...hostState,
|
|
500
500
|
dataSourceState: {
|
|
501
501
|
...hostState.dataSourceState,
|
|
502
|
-
[
|
|
502
|
+
[message.subscriptionId]: {
|
|
503
|
+
dataSourceKey: currentState.dataSourceKey,
|
|
503
504
|
items: queryResult.items,
|
|
504
505
|
isLoading: false,
|
|
505
506
|
hasMore: queryResult.hasMore,
|
|
506
507
|
error: queryResult.error,
|
|
507
|
-
subscriptionId: message.subscriptionId,
|
|
508
508
|
latestLimit: currentState.latestLimit,
|
|
509
|
+
latestQueryIdentity: currentState.latestQueryIdentity,
|
|
509
510
|
},
|
|
510
511
|
},
|
|
511
512
|
}
|
|
@@ -672,7 +673,15 @@ export class SandboxBridge {
|
|
|
672
673
|
}
|
|
673
674
|
}
|
|
674
675
|
|
|
675
|
-
|
|
676
|
+
createDataSourceSubscriptionId(): string {
|
|
677
|
+
return `data-source:${globalThis.crypto.randomUUID()}`
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
queryDataSource(
|
|
681
|
+
subscriptionId: string,
|
|
682
|
+
key: string,
|
|
683
|
+
options: UseDataSourceOptions = {},
|
|
684
|
+
) {
|
|
676
685
|
if (this.hostState.status !== "initialized") {
|
|
677
686
|
return
|
|
678
687
|
}
|
|
@@ -680,10 +689,13 @@ export class SandboxBridge {
|
|
|
680
689
|
const dataSource = this.hostState.dataSources.find(
|
|
681
690
|
entry => entry.key === key,
|
|
682
691
|
)
|
|
692
|
+
const subscriptionState = this.hostState.dataSourceState[subscriptionId]
|
|
683
693
|
const currentState =
|
|
684
|
-
|
|
694
|
+
subscriptionState?.dataSourceKey === key
|
|
695
|
+
? subscriptionState
|
|
696
|
+
: createEmptyDataSourceQueryState(key)
|
|
685
697
|
if (dataSource === undefined) {
|
|
686
|
-
this.setDataSourceQueryError(
|
|
698
|
+
this.setDataSourceQueryError(subscriptionId, currentState, {
|
|
687
699
|
code: "unknown_data_source_key",
|
|
688
700
|
message: `Unknown data source key "${key}". Known keys: [${this.hostState.dataSources.map(entry => entry.key).join(", ")}].`,
|
|
689
701
|
isRetryable: false,
|
|
@@ -691,7 +703,7 @@ export class SandboxBridge {
|
|
|
691
703
|
return
|
|
692
704
|
}
|
|
693
705
|
if (dataSource.collectionPointer === undefined) {
|
|
694
|
-
this.setDataSourceQueryError(
|
|
706
|
+
this.setDataSourceQueryError(subscriptionId, currentState, {
|
|
695
707
|
code: "unmapped_data_source",
|
|
696
708
|
message: `Data source "${key}" has not been mapped to a database yet.`,
|
|
697
709
|
isRetryable: false,
|
|
@@ -699,15 +711,24 @@ export class SandboxBridge {
|
|
|
699
711
|
return
|
|
700
712
|
}
|
|
701
713
|
|
|
702
|
-
const
|
|
703
|
-
|
|
714
|
+
const resolvedQuery = resolveDataSourceQuery({
|
|
715
|
+
dataSources: this.hostState.dataSources,
|
|
704
716
|
key,
|
|
717
|
+
options,
|
|
705
718
|
})
|
|
719
|
+
if (resolvedQuery.status === "error") {
|
|
720
|
+
this.setDataSourceQueryError(subscriptionId, currentState, {
|
|
721
|
+
code: "invalid_data_source_query",
|
|
722
|
+
message: resolvedQuery.error,
|
|
723
|
+
isRetryable: false,
|
|
724
|
+
})
|
|
725
|
+
return
|
|
726
|
+
}
|
|
727
|
+
const query = resolvedQuery.query
|
|
706
728
|
|
|
707
729
|
if (
|
|
708
730
|
currentState.isLoading &&
|
|
709
|
-
currentState.
|
|
710
|
-
currentState.latestLimit === limit
|
|
731
|
+
currentState.latestQueryIdentity === query.identity
|
|
711
732
|
) {
|
|
712
733
|
return
|
|
713
734
|
}
|
|
@@ -716,12 +737,13 @@ export class SandboxBridge {
|
|
|
716
737
|
...this.hostState,
|
|
717
738
|
dataSourceState: {
|
|
718
739
|
...this.hostState.dataSourceState,
|
|
719
|
-
[
|
|
740
|
+
[subscriptionId]: {
|
|
720
741
|
...currentState,
|
|
742
|
+
dataSourceKey: key,
|
|
721
743
|
isLoading: true,
|
|
722
744
|
error: undefined,
|
|
723
|
-
|
|
724
|
-
|
|
745
|
+
latestLimit: query.limit,
|
|
746
|
+
latestQueryIdentity: query.identity,
|
|
725
747
|
},
|
|
726
748
|
},
|
|
727
749
|
}
|
|
@@ -730,14 +752,16 @@ export class SandboxBridge {
|
|
|
730
752
|
const outbound: QueryDataSourceMessage = {
|
|
731
753
|
type: "queryDataSource",
|
|
732
754
|
subscriptionId,
|
|
733
|
-
dataSourceId:
|
|
734
|
-
limit,
|
|
755
|
+
dataSourceId: query.dataSourceId,
|
|
756
|
+
limit: query.limit,
|
|
757
|
+
...(query.filter !== undefined ? { filter: query.filter } : {}),
|
|
758
|
+
...(query.sorts !== undefined ? { sorts: query.sorts } : {}),
|
|
735
759
|
}
|
|
736
760
|
this.postToHost(outbound)
|
|
737
761
|
}
|
|
738
762
|
|
|
739
763
|
private setDataSourceQueryError(
|
|
740
|
-
|
|
764
|
+
subscriptionId: string,
|
|
741
765
|
currentState: DataSourceQueryState,
|
|
742
766
|
error: CustomBlockQueryDataSourceErrorInfo,
|
|
743
767
|
) {
|
|
@@ -748,18 +772,33 @@ export class SandboxBridge {
|
|
|
748
772
|
...this.hostState,
|
|
749
773
|
dataSourceState: {
|
|
750
774
|
...this.hostState.dataSourceState,
|
|
751
|
-
[
|
|
775
|
+
[subscriptionId]: {
|
|
752
776
|
...currentState,
|
|
753
777
|
isLoading: false,
|
|
754
778
|
error,
|
|
755
|
-
subscriptionId: undefined,
|
|
756
779
|
latestLimit: undefined,
|
|
780
|
+
latestQueryIdentity: undefined,
|
|
757
781
|
},
|
|
758
782
|
},
|
|
759
783
|
}
|
|
760
784
|
this.notify()
|
|
761
785
|
}
|
|
762
786
|
|
|
787
|
+
releaseDataSourceSubscription(subscriptionId: string) {
|
|
788
|
+
if (
|
|
789
|
+
this.hostState.status !== "initialized" ||
|
|
790
|
+
this.hostState.dataSourceState[subscriptionId] === undefined
|
|
791
|
+
) {
|
|
792
|
+
return
|
|
793
|
+
}
|
|
794
|
+
const { [subscriptionId]: _, ...dataSourceState } =
|
|
795
|
+
this.hostState.dataSourceState
|
|
796
|
+
this.hostState = {
|
|
797
|
+
...this.hostState,
|
|
798
|
+
dataSourceState,
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
|
|
763
802
|
postResize(height: number) {
|
|
764
803
|
if (typeof window === "undefined") {
|
|
765
804
|
return
|
|
@@ -1054,36 +1093,6 @@ function reuseDataSourcesForUnchangedBindings(args: {
|
|
|
1054
1093
|
})
|
|
1055
1094
|
}
|
|
1056
1095
|
|
|
1057
|
-
// The default number of items to return in a live snapshot response if no limit is provided.
|
|
1058
|
-
const DEFAULT_DATA_SOURCE_QUERY_LIMIT = 20
|
|
1059
|
-
|
|
1060
|
-
// The maximum number of items to return in a single live snapshot response.
|
|
1061
|
-
const MAX_DATA_SOURCE_QUERY_LIMIT = 999
|
|
1062
|
-
|
|
1063
|
-
function resolveDataSourceQueryLimit(limit: number | undefined): number {
|
|
1064
|
-
if (limit === undefined) {
|
|
1065
|
-
return DEFAULT_DATA_SOURCE_QUERY_LIMIT
|
|
1066
|
-
}
|
|
1067
|
-
if (!Number.isFinite(limit) || !Number.isInteger(limit) || limit < 1) {
|
|
1068
|
-
console.warn(
|
|
1069
|
-
`[custom-blocks-sdk] useDataSource limit must be a positive integer; using ${DEFAULT_DATA_SOURCE_QUERY_LIMIT}.`,
|
|
1070
|
-
)
|
|
1071
|
-
return DEFAULT_DATA_SOURCE_QUERY_LIMIT
|
|
1072
|
-
}
|
|
1073
|
-
if (limit > MAX_DATA_SOURCE_QUERY_LIMIT) {
|
|
1074
|
-
console.warn(
|
|
1075
|
-
`[custom-blocks-sdk] useDataSource limit is capped at ${MAX_DATA_SOURCE_QUERY_LIMIT}.`,
|
|
1076
|
-
)
|
|
1077
|
-
return MAX_DATA_SOURCE_QUERY_LIMIT
|
|
1078
|
-
}
|
|
1079
|
-
return limit
|
|
1080
|
-
}
|
|
1081
|
-
|
|
1082
|
-
function makeDataSourceSubscriptionId(args: { key: string }): string {
|
|
1083
|
-
const { key } = args
|
|
1084
|
-
return `data-source:${encodeURIComponent(key)}`
|
|
1085
|
-
}
|
|
1086
|
-
|
|
1087
1096
|
function invalidInitPayloadError(
|
|
1088
1097
|
issues: readonly v.BaseIssue<unknown>[],
|
|
1089
1098
|
): CustomBlockInitResultErrorInfo {
|