@notionhq/custom-blocks-host 0.2.4 → 0.2.6

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/README.md CHANGED
@@ -246,7 +246,10 @@ The returned handle exposes:
246
246
 
247
247
  State updates are sent after `initResult.success`. Updates made earlier are held until
248
248
  initialization completes. `refreshQuery()` re-runs `queryDataSource` for every active subscription
249
- with the supplied data source ID, preserving each subscription's filter, sorts, and limit.
249
+ with the supplied data source ID, preserving each subscription's filter, sorts, and limit. If that
250
+ query is already running, refresh requests coalesce into one follow-up query. The running query
251
+ delivers its snapshot before the follow-up starts, so continuous changes do not starve updates.
252
+ Unsubscribing, replacing the query, or stopping the host discards its queued refresh.
250
253
 
251
254
  After `stop()`, the host drops outbound messages, including pending request responses. The runtime
252
255
  removes a subscription when it receives `unsubscribeDataSourceQuery`. Repeated unsubscribe messages
@@ -1 +1 @@
1
- {"version":3,"file":"createCustomBlockHost.d.ts","sourceRoot":"","sources":["../src/createCustomBlockHost.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,8CAA8C,CAAA;AAI5F,OAAO,EAAE,wBAAwB,EAAE,MAAM,yCAAyC,CAAA;AAClF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAA;AAiBvF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gDAAgD,CAAA;AAC3F,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAA;AAEpF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2CAA2C,CAAA;AAClF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gDAAgD,CAAA;AACtF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAKzC,OAAO,KAAK,EACX,iCAAiC,EACjC,8BAA8B,EAI9B,MAAM,sBAAsB,CAAA;AAG7B,OAAO,KAAK,EACX,sBAAsB,EAC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wBAAwB,CAAC,CAAA;KACzD,KAAK,IAAI,CAAA;CACV,CAAA;AAQD,wBAAgB,qBAAqB,CACpC,OAAO,EAAE,sBAAsB,GAC7B,qBAAqB,CAuYvB"}
@@ -109,25 +109,33 @@ export function createCustomBlockHost(options) {
109
109
  sendInitializedMessage(message);
110
110
  }
111
111
  async function handleQuery(message, token = querySubscriptions.subscribe(message)) {
112
- const collectionSchema = getCollectionSchema(activeDataSources, message.dataSourceId);
113
- const queryError = getQueryValidationError(message, collectionSchema);
114
- if (queryError !== undefined) {
115
- if (querySubscriptions.isCurrent(message.subscriptionId, token)) {
116
- postQueryDataSourceResult({
117
- subscriptionId: message.subscriptionId,
118
- response: { status: "error", error: queryError },
119
- });
112
+ try {
113
+ const collectionSchema = getCollectionSchema(activeDataSources, message.dataSourceId);
114
+ const queryError = getQueryValidationError(message, collectionSchema);
115
+ if (queryError !== undefined) {
116
+ if (querySubscriptions.isCurrent(message.subscriptionId, token)) {
117
+ postQueryDataSourceResult({
118
+ subscriptionId: message.subscriptionId,
119
+ response: { status: "error", error: queryError },
120
+ });
121
+ }
122
+ return;
120
123
  }
121
- return;
124
+ const response = await handlers.queryDataSource(message);
125
+ if (!querySubscriptions.isCurrent(message.subscriptionId, token)) {
126
+ return;
127
+ }
128
+ postQueryDataSourceResult({
129
+ subscriptionId: message.subscriptionId,
130
+ response,
131
+ });
122
132
  }
123
- const response = await handlers.queryDataSource(message);
124
- if (!querySubscriptions.isCurrent(message.subscriptionId, token)) {
125
- return;
133
+ finally {
134
+ const refresh = querySubscriptions.finish(message.subscriptionId, token);
135
+ if (refresh !== undefined) {
136
+ void handleQuery(refresh.message, refresh.token);
137
+ }
126
138
  }
127
- postQueryDataSourceResult({
128
- subscriptionId: message.subscriptionId,
129
- response,
130
- });
131
139
  }
132
140
  function updateHostState(update) {
133
141
  if (initializationController.status === "stopped" ||
@@ -313,7 +321,7 @@ export function createCustomBlockHost(options) {
313
321
  }
314
322
  const normalizedDataSourceId = v.parse(notionDataSourceIdSchema, dataSourceId);
315
323
  const refreshes = querySubscriptions.refresh(normalizedDataSourceId);
316
- if (refreshes.length === 0) {
324
+ if (refreshes === undefined) {
317
325
  emit("warn", `No active query exists for data source "${dataSourceId}"`);
318
326
  return;
319
327
  }
@@ -123,20 +123,27 @@ export declare const customBlockContainsFilterOperatorSchema: v.UnionSchema<[v.S
123
123
  }, undefined>], undefined>], undefined>;
124
124
  export type CustomBlockContainsFilterOperator = v.InferOutput<typeof customBlockContainsFilterOperatorSchema>;
125
125
  export declare const customBlockDateFilterOperatorSchema: v.UnionSchema<[v.StrictObjectSchema<{
126
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
126
127
  readonly equals: v.StringSchema<undefined>;
127
128
  }, undefined>, v.StrictObjectSchema<{
129
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
128
130
  readonly before: v.StringSchema<undefined>;
129
131
  }, undefined>, v.StrictObjectSchema<{
132
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
130
133
  readonly after: v.StringSchema<undefined>;
131
134
  }, undefined>, v.StrictObjectSchema<{
135
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
132
136
  readonly on_or_before: v.StringSchema<undefined>;
133
137
  }, undefined>, v.StrictObjectSchema<{
138
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
134
139
  readonly on_or_after: v.StringSchema<undefined>;
135
- }, undefined>, v.UnionSchema<[v.StrictObjectSchema<{
140
+ }, undefined>, v.StrictObjectSchema<{
141
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
136
142
  readonly is_empty: v.LiteralSchema<true, undefined>;
137
143
  }, undefined>, v.StrictObjectSchema<{
144
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
138
145
  readonly is_not_empty: v.LiteralSchema<true, undefined>;
139
- }, undefined>], undefined>], undefined>;
146
+ }, undefined>], undefined>;
140
147
  export type CustomBlockDateFilterOperator = v.InferOutput<typeof customBlockDateFilterOperatorSchema>;
141
148
  export declare const resolvedCustomBlockDataSourcePropertyFilterSchema: v.UnionSchema<[v.StrictObjectSchema<{
142
149
  readonly propertyId: v.StringSchema<undefined>;
@@ -318,20 +325,27 @@ export declare const resolvedCustomBlockDataSourcePropertyFilterSchema: v.UnionS
318
325
  }, undefined>, v.StrictObjectSchema<{
319
326
  readonly propertyId: v.StringSchema<undefined>;
320
327
  readonly date: v.UnionSchema<[v.StrictObjectSchema<{
328
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
321
329
  readonly equals: v.StringSchema<undefined>;
322
330
  }, undefined>, v.StrictObjectSchema<{
331
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
323
332
  readonly before: v.StringSchema<undefined>;
324
333
  }, undefined>, v.StrictObjectSchema<{
334
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
325
335
  readonly after: v.StringSchema<undefined>;
326
336
  }, undefined>, v.StrictObjectSchema<{
337
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
327
338
  readonly on_or_before: v.StringSchema<undefined>;
328
339
  }, undefined>, v.StrictObjectSchema<{
340
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
329
341
  readonly on_or_after: v.StringSchema<undefined>;
330
- }, undefined>, v.UnionSchema<[v.StrictObjectSchema<{
342
+ }, undefined>, v.StrictObjectSchema<{
343
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
331
344
  readonly is_empty: v.LiteralSchema<true, undefined>;
332
345
  }, undefined>, v.StrictObjectSchema<{
346
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
333
347
  readonly is_not_empty: v.LiteralSchema<true, undefined>;
334
- }, undefined>], undefined>], undefined>;
348
+ }, undefined>], undefined>;
335
349
  }, undefined>, v.StrictObjectSchema<{
336
350
  readonly propertyId: v.StringSchema<undefined>;
337
351
  readonly people: v.UnionSchema<[v.StrictObjectSchema<{
@@ -531,20 +545,27 @@ export declare const resolvedCustomBlockDataSourceFilterSchema: v.UnionSchema<[v
531
545
  }, undefined>, v.StrictObjectSchema<{
532
546
  readonly propertyId: v.StringSchema<undefined>;
533
547
  readonly date: v.UnionSchema<[v.StrictObjectSchema<{
548
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
534
549
  readonly equals: v.StringSchema<undefined>;
535
550
  }, undefined>, v.StrictObjectSchema<{
551
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
536
552
  readonly before: v.StringSchema<undefined>;
537
553
  }, undefined>, v.StrictObjectSchema<{
554
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
538
555
  readonly after: v.StringSchema<undefined>;
539
556
  }, undefined>, v.StrictObjectSchema<{
557
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
540
558
  readonly on_or_before: v.StringSchema<undefined>;
541
559
  }, undefined>, v.StrictObjectSchema<{
560
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
542
561
  readonly on_or_after: v.StringSchema<undefined>;
543
- }, undefined>, v.UnionSchema<[v.StrictObjectSchema<{
562
+ }, undefined>, v.StrictObjectSchema<{
563
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
544
564
  readonly is_empty: v.LiteralSchema<true, undefined>;
545
565
  }, undefined>, v.StrictObjectSchema<{
566
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
546
567
  readonly is_not_empty: v.LiteralSchema<true, undefined>;
547
- }, undefined>], undefined>], undefined>;
568
+ }, undefined>], undefined>;
548
569
  }, undefined>, v.StrictObjectSchema<{
549
570
  readonly propertyId: v.StringSchema<undefined>;
550
571
  readonly people: v.UnionSchema<[v.StrictObjectSchema<{
@@ -743,20 +764,27 @@ export declare const resolvedCustomBlockDataSourceFilterSchema: v.UnionSchema<[v
743
764
  }, undefined>, v.StrictObjectSchema<{
744
765
  readonly propertyId: v.StringSchema<undefined>;
745
766
  readonly date: v.UnionSchema<[v.StrictObjectSchema<{
767
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
746
768
  readonly equals: v.StringSchema<undefined>;
747
769
  }, undefined>, v.StrictObjectSchema<{
770
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
748
771
  readonly before: v.StringSchema<undefined>;
749
772
  }, undefined>, v.StrictObjectSchema<{
773
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
750
774
  readonly after: v.StringSchema<undefined>;
751
775
  }, undefined>, v.StrictObjectSchema<{
776
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
752
777
  readonly on_or_before: v.StringSchema<undefined>;
753
778
  }, undefined>, v.StrictObjectSchema<{
779
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
754
780
  readonly on_or_after: v.StringSchema<undefined>;
755
- }, undefined>, v.UnionSchema<[v.StrictObjectSchema<{
781
+ }, undefined>, v.StrictObjectSchema<{
782
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
756
783
  readonly is_empty: v.LiteralSchema<true, undefined>;
757
784
  }, undefined>, v.StrictObjectSchema<{
785
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
758
786
  readonly is_not_empty: v.LiteralSchema<true, undefined>;
759
- }, undefined>], undefined>], undefined>;
787
+ }, undefined>], undefined>;
760
788
  }, undefined>, v.StrictObjectSchema<{
761
789
  readonly propertyId: v.StringSchema<undefined>;
762
790
  readonly people: v.UnionSchema<[v.StrictObjectSchema<{
@@ -980,20 +1008,27 @@ export declare const queryDataSourceMessageSchema: v.ObjectSchema<{
980
1008
  }, undefined>, v.StrictObjectSchema<{
981
1009
  readonly propertyId: v.StringSchema<undefined>;
982
1010
  readonly date: v.UnionSchema<[v.StrictObjectSchema<{
1011
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
983
1012
  readonly equals: v.StringSchema<undefined>;
984
1013
  }, undefined>, v.StrictObjectSchema<{
1014
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
985
1015
  readonly before: v.StringSchema<undefined>;
986
1016
  }, undefined>, v.StrictObjectSchema<{
1017
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
987
1018
  readonly after: v.StringSchema<undefined>;
988
1019
  }, undefined>, v.StrictObjectSchema<{
1020
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
989
1021
  readonly on_or_before: v.StringSchema<undefined>;
990
1022
  }, undefined>, v.StrictObjectSchema<{
1023
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
991
1024
  readonly on_or_after: v.StringSchema<undefined>;
992
- }, undefined>, v.UnionSchema<[v.StrictObjectSchema<{
1025
+ }, undefined>, v.StrictObjectSchema<{
1026
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
993
1027
  readonly is_empty: v.LiteralSchema<true, undefined>;
994
1028
  }, undefined>, v.StrictObjectSchema<{
1029
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
995
1030
  readonly is_not_empty: v.LiteralSchema<true, undefined>;
996
- }, undefined>], undefined>], undefined>;
1031
+ }, undefined>], undefined>;
997
1032
  }, undefined>, v.StrictObjectSchema<{
998
1033
  readonly propertyId: v.StringSchema<undefined>;
999
1034
  readonly people: v.UnionSchema<[v.StrictObjectSchema<{
@@ -1192,20 +1227,27 @@ export declare const queryDataSourceMessageSchema: v.ObjectSchema<{
1192
1227
  }, undefined>, v.StrictObjectSchema<{
1193
1228
  readonly propertyId: v.StringSchema<undefined>;
1194
1229
  readonly date: v.UnionSchema<[v.StrictObjectSchema<{
1230
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
1195
1231
  readonly equals: v.StringSchema<undefined>;
1196
1232
  }, undefined>, v.StrictObjectSchema<{
1233
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
1197
1234
  readonly before: v.StringSchema<undefined>;
1198
1235
  }, undefined>, v.StrictObjectSchema<{
1236
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
1199
1237
  readonly after: v.StringSchema<undefined>;
1200
1238
  }, undefined>, v.StrictObjectSchema<{
1239
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
1201
1240
  readonly on_or_before: v.StringSchema<undefined>;
1202
1241
  }, undefined>, v.StrictObjectSchema<{
1242
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
1203
1243
  readonly on_or_after: v.StringSchema<undefined>;
1204
- }, undefined>, v.UnionSchema<[v.StrictObjectSchema<{
1244
+ }, undefined>, v.StrictObjectSchema<{
1245
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
1205
1246
  readonly is_empty: v.LiteralSchema<true, undefined>;
1206
1247
  }, undefined>, v.StrictObjectSchema<{
1248
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
1207
1249
  readonly is_not_empty: v.LiteralSchema<true, undefined>;
1208
- }, undefined>], undefined>], undefined>;
1250
+ }, undefined>], undefined>;
1209
1251
  }, undefined>, v.StrictObjectSchema<{
1210
1252
  readonly propertyId: v.StringSchema<undefined>;
1211
1253
  readonly people: v.UnionSchema<[v.StrictObjectSchema<{
@@ -82,13 +82,36 @@ export const customBlockContainsFilterOperatorSchema = v.union([
82
82
  v.strictObject({ does_not_contain: stringOrStringArraySchema }),
83
83
  emptyOperatorSchema,
84
84
  ]);
85
+ const dateTargetSchema = v.picklist(["start_date", "end_date"]);
85
86
  export const customBlockDateFilterOperatorSchema = v.union([
86
- v.strictObject({ equals: v.string() }),
87
- v.strictObject({ before: v.string() }),
88
- v.strictObject({ after: v.string() }),
89
- v.strictObject({ on_or_before: v.string() }),
90
- v.strictObject({ on_or_after: v.string() }),
91
- emptyOperatorSchema,
87
+ v.strictObject({
88
+ target: v.optional(dateTargetSchema),
89
+ equals: v.string(),
90
+ }),
91
+ v.strictObject({
92
+ target: v.optional(dateTargetSchema),
93
+ before: v.string(),
94
+ }),
95
+ v.strictObject({
96
+ target: v.optional(dateTargetSchema),
97
+ after: v.string(),
98
+ }),
99
+ v.strictObject({
100
+ target: v.optional(dateTargetSchema),
101
+ on_or_before: v.string(),
102
+ }),
103
+ v.strictObject({
104
+ target: v.optional(dateTargetSchema),
105
+ on_or_after: v.string(),
106
+ }),
107
+ v.strictObject({
108
+ target: v.optional(dateTargetSchema),
109
+ is_empty: v.literal(true),
110
+ }),
111
+ v.strictObject({
112
+ target: v.optional(dateTargetSchema),
113
+ is_not_empty: v.literal(true),
114
+ }),
92
115
  ]);
93
116
  export const resolvedCustomBlockDataSourcePropertyFilterSchema = v.union([
94
117
  v.strictObject({
@@ -238,20 +238,27 @@ export declare const sandboxToHostMessageSchema: v.VariantSchema<"type", [v.Vari
238
238
  }, undefined>, v.StrictObjectSchema<{
239
239
  readonly propertyId: v.StringSchema<undefined>;
240
240
  readonly date: v.UnionSchema<[v.StrictObjectSchema<{
241
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
241
242
  readonly equals: v.StringSchema<undefined>;
242
243
  }, undefined>, v.StrictObjectSchema<{
244
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
243
245
  readonly before: v.StringSchema<undefined>;
244
246
  }, undefined>, v.StrictObjectSchema<{
247
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
245
248
  readonly after: v.StringSchema<undefined>;
246
249
  }, undefined>, v.StrictObjectSchema<{
250
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
247
251
  readonly on_or_before: v.StringSchema<undefined>;
248
252
  }, undefined>, v.StrictObjectSchema<{
253
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
249
254
  readonly on_or_after: v.StringSchema<undefined>;
250
- }, undefined>, v.UnionSchema<[v.StrictObjectSchema<{
255
+ }, undefined>, v.StrictObjectSchema<{
256
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
251
257
  readonly is_empty: v.LiteralSchema<true, undefined>;
252
258
  }, undefined>, v.StrictObjectSchema<{
259
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
253
260
  readonly is_not_empty: v.LiteralSchema<true, undefined>;
254
- }, undefined>], undefined>], undefined>;
261
+ }, undefined>], undefined>;
255
262
  }, undefined>, v.StrictObjectSchema<{
256
263
  readonly propertyId: v.StringSchema<undefined>;
257
264
  readonly people: v.UnionSchema<[v.StrictObjectSchema<{
@@ -450,20 +457,27 @@ export declare const sandboxToHostMessageSchema: v.VariantSchema<"type", [v.Vari
450
457
  }, undefined>, v.StrictObjectSchema<{
451
458
  readonly propertyId: v.StringSchema<undefined>;
452
459
  readonly date: v.UnionSchema<[v.StrictObjectSchema<{
460
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
453
461
  readonly equals: v.StringSchema<undefined>;
454
462
  }, undefined>, v.StrictObjectSchema<{
463
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
455
464
  readonly before: v.StringSchema<undefined>;
456
465
  }, undefined>, v.StrictObjectSchema<{
466
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
457
467
  readonly after: v.StringSchema<undefined>;
458
468
  }, undefined>, v.StrictObjectSchema<{
469
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
459
470
  readonly on_or_before: v.StringSchema<undefined>;
460
471
  }, undefined>, v.StrictObjectSchema<{
472
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
461
473
  readonly on_or_after: v.StringSchema<undefined>;
462
- }, undefined>, v.UnionSchema<[v.StrictObjectSchema<{
474
+ }, undefined>, v.StrictObjectSchema<{
475
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
463
476
  readonly is_empty: v.LiteralSchema<true, undefined>;
464
477
  }, undefined>, v.StrictObjectSchema<{
478
+ readonly target: v.OptionalSchema<v.PicklistSchema<["start_date", "end_date"], undefined>, undefined>;
465
479
  readonly is_not_empty: v.LiteralSchema<true, undefined>;
466
- }, undefined>], undefined>], undefined>;
480
+ }, undefined>], undefined>;
467
481
  }, undefined>, v.StrictObjectSchema<{
468
482
  readonly propertyId: v.StringSchema<undefined>;
469
483
  readonly people: v.UnionSchema<[v.StrictObjectSchema<{
@@ -12,7 +12,8 @@ export declare class QuerySubscriptions {
12
12
  subscribe(message: QueryDataSourceMessage): QuerySubscriptionToken;
13
13
  isCurrent(subscriptionId: string, token: QuerySubscriptionToken): boolean;
14
14
  unsubscribe(subscriptionId: string): void;
15
- refresh(dataSourceId: NotionDataSourceId): QueryRefresh[];
15
+ refresh(dataSourceId: NotionDataSourceId): QueryRefresh[] | undefined;
16
+ finish(subscriptionId: string, token: QuerySubscriptionToken): QueryRefresh | undefined;
16
17
  unsubscribeAll(): void;
17
18
  }
18
19
  //# sourceMappingURL=querySubscriptions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"querySubscriptions.d.ts","sourceRoot":"","sources":["../../src/queries/querySubscriptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAA;AACjF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,8DAA8D,CAAA;AAE1G,MAAM,MAAM,YAAY,GAAG;IAC1B,OAAO,EAAE,sBAAsB,CAAA;IAC/B,KAAK,EAAE,sBAAsB,CAAA;CAC7B,CAAA;AAED,MAAM,MAAM,sBAAsB,GAAG;IACpC,QAAQ,CAAC,IAAI,EAAE,wBAAwB,CAAA;CACvC,CAAA;AAOD,qBAAa,kBAAkB;IAC9B,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAA4C;IAE7E,SAAS,CAAC,OAAO,EAAE,sBAAsB,GAAG,sBAAsB,CASjE;IAED,SAAS,CAAC,cAAc,EAAE,MAAM,EAAE,KAAK,EAAE,sBAAsB,GAAG,OAAO,CAExE;IAED,WAAW,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,CAExC;IAED,OAAO,CAAC,YAAY,EAAE,kBAAkB,GAAG,YAAY,EAAE,CAgBxD;IAED,cAAc,SAEb;CACD"}
1
+ {"version":3,"file":"querySubscriptions.d.ts","sourceRoot":"","sources":["../../src/queries/querySubscriptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAA;AACjF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,8DAA8D,CAAA;AAE1G,MAAM,MAAM,YAAY,GAAG;IAC1B,OAAO,EAAE,sBAAsB,CAAA;IAC/B,KAAK,EAAE,sBAAsB,CAAA;CAC7B,CAAA;AAED,MAAM,MAAM,sBAAsB,GAAG;IACpC,QAAQ,CAAC,IAAI,EAAE,wBAAwB,CAAA;CACvC,CAAA;AASD,qBAAa,kBAAkB;IAC9B,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAA4C;IAE7E,SAAS,CAAC,OAAO,EAAE,sBAAsB,GAAG,sBAAsB,CAWjE;IAED,SAAS,CAAC,cAAc,EAAE,MAAM,EAAE,KAAK,EAAE,sBAAsB,GAAG,OAAO,CAExE;IAED,WAAW,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,CAExC;IAED,OAAO,CAAC,YAAY,EAAE,kBAAkB,GAAG,YAAY,EAAE,GAAG,SAAS,CAmBpE;IAED,MAAM,CACL,cAAc,EAAE,MAAM,EACtB,KAAK,EAAE,sBAAsB,GAC3B,YAAY,GAAG,SAAS,CAY1B;IAED,cAAc,SAEb;CACD"}
@@ -7,6 +7,8 @@ export class QuerySubscriptions {
7
7
  this.bySubscriptionId.set(message.subscriptionId, {
8
8
  message,
9
9
  token,
10
+ isRefreshing: true,
11
+ shouldRefreshAgain: false,
10
12
  });
11
13
  return token;
12
14
  }
@@ -18,20 +20,36 @@ export class QuerySubscriptions {
18
20
  }
19
21
  refresh(dataSourceId) {
20
22
  const refreshes = [];
23
+ let hasSubscriptions = false;
21
24
  for (const queryState of this.bySubscriptionId.values()) {
22
25
  if (queryState.message.dataSourceId !== dataSourceId) {
23
26
  continue;
24
27
  }
25
- const token = {
26
- _tag: "QuerySubscriptionToken",
27
- };
28
- queryState.token = token;
28
+ hasSubscriptions = true;
29
+ if (queryState.isRefreshing) {
30
+ queryState.shouldRefreshAgain = true;
31
+ continue;
32
+ }
33
+ queryState.isRefreshing = true;
29
34
  refreshes.push({
30
35
  message: queryState.message,
31
- token,
36
+ token: queryState.token,
32
37
  });
33
38
  }
34
- return refreshes;
39
+ return hasSubscriptions ? refreshes : undefined;
40
+ }
41
+ finish(subscriptionId, token) {
42
+ const state = this.bySubscriptionId.get(subscriptionId);
43
+ if (state?.token !== token) {
44
+ return undefined;
45
+ }
46
+ state.isRefreshing = false;
47
+ if (!state.shouldRefreshAgain) {
48
+ return undefined;
49
+ }
50
+ state.shouldRefreshAgain = false;
51
+ state.isRefreshing = true;
52
+ return { message: state.message, token: state.token };
35
53
  }
36
54
  unsubscribeAll() {
37
55
  this.bySubscriptionId.clear();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@notionhq/custom-blocks-host",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "Reusable host runtime for Notion custom blocks.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -247,28 +247,35 @@ export function createCustomBlockHost(
247
247
  message: QueryDataSourceMessage,
248
248
  token: QuerySubscriptionToken = querySubscriptions.subscribe(message),
249
249
  ) {
250
- const collectionSchema = getCollectionSchema(
251
- activeDataSources,
252
- message.dataSourceId,
253
- )
254
- const queryError = getQueryValidationError(message, collectionSchema)
255
- if (queryError !== undefined) {
256
- if (querySubscriptions.isCurrent(message.subscriptionId, token)) {
257
- postQueryDataSourceResult({
258
- subscriptionId: message.subscriptionId,
259
- response: { status: "error", error: queryError },
260
- })
250
+ try {
251
+ const collectionSchema = getCollectionSchema(
252
+ activeDataSources,
253
+ message.dataSourceId,
254
+ )
255
+ const queryError = getQueryValidationError(message, collectionSchema)
256
+ if (queryError !== undefined) {
257
+ if (querySubscriptions.isCurrent(message.subscriptionId, token)) {
258
+ postQueryDataSourceResult({
259
+ subscriptionId: message.subscriptionId,
260
+ response: { status: "error", error: queryError },
261
+ })
262
+ }
263
+ return
264
+ }
265
+ const response = await handlers.queryDataSource(message)
266
+ if (!querySubscriptions.isCurrent(message.subscriptionId, token)) {
267
+ return
268
+ }
269
+ postQueryDataSourceResult({
270
+ subscriptionId: message.subscriptionId,
271
+ response,
272
+ })
273
+ } finally {
274
+ const refresh = querySubscriptions.finish(message.subscriptionId, token)
275
+ if (refresh !== undefined) {
276
+ void handleQuery(refresh.message, refresh.token)
261
277
  }
262
- return
263
- }
264
- const response = await handlers.queryDataSource(message)
265
- if (!querySubscriptions.isCurrent(message.subscriptionId, token)) {
266
- return
267
278
  }
268
- postQueryDataSourceResult({
269
- subscriptionId: message.subscriptionId,
270
- response,
271
- })
272
279
  }
273
280
 
274
281
  function updateHostState(update: HostStateUpdates) {
@@ -487,7 +494,7 @@ export function createCustomBlockHost(
487
494
  dataSourceId,
488
495
  )
489
496
  const refreshes = querySubscriptions.refresh(normalizedDataSourceId)
490
- if (refreshes.length === 0) {
497
+ if (refreshes === undefined) {
491
498
  emit("warn", `No active query exists for data source "${dataSourceId}"`)
492
499
  return
493
500
  }
@@ -13,6 +13,8 @@ export type QuerySubscriptionToken = {
13
13
  type QuerySubscriptionState = {
14
14
  message: QueryDataSourceMessage
15
15
  token: QuerySubscriptionToken
16
+ isRefreshing: boolean
17
+ shouldRefreshAgain: boolean
16
18
  }
17
19
 
18
20
  export class QuerySubscriptions {
@@ -25,6 +27,8 @@ export class QuerySubscriptions {
25
27
  this.bySubscriptionId.set(message.subscriptionId, {
26
28
  message,
27
29
  token,
30
+ isRefreshing: true,
31
+ shouldRefreshAgain: false,
28
32
  })
29
33
  return token
30
34
  }
@@ -37,22 +41,42 @@ export class QuerySubscriptions {
37
41
  this.bySubscriptionId.delete(subscriptionId)
38
42
  }
39
43
 
40
- refresh(dataSourceId: NotionDataSourceId): QueryRefresh[] {
44
+ refresh(dataSourceId: NotionDataSourceId): QueryRefresh[] | undefined {
41
45
  const refreshes: QueryRefresh[] = []
46
+ let hasSubscriptions = false
42
47
  for (const queryState of this.bySubscriptionId.values()) {
43
48
  if (queryState.message.dataSourceId !== dataSourceId) {
44
49
  continue
45
50
  }
46
- const token: QuerySubscriptionToken = {
47
- _tag: "QuerySubscriptionToken",
51
+ hasSubscriptions = true
52
+ if (queryState.isRefreshing) {
53
+ queryState.shouldRefreshAgain = true
54
+ continue
48
55
  }
49
- queryState.token = token
56
+ queryState.isRefreshing = true
50
57
  refreshes.push({
51
58
  message: queryState.message,
52
- token,
59
+ token: queryState.token,
53
60
  })
54
61
  }
55
- return refreshes
62
+ return hasSubscriptions ? refreshes : undefined
63
+ }
64
+
65
+ finish(
66
+ subscriptionId: string,
67
+ token: QuerySubscriptionToken,
68
+ ): QueryRefresh | undefined {
69
+ const state = this.bySubscriptionId.get(subscriptionId)
70
+ if (state?.token !== token) {
71
+ return undefined
72
+ }
73
+ state.isRefreshing = false
74
+ if (!state.shouldRefreshAgain) {
75
+ return undefined
76
+ }
77
+ state.shouldRefreshAgain = false
78
+ state.isRefreshing = true
79
+ return { message: state.message, token: state.token }
56
80
  }
57
81
 
58
82
  unsubscribeAll() {