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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.html CHANGED
@@ -4,7 +4,7 @@
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>Workers local shell</title>
7
- <script type="module" crossorigin src="/assets/index-BlifLoaB.js"></script>
7
+ <script type="module" crossorigin src="/assets/index-B1RObNc_.js"></script>
8
8
  <link rel="stylesheet" crossorigin href="/assets/index-CohEBjwO.css">
9
9
  </head>
10
10
  <body>
@@ -1518,7 +1518,7 @@ var contrastModeChangedMessageSchema = object({
1518
1518
  });
1519
1519
 
1520
1520
  // ../protocol/src/context/containingPage.ts
1521
- var customBlockPageSchema = variant("type", [
1521
+ var containingPageSchema = variant("type", [
1522
1522
  /** The viewer cannot access the containing page. Its ID and parent are not exposed. */
1523
1523
  object({ type: literal("unavailable") }),
1524
1524
  /** The accessible containing page, with its ID and parent location. */
@@ -1542,7 +1542,7 @@ var customBlockPageSchema = variant("type", [
1542
1542
  // ../protocol/src/context/messages/pageChanged.ts
1543
1543
  var pageChangedMessageSchema = object({
1544
1544
  type: literal("pageChanged"),
1545
- page: customBlockPageSchema
1545
+ page: containingPageSchema
1546
1546
  });
1547
1547
 
1548
1548
  // ../protocol/src/context/messages/pageError.ts
@@ -1945,13 +1945,14 @@ var bridgePagePropertyWriteValueSchema = variant("type", [
1945
1945
  files: array(bridgeFilePropertyItemSchema)
1946
1946
  })
1947
1947
  ]);
1948
+ var bridgeFilesPropertyReadValueSchema = object({
1949
+ ...pagePropertyBaseSchema,
1950
+ type: literal("files"),
1951
+ files: array(bridgeFilePropertyReadItemSchema)
1952
+ });
1948
1953
  var bridgePagePropertyReadValueSchema = variant("type", [
1949
1954
  ...basePropertySchemas,
1950
- object({
1951
- ...pagePropertyBaseSchema,
1952
- type: literal("files"),
1953
- files: array(bridgeFilePropertyReadItemSchema)
1954
- })
1955
+ bridgeFilesPropertyReadValueSchema
1955
1956
  ]);
1956
1957
 
1957
1958
  // ../protocol/src/pages/properties/bridgePagePropertyMaps.ts
@@ -3036,119 +3037,6 @@ var notionDataSourceSchema = object({
3036
3037
  // ../protocol/src/utils/readRequestId.ts
3037
3038
  var requestIdentitySchema = object({ requestId: string() });
3038
3039
 
3039
- // shared/dataSources/localPropertyValues.ts
3040
- var stringValue = string();
3041
- var numberValue = pipe(number(), finite());
3042
- var booleanValue = boolean();
3043
- var stringArrayValue = array(string());
3044
- var pointerArrayValue = array(notionRecordPointerSchema);
3045
- var anyLocalValue = union([
3046
- stringValue,
3047
- numberValue,
3048
- booleanValue,
3049
- notionDateValueSchema,
3050
- stringArrayValue,
3051
- pointerArrayValue
3052
- ]);
3053
- var bindingValueSchemas = {
3054
- title: stringValue,
3055
- rich_text: stringValue,
3056
- url: stringValue,
3057
- email: stringValue,
3058
- phone_number: stringValue,
3059
- select: stringValue,
3060
- status: stringValue,
3061
- number: numberValue,
3062
- checkbox: booleanValue,
3063
- multi_select: stringArrayValue,
3064
- date: notionDateValueSchema,
3065
- created_time: notionDateValueSchema,
3066
- last_edited_time: notionDateValueSchema,
3067
- people: pointerArrayValue,
3068
- relation: pointerArrayValue,
3069
- files: stringValue
3070
- };
3071
- var convertedValueSchemas = {
3072
- ...bindingValueSchemas,
3073
- created_by: pointerArrayValue,
3074
- last_edited_by: pointerArrayValue,
3075
- unique_id: stringValue,
3076
- formula: stringValue,
3077
- rollup: stringValue,
3078
- verification: stringValue,
3079
- place: stringValue
3080
- };
3081
- function matchesConvertedPropertyType(value, type) {
3082
- const schema = is(notionPropertyTypeSchema, type) ? convertedValueSchemas[type] : void 0;
3083
- return is(schema ?? anyLocalValue, value);
3084
- }
3085
- function isConvertedDataSourceValue(value) {
3086
- return is(anyLocalValue, value);
3087
- }
3088
-
3089
- // cli/diagnostics/formatUnknownError.ts
3090
- function formatUnknownError(error) {
3091
- return error instanceof Error ? error.message : String(error);
3092
- }
3093
-
3094
- // cli/utils/claimUniqueKey.ts
3095
- function claimUniqueKey(base, used) {
3096
- let key = base;
3097
- for (let counter = 2; used.has(key); counter++) {
3098
- key = `${base}_${counter}`;
3099
- }
3100
- used.add(key);
3101
- return key;
3102
- }
3103
-
3104
- // cli/utils/parseCliArgs.ts
3105
- function parseCliArgs({
3106
- argv,
3107
- handlers,
3108
- flags = {},
3109
- onUnknown,
3110
- onPositional
3111
- }) {
3112
- const takeValue = (name, index) => {
3113
- const value = argv[index];
3114
- if (value === void 0 || value.startsWith("--")) {
3115
- throw new Error(`${name} requires a value.`);
3116
- }
3117
- return value;
3118
- };
3119
- for (let index = 0; index < argv.length; index++) {
3120
- const arg = argv[index];
3121
- const flag = flags[arg];
3122
- if (flag !== void 0) {
3123
- flag();
3124
- continue;
3125
- }
3126
- const separator = arg.indexOf("=");
3127
- const name = separator === -1 ? arg : arg.slice(0, separator);
3128
- const handler = handlers[name];
3129
- if (handler === void 0) {
3130
- if (arg.startsWith("-")) {
3131
- onUnknown(arg);
3132
- } else {
3133
- onPositional(arg);
3134
- }
3135
- continue;
3136
- }
3137
- const value = separator === -1 ? takeValue(name, ++index) : arg.slice(separator + 1);
3138
- handler(value);
3139
- }
3140
- }
3141
-
3142
- // cli/utils/slugify.ts
3143
- function slugify(name) {
3144
- const slug = name.toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
3145
- return slug.length > 0 ? slug : void 0;
3146
- }
3147
-
3148
- // cli/dataSources/readSampleDataSources.ts
3149
- import { readFileSync } from "node:fs";
3150
- import { basename, resolve } from "node:path";
3151
-
3152
3040
  // ../node_modules/.pnpm/temporal-polyfill@1.0.6/node_modules/temporal-polyfill/chunks/root.js
3153
3041
  var NativeTemporal = globalThis.Temporal;
3154
3042
 
@@ -6948,6 +6836,156 @@ function validateTimeZone(timeZone) {
6948
6836
  }
6949
6837
  }
6950
6838
 
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
+ // shared/dataSources/localPropertyValues.ts
6869
+ var stringValue = string();
6870
+ var numberValue = pipe(number(), finite());
6871
+ var booleanValue = boolean();
6872
+ var stringArrayValue = array(string());
6873
+ var pointerArrayValue = array(notionRecordPointerSchema);
6874
+ var filesValue = array(
6875
+ custom((value) => parseSampleFileItem(value) !== void 0)
6876
+ );
6877
+ var sampleDataSourceValueSchema = union([
6878
+ stringValue,
6879
+ numberValue,
6880
+ booleanValue,
6881
+ notionDateValueSchema,
6882
+ stringArrayValue,
6883
+ pointerArrayValue,
6884
+ filesValue
6885
+ ]);
6886
+ var bindingValueSchemas = {
6887
+ title: stringValue,
6888
+ rich_text: stringValue,
6889
+ url: stringValue,
6890
+ email: stringValue,
6891
+ phone_number: stringValue,
6892
+ select: stringValue,
6893
+ status: stringValue,
6894
+ number: numberValue,
6895
+ checkbox: booleanValue,
6896
+ multi_select: stringArrayValue,
6897
+ date: notionDateValueSchema,
6898
+ created_time: notionDateValueSchema,
6899
+ last_edited_time: notionDateValueSchema,
6900
+ people: pointerArrayValue,
6901
+ relation: pointerArrayValue,
6902
+ files: union([stringValue, filesValue])
6903
+ };
6904
+ var convertedValueSchemas = {
6905
+ ...bindingValueSchemas,
6906
+ created_by: pointerArrayValue,
6907
+ last_edited_by: pointerArrayValue,
6908
+ unique_id: stringValue,
6909
+ formula: stringValue,
6910
+ rollup: stringValue,
6911
+ verification: stringValue,
6912
+ place: stringValue
6913
+ };
6914
+ function matchesConvertedPropertyType(value, type) {
6915
+ const schema = is(notionPropertyTypeSchema, type) ? convertedValueSchemas[type] : void 0;
6916
+ return is(schema ?? sampleDataSourceValueSchema, value);
6917
+ }
6918
+ function isSampleDataSourceValue(value) {
6919
+ return is(sampleDataSourceValueSchema, value);
6920
+ }
6921
+ function parseSampleFileItem(value) {
6922
+ const parsed = safeParse(bridgeFilePropertyReadItemSchema, value);
6923
+ return parsed.success && parsed.output.type !== "file" ? parsed.output : void 0;
6924
+ }
6925
+
6926
+ // cli/diagnostics/formatUnknownError.ts
6927
+ function formatUnknownError(error) {
6928
+ return error instanceof Error ? error.message : String(error);
6929
+ }
6930
+
6931
+ // cli/utils/claimUniqueKey.ts
6932
+ function claimUniqueKey(base, used) {
6933
+ let key = base;
6934
+ for (let counter = 2; used.has(key); counter++) {
6935
+ key = `${base}_${counter}`;
6936
+ }
6937
+ used.add(key);
6938
+ return key;
6939
+ }
6940
+
6941
+ // cli/utils/parseCliArgs.ts
6942
+ function parseCliArgs({
6943
+ argv,
6944
+ handlers,
6945
+ flags = {},
6946
+ onUnknown,
6947
+ onPositional
6948
+ }) {
6949
+ const takeValue = (name, index) => {
6950
+ const value = argv[index];
6951
+ if (value === void 0 || value.startsWith("--")) {
6952
+ throw new Error(`${name} requires a value.`);
6953
+ }
6954
+ return value;
6955
+ };
6956
+ for (let index = 0; index < argv.length; index++) {
6957
+ const arg = argv[index];
6958
+ const flag = flags[arg];
6959
+ if (flag !== void 0) {
6960
+ flag();
6961
+ continue;
6962
+ }
6963
+ const separator = arg.indexOf("=");
6964
+ const name = separator === -1 ? arg : arg.slice(0, separator);
6965
+ const handler = handlers[name];
6966
+ if (handler === void 0) {
6967
+ if (arg.startsWith("-")) {
6968
+ onUnknown(arg);
6969
+ } else {
6970
+ onPositional(arg);
6971
+ }
6972
+ continue;
6973
+ }
6974
+ const value = separator === -1 ? takeValue(name, ++index) : arg.slice(separator + 1);
6975
+ handler(value);
6976
+ }
6977
+ }
6978
+
6979
+ // cli/utils/slugify.ts
6980
+ function slugify(name) {
6981
+ const slug = name.toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
6982
+ return slug.length > 0 ? slug : void 0;
6983
+ }
6984
+
6985
+ // cli/dataSources/readSampleDataSources.ts
6986
+ import { readFileSync } from "node:fs";
6987
+ import { basename, resolve } from "node:path";
6988
+
6951
6989
  // shared/dataSources/sampleDataSource.ts
6952
6990
  var sampleDataSourceTypeSchema = picklist([
6953
6991
  "built-in",
@@ -6992,35 +7030,6 @@ function selectSampleDataSource({
6992
7030
  return sources.find((source) => source.filename === `worker_${slotKey}`) ?? sources.find((source) => source.filename === slotKey);
6993
7031
  }
6994
7032
 
6995
- // shared/dataSources/toDataSourceDateValue.ts
6996
- function toDataSourceDateValue(value) {
6997
- if (is(notionDateValueSchema, value)) {
6998
- return value;
6999
- }
7000
- if (typeof value !== "string") {
7001
- return void 0;
7002
- }
7003
- try {
7004
- const [date, time] = value.split("T");
7005
- const { start } = toNotionDateInput({
7006
- type: "datetime",
7007
- start_date: date,
7008
- start_time: time ?? "00:00:00Z"
7009
- });
7010
- return {
7011
- type: "datetime",
7012
- start_date: start.slice(0, 10),
7013
- start_time: start.slice(11),
7014
- time_zone: "UTC"
7015
- };
7016
- } catch (error) {
7017
- if (error instanceof RangeError) {
7018
- return void 0;
7019
- }
7020
- throw error;
7021
- }
7022
- }
7023
-
7024
7033
  // cli/dataSources/listDataSourceFiles.ts
7025
7034
  import { existsSync, readdirSync } from "node:fs";
7026
7035
  function listDataSourceFiles(dataDir) {
@@ -7252,7 +7261,7 @@ function convertPublicApiPropertyValue(publicType, value) {
7252
7261
  table: "notion_user"
7253
7262
  }));
7254
7263
  case "files":
7255
- return filesToText(payload);
7264
+ return Array.isArray(payload) ? payload.flatMap(toSampleFile) : void 0;
7256
7265
  case "relation":
7257
7266
  return payload.map((target) => ({
7258
7267
  id: target.id,
@@ -7283,8 +7292,20 @@ function convertPublicApiPropertyValue(publicType, value) {
7283
7292
  return unreachable(publicType);
7284
7293
  }
7285
7294
  }
7286
- function filesToText(files) {
7287
- return files.map((file) => file.name ?? "").filter((name) => name.length > 0).join(", ");
7295
+ function toSampleFile(value) {
7296
+ if (typeof value !== "object" || value === null) {
7297
+ return [];
7298
+ }
7299
+ const file = parseSampleFileItem(value);
7300
+ if (file?.type === "external") {
7301
+ return [file];
7302
+ }
7303
+ return [
7304
+ {
7305
+ type: "unavailable",
7306
+ ..."name" in value && typeof value.name === "string" ? { name: value.name } : {}
7307
+ }
7308
+ ];
7288
7309
  }
7289
7310
  function formulaToText(formula) {
7290
7311
  switch (formula.type) {
@@ -7509,7 +7530,7 @@ function validateSource(source) {
7509
7530
  );
7510
7531
  continue;
7511
7532
  }
7512
- const matches = declared ? matchesConvertedPropertyType(value, declared.type) : isConvertedDataSourceValue(value);
7533
+ const matches = declared ? matchesConvertedPropertyType(value, declared.type) : isSampleDataSourceValue(value);
7513
7534
  if (!matches) {
7514
7535
  issues.push(
7515
7536
  `row ${JSON.stringify(row.id)}: ${JSON.stringify(key)} does not match ${declared ? `type ${JSON.stringify(declared.type)}` : "any supported value shape"}`
@@ -65,10 +65,30 @@ Value shapes by property type:
65
65
  | `date` | `{ "type": "date", "start_date": "YYYY-MM-DD" }`. Ranges and datetimes use `"daterange"`, `"datetime"`, or `"datetimerange"` with `end_date`, `start_time`, and `end_time`. |
66
66
  | `people` | array of `{ "id": "...", "table": "notion_user" }` pointers |
67
67
  | `relation` | array of `{ "id": "...", "table": "block" }` pointers |
68
- | `files` | string (the host serializes file properties as text today) |
68
+ | `files` | Array of named external links and unavailable placeholders. |
69
69
 
70
70
  People properties use user IDs, not page IDs from a directory data source.
71
71
 
72
+ To test how a block handles an unavailable attachment, add a placeholder to a Files cell. For a
73
+ schema property named `files`, a row can contain this value:
74
+
75
+ ```json
76
+ {
77
+ "files": [
78
+ {
79
+ "type": "external",
80
+ "name": "Analytical Engine reference",
81
+ "external": { "url": "https://en.wikipedia.org/wiki/Analytical_Engine" }
82
+ },
83
+ { "type": "unavailable", "name": "Engine diagrams.png" }
84
+ ]
85
+ }
86
+ ```
87
+
88
+ Reads preserve entry order. The sample data contains links and labels, so loading a row does not
89
+ fetch the linked content. A placeholder's name is optional. The shell skips malformed entries and
90
+ treats missing cells and older text values as empty arrays.
91
+
72
92
  ## Validation
73
93
 
74
94
  Files are validated independently at startup and after edits. Errors name the file and problem, for
@@ -125,6 +145,10 @@ ntn workers customblocks sample <url-or-data-source-id> \
125
145
  Run the dev shell once to create the generated file, then sample your data. `--row-only` preserves
126
146
  the schema and appends rows with new IDs. Add `--overwrite` to replace existing rows.
127
147
 
148
+ Imported Files cells keep external links in order. Notion-hosted files and pending uploads become
149
+ unavailable placeholders, with a name when supplied. The sample JSON does not store temporary file
150
+ URLs.
151
+
128
152
  Sampled property keys must match the generated schema. If they differ, sample into a separate file
129
153
  and select it with [`--bind`](bindings.md#choose-sample-data).
130
154
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@notionhq/custom-blocks-dev-shell",
3
- "version": "0.4.3",
3
+ "version": "0.4.4",
4
4
  "description": "Local development shell for Notion custom block workers.",
5
5
  "license": "MIT",
6
6
  "type": "module",