@notionhq/custom-blocks-dev-shell 0.4.4 → 0.6.0

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.
@@ -410,6 +410,96 @@ function custom(check$1, message$1) {
410
410
  });
411
411
  }
412
412
  // @__NO_SIDE_EFFECTS__
413
+ function exactOptional(wrapped, default_) {
414
+ return _standardSchema({
415
+ kind: "schema",
416
+ type: "exact_optional",
417
+ reference: exactOptional,
418
+ expects: wrapped.expects,
419
+ async: false,
420
+ wrapped,
421
+ default: default_,
422
+ "~run"(dataset, config$1) {
423
+ return this.wrapped["~run"](dataset, config$1);
424
+ }
425
+ });
426
+ }
427
+ // @__NO_SIDE_EFFECTS__
428
+ function _merge(value1, value2) {
429
+ if (typeof value1 === typeof value2) {
430
+ if (/* @__PURE__ */ _isSameValueZero(value1, value2) || value1 instanceof Date && value2 instanceof Date && /* @__PURE__ */ _isSameValueZero(+value1, +value2)) return { value: value1 };
431
+ if (value1 && value2 && value1.constructor === Object && value2.constructor === Object) {
432
+ const nextValue = {
433
+ ...value1,
434
+ ...value2
435
+ };
436
+ for (const key in value2) if (Object.prototype.hasOwnProperty.call(value1, key) && Object.prototype.hasOwnProperty.call(value2, key)) {
437
+ const dataset = /* @__PURE__ */ _merge(value1[key], value2[key]);
438
+ if (dataset.issue) return dataset;
439
+ nextValue[key] = dataset.value;
440
+ }
441
+ return { value: nextValue };
442
+ }
443
+ if (Array.isArray(value1) && Array.isArray(value2)) {
444
+ if (value1.length === value2.length) {
445
+ const nextValue = [...value1];
446
+ for (let index = 0; index < value1.length; index++) {
447
+ const dataset = /* @__PURE__ */ _merge(value1[index], value2[index]);
448
+ if (dataset.issue) return dataset;
449
+ nextValue[index] = dataset.value;
450
+ }
451
+ return { value: nextValue };
452
+ }
453
+ }
454
+ }
455
+ return { issue: true };
456
+ }
457
+ // @__NO_SIDE_EFFECTS__
458
+ function intersect(options, message$1) {
459
+ return _standardSchema({
460
+ kind: "schema",
461
+ type: "intersect",
462
+ reference: intersect,
463
+ expects: /* @__PURE__ */ _joinExpects(options.map((option) => option.expects), "&"),
464
+ async: false,
465
+ options,
466
+ message: message$1,
467
+ "~run"(dataset, config$1) {
468
+ if (this.options.length) {
469
+ const input = dataset.value;
470
+ let outputs;
471
+ dataset.typed = true;
472
+ for (const schema of this.options) {
473
+ const optionDataset = schema["~run"]({ value: input }, config$1);
474
+ if (optionDataset.issues) {
475
+ if (dataset.issues) for (const issue of optionDataset.issues) dataset.issues.push(issue);
476
+ else dataset.issues = optionDataset.issues;
477
+ if (config$1.abortEarly) {
478
+ dataset.typed = false;
479
+ break;
480
+ }
481
+ }
482
+ if (!optionDataset.typed) dataset.typed = false;
483
+ if (dataset.typed) if (outputs) outputs.push(optionDataset.value);
484
+ else outputs = [optionDataset.value];
485
+ }
486
+ if (dataset.typed) {
487
+ dataset.value = outputs[0];
488
+ for (let index = 1; index < outputs.length; index++) {
489
+ const mergeDataset = /* @__PURE__ */ _merge(dataset.value, outputs[index]);
490
+ if (mergeDataset.issue) {
491
+ _addIssue(this, "type", dataset, config$1, { received: "unknown" });
492
+ break;
493
+ }
494
+ dataset.value = mergeDataset.value;
495
+ }
496
+ }
497
+ } else _addIssue(this, "type", dataset, config$1);
498
+ return dataset;
499
+ }
500
+ });
501
+ }
502
+ // @__NO_SIDE_EFFECTS__
413
503
  function literal(literal_, message$1) {
414
504
  return _standardSchema({
415
505
  kind: "schema",
@@ -492,6 +582,22 @@ function looseObject(entries$1, message$1) {
492
582
  });
493
583
  }
494
584
  // @__NO_SIDE_EFFECTS__
585
+ function nan(message$1) {
586
+ return _standardSchema({
587
+ kind: "schema",
588
+ type: "nan",
589
+ reference: nan,
590
+ expects: "NaN",
591
+ async: false,
592
+ message: message$1,
593
+ "~run"(dataset, config$1) {
594
+ if (Number.isNaN(dataset.value)) dataset.typed = true;
595
+ else _addIssue(this, "type", dataset, config$1);
596
+ return dataset;
597
+ }
598
+ });
599
+ }
600
+ // @__NO_SIDE_EFFECTS__
495
601
  function never(message$1) {
496
602
  return _standardSchema({
497
603
  kind: "schema",
@@ -524,6 +630,22 @@ function nonOptional(wrapped, message$1) {
524
630
  });
525
631
  }
526
632
  // @__NO_SIDE_EFFECTS__
633
+ function null_(message$1) {
634
+ return _standardSchema({
635
+ kind: "schema",
636
+ type: "null",
637
+ reference: null_,
638
+ expects: "null",
639
+ async: false,
640
+ message: message$1,
641
+ "~run"(dataset, config$1) {
642
+ if (dataset.value === null) dataset.typed = true;
643
+ else _addIssue(this, "type", dataset, config$1);
644
+ return dataset;
645
+ }
646
+ });
647
+ }
648
+ // @__NO_SIDE_EFFECTS__
527
649
  function nullable(wrapped, default_) {
528
650
  return _standardSchema({
529
651
  kind: "schema",
@@ -960,6 +1082,15 @@ function parse(schema, input, config$1) {
960
1082
  return dataset.value;
961
1083
  }
962
1084
  // @__NO_SIDE_EFFECTS__
1085
+ function partial(schema, keys) {
1086
+ const entries$1 = {};
1087
+ for (const key in schema.entries) entries$1[key] = !keys || keys.includes(key) ? /* @__PURE__ */ optional(schema.entries[key]) : schema.entries[key];
1088
+ return _standardSchema({
1089
+ ...schema,
1090
+ entries: entries$1
1091
+ });
1092
+ }
1093
+ // @__NO_SIDE_EFFECTS__
963
1094
  function pipe(...pipe$1) {
964
1095
  return _standardSchema({
965
1096
  ...pipe$1[0],
@@ -998,6 +1129,17 @@ function safeParse(schema, input, config$1) {
998
1129
  };
999
1130
  }
1000
1131
 
1132
+ // ../protocol/src/utils/unknownPropertyTypeSchema.ts
1133
+ var unknownPropertyTypeSchema = pipe(
1134
+ string(),
1135
+ minLength(1),
1136
+ check(
1137
+ (type) => type !== "unknown" && // Reserved for the placeholder's `type`. `originalType` carries the source type.
1138
+ // These values exist in Notion but are unsupported in custom blocks.
1139
+ type !== "last_visited_time" && type !== "location"
1140
+ )
1141
+ );
1142
+
1001
1143
  // ../protocol/src/dataSources/properties/propertySchema.ts
1002
1144
  var knownNotionPropertyColorSchema = picklist([
1003
1145
  "default",
@@ -1028,13 +1170,13 @@ var notionPropertyOptionSchema = object({
1028
1170
  color: optional(notionPropertyColorSchema),
1029
1171
  description: optional(string())
1030
1172
  });
1031
- var notionStatusGroupSchema = object({
1173
+ var bridgeStatusGroupSchema = object({
1032
1174
  id: string(),
1033
1175
  name: string(),
1034
1176
  color: optional(notionPropertyColorSchema),
1035
1177
  option_ids: array(string())
1036
1178
  });
1037
- var notionDualPropertySchema = object({
1179
+ var bridgeDualPropertySchema = object({
1038
1180
  synced_property_id: string(),
1039
1181
  synced_property_name: string()
1040
1182
  });
@@ -1069,7 +1211,22 @@ var NOTION_PROPERTY_TYPES = [
1069
1211
  "last_edited_by"
1070
1212
  ];
1071
1213
  var notionPropertyTypeSchema = picklist(NOTION_PROPERTY_TYPES);
1072
- var notionPropertySchemaSchema = variant("type", [
1214
+ var CUSTOM_BLOCK_DATA_SOURCE_SORTABLE_PROPERTY_TYPES = [
1215
+ "title",
1216
+ "rich_text",
1217
+ "number",
1218
+ "checkbox",
1219
+ "url",
1220
+ "email",
1221
+ "phone_number",
1222
+ "date",
1223
+ "created_time",
1224
+ "last_edited_time",
1225
+ "people",
1226
+ "created_by",
1227
+ "last_edited_by"
1228
+ ];
1229
+ var knownBridgePropertySchema = variant("type", [
1073
1230
  object({ ...baseProp.entries, type: literal("title") }),
1074
1231
  object({ ...baseProp.entries, type: literal("rich_text") }),
1075
1232
  object({ ...baseProp.entries, type: literal("number") }),
@@ -1091,7 +1248,7 @@ var notionPropertySchemaSchema = variant("type", [
1091
1248
  ...baseProp.entries,
1092
1249
  type: literal("status"),
1093
1250
  options: array(notionPropertyOptionSchema),
1094
- groups: array(notionStatusGroupSchema)
1251
+ groups: array(bridgeStatusGroupSchema)
1095
1252
  }),
1096
1253
  object({ ...baseProp.entries, type: literal("date") }),
1097
1254
  object({ ...baseProp.entries, type: literal("people") }),
@@ -1101,7 +1258,7 @@ var notionPropertySchemaSchema = variant("type", [
1101
1258
  ...baseProp.entries,
1102
1259
  type: literal("relation"),
1103
1260
  data_source_id: optional(string()),
1104
- dual_property: optional(notionDualPropertySchema)
1261
+ dual_property: optional(bridgeDualPropertySchema)
1105
1262
  }),
1106
1263
  object({ ...baseProp.entries, type: literal("place") }),
1107
1264
  object({ ...baseProp.entries, type: literal("formula") }),
@@ -1115,6 +1272,28 @@ var notionPropertySchemaSchema = variant("type", [
1115
1272
  object({ ...baseProp.entries, type: literal("created_by") }),
1116
1273
  object({ ...baseProp.entries, type: literal("last_edited_by") })
1117
1274
  ]);
1275
+ var bridgeUnknownPropertySchema = object({
1276
+ ...baseProp.entries,
1277
+ type: literal("unknown"),
1278
+ originalType: unknownPropertyTypeSchema
1279
+ });
1280
+ var futurePropertySchema = pipe(
1281
+ object({ ...baseProp.entries, type: unknownPropertyTypeSchema }),
1282
+ check(({ type }) => !is(notionPropertyTypeSchema, type)),
1283
+ transform(
1284
+ ({ name, description, type }) => ({
1285
+ name,
1286
+ description,
1287
+ type: "unknown",
1288
+ originalType: type
1289
+ })
1290
+ )
1291
+ );
1292
+ var bridgePropertySchema = union([
1293
+ knownBridgePropertySchema,
1294
+ bridgeUnknownPropertySchema,
1295
+ futurePropertySchema
1296
+ ]);
1118
1297
 
1119
1298
  // ../protocol/src/manifest/grants.ts
1120
1299
  var customBlockGrantSchema = object({
@@ -1305,10 +1484,24 @@ var pageParentSchema = object({
1305
1484
  type: literal("page_id"),
1306
1485
  page_id: notionPageIdSchema
1307
1486
  });
1487
+ var pageKeyParentSchema = strictObject({
1488
+ type: literal("page_key"),
1489
+ pageKey: string()
1490
+ });
1491
+ var pageKindParentSchema = strictObject({
1492
+ type: literal("page")
1493
+ });
1308
1494
  var dataSourceParentSchema = object({
1309
1495
  type: literal("data_source_id"),
1310
1496
  data_source_id: notionDataSourceIdSchema
1311
1497
  });
1498
+ var dataSourceKeyParentSchema = strictObject({
1499
+ type: literal("data_source_key"),
1500
+ key: string()
1501
+ });
1502
+ var dataSourceKindParentSchema = strictObject({
1503
+ type: literal("data_source")
1504
+ });
1312
1505
  var workspaceParentSchema = object({
1313
1506
  type: literal("workspace"),
1314
1507
  workspace: literal(true)
@@ -1326,7 +1519,7 @@ var appInstallationParentSchema = object({
1326
1519
  app_installation_id: notionAppInstallationIdSchema
1327
1520
  });
1328
1521
  var unavailableParentSchema = object({ type: literal("unavailable") });
1329
- var notionParentSchema = variant("type", [
1522
+ var parentThroughProtocol13Schema = variant("type", [
1330
1523
  pageParentSchema,
1331
1524
  dataSourceParentSchema,
1332
1525
  workspaceParentSchema,
@@ -1335,6 +1528,13 @@ var notionParentSchema = variant("type", [
1335
1528
  appInstallationParentSchema,
1336
1529
  unavailableParentSchema
1337
1530
  ]);
1531
+ var notionParentSchema = variant("type", [
1532
+ ...parentThroughProtocol13Schema.options,
1533
+ pageKeyParentSchema,
1534
+ pageKindParentSchema,
1535
+ dataSourceKindParentSchema,
1536
+ dataSourceKeyParentSchema
1537
+ ]);
1338
1538
 
1339
1539
  // ../protocol/src/dataSources/dataSourcePointer.ts
1340
1540
  var dataSourcePointerValidator = object({
@@ -1344,15 +1544,18 @@ var dataSourcePointerValidator = object({
1344
1544
  });
1345
1545
 
1346
1546
  // ../protocol/src/dataSources/dataSourceSchema.ts
1347
- var notionDataSourceSchemaValidator = object({
1348
- id: optional(notionDataSourceIdSchema),
1349
- /**
1350
- * Describes actual database properties in protocol 5. Protocol 3/4 payloads can also include
1351
- * synthetic metadata for compatibility. Use this map to resolve property bindings. Use this map
1352
- * to validate filter and sort references.
1353
- */
1354
- propertiesById: record(string(), notionPropertySchemaSchema)
1355
- });
1547
+ var bridgeDataSourceSchemaValidator = makeNotionDataSourceSchemaValidator(bridgePropertySchema);
1548
+ function makeNotionDataSourceSchemaValidator(propertySchema) {
1549
+ return object({
1550
+ id: optional(notionDataSourceIdSchema),
1551
+ /**
1552
+ * Describes actual database properties in protocol 5. Protocol 3/4 payloads can also include
1553
+ * synthetic metadata for compatibility. Use this map to resolve property bindings. Use this map
1554
+ * to validate filter and sort references.
1555
+ */
1556
+ propertiesById: record(string(), propertySchema)
1557
+ });
1558
+ }
1356
1559
 
1357
1560
  // ../protocol/src/dataSources/bridgeDataSourceBinding.ts
1358
1561
  var bridgeDataSourceBindingSchema = object({
@@ -1362,7 +1565,7 @@ var bridgeDataSourceBindingSchema = object({
1362
1565
  * schema to validate filter and sort references. Undefined when the host does not provide a
1363
1566
  * database schema.
1364
1567
  */
1365
- dataSourceSchema: optional(notionDataSourceSchemaValidator),
1568
+ dataSourceSchema: optional(bridgeDataSourceSchemaValidator),
1366
1569
  /**
1367
1570
  * Maps user-defined property keys to database property IDs. Use this map to resolve a key
1368
1571
  * such as `name` to its database property ID. A value of `undefined` marks a declared
@@ -1442,7 +1645,7 @@ var protocol3To11ContainingPageSchema = variant("type", [
1442
1645
  object({
1443
1646
  type: literal("page"),
1444
1647
  id: notionPageIdSchema,
1445
- parent: notionParentSchema
1648
+ parent: parentThroughProtocol13Schema
1446
1649
  })
1447
1650
  ]);
1448
1651
  var protocol3To11PageChangedMessageSchema = object({
@@ -1458,7 +1661,7 @@ var protocol3To11InitSuccessMessageSchema = object({
1458
1661
  theme: notionThemeSchema,
1459
1662
  contrastMode: notionContrastModeSchema,
1460
1663
  blockId: notionBlockIdSchema,
1461
- parent: notionParentSchema,
1664
+ parent: parentThroughProtocol13Schema,
1462
1665
  page: protocol3To11ContainingPageSchema,
1463
1666
  manifest: manifestSchema,
1464
1667
  dataSources: object({
@@ -1511,12 +1714,6 @@ var initResultMessageWithCompatibilitySchema = union([
1511
1714
  protocol3To11InitResultMessageSchema
1512
1715
  ]);
1513
1716
 
1514
- // ../protocol/src/context/messages/contrastModeChanged.ts
1515
- var contrastModeChangedMessageSchema = object({
1516
- type: literal("contrastModeChanged"),
1517
- contrastMode: notionContrastModeSchema
1518
- });
1519
-
1520
1717
  // ../protocol/src/context/containingPage.ts
1521
1718
  var containingPageSchema = variant("type", [
1522
1719
  /** The viewer cannot access the containing page. Its ID and parent are not exposed. */
@@ -1538,11 +1735,25 @@ var containingPageSchema = variant("type", [
1538
1735
  )
1539
1736
  })
1540
1737
  ]);
1738
+ var containingPageContextSchema = variant("type", [
1739
+ strictObject({ type: literal("unavailable") }),
1740
+ strictObject({
1741
+ type: literal("page"),
1742
+ parent: notionParentSchema,
1743
+ displayMode: containingPageSchema.options[1].entries.displayMode
1744
+ })
1745
+ ]);
1541
1746
 
1542
- // ../protocol/src/context/messages/pageChanged.ts
1543
- var pageChangedMessageSchema = object({
1544
- type: literal("pageChanged"),
1545
- page: containingPageSchema
1747
+ // ../protocol/src/context/messages/containingPageChanged.ts
1748
+ var containingPageChangedMessageSchema = object({
1749
+ type: literal("containingPageChanged"),
1750
+ page: containingPageContextSchema
1751
+ });
1752
+
1753
+ // ../protocol/src/context/messages/contrastModeChanged.ts
1754
+ var contrastModeChangedMessageSchema = object({
1755
+ type: literal("contrastModeChanged"),
1756
+ contrastMode: notionContrastModeSchema
1546
1757
  });
1547
1758
 
1548
1759
  // ../protocol/src/context/messages/pageError.ts
@@ -1569,32 +1780,6 @@ var themeChangedMessageSchema = object({
1569
1780
  theme: notionThemeSchema
1570
1781
  });
1571
1782
 
1572
- // ../protocol/src/dataSources/messages/getDataSource.ts
1573
- var getDataSourceMessageSchema = object({
1574
- type: literal("getDataSource"),
1575
- requestId: string(),
1576
- key: string()
1577
- });
1578
- var getDataSourceResultMessageSchema = variant("status", [
1579
- object({
1580
- type: literal("getDataSourceResult"),
1581
- requestId: string(),
1582
- status: literal("success"),
1583
- binding: required(
1584
- omit(bridgeDataSourceBindingSchema, ["inaccessible"])
1585
- )
1586
- }),
1587
- object({
1588
- type: literal("getDataSourceResult"),
1589
- requestId: string(),
1590
- status: literal("error"),
1591
- error: customBlockErrorInfoSchema
1592
- })
1593
- ]);
1594
- var dataSourcesInvalidatedMessageSchema = object({
1595
- type: literal("dataSourcesInvalidated")
1596
- });
1597
-
1598
1783
  // ../protocol/src/files.ts
1599
1784
  var bridgeExternalFileSchema = object({
1600
1785
  type: literal("external"),
@@ -1671,10 +1856,148 @@ var bridgePageCoverSchema = variant("type", [
1671
1856
  bridgeNotionHostedFileSchema
1672
1857
  ]);
1673
1858
 
1859
+ // ../protocol/src/dataSources/messages/dataSourceChanged.ts
1860
+ var sourcePropertySchema = pipe(
1861
+ bridgePropertySchema,
1862
+ transform((property) => {
1863
+ if (property.type !== "relation") {
1864
+ return property;
1865
+ }
1866
+ const { data_source_id: _dataSourceId2, ...definition } = property;
1867
+ return definition;
1868
+ })
1869
+ );
1870
+ var sourceSnapshotPropertySchema = intersect([
1871
+ object({
1872
+ id: string(),
1873
+ key: optional(string()),
1874
+ restricted: optional(literal(true))
1875
+ }),
1876
+ sourcePropertySchema
1877
+ ]);
1878
+ var availableDataSourceSnapshotSchema = object({
1879
+ type: literal("available"),
1880
+ /** Columns in the viewer's schema. */
1881
+ properties: array(sourceSnapshotPropertySchema),
1882
+ relationTargetKeysByPropertyId: optional(
1883
+ record(string(), string()),
1884
+ () => ({})
1885
+ ),
1886
+ title: optional(string()),
1887
+ description: optional(string()),
1888
+ icon: optional(bridgePageIconSchema)
1889
+ });
1890
+ var settledDataSourceSnapshotSchema = union([
1891
+ availableDataSourceSnapshotSchema,
1892
+ strictObject({ type: literal("not_bound") }),
1893
+ strictObject({ type: literal("unavailable") })
1894
+ ]);
1895
+ var dataSourceSnapshotSchema = union([
1896
+ settledDataSourceSnapshotSchema,
1897
+ strictObject({
1898
+ type: literal("error"),
1899
+ error: customBlockErrorInfoSchema
1900
+ })
1901
+ ]);
1902
+ var dataSourceTargetSchema = strictObject({
1903
+ type: literal("data_source_key"),
1904
+ dataSourceKey: string()
1905
+ });
1906
+ var subscribeToDataSourceMessageSchema = strictObject({
1907
+ type: literal("subscribeToDataSource"),
1908
+ requestId: string(),
1909
+ dataSourceTarget: dataSourceTargetSchema
1910
+ });
1911
+ var unsubscribeFromDataSourceMessageSchema = strictObject({
1912
+ type: literal("unsubscribeFromDataSource"),
1913
+ requestId: string()
1914
+ });
1915
+ var subscribeToDataSourceResultMessageSchema = variant("status", [
1916
+ strictObject({
1917
+ type: literal("subscribeToDataSourceResult"),
1918
+ requestId: string(),
1919
+ status: literal("success")
1920
+ }),
1921
+ strictObject({
1922
+ type: literal("subscribeToDataSourceResult"),
1923
+ requestId: string(),
1924
+ status: literal("error"),
1925
+ error: customBlockErrorInfoSchema
1926
+ })
1927
+ ]);
1928
+ var dataSourceSnapshotChangedMessageSchema = variant("status", [
1929
+ strictObject({
1930
+ type: literal("dataSourceSnapshotChanged"),
1931
+ requestId: string(),
1932
+ status: literal("available"),
1933
+ dataSource: omit(availableDataSourceSnapshotSchema, ["type"])
1934
+ }),
1935
+ strictObject({
1936
+ type: literal("dataSourceSnapshotChanged"),
1937
+ requestId: string(),
1938
+ status: literal("loading")
1939
+ }),
1940
+ strictObject({
1941
+ type: literal("dataSourceSnapshotChanged"),
1942
+ requestId: string(),
1943
+ status: literal("not_bound")
1944
+ }),
1945
+ strictObject({
1946
+ type: literal("dataSourceSnapshotChanged"),
1947
+ requestId: string(),
1948
+ status: literal("unavailable")
1949
+ }),
1950
+ strictObject({
1951
+ type: literal("dataSourceSnapshotChanged"),
1952
+ requestId: string(),
1953
+ status: literal("error"),
1954
+ error: customBlockErrorInfoSchema
1955
+ })
1956
+ ]);
1957
+
1958
+ // ../protocol/src/utils/recordPointer.ts
1959
+ var notionRecordPointerSchema = object({
1960
+ id: string(),
1961
+ table: string()
1962
+ });
1963
+
1964
+ // ../protocol/src/pages/properties/actor.ts
1965
+ var bridgeActorSchema = object({
1966
+ ...notionRecordPointerSchema.entries,
1967
+ spaceId: optional(string())
1968
+ });
1969
+
1970
+ // ../protocol/src/compatibility/pageTextPropertySchemas.ts
1971
+ var textUniqueIdPropertySchema = object({
1972
+ id: string(),
1973
+ type: literal("unique_id"),
1974
+ unique_id: string()
1975
+ });
1976
+ var textVerificationPropertySchema = object({
1977
+ id: string(),
1978
+ type: literal("verification"),
1979
+ verification: string()
1980
+ });
1981
+
1674
1982
  // ../protocol/src/utils/nullableStringSchema.ts
1675
1983
  var nullableStringSchema = nullable(string());
1676
1984
 
1677
- // ../protocol/src/dataSources/properties/dateValue.ts
1985
+ // ../protocol/src/pages/pageAddress.ts
1986
+ var pageReadTargetSchema = variant("type", [
1987
+ strictObject({ type: literal("page_key"), pageKey: string() }),
1988
+ strictObject({
1989
+ type: literal("data_source_descendant"),
1990
+ dataSourceKey: string(),
1991
+ pageId: notionPageIdSchema
1992
+ }),
1993
+ strictObject({ type: literal("containing_page") })
1994
+ ]);
1995
+ var pageAddressSchema = variant("type", [
1996
+ ...pageReadTargetSchema.options,
1997
+ strictObject({ type: literal("page_id"), pageId: notionPageIdSchema })
1998
+ ]);
1999
+
2000
+ // ../protocol/src/dataSources/properties/dateReminders.ts
1678
2001
  var notionDateReminderSchema = object({
1679
2002
  unit: picklist(["year", "month", "week", "day"]),
1680
2003
  value: number(),
@@ -1692,48 +2015,9 @@ var notionDateTimeReminderSchema = union([
1692
2015
  notionDateReminderSchema,
1693
2016
  notionTimeReminderSchema
1694
2017
  ]);
1695
- var dateOrDisabledReminder = optional(
1696
- union([notionDateReminderSchema, notionDisabledReminderSchema])
1697
- );
1698
- var dateTimeOrDisabledReminder = optional(
1699
- union([notionDateTimeReminderSchema, notionDisabledReminderSchema])
1700
- );
1701
- var notionDateSchema = object({
1702
- type: literal("date"),
1703
- start_date: string(),
1704
- reminder: dateOrDisabledReminder
1705
- });
1706
- var notionDateRangeSchema = object({
1707
- type: literal("daterange"),
1708
- start_date: string(),
1709
- end_date: string(),
1710
- reminder: dateOrDisabledReminder
1711
- });
1712
- var notionDateTimeSchema = object({
1713
- type: literal("datetime"),
1714
- start_date: string(),
1715
- start_time: string(),
1716
- time_zone: optional(string()),
1717
- reminder: dateTimeOrDisabledReminder
1718
- });
1719
- var notionDateTimeRangeSchema = object({
1720
- type: literal("datetimerange"),
1721
- start_date: string(),
1722
- start_time: string(),
1723
- end_date: string(),
1724
- end_time: string(),
1725
- time_zone: optional(string()),
1726
- reminder: dateTimeOrDisabledReminder
1727
- });
1728
- var notionDateValueSchema = variant("type", [
1729
- notionDateSchema,
1730
- notionDateRangeSchema,
1731
- notionDateTimeSchema,
1732
- notionDateTimeRangeSchema
1733
- ]);
1734
2018
 
1735
- // ../protocol/src/pages/properties/dateInput.ts
1736
- var dateInputEntries = {
2019
+ // ../protocol/src/pages/properties/date.ts
2020
+ var dateEntries = {
1737
2021
  start: string(),
1738
2022
  end: optional(nullableStringSchema),
1739
2023
  time_zone: optional(nullableStringSchema),
@@ -1741,39 +2025,38 @@ var dateInputEntries = {
1741
2025
  union([notionDateTimeReminderSchema, notionDisabledReminderSchema])
1742
2026
  )
1743
2027
  };
1744
- var notionDateInputSchema = union([
2028
+ var bridgeDateSchema = union([
1745
2029
  object({
1746
- ...dateInputEntries,
2030
+ ...dateEntries,
1747
2031
  start: pipe(string(), includes("T"))
1748
2032
  }),
1749
2033
  object({
1750
- ...dateInputEntries,
2034
+ ...dateEntries,
1751
2035
  time_zone: string()
1752
2036
  }),
1753
2037
  object({
1754
- ...dateInputEntries,
2038
+ ...dateEntries,
1755
2039
  reminder: optional(
1756
2040
  union([notionDateReminderSchema, notionDisabledReminderSchema])
1757
2041
  )
1758
2042
  })
1759
2043
  ]);
1760
2044
 
1761
- // ../protocol/src/utils/recordPointer.ts
1762
- var notionRecordPointerSchema = object({
1763
- id: string(),
1764
- table: string()
1765
- });
1766
-
1767
- // ../protocol/src/pages/properties/metadataActor.ts
1768
- var metadataActorSchema = nullable(
2045
+ // ../protocol/src/pages/properties/personItem.ts
2046
+ var bridgePersonItemSchema = union([
2047
+ object({
2048
+ object: optional(literal("user")),
2049
+ id: string()
2050
+ }),
1769
2051
  object({
1770
- ...notionRecordPointerSchema.entries,
1771
- spaceId: optional(string())
2052
+ object: literal("group"),
2053
+ id: string(),
2054
+ name: optional(nullableStringSchema)
1772
2055
  })
1773
- );
2056
+ ]);
1774
2057
 
1775
- // ../protocol/src/pages/properties/placeInput.ts
1776
- var notionPlaceInputSchema = object({
2058
+ // ../protocol/src/pages/properties/place.ts
2059
+ var bridgePlaceSchema = object({
1777
2060
  lat: number(),
1778
2061
  lon: number(),
1779
2062
  name: optional(nullableStringSchema),
@@ -1782,14 +2065,14 @@ var notionPlaceInputSchema = object({
1782
2065
  google_place_id: optional(nullableStringSchema)
1783
2066
  });
1784
2067
 
1785
- // ../protocol/src/pages/properties/relationInput.ts
1786
- var notionRelationInputSchema = object({ id: string() });
2068
+ // ../protocol/src/pages/properties/relationItem.ts
2069
+ var bridgeRelationItemSchema = object({ id: string() });
1787
2070
 
1788
2071
  // ../protocol/src/pages/properties/richText.ts
1789
- var notionRichTextItemSchema = record(string(), unknown());
2072
+ var bridgeRichTextItemSchema = record(string(), unknown());
1790
2073
 
1791
2074
  // ../protocol/src/pages/properties/selectOption.ts
1792
- var notionSelectOptionInputSchema = union([
2075
+ var bridgeSelectOptionSchema = union([
1793
2076
  object({
1794
2077
  id: string(),
1795
2078
  name: optional(string()),
@@ -1804,31 +2087,22 @@ var notionSelectOptionInputSchema = union([
1804
2087
  })
1805
2088
  ]);
1806
2089
 
1807
- // ../protocol/src/pages/properties/userInput.ts
1808
- var notionUserInputSchema = union([
1809
- object({
1810
- object: optional(literal("user")),
1811
- id: string()
1812
- }),
1813
- object({
1814
- object: literal("group"),
1815
- id: string(),
1816
- name: optional(nullableStringSchema)
1817
- })
1818
- ]);
1819
-
1820
2090
  // ../protocol/src/pages/properties/bridgePagePropertyValue.ts
1821
- var pagePropertyBaseSchema = { id: string() };
1822
- var basePropertySchemas = [
2091
+ var pagePropertyBaseSchema = {
2092
+ id: string(),
2093
+ /** Readable values omit `restricted`. Only restricted values set it, to `true`. */
2094
+ restricted: optional(literal(false))
2095
+ };
2096
+ var commonPagePropertySchemas = [
1823
2097
  object({
1824
2098
  ...pagePropertyBaseSchema,
1825
2099
  type: literal("title"),
1826
- title: array(notionRichTextItemSchema)
2100
+ title: array(bridgeRichTextItemSchema)
1827
2101
  }),
1828
2102
  object({
1829
2103
  ...pagePropertyBaseSchema,
1830
2104
  type: literal("rich_text"),
1831
- rich_text: array(notionRichTextItemSchema)
2105
+ rich_text: array(bridgeRichTextItemSchema)
1832
2106
  }),
1833
2107
  object({
1834
2108
  ...pagePropertyBaseSchema,
@@ -1858,38 +2132,38 @@ var basePropertySchemas = [
1858
2132
  object({
1859
2133
  ...pagePropertyBaseSchema,
1860
2134
  type: literal("select"),
1861
- select: nullable(notionSelectOptionInputSchema)
2135
+ select: nullable(bridgeSelectOptionSchema)
1862
2136
  }),
1863
2137
  object({
1864
2138
  ...pagePropertyBaseSchema,
1865
2139
  type: literal("status"),
1866
- status: nullable(notionSelectOptionInputSchema)
2140
+ status: nullable(bridgeSelectOptionSchema)
1867
2141
  }),
1868
2142
  object({
1869
2143
  ...pagePropertyBaseSchema,
1870
2144
  type: literal("multi_select"),
1871
- multi_select: array(notionSelectOptionInputSchema)
2145
+ multi_select: array(bridgeSelectOptionSchema)
1872
2146
  }),
1873
2147
  object({
1874
2148
  ...pagePropertyBaseSchema,
1875
2149
  type: literal("date"),
1876
- date: nullable(notionDateInputSchema)
2150
+ date: nullable(bridgeDateSchema)
1877
2151
  }),
1878
2152
  object({
1879
2153
  ...pagePropertyBaseSchema,
1880
2154
  type: literal("people"),
1881
- people: array(notionUserInputSchema)
2155
+ people: array(bridgePersonItemSchema)
1882
2156
  }),
1883
2157
  object({
1884
2158
  ...pagePropertyBaseSchema,
1885
2159
  type: literal("relation"),
1886
2160
  has_more: optional(boolean()),
1887
- relation: array(notionRelationInputSchema)
2161
+ relation: array(bridgeRelationItemSchema)
1888
2162
  }),
1889
2163
  object({
1890
2164
  ...pagePropertyBaseSchema,
1891
2165
  type: literal("place"),
1892
- place: nullable(notionPlaceInputSchema)
2166
+ place: nullable(bridgePlaceSchema)
1893
2167
  }),
1894
2168
  object({
1895
2169
  ...pagePropertyBaseSchema,
@@ -1904,17 +2178,12 @@ var basePropertySchemas = [
1904
2178
  object({
1905
2179
  ...pagePropertyBaseSchema,
1906
2180
  type: literal("created_by"),
1907
- created_by: metadataActorSchema
2181
+ created_by: nullable(bridgeActorSchema)
1908
2182
  }),
1909
2183
  object({
1910
2184
  ...pagePropertyBaseSchema,
1911
2185
  type: literal("last_edited_by"),
1912
- last_edited_by: metadataActorSchema
1913
- }),
1914
- object({
1915
- ...pagePropertyBaseSchema,
1916
- type: literal("unique_id"),
1917
- unique_id: string()
2186
+ last_edited_by: nullable(bridgeActorSchema)
1918
2187
  }),
1919
2188
  object({
1920
2189
  ...pagePropertyBaseSchema,
@@ -1930,36 +2199,254 @@ var basePropertySchemas = [
1930
2199
  ...pagePropertyBaseSchema,
1931
2200
  type: literal("rollup"),
1932
2201
  rollup: string()
1933
- }),
1934
- object({
1935
- ...pagePropertyBaseSchema,
1936
- type: literal("verification"),
1937
- verification: string()
1938
2202
  })
1939
2203
  ];
2204
+ var bridgeFilesPropertyWriteValueSchema = object({
2205
+ ...pagePropertyBaseSchema,
2206
+ type: literal("files"),
2207
+ files: array(bridgeFilePropertyItemSchema)
2208
+ });
1940
2209
  var bridgePagePropertyWriteValueSchema = variant("type", [
1941
- ...basePropertySchemas,
2210
+ ...commonPagePropertySchemas,
1942
2211
  object({
1943
- ...pagePropertyBaseSchema,
1944
- type: literal("files"),
1945
- files: array(bridgeFilePropertyItemSchema)
1946
- })
2212
+ ...textUniqueIdPropertySchema.entries,
2213
+ restricted: optional(literal(false))
2214
+ }),
2215
+ object({
2216
+ ...textVerificationPropertySchema.entries,
2217
+ restricted: optional(literal(false))
2218
+ }),
2219
+ bridgeFilesPropertyWriteValueSchema
2220
+ ]);
2221
+ var addressedRelationEntries = {
2222
+ type: literal("relation"),
2223
+ has_more: optional(boolean()),
2224
+ relation: array(union([bridgeRelationItemSchema, pageAddressSchema]))
2225
+ };
2226
+ var bridgePageAddressedPropertyWriteValueSchema = union([
2227
+ bridgePagePropertyWriteValueSchema,
2228
+ object({ ...pagePropertyBaseSchema, ...addressedRelationEntries })
2229
+ ]);
2230
+ var bridgePageKeyedPropertyWriteValueSchema = union([
2231
+ variant(
2232
+ "type",
2233
+ bridgePagePropertyWriteValueSchema.options.map(
2234
+ (schema) => object({ ...schema.entries, id: optional(string()) })
2235
+ )
2236
+ ),
2237
+ object({ ...addressedRelationEntries, id: optional(string()) })
1947
2238
  ]);
1948
2239
  var bridgeFilesPropertyReadValueSchema = object({
1949
2240
  ...pagePropertyBaseSchema,
1950
2241
  type: literal("files"),
1951
2242
  files: array(bridgeFilePropertyReadItemSchema)
1952
2243
  });
1953
- var bridgePagePropertyReadValueSchema = variant("type", [
1954
- ...basePropertySchemas,
2244
+ var knownBridgePagePropertyReadValueSchema = variant("type", [
2245
+ ...commonPagePropertySchemas,
2246
+ object({
2247
+ ...textUniqueIdPropertySchema.entries,
2248
+ restricted: optional(literal(false))
2249
+ }),
2250
+ object({
2251
+ ...textVerificationPropertySchema.entries,
2252
+ restricted: optional(literal(false))
2253
+ }),
1955
2254
  bridgeFilesPropertyReadValueSchema
1956
2255
  ]);
2256
+ var bridgeRestrictedPagePropertyValueSchema = variant("type", [
2257
+ object({
2258
+ id: string(),
2259
+ type: literal("title"),
2260
+ title: null_(),
2261
+ restricted: literal(true)
2262
+ }),
2263
+ object({
2264
+ id: string(),
2265
+ type: literal("rich_text"),
2266
+ rich_text: null_(),
2267
+ restricted: literal(true)
2268
+ }),
2269
+ object({
2270
+ id: string(),
2271
+ type: literal("number"),
2272
+ number: null_(),
2273
+ restricted: literal(true)
2274
+ }),
2275
+ object({
2276
+ id: string(),
2277
+ type: literal("url"),
2278
+ url: null_(),
2279
+ restricted: literal(true)
2280
+ }),
2281
+ object({
2282
+ id: string(),
2283
+ type: literal("email"),
2284
+ email: null_(),
2285
+ restricted: literal(true)
2286
+ }),
2287
+ object({
2288
+ id: string(),
2289
+ type: literal("phone_number"),
2290
+ phone_number: null_(),
2291
+ restricted: literal(true)
2292
+ }),
2293
+ object({
2294
+ id: string(),
2295
+ type: literal("checkbox"),
2296
+ checkbox: null_(),
2297
+ restricted: literal(true)
2298
+ }),
2299
+ object({
2300
+ id: string(),
2301
+ type: literal("select"),
2302
+ select: null_(),
2303
+ restricted: literal(true)
2304
+ }),
2305
+ object({
2306
+ id: string(),
2307
+ type: literal("status"),
2308
+ status: null_(),
2309
+ restricted: literal(true)
2310
+ }),
2311
+ object({
2312
+ id: string(),
2313
+ type: literal("multi_select"),
2314
+ multi_select: null_(),
2315
+ restricted: literal(true)
2316
+ }),
2317
+ object({
2318
+ id: string(),
2319
+ type: literal("date"),
2320
+ date: null_(),
2321
+ restricted: literal(true)
2322
+ }),
2323
+ object({
2324
+ id: string(),
2325
+ type: literal("people"),
2326
+ people: null_(),
2327
+ restricted: literal(true)
2328
+ }),
2329
+ object({
2330
+ id: string(),
2331
+ type: literal("relation"),
2332
+ relation: null_(),
2333
+ restricted: literal(true)
2334
+ }),
2335
+ object({
2336
+ id: string(),
2337
+ type: literal("files"),
2338
+ files: null_(),
2339
+ restricted: literal(true)
2340
+ }),
2341
+ object({
2342
+ id: string(),
2343
+ type: literal("place"),
2344
+ place: null_(),
2345
+ restricted: literal(true)
2346
+ }),
2347
+ object({
2348
+ id: string(),
2349
+ type: literal("created_time"),
2350
+ created_time: null_(),
2351
+ restricted: literal(true)
2352
+ }),
2353
+ object({
2354
+ id: string(),
2355
+ type: literal("last_edited_time"),
2356
+ last_edited_time: null_(),
2357
+ restricted: literal(true)
2358
+ }),
2359
+ object({
2360
+ id: string(),
2361
+ type: literal("created_by"),
2362
+ created_by: null_(),
2363
+ restricted: literal(true)
2364
+ }),
2365
+ object({
2366
+ id: string(),
2367
+ type: literal("last_edited_by"),
2368
+ last_edited_by: null_(),
2369
+ restricted: literal(true)
2370
+ }),
2371
+ object({
2372
+ id: string(),
2373
+ type: literal("unique_id"),
2374
+ unique_id: null_(),
2375
+ restricted: literal(true)
2376
+ }),
2377
+ object({
2378
+ id: string(),
2379
+ type: literal("button"),
2380
+ button: null_(),
2381
+ restricted: literal(true)
2382
+ }),
2383
+ object({
2384
+ id: string(),
2385
+ type: literal("formula"),
2386
+ formula: null_(),
2387
+ restricted: literal(true)
2388
+ }),
2389
+ object({
2390
+ id: string(),
2391
+ type: literal("rollup"),
2392
+ rollup: null_(),
2393
+ restricted: literal(true)
2394
+ }),
2395
+ object({
2396
+ id: string(),
2397
+ type: literal("verification"),
2398
+ verification: null_(),
2399
+ restricted: literal(true)
2400
+ })
2401
+ ]);
2402
+ var bridgeUnknownPagePropertyReadValueSchema = object({
2403
+ ...pagePropertyBaseSchema,
2404
+ type: literal("unknown"),
2405
+ originalType: unknownPropertyTypeSchema
2406
+ });
2407
+ var futurePagePropertyReadValueSchema = pipe(
2408
+ object({
2409
+ id: string(),
2410
+ type: unknownPropertyTypeSchema,
2411
+ restricted: optional(boolean())
2412
+ }),
2413
+ check(
2414
+ ({ type }) => !knownBridgePagePropertyReadValueSchema.options.some(
2415
+ (schema) => schema.entries.type.literal === type
2416
+ )
2417
+ ),
2418
+ transform(
2419
+ ({ id, type }) => ({
2420
+ id,
2421
+ type: "unknown",
2422
+ originalType: type
2423
+ })
2424
+ )
2425
+ );
2426
+ var bridgePagePropertyReadValueSchema = union([
2427
+ bridgeRestrictedPagePropertyValueSchema,
2428
+ knownBridgePagePropertyReadValueSchema,
2429
+ bridgeUnknownPagePropertyReadValueSchema,
2430
+ futurePagePropertyReadValueSchema
2431
+ ]);
1957
2432
 
1958
2433
  // ../protocol/src/pages/properties/bridgePagePropertyMaps.ts
1959
2434
  var bridgePagePropertyWriteMapSchema = record(
1960
2435
  string(),
1961
2436
  bridgePagePropertyWriteValueSchema
1962
2437
  );
2438
+ var bridgePageAddressedPropertyWriteMapSchema = record(
2439
+ string(),
2440
+ bridgePageAddressedPropertyWriteValueSchema
2441
+ );
2442
+ var bridgePageKeyedPropertyWriteMapSchema = record(
2443
+ string(),
2444
+ bridgePageKeyedPropertyWriteValueSchema
2445
+ );
2446
+ var bridgePropertyIdsByKeySchema = record(
2447
+ string(),
2448
+ optional(string())
2449
+ );
1963
2450
  var bridgePagePropertyReadMapSchema = record(
1964
2451
  string(),
1965
2452
  nullable(bridgePagePropertyReadValueSchema)
@@ -1983,8 +2470,8 @@ var bridgePageSchema = object({
1983
2470
  id: notionPageIdSchema,
1984
2471
  parent: notionParentSchema,
1985
2472
  properties: bridgePagePropertyReadMapSchema,
1986
- created_by: optional(metadataActorSchema, null),
1987
- last_edited_by: optional(metadataActorSchema, null),
2473
+ created_by: optional(nullable(bridgeActorSchema), null),
2474
+ last_edited_by: optional(nullable(bridgeActorSchema), null),
1988
2475
  created_time: optional(nullable(string()), null),
1989
2476
  last_edited_time: optional(nullable(string()), null),
1990
2477
  icon: optional(nullable(pageIconReadSchema), null),
@@ -1997,6 +2484,29 @@ var bridgePageSchema = object({
1997
2484
  in_trash: boolean()
1998
2485
  });
1999
2486
 
2487
+ // ../protocol/src/pages/pageSnapshot.ts
2488
+ var unavailablePagePropertySchema = object({
2489
+ id: string(),
2490
+ key: optional(string()),
2491
+ type: literal("unavailable")
2492
+ });
2493
+ var pageSnapshotPropertySchema = union([
2494
+ unavailablePagePropertySchema,
2495
+ intersect([
2496
+ bridgePagePropertyReadValueSchema,
2497
+ object({ key: optional(string()) })
2498
+ ])
2499
+ ]);
2500
+ var bridgePageSnapshotSchema = object({
2501
+ ...bridgePageSchema.entries,
2502
+ id: optional(bridgePageSchema.entries.id),
2503
+ properties: array(pageSnapshotPropertySchema)
2504
+ });
2505
+ var identifiedPageSnapshotSchema = required(
2506
+ bridgePageSnapshotSchema,
2507
+ ["id"]
2508
+ );
2509
+
2000
2510
  // ../protocol/src/dataSources/bridgeArchiveStatus.ts
2001
2511
  var bridgeArchiveStatusSchema = picklist([
2002
2512
  "active",
@@ -2332,6 +2842,52 @@ var queryDataSourceResultMessageSchema = variant("status", [
2332
2842
  })
2333
2843
  ]);
2334
2844
 
2845
+ // ../protocol/src/dataSources/messages/dataSourceQueryResult.ts
2846
+ var queryLoadingSchema = object({
2847
+ type: literal("queryDataSourceResult"),
2848
+ subscriptionId: string(),
2849
+ status: literal("loading")
2850
+ });
2851
+ var dataSourceQueryRecordResultMessageSchema = variant("status", [
2852
+ object({
2853
+ ...queryDataSourceResultMessageSchema.options[0].entries,
2854
+ propertyIdsByKey: optional(bridgePropertyIdsByKeySchema)
2855
+ }),
2856
+ queryDataSourceResultMessageSchema.options[1],
2857
+ queryLoadingSchema
2858
+ ]);
2859
+ var dataSourceQueryResultMessageSchema = variant("status", [
2860
+ object({
2861
+ ...queryDataSourceResultMessageSchema.options[0].entries,
2862
+ items: array(identifiedPageSnapshotSchema),
2863
+ // A query row carries its own keys. Reject the retired sibling mapping.
2864
+ propertyIdsByKey: exactOptional(never())
2865
+ }),
2866
+ queryDataSourceResultMessageSchema.options[1],
2867
+ queryLoadingSchema
2868
+ ]);
2869
+
2870
+ // ../protocol/src/dataSources/messages/dataSourceRead.ts
2871
+ var dataSourceReadMessageSchema = strictObject({
2872
+ type: literal("getDataSource"),
2873
+ requestId: string(),
2874
+ target: dataSourceTargetSchema
2875
+ });
2876
+ var dataSourceReadResultMessageSchema = variant("status", [
2877
+ strictObject({
2878
+ type: literal("getDataSourceResult"),
2879
+ requestId: string(),
2880
+ status: literal("success"),
2881
+ dataSource: settledDataSourceSnapshotSchema
2882
+ }),
2883
+ strictObject({
2884
+ type: literal("getDataSourceResult"),
2885
+ requestId: string(),
2886
+ status: literal("error"),
2887
+ error: customBlockErrorInfoSchema
2888
+ })
2889
+ ]);
2890
+
2335
2891
  // ../protocol/src/handshake/connectResult.ts
2336
2892
  var connectResultMessageSchema = variant("status", [
2337
2893
  object({
@@ -2375,50 +2931,146 @@ var openExternalUrlResultMessageSchema = variant("status", [
2375
2931
  })
2376
2932
  ]);
2377
2933
 
2378
- // ../protocol/src/pages/messages/createPage.ts
2379
- var customBlockCreatePageErrorCodeSchema = string();
2380
- var customBlockCreatePageErrorInfoSchema = object({
2381
- code: customBlockCreatePageErrorCodeSchema,
2934
+ // ../protocol/src/pages/messages/getPage.ts
2935
+ var customBlockGetPageErrorCodeSchema = string();
2936
+ var customBlockGetPageErrorInfoSchema = object({
2937
+ code: customBlockGetPageErrorCodeSchema,
2382
2938
  message: string(),
2383
- isRetryable: boolean()
2939
+ isRetryable: boolean(),
2940
+ details: fallback(optional(customBlockErrorDetailsSchema), void 0)
2384
2941
  });
2385
- var createPageResultMessageSchema = variant("status", [
2942
+ var getPageMessageSchema = object({
2943
+ type: literal("getPage"),
2944
+ requestId: string(),
2945
+ pageId: notionPageIdSchema,
2946
+ dataSourceId: optional(notionDataSourceIdSchema)
2947
+ });
2948
+ var keyedGetPageMessageSchema = variant("type", [
2949
+ strictObject({
2950
+ type: literal("getPage"),
2951
+ requestId: string(),
2952
+ target: pageReadTargetSchema
2953
+ }),
2954
+ // The host checks bare IDs against current bindings or pages created on the connection.
2955
+ strictObject({
2956
+ type: literal("getPage"),
2957
+ requestId: string(),
2958
+ pageId: notionPageIdSchema
2959
+ })
2960
+ ]);
2961
+ var getPageResultMessageSchema = variant("status", [
2386
2962
  object({
2387
- type: literal("createPageResult"),
2963
+ type: literal("getPageResult"),
2388
2964
  requestId: string(),
2389
2965
  status: literal("success"),
2390
- /** The newly created page. */
2391
- page: bridgePageSchema
2966
+ page: bridgePageSchema,
2967
+ propertyIdsByKey: optional(bridgePropertyIdsByKeySchema)
2392
2968
  }),
2393
2969
  object({
2394
- type: literal("createPageResult"),
2970
+ type: literal("getPageResult"),
2395
2971
  requestId: string(),
2396
2972
  status: literal("error"),
2397
- error: customBlockCreatePageErrorInfoSchema
2973
+ error: customBlockGetPageErrorInfoSchema
2398
2974
  })
2399
2975
  ]);
2400
- var notionCreatePagePositionSchema = variant("type", [
2401
- object({ type: literal("start") }),
2402
- object({ type: literal("end") }),
2403
- object({ type: literal("before"), blockId: notionBlockIdSchema }),
2404
- object({ type: literal("after"), blockId: notionBlockIdSchema })
2405
- ]);
2406
- var createPageParentSchema = variant("type", [
2407
- pageParentSchema,
2408
- dataSourceParentSchema
2976
+ var addressedGetPageResultMessageSchema = variant("status", [
2977
+ object({
2978
+ ...getPageResultMessageSchema.options[0].entries,
2979
+ page: object({
2980
+ ...bridgePageSchema.entries,
2981
+ id: optional(notionPageIdSchema)
2982
+ })
2983
+ }),
2984
+ getPageResultMessageSchema.options[1]
2409
2985
  ]);
2410
- var createPageBaseEntries = {
2411
- /**
2412
- * Property values, keyed by raw property IDs from Notion.
2413
- *
2414
- * Each value must carry the same raw property ID in its `id` field.
2415
- * To create a page with manifest-defined property keys, call `pages.create`. The SDK resolves
2416
- * those keys before it sends this message.
2417
- */
2418
- properties: bridgePagePropertyWriteMapSchema,
2419
- icon: optional(bridgePageIconSchema),
2986
+
2987
+ // ../protocol/src/pages/messages/openPage.ts
2988
+ var openPageModeSchema = picklist(["side_peek", "center_peek"]);
2989
+ var customBlockOpenPageErrorCodeSchema = string();
2990
+ var customBlockOpenPageErrorInfoSchema = object({
2991
+ code: customBlockOpenPageErrorCodeSchema,
2992
+ message: string(),
2993
+ isRetryable: boolean()
2994
+ });
2995
+ var openPageMessageSchema = object({
2996
+ type: literal("openPage"),
2997
+ requestId: string(),
2998
+ pageId: notionPageIdSchema,
2999
+ mode: openPageModeSchema
3000
+ });
3001
+ var openPageResultMessageSchema = variant("status", [
3002
+ object({
3003
+ type: literal("openPageResult"),
3004
+ requestId: string(),
3005
+ status: literal("success"),
3006
+ pageId: notionPageIdSchema
3007
+ }),
3008
+ object({
3009
+ type: literal("openPageResult"),
3010
+ requestId: string(),
3011
+ status: literal("error"),
3012
+ error: customBlockOpenPageErrorInfoSchema
3013
+ })
3014
+ ]);
3015
+ var addressedOpenPageMessageSchema = strictObject({
3016
+ type: literal("openPage"),
3017
+ requestId: string(),
3018
+ target: pageAddressSchema,
3019
+ mode: openPageModeSchema
3020
+ });
3021
+ var addressedOpenPageResultMessageSchema = variant("status", [
3022
+ strictObject(
3023
+ omit(openPageResultMessageSchema.options[0], ["pageId"]).entries
3024
+ ),
3025
+ openPageResultMessageSchema.options[1]
3026
+ ]);
3027
+
3028
+ // ../protocol/src/pages/messages/createPage.ts
3029
+ var customBlockCreatePageErrorCodeSchema = string();
3030
+ var customBlockCreatePageErrorInfoSchema = object({
3031
+ code: customBlockCreatePageErrorCodeSchema,
3032
+ message: string(),
3033
+ isRetryable: boolean()
3034
+ });
3035
+ var createPageResultMessageSchema = variant("status", [
3036
+ object({
3037
+ type: literal("createPageResult"),
3038
+ requestId: string(),
3039
+ status: literal("success"),
3040
+ /** The newly created page. */
3041
+ page: bridgePageSchema,
3042
+ propertyIdsByKey: optional(bridgePropertyIdsByKeySchema)
3043
+ }),
3044
+ object({
3045
+ type: literal("createPageResult"),
3046
+ requestId: string(),
3047
+ status: literal("error"),
3048
+ error: customBlockCreatePageErrorInfoSchema
3049
+ })
3050
+ ]);
3051
+ var notionCreatePagePositionSchema = variant("type", [
3052
+ object({ type: literal("start") }),
3053
+ object({ type: literal("end") }),
3054
+ object({ type: literal("before"), blockId: notionBlockIdSchema }),
3055
+ object({ type: literal("after"), blockId: notionBlockIdSchema })
3056
+ ]);
3057
+ var createPageParentSchema = variant("type", [
3058
+ pageParentSchema,
3059
+ dataSourceParentSchema
3060
+ ]);
3061
+ var createPageAppearanceEntries = {
3062
+ icon: optional(bridgePageIconSchema),
2420
3063
  cover: optional(bridgePageCoverSchema)
2421
3064
  };
3065
+ var createPageBaseEntries = {
3066
+ ...createPageAppearanceEntries,
3067
+ /**
3068
+ * Property values, keyed by raw property IDs from Notion.
3069
+ *
3070
+ * Each value must carry the same raw property ID in its `id` field.
3071
+ */
3072
+ properties: bridgePagePropertyWriteMapSchema
3073
+ };
2422
3074
  var createPageUnderPageArgsSchema = object({
2423
3075
  ...createPageBaseEntries,
2424
3076
  parent: pageParentSchema,
@@ -2447,62 +3099,19 @@ var createPageMessageSchema = variant("type", [
2447
3099
  ...createPageUnderDataSourceArgsSchema.entries
2448
3100
  })
2449
3101
  ]);
2450
-
2451
- // ../protocol/src/pages/messages/getPage.ts
2452
- var customBlockGetPageErrorCodeSchema = string();
2453
- var customBlockGetPageErrorInfoSchema = object({
2454
- code: customBlockGetPageErrorCodeSchema,
2455
- message: string(),
2456
- isRetryable: boolean(),
2457
- details: fallback(optional(customBlockErrorDetailsSchema), void 0)
2458
- });
2459
- var getPageMessageSchema = object({
2460
- type: literal("getPage"),
2461
- requestId: string(),
2462
- pageId: notionPageIdSchema,
2463
- dataSourceId: optional(notionDataSourceIdSchema)
2464
- });
2465
- var getPageResultMessageSchema = variant("status", [
2466
- object({
2467
- type: literal("getPageResult"),
2468
- requestId: string(),
2469
- status: literal("success"),
2470
- page: bridgePageSchema
2471
- }),
2472
- object({
2473
- type: literal("getPageResult"),
2474
- requestId: string(),
2475
- status: literal("error"),
2476
- error: customBlockGetPageErrorInfoSchema
2477
- })
2478
- ]);
2479
-
2480
- // ../protocol/src/pages/messages/openPage.ts
2481
- var openPageModeSchema = picklist(["side_peek", "center_peek"]);
2482
- var customBlockOpenPageErrorCodeSchema = string();
2483
- var customBlockOpenPageErrorInfoSchema = object({
2484
- code: customBlockOpenPageErrorCodeSchema,
2485
- message: string(),
2486
- isRetryable: boolean()
2487
- });
2488
- var openPageMessageSchema = object({
2489
- type: literal("openPage"),
2490
- requestId: string(),
2491
- pageId: notionPageIdSchema,
2492
- mode: openPageModeSchema
2493
- });
2494
- var openPageResultMessageSchema = variant("status", [
2495
- object({
2496
- type: literal("openPageResult"),
2497
- requestId: string(),
2498
- status: literal("success"),
2499
- pageId: notionPageIdSchema
3102
+ var keyedCreatePageMessageSchema = variant("type", [
3103
+ strictObject({
3104
+ ...createPageMessageEntries,
3105
+ ...createPageUnderPageArgsSchema.entries,
3106
+ parent: pageAddressSchema,
3107
+ properties: bridgePageAddressedPropertyWriteMapSchema
2500
3108
  }),
2501
- object({
2502
- type: literal("openPageResult"),
2503
- requestId: string(),
2504
- status: literal("error"),
2505
- error: customBlockOpenPageErrorInfoSchema
3109
+ strictObject({
3110
+ ...createPageMessageEntries,
3111
+ ...createPageAppearanceEntries,
3112
+ parent: dataSourceKeyParentSchema,
3113
+ propertiesByKey: bridgePageKeyedPropertyWriteMapSchema,
3114
+ position: optional(never())
2506
3115
  })
2507
3116
  ]);
2508
3117
 
@@ -2518,7 +3127,8 @@ var updatePageResultMessageSchema = variant("status", [
2518
3127
  type: literal("updatePageResult"),
2519
3128
  requestId: string(),
2520
3129
  status: literal("success"),
2521
- page: bridgePageSchema
3130
+ page: bridgePageSchema,
3131
+ propertyIdsByKey: optional(bridgePropertyIdsByKeySchema)
2522
3132
  }),
2523
3133
  object({
2524
3134
  type: literal("updatePageResult"),
@@ -2527,6 +3137,13 @@ var updatePageResultMessageSchema = variant("status", [
2527
3137
  error: customBlockUpdatePageErrorInfoSchema
2528
3138
  })
2529
3139
  ]);
3140
+ var addressedUpdatePageResultMessageSchema = variant("status", [
3141
+ object({
3142
+ ...updatePageResultMessageSchema.options[0].entries,
3143
+ page: partial(bridgePageSchema, ["id"])
3144
+ }),
3145
+ updatePageResultMessageSchema.options[1]
3146
+ ]);
2530
3147
  var updatePageMessageSchema = object({
2531
3148
  type: literal("updatePage"),
2532
3149
  requestId: string(),
@@ -2536,14 +3153,120 @@ var updatePageMessageSchema = object({
2536
3153
  * Property values, keyed by raw property IDs from Notion.
2537
3154
  *
2538
3155
  * Each value must carry the same raw property ID in its `id` field.
2539
- * To update a page with manifest-defined property keys, call `row.updateByKey()` on a row returned
2540
- * by `useDataSource()`. The SDK resolves those keys before it sends this message.
2541
3156
  */
2542
3157
  properties: optional(bridgePagePropertyWriteMapSchema),
2543
3158
  icon: optional(bridgePageIconSchema),
2544
3159
  cover: optional(bridgePageCoverSchema),
2545
3160
  archived: optional(boolean())
2546
3161
  });
3162
+ var {
3163
+ dataSourceId: _dataSourceId,
3164
+ pageId: _pageId,
3165
+ properties: _properties,
3166
+ ...updatePageFields
3167
+ } = updatePageMessageSchema.entries;
3168
+ var keyedUpdatePageMessageSchema = variant("type", [
3169
+ strictObject({
3170
+ ...updatePageFields,
3171
+ target: pageAddressSchema,
3172
+ dataSourceKey: optional(string()),
3173
+ properties: optional(bridgePageAddressedPropertyWriteMapSchema)
3174
+ }),
3175
+ strictObject({
3176
+ ...updatePageFields,
3177
+ target: pageAddressSchema,
3178
+ // Supply a mapping for targets that do not already identify a data source.
3179
+ dataSourceKey: optional(string()),
3180
+ propertiesByKey: bridgePageKeyedPropertyWriteMapSchema
3181
+ })
3182
+ ]);
3183
+
3184
+ // ../protocol/src/pages/messages/pageResults.ts
3185
+ var pageReadResultMessageSchema = variant("status", [
3186
+ object({
3187
+ ...omit(getPageResultMessageSchema.options[0], ["propertyIdsByKey"]).entries,
3188
+ propertyIdsByKey: exactOptional(never()),
3189
+ page: bridgePageSnapshotSchema
3190
+ }),
3191
+ getPageResultMessageSchema.options[1]
3192
+ ]);
3193
+ var pageCreateResultMessageSchema = variant("status", [
3194
+ object({
3195
+ ...omit(createPageResultMessageSchema.options[0], ["propertyIdsByKey"]).entries,
3196
+ propertyIdsByKey: exactOptional(never()),
3197
+ page: identifiedPageSnapshotSchema
3198
+ }),
3199
+ createPageResultMessageSchema.options[1]
3200
+ ]);
3201
+ var pageUpdateResultMessageSchema = variant("status", [
3202
+ object({
3203
+ ...omit(updatePageResultMessageSchema.options[0], ["propertyIdsByKey"]).entries,
3204
+ propertyIdsByKey: exactOptional(never()),
3205
+ page: bridgePageSnapshotSchema
3206
+ }),
3207
+ updatePageResultMessageSchema.options[1]
3208
+ ]);
3209
+ var pageRecordResultMessageSchema = union([
3210
+ dataSourceQueryRecordResultMessageSchema,
3211
+ createPageResultMessageSchema,
3212
+ addressedGetPageResultMessageSchema,
3213
+ addressedUpdatePageResultMessageSchema
3214
+ ]);
3215
+
3216
+ // ../protocol/src/pages/messages/pageSnapshots.ts
3217
+ var subscribeToPageMessageSchema = strictObject({
3218
+ type: literal("subscribeToPage"),
3219
+ requestId: string(),
3220
+ pageTarget: pageAddressSchema
3221
+ });
3222
+ var unsubscribeFromPageMessageSchema = strictObject({
3223
+ type: literal("unsubscribeFromPage"),
3224
+ requestId: string()
3225
+ });
3226
+ var subscribeToPageResultMessageSchema = variant("status", [
3227
+ strictObject({
3228
+ type: literal("subscribeToPageResult"),
3229
+ requestId: string(),
3230
+ status: literal("success")
3231
+ }),
3232
+ strictObject({
3233
+ type: literal("subscribeToPageResult"),
3234
+ requestId: string(),
3235
+ status: literal("error"),
3236
+ error: customBlockErrorInfoSchema
3237
+ })
3238
+ ]);
3239
+ var pageSnapshotSchema = variant("type", [
3240
+ strictObject({ type: literal("loading") }),
3241
+ strictObject({
3242
+ type: literal("available"),
3243
+ page: partial(bridgePageSchema, ["id"]),
3244
+ propertyIdsByKey: optional(bridgePropertyIdsByKeySchema)
3245
+ }),
3246
+ strictObject({
3247
+ type: literal("error"),
3248
+ error: customBlockErrorInfoSchema
3249
+ })
3250
+ ]);
3251
+ var pageSnapshotChangedMessageSchema = variant("status", [
3252
+ strictObject({
3253
+ type: literal("pageSnapshotChanged"),
3254
+ requestId: string(),
3255
+ status: literal("available"),
3256
+ page: bridgePageSnapshotSchema
3257
+ }),
3258
+ strictObject({
3259
+ type: literal("pageSnapshotChanged"),
3260
+ requestId: string(),
3261
+ status: literal("loading")
3262
+ }),
3263
+ strictObject({
3264
+ type: literal("pageSnapshotChanged"),
3265
+ requestId: string(),
3266
+ status: literal("error"),
3267
+ error: customBlockErrorInfoSchema
3268
+ })
3269
+ ]);
2547
3270
 
2548
3271
  // ../protocol/src/users/bridgeUser.ts
2549
3272
  var bridgeUserSchema = object({
@@ -2605,6 +3328,42 @@ var getUserResultMessageSchema = variant("status", [
2605
3328
  })
2606
3329
  ]);
2607
3330
 
3331
+ // ../protocol/src/users/userSnapshot.ts
3332
+ var userTargetSchema = object({
3333
+ type: literal("user_id"),
3334
+ userId: notionUserIdSchema
3335
+ });
3336
+ var bridgeUserSnapshotSchema = object({
3337
+ id: notionUserIdSchema,
3338
+ name: nullable(string()),
3339
+ avatarUrl: nullable(string()),
3340
+ email: optional(nullable(string()))
3341
+ });
3342
+
3343
+ // ../protocol/src/users/messages/getUserSnapshot.ts
3344
+ var getUserSnapshotMessageSchema = object({
3345
+ type: literal("getUserSnapshot"),
3346
+ requestId: string(),
3347
+ target: userTargetSchema,
3348
+ includeEmail: optional(boolean())
3349
+ });
3350
+ var getUserSnapshotResultMessageSchema = variant("status", [
3351
+ object({
3352
+ type: literal("getUserSnapshotResult"),
3353
+ requestId: string(),
3354
+ email: exactOptional(never()),
3355
+ status: literal("success"),
3356
+ user: bridgeUserSnapshotSchema
3357
+ }),
3358
+ object({
3359
+ type: literal("getUserSnapshotResult"),
3360
+ requestId: string(),
3361
+ email: exactOptional(never()),
3362
+ status: literal("error"),
3363
+ error: customBlockErrorInfoSchema
3364
+ })
3365
+ ]);
3366
+
2608
3367
  // ../protocol/src/users/viewer.ts
2609
3368
  var bridgeViewerSchema = variant("type", [
2610
3369
  object({
@@ -2627,98 +3386,357 @@ var getViewerResultMessageSchema = variant("status", [
2627
3386
  viewer: bridgeViewerSchema
2628
3387
  }),
2629
3388
  object({
2630
- type: literal("getViewerResult"),
2631
- requestId: string(),
2632
- status: literal("error"),
2633
- error: customBlockErrorInfoSchema
2634
- })
2635
- ]);
2636
-
2637
- // ../protocol/src/users/bridgeUserList.ts
2638
- var bridgeUserListSchema = object({
2639
- object: literal("list"),
2640
- results: array(bridgeUserSchema),
2641
- next_cursor: nullable(string()),
2642
- has_more: boolean(),
2643
- type: literal("user"),
2644
- user: record(string(), unknown())
2645
- });
2646
-
2647
- // ../protocol/src/users/messages/listUsers.ts
2648
- var customBlockListUsersErrorCodeSchema = string();
2649
- var customBlockListUsersErrorInfoSchema = object({
2650
- code: customBlockListUsersErrorCodeSchema,
2651
- message: string(),
2652
- isRetryable: boolean()
2653
- });
2654
- var listUsersMessageSchema = object({
2655
- type: literal("listUsers"),
2656
- requestId: string(),
2657
- startCursor: optional(string()),
2658
- pageSize: optional(number())
2659
- });
2660
- var listUsersResultMessageSchema = variant("status", [
3389
+ type: literal("getViewerResult"),
3390
+ requestId: string(),
3391
+ status: literal("error"),
3392
+ error: customBlockErrorInfoSchema
3393
+ })
3394
+ ]);
3395
+
3396
+ // ../protocol/src/users/bridgeUserList.ts
3397
+ var bridgeUserListSchema = object({
3398
+ object: literal("list"),
3399
+ results: array(bridgeUserSchema),
3400
+ next_cursor: nullable(string()),
3401
+ has_more: boolean(),
3402
+ type: literal("user"),
3403
+ user: record(string(), unknown())
3404
+ });
3405
+
3406
+ // ../protocol/src/users/messages/listUsers.ts
3407
+ var customBlockListUsersErrorCodeSchema = string();
3408
+ var customBlockListUsersErrorInfoSchema = object({
3409
+ code: customBlockListUsersErrorCodeSchema,
3410
+ message: string(),
3411
+ isRetryable: boolean()
3412
+ });
3413
+ var listUsersMessageSchema = object({
3414
+ type: literal("listUsers"),
3415
+ requestId: string(),
3416
+ startCursor: optional(string()),
3417
+ pageSize: optional(number())
3418
+ });
3419
+ var listUsersResultMessageSchema = variant("status", [
3420
+ object({
3421
+ type: literal("listUsersResult"),
3422
+ requestId: string(),
3423
+ status: literal("success"),
3424
+ list: bridgeUserListSchema
3425
+ }),
3426
+ object({
3427
+ type: literal("listUsersResult"),
3428
+ requestId: string(),
3429
+ status: literal("error"),
3430
+ error: customBlockListUsersErrorInfoSchema
3431
+ })
3432
+ ]);
3433
+
3434
+ // ../protocol/src/users/messages/userField.ts
3435
+ var userFieldSchema = picklist(["name", "avatarUrl", "email"]);
3436
+ var userFieldDataSchema = strictObject({
3437
+ name: optional(nullable(string())),
3438
+ avatarUrl: optional(nullable(string())),
3439
+ email: optional(nullable(string()))
3440
+ });
3441
+
3442
+ // ../protocol/src/users/messages/listUserReferences.ts
3443
+ var listUserReferencesMessageSchema = strictObject({
3444
+ type: literal("listUserReferences"),
3445
+ requestId: string(),
3446
+ startCursor: optional(string()),
3447
+ pageSize: optional(number()),
3448
+ includeEmail: optional(boolean())
3449
+ });
3450
+ var pagination = { nextCursor: nullable(string()), hasMore: boolean() };
3451
+ var pageSchema = strictObject({
3452
+ ...pagination,
3453
+ users: array(
3454
+ strictObject({ userId: notionUserIdSchema, fields: userFieldDataSchema })
3455
+ )
3456
+ });
3457
+ var envelope = {
3458
+ type: literal("listUserReferencesResult"),
3459
+ requestId: string()
3460
+ };
3461
+ var listUserReferencesResultMessageSchema = variant("status", [
3462
+ strictObject({
3463
+ ...envelope,
3464
+ status: literal("success"),
3465
+ ...pagination,
3466
+ users: array(bridgeUserSnapshotSchema)
3467
+ }),
3468
+ strictObject({
3469
+ ...envelope,
3470
+ status: literal("error"),
3471
+ error: customBlockListUsersErrorInfoSchema
3472
+ })
3473
+ ]);
3474
+
3475
+ // ../protocol/src/users/messages/userSnapshots.ts
3476
+ var subscribeToUserMessageSchema = object({
3477
+ type: literal("subscribeToUser"),
3478
+ requestId: string(),
3479
+ userTarget: userTargetSchema,
3480
+ includeEmail: optional(boolean())
3481
+ });
3482
+ var subscribeToUserResultMessageSchema = variant("status", [
3483
+ object({
3484
+ type: literal("subscribeToUserResult"),
3485
+ requestId: string(),
3486
+ email: exactOptional(never()),
3487
+ status: literal("success")
3488
+ }),
3489
+ object({
3490
+ type: literal("subscribeToUserResult"),
3491
+ requestId: string(),
3492
+ email: exactOptional(never()),
3493
+ status: literal("error"),
3494
+ error: customBlockErrorInfoSchema
3495
+ })
3496
+ ]);
3497
+ var userSnapshotChangedMessageSchema = variant("status", [
3498
+ object({
3499
+ type: literal("userSnapshotChanged"),
3500
+ requestId: string(),
3501
+ email: exactOptional(never()),
3502
+ status: literal("available"),
3503
+ user: bridgeUserSnapshotSchema
3504
+ }),
3505
+ object({
3506
+ type: literal("userSnapshotChanged"),
3507
+ requestId: string(),
3508
+ email: exactOptional(never()),
3509
+ status: literal("loading")
3510
+ }),
3511
+ object({
3512
+ type: literal("userSnapshotChanged"),
3513
+ requestId: string(),
3514
+ email: exactOptional(never()),
3515
+ status: literal("error"),
3516
+ error: customBlockErrorInfoSchema
3517
+ })
3518
+ ]);
3519
+ var unsubscribeFromUserMessageSchema = object({
3520
+ type: literal("unsubscribeFromUser"),
3521
+ requestId: string()
3522
+ });
3523
+
3524
+ // ../protocol/src/messages/invalidSandboxMessage.ts
3525
+ var invalidSandboxMessageSchema = object({
3526
+ type: literal("invalidSandboxMessage"),
3527
+ /** Identifies the rejected request or response, when readable. */
3528
+ requestId: optional(string()),
3529
+ /** Identifies the affected query subscription, when readable. */
3530
+ subscriptionId: optional(string()),
3531
+ /**
3532
+ * A human-readable string intended for sandbox-side logging. It has no structured contract.
3533
+ */
3534
+ reason: string()
3535
+ });
3536
+
3537
+ // ../protocol/src/messages/hostToSandbox.ts
3538
+ var commonHostToSandboxSchemas = [
3539
+ connectResultMessageSchema,
3540
+ setupInitMessageSchema,
3541
+ getCurrentUserResultMessageSchema,
3542
+ getViewerResultMessageSchema,
3543
+ themeChangedMessageSchema,
3544
+ contrastModeChangedMessageSchema,
3545
+ pageErrorMessageSchema,
3546
+ parentErrorMessageSchema,
3547
+ getUserResultMessageSchema,
3548
+ listUsersResultMessageSchema,
3549
+ openExternalUrlResultMessageSchema,
3550
+ invalidSandboxMessageSchema
3551
+ ];
3552
+ var hostToSandboxSchemasWithoutPageResults = [
3553
+ ...commonHostToSandboxSchemas,
3554
+ listUserReferencesResultMessageSchema,
3555
+ getUserSnapshotResultMessageSchema,
3556
+ subscribeToUserResultMessageSchema,
3557
+ userSnapshotChangedMessageSchema,
3558
+ addressedOpenPageResultMessageSchema,
3559
+ containingPageChangedMessageSchema,
3560
+ parentChangedMessageSchema,
3561
+ dataSourceSnapshotChangedMessageSchema,
3562
+ dataSourceReadResultMessageSchema,
3563
+ subscribeToDataSourceResultMessageSchema,
3564
+ pageSnapshotChangedMessageSchema,
3565
+ subscribeToPageResultMessageSchema
3566
+ ];
3567
+ var hostToSandboxMessageSchema = variant("type", [
3568
+ ...hostToSandboxSchemasWithoutPageResults,
3569
+ dataSourceQueryResultMessageSchema,
3570
+ pageReadResultMessageSchema,
3571
+ pageCreateResultMessageSchema,
3572
+ pageUpdateResultMessageSchema
3573
+ ]);
3574
+
3575
+ // ../protocol/src/pages/messages/pageRecords.ts
3576
+ var pageRecordHostToSandboxMessageSchema = variant("type", [
3577
+ ...hostToSandboxSchemasWithoutPageResults,
3578
+ dataSourceQueryRecordResultMessageSchema,
3579
+ createPageResultMessageSchema,
3580
+ addressedGetPageResultMessageSchema,
3581
+ addressedUpdatePageResultMessageSchema
3582
+ ]);
3583
+
3584
+ // ../protocol/src/context/messages/pageChanged.ts
3585
+ var pageChangedMessageSchema = object({
3586
+ type: literal("pageChanged"),
3587
+ page: containingPageContextSchema
3588
+ });
3589
+
3590
+ // ../protocol/src/compatibility/contextThroughProtocol13.ts
3591
+ var parentChangedThroughProtocol13Schema = object({
3592
+ ...parentChangedMessageSchema.entries,
3593
+ parent: parentThroughProtocol13Schema
3594
+ });
3595
+ var pageChangedThroughProtocol13Schema = object({
3596
+ ...pageChangedMessageSchema.entries,
3597
+ page: variant("type", [
3598
+ containingPageSchema.options[0],
3599
+ object({
3600
+ ...containingPageSchema.options[1].entries,
3601
+ parent: parentThroughProtocol13Schema
3602
+ })
3603
+ ])
3604
+ });
3605
+
3606
+ // ../protocol/src/compatibility/protocol13/pagePropertyValues.ts
3607
+ var pagePropertyBaseSchema2 = { id: string() };
3608
+ var commonPagePropertySchemas2 = [
3609
+ object({
3610
+ ...pagePropertyBaseSchema2,
3611
+ type: literal("title"),
3612
+ title: array(bridgeRichTextItemSchema)
3613
+ }),
3614
+ object({
3615
+ ...pagePropertyBaseSchema2,
3616
+ type: literal("rich_text"),
3617
+ rich_text: array(bridgeRichTextItemSchema)
3618
+ }),
3619
+ object({
3620
+ ...pagePropertyBaseSchema2,
3621
+ type: literal("number"),
3622
+ number: nullable(number())
3623
+ }),
3624
+ object({
3625
+ ...pagePropertyBaseSchema2,
3626
+ type: literal("url"),
3627
+ url: nullableStringSchema
3628
+ }),
3629
+ object({
3630
+ ...pagePropertyBaseSchema2,
3631
+ type: literal("email"),
3632
+ email: nullableStringSchema
3633
+ }),
3634
+ object({
3635
+ ...pagePropertyBaseSchema2,
3636
+ type: literal("phone_number"),
3637
+ phone_number: nullableStringSchema
3638
+ }),
3639
+ object({
3640
+ ...pagePropertyBaseSchema2,
3641
+ type: literal("checkbox"),
3642
+ checkbox: boolean()
3643
+ }),
3644
+ object({
3645
+ ...pagePropertyBaseSchema2,
3646
+ type: literal("select"),
3647
+ select: nullable(bridgeSelectOptionSchema)
3648
+ }),
3649
+ object({
3650
+ ...pagePropertyBaseSchema2,
3651
+ type: literal("status"),
3652
+ status: nullable(bridgeSelectOptionSchema)
3653
+ }),
3654
+ object({
3655
+ ...pagePropertyBaseSchema2,
3656
+ type: literal("multi_select"),
3657
+ multi_select: array(bridgeSelectOptionSchema)
3658
+ }),
3659
+ object({
3660
+ ...pagePropertyBaseSchema2,
3661
+ type: literal("date"),
3662
+ date: nullable(bridgeDateSchema)
3663
+ }),
3664
+ object({
3665
+ ...pagePropertyBaseSchema2,
3666
+ type: literal("people"),
3667
+ people: array(bridgePersonItemSchema)
3668
+ }),
3669
+ object({
3670
+ ...pagePropertyBaseSchema2,
3671
+ type: literal("relation"),
3672
+ has_more: optional(boolean()),
3673
+ relation: array(bridgeRelationItemSchema)
3674
+ }),
3675
+ object({
3676
+ ...pagePropertyBaseSchema2,
3677
+ type: literal("place"),
3678
+ place: nullable(bridgePlaceSchema)
3679
+ }),
3680
+ object({
3681
+ ...pagePropertyBaseSchema2,
3682
+ type: literal("created_time"),
3683
+ created_time: nullableStringSchema
3684
+ }),
3685
+ object({
3686
+ ...pagePropertyBaseSchema2,
3687
+ type: literal("last_edited_time"),
3688
+ last_edited_time: nullableStringSchema
3689
+ }),
3690
+ object({
3691
+ ...pagePropertyBaseSchema2,
3692
+ type: literal("created_by"),
3693
+ created_by: nullable(bridgeActorSchema)
3694
+ }),
3695
+ object({
3696
+ ...pagePropertyBaseSchema2,
3697
+ type: literal("last_edited_by"),
3698
+ last_edited_by: nullable(bridgeActorSchema)
3699
+ }),
2661
3700
  object({
2662
- type: literal("listUsersResult"),
2663
- requestId: string(),
2664
- status: literal("success"),
2665
- list: bridgeUserListSchema
3701
+ ...pagePropertyBaseSchema2,
3702
+ type: literal("button"),
3703
+ button: string()
2666
3704
  }),
2667
3705
  object({
2668
- type: literal("listUsersResult"),
2669
- requestId: string(),
2670
- status: literal("error"),
2671
- error: customBlockListUsersErrorInfoSchema
3706
+ ...pagePropertyBaseSchema2,
3707
+ type: literal("formula"),
3708
+ formula: string()
3709
+ }),
3710
+ object({
3711
+ ...pagePropertyBaseSchema2,
3712
+ type: literal("rollup"),
3713
+ rollup: string()
2672
3714
  })
2673
- ]);
2674
-
2675
- // ../protocol/src/messages/invalidSandboxMessage.ts
2676
- var invalidSandboxMessageSchema = object({
2677
- type: literal("invalidSandboxMessage"),
2678
- /** Identifies the rejected request or response, when readable. */
2679
- requestId: optional(string()),
2680
- /** Identifies the affected query subscription, when readable. */
2681
- subscriptionId: optional(string()),
2682
- /**
2683
- * A human-readable string intended for sandbox-side logging. It has no structured contract.
2684
- */
2685
- reason: string()
2686
- });
2687
-
2688
- // ../protocol/src/messages/hostToSandbox.ts
2689
- var commonHostToSandboxSchemas = [
2690
- connectResultMessageSchema,
2691
- setupInitMessageSchema,
2692
- getDataSourceResultMessageSchema,
2693
- getCurrentUserResultMessageSchema,
2694
- getViewerResultMessageSchema,
2695
- dataSourcesInvalidatedMessageSchema,
2696
- themeChangedMessageSchema,
2697
- contrastModeChangedMessageSchema,
2698
- parentChangedMessageSchema,
2699
- pageChangedMessageSchema,
2700
- pageErrorMessageSchema,
2701
- parentErrorMessageSchema,
2702
- getUserResultMessageSchema,
2703
- listUsersResultMessageSchema,
2704
- openPageResultMessageSchema,
2705
- openExternalUrlResultMessageSchema,
2706
- invalidSandboxMessageSchema
2707
3715
  ];
2708
- var hostToSandboxMessageSchema = variant("type", [
2709
- ...commonHostToSandboxSchemas,
2710
- queryDataSourceResultMessageSchema,
2711
- getPageResultMessageSchema,
2712
- createPageResultMessageSchema,
2713
- updatePageResultMessageSchema
2714
- ]);
3716
+ var bridgeFilesPropertyWriteValueSchema2 = object({
3717
+ ...pagePropertyBaseSchema2,
3718
+ type: literal("files"),
3719
+ files: array(bridgeFilePropertyItemSchema)
3720
+ });
3721
+ var bridgeFilesPropertyReadValueSchema2 = object({
3722
+ ...pagePropertyBaseSchema2,
3723
+ type: literal("files"),
3724
+ files: array(bridgeFilePropertyReadItemSchema)
3725
+ });
2715
3726
 
2716
3727
  // ../protocol/src/compatibility/protocol12/page.ts
3728
+ var bridgePagePropertyForProtocol12Schema = variant("type", [
3729
+ ...commonPagePropertySchemas2,
3730
+ textUniqueIdPropertySchema,
3731
+ textVerificationPropertySchema,
3732
+ bridgeFilesPropertyWriteValueSchema2
3733
+ ]);
2717
3734
  var bridgePageForProtocol12Schema = object({
2718
3735
  ...bridgePageSchema.entries,
3736
+ parent: parentThroughProtocol13Schema,
2719
3737
  properties: record(
2720
3738
  string(),
2721
- nullable(bridgePagePropertyWriteValueSchema)
3739
+ nullable(bridgePagePropertyForProtocol12Schema)
2722
3740
  )
2723
3741
  });
2724
3742
 
@@ -2726,8 +3744,8 @@ var bridgePageForProtocol12Schema = object({
2726
3744
  var bridgePageForProtocol3To5Schema = object({
2727
3745
  object: literal("page"),
2728
3746
  id: notionPageIdSchema,
2729
- parent: notionParentSchema,
2730
- properties: bridgePagePropertyWriteMapSchema,
3747
+ parent: parentThroughProtocol13Schema,
3748
+ properties: record(string(), bridgePagePropertyForProtocol12Schema),
2731
3749
  created_time: optional(string()),
2732
3750
  last_edited_time: optional(string()),
2733
3751
  icon: optional(bridgePageIconSchema),
@@ -2740,12 +3758,53 @@ var bridgePageForProtocol3To5Schema = object({
2740
3758
  in_trash: boolean()
2741
3759
  });
2742
3760
 
3761
+ // ../protocol/src/compatibility/protocol3To5/dateValue.ts
3762
+ var dateOrDisabledReminder = optional(
3763
+ union([notionDateReminderSchema, notionDisabledReminderSchema])
3764
+ );
3765
+ var dateTimeOrDisabledReminder = optional(
3766
+ union([notionDateTimeReminderSchema, notionDisabledReminderSchema])
3767
+ );
3768
+ var protocol3To5DateSchema = object({
3769
+ type: literal("date"),
3770
+ start_date: string(),
3771
+ reminder: dateOrDisabledReminder
3772
+ });
3773
+ var protocol3To5DateRangeSchema = object({
3774
+ type: literal("daterange"),
3775
+ start_date: string(),
3776
+ end_date: string(),
3777
+ reminder: dateOrDisabledReminder
3778
+ });
3779
+ var protocol3To5DateTimeSchema = object({
3780
+ type: literal("datetime"),
3781
+ start_date: string(),
3782
+ start_time: string(),
3783
+ time_zone: optional(string()),
3784
+ reminder: dateTimeOrDisabledReminder
3785
+ });
3786
+ var protocol3To5DateTimeRangeSchema = object({
3787
+ type: literal("datetimerange"),
3788
+ start_date: string(),
3789
+ start_time: string(),
3790
+ end_date: string(),
3791
+ end_time: string(),
3792
+ time_zone: optional(string()),
3793
+ reminder: dateTimeOrDisabledReminder
3794
+ });
3795
+ var protocol3To5DateValueSchema = variant("type", [
3796
+ protocol3To5DateSchema,
3797
+ protocol3To5DateRangeSchema,
3798
+ protocol3To5DateTimeSchema,
3799
+ protocol3To5DateTimeRangeSchema
3800
+ ]);
3801
+
2743
3802
  // ../protocol/src/compatibility/protocol3To5/dataSourceValue.ts
2744
3803
  var notionDataSourceValueSchema = union([
2745
3804
  string(),
2746
3805
  number(),
2747
3806
  boolean(),
2748
- notionDateValueSchema,
3807
+ protocol3To5DateValueSchema,
2749
3808
  array(string()),
2750
3809
  array(notionRecordPointerSchema)
2751
3810
  ]);
@@ -2848,7 +3907,7 @@ var protocol3To11HostToSandboxMessageSchema = variant("type", [
2848
3907
  protocol3To11InitMessageSchema,
2849
3908
  themeChangedMessageSchema,
2850
3909
  contrastModeChangedMessageSchema,
2851
- parentChangedMessageSchema,
3910
+ parentChangedThroughProtocol13Schema,
2852
3911
  protocol3To11PageChangedMessageSchema,
2853
3912
  currentUserChangedForProtocol3To11Schema,
2854
3913
  dataSourcesChangedMessageSchema,
@@ -2863,9 +3922,153 @@ var protocol3To11HostToSandboxMessageSchema = variant("type", [
2863
3922
  updatePageResultMessageWithProtocol3To5CompatibilitySchema
2864
3923
  ]);
2865
3924
 
3925
+ // ../protocol/src/dataSources/messages/getDataSource.ts
3926
+ var getDataSourceMessageSchema = object({
3927
+ type: literal("getDataSource"),
3928
+ requestId: string(),
3929
+ key: string()
3930
+ });
3931
+ var getDataSourceResultMessageSchema = variant("status", [
3932
+ object({
3933
+ type: literal("getDataSourceResult"),
3934
+ requestId: string(),
3935
+ status: literal("success"),
3936
+ binding: required(
3937
+ omit(bridgeDataSourceBindingSchema, ["inaccessible"])
3938
+ )
3939
+ }),
3940
+ object({
3941
+ type: literal("getDataSourceResult"),
3942
+ requestId: string(),
3943
+ status: literal("error"),
3944
+ error: customBlockErrorInfoSchema
3945
+ })
3946
+ ]);
3947
+ var dataSourcesInvalidatedMessageSchema = object({
3948
+ type: literal("dataSourcesInvalidated")
3949
+ });
3950
+
3951
+ // ../protocol/src/compatibility/protocol13/propertyTypes.ts
3952
+ var SUPPORTED_PROTOCOL_13_PROPERTY_TYPES = /* @__PURE__ */ new Set([
3953
+ "title",
3954
+ "rich_text",
3955
+ "number",
3956
+ "checkbox",
3957
+ "url",
3958
+ "email",
3959
+ "phone_number",
3960
+ "select",
3961
+ "multi_select",
3962
+ "status",
3963
+ "date",
3964
+ "people",
3965
+ "files",
3966
+ "unique_id",
3967
+ "relation",
3968
+ "place",
3969
+ "formula",
3970
+ "rollup",
3971
+ "button",
3972
+ "verification",
3973
+ "created_time",
3974
+ "last_edited_time",
3975
+ "created_by",
3976
+ "last_edited_by"
3977
+ ]);
3978
+ function supportsPropertyTypeThroughProtocol13(type) {
3979
+ return SUPPORTED_PROTOCOL_13_PROPERTY_TYPES.has(type);
3980
+ }
3981
+
3982
+ // ../protocol/src/compatibility/hostToSandboxWithPageSchema.ts
3983
+ var dataSourceSchemaThroughProtocol13 = makeNotionDataSourceSchemaValidator(
3984
+ pipe(
3985
+ knownBridgePropertySchema,
3986
+ check((property) => supportsPropertyTypeThroughProtocol13(property.type))
3987
+ )
3988
+ );
3989
+ var getDataSourceResultThroughProtocol13 = variant("status", [
3990
+ object({
3991
+ ...getDataSourceResultMessageSchema.options[0].entries,
3992
+ binding: required(
3993
+ omit(
3994
+ object({
3995
+ ...bridgeDataSourceBindingSchema.entries,
3996
+ dataSourceSchema: optional(dataSourceSchemaThroughProtocol13)
3997
+ }),
3998
+ ["inaccessible"]
3999
+ ),
4000
+ ["dataSourcePointer", "dataSourceSchema", "propertyIdsByKey"]
4001
+ )
4002
+ }),
4003
+ getDataSourceResultMessageSchema.options[1]
4004
+ ]);
4005
+ function makeHostToSandboxMessageWithPageSchema(pageSchema2) {
4006
+ return variant("type", [
4007
+ ...commonHostToSandboxSchemas,
4008
+ openPageResultMessageSchema,
4009
+ parentChangedThroughProtocol13Schema,
4010
+ pageChangedThroughProtocol13Schema,
4011
+ dataSourcesInvalidatedMessageSchema,
4012
+ getDataSourceResultThroughProtocol13,
4013
+ variant("status", [
4014
+ object({
4015
+ ...queryDataSourceResultMessageSchema.options[0].entries,
4016
+ items: array(pageSchema2)
4017
+ }),
4018
+ queryDataSourceResultMessageSchema.options[1]
4019
+ ]),
4020
+ variant("status", [
4021
+ object({
4022
+ ...getPageResultMessageSchema.options[0].entries,
4023
+ page: pageSchema2
4024
+ }),
4025
+ getPageResultMessageSchema.options[1]
4026
+ ]),
4027
+ variant("status", [
4028
+ object({
4029
+ ...createPageResultMessageSchema.options[0].entries,
4030
+ page: pageSchema2
4031
+ }),
4032
+ createPageResultMessageSchema.options[1]
4033
+ ]),
4034
+ variant("status", [
4035
+ object({
4036
+ ...updatePageResultMessageSchema.options[0].entries,
4037
+ page: pageSchema2
4038
+ }),
4039
+ updatePageResultMessageSchema.options[1]
4040
+ ])
4041
+ ]);
4042
+ }
4043
+
4044
+ // ../protocol/src/compatibility/protocol12/hostToSandbox.ts
4045
+ var hostToSandboxMessageForProtocol12Schema = makeHostToSandboxMessageWithPageSchema(bridgePageForProtocol12Schema);
4046
+
4047
+ // ../protocol/src/compatibility/protocol13/page.ts
4048
+ var bridgePagePropertyForProtocol13Schema = variant("type", [
4049
+ ...commonPagePropertySchemas2,
4050
+ textUniqueIdPropertySchema,
4051
+ textVerificationPropertySchema,
4052
+ bridgeFilesPropertyReadValueSchema2
4053
+ ]);
4054
+ var bridgePageForProtocol13Schema = object({
4055
+ ...bridgePageSchema.entries,
4056
+ parent: parentThroughProtocol13Schema,
4057
+ properties: record(
4058
+ string(),
4059
+ nullable(bridgePagePropertyForProtocol13Schema)
4060
+ )
4061
+ });
4062
+
4063
+ // ../protocol/src/compatibility/protocol13/hostToSandbox.ts
4064
+ var hostToSandboxMessageForProtocol13Schema = makeHostToSandboxMessageWithPageSchema(bridgePageForProtocol13Schema);
4065
+
2866
4066
  // ../protocol/src/compatibility/hostToSandbox.ts
2867
4067
  var hostToSandboxMessageWithCompatibilitySchema = union([
2868
4068
  hostToSandboxMessageSchema,
4069
+ pageRecordHostToSandboxMessageSchema,
4070
+ hostToSandboxMessageForProtocol13Schema,
4071
+ hostToSandboxMessageForProtocol12Schema,
2869
4072
  protocol3To11HostToSandboxMessageSchema
2870
4073
  ]);
2871
4074
 
@@ -2874,7 +4077,7 @@ var bridgeDataSourceBindingsForProtocol3To10Schema = record(
2874
4077
  string(),
2875
4078
  object({
2876
4079
  collectionPointer: optional(dataSourcePointerValidator),
2877
- collectionSchema: optional(notionDataSourceSchemaValidator),
4080
+ collectionSchema: optional(bridgeDataSourceSchemaValidator),
2878
4081
  propertyIdsByKey: optional(record(string(), optional(string()))),
2879
4082
  inaccessible: optional(literal(true))
2880
4083
  })
@@ -2941,11 +4144,15 @@ var protocol3To11SandboxToHostMessageSchema = variant("type", [
2941
4144
  ]);
2942
4145
 
2943
4146
  // ../protocol/src/compatibility/protocol11/hostToSandbox.ts
4147
+ var pageWithHistoricalParentSchema = object({
4148
+ ...bridgePageSchema.entries,
4149
+ parent: parentThroughProtocol13Schema
4150
+ });
2944
4151
  var protocol11HostToSandboxMessageSchema = variant("type", [
2945
4152
  protocol3To11InitMessageSchema,
2946
4153
  themeChangedMessageSchema,
2947
4154
  contrastModeChangedMessageSchema,
2948
- parentChangedMessageSchema,
4155
+ parentChangedThroughProtocol13Schema,
2949
4156
  protocol3To11PageChangedMessageSchema,
2950
4157
  currentUserChangedForProtocol3To11Schema,
2951
4158
  dataSourcesChangedMessageSchema,
@@ -2954,12 +4161,47 @@ var protocol11HostToSandboxMessageSchema = variant("type", [
2954
4161
  openPageResultMessageSchema,
2955
4162
  openExternalUrlResultMessageSchema,
2956
4163
  invalidSandboxMessageSchema,
2957
- queryDataSourceResultMessageSchema,
2958
- getPageResultMessageSchema,
2959
- createPageResultMessageSchema,
2960
- updatePageResultMessageSchema
4164
+ variant("status", [
4165
+ object({
4166
+ ...queryDataSourceResultMessageSchema.options[0].entries,
4167
+ items: array(pageWithHistoricalParentSchema)
4168
+ }),
4169
+ queryDataSourceResultMessageSchema.options[1]
4170
+ ]),
4171
+ variant("status", [
4172
+ object({
4173
+ ...createPageResultMessageSchema.options[0].entries,
4174
+ page: pageWithHistoricalParentSchema
4175
+ }),
4176
+ createPageResultMessageSchema.options[1]
4177
+ ]),
4178
+ variant("status", [
4179
+ object({
4180
+ ...getPageResultMessageSchema.options[0].entries,
4181
+ page: pageWithHistoricalParentSchema
4182
+ }),
4183
+ getPageResultMessageSchema.options[1]
4184
+ ]),
4185
+ variant("status", [
4186
+ object({
4187
+ ...updatePageResultMessageSchema.options[0].entries,
4188
+ page: pageWithHistoricalParentSchema
4189
+ }),
4190
+ updatePageResultMessageSchema.options[1]
4191
+ ])
2961
4192
  ]);
2962
4193
 
4194
+ // ../protocol/src/dataSources/messages/keyedQueryDataSource.ts
4195
+ var keyedQueryDataSourceMessageSchema = strictObject({
4196
+ type: literal("queryDataSource"),
4197
+ key: string(),
4198
+ subscriptionId: string(),
4199
+ limit: optional(number()),
4200
+ filter: optional(unknown()),
4201
+ sorts: optional(unknown()),
4202
+ archiveStatus: optional(picklist(["active", "archived", "all"]))
4203
+ });
4204
+
2963
4205
  // ../protocol/src/handshake/ready.ts
2964
4206
  var readyMessageSchema = object({
2965
4207
  type: literal("ready"),
@@ -2969,6 +4211,35 @@ var readyMessageSchema = object({
2969
4211
 
2970
4212
  // ../protocol/src/messages/sandboxToHost.ts
2971
4213
  var sandboxToHostMessageSchema = variant("type", [
4214
+ connectRequestMessageSchema,
4215
+ getCurrentUserMessageSchema,
4216
+ getViewerMessageSchema,
4217
+ initResultRequestMessageSchema,
4218
+ readyMessageSchema,
4219
+ keyedQueryDataSourceMessageSchema,
4220
+ unsubscribeDataSourceQueryMessageSchema,
4221
+ keyedCreatePageMessageSchema,
4222
+ keyedGetPageMessageSchema,
4223
+ subscribeToPageMessageSchema,
4224
+ unsubscribeFromPageMessageSchema,
4225
+ getUserMessageSchema,
4226
+ listUsersMessageSchema,
4227
+ listUserReferencesMessageSchema,
4228
+ addressedOpenPageMessageSchema,
4229
+ getUserSnapshotMessageSchema,
4230
+ subscribeToUserMessageSchema,
4231
+ unsubscribeFromUserMessageSchema,
4232
+ openExternalUrlMessageSchema,
4233
+ keyedUpdatePageMessageSchema,
4234
+ resizeMessageSchema,
4235
+ dataSourceReadMessageSchema,
4236
+ subscribeToDataSourceMessageSchema,
4237
+ unsubscribeFromDataSourceMessageSchema,
4238
+ invalidHostMessageSchema
4239
+ ]);
4240
+
4241
+ // ../protocol/src/compatibility/protocol13/sandboxToHost.ts
4242
+ var protocol13SandboxToHostMessageSchema = variant("type", [
2972
4243
  connectRequestMessageSchema,
2973
4244
  getDataSourceMessageSchema,
2974
4245
  getCurrentUserMessageSchema,
@@ -2991,6 +4262,7 @@ var sandboxToHostMessageSchema = variant("type", [
2991
4262
  // ../protocol/src/compatibility/sandboxToHost.ts
2992
4263
  var sandboxToHostMessageWithCompatibilitySchema = union([
2993
4264
  sandboxToHostMessageSchema,
4265
+ protocol13SandboxToHostMessageSchema,
2994
4266
  protocol3To11SandboxToHostMessageSchema
2995
4267
  ]);
2996
4268
 
@@ -3007,7 +4279,7 @@ var notionDataSourceSchema = object({
3007
4279
  * schema to validate filter and sort references. Undefined when the host does not provide a
3008
4280
  * database schema.
3009
4281
  */
3010
- dataSourceSchema: optional(notionDataSourceSchemaValidator),
4282
+ dataSourceSchema: optional(bridgeDataSourceSchemaValidator),
3011
4283
  /**
3012
4284
  * Maps user-defined property keys to database property IDs. Use this map to resolve a key
3013
4285
  * such as `name` to its database property ID. A value of `undefined` marks a declared
@@ -3025,7 +4297,7 @@ var notionDataSourceSchema = object({
3025
4297
  * Use `propertiesById` to read a value. Use this map to read the value's schema. Use
3026
4298
  * `dataSourceSchema` to validate filter and sort references.
3027
4299
  */
3028
- propertySchemasById: record(string(), notionPropertySchemaSchema),
4300
+ propertySchemasById: record(string(), bridgePropertySchema),
3029
4301
  /**
3030
4302
  * `true` when the data source is bound but the viewer can't read it. The block still
3031
4303
  * initializes. Queries and writes that use this data source fail with
@@ -3034,6 +4306,43 @@ var notionDataSourceSchema = object({
3034
4306
  inaccessible: optional(literal(true))
3035
4307
  });
3036
4308
 
4309
+ // ../protocol/src/dataSources/resolveDataSourceBinding.ts
4310
+ function resolveDataSourceBinding(args) {
4311
+ const properties = Object.entries(
4312
+ args.manifestDataSource.properties ?? {}
4313
+ ).map(([propertyKey, property]) => {
4314
+ const propertyId = args.propertyIdsByKey !== void 0 && Object.hasOwn(args.propertyIdsByKey, propertyKey) ? args.propertyIdsByKey[propertyKey] : void 0;
4315
+ const propertiesById = args.dataSourceSchema?.propertiesById;
4316
+ const mappedSchema = propertyId === void 0 || propertiesById === void 0 || !Object.hasOwn(propertiesById, propertyId) ? void 0 : propertiesById[propertyId];
4317
+ return resolvePropertyBinding(
4318
+ propertyKey,
4319
+ propertyId,
4320
+ mappedSchema?.type,
4321
+ property.type
4322
+ );
4323
+ });
4324
+ if (args.dataSourceSchema === void 0) {
4325
+ return { status: "missing_schema", properties };
4326
+ }
4327
+ if (properties.every((property) => property.status === "mapped")) {
4328
+ return { status: "complete", properties };
4329
+ }
4330
+ return { status: "incomplete", properties };
4331
+ }
4332
+ function resolvePropertyBinding(propertyKey, propertyId, actualType, expectedType) {
4333
+ if (propertyId === void 0) {
4334
+ return { status: "missing", propertyKey, propertyId };
4335
+ }
4336
+ if (actualType === void 0) {
4337
+ return { status: "invalid", propertyKey, propertyId };
4338
+ }
4339
+ return {
4340
+ status: actualType === expectedType ? "mapped" : "incompatible",
4341
+ propertyKey,
4342
+ propertyId
4343
+ };
4344
+ }
4345
+
3037
4346
  // ../protocol/src/utils/readRequestId.ts
3038
4347
  var requestIdentitySchema = object({ requestId: string() });
3039
4348
 
@@ -6774,42 +8083,70 @@ var Temporal = /* @__PURE__ */ Object.defineProperties({}, {
6774
8083
  var Temporal2 = NativeTemporal || Temporal;
6775
8084
  var toTemporalInstant2 = NativeTemporal ? Date.prototype.toTemporalInstant : toTemporalInstant;
6776
8085
 
6777
- // shared/dataSources/notionDate.ts
6778
- function toNotionDateInput(value) {
6779
- if ("time_zone" in value && value.time_zone !== void 0) {
6780
- validateTimeZone(value.time_zone);
8086
+ // shared/dataSources/sampleDate.ts
8087
+ var sampleDateSchema = pipe(
8088
+ strictObject({
8089
+ start: string(),
8090
+ end: optional(nullable(string())),
8091
+ timeZone: optional(nullable(string())),
8092
+ reminder: optional(
8093
+ union([notionDateTimeReminderSchema, notionDisabledReminderSchema])
8094
+ )
8095
+ }),
8096
+ check(
8097
+ ({ start, reminder }) => start.includes("T") || reminder?.unit !== "hour" && reminder?.unit !== "minute",
8098
+ "Reminders on all-day dates must include a time of day."
8099
+ )
8100
+ );
8101
+ function readSampleDate(value) {
8102
+ if (typeof value !== "string") {
8103
+ const result = safeParse(sampleDateSchema, value);
8104
+ return result.success ? result.output : void 0;
6781
8105
  }
6782
- const start = parseDatePropertyEndpoint(value, "start").toString();
6783
- if (value.type === "daterange" || value.type === "datetimerange") {
6784
- return {
6785
- start,
6786
- end: parseDatePropertyEndpoint(value, "end").toString(),
6787
- reminder: value.reminder
6788
- };
8106
+ try {
8107
+ parseDateBoundary({ value, timeZone: void 0 });
8108
+ return { start: value };
8109
+ } catch (error) {
8110
+ if (error instanceof RangeError) {
8111
+ return void 0;
8112
+ }
8113
+ throw error;
6789
8114
  }
6790
- return { start, reminder: value.reminder };
6791
8115
  }
6792
- function parseDatePropertyEndpoint(value, endpoint) {
6793
- const useEnd = endpoint === "end" && (value.type === "daterange" || value.type === "datetimerange");
6794
- const date = useEnd ? value.end_date : value.start_date;
6795
- if (!/^\d{4}-\d{2}-\d{2}$/.test(date)) {
6796
- const field = useEnd ? "end_date" : "start_date";
6797
- throw new RangeError(`${field} must use YYYY-MM-DD.`);
6798
- }
6799
- if (value.type === "datetime" || value.type === "datetimerange") {
6800
- const time = useEnd && value.type === "datetimerange" ? value.end_time : value.start_time;
6801
- return parseDateBoundary({
6802
- value: `${date}T${time}`,
6803
- timeZone: value.time_zone
6804
- });
8116
+ function toBridgeDate({
8117
+ start,
8118
+ end,
8119
+ timeZone,
8120
+ ...rest
8121
+ }) {
8122
+ if (timeZone != null) {
8123
+ validateTimeZone(timeZone);
6805
8124
  }
6806
- return Temporal2.PlainDate.from(date);
8125
+ return {
8126
+ ...rest,
8127
+ start: parseDateBoundary({
8128
+ value: start,
8129
+ timeZone: timeZone ?? void 0
8130
+ }).toString(),
8131
+ ...end === void 0 ? {} : {
8132
+ end: end === null ? null : parseDateBoundary({
8133
+ value: end,
8134
+ timeZone: timeZone ?? void 0
8135
+ }).toString()
8136
+ },
8137
+ ...timeZone === void 0 ? {} : { time_zone: timeZone }
8138
+ };
6807
8139
  }
6808
8140
  function parseDateBoundary({
6809
8141
  value,
6810
8142
  timeZone
6811
8143
  }) {
6812
8144
  if (!value.includes("T")) {
8145
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(value)) {
8146
+ throw new RangeError(
8147
+ "Date values must use YYYY-MM-DD or an ISO timestamp."
8148
+ );
8149
+ }
6813
8150
  return Temporal2.PlainDate.from(value);
6814
8151
  }
6815
8152
  if (/(?:Z|[+-]\d{2}:?\d{2})$/i.test(value)) {
@@ -6836,35 +8173,6 @@ function validateTimeZone(timeZone) {
6836
8173
  }
6837
8174
  }
6838
8175
 
6839
- // shared/dataSources/toDataSourceDateValue.ts
6840
- function toDataSourceDateValue(value) {
6841
- if (is(notionDateValueSchema, value)) {
6842
- return value;
6843
- }
6844
- if (typeof value !== "string") {
6845
- return void 0;
6846
- }
6847
- try {
6848
- const [date, time] = value.split("T");
6849
- const { start } = toNotionDateInput({
6850
- type: "datetime",
6851
- start_date: date,
6852
- start_time: time ?? "00:00:00Z"
6853
- });
6854
- return {
6855
- type: "datetime",
6856
- start_date: start.slice(0, 10),
6857
- start_time: start.slice(11),
6858
- time_zone: "UTC"
6859
- };
6860
- } catch (error) {
6861
- if (error instanceof RangeError) {
6862
- return void 0;
6863
- }
6864
- throw error;
6865
- }
6866
- }
6867
-
6868
8176
  // shared/dataSources/localPropertyValues.ts
6869
8177
  var stringValue = string();
6870
8178
  var numberValue = pipe(number(), finite());
@@ -6878,7 +8186,7 @@ var sampleDataSourceValueSchema = union([
6878
8186
  stringValue,
6879
8187
  numberValue,
6880
8188
  booleanValue,
6881
- notionDateValueSchema,
8189
+ sampleDateSchema,
6882
8190
  stringArrayValue,
6883
8191
  pointerArrayValue,
6884
8192
  filesValue
@@ -6894,9 +8202,9 @@ var bindingValueSchemas = {
6894
8202
  number: numberValue,
6895
8203
  checkbox: booleanValue,
6896
8204
  multi_select: stringArrayValue,
6897
- date: notionDateValueSchema,
6898
- created_time: notionDateValueSchema,
6899
- last_edited_time: notionDateValueSchema,
8205
+ date: sampleDateSchema,
8206
+ created_time: sampleDateSchema,
8207
+ last_edited_time: sampleDateSchema,
6900
8208
  people: pointerArrayValue,
6901
8209
  relation: pointerArrayValue,
6902
8210
  files: union([stringValue, filesValue])
@@ -6911,6 +8219,15 @@ var convertedValueSchemas = {
6911
8219
  verification: stringValue,
6912
8220
  place: stringValue
6913
8221
  };
8222
+ function matchesBindingPropertyType(value, type) {
8223
+ if (type === "date" || type === "created_time" || type === "last_edited_time") {
8224
+ return readSampleDate(value) !== void 0;
8225
+ }
8226
+ if (type === "created_by" || type === "last_edited_by") {
8227
+ return Array.isArray(value) ? value.every((item) => parseSampleMetadataActor(item) !== void 0) : typeof value === "string" || parseSampleMetadataActor(value) !== void 0;
8228
+ }
8229
+ return is(bindingValueSchemas[type] ?? sampleDataSourceValueSchema, value);
8230
+ }
6914
8231
  function matchesConvertedPropertyType(value, type) {
6915
8232
  const schema = is(notionPropertyTypeSchema, type) ? convertedValueSchemas[type] : void 0;
6916
8233
  return is(schema ?? sampleDataSourceValueSchema, value);
@@ -6922,6 +8239,9 @@ function parseSampleFileItem(value) {
6922
8239
  const parsed = safeParse(bridgeFilePropertyReadItemSchema, value);
6923
8240
  return parsed.success && parsed.output.type !== "file" ? parsed.output : void 0;
6924
8241
  }
8242
+ function parseSampleMetadataActor(value) {
8243
+ return is(bridgePageSchema.entries.created_by, value) && value !== void 0 && value !== null && (value.table === "notion_user" || value.table === "bot" || value.table === "organization_bot") ? value : void 0;
8244
+ }
6925
8245
 
6926
8246
  // cli/diagnostics/formatUnknownError.ts
6927
8247
  function formatUnknownError(error) {
@@ -6940,21 +8260,21 @@ function claimUniqueKey(base, used) {
6940
8260
 
6941
8261
  // cli/utils/parseCliArgs.ts
6942
8262
  function parseCliArgs({
6943
- argv,
8263
+ argv: argv2,
6944
8264
  handlers,
6945
8265
  flags = {},
6946
8266
  onUnknown,
6947
8267
  onPositional
6948
8268
  }) {
6949
8269
  const takeValue = (name, index) => {
6950
- const value = argv[index];
8270
+ const value = argv2[index];
6951
8271
  if (value === void 0 || value.startsWith("--")) {
6952
8272
  throw new Error(`${name} requires a value.`);
6953
8273
  }
6954
8274
  return value;
6955
8275
  };
6956
- for (let index = 0; index < argv.length; index++) {
6957
- const arg = argv[index];
8276
+ for (let index = 0; index < argv2.length; index++) {
8277
+ const arg = argv2[index];
6958
8278
  const flag = flags[arg];
6959
8279
  if (flag !== void 0) {
6960
8280
  flag();
@@ -6996,7 +8316,7 @@ var sampleDataSourceTypeSchema = picklist([
6996
8316
  var sampleDataSourceRowSchema = looseObject({ id: string() });
6997
8317
  var sampleDataSourcePropertiesSchema = record(
6998
8318
  string(),
6999
- notionPropertySchemaSchema
8319
+ knownBridgePropertySchema
7000
8320
  );
7001
8321
  var loadedSampleDataSourceSchema = object({
7002
8322
  status: literal("loaded"),
@@ -7017,6 +8337,9 @@ var sampleDataSourceSchema = variant("status", [
7017
8337
  loadedSampleDataSourceSchema,
7018
8338
  sampleDataSourceLoadErrorSchema
7019
8339
  ]);
8340
+ function getSampleDataSourceId(filename) {
8341
+ return parse(notionDataSourceIdSchema, `ds-${filename}`);
8342
+ }
7020
8343
  function selectSampleDataSource({
7021
8344
  slotKey,
7022
8345
  sources,
@@ -7045,7 +8368,7 @@ var DEV_SHELL_STATUS_GROUP_NAMES = [
7045
8368
  "Future"
7046
8369
  ];
7047
8370
  function readDataSources(dataDir) {
7048
- return readSampleDataSourcesSnapshot(dataDir).dataSources.map((source) => {
8371
+ return rejectConflictingPageIds(readSampleDataSources(dataDir), void 0).map((source) => {
7049
8372
  if (source.status === "failed") {
7050
8373
  throw new Error(
7051
8374
  `${resolve(dataDir, `${source.filename}.json`)}: ${source.message}`
@@ -7054,7 +8377,16 @@ function readDataSources(dataDir) {
7054
8377
  return source;
7055
8378
  }).sort((left, right) => left.name.localeCompare(right.name));
7056
8379
  }
7057
- function readSampleDataSourcesSnapshot(dataDir) {
8380
+ function readSampleDataSourcesSnapshot(args) {
8381
+ const { dataDir, containingPageId } = args;
8382
+ return {
8383
+ dataSources: rejectConflictingPageIds(
8384
+ readSampleDataSources(dataDir),
8385
+ containingPageId
8386
+ )
8387
+ };
8388
+ }
8389
+ function readSampleDataSources(dataDir) {
7058
8390
  const dataSources = [];
7059
8391
  for (const name of listDataSourceFiles(dataDir).sort()) {
7060
8392
  const filename = basename(name, ".json");
@@ -7071,9 +8403,9 @@ function readSampleDataSourcesSnapshot(dataDir) {
7071
8403
  });
7072
8404
  }
7073
8405
  }
7074
- return { dataSources: rejectDuplicatePageIds(dataSources) };
8406
+ return dataSources;
7075
8407
  }
7076
- function rejectDuplicatePageIds(sources) {
8408
+ function rejectConflictingPageIds(sources, containingPageId) {
7077
8409
  const filenamesByPageId = /* @__PURE__ */ new Map();
7078
8410
  for (const source of sources) {
7079
8411
  if (source.status === "failed") {
@@ -7087,11 +8419,12 @@ function rejectDuplicatePageIds(sources) {
7087
8419
  }
7088
8420
  const errorsByFilename = /* @__PURE__ */ new Map();
7089
8421
  for (const [pageId, filenames] of filenamesByPageId) {
7090
- if (filenames.length < 2) {
8422
+ const isContainingPage = pageId === containingPageId;
8423
+ if (!isContainingPage && filenames.length < 2) {
7091
8424
  continue;
7092
8425
  }
7093
8426
  const files = [...new Set(filenames)].map((filename) => `${filename}.json`).join(", ");
7094
- const message = `Duplicate page ID "${pageId}" in ${files}. Give each row a unique ID across all sample data files.`;
8427
+ const message = isContainingPage ? `Page ID "${pageId}" is reserved for Current page. Give the sample row a different ID.` : `Duplicate page ID "${pageId}" in ${files}. Give each row a unique ID across all sample data files.`;
7095
8428
  for (const filename of filenames) {
7096
8429
  if (!errorsByFilename.has(filename)) {
7097
8430
  errorsByFilename.set(filename, message);
@@ -7118,18 +8451,24 @@ var statusGroupsSchema = array(
7118
8451
  option_ids: array(nonEmptyString)
7119
8452
  })
7120
8453
  );
7121
- var sourcePropertySchema = object({
8454
+ var sourcePropertySchema2 = object({
7122
8455
  name: optional(string()),
7123
8456
  description: optional(string()),
7124
8457
  type: notionPropertyTypeSchema,
7125
8458
  options: optional(statusOptionsSchema),
7126
- groups: optional(statusGroupsSchema)
8459
+ groups: optional(statusGroupsSchema),
8460
+ targetFile: optional(
8461
+ pipe(
8462
+ string(),
8463
+ regex(/^[^/\\]+\.json$/, "Expected a sample .json filename")
8464
+ )
8465
+ )
7127
8466
  });
7128
8467
  var sourceFileSchema = object({
7129
8468
  type: optional(sampleDataSourceTypeSchema, "worker"),
7130
8469
  name: optional(nonEmptyString),
7131
8470
  icon: optional(string()),
7132
- schema: optional(record(string(), sourcePropertySchema), {}),
8471
+ schema: optional(record(string(), sourcePropertySchema2), {}),
7133
8472
  rows: optional(array(looseObject({ id: nonEmptyString })), [])
7134
8473
  });
7135
8474
  function readDataSource(file) {
@@ -7159,6 +8498,11 @@ function readDataSource(file) {
7159
8498
  `${file}: schema.${propertyKey}: groups require a Status property`
7160
8499
  );
7161
8500
  }
8501
+ if (property.targetFile !== void 0 && property.type !== "relation") {
8502
+ throw new Error(
8503
+ `${file}: schema.${propertyKey}: targetFile requires a Relation property`
8504
+ );
8505
+ }
7162
8506
  const optionIds = new Set((property.options ?? []).map((option) => option.id));
7163
8507
  const missingOptionId = (property.groups ?? []).flatMap((group) => group.option_ids).find((optionId) => !optionIds.has(optionId));
7164
8508
  if (missingOptionId !== void 0) {
@@ -7178,7 +8522,7 @@ function readDataSource(file) {
7178
8522
  schema: Object.fromEntries(
7179
8523
  Object.entries(schema).map(([propertyKey, property]) => [
7180
8524
  propertyKey,
7181
- toNotionPropertySchema(propertyKey, property)
8525
+ toBridgePropertySchema(propertyKey, property)
7182
8526
  ])
7183
8527
  ),
7184
8528
  rows
@@ -7197,11 +8541,11 @@ function validateDateValues(file, source) {
7197
8541
  continue;
7198
8542
  }
7199
8543
  try {
7200
- const date = toDataSourceDateValue(value);
8544
+ const date = readSampleDate(value);
7201
8545
  if (date === void 0) {
7202
8546
  throw new Error("Expected a date value or ISO timestamp.");
7203
8547
  }
7204
- toNotionDateInput(date);
8548
+ toBridgeDate(date);
7205
8549
  } catch (cause) {
7206
8550
  throw new Error(
7207
8551
  `${file}: row "${row.id}", property "${propertyId}": ${formatUnknownError(cause)}`,
@@ -7211,12 +8555,17 @@ function validateDateValues(file, source) {
7211
8555
  }
7212
8556
  }
7213
8557
  }
7214
- function toNotionPropertySchema(propertyKey, property) {
7215
- return parse(notionPropertySchemaSchema, {
8558
+ function toBridgePropertySchema(propertyKey, property) {
8559
+ return parse(knownBridgePropertySchema, {
7216
8560
  ...property,
7217
8561
  name: property.name ?? propertyKey,
7218
8562
  options: property.options ?? [],
7219
- groups: property.groups ?? []
8563
+ groups: property.groups ?? [],
8564
+ ...property.targetFile === void 0 ? {} : {
8565
+ data_source_id: getSampleDataSourceId(
8566
+ basename(property.targetFile, ".json")
8567
+ )
8568
+ }
7220
8569
  });
7221
8570
  }
7222
8571
 
@@ -7278,7 +8627,7 @@ function convertPublicApiPropertyValue(publicType, value) {
7278
8627
  return rollupToText(payload);
7279
8628
  case "created_time":
7280
8629
  case "last_edited_time":
7281
- return timestampToLocal(payload);
8630
+ return { start: payload };
7282
8631
  case "created_by":
7283
8632
  case "last_edited_by":
7284
8633
  return [{ id: payload.id, table: "notion_user" }];
@@ -7336,46 +8685,18 @@ function rollupToText(rollup) {
7336
8685
  function dateToText(date) {
7337
8686
  return date.end ? `${date.start} \u2192 ${date.end}` : date.start;
7338
8687
  }
7339
- function publicDateToLocal(date) {
7340
- const start = date.start;
7341
- const end = date.end ?? void 0;
7342
- const timeZone = date.time_zone ?? void 0;
7343
- if (!start.includes("T")) {
7344
- return end === void 0 ? { type: "date", start_date: start.slice(0, 10) } : {
7345
- type: "daterange",
7346
- start_date: start.slice(0, 10),
7347
- end_date: end.slice(0, 10)
7348
- };
7349
- }
7350
- if (end === void 0) {
7351
- return {
7352
- type: "datetime",
7353
- start_date: start.slice(0, 10),
7354
- start_time: start.slice(11, 16),
7355
- ...timeZone !== void 0 ? { time_zone: timeZone } : {}
7356
- };
7357
- }
8688
+ function publicDateToLocal({ start, end, time_zone }) {
7358
8689
  return {
7359
- type: "datetimerange",
7360
- start_date: start.slice(0, 10),
7361
- start_time: start.slice(11, 16),
7362
- end_date: end.slice(0, 10),
7363
- end_time: end.slice(11, 16),
7364
- ...timeZone !== void 0 ? { time_zone: timeZone } : {}
8690
+ start,
8691
+ ...end == null ? {} : { end },
8692
+ ...time_zone == null ? {} : { timeZone: time_zone }
7365
8693
  };
7366
8694
  }
7367
- function timestampToLocal(timestamp) {
7368
- return timestamp.includes("T") ? {
7369
- type: "datetime",
7370
- start_date: timestamp.slice(0, 10),
7371
- start_time: timestamp.slice(11, 16)
7372
- } : { type: "date", start_date: timestamp.slice(0, 10) };
7373
- }
7374
8695
 
7375
8696
  // cli/dataSources/conversion/runConvert.ts
7376
8697
  var SUPPORTED_TYPES = new Set(NOTION_PROPERTY_TYPES);
7377
8698
  var UNSUPPORTED_TYPE_FALLBACK = "rich_text";
7378
- function parseConvertArgs(argv) {
8699
+ function parseConvertArgs(argv2) {
7379
8700
  const args = {
7380
8701
  input: void 0,
7381
8702
  name: void 0
@@ -7386,7 +8707,7 @@ function parseConvertArgs(argv) {
7386
8707
  );
7387
8708
  };
7388
8709
  parseCliArgs({
7389
- argv,
8710
+ argv: argv2,
7390
8711
  handlers: {
7391
8712
  "--in": (value) => {
7392
8713
  args.input = value;
@@ -7542,8 +8863,8 @@ function validateSource(source) {
7542
8863
  throw new Error(`Converted rows are invalid: ${issues.join("; ")}`);
7543
8864
  }
7544
8865
  }
7545
- async function runConvert(argv) {
7546
- const args = parseConvertArgs(argv);
8866
+ async function runConvert(argv2) {
8867
+ const args = parseConvertArgs(argv2);
7547
8868
  let raw;
7548
8869
  if (args.input !== void 0) {
7549
8870
  try {
@@ -7580,8 +8901,9 @@ async function runConvert(argv) {
7580
8901
  // cli/bindings/errors.ts
7581
8902
  var DevShellLauncherBindingError = class extends Error {
7582
8903
  code;
7583
- constructor(code, message) {
7584
- super(`${message} (error code: ${code})`);
8904
+ constructor(args) {
8905
+ const { code, message } = args;
8906
+ super(message);
7585
8907
  this.name = "DevShellLauncherBindingError";
7586
8908
  this.code = code;
7587
8909
  }
@@ -7589,14 +8911,14 @@ var DevShellLauncherBindingError = class extends Error {
7589
8911
  function bindingFailure(code, message) {
7590
8912
  return {
7591
8913
  status: "error",
7592
- error: new DevShellLauncherBindingError(code, message)
8914
+ error: new DevShellLauncherBindingError({ code, message })
7593
8915
  };
7594
8916
  }
7595
8917
 
7596
8918
  // cli/diagnostics/formatUnknownErrorWithStack.ts
7597
8919
  function formatUnknownErrorWithStack(error) {
7598
8920
  if (error instanceof DevShellLauncherBindingError) {
7599
- return error.message;
8921
+ return `${error.message} (error code: ${error.code})`;
7600
8922
  }
7601
8923
  return error instanceof Error ? error.stack ?? error.message : String(error);
7602
8924
  }
@@ -7606,23 +8928,63 @@ import { spawn } from "node:child_process";
7606
8928
  import { readFileSync as readFileSync3, writeSync } from "node:fs";
7607
8929
  import { join } from "node:path";
7608
8930
  import { Readable } from "node:stream";
8931
+
8932
+ // cli/diagnostics/DevShellStartupError.ts
8933
+ var DevShellStartupError = class extends Error {
8934
+ code;
8935
+ constructor(args) {
8936
+ const { code, message, options } = args;
8937
+ super(message, options);
8938
+ this.name = "DevShellStartupError";
8939
+ this.code = code;
8940
+ }
8941
+ };
8942
+
8943
+ // cli/diagnostics/startupOutput.ts
7609
8944
  var STARTUP_PIPE_ENV = "DEV_SHELL_STARTUP_PIPE";
7610
- var startupPipe;
7611
- async function runWithStartupOutput(main2) {
8945
+ async function runWithStartupOutput(args) {
8946
+ const { main: main2 } = args;
7612
8947
  if (process.env[STARTUP_PIPE_ENV] === "3") {
7613
8948
  delete process.env[STARTUP_PIPE_ENV];
7614
- startupPipe = 3;
7615
- await main2();
8949
+ const writeStartupEvent = createStartupWriter({ outputFd: 3 });
8950
+ try {
8951
+ await main2({ writeStartupEvent });
8952
+ } catch (error) {
8953
+ writeStartupFailure({ writeStartupEvent, error });
8954
+ throw error;
8955
+ }
7616
8956
  return;
7617
8957
  }
7618
- const argv = process.argv.slice(2);
7619
- if (!argv.includes("--json")) {
7620
- await main2();
8958
+ const argv2 = process.argv.slice(2);
8959
+ if (!argv2.includes("--json")) {
8960
+ await main2({});
7621
8961
  return;
7622
8962
  }
8963
+ await relayStartupOutput({ argv: argv2 });
8964
+ }
8965
+ function writeStartupFailure(args) {
8966
+ const { writeStartupEvent, error } = args;
8967
+ writeStartupEvent?.({
8968
+ event: "startup_failed",
8969
+ version: 1,
8970
+ error: {
8971
+ code: error instanceof DevShellLauncherBindingError || error instanceof DevShellStartupError ? error.code : "startup_error",
8972
+ message: formatUnknownError(error)
8973
+ }
8974
+ });
8975
+ }
8976
+ function readDevShellVersion(args) {
8977
+ const { packageDir } = args;
8978
+ const metadata = JSON.parse(
8979
+ readFileSync3(join(packageDir, "package.json"), "utf8")
8980
+ );
8981
+ return parse(object({ version: string() }), metadata).version;
8982
+ }
8983
+ async function relayStartupOutput(args) {
8984
+ const { argv: argv2 } = args;
7623
8985
  const child = spawn(
7624
8986
  process.execPath,
7625
- [...process.execArgv, process.argv[1], ...argv],
8987
+ [...process.execArgv, process.argv[1], ...argv2],
7626
8988
  {
7627
8989
  env: { ...process.env, [STARTUP_PIPE_ENV]: "3" },
7628
8990
  stdio: ["inherit", 2, 2, "pipe"]
@@ -7673,28 +9035,23 @@ async function runWithStartupOutput(main2) {
7673
9035
  }
7674
9036
  }
7675
9037
  }
7676
- function configureStartupOutput(json) {
7677
- if (!json) {
7678
- return void 0;
7679
- }
7680
- const outputFd = startupPipe;
7681
- const writeStdout = outputFd === void 0 ? process.stdout.write.bind(process.stdout) : (text) => writeSync(outputFd, text);
9038
+ function createStartupWriter(args) {
9039
+ const { outputFd } = args;
7682
9040
  process.stdout.write = process.stderr.write.bind(process.stderr);
9041
+ let written = false;
7683
9042
  return (event) => {
7684
- writeStdout(`${JSON.stringify(event)}
9043
+ if (written) {
9044
+ return;
9045
+ }
9046
+ written = true;
9047
+ writeSync(outputFd, `${JSON.stringify(event)}
7685
9048
  `);
7686
9049
  };
7687
9050
  }
7688
- function readDevShellVersion(packageDir) {
7689
- const metadata = JSON.parse(
7690
- readFileSync3(join(packageDir, "package.json"), "utf8")
7691
- );
7692
- return parse(object({ version: string() }), metadata).version;
7693
- }
7694
9051
 
7695
9052
  // cli/launchDevShell.ts
7696
9053
  import { existsSync as existsSync8, mkdirSync as mkdirSync6, mkdtempSync, rmSync } from "node:fs";
7697
- import { basename as basename3, join as join3, resolve as resolve7 } from "node:path";
9054
+ import { basename as basename3, join as join3, relative as relative2, resolve as resolve7, sep } from "node:path";
7698
9055
 
7699
9056
  // shared/dataSources/sampleDataSourceUpdates.ts
7700
9057
  var sampleDataSourcesSnapshotSchema = object({
@@ -7705,6 +9062,349 @@ function getLoadedDataSources(snapshot) {
7705
9062
  return snapshot.dataSources.filter((source) => source.status === "loaded").sort((a, b) => a.name.localeCompare(b.name));
7706
9063
  }
7707
9064
 
9065
+ // shared/dataSources/getSampleDataRowIssues.ts
9066
+ function getSampleDataRowIssues(args) {
9067
+ const { source, mappings } = args;
9068
+ const issues = [];
9069
+ const typeCheckedIds = /* @__PURE__ */ new Set();
9070
+ const checkedPairs = /* @__PURE__ */ new Set();
9071
+ for (const { propertyId, expectedType } of mappings) {
9072
+ typeCheckedIds.add(propertyId);
9073
+ const pair = `${propertyId}\0${expectedType}`;
9074
+ if (checkedPairs.has(pair)) {
9075
+ continue;
9076
+ }
9077
+ checkedPairs.add(pair);
9078
+ const rowIds = source.rows.filter((row) => Object.hasOwn(row, propertyId)).filter((row) => !matchesBindingPropertyType(row[propertyId], expectedType)).map((row) => row.id);
9079
+ if (rowIds.length > 0) {
9080
+ issues.push({
9081
+ type: "invalid_property_value",
9082
+ propertyId,
9083
+ expectedType,
9084
+ rowIds
9085
+ });
9086
+ }
9087
+ }
9088
+ return issues.concat(getUnmappedRowIssues({ source, typeCheckedIds }));
9089
+ }
9090
+ function getUnmappedRowIssues(args) {
9091
+ const { source, typeCheckedIds } = args;
9092
+ const issues = [];
9093
+ for (const row of source.rows) {
9094
+ for (const [propertyId, value] of Object.entries(row)) {
9095
+ if (propertyId === "id" || typeCheckedIds.has(propertyId)) {
9096
+ continue;
9097
+ }
9098
+ const type = source.schema[propertyId]?.type;
9099
+ const isSupported = type === "files" || type === "created_by" || type === "last_edited_by" ? matchesBindingPropertyType(value, type) : isSampleDataSourceValue(value);
9100
+ if (!isSupported) {
9101
+ issues.push({
9102
+ type: "unsupported_property_value",
9103
+ propertyId,
9104
+ rowIds: [row.id]
9105
+ });
9106
+ }
9107
+ }
9108
+ }
9109
+ return issues;
9110
+ }
9111
+
9112
+ // ../host/src/bindings.ts
9113
+ var customBlockHostBindingsSchema = object({
9114
+ pages: record(string(), object({ pageId: notionPageIdSchema })),
9115
+ dataSources: record(
9116
+ string(),
9117
+ object({
9118
+ dataSourceId: notionDataSourceIdSchema,
9119
+ propertyIdsByKey: record(string(), optional(string()))
9120
+ })
9121
+ )
9122
+ });
9123
+ var hostDataSourceSchemaValidator = makeNotionDataSourceSchemaValidator(
9124
+ union([knownBridgePropertySchema, bridgeUnknownPropertySchema])
9125
+ );
9126
+ var customBlockHostDataSourceStateSchema = variant("status", [
9127
+ object({ status: literal("unavailable") }),
9128
+ object({
9129
+ status: literal("available"),
9130
+ dataSource: object({
9131
+ dataSourceSchema: hostDataSourceSchemaValidator,
9132
+ title: fallback(optional(string()), void 0),
9133
+ description: fallback(optional(string()), void 0),
9134
+ icon: fallback(optional(bridgePageIconSchema), void 0),
9135
+ capabilities: object({
9136
+ read: boolean(),
9137
+ create: boolean(),
9138
+ update: boolean(),
9139
+ archive: boolean()
9140
+ })
9141
+ })
9142
+ })
9143
+ ]);
9144
+
9145
+ // ../host/src/compatibility/protocol3To11/handleInvalidProtocol3To11Handshake.ts
9146
+ var initializationIdentitySchema = object({ initializationId: string() });
9147
+ var protocolVersionSchema = object({
9148
+ // Preserve `NaN` so protocols 3–11 admission reports `invalid_protocol_version`.
9149
+ bridgeProtocolVersion: union([number(), nan()])
9150
+ });
9151
+
9152
+ // ../protocol/src/utils/readSubscriptionId.ts
9153
+ var subscriptionIdentitySchema = object({ subscriptionId: string() });
9154
+
9155
+ // ../protocol/src/dataSources/filters/filterFields.ts
9156
+ var BRIDGE_TO_SDK_FILTER_KEYS = {
9157
+ rich_text: "richText",
9158
+ phone_number: "phoneNumber",
9159
+ multi_select: "multiSelect",
9160
+ created_time: "createdTime",
9161
+ last_edited_time: "lastEditedTime",
9162
+ created_by: "createdBy",
9163
+ last_edited_by: "lastEditedBy",
9164
+ does_not_equal: "doesNotEqual",
9165
+ does_not_contain: "doesNotContain",
9166
+ contains_all: "containsAll",
9167
+ starts_with: "startsWith",
9168
+ ends_with: "endsWith",
9169
+ greater_than: "greaterThan",
9170
+ less_than: "lessThan",
9171
+ greater_than_or_equal_to: "greaterThanOrEqualTo",
9172
+ less_than_or_equal_to: "lessThanOrEqualTo",
9173
+ is_empty: "isEmpty",
9174
+ is_not_empty: "isNotEmpty",
9175
+ group_equals: "groupEquals",
9176
+ group_does_not_equal: "groupDoesNotEqual",
9177
+ on_or_before: "onOrBefore",
9178
+ on_or_after: "onOrAfter",
9179
+ this_week: "thisWeek",
9180
+ past_week: "pastWeek",
9181
+ past_month: "pastMonth",
9182
+ past_year: "pastYear",
9183
+ next_week: "nextWeek",
9184
+ next_month: "nextMonth",
9185
+ next_year: "nextYear"
9186
+ };
9187
+ var BRIDGE_TO_SDK_FILTER_KEY_MAP = new Map(
9188
+ Object.entries(BRIDGE_TO_SDK_FILTER_KEYS)
9189
+ );
9190
+ var SDK_TO_BRIDGE_FILTER_KEY_MAP = new Map(
9191
+ Object.entries(BRIDGE_TO_SDK_FILTER_KEYS).map(([bridgeKey, sdkKey]) => [
9192
+ sdkKey,
9193
+ bridgeKey
9194
+ ])
9195
+ );
9196
+
9197
+ // ../protocol/src/dataSources/queries/resolveSorts.ts
9198
+ var supportedDataSourceSortPropertyTypes = new Set(
9199
+ CUSTOM_BLOCK_DATA_SOURCE_SORTABLE_PROPERTY_TYPES
9200
+ );
9201
+
9202
+ // ../host/src/dataSources/validation/validateQueryDataSourceSorts.ts
9203
+ var supportedDataSourceSortPropertyTypes2 = new Set(
9204
+ CUSTOM_BLOCK_DATA_SOURCE_SORTABLE_PROPERTY_TYPES
9205
+ );
9206
+
9207
+ // ../host/src/manifest/types.ts
9208
+ var customBlockHostManifestResultSchema = variant("status", [
9209
+ object({ status: literal("success"), manifest: manifestSchema }),
9210
+ object({
9211
+ status: literal("error"),
9212
+ error: customBlockInitErrorInfoSchema
9213
+ })
9214
+ ]);
9215
+
9216
+ // ../host/src/messages/invalidNativeIconColor.ts
9217
+ var nativeIconMutationSchema = object({
9218
+ type: picklist(["updatePage", "createPage"]),
9219
+ requestId: string(),
9220
+ icon: object({
9221
+ type: literal("icon"),
9222
+ icon: object({ color: unknown() })
9223
+ })
9224
+ });
9225
+
9226
+ // ../host/src/createCustomBlockHost.ts
9227
+ var initializedHostMessageSchema = union([
9228
+ openPageResultMessageSchema,
9229
+ pageChangedThroughProtocol13Schema,
9230
+ pageRecordHostToSandboxMessageSchema,
9231
+ dataSourcesInvalidatedMessageSchema,
9232
+ getDataSourceResultMessageSchema
9233
+ ]);
9234
+
9235
+ // ../host/src/dataSources/bindings/resolveAutoPropertyBinding.ts
9236
+ function resolveAutoPropertyBinding(args) {
9237
+ const { propertyKey, manifestProperty, propertySchemasById } = args;
9238
+ const normalizedManifestName = normalizePropertyDisplayName(
9239
+ manifestProperty.name
9240
+ );
9241
+ const compatibleIds = [];
9242
+ const incompatible = [];
9243
+ for (const [propertyId, schema] of Object.entries(propertySchemasById)) {
9244
+ if (propertyId !== propertyKey && normalizePropertyDisplayName(schema.name) !== normalizedManifestName) {
9245
+ continue;
9246
+ }
9247
+ if (schema.type === manifestProperty.type) {
9248
+ compatibleIds.push(propertyId);
9249
+ } else {
9250
+ incompatible.push({ propertyId, actualType: schema.type });
9251
+ }
9252
+ }
9253
+ if (compatibleIds.length === 1) {
9254
+ return { status: "matched", propertyId: compatibleIds[0] };
9255
+ }
9256
+ if (compatibleIds.length > 1) {
9257
+ return { status: "ambiguous_match", candidatePropertyIds: compatibleIds };
9258
+ }
9259
+ return incompatible.length > 0 ? { status: "type_mismatch", candidates: incompatible } : { status: "no_match" };
9260
+ }
9261
+ function normalizePropertyDisplayName(value) {
9262
+ return value.trim().toLowerCase();
9263
+ }
9264
+
9265
+ // shared/dataSources/resolveInitialDataSourceBinding.ts
9266
+ function resolveInitialDataSourceBinding(args) {
9267
+ const { slotKey, slot, sources, sampleFiles, propertyOverrides } = args;
9268
+ const explicitFilename = Object.hasOwn(sampleFiles, slotKey) ? sampleFiles[slotKey] : void 0;
9269
+ const source = selectSampleDataSource({ slotKey, sources, explicitFilename });
9270
+ if (source?.status !== "loaded") {
9271
+ return { source, explicitFilename, properties: [] };
9272
+ }
9273
+ const overrides = Object.hasOwn(propertyOverrides, slotKey) ? propertyOverrides[slotKey] : void 0;
9274
+ const { properties } = resolveDataSourceBinding({
9275
+ manifestDataSource: slot,
9276
+ dataSourceSchema: { propertiesById: source.schema },
9277
+ propertyIdsByKey: overrides
9278
+ });
9279
+ return {
9280
+ source,
9281
+ explicitFilename,
9282
+ properties: properties.map(({ propertyKey, propertyId, status }) => {
9283
+ const manifestProperty = slot.properties[propertyKey];
9284
+ const property = { propertyKey, expectedType: manifestProperty.type };
9285
+ if (overrides === void 0 || !Object.hasOwn(overrides, propertyKey)) {
9286
+ return resolveAutomaticProperty(
9287
+ property,
9288
+ manifestProperty,
9289
+ source.schema
9290
+ );
9291
+ }
9292
+ switch (status) {
9293
+ case "mapped":
9294
+ return { ...property, type: "mapped", propertyId };
9295
+ case "invalid":
9296
+ return {
9297
+ ...property,
9298
+ type: "sample_key_not_found",
9299
+ sampleKey: propertyId
9300
+ };
9301
+ case "incompatible":
9302
+ return {
9303
+ ...property,
9304
+ type: "property_type_mismatch",
9305
+ bindingMode: "explicit",
9306
+ sampleProperties: [
9307
+ {
9308
+ sampleKey: propertyId,
9309
+ actualType: source.schema[propertyId].type
9310
+ }
9311
+ ]
9312
+ };
9313
+ case "missing":
9314
+ return { ...property, type: "property_binding_missing" };
9315
+ default:
9316
+ return unreachable(status);
9317
+ }
9318
+ })
9319
+ };
9320
+ }
9321
+ function resolveAutomaticProperty(property, manifestProperty, schema) {
9322
+ const result = resolveAutoPropertyBinding({
9323
+ propertyKey: property.propertyKey,
9324
+ manifestProperty,
9325
+ propertySchemasById: schema
9326
+ });
9327
+ switch (result.status) {
9328
+ case "matched":
9329
+ return { ...property, type: "mapped", propertyId: result.propertyId };
9330
+ case "no_match":
9331
+ return { ...property, type: "property_binding_missing" };
9332
+ case "ambiguous_match":
9333
+ return {
9334
+ ...property,
9335
+ type: "ambiguous_property_binding",
9336
+ candidateSampleKeys: result.candidatePropertyIds
9337
+ };
9338
+ case "type_mismatch":
9339
+ return {
9340
+ ...property,
9341
+ type: "property_type_mismatch",
9342
+ bindingMode: "automatic",
9343
+ sampleProperties: result.candidates.map(
9344
+ ({ propertyId, actualType }) => ({
9345
+ sampleKey: propertyId,
9346
+ actualType
9347
+ })
9348
+ )
9349
+ };
9350
+ default:
9351
+ return unreachable(result);
9352
+ }
9353
+ }
9354
+
9355
+ // cli/bindings/describeStartupDataSourceBindings.ts
9356
+ function describeStartupDataSourceBindings(block, sources) {
9357
+ return Object.fromEntries(
9358
+ Object.entries(block.manifest.dataSources).map(([slotKey, slot]) => [
9359
+ slotKey,
9360
+ describeBinding(
9361
+ resolveInitialDataSourceBinding({
9362
+ slotKey,
9363
+ slot,
9364
+ sources,
9365
+ sampleFiles: block.sampleFilesByDataSource,
9366
+ propertyOverrides: block.propertyIdsByDataSource
9367
+ })
9368
+ )
9369
+ ])
9370
+ );
9371
+ }
9372
+ function describeBinding(binding) {
9373
+ const { source, explicitFilename, properties } = binding;
9374
+ if (source === void 0) {
9375
+ return explicitFilename === void 0 ? { status: "data_source_binding_missing" } : {
9376
+ status: "data_source_load_failed",
9377
+ sampleFile: `data/${explicitFilename}`,
9378
+ message: "The selected sample file disappeared during startup."
9379
+ };
9380
+ }
9381
+ const sampleFile = `data/${source.filename}.json`;
9382
+ if (source.status === "failed") {
9383
+ return {
9384
+ status: "data_source_load_failed",
9385
+ sampleFile,
9386
+ message: source.message
9387
+ };
9388
+ }
9389
+ const mapped = properties.filter((property) => property.type === "mapped");
9390
+ const errors = getSampleDataRowIssues({ source, mappings: mapped });
9391
+ const report = {
9392
+ sampleFile,
9393
+ propertyIdsByKey: Object.fromEntries(
9394
+ mapped.map(({ propertyKey, propertyId }) => [propertyKey, propertyId])
9395
+ ),
9396
+ ...errors.length > 0 ? { errors } : {}
9397
+ };
9398
+ const [first, ...remaining] = properties.filter(
9399
+ (property) => property.type !== "mapped"
9400
+ );
9401
+ return first === void 0 ? { status: "complete", ...report } : {
9402
+ status: "incomplete_property_bindings",
9403
+ ...report,
9404
+ propertyIssues: [first, ...remaining]
9405
+ };
9406
+ }
9407
+
7708
9408
  // cli/bindings/parseDataSourceBindingOverride.ts
7709
9409
  function parseDataSourceBindingOverride({
7710
9410
  value
@@ -7714,14 +9414,34 @@ function parseDataSourceBindingOverride({
7714
9414
  const filename = value.slice(separator + 1);
7715
9415
  const dot = target.indexOf(".");
7716
9416
  if (separator < 0 || dot <= 0 || dot === target.length - 1 || target !== target.trim() || filename !== filename.trim() || !filename.endsWith(".json") || filename === ".json" || /[\\/\0]/.test(filename)) {
7717
- throw new DevShellLauncherBindingError(
7718
- "invalid_binding_syntax",
7719
- "--bind requires <capabilityKey>.<dataSourceKey>=<sampleDataFileName.json>. Use a filename in data/."
7720
- );
9417
+ throw new DevShellLauncherBindingError({
9418
+ code: "invalid_data_source_binding_syntax",
9419
+ message: "--bind-data-source requires <capabilityKey>.<dataSourceKey>=<sampleDataFileName.json>. Use a filename in data/."
9420
+ });
7721
9421
  }
7722
9422
  return { target, filename };
7723
9423
  }
7724
9424
 
9425
+ // cli/bindings/parsePageBindingOverride.ts
9426
+ function parsePageBindingOverride(args) {
9427
+ const { value } = args;
9428
+ let separator = 0;
9429
+ while (separator < value.length && value[separator] !== "=") {
9430
+ const next = value[separator + 1];
9431
+ separator += value[separator] === "\\" && (next === "=" || next === "\\") ? 2 : 1;
9432
+ }
9433
+ const target = value.slice(0, separator).replace(/\\([=\\])/g, "$1");
9434
+ const pageId = value.slice(separator + 1);
9435
+ const dot = target.indexOf(".");
9436
+ if (dot <= 0 || dot === target.length - 1 || pageId.length === 0) {
9437
+ throw new DevShellLauncherBindingError({
9438
+ code: "invalid_page_binding_syntax",
9439
+ message: "--bind-page requires <capabilityKey>.<pageKey>=<pageId>."
9440
+ });
9441
+ }
9442
+ return { target, pageId };
9443
+ }
9444
+
7725
9445
  // cli/bindings/parsePropertyBindingOverride.ts
7726
9446
  function parsePropertyBindingOverride({
7727
9447
  value
@@ -7731,10 +9451,10 @@ function parsePropertyBindingOverride({
7731
9451
  const sourcePropertyKey = value.slice(separator + 1);
7732
9452
  const parts = target.split(".");
7733
9453
  if (separator < 0 || parts.length < 3 || parts.some((part) => part.length === 0) || target !== target.trim() || sourcePropertyKey.length === 0 || sourcePropertyKey !== sourcePropertyKey.trim()) {
7734
- throw new DevShellLauncherBindingError(
7735
- "invalid_property_binding_syntax",
7736
- "--bind-property requires <capabilityKey>.<dataSourceKey>.<propertyKey>=<sourcePropertyKey>."
7737
- );
9454
+ throw new DevShellLauncherBindingError({
9455
+ code: "invalid_property_binding_syntax",
9456
+ message: "--bind-property requires <capabilityKey>.<dataSourceKey>.<propertyKey>=<sourcePropertyKey>."
9457
+ });
7738
9458
  }
7739
9459
  return { target, sourcePropertyKey };
7740
9460
  }
@@ -7816,14 +9536,14 @@ function resolveDataSourceBindingSlot({
7816
9536
  const matches = dataSourceSlots.filter((slot2) => slot2.target === target);
7817
9537
  if (matches.length !== 1) {
7818
9538
  return bindingFailure(
7819
- matches.length === 0 ? "unknown_binding_target" : "ambiguous_binding_target",
9539
+ matches.length === 0 ? "unknown_data_source_binding_target" : "ambiguous_data_source_binding_target",
7820
9540
  `${matches.length === 0 ? "Unknown" : "Ambiguous"} binding target "${target}". Available targets: ${dataSourceSlots.map((slot2) => slot2.target).join(", ") || "(none)"}.`
7821
9541
  );
7822
9542
  }
7823
9543
  if (explicitSlots.has(target)) {
7824
9544
  return bindingFailure(
7825
- "duplicate_binding_target",
7826
- `Duplicate --bind target "${target}". Specify each target once.`
9545
+ "duplicate_data_source_binding_target",
9546
+ `Duplicate --bind-data-source target "${target}". Specify each target once.`
7827
9547
  );
7828
9548
  }
7829
9549
  const slot = matches[0];
@@ -7866,8 +9586,8 @@ function resolvePropertyBindingSlot({
7866
9586
  const { dataSourceResult } = slot;
7867
9587
  if (dataSourceResult === void 0) {
7868
9588
  return bindingFailure(
7869
- "binding_source_missing",
7870
- `Cannot bind ${target}: no sample data source selected. Use --bind ${slot.target}=<sampleDataFileName.json>.`
9589
+ "property_binding_source_missing",
9590
+ `Cannot bind ${target}: no sample data source selected. Use --bind-data-source ${slot.target}=<sampleDataFileName.json>.`
7871
9591
  );
7872
9592
  }
7873
9593
  if (dataSourceResult.status === "failed") {
@@ -7938,7 +9658,71 @@ function buildBindingRegistry({
7938
9658
  return { registryBindings, registryPropertyBindings };
7939
9659
  }
7940
9660
 
9661
+ // cli/bindings/resolvePageBindingOverrides.ts
9662
+ function resolvePageBindingOverrides(args) {
9663
+ const { blocks, sources, overrides } = args;
9664
+ const pageIdsByBlock = /* @__PURE__ */ new Map();
9665
+ if (overrides.length === 0) {
9666
+ return { status: "success", value: pageIdsByBlock };
9667
+ }
9668
+ const slots = blocks.flatMap(
9669
+ (block) => Object.keys(block.config.manifest.pages ?? {}).map((pageKey) => ({
9670
+ blockKey: block.key,
9671
+ pageKey,
9672
+ target: `${block.key}.${pageKey}`
9673
+ }))
9674
+ );
9675
+ const pageIds = getLoadedSamplePageIds(sources);
9676
+ const seenTargets = /* @__PURE__ */ new Set();
9677
+ for (const { target, pageId } of overrides) {
9678
+ const matches = slots.filter((slot) => slot.target === target);
9679
+ if (matches.length === 0) {
9680
+ return bindingFailure(
9681
+ "unknown_page_binding_target",
9682
+ `Unknown page binding target "${target}". Available targets: ${slots.map((slot) => slot.target).join(", ") || "(none)"}.`
9683
+ );
9684
+ }
9685
+ if (matches.length > 1) {
9686
+ return bindingFailure(
9687
+ "ambiguous_page_binding_target",
9688
+ `More than one declared page slot matches "${target}".`
9689
+ );
9690
+ }
9691
+ if (seenTargets.has(target)) {
9692
+ return bindingFailure(
9693
+ "duplicate_page_binding_target",
9694
+ `Duplicate --bind-page target "${target}". Specify each target once.`
9695
+ );
9696
+ }
9697
+ if (!pageIds.has(pageId)) {
9698
+ return bindingFailure(
9699
+ "sample_page_not_found",
9700
+ `Cannot bind ${target}: no loaded sample row has ID "${pageId}".`
9701
+ );
9702
+ }
9703
+ seenTargets.add(target);
9704
+ const { blockKey, pageKey } = matches[0];
9705
+ pageIdsByBlock.set(blockKey, {
9706
+ ...pageIdsByBlock.get(blockKey),
9707
+ [pageKey]: pageId
9708
+ });
9709
+ }
9710
+ return { status: "success", value: pageIdsByBlock };
9711
+ }
9712
+ function getLoadedSamplePageIds(sources) {
9713
+ const pageIds = /* @__PURE__ */ new Set();
9714
+ for (const source of sources) {
9715
+ if (source.status === "loaded") {
9716
+ for (const row of source.rows) {
9717
+ pageIds.add(row.id);
9718
+ }
9719
+ }
9720
+ }
9721
+ return pageIds;
9722
+ }
9723
+
7941
9724
  // cli/dataSources/createDevShellDataService.ts
9725
+ import { randomUUID } from "node:crypto";
7942
9726
  import { existsSync as existsSync3, mkdirSync as mkdirSync2, watch } from "node:fs";
7943
9727
  import { basename as basename2, dirname } from "node:path";
7944
9728
 
@@ -7968,7 +9752,9 @@ function createDevShellDataService(options) {
7968
9752
  const { dataDir, prebuiltDir, blocks, log } = options;
7969
9753
  mkdirSync2(dataDir, { recursive: true });
7970
9754
  const clients = /* @__PURE__ */ new Set();
9755
+ const containingPageId = parse(notionPageIdSchema, randomUUID());
7971
9756
  let snapshot = {
9757
+ containingPageId,
7972
9758
  blocks,
7973
9759
  prebuiltSources: readDataSources(prebuiltDir).map((source) => ({
7974
9760
  filename: source.filename,
@@ -7979,7 +9765,7 @@ function createDevShellDataService(options) {
7979
9765
  (property) => property.name
7980
9766
  )
7981
9767
  })),
7982
- ...readSampleDataSourcesSnapshot(dataDir)
9768
+ ...readSampleDataSourcesSnapshot({ dataDir, containingPageId })
7983
9769
  };
7984
9770
  let serialized = JSON.stringify(snapshot);
7985
9771
  let timer;
@@ -8009,7 +9795,10 @@ function createDevShellDataService(options) {
8009
9795
  return;
8010
9796
  }
8011
9797
  try {
8012
- snapshot = { ...snapshot, ...readSampleDataSourcesSnapshot(dataDir) };
9798
+ snapshot = {
9799
+ ...snapshot,
9800
+ ...readSampleDataSourcesSnapshot({ dataDir, containingPageId })
9801
+ };
8013
9802
  publish();
8014
9803
  } catch (error) {
8015
9804
  fail(error);
@@ -8117,6 +9906,10 @@ function createDevShellDataService(options) {
8117
9906
  handleUpdatesRequest,
8118
9907
  handleAddPrebuiltRequest,
8119
9908
  getSnapshot: () => snapshot,
9909
+ refreshSnapshot() {
9910
+ scan();
9911
+ return snapshot;
9912
+ },
8120
9913
  close() {
8121
9914
  clearImmediate(initialScan);
8122
9915
  clearTimeout(timer);
@@ -8306,15 +10099,15 @@ async function closeResource(resource) {
8306
10099
  }
8307
10100
 
8308
10101
  // cli/lifecycle/installProcessSignalHandlers.ts
8309
- function installProcessSignalHandlers(run) {
10102
+ function installProcessSignalHandlers(run2) {
8310
10103
  for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"]) {
8311
- process.on(signal, () => run.shutdown(signal));
10104
+ process.on(signal, () => run2.shutdown(signal));
8312
10105
  }
8313
- process.on("exit", () => run.shutdown("exit"));
10106
+ process.on("exit", () => run2.shutdown("exit"));
8314
10107
  process.on("uncaughtException", (error) => {
8315
10108
  console.error(error);
8316
10109
  process.exitCode = 1;
8317
- run.shutdown("SIGTERM");
10110
+ run2.shutdown("SIGTERM");
8318
10111
  });
8319
10112
  }
8320
10113
 
@@ -8372,7 +10165,7 @@ function buildCustomBlockDevShellCsp(args) {
8372
10165
  // Local hosts replace Notion's production app, relay, and mobile-shell ancestors.
8373
10166
  `frame-ancestors 'self' ${shellOrigin} ${allowedFrameAncestors.join(" ")}`,
8374
10167
  // Allow WebAssembly compilation without enabling JavaScript string evaluation.
8375
- "script-src 'self' 'unsafe-inline' 'wasm-unsafe-eval'",
10168
+ "script-src 'self' 'wasm-unsafe-eval'",
8376
10169
  `style-src 'self' 'unsafe-inline' https://fonts.googleapis.com ${approved}`
8377
10170
  ].map((directive) => directive.trim()).join("; ");
8378
10171
  }
@@ -8576,7 +10369,8 @@ var SharedServer = class {
8576
10369
  // cli/server/waitForPreviewUrls.ts
8577
10370
  import { request } from "node:http";
8578
10371
  import { setTimeout as delay } from "node:timers/promises";
8579
- async function waitForPreviewUrls(urls, signal, timeoutMs = 1e4) {
10372
+ async function waitForPreviewUrls(args) {
10373
+ const { urls, signal, timeoutMs = 1e4 } = args;
8580
10374
  const deadline = new AbortController();
8581
10375
  const timer = setTimeout(() => deadline.abort(), timeoutMs);
8582
10376
  const bounded = AbortSignal.any([signal, deadline.signal]);
@@ -8598,9 +10392,10 @@ async function waitForPreviewUrls(urls, signal, timeoutMs = 1e4) {
8598
10392
  bounded.throwIfAborted();
8599
10393
  } catch (error) {
8600
10394
  if (deadline.signal.aborted && !signal.aborted) {
8601
- throw new Error(
8602
- `Preview readiness timed out after ${timeoutMs}ms. No successful HTTP response from: ${[...pending].join(", ")}.`
8603
- );
10395
+ throw new DevShellStartupError({
10396
+ code: "preview_readiness_timeout",
10397
+ message: `Preview readiness timed out after ${timeoutMs}ms. No successful HTTP response from: ${[...pending].join(", ")}.`
10398
+ });
8604
10399
  }
8605
10400
  throw error;
8606
10401
  } finally {
@@ -8712,6 +10507,17 @@ const resolved =
8712
10507
 
8713
10508
  const injectBlockBootstrap = {
8714
10509
  name: "dev-shell:block-bootstrap",
10510
+ configResolved(config) {
10511
+ // Run React's Fast Refresh preamble before Vite transforms the HTML, so
10512
+ // Vite serves it as a same-origin module that the block CSP allows.
10513
+ const refresh = config.plugins.find(plugin => plugin.name === "vite:react-refresh")
10514
+ if (typeof refresh?.transformIndexHtml === "function") {
10515
+ refresh.transformIndexHtml = {
10516
+ order: "pre",
10517
+ handler: refresh.transformIndexHtml,
10518
+ }
10519
+ }
10520
+ },
8715
10521
  transformIndexHtml: {
8716
10522
  order: "pre",
8717
10523
  handler() {
@@ -18932,7 +20738,7 @@ import { promisify } from "node:util";
18932
20738
  var WORKER_MANIFEST_FILENAME = "worker_manifest.json";
18933
20739
  async function generateWorkerManifest(workerDir, options = {}) {
18934
20740
  const manifest = await extractWorkerManifest(workerDir, options);
18935
- const dir = resolve6(workerDir, ".dev-shell");
20741
+ const dir = options.outputDir ?? resolve6(workerDir, ".dev-shell");
18936
20742
  mkdirSync5(dir, { recursive: true });
18937
20743
  const manifestPath = resolve6(dir, WORKER_MANIFEST_FILENAME);
18938
20744
  writeFileSync3(manifestPath, `${JSON.stringify(manifest, null, 2)}
@@ -18990,7 +20796,7 @@ async function extractWorkerManifest(workerDir, options = {}) {
18990
20796
  `Built worker at ${entry} exposed no usable manifest (expected .manifest or .capabilities).`
18991
20797
  );
18992
20798
  }
18993
- async function buildWorker(workerDir, run) {
20799
+ async function buildWorker(workerDir, run2) {
18994
20800
  const child = spawn2("npm run build", {
18995
20801
  cwd: workerDir,
18996
20802
  shell: true,
@@ -19002,7 +20808,7 @@ async function buildWorker(workerDir, run) {
19002
20808
  child.once("error", reject);
19003
20809
  child.once("close", (code2) => resolve10(code2));
19004
20810
  });
19005
- run?.addResource(async () => {
20811
+ run2?.addResource(async () => {
19006
20812
  const pid = child.pid;
19007
20813
  if (pid === void 0 || child.exitCode !== null || child.signalCode !== null) {
19008
20814
  return;
@@ -19017,7 +20823,7 @@ async function buildWorker(workerDir, run) {
19017
20823
  await finished;
19018
20824
  });
19019
20825
  const code = await finished;
19020
- if (run?.closing) {
20826
+ if (run2?.closing) {
19021
20827
  throw new Error("Worker build cancelled");
19022
20828
  }
19023
20829
  if (code !== 0) {
@@ -19049,6 +20855,7 @@ async function prepareWorkerLaunchPlan(workerDir, options = {}) {
19049
20855
  }
19050
20856
  const { manifest, manifestPath } = await generateWorkerManifest(root, {
19051
20857
  build: options.build,
20858
+ outputDir: options.configDir,
19052
20859
  run: options.run
19053
20860
  });
19054
20861
  const capabilities = blockCapabilities(manifest);
@@ -19085,30 +20892,59 @@ async function prepareWorkerLaunchPlan(workerDir, options = {}) {
19085
20892
  registry
19086
20893
  };
19087
20894
  }
19088
- function parseWorkerLaunchArgs(argv) {
20895
+ function warnAboutDeprecatedBind({
20896
+ argv: argv2
20897
+ }) {
20898
+ if (argv2.some((arg) => arg === "--bind" || arg.startsWith("--bind="))) {
20899
+ console.error("--bind is deprecated. Use --bind-data-source instead.");
20900
+ }
20901
+ }
20902
+ function parseWorkerLaunchArgs(args) {
20903
+ try {
20904
+ return parseWorkerLaunchOptions(args);
20905
+ } catch (error) {
20906
+ if (error instanceof DevShellLauncherBindingError) {
20907
+ throw error;
20908
+ }
20909
+ throw new DevShellStartupError({
20910
+ code: "invalid_arguments",
20911
+ message: formatUnknownError(error),
20912
+ options: { cause: error }
20913
+ });
20914
+ }
20915
+ }
20916
+ function parseWorkerLaunchOptions(options) {
20917
+ const { argv: argv2 } = options;
19089
20918
  const args = {
19090
20919
  worker: void 0,
19091
20920
  shellPort: DEFAULT_DEV_SHELL_PORT,
19092
20921
  strictPort: false,
19093
20922
  json: false,
19094
20923
  bindings: [],
19095
- propertyBindings: []
20924
+ propertyBindings: [],
20925
+ pageBindings: []
19096
20926
  };
19097
20927
  let hasPositionalWorker = false;
20928
+ const bindDataSource = (value) => {
20929
+ args.bindings.push(parseDataSourceBindingOverride({ value }));
20930
+ };
19098
20931
  parseCliArgs({
19099
- argv,
20932
+ argv: argv2,
19100
20933
  flags: {
19101
20934
  "--json": () => {
19102
20935
  args.json = true;
19103
20936
  }
19104
20937
  },
19105
20938
  handlers: {
19106
- "--bind": (value) => {
19107
- args.bindings.push(parseDataSourceBindingOverride({ value }));
19108
- },
20939
+ "--bind-data-source": bindDataSource,
20940
+ /** @deprecated Use `--bind-data-source` instead. */
20941
+ "--bind": bindDataSource,
19109
20942
  "--bind-property": (value) => {
19110
20943
  args.propertyBindings.push(parsePropertyBindingOverride({ value }));
19111
20944
  },
20945
+ "--bind-page": (value) => {
20946
+ args.pageBindings.push(parsePageBindingOverride({ value }));
20947
+ },
19112
20948
  "--worker": (value) => {
19113
20949
  if (value.length === 0) {
19114
20950
  throw new Error("--worker requires a path to a worker directory.");
@@ -19127,7 +20963,7 @@ function parseWorkerLaunchArgs(argv) {
19127
20963
  },
19128
20964
  onUnknown: (arg) => {
19129
20965
  throw new Error(
19130
- `Unknown dev shell option "${arg}". Supported: --worker <dir>, --port <port>, --json, --bind <capabilityKey>.<dataSourceKey>=<sampleDataFileName>, --bind-property <capabilityKey>.<dataSourceKey>.<propertyKey>=<sourcePropertyKey>.`
20966
+ `Unknown dev shell option "${arg}". Supported: --worker <dir>, --port <port>, --json, --bind-data-source <capabilityKey>.<dataSourceKey>=<sampleDataFileName>, --bind-property <capabilityKey>.<dataSourceKey>.<propertyKey>=<sourcePropertyKey>, --bind-page <capabilityKey>.<pageKey>=<pageId>. --bind is a deprecated alias for --bind-data-source.`
19131
20967
  );
19132
20968
  },
19133
20969
  onPositional: (arg) => {
@@ -19188,8 +21024,9 @@ function logWorkerPlan(workerName, plan, snapshot) {
19188
21024
  );
19189
21025
  }
19190
21026
  function applyBindingsAndLog(args, plan, workerDir, snapshot) {
21027
+ const blocks = plan.blocks.map((block) => block.capability);
19191
21028
  const result = resolveDevShellLauncherBindings({
19192
- blocks: plan.blocks.map((block) => block.capability),
21029
+ blocks,
19193
21030
  dataSourceResults: snapshot.dataSources,
19194
21031
  sourceOverrides: args.bindings,
19195
21032
  propertyOverrides: args.propertyBindings
@@ -19197,42 +21034,50 @@ function applyBindingsAndLog(args, plan, workerDir, snapshot) {
19197
21034
  if (result.status === "error") {
19198
21035
  throw result.error;
19199
21036
  }
21037
+ const pages = resolvePageBindingOverrides({
21038
+ blocks,
21039
+ sources: snapshot.dataSources,
21040
+ overrides: args.pageBindings
21041
+ });
21042
+ if (pages.status === "error") {
21043
+ throw pages.error;
21044
+ }
19200
21045
  const { registryBindings, registryPropertyBindings } = result.value;
19201
21046
  for (const entry of plan.registry) {
19202
21047
  entry.propertyIdsByDataSource = registryPropertyBindings.get(entry.key) ?? {};
19203
21048
  entry.sampleFilesByDataSource = registryBindings.get(entry.key) ?? {};
21049
+ entry.initialPageIdsByKey = pages.value.get(entry.key);
19204
21050
  }
19205
21051
  logWorkerPlan(basename3(workerDir), plan, snapshot);
19206
21052
  }
19207
21053
  async function launchDevShell(options) {
19208
- const { installSignalHandlers = true } = options;
21054
+ const { installSignalHandlers = true, writeStartupEvent } = options;
19209
21055
  const shared = new SharedServer();
19210
21056
  const beforeCleanup = () => shared.close();
19211
- const run = options.createRun?.(beforeCleanup) ?? new DevShellRun(beforeCleanup);
21057
+ const run2 = options.createRun?.(beforeCleanup) ?? new DevShellRun(beforeCleanup);
19212
21058
  if (installSignalHandlers) {
19213
- installProcessSignalHandlers(run);
21059
+ installProcessSignalHandlers(run2);
19214
21060
  }
19215
21061
  const readiness = new AbortController();
19216
- run.addResource(() => readiness.abort());
21062
+ run2.addResource(() => readiness.abort());
19217
21063
  try {
19218
- const writeReady = configureStartupOutput(options.argv.includes("--json"));
19219
- const args = parseWorkerLaunchArgs(options.argv);
21064
+ const args = parseWorkerLaunchArgs({ argv: options.argv });
19220
21065
  const { workerDir } = resolveWorkerLaunch({ ...options, args });
19221
21066
  const originalCwd = process.cwd();
19222
21067
  process.chdir(workerDir);
19223
- run.addResource(() => process.chdir(originalCwd));
21068
+ run2.addResource(() => process.chdir(originalCwd));
19224
21069
  args.shellPort = await shared.listen(args.shellPort, args.strictPort);
19225
21070
  const tempRoot = join3(workerDir, ".dev-shell");
19226
21071
  mkdirSync6(tempRoot, { recursive: true });
19227
21072
  const configDir = mkdtempSync(join3(tempRoot, "run-"));
19228
- run.addResource(() => rmSync(configDir, { recursive: true, force: true }));
21073
+ run2.addResource(() => rmSync(configDir, { recursive: true, force: true }));
19229
21074
  logNamed(basename3(workerDir), "Extracting worker manifest...");
19230
21075
  const plan = await prepareWorkerLaunchPlan(workerDir, {
19231
21076
  shellPort: args.shellPort,
19232
21077
  configDir,
19233
- run
21078
+ run: run2
19234
21079
  });
19235
- if (run.closing) {
21080
+ if (run2.closing) {
19236
21081
  return;
19237
21082
  }
19238
21083
  const dataService = createDevShellDataService({
@@ -19241,7 +21086,7 @@ async function launchDevShell(options) {
19241
21086
  blocks: plan.registry,
19242
21087
  log: (message) => logNamed(basename3(workerDir), message)
19243
21088
  });
19244
- run.addResource(() => dataService.close());
21089
+ run2.addResource(() => dataService.close());
19245
21090
  applyBindingsAndLog(args, plan, workerDir, dataService.getSnapshot());
19246
21091
  shared.shellApiRoutes.set(
19247
21092
  "/api/dev-shell",
@@ -19257,10 +21102,10 @@ async function launchDevShell(options) {
19257
21102
  log: logNamed
19258
21103
  });
19259
21104
  if (closeShell) {
19260
- run.addResource(closeShell);
21105
+ run2.addResource(closeShell);
19261
21106
  }
19262
21107
  for (const block of plan.blocks) {
19263
- if (run.closing) {
21108
+ if (run2.closing) {
19264
21109
  return;
19265
21110
  }
19266
21111
  const close = await mountVite({
@@ -19273,36 +21118,62 @@ async function launchDevShell(options) {
19273
21118
  shared,
19274
21119
  config: { configFile: block.configFile, root: block.blockDir }
19275
21120
  });
19276
- run.addResource(close);
21121
+ run2.addResource(close);
19277
21122
  }
19278
- if (run.closing) {
21123
+ if (run2.closing) {
19279
21124
  return;
19280
21125
  }
19281
- if (writeReady) {
19282
- await waitForPreviewUrls(
19283
- [
21126
+ if (writeStartupEvent) {
21127
+ await waitForPreviewUrls({
21128
+ urls: [
19284
21129
  `http://localhost:${args.shellPort}`,
19285
21130
  ...plan.registry.map((block) => block.url)
19286
21131
  ],
19287
- readiness.signal
19288
- );
19289
- if (run.closing) {
21132
+ signal: readiness.signal
21133
+ });
21134
+ if (run2.closing) {
19290
21135
  return;
19291
21136
  }
19292
- writeReady({
21137
+ const { dataSources } = dataService.refreshSnapshot();
21138
+ const availablePageIds = args.pageBindings.length > 0 ? getLoadedSamplePageIds(dataSources) : void 0;
21139
+ writeStartupEvent({
19293
21140
  event: "ready",
21141
+ version: 1,
19294
21142
  shellUrl: `http://localhost:${args.shellPort}`,
19295
21143
  workerDir,
19296
21144
  devShellVersion: options.devShellVersion,
19297
- customBlocks: describeStartupCustomBlocks(
19298
- plan,
19299
- dataService.getSnapshot().dataSources
19300
- )
21145
+ workerManifestPath: relative2(workerDir, plan.manifestPath).split(sep).join("/"),
21146
+ customBlocks: plan.registry.map((block) => {
21147
+ const pageKeys = Object.keys(block.manifest.pages ?? {});
21148
+ const initialPageIdsByKey = block.initialPageIdsByKey ?? {};
21149
+ return {
21150
+ key: block.key,
21151
+ url: block.url,
21152
+ bindings: {
21153
+ dataSources: describeStartupDataSourceBindings(
21154
+ block,
21155
+ dataSources
21156
+ ),
21157
+ pages: pageKeys.length === 0 ? void 0 : Object.fromEntries(
21158
+ pageKeys.map((key) => {
21159
+ const selectedPageId = Object.hasOwn(
21160
+ initialPageIdsByKey,
21161
+ key
21162
+ ) ? initialPageIdsByKey[key] : void 0;
21163
+ return [
21164
+ key,
21165
+ selectedPageId === void 0 || !availablePageIds?.has(selectedPageId) ? { status: "page_binding_missing" } : { status: "complete", selectedPageId }
21166
+ ];
21167
+ })
21168
+ )
21169
+ }
21170
+ };
21171
+ })
19301
21172
  });
19302
21173
  }
19303
21174
  printSummary(args, plan.registry);
19304
21175
  } catch (error) {
19305
- if (run.closing) {
21176
+ if (run2.closing) {
19306
21177
  return;
19307
21178
  }
19308
21179
  console.error(
@@ -19310,31 +21181,17 @@ async function launchDevShell(options) {
19310
21181
  ${formatUnknownErrorWithStack(error)}`
19311
21182
  );
19312
21183
  process.exitCode = 1;
19313
- run.shutdown("SIGTERM");
19314
- }
19315
- }
19316
- function describeStartupCustomBlocks(plan, sources) {
19317
- return plan.blocks.map(({ capability }, index) => {
19318
- const block = plan.registry[index];
19319
- const manifest = capability.config.manifest;
19320
- const sampleFilesByDataSource = {};
19321
- for (const slotKey of Object.keys(manifest.dataSources)) {
19322
- const source = selectSampleDataSource({
19323
- slotKey,
19324
- sources,
19325
- explicitFilename: block.sampleFilesByDataSource[slotKey]
19326
- });
19327
- if (source?.filename !== void 0) {
19328
- sampleFilesByDataSource[slotKey] = `data/${source.filename}.json`;
19329
- }
21184
+ try {
21185
+ writeStartupFailure({ writeStartupEvent, error });
21186
+ } finally {
21187
+ run2.shutdown("SIGTERM");
19330
21188
  }
19331
- return { key: block.key, url: block.url, manifest, sampleFilesByDataSource };
19332
- });
21189
+ }
19333
21190
  }
19334
21191
 
19335
21192
  // cli/server/createUiHandler.ts
19336
21193
  import { readFileSync as readFileSync6 } from "node:fs";
19337
- import { extname, join as join4, normalize, resolve as resolve8, sep } from "node:path";
21194
+ import { extname, join as join4, normalize, resolve as resolve8, sep as sep2 } from "node:path";
19338
21195
  var CONTENT_TYPES = {
19339
21196
  ".html": "text/html; charset=utf-8",
19340
21197
  ".js": "text/javascript; charset=utf-8",
@@ -19361,12 +21218,12 @@ function createUiHandler(distDir) {
19361
21218
  }
19362
21219
  const path = normalize(urlPath);
19363
21220
  const filePath = join4(dist, path);
19364
- if (!filePath.startsWith(dist + sep) && filePath !== dist) {
21221
+ if (!filePath.startsWith(dist + sep2) && filePath !== dist) {
19365
21222
  res.writeHead(403).end();
19366
21223
  return;
19367
21224
  }
19368
21225
  const ext = extname(filePath);
19369
- if (path === "/" || path === `${sep}index.html` || ext === "") {
21226
+ if (path === "/" || path === `${sep2}index.html` || ext === "") {
19370
21227
  res.writeHead(200, { "Content-Type": CONTENT_TYPES[".html"] }).end(indexHtml);
19371
21228
  return;
19372
21229
  }
@@ -19394,22 +21251,24 @@ var createShellLaunch = async ({ shared }) => {
19394
21251
  handle: createUiHandler(distDir)
19395
21252
  });
19396
21253
  };
19397
- async function main() {
19398
- const argv = process.argv.slice(2);
19399
- if (argv[0] === "convert") {
19400
- await runConvert(argv.slice(1));
19401
- return;
19402
- }
21254
+ var argv = process.argv.slice(2);
21255
+ async function main(args) {
21256
+ const { writeStartupEvent } = args;
21257
+ warnAboutDeprecatedBind({ argv });
19403
21258
  await launchDevShell({
19404
- devShellVersion: readDevShellVersion(resolve9(__dirname, "../..")),
21259
+ devShellVersion: readDevShellVersion({
21260
+ packageDir: resolve9(__dirname, "../..")
21261
+ }),
19405
21262
  argv,
19406
21263
  workerBaseDir: process.cwd(),
19407
21264
  detectFromDir: process.cwd(),
19408
21265
  createShellLaunch,
19409
- prebuiltDir: resolve9(__dirname, "../..", "data")
21266
+ prebuiltDir: resolve9(__dirname, "../..", "data"),
21267
+ writeStartupEvent
19410
21268
  });
19411
21269
  }
19412
- runWithStartupOutput(main).catch((error) => {
21270
+ var run = argv[0] === "convert" ? runConvert(argv.slice(1)) : runWithStartupOutput({ main });
21271
+ run.catch((error) => {
19413
21272
  console.error(formatUnknownErrorWithStack(error));
19414
21273
  process.exitCode = 1;
19415
21274
  });