@elaraai/east-plugin 1.0.114 → 1.0.115

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.
Files changed (2) hide show
  1. package/index.json +634 -68
  2. package/package.json +3 -3
package/index.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "version": 2,
3
3
  "stats": {
4
- "totalEntries": 1394,
5
- "totalFiles": 228,
4
+ "totalEntries": 1410,
5
+ "totalFiles": 230,
6
6
  "packages": {
7
7
  "east": 595,
8
8
  "east-node-std": 55,
9
9
  "east-node-io": 63,
10
10
  "east-py-datascience": 94,
11
- "east-ui": 308,
12
- "e3-ui": 229,
11
+ "east-ui": 310,
12
+ "e3-ui": 243,
13
13
  "e3": 36,
14
14
  "e3-ui-cli": 8,
15
15
  "e3-create": 6
@@ -25152,17 +25152,17 @@
25152
25152
  "mdb"
25153
25153
  ],
25154
25154
  "imports": [
25155
- "import { East, BooleanType, IntegerType, NullType, OptionType, StringType, StructType, variant, example } from \"@elaraai/east\";",
25155
+ "import { East, BooleanType, IntegerType, NullType, OptionType, StringType, StructType, example, none, some } from \"@elaraai/east\";",
25156
25156
  "import { SQL } from \"@elaraai/east-node-io\";",
25157
- "import { Fetch, FileSystem } from \"@elaraai/east-node-std\";"
25157
+ "import { ACTORS_PATH } from \"./access-actors.js\";"
25158
25158
  ],
25159
25159
  "languages": [
25160
25160
  "typescript",
25161
25161
  "python"
25162
25162
  ],
25163
- "ir": "{\"type\":\"AsyncFunction\",\"value\":{\"type\":{\"type\":\"AsyncFunction\",\"value\":{\"inputs\":[],\"output\":{\"type\":\"Null\",\"value\":null}}},\"loc_id\":\"0\",\"captures\":[],\"parameters\":[],\"body\":{\"type\":\"Block\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"statements\":[{\"type\":\"Let\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"variable\":{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"Blob\",\"value\":null},\"loc_id\":\"0\",\"name\":\"bytes\",\"mutable\":true,\"captured\":false}},\"value\":{\"type\":\"Platform\",\"value\":{\"type\":{\"type\":\"Blob\",\"value\":null},\"loc_id\":\"0\",\"name\":\"fetch_get_bytes\",\"type_parameters\":[],\"arguments\":[{\"type\":\"Value\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"value\":{\"type\":\"String\",\"value\":\"https://raw.githubusercontent.com/ozzymcduff/sakila-sample-database-ports/master/ms-access-sakila-db/access-sakila.mdb\"}}}],\"async\":true,\"optional\":false}}}},{\"type\":\"Platform\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"name\":\"fs_write_file_bytes\",\"type_parameters\":[],\"arguments\":[{\"type\":\"Value\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"value\":{\"type\":\"String\",\"value\":\"/tmp/east-test-sakila-examples.mdb\"}}},{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"Blob\",\"value\":null},\"loc_id\":\"0\",\"name\":\"bytes\",\"mutable\":true,\"captured\":false}}],\"async\":false,\"optional\":false}},{\"type\":\"Let\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"variable\":{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"Struct\",\"value\":[{\"name\":\"path\",\"type\":{\"type\":\"String\",\"value\":null}},{\"name\":\"password\",\"type\":{\"type\":\"Variant\",\"value\":[{\"name\":\"none\",\"type\":{\"type\":\"Null\",\"value\":null}},{\"name\":\"some\",\"type\":{\"type\":\"String\",\"value\":null}}]}}]},\"loc_id\":\"0\",\"name\":\"config\",\"mutable\":true,\"captured\":false}},\"value\":{\"type\":\"Struct\",\"value\":{\"type\":{\"type\":\"Struct\",\"value\":{\"$ref\":\"4#variable/Variable/type/Struct\"}},\"loc_id\":\"0\",\"fields\":[{\"name\":\"path\",\"value\":{\"type\":\"Value\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"value\":{\"type\":\"String\",\"value\":\"/tmp/east-test-sakila-examples.mdb\"}}}},{\"name\":\"password\",\"value\":{\"type\":\"Variant\",\"value\":{\"type\":{\"type\":\"Variant\",\"value\":{\"$ref\":\"8#variable/Variable/type/Struct/1/type/Variant\"}},\"loc_id\":\"0\",\"case\":\"none\",\"value\":{\"type\":\"Value\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"value\":{\"type\":\"Null\",\"value\":null}}}}}}]}}}},{\"type\":\"Let\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"variable\":{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"name\":\"handle\",\"mutable\":true,\"captured\":false}},\"value\":{\"type\":\"Platform\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"name\":\"access_open\",\"type_parameters\":[],\"arguments\":[{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"Struct\",\"value\":{\"$ref\":\"9#2/Let/variable/Variable/type/Struct\"}},\"loc_id\":\"0\",\"name\":\"config\",\"mutable\":true,\"captured\":false}}],\"async\":true,\"optional\":false}}}},{\"type\":\"Platform\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"name\":\"access_close\",\"type_parameters\":[],\"arguments\":[{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"name\":\"handle\",\"mutable\":true,\"captured\":false}}],\"async\":true,\"optional\":false}}]}}}}",
25164
- "ts": "// Generated by east-node transpile — East IR printed as the East.function\n// builder surface. Rebuilding this module yields the same IR (normalized).\nimport { East, none, NullType, StringType, StructType, OptionType } from \"@elaraai/east\";\nimport { SQL } from \"@elaraai/east-node-io\";\nimport { Fetch, FileSystem } from \"@elaraai/east-node-std\";\n\nexport const accessOpen = East.asyncFunction([], NullType, ($) => {\n const bytes = $.let(\n Fetch.getBytes(\n \"https://raw.githubusercontent.com/ozzymcduff/sakila-sample-database-ports/master/ms-access-sakila-db/access-sakila.mdb\",\n ),\n );\n $(FileSystem.writeFileBytes(\"/tmp/east-test-sakila-examples.mdb\", bytes));\n const config = $.let(\n { path: \"/tmp/east-test-sakila-examples.mdb\", password: none },\n StructType({ path: StringType, password: OptionType(StringType) }),\n );\n const handle = $.let(SQL.Access.open(config));\n return SQL.Access.close(handle);\n});\n",
25165
- "python": "# Generated by east-py transpile — East IR printed as the East.function\n# builder surface. Rebuilding this module yields the same IR (normalized).\nfrom east import East, none, NullType\nfrom east_py_io import AccessConfigType, access_close, access_open\nfrom east_py_std import fetch_get_bytes, fs_write_file_bytes\n\n@East.asyncFunction([], NullType)\ndef accessOpen(b):\n bytes = b.let(\n fetch_get_bytes(\n 'https://raw.githubusercontent.com/ozzymcduff/sakila-sample-database-ports/master/ms-access-sakila-db/access-sakila.mdb',\n ),\n )\n b.do(fs_write_file_bytes('/tmp/east-test-sakila-examples.mdb', bytes))\n config = b.let(\n {'path': '/tmp/east-test-sakila-examples.mdb', 'password': none},\n AccessConfigType,\n )\n handle = b.let(access_open(config))\n return access_close(handle)\n",
25163
+ "ir": "{\"type\":\"AsyncFunction\",\"value\":{\"type\":{\"type\":\"AsyncFunction\",\"value\":{\"inputs\":[],\"output\":{\"type\":\"Null\",\"value\":null}}},\"loc_id\":\"0\",\"captures\":[],\"parameters\":[],\"body\":{\"type\":\"Block\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"statements\":[{\"type\":\"Let\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"variable\":{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"Struct\",\"value\":[{\"name\":\"path\",\"type\":{\"type\":\"String\",\"value\":null}},{\"name\":\"password\",\"type\":{\"type\":\"Variant\",\"value\":[{\"name\":\"none\",\"type\":{\"type\":\"Null\",\"value\":null}},{\"name\":\"some\",\"type\":{\"type\":\"String\",\"value\":null}}]}}]},\"loc_id\":\"0\",\"name\":\"config\",\"mutable\":true,\"captured\":false}},\"value\":{\"type\":\"Struct\",\"value\":{\"type\":{\"type\":\"Struct\",\"value\":{\"$ref\":\"4#variable/Variable/type/Struct\"}},\"loc_id\":\"0\",\"fields\":[{\"name\":\"path\",\"value\":{\"type\":\"Value\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"value\":{\"type\":\"String\",\"value\":\"test/sql/fixtures/actors.mdb\"}}}},{\"name\":\"password\",\"value\":{\"type\":\"Variant\",\"value\":{\"type\":{\"type\":\"Variant\",\"value\":{\"$ref\":\"8#variable/Variable/type/Struct/1/type/Variant\"}},\"loc_id\":\"0\",\"case\":\"none\",\"value\":{\"type\":\"Value\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"value\":{\"type\":\"Null\",\"value\":null}}}}}}]}}}},{\"type\":\"Let\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"variable\":{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"name\":\"handle\",\"mutable\":true,\"captured\":false}},\"value\":{\"type\":\"Platform\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"name\":\"access_open\",\"type_parameters\":[],\"arguments\":[{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"Struct\",\"value\":{\"$ref\":\"9#0/Let/variable/Variable/type/Struct\"}},\"loc_id\":\"0\",\"name\":\"config\",\"mutable\":true,\"captured\":false}}],\"async\":true,\"optional\":false}}}},{\"type\":\"Platform\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"name\":\"access_close\",\"type_parameters\":[],\"arguments\":[{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"name\":\"handle\",\"mutable\":true,\"captured\":false}}],\"async\":true,\"optional\":false}}]}}}}",
25164
+ "ts": "// Generated by east-node transpile — East IR printed as the East.function\n// builder surface. Rebuilding this module yields the same IR (normalized).\nimport { East, none, NullType, StringType, StructType, OptionType } from \"@elaraai/east\";\nimport { SQL } from \"@elaraai/east-node-io\";\n\nexport const accessOpen = East.asyncFunction([], NullType, ($) => {\n const config = $.let(\n { path: \"test/sql/fixtures/actors.mdb\", password: none },\n StructType({ path: StringType, password: OptionType(StringType) }),\n );\n const handle = $.let(SQL.Access.open(config));\n return SQL.Access.close(handle);\n});\n",
25165
+ "python": "# Generated by east-py transpile — East IR printed as the East.function\n# builder surface. Rebuilding this module yields the same IR (normalized).\nfrom east import East, none, NullType\nfrom east_py_io import AccessConfigType, access_close, access_open\n\n@East.asyncFunction([], NullType)\ndef accessOpen(b):\n config = b.let({'path': 'test/sql/fixtures/actors.mdb', 'password': none}, AccessConfigType)\n handle = b.let(access_open(config))\n return access_close(handle)\n",
25166
25166
  "signature": {
25167
25167
  "inputs": [],
25168
25168
  "output": "NullType",
@@ -25172,9 +25172,7 @@
25172
25172
  "returns": null,
25173
25173
  "builtins": [
25174
25174
  "access_close",
25175
- "access_open",
25176
- "fetch_get_bytes",
25177
- "fs_write_file_bytes"
25175
+ "access_open"
25178
25176
  ]
25179
25177
  },
25180
25178
  {
@@ -25191,17 +25189,17 @@
25191
25189
  "disconnect"
25192
25190
  ],
25193
25191
  "imports": [
25194
- "import { East, BooleanType, IntegerType, NullType, OptionType, StringType, StructType, variant, example } from \"@elaraai/east\";",
25192
+ "import { East, BooleanType, IntegerType, NullType, OptionType, StringType, StructType, example, none, some } from \"@elaraai/east\";",
25195
25193
  "import { SQL } from \"@elaraai/east-node-io\";",
25196
- "import { Fetch, FileSystem } from \"@elaraai/east-node-std\";"
25194
+ "import { ACTORS_PATH } from \"./access-actors.js\";"
25197
25195
  ],
25198
25196
  "languages": [
25199
25197
  "typescript",
25200
25198
  "python"
25201
25199
  ],
25202
- "ir": "{\"type\":\"AsyncFunction\",\"value\":{\"type\":{\"type\":\"AsyncFunction\",\"value\":{\"inputs\":[],\"output\":{\"type\":\"Null\",\"value\":null}}},\"loc_id\":\"0\",\"captures\":[],\"parameters\":[],\"body\":{\"type\":\"Block\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"statements\":[{\"type\":\"Let\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"variable\":{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"Blob\",\"value\":null},\"loc_id\":\"0\",\"name\":\"bytes\",\"mutable\":true,\"captured\":false}},\"value\":{\"type\":\"Platform\",\"value\":{\"type\":{\"type\":\"Blob\",\"value\":null},\"loc_id\":\"0\",\"name\":\"fetch_get_bytes\",\"type_parameters\":[],\"arguments\":[{\"type\":\"Value\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"value\":{\"type\":\"String\",\"value\":\"https://raw.githubusercontent.com/ozzymcduff/sakila-sample-database-ports/master/ms-access-sakila-db/access-sakila.mdb\"}}}],\"async\":true,\"optional\":false}}}},{\"type\":\"Platform\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"name\":\"fs_write_file_bytes\",\"type_parameters\":[],\"arguments\":[{\"type\":\"Value\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"value\":{\"type\":\"String\",\"value\":\"/tmp/east-test-sakila-examples.mdb\"}}},{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"Blob\",\"value\":null},\"loc_id\":\"0\",\"name\":\"bytes\",\"mutable\":true,\"captured\":false}}],\"async\":false,\"optional\":false}},{\"type\":\"Let\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"variable\":{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"Struct\",\"value\":[{\"name\":\"path\",\"type\":{\"type\":\"String\",\"value\":null}},{\"name\":\"password\",\"type\":{\"type\":\"Variant\",\"value\":[{\"name\":\"none\",\"type\":{\"type\":\"Null\",\"value\":null}},{\"name\":\"some\",\"type\":{\"type\":\"String\",\"value\":null}}]}}]},\"loc_id\":\"0\",\"name\":\"config\",\"mutable\":true,\"captured\":false}},\"value\":{\"type\":\"Struct\",\"value\":{\"type\":{\"type\":\"Struct\",\"value\":{\"$ref\":\"4#variable/Variable/type/Struct\"}},\"loc_id\":\"0\",\"fields\":[{\"name\":\"path\",\"value\":{\"type\":\"Value\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"value\":{\"type\":\"String\",\"value\":\"/tmp/east-test-sakila-examples.mdb\"}}}},{\"name\":\"password\",\"value\":{\"type\":\"Variant\",\"value\":{\"type\":{\"type\":\"Variant\",\"value\":{\"$ref\":\"8#variable/Variable/type/Struct/1/type/Variant\"}},\"loc_id\":\"0\",\"case\":\"none\",\"value\":{\"type\":\"Value\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"value\":{\"type\":\"Null\",\"value\":null}}}}}}]}}}},{\"type\":\"Let\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"variable\":{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"name\":\"handle\",\"mutable\":true,\"captured\":false}},\"value\":{\"type\":\"Platform\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"name\":\"access_open\",\"type_parameters\":[],\"arguments\":[{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"Struct\",\"value\":{\"$ref\":\"9#2/Let/variable/Variable/type/Struct\"}},\"loc_id\":\"0\",\"name\":\"config\",\"mutable\":true,\"captured\":false}}],\"async\":true,\"optional\":false}}}},{\"type\":\"Platform\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"name\":\"access_close\",\"type_parameters\":[],\"arguments\":[{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"name\":\"handle\",\"mutable\":true,\"captured\":false}}],\"async\":true,\"optional\":false}}]}}}}",
25203
- "ts": "// Generated by east-node transpile — East IR printed as the East.function\n// builder surface. Rebuilding this module yields the same IR (normalized).\nimport { East, none, NullType, StringType, StructType, OptionType } from \"@elaraai/east\";\nimport { SQL } from \"@elaraai/east-node-io\";\nimport { Fetch, FileSystem } from \"@elaraai/east-node-std\";\n\nexport const accessClose = East.asyncFunction([], NullType, ($) => {\n const bytes = $.let(\n Fetch.getBytes(\n \"https://raw.githubusercontent.com/ozzymcduff/sakila-sample-database-ports/master/ms-access-sakila-db/access-sakila.mdb\",\n ),\n );\n $(FileSystem.writeFileBytes(\"/tmp/east-test-sakila-examples.mdb\", bytes));\n const config = $.let(\n { path: \"/tmp/east-test-sakila-examples.mdb\", password: none },\n StructType({ path: StringType, password: OptionType(StringType) }),\n );\n const handle = $.let(SQL.Access.open(config));\n return SQL.Access.close(handle);\n});\n",
25204
- "python": "# Generated by east-py transpile — East IR printed as the East.function\n# builder surface. Rebuilding this module yields the same IR (normalized).\nfrom east import East, none, NullType\nfrom east_py_io import AccessConfigType, access_close, access_open\nfrom east_py_std import fetch_get_bytes, fs_write_file_bytes\n\n@East.asyncFunction([], NullType)\ndef accessClose(b):\n bytes = b.let(\n fetch_get_bytes(\n 'https://raw.githubusercontent.com/ozzymcduff/sakila-sample-database-ports/master/ms-access-sakila-db/access-sakila.mdb',\n ),\n )\n b.do(fs_write_file_bytes('/tmp/east-test-sakila-examples.mdb', bytes))\n config = b.let(\n {'path': '/tmp/east-test-sakila-examples.mdb', 'password': none},\n AccessConfigType,\n )\n handle = b.let(access_open(config))\n return access_close(handle)\n",
25200
+ "ir": "{\"type\":\"AsyncFunction\",\"value\":{\"type\":{\"type\":\"AsyncFunction\",\"value\":{\"inputs\":[],\"output\":{\"type\":\"Null\",\"value\":null}}},\"loc_id\":\"0\",\"captures\":[],\"parameters\":[],\"body\":{\"type\":\"Block\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"statements\":[{\"type\":\"Let\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"variable\":{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"Struct\",\"value\":[{\"name\":\"path\",\"type\":{\"type\":\"String\",\"value\":null}},{\"name\":\"password\",\"type\":{\"type\":\"Variant\",\"value\":[{\"name\":\"none\",\"type\":{\"type\":\"Null\",\"value\":null}},{\"name\":\"some\",\"type\":{\"type\":\"String\",\"value\":null}}]}}]},\"loc_id\":\"0\",\"name\":\"config\",\"mutable\":true,\"captured\":false}},\"value\":{\"type\":\"Struct\",\"value\":{\"type\":{\"type\":\"Struct\",\"value\":{\"$ref\":\"4#variable/Variable/type/Struct\"}},\"loc_id\":\"0\",\"fields\":[{\"name\":\"path\",\"value\":{\"type\":\"Value\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"value\":{\"type\":\"String\",\"value\":\"test/sql/fixtures/actors.mdb\"}}}},{\"name\":\"password\",\"value\":{\"type\":\"Variant\",\"value\":{\"type\":{\"type\":\"Variant\",\"value\":{\"$ref\":\"8#variable/Variable/type/Struct/1/type/Variant\"}},\"loc_id\":\"0\",\"case\":\"none\",\"value\":{\"type\":\"Value\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"value\":{\"type\":\"Null\",\"value\":null}}}}}}]}}}},{\"type\":\"Let\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"variable\":{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"name\":\"handle\",\"mutable\":true,\"captured\":false}},\"value\":{\"type\":\"Platform\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"name\":\"access_open\",\"type_parameters\":[],\"arguments\":[{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"Struct\",\"value\":{\"$ref\":\"9#0/Let/variable/Variable/type/Struct\"}},\"loc_id\":\"0\",\"name\":\"config\",\"mutable\":true,\"captured\":false}}],\"async\":true,\"optional\":false}}}},{\"type\":\"Platform\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"name\":\"access_close\",\"type_parameters\":[],\"arguments\":[{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"name\":\"handle\",\"mutable\":true,\"captured\":false}}],\"async\":true,\"optional\":false}}]}}}}",
25201
+ "ts": "// Generated by east-node transpile — East IR printed as the East.function\n// builder surface. Rebuilding this module yields the same IR (normalized).\nimport { East, none, NullType, StringType, StructType, OptionType } from \"@elaraai/east\";\nimport { SQL } from \"@elaraai/east-node-io\";\n\nexport const accessClose = East.asyncFunction([], NullType, ($) => {\n const config = $.let(\n { path: \"test/sql/fixtures/actors.mdb\", password: none },\n StructType({ path: StringType, password: OptionType(StringType) }),\n );\n const handle = $.let(SQL.Access.open(config));\n return SQL.Access.close(handle);\n});\n",
25202
+ "python": "# Generated by east-py transpile — East IR printed as the East.function\n# builder surface. Rebuilding this module yields the same IR (normalized).\nfrom east import East, none, NullType\nfrom east_py_io import AccessConfigType, access_close, access_open\n\n@East.asyncFunction([], NullType)\ndef accessClose(b):\n config = b.let({'path': 'test/sql/fixtures/actors.mdb', 'password': none}, AccessConfigType)\n handle = b.let(access_open(config))\n return access_close(handle)\n",
25205
25203
  "signature": {
25206
25204
  "inputs": [],
25207
25205
  "output": "NullType",
@@ -25211,9 +25209,7 @@
25211
25209
  "returns": null,
25212
25210
  "builtins": [
25213
25211
  "access_close",
25214
- "access_open",
25215
- "fetch_get_bytes",
25216
- "fs_write_file_bytes"
25212
+ "access_open"
25217
25213
  ]
25218
25214
  },
25219
25215
  {
@@ -25231,17 +25227,17 @@
25231
25227
  "schema"
25232
25228
  ],
25233
25229
  "imports": [
25234
- "import { East, BooleanType, IntegerType, NullType, OptionType, StringType, StructType, variant, example } from \"@elaraai/east\";",
25230
+ "import { East, BooleanType, IntegerType, NullType, OptionType, StringType, StructType, example, none, some } from \"@elaraai/east\";",
25235
25231
  "import { SQL } from \"@elaraai/east-node-io\";",
25236
- "import { Fetch, FileSystem } from \"@elaraai/east-node-std\";"
25232
+ "import { ACTORS_PATH } from \"./access-actors.js\";"
25237
25233
  ],
25238
25234
  "languages": [
25239
25235
  "typescript",
25240
25236
  "python"
25241
25237
  ],
25242
- "ir": "{\"type\":\"AsyncFunction\",\"value\":{\"type\":{\"type\":\"AsyncFunction\",\"value\":{\"inputs\":[],\"output\":{\"type\":\"Boolean\",\"value\":null}}},\"loc_id\":\"0\",\"captures\":[],\"parameters\":[],\"body\":{\"type\":\"Block\",\"value\":{\"type\":{\"type\":\"Boolean\",\"value\":null},\"loc_id\":\"0\",\"statements\":[{\"type\":\"Let\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"variable\":{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"Blob\",\"value\":null},\"loc_id\":\"0\",\"name\":\"bytes\",\"mutable\":true,\"captured\":false}},\"value\":{\"type\":\"Platform\",\"value\":{\"type\":{\"type\":\"Blob\",\"value\":null},\"loc_id\":\"0\",\"name\":\"fetch_get_bytes\",\"type_parameters\":[],\"arguments\":[{\"type\":\"Value\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"value\":{\"type\":\"String\",\"value\":\"https://raw.githubusercontent.com/ozzymcduff/sakila-sample-database-ports/master/ms-access-sakila-db/access-sakila.mdb\"}}}],\"async\":true,\"optional\":false}}}},{\"type\":\"Platform\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"name\":\"fs_write_file_bytes\",\"type_parameters\":[],\"arguments\":[{\"type\":\"Value\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"value\":{\"type\":\"String\",\"value\":\"/tmp/east-test-sakila-examples.mdb\"}}},{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"Blob\",\"value\":null},\"loc_id\":\"0\",\"name\":\"bytes\",\"mutable\":true,\"captured\":false}}],\"async\":false,\"optional\":false}},{\"type\":\"Let\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"variable\":{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"Struct\",\"value\":[{\"name\":\"path\",\"type\":{\"type\":\"String\",\"value\":null}},{\"name\":\"password\",\"type\":{\"type\":\"Variant\",\"value\":[{\"name\":\"none\",\"type\":{\"type\":\"Null\",\"value\":null}},{\"name\":\"some\",\"type\":{\"type\":\"String\",\"value\":null}}]}}]},\"loc_id\":\"0\",\"name\":\"config\",\"mutable\":true,\"captured\":false}},\"value\":{\"type\":\"Struct\",\"value\":{\"type\":{\"type\":\"Struct\",\"value\":{\"$ref\":\"4#variable/Variable/type/Struct\"}},\"loc_id\":\"0\",\"fields\":[{\"name\":\"path\",\"value\":{\"type\":\"Value\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"value\":{\"type\":\"String\",\"value\":\"/tmp/east-test-sakila-examples.mdb\"}}}},{\"name\":\"password\",\"value\":{\"type\":\"Variant\",\"value\":{\"type\":{\"type\":\"Variant\",\"value\":{\"$ref\":\"8#variable/Variable/type/Struct/1/type/Variant\"}},\"loc_id\":\"0\",\"case\":\"none\",\"value\":{\"type\":\"Value\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"value\":{\"type\":\"Null\",\"value\":null}}}}}}]}}}},{\"type\":\"Let\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"variable\":{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"name\":\"handle\",\"mutable\":true,\"captured\":false}},\"value\":{\"type\":\"Platform\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"name\":\"access_open\",\"type_parameters\":[],\"arguments\":[{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"Struct\",\"value\":{\"$ref\":\"9#2/Let/variable/Variable/type/Struct\"}},\"loc_id\":\"0\",\"name\":\"config\",\"mutable\":true,\"captured\":false}}],\"async\":true,\"optional\":false}}}},{\"type\":\"Let\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"variable\":{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"Struct\",\"value\":[{\"name\":\"tables\",\"type\":{\"type\":\"Array\",\"value\":{\"type\":\"String\",\"value\":null}}}]},\"loc_id\":\"0\",\"name\":\"result\",\"mutable\":true,\"captured\":false}},\"value\":{\"type\":\"Platform\",\"value\":{\"type\":{\"type\":\"Struct\",\"value\":{\"$ref\":\"4#variable/Variable/type/Struct\"}},\"loc_id\":\"0\",\"name\":\"access_tables\",\"type_parameters\":[],\"arguments\":[{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"name\":\"handle\",\"mutable\":true,\"captured\":false}}],\"async\":true,\"optional\":false}}}},{\"type\":\"Platform\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"name\":\"access_close\",\"type_parameters\":[],\"arguments\":[{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"name\":\"handle\",\"mutable\":true,\"captured\":false}}],\"async\":true,\"optional\":false}},{\"type\":\"Builtin\",\"value\":{\"type\":{\"type\":\"Boolean\",\"value\":null},\"loc_id\":\"0\",\"builtin\":\"Greater\",\"type_parameters\":[{\"type\":\"Integer\",\"value\":null}],\"arguments\":[{\"type\":\"Builtin\",\"value\":{\"type\":{\"type\":\"Integer\",\"value\":null},\"loc_id\":\"0\",\"builtin\":\"ArraySize\",\"type_parameters\":[{\"type\":\"String\",\"value\":null}],\"arguments\":[{\"type\":\"GetField\",\"value\":{\"type\":{\"type\":\"Array\",\"value\":{\"type\":\"String\",\"value\":null}},\"loc_id\":\"0\",\"field\":\"tables\",\"struct\":{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"Struct\",\"value\":{\"$ref\":\"12#4/Let/variable/Variable/type/Struct\"}},\"loc_id\":\"0\",\"name\":\"result\",\"mutable\":true,\"captured\":false}}}}]}},{\"type\":\"Value\",\"value\":{\"type\":{\"type\":\"Integer\",\"value\":null},\"loc_id\":\"0\",\"value\":{\"type\":\"Integer\",\"value\":\"0\"}}}]}}]}}}}",
25243
- "ts": "// Generated by east-node transpile — East IR printed as the East.function\n// builder surface. Rebuilding this module yields the same IR (normalized).\nimport { East, none, BooleanType, StringType, StructType, OptionType } from \"@elaraai/east\";\nimport { SQL } from \"@elaraai/east-node-io\";\nimport { Fetch, FileSystem } from \"@elaraai/east-node-std\";\n\nexport const accessTables = East.asyncFunction([], BooleanType, ($) => {\n const bytes = $.let(\n Fetch.getBytes(\n \"https://raw.githubusercontent.com/ozzymcduff/sakila-sample-database-ports/master/ms-access-sakila-db/access-sakila.mdb\",\n ),\n );\n $(FileSystem.writeFileBytes(\"/tmp/east-test-sakila-examples.mdb\", bytes));\n const config = $.let(\n { path: \"/tmp/east-test-sakila-examples.mdb\", password: none },\n StructType({ path: StringType, password: OptionType(StringType) }),\n );\n const handle = $.let(SQL.Access.open(config));\n const result = $.let(SQL.Access.tables(handle));\n $(SQL.Access.close(handle));\n return East.greater(result.tables.size(), 0n);\n});\n",
25244
- "python": "# Generated by east-py transpile — East IR printed as the East.function\n# builder surface. Rebuilding this module yields the same IR (normalized).\nfrom east import East, none, BooleanType, IntegerType, StringType\nfrom east_py_io import AccessConfigType, access_close, access_open, access_tables\nfrom east_py_std import fetch_get_bytes, fs_write_file_bytes\n\n@East.asyncFunction([], BooleanType)\ndef accessTables(b):\n bytes = b.let(\n fetch_get_bytes(\n 'https://raw.githubusercontent.com/ozzymcduff/sakila-sample-database-ports/master/ms-access-sakila-db/access-sakila.mdb',\n ),\n )\n b.do(fs_write_file_bytes('/tmp/east-test-sakila-examples.mdb', bytes))\n config = b.let(\n {'path': '/tmp/east-test-sakila-examples.mdb', 'password': none},\n AccessConfigType,\n )\n handle = b.let(access_open(config))\n result = b.let(access_tables(handle))\n b.do(access_close(handle))\n return (result.tables.size() > 0)\n",
25238
+ "ir": "{\"type\":\"AsyncFunction\",\"value\":{\"type\":{\"type\":\"AsyncFunction\",\"value\":{\"inputs\":[],\"output\":{\"type\":\"Boolean\",\"value\":null}}},\"loc_id\":\"0\",\"captures\":[],\"parameters\":[],\"body\":{\"type\":\"Block\",\"value\":{\"type\":{\"type\":\"Boolean\",\"value\":null},\"loc_id\":\"0\",\"statements\":[{\"type\":\"Let\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"variable\":{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"Struct\",\"value\":[{\"name\":\"path\",\"type\":{\"type\":\"String\",\"value\":null}},{\"name\":\"password\",\"type\":{\"type\":\"Variant\",\"value\":[{\"name\":\"none\",\"type\":{\"type\":\"Null\",\"value\":null}},{\"name\":\"some\",\"type\":{\"type\":\"String\",\"value\":null}}]}}]},\"loc_id\":\"0\",\"name\":\"config\",\"mutable\":true,\"captured\":false}},\"value\":{\"type\":\"Struct\",\"value\":{\"type\":{\"type\":\"Struct\",\"value\":{\"$ref\":\"4#variable/Variable/type/Struct\"}},\"loc_id\":\"0\",\"fields\":[{\"name\":\"path\",\"value\":{\"type\":\"Value\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"value\":{\"type\":\"String\",\"value\":\"test/sql/fixtures/actors.mdb\"}}}},{\"name\":\"password\",\"value\":{\"type\":\"Variant\",\"value\":{\"type\":{\"type\":\"Variant\",\"value\":{\"$ref\":\"8#variable/Variable/type/Struct/1/type/Variant\"}},\"loc_id\":\"0\",\"case\":\"none\",\"value\":{\"type\":\"Value\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"value\":{\"type\":\"Null\",\"value\":null}}}}}}]}}}},{\"type\":\"Let\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"variable\":{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"name\":\"handle\",\"mutable\":true,\"captured\":false}},\"value\":{\"type\":\"Platform\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"name\":\"access_open\",\"type_parameters\":[],\"arguments\":[{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"Struct\",\"value\":{\"$ref\":\"9#0/Let/variable/Variable/type/Struct\"}},\"loc_id\":\"0\",\"name\":\"config\",\"mutable\":true,\"captured\":false}}],\"async\":true,\"optional\":false}}}},{\"type\":\"Let\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"variable\":{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"Struct\",\"value\":[{\"name\":\"tables\",\"type\":{\"type\":\"Array\",\"value\":{\"type\":\"String\",\"value\":null}}}]},\"loc_id\":\"0\",\"name\":\"result\",\"mutable\":true,\"captured\":false}},\"value\":{\"type\":\"Platform\",\"value\":{\"type\":{\"type\":\"Struct\",\"value\":{\"$ref\":\"4#variable/Variable/type/Struct\"}},\"loc_id\":\"0\",\"name\":\"access_tables\",\"type_parameters\":[],\"arguments\":[{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"name\":\"handle\",\"mutable\":true,\"captured\":false}}],\"async\":true,\"optional\":false}}}},{\"type\":\"Platform\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"name\":\"access_close\",\"type_parameters\":[],\"arguments\":[{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"name\":\"handle\",\"mutable\":true,\"captured\":false}}],\"async\":true,\"optional\":false}},{\"type\":\"Builtin\",\"value\":{\"type\":{\"type\":\"Boolean\",\"value\":null},\"loc_id\":\"0\",\"builtin\":\"Greater\",\"type_parameters\":[{\"type\":\"Integer\",\"value\":null}],\"arguments\":[{\"type\":\"Builtin\",\"value\":{\"type\":{\"type\":\"Integer\",\"value\":null},\"loc_id\":\"0\",\"builtin\":\"ArraySize\",\"type_parameters\":[{\"type\":\"String\",\"value\":null}],\"arguments\":[{\"type\":\"GetField\",\"value\":{\"type\":{\"type\":\"Array\",\"value\":{\"type\":\"String\",\"value\":null}},\"loc_id\":\"0\",\"field\":\"tables\",\"struct\":{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"Struct\",\"value\":{\"$ref\":\"12#2/Let/variable/Variable/type/Struct\"}},\"loc_id\":\"0\",\"name\":\"result\",\"mutable\":true,\"captured\":false}}}}]}},{\"type\":\"Value\",\"value\":{\"type\":{\"type\":\"Integer\",\"value\":null},\"loc_id\":\"0\",\"value\":{\"type\":\"Integer\",\"value\":\"0\"}}}]}}]}}}}",
25239
+ "ts": "// Generated by east-node transpile — East IR printed as the East.function\n// builder surface. Rebuilding this module yields the same IR (normalized).\nimport { East, none, BooleanType, StringType, StructType, OptionType } from \"@elaraai/east\";\nimport { SQL } from \"@elaraai/east-node-io\";\n\nexport const accessTables = East.asyncFunction([], BooleanType, ($) => {\n const config = $.let(\n { path: \"test/sql/fixtures/actors.mdb\", password: none },\n StructType({ path: StringType, password: OptionType(StringType) }),\n );\n const handle = $.let(SQL.Access.open(config));\n const result = $.let(SQL.Access.tables(handle));\n $(SQL.Access.close(handle));\n return East.greater(result.tables.size(), 0n);\n});\n",
25240
+ "python": "# Generated by east-py transpile — East IR printed as the East.function\n# builder surface. Rebuilding this module yields the same IR (normalized).\nfrom east import East, none, BooleanType, IntegerType, StringType\nfrom east_py_io import AccessConfigType, access_close, access_open, access_tables\n\n@East.asyncFunction([], BooleanType)\ndef accessTables(b):\n config = b.let({'path': 'test/sql/fixtures/actors.mdb', 'password': none}, AccessConfigType)\n handle = b.let(access_open(config))\n result = b.let(access_tables(handle))\n b.do(access_close(handle))\n return (result.tables.size() > 0)\n",
25245
25241
  "signature": {
25246
25242
  "inputs": [],
25247
25243
  "output": "BooleanType",
@@ -25254,9 +25250,7 @@
25254
25250
  "Greater",
25255
25251
  "access_close",
25256
25252
  "access_open",
25257
- "access_tables",
25258
- "fetch_get_bytes",
25259
- "fs_write_file_bytes"
25253
+ "access_tables"
25260
25254
  ]
25261
25255
  },
25262
25256
  {
@@ -25275,17 +25269,17 @@
25275
25269
  "row"
25276
25270
  ],
25277
25271
  "imports": [
25278
- "import { East, BooleanType, IntegerType, NullType, OptionType, StringType, StructType, variant, example } from \"@elaraai/east\";",
25272
+ "import { East, BooleanType, IntegerType, NullType, OptionType, StringType, StructType, example, none, some } from \"@elaraai/east\";",
25279
25273
  "import { SQL } from \"@elaraai/east-node-io\";",
25280
- "import { Fetch, FileSystem } from \"@elaraai/east-node-std\";"
25274
+ "import { ACTORS_PATH } from \"./access-actors.js\";"
25281
25275
  ],
25282
25276
  "languages": [
25283
25277
  "typescript",
25284
25278
  "python"
25285
25279
  ],
25286
- "ir": "{\"type\":\"AsyncFunction\",\"value\":{\"type\":{\"type\":\"AsyncFunction\",\"value\":{\"inputs\":[],\"output\":{\"type\":\"Boolean\",\"value\":null}}},\"loc_id\":\"0\",\"captures\":[],\"parameters\":[],\"body\":{\"type\":\"Block\",\"value\":{\"type\":{\"type\":\"Boolean\",\"value\":null},\"loc_id\":\"0\",\"statements\":[{\"type\":\"Let\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"variable\":{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"Blob\",\"value\":null},\"loc_id\":\"0\",\"name\":\"bytes\",\"mutable\":true,\"captured\":false}},\"value\":{\"type\":\"Platform\",\"value\":{\"type\":{\"type\":\"Blob\",\"value\":null},\"loc_id\":\"0\",\"name\":\"fetch_get_bytes\",\"type_parameters\":[],\"arguments\":[{\"type\":\"Value\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"value\":{\"type\":\"String\",\"value\":\"https://raw.githubusercontent.com/ozzymcduff/sakila-sample-database-ports/master/ms-access-sakila-db/access-sakila.mdb\"}}}],\"async\":true,\"optional\":false}}}},{\"type\":\"Platform\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"name\":\"fs_write_file_bytes\",\"type_parameters\":[],\"arguments\":[{\"type\":\"Value\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"value\":{\"type\":\"String\",\"value\":\"/tmp/east-test-sakila-examples.mdb\"}}},{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"Blob\",\"value\":null},\"loc_id\":\"0\",\"name\":\"bytes\",\"mutable\":true,\"captured\":false}}],\"async\":false,\"optional\":false}},{\"type\":\"Let\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"variable\":{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"Struct\",\"value\":[{\"name\":\"path\",\"type\":{\"type\":\"String\",\"value\":null}},{\"name\":\"password\",\"type\":{\"type\":\"Variant\",\"value\":[{\"name\":\"none\",\"type\":{\"type\":\"Null\",\"value\":null}},{\"name\":\"some\",\"type\":{\"type\":\"String\",\"value\":null}}]}}]},\"loc_id\":\"0\",\"name\":\"config\",\"mutable\":true,\"captured\":false}},\"value\":{\"type\":\"Struct\",\"value\":{\"type\":{\"type\":\"Struct\",\"value\":{\"$ref\":\"4#variable/Variable/type/Struct\"}},\"loc_id\":\"0\",\"fields\":[{\"name\":\"path\",\"value\":{\"type\":\"Value\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"value\":{\"type\":\"String\",\"value\":\"/tmp/east-test-sakila-examples.mdb\"}}}},{\"name\":\"password\",\"value\":{\"type\":\"Variant\",\"value\":{\"type\":{\"type\":\"Variant\",\"value\":{\"$ref\":\"8#variable/Variable/type/Struct/1/type/Variant\"}},\"loc_id\":\"0\",\"case\":\"none\",\"value\":{\"type\":\"Value\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"value\":{\"type\":\"Null\",\"value\":null}}}}}}]}}}},{\"type\":\"Let\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"variable\":{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"name\":\"handle\",\"mutable\":true,\"captured\":false}},\"value\":{\"type\":\"Platform\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"name\":\"access_open\",\"type_parameters\":[],\"arguments\":[{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"Struct\",\"value\":{\"$ref\":\"9#2/Let/variable/Variable/type/Struct\"}},\"loc_id\":\"0\",\"name\":\"config\",\"mutable\":true,\"captured\":false}}],\"async\":true,\"optional\":false}}}},{\"type\":\"Let\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"variable\":{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"Struct\",\"value\":[{\"name\":\"table\",\"type\":{\"type\":\"String\",\"value\":null}},{\"name\":\"columns\",\"type\":{\"type\":\"Variant\",\"value\":[{\"name\":\"none\",\"type\":{\"type\":\"Null\",\"value\":null}}]}},{\"name\":\"rowOffset\",\"type\":{\"type\":\"Variant\",\"value\":{\"$ref\":\"3#1/type/Variant\"}}},{\"name\":\"rowLimit\",\"type\":{\"type\":\"Variant\",\"value\":[{\"name\":\"some\",\"type\":{\"type\":\"Integer\",\"value\":null}}]}}]},\"loc_id\":\"0\",\"name\":\"options\",\"mutable\":true,\"captured\":false}},\"value\":{\"type\":\"Struct\",\"value\":{\"type\":{\"type\":\"Struct\",\"value\":{\"$ref\":\"4#variable/Variable/type/Struct\"}},\"loc_id\":\"0\",\"fields\":[{\"name\":\"table\",\"value\":{\"type\":\"Value\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"value\":{\"type\":\"String\",\"value\":\"actor\"}}}},{\"name\":\"columns\",\"value\":{\"type\":\"Variant\",\"value\":{\"type\":{\"type\":\"Variant\",\"value\":{\"$ref\":\"8#variable/Variable/type/Struct/1/type/Variant\"}},\"loc_id\":\"0\",\"case\":\"none\",\"value\":{\"type\":\"Value\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"value\":{\"type\":\"Null\",\"value\":null}}}}}},{\"name\":\"rowOffset\",\"value\":{\"type\":\"Variant\",\"value\":{\"type\":{\"type\":\"Variant\",\"value\":{\"$ref\":\"8#variable/Variable/type/Struct/1/type/Variant\"}},\"loc_id\":\"0\",\"case\":\"none\",\"value\":{\"type\":\"Value\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"value\":{\"type\":\"Null\",\"value\":null}}}}}},{\"name\":\"rowLimit\",\"value\":{\"type\":\"Variant\",\"value\":{\"type\":{\"type\":\"Variant\",\"value\":{\"$ref\":\"8#variable/Variable/type/Struct/3/type/Variant\"}},\"loc_id\":\"0\",\"case\":\"some\",\"value\":{\"type\":\"Value\",\"value\":{\"type\":{\"type\":\"Integer\",\"value\":null},\"loc_id\":\"0\",\"value\":{\"type\":\"Integer\",\"value\":\"5\"}}}}}}]}}}},{\"type\":\"Let\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"variable\":{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"Array\",\"value\":{\"type\":\"Struct\",\"value\":[{\"name\":\"actor_id\",\"type\":{\"type\":\"Variant\",\"value\":[{\"name\":\"none\",\"type\":{\"type\":\"Null\",\"value\":null}},{\"name\":\"some\",\"type\":{\"type\":\"Integer\",\"value\":null}}]}},{\"name\":\"first_name\",\"type\":{\"type\":\"Variant\",\"value\":{\"$ref\":\"10#2/Let/variable/Variable/type/Struct/1/type/Variant\"}}},{\"name\":\"last_name\",\"type\":{\"type\":\"Variant\",\"value\":{\"$ref\":\"10#2/Let/variable/Variable/type/Struct/1/type/Variant\"}}}]}},\"loc_id\":\"0\",\"name\":\"rows\",\"mutable\":true,\"captured\":false}},\"value\":{\"type\":\"Platform\",\"value\":{\"type\":{\"type\":\"Array\",\"value\":{\"type\":\"Struct\",\"value\":{\"$ref\":\"5#variable/Variable/type/Array/Struct\"}}},\"loc_id\":\"0\",\"name\":\"access_query\",\"type_parameters\":[{\"type\":\"Struct\",\"value\":{\"$ref\":\"5#variable/Variable/type/Array/Struct\"}}],\"arguments\":[{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"name\":\"handle\",\"mutable\":true,\"captured\":false}},{\"type\":\"As\",\"value\":{\"type\":{\"type\":\"Struct\",\"value\":[{\"name\":\"table\",\"type\":{\"type\":\"String\",\"value\":null}},{\"name\":\"columns\",\"type\":{\"type\":\"Variant\",\"value\":[{\"name\":\"none\",\"type\":{\"type\":\"Null\",\"value\":null}},{\"name\":\"some\",\"type\":{\"type\":\"Array\",\"value\":{\"type\":\"String\",\"value\":null}}}]}},{\"name\":\"rowOffset\",\"type\":{\"type\":\"Variant\",\"value\":[{\"name\":\"none\",\"type\":{\"type\":\"Null\",\"value\":null}},{\"name\":\"some\",\"type\":{\"type\":\"Integer\",\"value\":null}}]}},{\"name\":\"rowLimit\",\"type\":{\"type\":\"Variant\",\"value\":[{\"name\":\"none\",\"type\":{\"type\":\"Null\",\"value\":null}},{\"name\":\"some\",\"type\":{\"type\":\"Integer\",\"value\":null}}]}}]},\"loc_id\":\"0\",\"value\":{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"Struct\",\"value\":{\"$ref\":\"11#4/Let/variable/Variable/type/Struct\"}},\"loc_id\":\"0\",\"name\":\"options\",\"mutable\":true,\"captured\":false}}}}],\"async\":true,\"optional\":false}}}},{\"type\":\"Platform\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"name\":\"access_close\",\"type_parameters\":[],\"arguments\":[{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"name\":\"handle\",\"mutable\":true,\"captured\":false}}],\"async\":true,\"optional\":false}},{\"type\":\"Builtin\",\"value\":{\"type\":{\"type\":\"Boolean\",\"value\":null},\"loc_id\":\"0\",\"builtin\":\"Greater\",\"type_parameters\":[{\"type\":\"Integer\",\"value\":null}],\"arguments\":[{\"type\":\"Builtin\",\"value\":{\"type\":{\"type\":\"Integer\",\"value\":null},\"loc_id\":\"0\",\"builtin\":\"ArraySize\",\"type_parameters\":[{\"type\":\"Struct\",\"value\":{\"$ref\":\"8#5/Let/variable/Variable/type/Array/Struct\"}}],\"arguments\":[{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"Array\",\"value\":{\"type\":\"Struct\",\"value\":{\"$ref\":\"11#5/Let/variable/Variable/type/Array/Struct\"}}},\"loc_id\":\"0\",\"name\":\"rows\",\"mutable\":true,\"captured\":false}}]}},{\"type\":\"Value\",\"value\":{\"type\":{\"type\":\"Integer\",\"value\":null},\"loc_id\":\"0\",\"value\":{\"type\":\"Integer\",\"value\":\"0\"}}}]}}]}}}}",
25287
- "ts": "// Generated by east-node transpile — East IR printed as the East.function\n// builder surface. Rebuilding this module yields the same IR (normalized).\nimport { East, variant, none, NullType, BooleanType, IntegerType, StringType, StructType, VariantType, OptionType } from \"@elaraai/east\";\nimport { SQL } from \"@elaraai/east-node-io\";\nimport { Fetch, FileSystem } from \"@elaraai/east-node-std\";\n\nexport const accessQuery = East.asyncFunction([], BooleanType, ($) => {\n const bytes = $.let(\n Fetch.getBytes(\n \"https://raw.githubusercontent.com/ozzymcduff/sakila-sample-database-ports/master/ms-access-sakila-db/access-sakila.mdb\",\n ),\n );\n $(FileSystem.writeFileBytes(\"/tmp/east-test-sakila-examples.mdb\", bytes));\n const config = $.let(\n { path: \"/tmp/east-test-sakila-examples.mdb\", password: none },\n StructType({ path: StringType, password: OptionType(StringType) }),\n );\n const handle = $.let(SQL.Access.open(config));\n const options = $.let(\n {\n table: \"actor\",\n columns: variant(\"none\", null),\n rowOffset: variant(\"none\", null),\n rowLimit: variant(\"some\", 5n),\n },\n StructType({\n table: StringType,\n columns: VariantType({ none: NullType }),\n rowOffset: VariantType({ none: NullType }),\n rowLimit: VariantType({ some: IntegerType }),\n }),\n );\n const rows = $.let(\n SQL.Access.query(\n [\n StructType({\n actor_id: OptionType(IntegerType),\n first_name: OptionType(StringType),\n last_name: OptionType(StringType),\n }),\n ],\n handle,\n options,\n ),\n );\n $(SQL.Access.close(handle));\n return East.greater(rows.size(), 0n);\n});\n",
25288
- "python": "# Generated by east-py transpile — East IR printed as the East.function\n# builder surface. Rebuilding this module yields the same IR (normalized).\nfrom east import East, variant, none, east_null, NullType, BooleanType, IntegerType, StringType, StructType, VariantType, OptionType\nfrom east_py_io import AccessConfigType, access_close, access_open, access_query\nfrom east_py_std import fetch_get_bytes, fs_write_file_bytes\n\n@East.asyncFunction([], BooleanType)\ndef accessQuery(b):\n bytes = b.let(\n fetch_get_bytes(\n 'https://raw.githubusercontent.com/ozzymcduff/sakila-sample-database-ports/master/ms-access-sakila-db/access-sakila.mdb',\n ),\n )\n b.do(fs_write_file_bytes('/tmp/east-test-sakila-examples.mdb', bytes))\n config = b.let(\n {'path': '/tmp/east-test-sakila-examples.mdb', 'password': none},\n AccessConfigType,\n )\n handle = b.let(access_open(config))\n options = b.let(\n {\n 'table': 'actor',\n 'columns': variant('none', east_null),\n 'rowOffset': variant('none', east_null),\n 'rowLimit': variant('some', 5),\n },\n StructType([\n ('table', StringType),\n ('columns', VariantType([('none', NullType)])),\n ('rowOffset', VariantType([('none', NullType)])),\n ('rowLimit', VariantType([('some', IntegerType)])),\n ]),\n )\n rows = b.let(\n access_query(\n StructType([\n ('actor_id', OptionType(IntegerType)),\n ('first_name', OptionType(StringType)),\n ('last_name', OptionType(StringType)),\n ]),\n handle,\n options,\n ),\n )\n b.do(access_close(handle))\n return (rows.size() > 0)\n",
25280
+ "ir": "{\"type\":\"AsyncFunction\",\"value\":{\"type\":{\"type\":\"AsyncFunction\",\"value\":{\"inputs\":[],\"output\":{\"type\":\"Boolean\",\"value\":null}}},\"loc_id\":\"0\",\"captures\":[],\"parameters\":[],\"body\":{\"type\":\"Block\",\"value\":{\"type\":{\"type\":\"Boolean\",\"value\":null},\"loc_id\":\"0\",\"statements\":[{\"type\":\"Let\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"variable\":{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"Struct\",\"value\":[{\"name\":\"path\",\"type\":{\"type\":\"String\",\"value\":null}},{\"name\":\"password\",\"type\":{\"type\":\"Variant\",\"value\":[{\"name\":\"none\",\"type\":{\"type\":\"Null\",\"value\":null}},{\"name\":\"some\",\"type\":{\"type\":\"String\",\"value\":null}}]}}]},\"loc_id\":\"0\",\"name\":\"config\",\"mutable\":true,\"captured\":false}},\"value\":{\"type\":\"Struct\",\"value\":{\"type\":{\"type\":\"Struct\",\"value\":{\"$ref\":\"4#variable/Variable/type/Struct\"}},\"loc_id\":\"0\",\"fields\":[{\"name\":\"path\",\"value\":{\"type\":\"Value\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"value\":{\"type\":\"String\",\"value\":\"test/sql/fixtures/actors.mdb\"}}}},{\"name\":\"password\",\"value\":{\"type\":\"Variant\",\"value\":{\"type\":{\"type\":\"Variant\",\"value\":{\"$ref\":\"8#variable/Variable/type/Struct/1/type/Variant\"}},\"loc_id\":\"0\",\"case\":\"none\",\"value\":{\"type\":\"Value\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"value\":{\"type\":\"Null\",\"value\":null}}}}}}]}}}},{\"type\":\"Let\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"variable\":{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"name\":\"handle\",\"mutable\":true,\"captured\":false}},\"value\":{\"type\":\"Platform\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"name\":\"access_open\",\"type_parameters\":[],\"arguments\":[{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"Struct\",\"value\":{\"$ref\":\"9#0/Let/variable/Variable/type/Struct\"}},\"loc_id\":\"0\",\"name\":\"config\",\"mutable\":true,\"captured\":false}}],\"async\":true,\"optional\":false}}}},{\"type\":\"Let\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"variable\":{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"Struct\",\"value\":[{\"name\":\"table\",\"type\":{\"type\":\"String\",\"value\":null}},{\"name\":\"columns\",\"type\":{\"type\":\"Variant\",\"value\":[{\"name\":\"none\",\"type\":{\"type\":\"Null\",\"value\":null}}]}},{\"name\":\"rowOffset\",\"type\":{\"type\":\"Variant\",\"value\":{\"$ref\":\"3#1/type/Variant\"}}},{\"name\":\"rowLimit\",\"type\":{\"type\":\"Variant\",\"value\":[{\"name\":\"some\",\"type\":{\"type\":\"Integer\",\"value\":null}}]}}]},\"loc_id\":\"0\",\"name\":\"options\",\"mutable\":true,\"captured\":false}},\"value\":{\"type\":\"Struct\",\"value\":{\"type\":{\"type\":\"Struct\",\"value\":{\"$ref\":\"4#variable/Variable/type/Struct\"}},\"loc_id\":\"0\",\"fields\":[{\"name\":\"table\",\"value\":{\"type\":\"Value\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"value\":{\"type\":\"String\",\"value\":\"actor\"}}}},{\"name\":\"columns\",\"value\":{\"type\":\"Variant\",\"value\":{\"type\":{\"type\":\"Variant\",\"value\":{\"$ref\":\"8#variable/Variable/type/Struct/1/type/Variant\"}},\"loc_id\":\"0\",\"case\":\"none\",\"value\":{\"type\":\"Value\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"value\":{\"type\":\"Null\",\"value\":null}}}}}},{\"name\":\"rowOffset\",\"value\":{\"type\":\"Variant\",\"value\":{\"type\":{\"type\":\"Variant\",\"value\":{\"$ref\":\"8#variable/Variable/type/Struct/1/type/Variant\"}},\"loc_id\":\"0\",\"case\":\"none\",\"value\":{\"type\":\"Value\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"value\":{\"type\":\"Null\",\"value\":null}}}}}},{\"name\":\"rowLimit\",\"value\":{\"type\":\"Variant\",\"value\":{\"type\":{\"type\":\"Variant\",\"value\":{\"$ref\":\"8#variable/Variable/type/Struct/3/type/Variant\"}},\"loc_id\":\"0\",\"case\":\"some\",\"value\":{\"type\":\"Value\",\"value\":{\"type\":{\"type\":\"Integer\",\"value\":null},\"loc_id\":\"0\",\"value\":{\"type\":\"Integer\",\"value\":\"5\"}}}}}}]}}}},{\"type\":\"Let\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"variable\":{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"Array\",\"value\":{\"type\":\"Struct\",\"value\":[{\"name\":\"actor_id\",\"type\":{\"type\":\"Variant\",\"value\":[{\"name\":\"none\",\"type\":{\"type\":\"Null\",\"value\":null}},{\"name\":\"some\",\"type\":{\"type\":\"Integer\",\"value\":null}}]}},{\"name\":\"first_name\",\"type\":{\"type\":\"Variant\",\"value\":{\"$ref\":\"10#0/Let/variable/Variable/type/Struct/1/type/Variant\"}}},{\"name\":\"last_name\",\"type\":{\"type\":\"Variant\",\"value\":{\"$ref\":\"10#0/Let/variable/Variable/type/Struct/1/type/Variant\"}}}]}},\"loc_id\":\"0\",\"name\":\"rows\",\"mutable\":true,\"captured\":false}},\"value\":{\"type\":\"Platform\",\"value\":{\"type\":{\"type\":\"Array\",\"value\":{\"type\":\"Struct\",\"value\":{\"$ref\":\"5#variable/Variable/type/Array/Struct\"}}},\"loc_id\":\"0\",\"name\":\"access_query\",\"type_parameters\":[{\"type\":\"Struct\",\"value\":{\"$ref\":\"5#variable/Variable/type/Array/Struct\"}}],\"arguments\":[{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"name\":\"handle\",\"mutable\":true,\"captured\":false}},{\"type\":\"As\",\"value\":{\"type\":{\"type\":\"Struct\",\"value\":[{\"name\":\"table\",\"type\":{\"type\":\"String\",\"value\":null}},{\"name\":\"columns\",\"type\":{\"type\":\"Variant\",\"value\":[{\"name\":\"none\",\"type\":{\"type\":\"Null\",\"value\":null}},{\"name\":\"some\",\"type\":{\"type\":\"Array\",\"value\":{\"type\":\"String\",\"value\":null}}}]}},{\"name\":\"rowOffset\",\"type\":{\"type\":\"Variant\",\"value\":[{\"name\":\"none\",\"type\":{\"type\":\"Null\",\"value\":null}},{\"name\":\"some\",\"type\":{\"type\":\"Integer\",\"value\":null}}]}},{\"name\":\"rowLimit\",\"type\":{\"type\":\"Variant\",\"value\":[{\"name\":\"none\",\"type\":{\"type\":\"Null\",\"value\":null}},{\"name\":\"some\",\"type\":{\"type\":\"Integer\",\"value\":null}}]}}]},\"loc_id\":\"0\",\"value\":{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"Struct\",\"value\":{\"$ref\":\"11#2/Let/variable/Variable/type/Struct\"}},\"loc_id\":\"0\",\"name\":\"options\",\"mutable\":true,\"captured\":false}}}}],\"async\":true,\"optional\":false}}}},{\"type\":\"Platform\",\"value\":{\"type\":{\"type\":\"Null\",\"value\":null},\"loc_id\":\"0\",\"name\":\"access_close\",\"type_parameters\":[],\"arguments\":[{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"String\",\"value\":null},\"loc_id\":\"0\",\"name\":\"handle\",\"mutable\":true,\"captured\":false}}],\"async\":true,\"optional\":false}},{\"type\":\"Builtin\",\"value\":{\"type\":{\"type\":\"Boolean\",\"value\":null},\"loc_id\":\"0\",\"builtin\":\"Greater\",\"type_parameters\":[{\"type\":\"Integer\",\"value\":null}],\"arguments\":[{\"type\":\"Builtin\",\"value\":{\"type\":{\"type\":\"Integer\",\"value\":null},\"loc_id\":\"0\",\"builtin\":\"ArraySize\",\"type_parameters\":[{\"type\":\"Struct\",\"value\":{\"$ref\":\"8#3/Let/variable/Variable/type/Array/Struct\"}}],\"arguments\":[{\"type\":\"Variable\",\"value\":{\"type\":{\"type\":\"Array\",\"value\":{\"type\":\"Struct\",\"value\":{\"$ref\":\"11#3/Let/variable/Variable/type/Array/Struct\"}}},\"loc_id\":\"0\",\"name\":\"rows\",\"mutable\":true,\"captured\":false}}]}},{\"type\":\"Value\",\"value\":{\"type\":{\"type\":\"Integer\",\"value\":null},\"loc_id\":\"0\",\"value\":{\"type\":\"Integer\",\"value\":\"0\"}}}]}}]}}}}",
25281
+ "ts": "// Generated by east-node transpile — East IR printed as the East.function\n// builder surface. Rebuilding this module yields the same IR (normalized).\nimport { East, variant, none, NullType, BooleanType, IntegerType, StringType, StructType, VariantType, OptionType } from \"@elaraai/east\";\nimport { SQL } from \"@elaraai/east-node-io\";\n\nexport const accessQuery = East.asyncFunction([], BooleanType, ($) => {\n const config = $.let(\n { path: \"test/sql/fixtures/actors.mdb\", password: none },\n StructType({ path: StringType, password: OptionType(StringType) }),\n );\n const handle = $.let(SQL.Access.open(config));\n const options = $.let(\n {\n table: \"actor\",\n columns: variant(\"none\", null),\n rowOffset: variant(\"none\", null),\n rowLimit: variant(\"some\", 5n),\n },\n StructType({\n table: StringType,\n columns: VariantType({ none: NullType }),\n rowOffset: VariantType({ none: NullType }),\n rowLimit: VariantType({ some: IntegerType }),\n }),\n );\n const rows = $.let(\n SQL.Access.query(\n [\n StructType({\n actor_id: OptionType(IntegerType),\n first_name: OptionType(StringType),\n last_name: OptionType(StringType),\n }),\n ],\n handle,\n options,\n ),\n );\n $(SQL.Access.close(handle));\n return East.greater(rows.size(), 0n);\n});\n",
25282
+ "python": "# Generated by east-py transpile — East IR printed as the East.function\n# builder surface. Rebuilding this module yields the same IR (normalized).\nfrom east import East, variant, none, east_null, NullType, BooleanType, IntegerType, StringType, StructType, VariantType, OptionType\nfrom east_py_io import AccessConfigType, access_close, access_open, access_query\n\n@East.asyncFunction([], BooleanType)\ndef accessQuery(b):\n config = b.let({'path': 'test/sql/fixtures/actors.mdb', 'password': none}, AccessConfigType)\n handle = b.let(access_open(config))\n options = b.let(\n {\n 'table': 'actor',\n 'columns': variant('none', east_null),\n 'rowOffset': variant('none', east_null),\n 'rowLimit': variant('some', 5),\n },\n StructType([\n ('table', StringType),\n ('columns', VariantType([('none', NullType)])),\n ('rowOffset', VariantType([('none', NullType)])),\n ('rowLimit', VariantType([('some', IntegerType)])),\n ]),\n )\n rows = b.let(\n access_query(\n StructType([\n ('actor_id', OptionType(IntegerType)),\n ('first_name', OptionType(StringType)),\n ('last_name', OptionType(StringType)),\n ]),\n handle,\n options,\n ),\n )\n b.do(access_close(handle))\n return (rows.size() > 0)\n",
25289
25283
  "signature": {
25290
25284
  "inputs": [],
25291
25285
  "output": "BooleanType",
@@ -25298,9 +25292,7 @@
25298
25292
  "Greater",
25299
25293
  "access_close",
25300
25294
  "access_open",
25301
- "access_query",
25302
- "fetch_get_bytes",
25303
- "fs_write_file_bytes"
25295
+ "access_query"
25304
25296
  ]
25305
25297
  },
25306
25298
  {
@@ -25317,9 +25309,9 @@
25317
25309
  "cleanup"
25318
25310
  ],
25319
25311
  "imports": [
25320
- "import { East, BooleanType, IntegerType, NullType, OptionType, StringType, StructType, variant, example } from \"@elaraai/east\";",
25312
+ "import { East, BooleanType, IntegerType, NullType, OptionType, StringType, StructType, example, none, some } from \"@elaraai/east\";",
25321
25313
  "import { SQL } from \"@elaraai/east-node-io\";",
25322
- "import { Fetch, FileSystem } from \"@elaraai/east-node-std\";"
25314
+ "import { ACTORS_PATH } from \"./access-actors.js\";"
25323
25315
  ],
25324
25316
  "languages": [
25325
25317
  "typescript",
@@ -31502,6 +31494,66 @@
31502
31494
  ],
31503
31495
  "source": "// Bubble scatter — per-point size encodes population\n// inputs: []\nEast.function([], UIComponentType, ($) => {\n const SCATTER_BUBBLE_DATA = [\n { gdp: 1.2, life: 62.0, pop: 1400.0 }, { gdp: 4.5, life: 78.0, pop: 330.0 },\n { gdp: 2.1, life: 70.0, pop: 210.0 }, { gdp: 5.8, life: 82.0, pop: 125.0 },\n ];\n const rows = $.const(SCATTER_BUBBLE_DATA, ArrayType(StructType({ gdp: FloatType, life: FloatType, pop: FloatType })));\n return (\n <Box height=\"280px\" width=\"100%\">\n <Chart layers={Chart.Scatter(rows, { x: r => r.gdp, y: r => r.life, size: r => r.pop })} x={{ label: \"GDP per capita\" }} y={{ label: \"Life expectancy\" }} grid />\n </Box>\n );\n })"
31504
31496
  },
31497
+ {
31498
+ "id": "east-ui:chart.examples.tsx:pieShares",
31499
+ "skill": "east-ui",
31500
+ "package": "east-ui",
31501
+ "file": "east-ui/packages/east-ui/test/charts/chart.examples.tsx",
31502
+ "suite": "",
31503
+ "test": "Pie of revenue by region — largest first from twelve o'clock, the first four regions then Other, drawn as a donut with the total in its centre over a caption; the legend carries each slice's value and share over a note that says what they are, and the slices carry no labels",
31504
+ "keywords": [
31505
+ "Chart",
31506
+ "Pie",
31507
+ "donut",
31508
+ "shares",
31509
+ "share",
31510
+ "total",
31511
+ "Other",
31512
+ "top",
31513
+ "slice",
31514
+ "legend",
31515
+ "percent",
31516
+ "caption",
31517
+ "note"
31518
+ ],
31519
+ "imports": [
31520
+ "import { East, IntegerType, FloatType, StringType, StructType, ArrayType, BooleanType, NullType, example, variant } from \"@elaraai/east\";",
31521
+ "import { State, UIComponentType } from \"@elaraai/east-ui\";",
31522
+ "import { Box, Button, Chart, Configurator, HStack, Reactive, Select, Switch, Table, Text, VStack } from \"@elaraai/east-ui\";"
31523
+ ],
31524
+ "languages": [
31525
+ "tsx"
31526
+ ],
31527
+ "source": "// Pie of revenue by region — largest first from twelve o'clock, the first four regions then Other, drawn as a donut with the total in its centre over a caption; the legend carries each slice's value and share over a note that says what they are, and the slices carry no labels\n// inputs: []\nEast.function([], UIComponentType, ($) => {\n const rows = $.const([\n { region: \"NSW\", revenue: 420.0 }, { region: \"VIC\", revenue: 310.0 }, { region: \"QLD\", revenue: 260.0 },\n { region: \"WA\", revenue: 140.0 }, { region: \"SA\", revenue: 90.0 }, { region: \"TAS\", revenue: 40.0 },\n ], ArrayType(StructType({ region: StringType, revenue: FloatType })));\n return (\n <Box height=\"240px\" width=\"100%\">\n <Chart layers={Chart.Pie(rows, { label: r => r.region, value: r => r.revenue }, { donut: true, caption: \"AUD · total\", note: \"AUD · share of revenue\", format: Chart.format.currency({ code: \"AUD\", compact: true }) })} height={220} />\n </Box>\n );\n })"
31528
+ },
31529
+ {
31530
+ "id": "east-ui:chart.examples.tsx:pieLegendNames",
31531
+ "skill": "east-ui",
31532
+ "package": "east-ui",
31533
+ "file": "east-ui/packages/east-ui/test/charts/chart.examples.tsx",
31534
+ "suite": "",
31535
+ "test": "Pie of revenue by region whose legend names each slice and no more — `legend: \"names\"`; `\"hidden\"` draws the pie alone, and the default, `\"values\"`, carries each slice's value and share. A slice says its name, its value and its share where the pointer rests",
31536
+ "keywords": [
31537
+ "Chart",
31538
+ "Pie",
31539
+ "legend",
31540
+ "names",
31541
+ "hidden",
31542
+ "values",
31543
+ "no legend",
31544
+ "names only",
31545
+ "shares"
31546
+ ],
31547
+ "imports": [
31548
+ "import { East, IntegerType, FloatType, StringType, StructType, ArrayType, BooleanType, NullType, example, variant } from \"@elaraai/east\";",
31549
+ "import { State, UIComponentType } from \"@elaraai/east-ui\";",
31550
+ "import { Box, Button, Chart, Configurator, HStack, Reactive, Select, Switch, Table, Text, VStack } from \"@elaraai/east-ui\";"
31551
+ ],
31552
+ "languages": [
31553
+ "tsx"
31554
+ ],
31555
+ "source": "// Pie of revenue by region whose legend names each slice and no more — `legend: \"names\"`; `\"hidden\"` draws the pie alone, and the default, `\"values\"`, carries each slice's value and share. A slice says its name, its value and its share where the pointer rests\n// inputs: []\nEast.function([], UIComponentType, ($) => {\n const rows = $.const([\n { region: \"NSW\", revenue: 420.0 }, { region: \"VIC\", revenue: 310.0 }, { region: \"QLD\", revenue: 260.0 },\n { region: \"WA\", revenue: 140.0 }, { region: \"SA\", revenue: 90.0 }, { region: \"TAS\", revenue: 40.0 },\n ], ArrayType(StructType({ region: StringType, revenue: FloatType })));\n return (\n <Box height=\"240px\" width=\"100%\">\n <Chart layers={Chart.Pie(rows, { label: r => r.region, value: r => r.revenue }, { legend: \"names\", format: Chart.format.currency({ code: \"AUD\", compact: true }) })} height={220} />\n </Box>\n );\n })"
31556
+ },
31505
31557
  {
31506
31558
  "id": "east-ui:chart.examples.tsx:composedColumnLine",
31507
31559
  "skill": "east-ui",
@@ -45339,7 +45391,7 @@
45339
45391
  "package": "e3-ui",
45340
45392
  "file": "east-ui/packages/e3-ui/test/query/query.examples.tsx",
45341
45393
  "suite": "",
45342
- "test": "The query builder over the shared fixture's datasets and the saved queries record, open on Top shipped orders, 2026: one toolbar — Visual · jq, Table · Tree, Download, the history item, Copy jq, Save… and Run — the pane's Query tab with its five steps and their counted shape lines, and the ten orders it gives as a Table beside it",
45394
+ "test": "The query builder over the shared fixture's datasets and the saved queries record, open on Top shipped orders, 2026: one toolbar — Visual · jq, Table · Tree, Download, the history item, Copy jq, Save… and Run — the pane's Query tab with its five steps and their counted shape lines, and the ten orders it gives as a Table beside it; the query it shows is the surface's own state, given as `query` and changed in `onOpen` when its Datasets or Library tab asks for another",
45343
45395
  "keywords": [
45344
45396
  "Query",
45345
45397
  "Query.Builder",
@@ -45370,7 +45422,7 @@
45370
45422
  "languages": [
45371
45423
  "tsx"
45372
45424
  ],
45373
- "source": "// The query builder over the shared fixture's datasets and the saved queries record, open on Top shipped orders, 2026: one toolbar — Visual · jq, Table · Tree, Download, the history item, Copy jq, Save… and Run — the pane's Query tab with its five steps and their counted shape lines, and the ten orders it gives as a Table beside it\n// inputs: []\n/** One line of an order: a SKU, its unit price and the quantity ordered. */\nconst Line = StructType({ price: FloatType, qty: IntegerType, sku: StringType });\n\n/** Where an order stands: cancelled for a reason, pending, or shipped on a date. */\nconst Status = VariantType({ cancelled: StructType({ reason: StringType }), pending: NullType, shipped: StructType({ date: DateTimeType }) });\n\n/** An order: `discount` is the fraction taken off, when there is one, and `total` the lines' gross less it, to the cent. */\nconst Order = StructType({\n customer_id: StringType, discount: OptionType(FloatType), id: IntegerType, lines: ArrayType(Line), status: Status, total: FloatType,\n});\n\n/** A customer's tier. */\nconst Tier = VariantType({ gold: NullType, standard: NullType });\n\n/** A customer, and their tier. */\nconst Customer = StructType({ name: StringType, region: StringType, tier: Tier });\n\n/** Weekly demand by region: eight weeks, the first at index 0. */\nconst Forecast = StructType({ regions: DictType(StringType, StructType({ weekly: ArrayType(FloatType) })) });\n\n/** A part and the parts it is built from: a bill of materials. */\nconst Part = RecursiveType(self => StructType({ children: ArrayType(self), cost: FloatType, sku: StringType }));\n\n/** The demand model: units sold at a unit price in a region. */\nconst ModelInput = StructType({ price: FloatType, region: StringType });\n\nconst Model = FunctionType([ModelInput], FloatType);\n\n/** The orders, ids 1001–1040, in id order: the mock's forty, drawn from seed 875 (`Query Editor Spec.md` §6). */\nexport const orders = e3.input(\"orders\", ArrayType(Order), variant(\"value\", [\n { id: 1001n, customer_id: \"C01\", discount: some(0.1), total: 80.1, status: variant(\"shipped\", { date: new Date(\"2026-04-27T09:00:00.000Z\") }),\n lines: [{ price: 8.9, qty: 10n, sku: \"HNG-220\" }] },\n { id: 1002n, customer_id: \"C07\", discount: none, total: 1171.58, status: variant(\"shipped\", { date: new Date(\"2026-01-15T16:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 38n, sku: \"BLT-045\" }, { price: 46.0, qty: 24n, sku: \"PLT-310\" }, { price: 0.18, qty: 196n, sku: \"WSH-008\" }] },\n { id: 1003n, customer_id: \"C02\", discount: none, total: 453.0, status: variant(\"shipped\", { date: new Date(\"2026-04-06T16:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 15n, sku: \"BRK-100\" }, { price: 8.9, qty: 30n, sku: \"HNG-220\" }] },\n { id: 1004n, customer_id: \"C05\", discount: some(0.15), total: 128.61, status: variant(\"pending\", null),\n lines: [{ price: 8.9, qty: 17n, sku: \"HNG-220\" }] },\n { id: 1005n, customer_id: \"C02\", discount: none, total: 520.24, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 6n, sku: \"PLT-310\" }, { price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 0.18, qty: 48n, sku: \"WSH-008\" }] },\n { id: 1006n, customer_id: \"C06\", discount: none, total: 210.8, status: variant(\"shipped\", { date: new Date(\"2026-06-03T14:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 17n, sku: \"BRK-100\" }] },\n { id: 1007n, customer_id: \"C05\", discount: some(0.1), total: 1162.92, status: variant(\"shipped\", { date: new Date(\"2026-04-06T09:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 184n, sku: \"SCR-012\" }, { price: 64.5, qty: 5n, sku: \"RAL-900\" }, { price: 46.0, qty: 7n, sku: \"PLT-310\" }, { price: 3.75, qty: 157n, sku: \"CLP-150\" }] },\n { id: 1008n, customer_id: \"C05\", discount: none, total: 1280.3, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 143n, sku: \"BLT-045\" }, { price: 64.5, qty: 10n, sku: \"RAL-900\" }, { price: 3.75, qty: 137n, sku: \"CLP-150\" }] },\n { id: 1009n, customer_id: \"C04\", discount: some(0.05), total: 409.51, status: variant(\"shipped\", { date: new Date(\"2025-11-18T09:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 6n, sku: \"RAL-900\" }, { price: 0.18, qty: 211n, sku: \"WSH-008\" }, { price: 0.32, qty: 19n, sku: \"SCR-012\" }] },\n { id: 1010n, customer_id: \"C05\", discount: some(0.05), total: 142.23, status: variant(\"shipped\", { date: new Date(\"2025-10-14T12:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 189n, sku: \"WSH-008\" }, { price: 8.9, qty: 13n, sku: \"HNG-220\" }] },\n { id: 1011n, customer_id: \"C08\", discount: none, total: 1027.4, status: variant(\"pending\", null),\n lines: [{ price: 8.9, qty: 29n, sku: \"HNG-220\" }, { price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 0.85, qty: 298n, sku: \"BLT-045\" }] },\n { id: 1012n, customer_id: \"C02\", discount: none, total: 1109.6, status: variant(\"shipped\", { date: new Date(\"2026-04-01T08:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 46.0, qty: 19n, sku: \"PLT-310\" }] },\n { id: 1013n, customer_id: \"C08\", discount: some(0.05), total: 311.37, status: variant(\"shipped\", { date: new Date(\"2026-04-27T10:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 4n, sku: \"RAL-900\" }, { price: 0.32, qty: 218n, sku: \"SCR-012\" }] },\n { id: 1014n, customer_id: \"C07\", discount: none, total: 1765.97, status: variant(\"shipped\", { date: new Date(\"2026-03-09T08:00:00.000Z\") }),\n lines: [{ price: 46.0, qty: 30n, sku: \"PLT-310\" }, { price: 0.18, qty: 254n, sku: \"WSH-008\" }, { price: 0.85, qty: 269n, sku: \"BLT-045\" }, { price: 12.4, qty: 9n, sku: \"BRK-100\" }] },\n { id: 1015n, customer_id: \"C03\", discount: none, total: 3646.84, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 19n, sku: \"PLT-310\" }, { price: 64.5, qty: 26n, sku: \"RAL-900\" }, { price: 3.75, qty: 276n, sku: \"CLP-150\" }, { price: 0.18, qty: 338n, sku: \"WSH-008\" }] },\n { id: 1016n, customer_id: \"C02\", discount: none, total: 1882.9, status: variant(\"pending\", null),\n lines: [{ price: 12.4, qty: 1n, sku: \"BRK-100\" }, { price: 64.5, qty: 29n, sku: \"RAL-900\" }] },\n { id: 1017n, customer_id: \"C02\", discount: some(0.05), total: 2005.59, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 89n, sku: \"BLT-045\" }, { price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 64.5, qty: 23n, sku: \"RAL-900\" }] },\n { id: 1018n, customer_id: \"C03\", discount: none, total: 1372.99, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 26n, sku: \"PLT-310\" }, { price: 0.18, qty: 138n, sku: \"WSH-008\" }, { price: 0.85, qty: 179n, sku: \"BLT-045\" }] },\n { id: 1019n, customer_id: \"C05\", discount: none, total: 684.65, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 301n, sku: \"BLT-045\" }, { price: 12.4, qty: 26n, sku: \"BRK-100\" }, { price: 8.9, qty: 8n, sku: \"HNG-220\" }, { price: 0.32, qty: 110n, sku: \"SCR-012\" }] },\n { id: 1020n, customer_id: \"C01\", discount: some(0.05), total: 297.01, status: variant(\"shipped\", { date: new Date(\"2026-02-06T11:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 75n, sku: \"SCR-012\" }, { price: 0.18, qty: 88n, sku: \"WSH-008\" }, { price: 12.4, qty: 22n, sku: \"BRK-100\" }] },\n { id: 1021n, customer_id: \"C07\", discount: none, total: 1225.5, status: variant(\"shipped\", { date: new Date(\"2026-05-18T14:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 19n, sku: \"RAL-900\" }] },\n { id: 1022n, customer_id: \"C07\", discount: some(0.15), total: 36.26, status: variant(\"shipped\", { date: new Date(\"2026-01-03T10:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 237n, sku: \"WSH-008\" }] },\n { id: 1023n, customer_id: \"C01\", discount: some(0.1), total: 1352.32, status: variant(\"shipped\", { date: new Date(\"2026-01-08T12:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 32n, sku: \"SCR-012\" }, { price: 8.9, qty: 13n, sku: \"HNG-220\" }, { price: 0.18, qty: 123n, sku: \"WSH-008\" }, { price: 64.5, qty: 21n, sku: \"RAL-900\" }] },\n { id: 1024n, customer_id: \"C05\", discount: some(0.05), total: 623.52, status: variant(\"cancelled\", { reason: \"Customer request\" }),\n lines: [{ price: 46.0, qty: 4n, sku: \"PLT-310\" }, { price: 0.18, qty: 209n, sku: \"WSH-008\" }, { price: 0.32, qty: 351n, sku: \"SCR-012\" }, { price: 12.4, qty: 26n, sku: \"BRK-100\" }] },\n { id: 1025n, customer_id: \"C01\", discount: some(0.1), total: 2577.23, status: variant(\"cancelled\", { reason: \"Payment failed\" }),\n lines: [{ price: 0.18, qty: 213n, sku: \"WSH-008\" }, { price: 64.5, qty: 27n, sku: \"RAL-900\" }, { price: 3.75, qty: 289n, sku: \"CLP-150\" }] },\n { id: 1026n, customer_id: \"C03\", discount: none, total: 1913.4, status: variant(\"shipped\", { date: new Date(\"2026-03-07T08:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 354n, sku: \"BLT-045\" }, { price: 64.5, qty: 25n, sku: \"RAL-900\" }] },\n { id: 1027n, customer_id: \"C08\", discount: none, total: 808.19, status: variant(\"shipped\", { date: new Date(\"2026-06-26T10:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 3n, sku: \"BLT-045\" }, { price: 8.9, qty: 25n, sku: \"HNG-220\" }, { price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 0.18, qty: 373n, sku: \"WSH-008\" }] },\n { id: 1028n, customer_id: \"C06\", discount: none, total: 173.45, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 47n, sku: \"BLT-045\" }, { price: 8.9, qty: 15n, sku: \"HNG-220\" }] },\n { id: 1029n, customer_id: \"C05\", discount: none, total: 64.96, status: variant(\"shipped\", { date: new Date(\"2026-03-19T16:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 203n, sku: \"SCR-012\" }] },\n { id: 1030n, customer_id: \"C03\", discount: none, total: 913.36, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 380n, sku: \"BLT-045\" }, { price: 3.75, qty: 4n, sku: \"CLP-150\" }, { price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 0.32, qty: 73n, sku: \"SCR-012\" }] },\n { id: 1031n, customer_id: \"C06\", discount: none, total: 1537.52, status: variant(\"shipped\", { date: new Date(\"2026-05-31T13:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 264n, sku: \"WSH-008\" }, { price: 12.4, qty: 20n, sku: \"BRK-100\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1032n, customer_id: \"C02\", discount: none, total: 1892.81, status: variant(\"cancelled\", { reason: \"Out of stock\" }),\n lines: [{ price: 46.0, qty: 26n, sku: \"PLT-310\" }, { price: 3.75, qty: 183n, sku: \"CLP-150\" }, { price: 0.32, qty: 33n, sku: \"SCR-012\" }] },\n { id: 1033n, customer_id: \"C01\", discount: none, total: 1834.15, status: variant(\"pending\", null),\n lines: [{ price: 64.5, qty: 27n, sku: \"RAL-900\" }, { price: 0.85, qty: 109n, sku: \"BLT-045\" }] },\n { id: 1034n, customer_id: \"C03\", discount: none, total: 323.06, status: variant(\"pending\", null),\n lines: [{ price: 0.32, qty: 140n, sku: \"SCR-012\" }, { price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 0.18, qty: 237n, sku: \"WSH-008\" }] },\n { id: 1035n, customer_id: \"C06\", discount: none, total: 2381.61, status: variant(\"shipped\", { date: new Date(\"2026-06-01T14:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 292n, sku: \"WSH-008\" }, { price: 3.75, qty: 279n, sku: \"CLP-150\" }, { price: 0.85, qty: 48n, sku: \"BLT-045\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1036n, customer_id: \"C01\", discount: some(0.05), total: 1041.68, status: variant(\"shipped\", { date: new Date(\"2026-05-26T13:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 17n, sku: \"RAL-900\" }] },\n { id: 1037n, customer_id: \"C08\", discount: none, total: 774.5, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 8.9, qty: 25n, sku: \"HNG-220\" }] },\n { id: 1038n, customer_id: \"C01\", discount: none, total: 1758.0, status: variant(\"shipped\", { date: new Date(\"2025-10-28T08:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1039n, customer_id: \"C06\", discount: none, total: 471.06, status: variant(\"shipped\", { date: new Date(\"2026-04-04T13:00:00.000Z\") }),\n lines: [{ price: 8.9, qty: 15n, sku: \"HNG-220\" }, { price: 0.18, qty: 222n, sku: \"WSH-008\" }, { price: 12.4, qty: 24n, sku: \"BRK-100\" }] },\n { id: 1040n, customer_id: \"C02\", discount: none, total: 884.1, status: variant(\"shipped\", { date: new Date(\"2025-12-08T14:00:00.000Z\") }),\n lines: [{ price: 46.0, qty: 14n, sku: \"PLT-310\" }, { price: 8.9, qty: 18n, sku: \"HNG-220\" }, { price: 0.85, qty: 94n, sku: \"BLT-045\" }] },\n]));\n\n/** The customers, by id. */\nexport const customers = e3.input(\"customers\", DictType(StringType, Customer), variant(\"value\", new SortedMap([\n [\"C01\", { name: \"Harbour Foods\", region: \"NSW\", tier: variant(\"gold\", null) }],\n [\"C02\", { name: \"Coastline Retail\", region: \"NSW\", tier: variant(\"standard\", null) }],\n [\"C03\", { name: \"Ridge Grocers\", region: \"VIC\", tier: variant(\"gold\", null) }],\n [\"C04\", { name: \"Southbank Market\", region: \"VIC\", tier: variant(\"standard\", null) }],\n [\"C05\", { name: \"Sunfield Traders\", region: \"QLD\", tier: variant(\"standard\", null) }],\n [\"C06\", { name: \"Northgate Supply\", region: \"QLD\", tier: variant(\"gold\", null) }],\n [\"C07\", { name: \"Westend Provisions\", region: \"WA\", tier: variant(\"standard\", null) }],\n [\"C08\", { name: \"Ironbark Stores\", region: \"SA\", tier: variant(\"standard\", null) }],\n], compareFor(StringType))));\n\n/** Weekly demand by region: eight weeks of `base × (0.9 + 0.03w + 0.01i)`, to one place, for the region at index i of NSW, VIC, QLD, WA, SA. */\nexport const forecast = e3.input(\"forecast\", Forecast, variant(\"value\", {\n regions: new SortedMap([\n [\"NSW\", { weekly: [1080.0, 1116.0, 1152.0, 1188.0, 1224.0, 1260.0, 1296.0, 1332.0] }],\n [\"QLD\", { weekly: [791.2, 817.0, 842.8, 868.6, 894.4, 920.2, 946.0, 971.8] }],\n [\"SA\", { weekly: [385.4, 397.7, 410.0, 422.3, 434.6, 446.9, 459.2, 471.5] }],\n [\"VIC\", { weekly: [955.5, 987.0, 1018.5, 1050.0, 1081.5, 1113.0, 1144.5, 1176.0] }],\n [\"WA\", { weekly: [502.2, 518.4, 534.6, 550.8, 567.0, 583.2, 599.4, 615.6] }],\n ], compareFor(StringType)),\n}));\n\n/** The demand model, `round₂(base[region] × (price / 10)^−1.4)`: the units sold at a unit price in a region. */\nconst demandModel = East.function([ModelInput], FloatType, ($, input) => {\n const base = $.const(new SortedMap([[\"NSW\", 1200.0], [\"QLD\", 860.0], [\"SA\", 410.0], [\"VIC\", 1050.0], [\"WA\", 540.0]], compareFor(StringType)), DictType(StringType, FloatType));\n // A region the model does not know has a base of 300.\n const demand = base.get(input.region, () => 300.0).multiply(input.price.divide(10.0).pow(-1.4));\n const cents = $.const(demand.multiply(100.0).add(0.5));\n return cents.subtract(cents.remainder(1.0)).divide(100.0);\n});\n\n/** The demand model as data: an East function every runtime can call, which a query tries over a range. */\nexport const model = e3.input(\"model\", Model, variant(\"value\", East.compile(demandModel, [])));\n\n/** The bill of materials for PUMP-A. */\nexport const bom = e3.input(\"bom\", Part, variant(\"value\", {\n sku: \"PUMP-A\", cost: 42.0, children: [\n { sku: \"MOTOR-1\", cost: 120.0, children: [\n { sku: \"ROTOR-1\", cost: 18.5, children: [] }, { sku: \"STATOR-1\", cost: 22.0, children: [] }, { sku: \"BRG-6203\", cost: 3.2, children: [] },\n ] },\n { sku: \"HOUSING-2\", cost: 35.0, children: [{ sku: \"GASKET-9\", cost: 1.1, children: [] }, { sku: \"BOLT-M8\", cost: 0.4, children: [] }] },\n { sku: \"IMPELLER-3\", cost: 27.5, children: [] },\n { sku: \"SEAL-KIT\", cost: 6.8, children: [{ sku: \"ORING-12\", cost: 0.3, children: [] }, { sku: \"ORING-18\", cost: 0.35, children: [] }] },\n ],\n}));\n\n/**\n * The saved queries record: the mock's seven (`Query Editor Spec.md` §6),\n * each its canonical jq — what the builder's steps print — checked against the\n * data sources the builders bind when the package builds, and described where\n * the mock describes it; the rest describe themselves.\n */\nexport const queries = e3.record(\"queries\", Query.Types.Saved, {\n initial: Query.value({ orders, customers, forecast, model, bom }, [\n {\n name: \"Top shipped orders, 2026\",\n jq: `.customers as $customers\n | .orders\n | map(select(.status.type == \"shipped\") | select(.total >= 100 and (.status.value.date | year) == 2026))\n | map(. + {name: $customers[.customer_id].name, region: $customers[.customer_id].region})\n | map({order: .id, customer: .name, region, total, shipped: .status.value.date})\n | sort_by(-.total)\n | .[:10]`,\n savedAt: new Date(\"2026-10-01T09:00:00Z\"),\n },\n {\n name: \"Revenue by region\",\n jq: `.customers as $customers\n | .orders\n | map(select(.status.type == \"shipped\") | select(.total >= 100 and (.status.value.date | year) == 2026))\n | map(. + {region: $customers[.customer_id].region})\n | group_by(.region)\n | map({region: .[0].region, revenue: map(.total) | add, orders: length})\n | sort_by(-.revenue)\n | .[:3]`,\n description: \"Top 3 regions by shipped revenue in 2026, from orders of $100 or more.\",\n savedAt: new Date(\"2026-09-29T09:00:00Z\"),\n },\n {\n name: \"Shipped revenue by month\",\n jq: `.orders\n | map(select(.status.type == \"shipped\"))\n | map(. + {ship_month: .status.value.date | strftime(\"%Y-%m\")})\n | group_by(.ship_month)\n | map({ship_month: .[0].ship_month, revenue: map(.total) | add, orders: length})\n | sort_by(.ship_month)`,\n savedAt: new Date(\"2026-09-12T09:00:00Z\"),\n },\n {\n name: \"Large orders with no discount\",\n jq: `.orders\n | map(select(.total >= 1000 and .discount == null))\n | map({id, customer_id, total, status})\n | sort_by(-.total)`,\n savedAt: new Date(\"2026-09-03T09:00:00Z\"),\n },\n {\n name: \"Units by SKU\",\n jq: `.orders\n | [.[] | . as $order | .lines[] | . + {order_id: $order.id}]\n | group_by(.sku)\n | map({sku: .[0].sku, units: map(.qty) | add, orders: map(.order_id) | unique | length})\n | sort_by(-.units)`,\n savedAt: new Date(\"2026-08-28T09:00:00Z\"),\n },\n {\n name: \"Pump parts cost\",\n jq: `.bom\n | [recurse(.children[]) | {cost, sku}]\n | {total_cost: map(.cost) | add, parts: length, dearest: map(.cost) | max}`,\n description: \"Total cost, part count and dearest part in the PUMP-A bill of materials.\",\n savedAt: new Date(\"2026-08-20T09:00:00Z\"),\n },\n {\n name: \"Demand at $10–$12, NSW\",\n jq: `.model\n | [range(10.0; 12.0 + 0.5 / 2; 0.5) as $price | {price: $price, demand: call(.; {price: $price, region: \"NSW\"})}]`,\n description: \"Modelled demand in NSW at prices from $10 to $12, in $0.50 steps.\",\n savedAt: new Date(\"2026-08-14T09:00:00Z\"),\n },\n ]),\n mutations: (mutation) => ({\n // The record's one write.\n patch: mutation.patch(),\n }),\n});\n\nEast.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const saved = $.let(Record.bind(queries));\n const orderRows = $.let(Data.bind(orders));\n const customerRows = $.let(Data.bind(customers));\n const weekly = $.let(Data.bind(forecast));\n const demand = $.let(Data.bind(model));\n const parts = $.let(Data.bind(bom));\n return (\n <Box height=\"760px\">\n <Query.Builder queries={saved} query=\"Top shipped orders, 2026\" id=\"top\"\n datasets={{ orders: orderRows, customers: customerRows, forecast: weekly, model: demand, bom: parts }} />\n </Box>\n );\n }}</Reactive>\n ))"
45425
+ "source": "// The query builder over the shared fixture's datasets and the saved queries record, open on Top shipped orders, 2026: one toolbar — Visual · jq, Table · Tree, Download, the history item, Copy jq, Save… and Run — the pane's Query tab with its five steps and their counted shape lines, and the ten orders it gives as a Table beside it; the query it shows is the surface's own state, given as `query` and changed in `onOpen` when its Datasets or Library tab asks for another\n// inputs: []\n/** One line of an order: a SKU, its unit price and the quantity ordered. */\nconst Line = StructType({ price: FloatType, qty: IntegerType, sku: StringType });\n\n/** Where an order stands: cancelled for a reason, pending, or shipped on a date. */\nconst Status = VariantType({ cancelled: StructType({ reason: StringType }), pending: NullType, shipped: StructType({ date: DateTimeType }) });\n\n/** An order: `discount` is the fraction taken off, when there is one, and `total` the lines' gross less it, to the cent. */\nconst Order = StructType({\n customer_id: StringType, discount: OptionType(FloatType), id: IntegerType, lines: ArrayType(Line), status: Status, total: FloatType,\n});\n\n/** A customer's tier. */\nconst Tier = VariantType({ gold: NullType, standard: NullType });\n\n/** A customer, and their tier. */\nconst Customer = StructType({ name: StringType, region: StringType, tier: Tier });\n\n/** Weekly demand by region: eight weeks, the first at index 0. */\nconst Forecast = StructType({ regions: DictType(StringType, StructType({ weekly: ArrayType(FloatType) })) });\n\n/** A part and the parts it is built from: a bill of materials. */\nconst Part = RecursiveType(self => StructType({ children: ArrayType(self), cost: FloatType, sku: StringType }));\n\n/** The demand model: units sold at a unit price in a region. */\nconst ModelInput = StructType({ price: FloatType, region: StringType });\n\nconst Model = FunctionType([ModelInput], FloatType);\n\n/** The orders, ids 1001–1040, in id order: the mock's forty, drawn from seed 875 (`Query Editor Spec.md` §6). */\nexport const orders = e3.input(\"orders\", ArrayType(Order), variant(\"value\", [\n { id: 1001n, customer_id: \"C01\", discount: some(0.1), total: 80.1, status: variant(\"shipped\", { date: new Date(\"2026-04-27T09:00:00.000Z\") }),\n lines: [{ price: 8.9, qty: 10n, sku: \"HNG-220\" }] },\n { id: 1002n, customer_id: \"C07\", discount: none, total: 1171.58, status: variant(\"shipped\", { date: new Date(\"2026-01-15T16:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 38n, sku: \"BLT-045\" }, { price: 46.0, qty: 24n, sku: \"PLT-310\" }, { price: 0.18, qty: 196n, sku: \"WSH-008\" }] },\n { id: 1003n, customer_id: \"C02\", discount: none, total: 453.0, status: variant(\"shipped\", { date: new Date(\"2026-04-06T16:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 15n, sku: \"BRK-100\" }, { price: 8.9, qty: 30n, sku: \"HNG-220\" }] },\n { id: 1004n, customer_id: \"C05\", discount: some(0.15), total: 128.61, status: variant(\"pending\", null),\n lines: [{ price: 8.9, qty: 17n, sku: \"HNG-220\" }] },\n { id: 1005n, customer_id: \"C02\", discount: none, total: 520.24, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 6n, sku: \"PLT-310\" }, { price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 0.18, qty: 48n, sku: \"WSH-008\" }] },\n { id: 1006n, customer_id: \"C06\", discount: none, total: 210.8, status: variant(\"shipped\", { date: new Date(\"2026-06-03T14:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 17n, sku: \"BRK-100\" }] },\n { id: 1007n, customer_id: \"C05\", discount: some(0.1), total: 1162.92, status: variant(\"shipped\", { date: new Date(\"2026-04-06T09:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 184n, sku: \"SCR-012\" }, { price: 64.5, qty: 5n, sku: \"RAL-900\" }, { price: 46.0, qty: 7n, sku: \"PLT-310\" }, { price: 3.75, qty: 157n, sku: \"CLP-150\" }] },\n { id: 1008n, customer_id: \"C05\", discount: none, total: 1280.3, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 143n, sku: \"BLT-045\" }, { price: 64.5, qty: 10n, sku: \"RAL-900\" }, { price: 3.75, qty: 137n, sku: \"CLP-150\" }] },\n { id: 1009n, customer_id: \"C04\", discount: some(0.05), total: 409.51, status: variant(\"shipped\", { date: new Date(\"2025-11-18T09:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 6n, sku: \"RAL-900\" }, { price: 0.18, qty: 211n, sku: \"WSH-008\" }, { price: 0.32, qty: 19n, sku: \"SCR-012\" }] },\n { id: 1010n, customer_id: \"C05\", discount: some(0.05), total: 142.23, status: variant(\"shipped\", { date: new Date(\"2025-10-14T12:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 189n, sku: \"WSH-008\" }, { price: 8.9, qty: 13n, sku: \"HNG-220\" }] },\n { id: 1011n, customer_id: \"C08\", discount: none, total: 1027.4, status: variant(\"pending\", null),\n lines: [{ price: 8.9, qty: 29n, sku: \"HNG-220\" }, { price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 0.85, qty: 298n, sku: \"BLT-045\" }] },\n { id: 1012n, customer_id: \"C02\", discount: none, total: 1109.6, status: variant(\"shipped\", { date: new Date(\"2026-04-01T08:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 46.0, qty: 19n, sku: \"PLT-310\" }] },\n { id: 1013n, customer_id: \"C08\", discount: some(0.05), total: 311.37, status: variant(\"shipped\", { date: new Date(\"2026-04-27T10:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 4n, sku: \"RAL-900\" }, { price: 0.32, qty: 218n, sku: \"SCR-012\" }] },\n { id: 1014n, customer_id: \"C07\", discount: none, total: 1765.97, status: variant(\"shipped\", { date: new Date(\"2026-03-09T08:00:00.000Z\") }),\n lines: [{ price: 46.0, qty: 30n, sku: \"PLT-310\" }, { price: 0.18, qty: 254n, sku: \"WSH-008\" }, { price: 0.85, qty: 269n, sku: \"BLT-045\" }, { price: 12.4, qty: 9n, sku: \"BRK-100\" }] },\n { id: 1015n, customer_id: \"C03\", discount: none, total: 3646.84, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 19n, sku: \"PLT-310\" }, { price: 64.5, qty: 26n, sku: \"RAL-900\" }, { price: 3.75, qty: 276n, sku: \"CLP-150\" }, { price: 0.18, qty: 338n, sku: \"WSH-008\" }] },\n { id: 1016n, customer_id: \"C02\", discount: none, total: 1882.9, status: variant(\"pending\", null),\n lines: [{ price: 12.4, qty: 1n, sku: \"BRK-100\" }, { price: 64.5, qty: 29n, sku: \"RAL-900\" }] },\n { id: 1017n, customer_id: \"C02\", discount: some(0.05), total: 2005.59, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 89n, sku: \"BLT-045\" }, { price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 64.5, qty: 23n, sku: \"RAL-900\" }] },\n { id: 1018n, customer_id: \"C03\", discount: none, total: 1372.99, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 26n, sku: \"PLT-310\" }, { price: 0.18, qty: 138n, sku: \"WSH-008\" }, { price: 0.85, qty: 179n, sku: \"BLT-045\" }] },\n { id: 1019n, customer_id: \"C05\", discount: none, total: 684.65, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 301n, sku: \"BLT-045\" }, { price: 12.4, qty: 26n, sku: \"BRK-100\" }, { price: 8.9, qty: 8n, sku: \"HNG-220\" }, { price: 0.32, qty: 110n, sku: \"SCR-012\" }] },\n { id: 1020n, customer_id: \"C01\", discount: some(0.05), total: 297.01, status: variant(\"shipped\", { date: new Date(\"2026-02-06T11:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 75n, sku: \"SCR-012\" }, { price: 0.18, qty: 88n, sku: \"WSH-008\" }, { price: 12.4, qty: 22n, sku: \"BRK-100\" }] },\n { id: 1021n, customer_id: \"C07\", discount: none, total: 1225.5, status: variant(\"shipped\", { date: new Date(\"2026-05-18T14:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 19n, sku: \"RAL-900\" }] },\n { id: 1022n, customer_id: \"C07\", discount: some(0.15), total: 36.26, status: variant(\"shipped\", { date: new Date(\"2026-01-03T10:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 237n, sku: \"WSH-008\" }] },\n { id: 1023n, customer_id: \"C01\", discount: some(0.1), total: 1352.32, status: variant(\"shipped\", { date: new Date(\"2026-01-08T12:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 32n, sku: \"SCR-012\" }, { price: 8.9, qty: 13n, sku: \"HNG-220\" }, { price: 0.18, qty: 123n, sku: \"WSH-008\" }, { price: 64.5, qty: 21n, sku: \"RAL-900\" }] },\n { id: 1024n, customer_id: \"C05\", discount: some(0.05), total: 623.52, status: variant(\"cancelled\", { reason: \"Customer request\" }),\n lines: [{ price: 46.0, qty: 4n, sku: \"PLT-310\" }, { price: 0.18, qty: 209n, sku: \"WSH-008\" }, { price: 0.32, qty: 351n, sku: \"SCR-012\" }, { price: 12.4, qty: 26n, sku: \"BRK-100\" }] },\n { id: 1025n, customer_id: \"C01\", discount: some(0.1), total: 2577.23, status: variant(\"cancelled\", { reason: \"Payment failed\" }),\n lines: [{ price: 0.18, qty: 213n, sku: \"WSH-008\" }, { price: 64.5, qty: 27n, sku: \"RAL-900\" }, { price: 3.75, qty: 289n, sku: \"CLP-150\" }] },\n { id: 1026n, customer_id: \"C03\", discount: none, total: 1913.4, status: variant(\"shipped\", { date: new Date(\"2026-03-07T08:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 354n, sku: \"BLT-045\" }, { price: 64.5, qty: 25n, sku: \"RAL-900\" }] },\n { id: 1027n, customer_id: \"C08\", discount: none, total: 808.19, status: variant(\"shipped\", { date: new Date(\"2026-06-26T10:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 3n, sku: \"BLT-045\" }, { price: 8.9, qty: 25n, sku: \"HNG-220\" }, { price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 0.18, qty: 373n, sku: \"WSH-008\" }] },\n { id: 1028n, customer_id: \"C06\", discount: none, total: 173.45, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 47n, sku: \"BLT-045\" }, { price: 8.9, qty: 15n, sku: \"HNG-220\" }] },\n { id: 1029n, customer_id: \"C05\", discount: none, total: 64.96, status: variant(\"shipped\", { date: new Date(\"2026-03-19T16:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 203n, sku: \"SCR-012\" }] },\n { id: 1030n, customer_id: \"C03\", discount: none, total: 913.36, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 380n, sku: \"BLT-045\" }, { price: 3.75, qty: 4n, sku: \"CLP-150\" }, { price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 0.32, qty: 73n, sku: \"SCR-012\" }] },\n { id: 1031n, customer_id: \"C06\", discount: none, total: 1537.52, status: variant(\"shipped\", { date: new Date(\"2026-05-31T13:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 264n, sku: \"WSH-008\" }, { price: 12.4, qty: 20n, sku: \"BRK-100\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1032n, customer_id: \"C02\", discount: none, total: 1892.81, status: variant(\"cancelled\", { reason: \"Out of stock\" }),\n lines: [{ price: 46.0, qty: 26n, sku: \"PLT-310\" }, { price: 3.75, qty: 183n, sku: \"CLP-150\" }, { price: 0.32, qty: 33n, sku: \"SCR-012\" }] },\n { id: 1033n, customer_id: \"C01\", discount: none, total: 1834.15, status: variant(\"pending\", null),\n lines: [{ price: 64.5, qty: 27n, sku: \"RAL-900\" }, { price: 0.85, qty: 109n, sku: \"BLT-045\" }] },\n { id: 1034n, customer_id: \"C03\", discount: none, total: 323.06, status: variant(\"pending\", null),\n lines: [{ price: 0.32, qty: 140n, sku: \"SCR-012\" }, { price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 0.18, qty: 237n, sku: \"WSH-008\" }] },\n { id: 1035n, customer_id: \"C06\", discount: none, total: 2381.61, status: variant(\"shipped\", { date: new Date(\"2026-06-01T14:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 292n, sku: \"WSH-008\" }, { price: 3.75, qty: 279n, sku: \"CLP-150\" }, { price: 0.85, qty: 48n, sku: \"BLT-045\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1036n, customer_id: \"C01\", discount: some(0.05), total: 1041.68, status: variant(\"shipped\", { date: new Date(\"2026-05-26T13:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 17n, sku: \"RAL-900\" }] },\n { id: 1037n, customer_id: \"C08\", discount: none, total: 774.5, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 8.9, qty: 25n, sku: \"HNG-220\" }] },\n { id: 1038n, customer_id: \"C01\", discount: none, total: 1758.0, status: variant(\"shipped\", { date: new Date(\"2025-10-28T08:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1039n, customer_id: \"C06\", discount: none, total: 471.06, status: variant(\"shipped\", { date: new Date(\"2026-04-04T13:00:00.000Z\") }),\n lines: [{ price: 8.9, qty: 15n, sku: \"HNG-220\" }, { price: 0.18, qty: 222n, sku: \"WSH-008\" }, { price: 12.4, qty: 24n, sku: \"BRK-100\" }] },\n { id: 1040n, customer_id: \"C02\", discount: none, total: 884.1, status: variant(\"shipped\", { date: new Date(\"2025-12-08T14:00:00.000Z\") }),\n lines: [{ price: 46.0, qty: 14n, sku: \"PLT-310\" }, { price: 8.9, qty: 18n, sku: \"HNG-220\" }, { price: 0.85, qty: 94n, sku: \"BLT-045\" }] },\n]));\n\n/** The customers, by id. */\nexport const customers = e3.input(\"customers\", DictType(StringType, Customer), variant(\"value\", new SortedMap([\n [\"C01\", { name: \"Harbour Foods\", region: \"NSW\", tier: variant(\"gold\", null) }],\n [\"C02\", { name: \"Coastline Retail\", region: \"NSW\", tier: variant(\"standard\", null) }],\n [\"C03\", { name: \"Ridge Grocers\", region: \"VIC\", tier: variant(\"gold\", null) }],\n [\"C04\", { name: \"Southbank Market\", region: \"VIC\", tier: variant(\"standard\", null) }],\n [\"C05\", { name: \"Sunfield Traders\", region: \"QLD\", tier: variant(\"standard\", null) }],\n [\"C06\", { name: \"Northgate Supply\", region: \"QLD\", tier: variant(\"gold\", null) }],\n [\"C07\", { name: \"Westend Provisions\", region: \"WA\", tier: variant(\"standard\", null) }],\n [\"C08\", { name: \"Ironbark Stores\", region: \"SA\", tier: variant(\"standard\", null) }],\n], compareFor(StringType))));\n\n/** Weekly demand by region: eight weeks of `base × (0.9 + 0.03w + 0.01i)`, to one place, for the region at index i of NSW, VIC, QLD, WA, SA. */\nexport const forecast = e3.input(\"forecast\", Forecast, variant(\"value\", {\n regions: new SortedMap([\n [\"NSW\", { weekly: [1080.0, 1116.0, 1152.0, 1188.0, 1224.0, 1260.0, 1296.0, 1332.0] }],\n [\"QLD\", { weekly: [791.2, 817.0, 842.8, 868.6, 894.4, 920.2, 946.0, 971.8] }],\n [\"SA\", { weekly: [385.4, 397.7, 410.0, 422.3, 434.6, 446.9, 459.2, 471.5] }],\n [\"VIC\", { weekly: [955.5, 987.0, 1018.5, 1050.0, 1081.5, 1113.0, 1144.5, 1176.0] }],\n [\"WA\", { weekly: [502.2, 518.4, 534.6, 550.8, 567.0, 583.2, 599.4, 615.6] }],\n ], compareFor(StringType)),\n}));\n\n/** The demand model, `round₂(base[region] × (price / 10)^−1.4)`: the units sold at a unit price in a region. */\nconst demandModel = East.function([ModelInput], FloatType, ($, input) => {\n const base = $.const(new SortedMap([[\"NSW\", 1200.0], [\"QLD\", 860.0], [\"SA\", 410.0], [\"VIC\", 1050.0], [\"WA\", 540.0]], compareFor(StringType)), DictType(StringType, FloatType));\n // A region the model does not know has a base of 300.\n const demand = base.get(input.region, () => 300.0).multiply(input.price.divide(10.0).pow(-1.4));\n const cents = $.const(demand.multiply(100.0).add(0.5));\n return cents.subtract(cents.remainder(1.0)).divide(100.0);\n});\n\n/** The demand model as data: an East function every runtime can call, which a query tries over a range. */\nexport const model = e3.input(\"model\", Model, variant(\"value\", East.compile(demandModel, [])));\n\n/** The bill of materials for PUMP-A. */\nexport const bom = e3.input(\"bom\", Part, variant(\"value\", {\n sku: \"PUMP-A\", cost: 42.0, children: [\n { sku: \"MOTOR-1\", cost: 120.0, children: [\n { sku: \"ROTOR-1\", cost: 18.5, children: [] }, { sku: \"STATOR-1\", cost: 22.0, children: [] }, { sku: \"BRG-6203\", cost: 3.2, children: [] },\n ] },\n { sku: \"HOUSING-2\", cost: 35.0, children: [{ sku: \"GASKET-9\", cost: 1.1, children: [] }, { sku: \"BOLT-M8\", cost: 0.4, children: [] }] },\n { sku: \"IMPELLER-3\", cost: 27.5, children: [] },\n { sku: \"SEAL-KIT\", cost: 6.8, children: [{ sku: \"ORING-12\", cost: 0.3, children: [] }, { sku: \"ORING-18\", cost: 0.35, children: [] }] },\n ],\n}));\n\n/**\n * The saved queries record: the mock's seven (`Query Editor Spec.md` §6),\n * each its canonical jq — what the builder's steps print — checked against the\n * data sources the builders bind when the package builds, and described where\n * the mock describes it; the rest describe themselves.\n */\nexport const queries = e3.record(\"queries\", Query.Types.Saved, {\n initial: Query.value({ orders, customers, forecast, model, bom }, [\n {\n name: \"Top shipped orders, 2026\",\n jq: `.customers as $customers\n | .orders\n | map(select(.status.type == \"shipped\") | select(.total >= 100 and (.status.value.date | year) == 2026))\n | map(. + {name: $customers[.customer_id].name, region: $customers[.customer_id].region})\n | map({order: .id, customer: .name, region, total, shipped: .status.value.date})\n | sort_by(-.total)\n | .[:10]`,\n savedAt: new Date(\"2026-10-01T09:00:00Z\"),\n },\n {\n name: \"Revenue by region\",\n jq: `.customers as $customers\n | .orders\n | map(select(.status.type == \"shipped\") | select(.total >= 100 and (.status.value.date | year) == 2026))\n | map(. + {region: $customers[.customer_id].region})\n | group_by(.region)\n | map({region: .[0].region, revenue: map(.total) | add, orders: length})\n | sort_by(-.revenue)\n | .[:3]`,\n description: \"Top 3 regions by shipped revenue in 2026, from orders of $100 or more.\",\n savedAt: new Date(\"2026-09-29T09:00:00Z\"),\n },\n {\n name: \"Shipped revenue by month\",\n jq: `.orders\n | map(select(.status.type == \"shipped\"))\n | map(. + {ship_month: .status.value.date | strftime(\"%Y-%m\")})\n | group_by(.ship_month)\n | map({ship_month: .[0].ship_month, revenue: map(.total) | add, orders: length})\n | sort_by(.ship_month)`,\n savedAt: new Date(\"2026-09-12T09:00:00Z\"),\n },\n {\n name: \"Large orders with no discount\",\n jq: `.orders\n | map(select(.total >= 1000 and .discount == null))\n | map({id, customer_id, total, status})\n | sort_by(-.total)`,\n savedAt: new Date(\"2026-09-03T09:00:00Z\"),\n },\n {\n name: \"Units by SKU\",\n jq: `.orders\n | [.[] | . as $order | .lines[] | . + {order_id: $order.id}]\n | group_by(.sku)\n | map({sku: .[0].sku, units: map(.qty) | add, orders: map(.order_id) | unique | length})\n | sort_by(-.units)`,\n savedAt: new Date(\"2026-08-28T09:00:00Z\"),\n },\n {\n name: \"Pump parts cost\",\n jq: `.bom\n | [recurse(.children[]) | {cost, sku}]\n | {total_cost: map(.cost) | add, parts: length, dearest: map(.cost) | max}`,\n description: \"Total cost, part count and dearest part in the PUMP-A bill of materials.\",\n savedAt: new Date(\"2026-08-20T09:00:00Z\"),\n },\n {\n name: \"Demand at $10–$12, NSW\",\n jq: `.model\n | [range(10.0; 12.0 + 0.5 / 2; 0.5) as $price | {price: $price, demand: call(.; {price: $price, region: \"NSW\"})}]`,\n description: \"Modelled demand in NSW at prices from $10 to $12, in $0.50 steps.\",\n savedAt: new Date(\"2026-08-14T09:00:00Z\"),\n },\n ]),\n mutations: (mutation) => ({\n // The record's one write.\n patch: mutation.patch(),\n }),\n});\n\nEast.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const saved = $.let(Record.bind(queries));\n const orderRows = $.let(Data.bind(orders));\n const customerRows = $.let(Data.bind(customers));\n const weekly = $.let(Data.bind(forecast));\n const demand = $.let(Data.bind(model));\n const parts = $.let(Data.bind(bom));\n // The open query is the surface's: the builder shows it, and tells the surface when its own tabs ask for another.\n const open = $.let(State.bind([Query.Types.Open], \"ex.query.open\", Query.open.saved(\"Top shipped orders, 2026\")));\n const go = $.const(East.function([Query.Types.Open], NullType, ($2, next) => { $2(open.write(next)); }));\n return (\n <Box height=\"760px\">\n <Query.Builder queries={saved} query={open.read()} onOpen={go} id=\"top\"\n datasets={{ orders: orderRows, customers: customerRows, forecast: weekly, model: demand, bom: parts }} />\n </Box>\n );\n }}</Reactive>\n ))"
45374
45426
  },
45375
45427
  {
45376
45428
  "id": "e3-ui:query.examples.tsx:queryBuilderViews",
@@ -45406,7 +45458,7 @@
45406
45458
  "languages": [
45407
45459
  "tsx"
45408
45460
  ],
45409
- "source": "// Which views an instance offers, chosen as the page runs: a multi-select wired into `views` (Visual · jq) and one into `resultViews` (Table · Tree), each an expression of an array of its variant. With one left its switch does not show, and with none chosen, both. `views={[\"visual\"]}` and `resultViews={[\"table\"]}` write the same choices in the code.\n// inputs: []\n/** One line of an order: a SKU, its unit price and the quantity ordered. */\nconst Line = StructType({ price: FloatType, qty: IntegerType, sku: StringType });\n\n/** Where an order stands: cancelled for a reason, pending, or shipped on a date. */\nconst Status = VariantType({ cancelled: StructType({ reason: StringType }), pending: NullType, shipped: StructType({ date: DateTimeType }) });\n\n/** An order: `discount` is the fraction taken off, when there is one, and `total` the lines' gross less it, to the cent. */\nconst Order = StructType({\n customer_id: StringType, discount: OptionType(FloatType), id: IntegerType, lines: ArrayType(Line), status: Status, total: FloatType,\n});\n\n/** A customer's tier. */\nconst Tier = VariantType({ gold: NullType, standard: NullType });\n\n/** A customer, and their tier. */\nconst Customer = StructType({ name: StringType, region: StringType, tier: Tier });\n\n/** Weekly demand by region: eight weeks, the first at index 0. */\nconst Forecast = StructType({ regions: DictType(StringType, StructType({ weekly: ArrayType(FloatType) })) });\n\n/** A part and the parts it is built from: a bill of materials. */\nconst Part = RecursiveType(self => StructType({ children: ArrayType(self), cost: FloatType, sku: StringType }));\n\n/** The demand model: units sold at a unit price in a region. */\nconst ModelInput = StructType({ price: FloatType, region: StringType });\n\nconst Model = FunctionType([ModelInput], FloatType);\n\n/** The orders, ids 1001–1040, in id order: the mock's forty, drawn from seed 875 (`Query Editor Spec.md` §6). */\nexport const orders = e3.input(\"orders\", ArrayType(Order), variant(\"value\", [\n { id: 1001n, customer_id: \"C01\", discount: some(0.1), total: 80.1, status: variant(\"shipped\", { date: new Date(\"2026-04-27T09:00:00.000Z\") }),\n lines: [{ price: 8.9, qty: 10n, sku: \"HNG-220\" }] },\n { id: 1002n, customer_id: \"C07\", discount: none, total: 1171.58, status: variant(\"shipped\", { date: new Date(\"2026-01-15T16:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 38n, sku: \"BLT-045\" }, { price: 46.0, qty: 24n, sku: \"PLT-310\" }, { price: 0.18, qty: 196n, sku: \"WSH-008\" }] },\n { id: 1003n, customer_id: \"C02\", discount: none, total: 453.0, status: variant(\"shipped\", { date: new Date(\"2026-04-06T16:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 15n, sku: \"BRK-100\" }, { price: 8.9, qty: 30n, sku: \"HNG-220\" }] },\n { id: 1004n, customer_id: \"C05\", discount: some(0.15), total: 128.61, status: variant(\"pending\", null),\n lines: [{ price: 8.9, qty: 17n, sku: \"HNG-220\" }] },\n { id: 1005n, customer_id: \"C02\", discount: none, total: 520.24, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 6n, sku: \"PLT-310\" }, { price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 0.18, qty: 48n, sku: \"WSH-008\" }] },\n { id: 1006n, customer_id: \"C06\", discount: none, total: 210.8, status: variant(\"shipped\", { date: new Date(\"2026-06-03T14:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 17n, sku: \"BRK-100\" }] },\n { id: 1007n, customer_id: \"C05\", discount: some(0.1), total: 1162.92, status: variant(\"shipped\", { date: new Date(\"2026-04-06T09:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 184n, sku: \"SCR-012\" }, { price: 64.5, qty: 5n, sku: \"RAL-900\" }, { price: 46.0, qty: 7n, sku: \"PLT-310\" }, { price: 3.75, qty: 157n, sku: \"CLP-150\" }] },\n { id: 1008n, customer_id: \"C05\", discount: none, total: 1280.3, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 143n, sku: \"BLT-045\" }, { price: 64.5, qty: 10n, sku: \"RAL-900\" }, { price: 3.75, qty: 137n, sku: \"CLP-150\" }] },\n { id: 1009n, customer_id: \"C04\", discount: some(0.05), total: 409.51, status: variant(\"shipped\", { date: new Date(\"2025-11-18T09:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 6n, sku: \"RAL-900\" }, { price: 0.18, qty: 211n, sku: \"WSH-008\" }, { price: 0.32, qty: 19n, sku: \"SCR-012\" }] },\n { id: 1010n, customer_id: \"C05\", discount: some(0.05), total: 142.23, status: variant(\"shipped\", { date: new Date(\"2025-10-14T12:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 189n, sku: \"WSH-008\" }, { price: 8.9, qty: 13n, sku: \"HNG-220\" }] },\n { id: 1011n, customer_id: \"C08\", discount: none, total: 1027.4, status: variant(\"pending\", null),\n lines: [{ price: 8.9, qty: 29n, sku: \"HNG-220\" }, { price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 0.85, qty: 298n, sku: \"BLT-045\" }] },\n { id: 1012n, customer_id: \"C02\", discount: none, total: 1109.6, status: variant(\"shipped\", { date: new Date(\"2026-04-01T08:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 46.0, qty: 19n, sku: \"PLT-310\" }] },\n { id: 1013n, customer_id: \"C08\", discount: some(0.05), total: 311.37, status: variant(\"shipped\", { date: new Date(\"2026-04-27T10:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 4n, sku: \"RAL-900\" }, { price: 0.32, qty: 218n, sku: \"SCR-012\" }] },\n { id: 1014n, customer_id: \"C07\", discount: none, total: 1765.97, status: variant(\"shipped\", { date: new Date(\"2026-03-09T08:00:00.000Z\") }),\n lines: [{ price: 46.0, qty: 30n, sku: \"PLT-310\" }, { price: 0.18, qty: 254n, sku: \"WSH-008\" }, { price: 0.85, qty: 269n, sku: \"BLT-045\" }, { price: 12.4, qty: 9n, sku: \"BRK-100\" }] },\n { id: 1015n, customer_id: \"C03\", discount: none, total: 3646.84, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 19n, sku: \"PLT-310\" }, { price: 64.5, qty: 26n, sku: \"RAL-900\" }, { price: 3.75, qty: 276n, sku: \"CLP-150\" }, { price: 0.18, qty: 338n, sku: \"WSH-008\" }] },\n { id: 1016n, customer_id: \"C02\", discount: none, total: 1882.9, status: variant(\"pending\", null),\n lines: [{ price: 12.4, qty: 1n, sku: \"BRK-100\" }, { price: 64.5, qty: 29n, sku: \"RAL-900\" }] },\n { id: 1017n, customer_id: \"C02\", discount: some(0.05), total: 2005.59, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 89n, sku: \"BLT-045\" }, { price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 64.5, qty: 23n, sku: \"RAL-900\" }] },\n { id: 1018n, customer_id: \"C03\", discount: none, total: 1372.99, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 26n, sku: \"PLT-310\" }, { price: 0.18, qty: 138n, sku: \"WSH-008\" }, { price: 0.85, qty: 179n, sku: \"BLT-045\" }] },\n { id: 1019n, customer_id: \"C05\", discount: none, total: 684.65, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 301n, sku: \"BLT-045\" }, { price: 12.4, qty: 26n, sku: \"BRK-100\" }, { price: 8.9, qty: 8n, sku: \"HNG-220\" }, { price: 0.32, qty: 110n, sku: \"SCR-012\" }] },\n { id: 1020n, customer_id: \"C01\", discount: some(0.05), total: 297.01, status: variant(\"shipped\", { date: new Date(\"2026-02-06T11:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 75n, sku: \"SCR-012\" }, { price: 0.18, qty: 88n, sku: \"WSH-008\" }, { price: 12.4, qty: 22n, sku: \"BRK-100\" }] },\n { id: 1021n, customer_id: \"C07\", discount: none, total: 1225.5, status: variant(\"shipped\", { date: new Date(\"2026-05-18T14:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 19n, sku: \"RAL-900\" }] },\n { id: 1022n, customer_id: \"C07\", discount: some(0.15), total: 36.26, status: variant(\"shipped\", { date: new Date(\"2026-01-03T10:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 237n, sku: \"WSH-008\" }] },\n { id: 1023n, customer_id: \"C01\", discount: some(0.1), total: 1352.32, status: variant(\"shipped\", { date: new Date(\"2026-01-08T12:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 32n, sku: \"SCR-012\" }, { price: 8.9, qty: 13n, sku: \"HNG-220\" }, { price: 0.18, qty: 123n, sku: \"WSH-008\" }, { price: 64.5, qty: 21n, sku: \"RAL-900\" }] },\n { id: 1024n, customer_id: \"C05\", discount: some(0.05), total: 623.52, status: variant(\"cancelled\", { reason: \"Customer request\" }),\n lines: [{ price: 46.0, qty: 4n, sku: \"PLT-310\" }, { price: 0.18, qty: 209n, sku: \"WSH-008\" }, { price: 0.32, qty: 351n, sku: \"SCR-012\" }, { price: 12.4, qty: 26n, sku: \"BRK-100\" }] },\n { id: 1025n, customer_id: \"C01\", discount: some(0.1), total: 2577.23, status: variant(\"cancelled\", { reason: \"Payment failed\" }),\n lines: [{ price: 0.18, qty: 213n, sku: \"WSH-008\" }, { price: 64.5, qty: 27n, sku: \"RAL-900\" }, { price: 3.75, qty: 289n, sku: \"CLP-150\" }] },\n { id: 1026n, customer_id: \"C03\", discount: none, total: 1913.4, status: variant(\"shipped\", { date: new Date(\"2026-03-07T08:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 354n, sku: \"BLT-045\" }, { price: 64.5, qty: 25n, sku: \"RAL-900\" }] },\n { id: 1027n, customer_id: \"C08\", discount: none, total: 808.19, status: variant(\"shipped\", { date: new Date(\"2026-06-26T10:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 3n, sku: \"BLT-045\" }, { price: 8.9, qty: 25n, sku: \"HNG-220\" }, { price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 0.18, qty: 373n, sku: \"WSH-008\" }] },\n { id: 1028n, customer_id: \"C06\", discount: none, total: 173.45, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 47n, sku: \"BLT-045\" }, { price: 8.9, qty: 15n, sku: \"HNG-220\" }] },\n { id: 1029n, customer_id: \"C05\", discount: none, total: 64.96, status: variant(\"shipped\", { date: new Date(\"2026-03-19T16:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 203n, sku: \"SCR-012\" }] },\n { id: 1030n, customer_id: \"C03\", discount: none, total: 913.36, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 380n, sku: \"BLT-045\" }, { price: 3.75, qty: 4n, sku: \"CLP-150\" }, { price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 0.32, qty: 73n, sku: \"SCR-012\" }] },\n { id: 1031n, customer_id: \"C06\", discount: none, total: 1537.52, status: variant(\"shipped\", { date: new Date(\"2026-05-31T13:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 264n, sku: \"WSH-008\" }, { price: 12.4, qty: 20n, sku: \"BRK-100\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1032n, customer_id: \"C02\", discount: none, total: 1892.81, status: variant(\"cancelled\", { reason: \"Out of stock\" }),\n lines: [{ price: 46.0, qty: 26n, sku: \"PLT-310\" }, { price: 3.75, qty: 183n, sku: \"CLP-150\" }, { price: 0.32, qty: 33n, sku: \"SCR-012\" }] },\n { id: 1033n, customer_id: \"C01\", discount: none, total: 1834.15, status: variant(\"pending\", null),\n lines: [{ price: 64.5, qty: 27n, sku: \"RAL-900\" }, { price: 0.85, qty: 109n, sku: \"BLT-045\" }] },\n { id: 1034n, customer_id: \"C03\", discount: none, total: 323.06, status: variant(\"pending\", null),\n lines: [{ price: 0.32, qty: 140n, sku: \"SCR-012\" }, { price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 0.18, qty: 237n, sku: \"WSH-008\" }] },\n { id: 1035n, customer_id: \"C06\", discount: none, total: 2381.61, status: variant(\"shipped\", { date: new Date(\"2026-06-01T14:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 292n, sku: \"WSH-008\" }, { price: 3.75, qty: 279n, sku: \"CLP-150\" }, { price: 0.85, qty: 48n, sku: \"BLT-045\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1036n, customer_id: \"C01\", discount: some(0.05), total: 1041.68, status: variant(\"shipped\", { date: new Date(\"2026-05-26T13:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 17n, sku: \"RAL-900\" }] },\n { id: 1037n, customer_id: \"C08\", discount: none, total: 774.5, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 8.9, qty: 25n, sku: \"HNG-220\" }] },\n { id: 1038n, customer_id: \"C01\", discount: none, total: 1758.0, status: variant(\"shipped\", { date: new Date(\"2025-10-28T08:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1039n, customer_id: \"C06\", discount: none, total: 471.06, status: variant(\"shipped\", { date: new Date(\"2026-04-04T13:00:00.000Z\") }),\n lines: [{ price: 8.9, qty: 15n, sku: \"HNG-220\" }, { price: 0.18, qty: 222n, sku: \"WSH-008\" }, { price: 12.4, qty: 24n, sku: \"BRK-100\" }] },\n { id: 1040n, customer_id: \"C02\", discount: none, total: 884.1, status: variant(\"shipped\", { date: new Date(\"2025-12-08T14:00:00.000Z\") }),\n lines: [{ price: 46.0, qty: 14n, sku: \"PLT-310\" }, { price: 8.9, qty: 18n, sku: \"HNG-220\" }, { price: 0.85, qty: 94n, sku: \"BLT-045\" }] },\n]));\n\n/** The customers, by id. */\nexport const customers = e3.input(\"customers\", DictType(StringType, Customer), variant(\"value\", new SortedMap([\n [\"C01\", { name: \"Harbour Foods\", region: \"NSW\", tier: variant(\"gold\", null) }],\n [\"C02\", { name: \"Coastline Retail\", region: \"NSW\", tier: variant(\"standard\", null) }],\n [\"C03\", { name: \"Ridge Grocers\", region: \"VIC\", tier: variant(\"gold\", null) }],\n [\"C04\", { name: \"Southbank Market\", region: \"VIC\", tier: variant(\"standard\", null) }],\n [\"C05\", { name: \"Sunfield Traders\", region: \"QLD\", tier: variant(\"standard\", null) }],\n [\"C06\", { name: \"Northgate Supply\", region: \"QLD\", tier: variant(\"gold\", null) }],\n [\"C07\", { name: \"Westend Provisions\", region: \"WA\", tier: variant(\"standard\", null) }],\n [\"C08\", { name: \"Ironbark Stores\", region: \"SA\", tier: variant(\"standard\", null) }],\n], compareFor(StringType))));\n\n/** Weekly demand by region: eight weeks of `base × (0.9 + 0.03w + 0.01i)`, to one place, for the region at index i of NSW, VIC, QLD, WA, SA. */\nexport const forecast = e3.input(\"forecast\", Forecast, variant(\"value\", {\n regions: new SortedMap([\n [\"NSW\", { weekly: [1080.0, 1116.0, 1152.0, 1188.0, 1224.0, 1260.0, 1296.0, 1332.0] }],\n [\"QLD\", { weekly: [791.2, 817.0, 842.8, 868.6, 894.4, 920.2, 946.0, 971.8] }],\n [\"SA\", { weekly: [385.4, 397.7, 410.0, 422.3, 434.6, 446.9, 459.2, 471.5] }],\n [\"VIC\", { weekly: [955.5, 987.0, 1018.5, 1050.0, 1081.5, 1113.0, 1144.5, 1176.0] }],\n [\"WA\", { weekly: [502.2, 518.4, 534.6, 550.8, 567.0, 583.2, 599.4, 615.6] }],\n ], compareFor(StringType)),\n}));\n\n/** The demand model, `round₂(base[region] × (price / 10)^−1.4)`: the units sold at a unit price in a region. */\nconst demandModel = East.function([ModelInput], FloatType, ($, input) => {\n const base = $.const(new SortedMap([[\"NSW\", 1200.0], [\"QLD\", 860.0], [\"SA\", 410.0], [\"VIC\", 1050.0], [\"WA\", 540.0]], compareFor(StringType)), DictType(StringType, FloatType));\n // A region the model does not know has a base of 300.\n const demand = base.get(input.region, () => 300.0).multiply(input.price.divide(10.0).pow(-1.4));\n const cents = $.const(demand.multiply(100.0).add(0.5));\n return cents.subtract(cents.remainder(1.0)).divide(100.0);\n});\n\n/** The demand model as data: an East function every runtime can call, which a query tries over a range. */\nexport const model = e3.input(\"model\", Model, variant(\"value\", East.compile(demandModel, [])));\n\n/** The bill of materials for PUMP-A. */\nexport const bom = e3.input(\"bom\", Part, variant(\"value\", {\n sku: \"PUMP-A\", cost: 42.0, children: [\n { sku: \"MOTOR-1\", cost: 120.0, children: [\n { sku: \"ROTOR-1\", cost: 18.5, children: [] }, { sku: \"STATOR-1\", cost: 22.0, children: [] }, { sku: \"BRG-6203\", cost: 3.2, children: [] },\n ] },\n { sku: \"HOUSING-2\", cost: 35.0, children: [{ sku: \"GASKET-9\", cost: 1.1, children: [] }, { sku: \"BOLT-M8\", cost: 0.4, children: [] }] },\n { sku: \"IMPELLER-3\", cost: 27.5, children: [] },\n { sku: \"SEAL-KIT\", cost: 6.8, children: [{ sku: \"ORING-12\", cost: 0.3, children: [] }, { sku: \"ORING-18\", cost: 0.35, children: [] }] },\n ],\n}));\n\n/**\n * The saved queries record: the mock's seven (`Query Editor Spec.md` §6),\n * each its canonical jq — what the builder's steps print — checked against the\n * data sources the builders bind when the package builds, and described where\n * the mock describes it; the rest describe themselves.\n */\nexport const queries = e3.record(\"queries\", Query.Types.Saved, {\n initial: Query.value({ orders, customers, forecast, model, bom }, [\n {\n name: \"Top shipped orders, 2026\",\n jq: `.customers as $customers\n | .orders\n | map(select(.status.type == \"shipped\") | select(.total >= 100 and (.status.value.date | year) == 2026))\n | map(. + {name: $customers[.customer_id].name, region: $customers[.customer_id].region})\n | map({order: .id, customer: .name, region, total, shipped: .status.value.date})\n | sort_by(-.total)\n | .[:10]`,\n savedAt: new Date(\"2026-10-01T09:00:00Z\"),\n },\n {\n name: \"Revenue by region\",\n jq: `.customers as $customers\n | .orders\n | map(select(.status.type == \"shipped\") | select(.total >= 100 and (.status.value.date | year) == 2026))\n | map(. + {region: $customers[.customer_id].region})\n | group_by(.region)\n | map({region: .[0].region, revenue: map(.total) | add, orders: length})\n | sort_by(-.revenue)\n | .[:3]`,\n description: \"Top 3 regions by shipped revenue in 2026, from orders of $100 or more.\",\n savedAt: new Date(\"2026-09-29T09:00:00Z\"),\n },\n {\n name: \"Shipped revenue by month\",\n jq: `.orders\n | map(select(.status.type == \"shipped\"))\n | map(. + {ship_month: .status.value.date | strftime(\"%Y-%m\")})\n | group_by(.ship_month)\n | map({ship_month: .[0].ship_month, revenue: map(.total) | add, orders: length})\n | sort_by(.ship_month)`,\n savedAt: new Date(\"2026-09-12T09:00:00Z\"),\n },\n {\n name: \"Large orders with no discount\",\n jq: `.orders\n | map(select(.total >= 1000 and .discount == null))\n | map({id, customer_id, total, status})\n | sort_by(-.total)`,\n savedAt: new Date(\"2026-09-03T09:00:00Z\"),\n },\n {\n name: \"Units by SKU\",\n jq: `.orders\n | [.[] | . as $order | .lines[] | . + {order_id: $order.id}]\n | group_by(.sku)\n | map({sku: .[0].sku, units: map(.qty) | add, orders: map(.order_id) | unique | length})\n | sort_by(-.units)`,\n savedAt: new Date(\"2026-08-28T09:00:00Z\"),\n },\n {\n name: \"Pump parts cost\",\n jq: `.bom\n | [recurse(.children[]) | {cost, sku}]\n | {total_cost: map(.cost) | add, parts: length, dearest: map(.cost) | max}`,\n description: \"Total cost, part count and dearest part in the PUMP-A bill of materials.\",\n savedAt: new Date(\"2026-08-20T09:00:00Z\"),\n },\n {\n name: \"Demand at $10–$12, NSW\",\n jq: `.model\n | [range(10.0; 12.0 + 0.5 / 2; 0.5) as $price | {price: $price, demand: call(.; {price: $price, region: \"NSW\"})}]`,\n description: \"Modelled demand in NSW at prices from $10 to $12, in $0.50 steps.\",\n savedAt: new Date(\"2026-08-14T09:00:00Z\"),\n },\n ]),\n mutations: (mutation) => ({\n // The record's one write.\n patch: mutation.patch(),\n }),\n});\n\nEast.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const saved = $.let(Record.bind(queries));\n const orderRows = $.let(Data.bind(orders));\n const customerRows = $.let(Data.bind(customers));\n // The tags each multi-select holds, and the views they name.\n const queryChosen = $.let(State.bind([ArrayType(StringType)], \"ex.queryBuilderViews.views\", []));\n const resultChosen = $.let(State.bind([ArrayType(StringType)], \"ex.queryBuilderViews.resultViews\", []));\n const queryTags = $.let(queryChosen.read());\n const resultTags = $.let(resultChosen.read());\n const onViews = $.const(East.function([ArrayType(StringType)], NullType, ($, next) => { $(queryChosen.write(next)); }));\n const onResultViews = $.const(East.function([ArrayType(StringType)], NullType, ($, next) => { $(resultChosen.write(next)); }));\n const everyView = $.const([variant(\"visual\", null), variant(\"jq\", null)], ArrayType(Query.Types.View));\n const everyResult = $.const([variant(\"table\", null), variant(\"tree\", null)], ArrayType(Query.Types.ResultView));\n const views = $.let(everyView.filter(($, view) => queryTags.toSet().has(view.getTag())));\n const resultViews = $.let(everyResult.filter(($, view) => resultTags.toSet().has(view.getTag())));\n return (\n <VStack gap=\"3\" align=\"stretch\" width=\"100%\">\n <HStack gap=\"3\" align=\"flex-start\">\n <HStack gap=\"2\" align=\"center\"><Text>Query</Text><Select value=\"\" placeholder=\"Every view\" multiple={true} onChangeMultiple={onViews}\n items={[Select.Item(\"visual\", \"Visual\"), Select.Item(\"jq\", \"jq\")]} /></HStack>\n <HStack gap=\"2\" align=\"center\"><Text>Results</Text><Select value=\"\" placeholder=\"Every view\" multiple={true} onChangeMultiple={onResultViews}\n items={[Select.Item(\"table\", \"Table\"), Select.Item(\"tree\", \"Tree\")]} /></HStack>\n </HStack>\n <Box height=\"680px\">\n <Query.Builder queries={saved} query=\"Top shipped orders, 2026\" id=\"views\" views={views} resultViews={resultViews}\n datasets={{ orders: orderRows, customers: customerRows }} />\n </Box>\n </VStack>\n );\n }}</Reactive>\n ))"
45461
+ "source": "// Which views an instance offers, chosen as the page runs: a multi-select wired into `views` (Visual · jq) and one into `resultViews` (Table · Tree), each an expression of an array of its variant. With one left its switch does not show, and with none chosen, both. `views={[\"visual\"]}` and `resultViews={[\"table\"]}` write the same choices in the code.\n// inputs: []\n/** One line of an order: a SKU, its unit price and the quantity ordered. */\nconst Line = StructType({ price: FloatType, qty: IntegerType, sku: StringType });\n\n/** Where an order stands: cancelled for a reason, pending, or shipped on a date. */\nconst Status = VariantType({ cancelled: StructType({ reason: StringType }), pending: NullType, shipped: StructType({ date: DateTimeType }) });\n\n/** An order: `discount` is the fraction taken off, when there is one, and `total` the lines' gross less it, to the cent. */\nconst Order = StructType({\n customer_id: StringType, discount: OptionType(FloatType), id: IntegerType, lines: ArrayType(Line), status: Status, total: FloatType,\n});\n\n/** A customer's tier. */\nconst Tier = VariantType({ gold: NullType, standard: NullType });\n\n/** A customer, and their tier. */\nconst Customer = StructType({ name: StringType, region: StringType, tier: Tier });\n\n/** Weekly demand by region: eight weeks, the first at index 0. */\nconst Forecast = StructType({ regions: DictType(StringType, StructType({ weekly: ArrayType(FloatType) })) });\n\n/** A part and the parts it is built from: a bill of materials. */\nconst Part = RecursiveType(self => StructType({ children: ArrayType(self), cost: FloatType, sku: StringType }));\n\n/** The demand model: units sold at a unit price in a region. */\nconst ModelInput = StructType({ price: FloatType, region: StringType });\n\nconst Model = FunctionType([ModelInput], FloatType);\n\n/** The orders, ids 1001–1040, in id order: the mock's forty, drawn from seed 875 (`Query Editor Spec.md` §6). */\nexport const orders = e3.input(\"orders\", ArrayType(Order), variant(\"value\", [\n { id: 1001n, customer_id: \"C01\", discount: some(0.1), total: 80.1, status: variant(\"shipped\", { date: new Date(\"2026-04-27T09:00:00.000Z\") }),\n lines: [{ price: 8.9, qty: 10n, sku: \"HNG-220\" }] },\n { id: 1002n, customer_id: \"C07\", discount: none, total: 1171.58, status: variant(\"shipped\", { date: new Date(\"2026-01-15T16:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 38n, sku: \"BLT-045\" }, { price: 46.0, qty: 24n, sku: \"PLT-310\" }, { price: 0.18, qty: 196n, sku: \"WSH-008\" }] },\n { id: 1003n, customer_id: \"C02\", discount: none, total: 453.0, status: variant(\"shipped\", { date: new Date(\"2026-04-06T16:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 15n, sku: \"BRK-100\" }, { price: 8.9, qty: 30n, sku: \"HNG-220\" }] },\n { id: 1004n, customer_id: \"C05\", discount: some(0.15), total: 128.61, status: variant(\"pending\", null),\n lines: [{ price: 8.9, qty: 17n, sku: \"HNG-220\" }] },\n { id: 1005n, customer_id: \"C02\", discount: none, total: 520.24, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 6n, sku: \"PLT-310\" }, { price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 0.18, qty: 48n, sku: \"WSH-008\" }] },\n { id: 1006n, customer_id: \"C06\", discount: none, total: 210.8, status: variant(\"shipped\", { date: new Date(\"2026-06-03T14:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 17n, sku: \"BRK-100\" }] },\n { id: 1007n, customer_id: \"C05\", discount: some(0.1), total: 1162.92, status: variant(\"shipped\", { date: new Date(\"2026-04-06T09:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 184n, sku: \"SCR-012\" }, { price: 64.5, qty: 5n, sku: \"RAL-900\" }, { price: 46.0, qty: 7n, sku: \"PLT-310\" }, { price: 3.75, qty: 157n, sku: \"CLP-150\" }] },\n { id: 1008n, customer_id: \"C05\", discount: none, total: 1280.3, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 143n, sku: \"BLT-045\" }, { price: 64.5, qty: 10n, sku: \"RAL-900\" }, { price: 3.75, qty: 137n, sku: \"CLP-150\" }] },\n { id: 1009n, customer_id: \"C04\", discount: some(0.05), total: 409.51, status: variant(\"shipped\", { date: new Date(\"2025-11-18T09:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 6n, sku: \"RAL-900\" }, { price: 0.18, qty: 211n, sku: \"WSH-008\" }, { price: 0.32, qty: 19n, sku: \"SCR-012\" }] },\n { id: 1010n, customer_id: \"C05\", discount: some(0.05), total: 142.23, status: variant(\"shipped\", { date: new Date(\"2025-10-14T12:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 189n, sku: \"WSH-008\" }, { price: 8.9, qty: 13n, sku: \"HNG-220\" }] },\n { id: 1011n, customer_id: \"C08\", discount: none, total: 1027.4, status: variant(\"pending\", null),\n lines: [{ price: 8.9, qty: 29n, sku: \"HNG-220\" }, { price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 0.85, qty: 298n, sku: \"BLT-045\" }] },\n { id: 1012n, customer_id: \"C02\", discount: none, total: 1109.6, status: variant(\"shipped\", { date: new Date(\"2026-04-01T08:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 46.0, qty: 19n, sku: \"PLT-310\" }] },\n { id: 1013n, customer_id: \"C08\", discount: some(0.05), total: 311.37, status: variant(\"shipped\", { date: new Date(\"2026-04-27T10:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 4n, sku: \"RAL-900\" }, { price: 0.32, qty: 218n, sku: \"SCR-012\" }] },\n { id: 1014n, customer_id: \"C07\", discount: none, total: 1765.97, status: variant(\"shipped\", { date: new Date(\"2026-03-09T08:00:00.000Z\") }),\n lines: [{ price: 46.0, qty: 30n, sku: \"PLT-310\" }, { price: 0.18, qty: 254n, sku: \"WSH-008\" }, { price: 0.85, qty: 269n, sku: \"BLT-045\" }, { price: 12.4, qty: 9n, sku: \"BRK-100\" }] },\n { id: 1015n, customer_id: \"C03\", discount: none, total: 3646.84, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 19n, sku: \"PLT-310\" }, { price: 64.5, qty: 26n, sku: \"RAL-900\" }, { price: 3.75, qty: 276n, sku: \"CLP-150\" }, { price: 0.18, qty: 338n, sku: \"WSH-008\" }] },\n { id: 1016n, customer_id: \"C02\", discount: none, total: 1882.9, status: variant(\"pending\", null),\n lines: [{ price: 12.4, qty: 1n, sku: \"BRK-100\" }, { price: 64.5, qty: 29n, sku: \"RAL-900\" }] },\n { id: 1017n, customer_id: \"C02\", discount: some(0.05), total: 2005.59, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 89n, sku: \"BLT-045\" }, { price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 64.5, qty: 23n, sku: \"RAL-900\" }] },\n { id: 1018n, customer_id: \"C03\", discount: none, total: 1372.99, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 26n, sku: \"PLT-310\" }, { price: 0.18, qty: 138n, sku: \"WSH-008\" }, { price: 0.85, qty: 179n, sku: \"BLT-045\" }] },\n { id: 1019n, customer_id: \"C05\", discount: none, total: 684.65, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 301n, sku: \"BLT-045\" }, { price: 12.4, qty: 26n, sku: \"BRK-100\" }, { price: 8.9, qty: 8n, sku: \"HNG-220\" }, { price: 0.32, qty: 110n, sku: \"SCR-012\" }] },\n { id: 1020n, customer_id: \"C01\", discount: some(0.05), total: 297.01, status: variant(\"shipped\", { date: new Date(\"2026-02-06T11:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 75n, sku: \"SCR-012\" }, { price: 0.18, qty: 88n, sku: \"WSH-008\" }, { price: 12.4, qty: 22n, sku: \"BRK-100\" }] },\n { id: 1021n, customer_id: \"C07\", discount: none, total: 1225.5, status: variant(\"shipped\", { date: new Date(\"2026-05-18T14:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 19n, sku: \"RAL-900\" }] },\n { id: 1022n, customer_id: \"C07\", discount: some(0.15), total: 36.26, status: variant(\"shipped\", { date: new Date(\"2026-01-03T10:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 237n, sku: \"WSH-008\" }] },\n { id: 1023n, customer_id: \"C01\", discount: some(0.1), total: 1352.32, status: variant(\"shipped\", { date: new Date(\"2026-01-08T12:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 32n, sku: \"SCR-012\" }, { price: 8.9, qty: 13n, sku: \"HNG-220\" }, { price: 0.18, qty: 123n, sku: \"WSH-008\" }, { price: 64.5, qty: 21n, sku: \"RAL-900\" }] },\n { id: 1024n, customer_id: \"C05\", discount: some(0.05), total: 623.52, status: variant(\"cancelled\", { reason: \"Customer request\" }),\n lines: [{ price: 46.0, qty: 4n, sku: \"PLT-310\" }, { price: 0.18, qty: 209n, sku: \"WSH-008\" }, { price: 0.32, qty: 351n, sku: \"SCR-012\" }, { price: 12.4, qty: 26n, sku: \"BRK-100\" }] },\n { id: 1025n, customer_id: \"C01\", discount: some(0.1), total: 2577.23, status: variant(\"cancelled\", { reason: \"Payment failed\" }),\n lines: [{ price: 0.18, qty: 213n, sku: \"WSH-008\" }, { price: 64.5, qty: 27n, sku: \"RAL-900\" }, { price: 3.75, qty: 289n, sku: \"CLP-150\" }] },\n { id: 1026n, customer_id: \"C03\", discount: none, total: 1913.4, status: variant(\"shipped\", { date: new Date(\"2026-03-07T08:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 354n, sku: \"BLT-045\" }, { price: 64.5, qty: 25n, sku: \"RAL-900\" }] },\n { id: 1027n, customer_id: \"C08\", discount: none, total: 808.19, status: variant(\"shipped\", { date: new Date(\"2026-06-26T10:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 3n, sku: \"BLT-045\" }, { price: 8.9, qty: 25n, sku: \"HNG-220\" }, { price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 0.18, qty: 373n, sku: \"WSH-008\" }] },\n { id: 1028n, customer_id: \"C06\", discount: none, total: 173.45, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 47n, sku: \"BLT-045\" }, { price: 8.9, qty: 15n, sku: \"HNG-220\" }] },\n { id: 1029n, customer_id: \"C05\", discount: none, total: 64.96, status: variant(\"shipped\", { date: new Date(\"2026-03-19T16:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 203n, sku: \"SCR-012\" }] },\n { id: 1030n, customer_id: \"C03\", discount: none, total: 913.36, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 380n, sku: \"BLT-045\" }, { price: 3.75, qty: 4n, sku: \"CLP-150\" }, { price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 0.32, qty: 73n, sku: \"SCR-012\" }] },\n { id: 1031n, customer_id: \"C06\", discount: none, total: 1537.52, status: variant(\"shipped\", { date: new Date(\"2026-05-31T13:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 264n, sku: \"WSH-008\" }, { price: 12.4, qty: 20n, sku: \"BRK-100\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1032n, customer_id: \"C02\", discount: none, total: 1892.81, status: variant(\"cancelled\", { reason: \"Out of stock\" }),\n lines: [{ price: 46.0, qty: 26n, sku: \"PLT-310\" }, { price: 3.75, qty: 183n, sku: \"CLP-150\" }, { price: 0.32, qty: 33n, sku: \"SCR-012\" }] },\n { id: 1033n, customer_id: \"C01\", discount: none, total: 1834.15, status: variant(\"pending\", null),\n lines: [{ price: 64.5, qty: 27n, sku: \"RAL-900\" }, { price: 0.85, qty: 109n, sku: \"BLT-045\" }] },\n { id: 1034n, customer_id: \"C03\", discount: none, total: 323.06, status: variant(\"pending\", null),\n lines: [{ price: 0.32, qty: 140n, sku: \"SCR-012\" }, { price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 0.18, qty: 237n, sku: \"WSH-008\" }] },\n { id: 1035n, customer_id: \"C06\", discount: none, total: 2381.61, status: variant(\"shipped\", { date: new Date(\"2026-06-01T14:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 292n, sku: \"WSH-008\" }, { price: 3.75, qty: 279n, sku: \"CLP-150\" }, { price: 0.85, qty: 48n, sku: \"BLT-045\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1036n, customer_id: \"C01\", discount: some(0.05), total: 1041.68, status: variant(\"shipped\", { date: new Date(\"2026-05-26T13:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 17n, sku: \"RAL-900\" }] },\n { id: 1037n, customer_id: \"C08\", discount: none, total: 774.5, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 8.9, qty: 25n, sku: \"HNG-220\" }] },\n { id: 1038n, customer_id: \"C01\", discount: none, total: 1758.0, status: variant(\"shipped\", { date: new Date(\"2025-10-28T08:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1039n, customer_id: \"C06\", discount: none, total: 471.06, status: variant(\"shipped\", { date: new Date(\"2026-04-04T13:00:00.000Z\") }),\n lines: [{ price: 8.9, qty: 15n, sku: \"HNG-220\" }, { price: 0.18, qty: 222n, sku: \"WSH-008\" }, { price: 12.4, qty: 24n, sku: \"BRK-100\" }] },\n { id: 1040n, customer_id: \"C02\", discount: none, total: 884.1, status: variant(\"shipped\", { date: new Date(\"2025-12-08T14:00:00.000Z\") }),\n lines: [{ price: 46.0, qty: 14n, sku: \"PLT-310\" }, { price: 8.9, qty: 18n, sku: \"HNG-220\" }, { price: 0.85, qty: 94n, sku: \"BLT-045\" }] },\n]));\n\n/** The customers, by id. */\nexport const customers = e3.input(\"customers\", DictType(StringType, Customer), variant(\"value\", new SortedMap([\n [\"C01\", { name: \"Harbour Foods\", region: \"NSW\", tier: variant(\"gold\", null) }],\n [\"C02\", { name: \"Coastline Retail\", region: \"NSW\", tier: variant(\"standard\", null) }],\n [\"C03\", { name: \"Ridge Grocers\", region: \"VIC\", tier: variant(\"gold\", null) }],\n [\"C04\", { name: \"Southbank Market\", region: \"VIC\", tier: variant(\"standard\", null) }],\n [\"C05\", { name: \"Sunfield Traders\", region: \"QLD\", tier: variant(\"standard\", null) }],\n [\"C06\", { name: \"Northgate Supply\", region: \"QLD\", tier: variant(\"gold\", null) }],\n [\"C07\", { name: \"Westend Provisions\", region: \"WA\", tier: variant(\"standard\", null) }],\n [\"C08\", { name: \"Ironbark Stores\", region: \"SA\", tier: variant(\"standard\", null) }],\n], compareFor(StringType))));\n\n/** Weekly demand by region: eight weeks of `base × (0.9 + 0.03w + 0.01i)`, to one place, for the region at index i of NSW, VIC, QLD, WA, SA. */\nexport const forecast = e3.input(\"forecast\", Forecast, variant(\"value\", {\n regions: new SortedMap([\n [\"NSW\", { weekly: [1080.0, 1116.0, 1152.0, 1188.0, 1224.0, 1260.0, 1296.0, 1332.0] }],\n [\"QLD\", { weekly: [791.2, 817.0, 842.8, 868.6, 894.4, 920.2, 946.0, 971.8] }],\n [\"SA\", { weekly: [385.4, 397.7, 410.0, 422.3, 434.6, 446.9, 459.2, 471.5] }],\n [\"VIC\", { weekly: [955.5, 987.0, 1018.5, 1050.0, 1081.5, 1113.0, 1144.5, 1176.0] }],\n [\"WA\", { weekly: [502.2, 518.4, 534.6, 550.8, 567.0, 583.2, 599.4, 615.6] }],\n ], compareFor(StringType)),\n}));\n\n/** The demand model, `round₂(base[region] × (price / 10)^−1.4)`: the units sold at a unit price in a region. */\nconst demandModel = East.function([ModelInput], FloatType, ($, input) => {\n const base = $.const(new SortedMap([[\"NSW\", 1200.0], [\"QLD\", 860.0], [\"SA\", 410.0], [\"VIC\", 1050.0], [\"WA\", 540.0]], compareFor(StringType)), DictType(StringType, FloatType));\n // A region the model does not know has a base of 300.\n const demand = base.get(input.region, () => 300.0).multiply(input.price.divide(10.0).pow(-1.4));\n const cents = $.const(demand.multiply(100.0).add(0.5));\n return cents.subtract(cents.remainder(1.0)).divide(100.0);\n});\n\n/** The demand model as data: an East function every runtime can call, which a query tries over a range. */\nexport const model = e3.input(\"model\", Model, variant(\"value\", East.compile(demandModel, [])));\n\n/** The bill of materials for PUMP-A. */\nexport const bom = e3.input(\"bom\", Part, variant(\"value\", {\n sku: \"PUMP-A\", cost: 42.0, children: [\n { sku: \"MOTOR-1\", cost: 120.0, children: [\n { sku: \"ROTOR-1\", cost: 18.5, children: [] }, { sku: \"STATOR-1\", cost: 22.0, children: [] }, { sku: \"BRG-6203\", cost: 3.2, children: [] },\n ] },\n { sku: \"HOUSING-2\", cost: 35.0, children: [{ sku: \"GASKET-9\", cost: 1.1, children: [] }, { sku: \"BOLT-M8\", cost: 0.4, children: [] }] },\n { sku: \"IMPELLER-3\", cost: 27.5, children: [] },\n { sku: \"SEAL-KIT\", cost: 6.8, children: [{ sku: \"ORING-12\", cost: 0.3, children: [] }, { sku: \"ORING-18\", cost: 0.35, children: [] }] },\n ],\n}));\n\n/**\n * The saved queries record: the mock's seven (`Query Editor Spec.md` §6),\n * each its canonical jq — what the builder's steps print — checked against the\n * data sources the builders bind when the package builds, and described where\n * the mock describes it; the rest describe themselves.\n */\nexport const queries = e3.record(\"queries\", Query.Types.Saved, {\n initial: Query.value({ orders, customers, forecast, model, bom }, [\n {\n name: \"Top shipped orders, 2026\",\n jq: `.customers as $customers\n | .orders\n | map(select(.status.type == \"shipped\") | select(.total >= 100 and (.status.value.date | year) == 2026))\n | map(. + {name: $customers[.customer_id].name, region: $customers[.customer_id].region})\n | map({order: .id, customer: .name, region, total, shipped: .status.value.date})\n | sort_by(-.total)\n | .[:10]`,\n savedAt: new Date(\"2026-10-01T09:00:00Z\"),\n },\n {\n name: \"Revenue by region\",\n jq: `.customers as $customers\n | .orders\n | map(select(.status.type == \"shipped\") | select(.total >= 100 and (.status.value.date | year) == 2026))\n | map(. + {region: $customers[.customer_id].region})\n | group_by(.region)\n | map({region: .[0].region, revenue: map(.total) | add, orders: length})\n | sort_by(-.revenue)\n | .[:3]`,\n description: \"Top 3 regions by shipped revenue in 2026, from orders of $100 or more.\",\n savedAt: new Date(\"2026-09-29T09:00:00Z\"),\n },\n {\n name: \"Shipped revenue by month\",\n jq: `.orders\n | map(select(.status.type == \"shipped\"))\n | map(. + {ship_month: .status.value.date | strftime(\"%Y-%m\")})\n | group_by(.ship_month)\n | map({ship_month: .[0].ship_month, revenue: map(.total) | add, orders: length})\n | sort_by(.ship_month)`,\n savedAt: new Date(\"2026-09-12T09:00:00Z\"),\n },\n {\n name: \"Large orders with no discount\",\n jq: `.orders\n | map(select(.total >= 1000 and .discount == null))\n | map({id, customer_id, total, status})\n | sort_by(-.total)`,\n savedAt: new Date(\"2026-09-03T09:00:00Z\"),\n },\n {\n name: \"Units by SKU\",\n jq: `.orders\n | [.[] | . as $order | .lines[] | . + {order_id: $order.id}]\n | group_by(.sku)\n | map({sku: .[0].sku, units: map(.qty) | add, orders: map(.order_id) | unique | length})\n | sort_by(-.units)`,\n savedAt: new Date(\"2026-08-28T09:00:00Z\"),\n },\n {\n name: \"Pump parts cost\",\n jq: `.bom\n | [recurse(.children[]) | {cost, sku}]\n | {total_cost: map(.cost) | add, parts: length, dearest: map(.cost) | max}`,\n description: \"Total cost, part count and dearest part in the PUMP-A bill of materials.\",\n savedAt: new Date(\"2026-08-20T09:00:00Z\"),\n },\n {\n name: \"Demand at $10–$12, NSW\",\n jq: `.model\n | [range(10.0; 12.0 + 0.5 / 2; 0.5) as $price | {price: $price, demand: call(.; {price: $price, region: \"NSW\"})}]`,\n description: \"Modelled demand in NSW at prices from $10 to $12, in $0.50 steps.\",\n savedAt: new Date(\"2026-08-14T09:00:00Z\"),\n },\n ]),\n mutations: (mutation) => ({\n // The record's one write.\n patch: mutation.patch(),\n }),\n});\n\nEast.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const saved = $.let(Record.bind(queries));\n const orderRows = $.let(Data.bind(orders));\n const customerRows = $.let(Data.bind(customers));\n // The tags each multi-select holds, and the views they name.\n const queryChosen = $.let(State.bind([ArrayType(StringType)], \"ex.queryBuilderViews.views\", []));\n const resultChosen = $.let(State.bind([ArrayType(StringType)], \"ex.queryBuilderViews.resultViews\", []));\n const queryTags = $.let(queryChosen.read());\n const resultTags = $.let(resultChosen.read());\n const onViews = $.const(East.function([ArrayType(StringType)], NullType, ($, next) => { $(queryChosen.write(next)); }));\n const onResultViews = $.const(East.function([ArrayType(StringType)], NullType, ($, next) => { $(resultChosen.write(next)); }));\n const everyView = $.const([variant(\"visual\", null), variant(\"jq\", null)], ArrayType(Query.Types.View));\n const everyResult = $.const([variant(\"table\", null), variant(\"tree\", null)], ArrayType(Query.Types.ResultView));\n const views = $.let(everyView.filter(($, view) => queryTags.toSet().has(view.getTag())));\n const resultViews = $.let(everyResult.filter(($, view) => resultTags.toSet().has(view.getTag())));\n // The open query is the surface's: the builder shows it, and tells the surface when its own tabs ask for another.\n const open = $.let(State.bind([Query.Types.Open], \"ex.queryBuilderViews.open\", Query.open.saved(\"Top shipped orders, 2026\")));\n const go = $.const(East.function([Query.Types.Open], NullType, ($2, next) => { $2(open.write(next)); }));\n return (\n <VStack gap=\"3\" align=\"stretch\" width=\"100%\">\n <HStack gap=\"3\" align=\"flex-start\">\n <HStack gap=\"2\" align=\"center\"><Text>Query</Text><Select value=\"\" placeholder=\"Every view\" multiple={true} onChangeMultiple={onViews}\n items={[Select.Item(\"visual\", \"Visual\"), Select.Item(\"jq\", \"jq\")]} /></HStack>\n <HStack gap=\"2\" align=\"center\"><Text>Results</Text><Select value=\"\" placeholder=\"Every view\" multiple={true} onChangeMultiple={onResultViews}\n items={[Select.Item(\"table\", \"Table\"), Select.Item(\"tree\", \"Tree\")]} /></HStack>\n </HStack>\n <Box height=\"680px\">\n <Query.Builder queries={saved} query={open.read()} onOpen={go} id=\"views\" views={views} resultViews={resultViews}\n datasets={{ orders: orderRows, customers: customerRows }} />\n </Box>\n </VStack>\n );\n }}</Reactive>\n ))"
45410
45462
  },
45411
45463
  {
45412
45464
  "id": "e3-ui:query.examples.tsx:queryBuilderMobile",
@@ -45436,7 +45488,7 @@
45436
45488
  "languages": [
45437
45489
  "tsx"
45438
45490
  ],
45439
- "source": "// The same builder open on Top shipped orders, 2026 in a phone's 390-wide frame: the toolbar over its second row — the history at 44px — the results the frame's whole width, and the Query tab a drawer up from the strip on the bottom edge\n// inputs: []\n/** One line of an order: a SKU, its unit price and the quantity ordered. */\nconst Line = StructType({ price: FloatType, qty: IntegerType, sku: StringType });\n\n/** Where an order stands: cancelled for a reason, pending, or shipped on a date. */\nconst Status = VariantType({ cancelled: StructType({ reason: StringType }), pending: NullType, shipped: StructType({ date: DateTimeType }) });\n\n/** An order: `discount` is the fraction taken off, when there is one, and `total` the lines' gross less it, to the cent. */\nconst Order = StructType({\n customer_id: StringType, discount: OptionType(FloatType), id: IntegerType, lines: ArrayType(Line), status: Status, total: FloatType,\n});\n\n/** A customer's tier. */\nconst Tier = VariantType({ gold: NullType, standard: NullType });\n\n/** A customer, and their tier. */\nconst Customer = StructType({ name: StringType, region: StringType, tier: Tier });\n\n/** Weekly demand by region: eight weeks, the first at index 0. */\nconst Forecast = StructType({ regions: DictType(StringType, StructType({ weekly: ArrayType(FloatType) })) });\n\n/** A part and the parts it is built from: a bill of materials. */\nconst Part = RecursiveType(self => StructType({ children: ArrayType(self), cost: FloatType, sku: StringType }));\n\n/** The demand model: units sold at a unit price in a region. */\nconst ModelInput = StructType({ price: FloatType, region: StringType });\n\nconst Model = FunctionType([ModelInput], FloatType);\n\n/** The orders, ids 1001–1040, in id order: the mock's forty, drawn from seed 875 (`Query Editor Spec.md` §6). */\nexport const orders = e3.input(\"orders\", ArrayType(Order), variant(\"value\", [\n { id: 1001n, customer_id: \"C01\", discount: some(0.1), total: 80.1, status: variant(\"shipped\", { date: new Date(\"2026-04-27T09:00:00.000Z\") }),\n lines: [{ price: 8.9, qty: 10n, sku: \"HNG-220\" }] },\n { id: 1002n, customer_id: \"C07\", discount: none, total: 1171.58, status: variant(\"shipped\", { date: new Date(\"2026-01-15T16:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 38n, sku: \"BLT-045\" }, { price: 46.0, qty: 24n, sku: \"PLT-310\" }, { price: 0.18, qty: 196n, sku: \"WSH-008\" }] },\n { id: 1003n, customer_id: \"C02\", discount: none, total: 453.0, status: variant(\"shipped\", { date: new Date(\"2026-04-06T16:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 15n, sku: \"BRK-100\" }, { price: 8.9, qty: 30n, sku: \"HNG-220\" }] },\n { id: 1004n, customer_id: \"C05\", discount: some(0.15), total: 128.61, status: variant(\"pending\", null),\n lines: [{ price: 8.9, qty: 17n, sku: \"HNG-220\" }] },\n { id: 1005n, customer_id: \"C02\", discount: none, total: 520.24, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 6n, sku: \"PLT-310\" }, { price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 0.18, qty: 48n, sku: \"WSH-008\" }] },\n { id: 1006n, customer_id: \"C06\", discount: none, total: 210.8, status: variant(\"shipped\", { date: new Date(\"2026-06-03T14:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 17n, sku: \"BRK-100\" }] },\n { id: 1007n, customer_id: \"C05\", discount: some(0.1), total: 1162.92, status: variant(\"shipped\", { date: new Date(\"2026-04-06T09:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 184n, sku: \"SCR-012\" }, { price: 64.5, qty: 5n, sku: \"RAL-900\" }, { price: 46.0, qty: 7n, sku: \"PLT-310\" }, { price: 3.75, qty: 157n, sku: \"CLP-150\" }] },\n { id: 1008n, customer_id: \"C05\", discount: none, total: 1280.3, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 143n, sku: \"BLT-045\" }, { price: 64.5, qty: 10n, sku: \"RAL-900\" }, { price: 3.75, qty: 137n, sku: \"CLP-150\" }] },\n { id: 1009n, customer_id: \"C04\", discount: some(0.05), total: 409.51, status: variant(\"shipped\", { date: new Date(\"2025-11-18T09:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 6n, sku: \"RAL-900\" }, { price: 0.18, qty: 211n, sku: \"WSH-008\" }, { price: 0.32, qty: 19n, sku: \"SCR-012\" }] },\n { id: 1010n, customer_id: \"C05\", discount: some(0.05), total: 142.23, status: variant(\"shipped\", { date: new Date(\"2025-10-14T12:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 189n, sku: \"WSH-008\" }, { price: 8.9, qty: 13n, sku: \"HNG-220\" }] },\n { id: 1011n, customer_id: \"C08\", discount: none, total: 1027.4, status: variant(\"pending\", null),\n lines: [{ price: 8.9, qty: 29n, sku: \"HNG-220\" }, { price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 0.85, qty: 298n, sku: \"BLT-045\" }] },\n { id: 1012n, customer_id: \"C02\", discount: none, total: 1109.6, status: variant(\"shipped\", { date: new Date(\"2026-04-01T08:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 46.0, qty: 19n, sku: \"PLT-310\" }] },\n { id: 1013n, customer_id: \"C08\", discount: some(0.05), total: 311.37, status: variant(\"shipped\", { date: new Date(\"2026-04-27T10:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 4n, sku: \"RAL-900\" }, { price: 0.32, qty: 218n, sku: \"SCR-012\" }] },\n { id: 1014n, customer_id: \"C07\", discount: none, total: 1765.97, status: variant(\"shipped\", { date: new Date(\"2026-03-09T08:00:00.000Z\") }),\n lines: [{ price: 46.0, qty: 30n, sku: \"PLT-310\" }, { price: 0.18, qty: 254n, sku: \"WSH-008\" }, { price: 0.85, qty: 269n, sku: \"BLT-045\" }, { price: 12.4, qty: 9n, sku: \"BRK-100\" }] },\n { id: 1015n, customer_id: \"C03\", discount: none, total: 3646.84, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 19n, sku: \"PLT-310\" }, { price: 64.5, qty: 26n, sku: \"RAL-900\" }, { price: 3.75, qty: 276n, sku: \"CLP-150\" }, { price: 0.18, qty: 338n, sku: \"WSH-008\" }] },\n { id: 1016n, customer_id: \"C02\", discount: none, total: 1882.9, status: variant(\"pending\", null),\n lines: [{ price: 12.4, qty: 1n, sku: \"BRK-100\" }, { price: 64.5, qty: 29n, sku: \"RAL-900\" }] },\n { id: 1017n, customer_id: \"C02\", discount: some(0.05), total: 2005.59, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 89n, sku: \"BLT-045\" }, { price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 64.5, qty: 23n, sku: \"RAL-900\" }] },\n { id: 1018n, customer_id: \"C03\", discount: none, total: 1372.99, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 26n, sku: \"PLT-310\" }, { price: 0.18, qty: 138n, sku: \"WSH-008\" }, { price: 0.85, qty: 179n, sku: \"BLT-045\" }] },\n { id: 1019n, customer_id: \"C05\", discount: none, total: 684.65, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 301n, sku: \"BLT-045\" }, { price: 12.4, qty: 26n, sku: \"BRK-100\" }, { price: 8.9, qty: 8n, sku: \"HNG-220\" }, { price: 0.32, qty: 110n, sku: \"SCR-012\" }] },\n { id: 1020n, customer_id: \"C01\", discount: some(0.05), total: 297.01, status: variant(\"shipped\", { date: new Date(\"2026-02-06T11:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 75n, sku: \"SCR-012\" }, { price: 0.18, qty: 88n, sku: \"WSH-008\" }, { price: 12.4, qty: 22n, sku: \"BRK-100\" }] },\n { id: 1021n, customer_id: \"C07\", discount: none, total: 1225.5, status: variant(\"shipped\", { date: new Date(\"2026-05-18T14:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 19n, sku: \"RAL-900\" }] },\n { id: 1022n, customer_id: \"C07\", discount: some(0.15), total: 36.26, status: variant(\"shipped\", { date: new Date(\"2026-01-03T10:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 237n, sku: \"WSH-008\" }] },\n { id: 1023n, customer_id: \"C01\", discount: some(0.1), total: 1352.32, status: variant(\"shipped\", { date: new Date(\"2026-01-08T12:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 32n, sku: \"SCR-012\" }, { price: 8.9, qty: 13n, sku: \"HNG-220\" }, { price: 0.18, qty: 123n, sku: \"WSH-008\" }, { price: 64.5, qty: 21n, sku: \"RAL-900\" }] },\n { id: 1024n, customer_id: \"C05\", discount: some(0.05), total: 623.52, status: variant(\"cancelled\", { reason: \"Customer request\" }),\n lines: [{ price: 46.0, qty: 4n, sku: \"PLT-310\" }, { price: 0.18, qty: 209n, sku: \"WSH-008\" }, { price: 0.32, qty: 351n, sku: \"SCR-012\" }, { price: 12.4, qty: 26n, sku: \"BRK-100\" }] },\n { id: 1025n, customer_id: \"C01\", discount: some(0.1), total: 2577.23, status: variant(\"cancelled\", { reason: \"Payment failed\" }),\n lines: [{ price: 0.18, qty: 213n, sku: \"WSH-008\" }, { price: 64.5, qty: 27n, sku: \"RAL-900\" }, { price: 3.75, qty: 289n, sku: \"CLP-150\" }] },\n { id: 1026n, customer_id: \"C03\", discount: none, total: 1913.4, status: variant(\"shipped\", { date: new Date(\"2026-03-07T08:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 354n, sku: \"BLT-045\" }, { price: 64.5, qty: 25n, sku: \"RAL-900\" }] },\n { id: 1027n, customer_id: \"C08\", discount: none, total: 808.19, status: variant(\"shipped\", { date: new Date(\"2026-06-26T10:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 3n, sku: \"BLT-045\" }, { price: 8.9, qty: 25n, sku: \"HNG-220\" }, { price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 0.18, qty: 373n, sku: \"WSH-008\" }] },\n { id: 1028n, customer_id: \"C06\", discount: none, total: 173.45, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 47n, sku: \"BLT-045\" }, { price: 8.9, qty: 15n, sku: \"HNG-220\" }] },\n { id: 1029n, customer_id: \"C05\", discount: none, total: 64.96, status: variant(\"shipped\", { date: new Date(\"2026-03-19T16:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 203n, sku: \"SCR-012\" }] },\n { id: 1030n, customer_id: \"C03\", discount: none, total: 913.36, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 380n, sku: \"BLT-045\" }, { price: 3.75, qty: 4n, sku: \"CLP-150\" }, { price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 0.32, qty: 73n, sku: \"SCR-012\" }] },\n { id: 1031n, customer_id: \"C06\", discount: none, total: 1537.52, status: variant(\"shipped\", { date: new Date(\"2026-05-31T13:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 264n, sku: \"WSH-008\" }, { price: 12.4, qty: 20n, sku: \"BRK-100\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1032n, customer_id: \"C02\", discount: none, total: 1892.81, status: variant(\"cancelled\", { reason: \"Out of stock\" }),\n lines: [{ price: 46.0, qty: 26n, sku: \"PLT-310\" }, { price: 3.75, qty: 183n, sku: \"CLP-150\" }, { price: 0.32, qty: 33n, sku: \"SCR-012\" }] },\n { id: 1033n, customer_id: \"C01\", discount: none, total: 1834.15, status: variant(\"pending\", null),\n lines: [{ price: 64.5, qty: 27n, sku: \"RAL-900\" }, { price: 0.85, qty: 109n, sku: \"BLT-045\" }] },\n { id: 1034n, customer_id: \"C03\", discount: none, total: 323.06, status: variant(\"pending\", null),\n lines: [{ price: 0.32, qty: 140n, sku: \"SCR-012\" }, { price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 0.18, qty: 237n, sku: \"WSH-008\" }] },\n { id: 1035n, customer_id: \"C06\", discount: none, total: 2381.61, status: variant(\"shipped\", { date: new Date(\"2026-06-01T14:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 292n, sku: \"WSH-008\" }, { price: 3.75, qty: 279n, sku: \"CLP-150\" }, { price: 0.85, qty: 48n, sku: \"BLT-045\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1036n, customer_id: \"C01\", discount: some(0.05), total: 1041.68, status: variant(\"shipped\", { date: new Date(\"2026-05-26T13:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 17n, sku: \"RAL-900\" }] },\n { id: 1037n, customer_id: \"C08\", discount: none, total: 774.5, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 8.9, qty: 25n, sku: \"HNG-220\" }] },\n { id: 1038n, customer_id: \"C01\", discount: none, total: 1758.0, status: variant(\"shipped\", { date: new Date(\"2025-10-28T08:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1039n, customer_id: \"C06\", discount: none, total: 471.06, status: variant(\"shipped\", { date: new Date(\"2026-04-04T13:00:00.000Z\") }),\n lines: [{ price: 8.9, qty: 15n, sku: \"HNG-220\" }, { price: 0.18, qty: 222n, sku: \"WSH-008\" }, { price: 12.4, qty: 24n, sku: \"BRK-100\" }] },\n { id: 1040n, customer_id: \"C02\", discount: none, total: 884.1, status: variant(\"shipped\", { date: new Date(\"2025-12-08T14:00:00.000Z\") }),\n lines: [{ price: 46.0, qty: 14n, sku: \"PLT-310\" }, { price: 8.9, qty: 18n, sku: \"HNG-220\" }, { price: 0.85, qty: 94n, sku: \"BLT-045\" }] },\n]));\n\n/** The customers, by id. */\nexport const customers = e3.input(\"customers\", DictType(StringType, Customer), variant(\"value\", new SortedMap([\n [\"C01\", { name: \"Harbour Foods\", region: \"NSW\", tier: variant(\"gold\", null) }],\n [\"C02\", { name: \"Coastline Retail\", region: \"NSW\", tier: variant(\"standard\", null) }],\n [\"C03\", { name: \"Ridge Grocers\", region: \"VIC\", tier: variant(\"gold\", null) }],\n [\"C04\", { name: \"Southbank Market\", region: \"VIC\", tier: variant(\"standard\", null) }],\n [\"C05\", { name: \"Sunfield Traders\", region: \"QLD\", tier: variant(\"standard\", null) }],\n [\"C06\", { name: \"Northgate Supply\", region: \"QLD\", tier: variant(\"gold\", null) }],\n [\"C07\", { name: \"Westend Provisions\", region: \"WA\", tier: variant(\"standard\", null) }],\n [\"C08\", { name: \"Ironbark Stores\", region: \"SA\", tier: variant(\"standard\", null) }],\n], compareFor(StringType))));\n\n/** Weekly demand by region: eight weeks of `base × (0.9 + 0.03w + 0.01i)`, to one place, for the region at index i of NSW, VIC, QLD, WA, SA. */\nexport const forecast = e3.input(\"forecast\", Forecast, variant(\"value\", {\n regions: new SortedMap([\n [\"NSW\", { weekly: [1080.0, 1116.0, 1152.0, 1188.0, 1224.0, 1260.0, 1296.0, 1332.0] }],\n [\"QLD\", { weekly: [791.2, 817.0, 842.8, 868.6, 894.4, 920.2, 946.0, 971.8] }],\n [\"SA\", { weekly: [385.4, 397.7, 410.0, 422.3, 434.6, 446.9, 459.2, 471.5] }],\n [\"VIC\", { weekly: [955.5, 987.0, 1018.5, 1050.0, 1081.5, 1113.0, 1144.5, 1176.0] }],\n [\"WA\", { weekly: [502.2, 518.4, 534.6, 550.8, 567.0, 583.2, 599.4, 615.6] }],\n ], compareFor(StringType)),\n}));\n\n/** The demand model, `round₂(base[region] × (price / 10)^−1.4)`: the units sold at a unit price in a region. */\nconst demandModel = East.function([ModelInput], FloatType, ($, input) => {\n const base = $.const(new SortedMap([[\"NSW\", 1200.0], [\"QLD\", 860.0], [\"SA\", 410.0], [\"VIC\", 1050.0], [\"WA\", 540.0]], compareFor(StringType)), DictType(StringType, FloatType));\n // A region the model does not know has a base of 300.\n const demand = base.get(input.region, () => 300.0).multiply(input.price.divide(10.0).pow(-1.4));\n const cents = $.const(demand.multiply(100.0).add(0.5));\n return cents.subtract(cents.remainder(1.0)).divide(100.0);\n});\n\n/** The demand model as data: an East function every runtime can call, which a query tries over a range. */\nexport const model = e3.input(\"model\", Model, variant(\"value\", East.compile(demandModel, [])));\n\n/** The bill of materials for PUMP-A. */\nexport const bom = e3.input(\"bom\", Part, variant(\"value\", {\n sku: \"PUMP-A\", cost: 42.0, children: [\n { sku: \"MOTOR-1\", cost: 120.0, children: [\n { sku: \"ROTOR-1\", cost: 18.5, children: [] }, { sku: \"STATOR-1\", cost: 22.0, children: [] }, { sku: \"BRG-6203\", cost: 3.2, children: [] },\n ] },\n { sku: \"HOUSING-2\", cost: 35.0, children: [{ sku: \"GASKET-9\", cost: 1.1, children: [] }, { sku: \"BOLT-M8\", cost: 0.4, children: [] }] },\n { sku: \"IMPELLER-3\", cost: 27.5, children: [] },\n { sku: \"SEAL-KIT\", cost: 6.8, children: [{ sku: \"ORING-12\", cost: 0.3, children: [] }, { sku: \"ORING-18\", cost: 0.35, children: [] }] },\n ],\n}));\n\n/**\n * The saved queries record: the mock's seven (`Query Editor Spec.md` §6),\n * each its canonical jq — what the builder's steps print — checked against the\n * data sources the builders bind when the package builds, and described where\n * the mock describes it; the rest describe themselves.\n */\nexport const queries = e3.record(\"queries\", Query.Types.Saved, {\n initial: Query.value({ orders, customers, forecast, model, bom }, [\n {\n name: \"Top shipped orders, 2026\",\n jq: `.customers as $customers\n | .orders\n | map(select(.status.type == \"shipped\") | select(.total >= 100 and (.status.value.date | year) == 2026))\n | map(. + {name: $customers[.customer_id].name, region: $customers[.customer_id].region})\n | map({order: .id, customer: .name, region, total, shipped: .status.value.date})\n | sort_by(-.total)\n | .[:10]`,\n savedAt: new Date(\"2026-10-01T09:00:00Z\"),\n },\n {\n name: \"Revenue by region\",\n jq: `.customers as $customers\n | .orders\n | map(select(.status.type == \"shipped\") | select(.total >= 100 and (.status.value.date | year) == 2026))\n | map(. + {region: $customers[.customer_id].region})\n | group_by(.region)\n | map({region: .[0].region, revenue: map(.total) | add, orders: length})\n | sort_by(-.revenue)\n | .[:3]`,\n description: \"Top 3 regions by shipped revenue in 2026, from orders of $100 or more.\",\n savedAt: new Date(\"2026-09-29T09:00:00Z\"),\n },\n {\n name: \"Shipped revenue by month\",\n jq: `.orders\n | map(select(.status.type == \"shipped\"))\n | map(. + {ship_month: .status.value.date | strftime(\"%Y-%m\")})\n | group_by(.ship_month)\n | map({ship_month: .[0].ship_month, revenue: map(.total) | add, orders: length})\n | sort_by(.ship_month)`,\n savedAt: new Date(\"2026-09-12T09:00:00Z\"),\n },\n {\n name: \"Large orders with no discount\",\n jq: `.orders\n | map(select(.total >= 1000 and .discount == null))\n | map({id, customer_id, total, status})\n | sort_by(-.total)`,\n savedAt: new Date(\"2026-09-03T09:00:00Z\"),\n },\n {\n name: \"Units by SKU\",\n jq: `.orders\n | [.[] | . as $order | .lines[] | . + {order_id: $order.id}]\n | group_by(.sku)\n | map({sku: .[0].sku, units: map(.qty) | add, orders: map(.order_id) | unique | length})\n | sort_by(-.units)`,\n savedAt: new Date(\"2026-08-28T09:00:00Z\"),\n },\n {\n name: \"Pump parts cost\",\n jq: `.bom\n | [recurse(.children[]) | {cost, sku}]\n | {total_cost: map(.cost) | add, parts: length, dearest: map(.cost) | max}`,\n description: \"Total cost, part count and dearest part in the PUMP-A bill of materials.\",\n savedAt: new Date(\"2026-08-20T09:00:00Z\"),\n },\n {\n name: \"Demand at $10–$12, NSW\",\n jq: `.model\n | [range(10.0; 12.0 + 0.5 / 2; 0.5) as $price | {price: $price, demand: call(.; {price: $price, region: \"NSW\"})}]`,\n description: \"Modelled demand in NSW at prices from $10 to $12, in $0.50 steps.\",\n savedAt: new Date(\"2026-08-14T09:00:00Z\"),\n },\n ]),\n mutations: (mutation) => ({\n // The record's one write.\n patch: mutation.patch(),\n }),\n});\n\nEast.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const saved = $.let(Record.bind(queries));\n const orderRows = $.let(Data.bind(orders));\n const customerRows = $.let(Data.bind(customers));\n const weekly = $.let(Data.bind(forecast));\n const demand = $.let(Data.bind(model));\n const parts = $.let(Data.bind(bom));\n return (\n <Box width=\"390px\" maxWidth=\"100%\" height=\"760px\">\n <Query.Builder queries={saved} query=\"Top shipped orders, 2026\" id=\"topMobile\"\n datasets={{ orders: orderRows, customers: customerRows, forecast: weekly, model: demand, bom: parts }} />\n </Box>\n );\n }}</Reactive>\n ))"
45491
+ "source": "// The same builder open on Top shipped orders, 2026 in a phone's 390-wide frame: the toolbar over its second row — the history at 44px — the results the frame's whole width, and the Query tab a drawer up from the strip on the bottom edge\n// inputs: []\n/** One line of an order: a SKU, its unit price and the quantity ordered. */\nconst Line = StructType({ price: FloatType, qty: IntegerType, sku: StringType });\n\n/** Where an order stands: cancelled for a reason, pending, or shipped on a date. */\nconst Status = VariantType({ cancelled: StructType({ reason: StringType }), pending: NullType, shipped: StructType({ date: DateTimeType }) });\n\n/** An order: `discount` is the fraction taken off, when there is one, and `total` the lines' gross less it, to the cent. */\nconst Order = StructType({\n customer_id: StringType, discount: OptionType(FloatType), id: IntegerType, lines: ArrayType(Line), status: Status, total: FloatType,\n});\n\n/** A customer's tier. */\nconst Tier = VariantType({ gold: NullType, standard: NullType });\n\n/** A customer, and their tier. */\nconst Customer = StructType({ name: StringType, region: StringType, tier: Tier });\n\n/** Weekly demand by region: eight weeks, the first at index 0. */\nconst Forecast = StructType({ regions: DictType(StringType, StructType({ weekly: ArrayType(FloatType) })) });\n\n/** A part and the parts it is built from: a bill of materials. */\nconst Part = RecursiveType(self => StructType({ children: ArrayType(self), cost: FloatType, sku: StringType }));\n\n/** The demand model: units sold at a unit price in a region. */\nconst ModelInput = StructType({ price: FloatType, region: StringType });\n\nconst Model = FunctionType([ModelInput], FloatType);\n\n/** The orders, ids 1001–1040, in id order: the mock's forty, drawn from seed 875 (`Query Editor Spec.md` §6). */\nexport const orders = e3.input(\"orders\", ArrayType(Order), variant(\"value\", [\n { id: 1001n, customer_id: \"C01\", discount: some(0.1), total: 80.1, status: variant(\"shipped\", { date: new Date(\"2026-04-27T09:00:00.000Z\") }),\n lines: [{ price: 8.9, qty: 10n, sku: \"HNG-220\" }] },\n { id: 1002n, customer_id: \"C07\", discount: none, total: 1171.58, status: variant(\"shipped\", { date: new Date(\"2026-01-15T16:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 38n, sku: \"BLT-045\" }, { price: 46.0, qty: 24n, sku: \"PLT-310\" }, { price: 0.18, qty: 196n, sku: \"WSH-008\" }] },\n { id: 1003n, customer_id: \"C02\", discount: none, total: 453.0, status: variant(\"shipped\", { date: new Date(\"2026-04-06T16:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 15n, sku: \"BRK-100\" }, { price: 8.9, qty: 30n, sku: \"HNG-220\" }] },\n { id: 1004n, customer_id: \"C05\", discount: some(0.15), total: 128.61, status: variant(\"pending\", null),\n lines: [{ price: 8.9, qty: 17n, sku: \"HNG-220\" }] },\n { id: 1005n, customer_id: \"C02\", discount: none, total: 520.24, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 6n, sku: \"PLT-310\" }, { price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 0.18, qty: 48n, sku: \"WSH-008\" }] },\n { id: 1006n, customer_id: \"C06\", discount: none, total: 210.8, status: variant(\"shipped\", { date: new Date(\"2026-06-03T14:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 17n, sku: \"BRK-100\" }] },\n { id: 1007n, customer_id: \"C05\", discount: some(0.1), total: 1162.92, status: variant(\"shipped\", { date: new Date(\"2026-04-06T09:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 184n, sku: \"SCR-012\" }, { price: 64.5, qty: 5n, sku: \"RAL-900\" }, { price: 46.0, qty: 7n, sku: \"PLT-310\" }, { price: 3.75, qty: 157n, sku: \"CLP-150\" }] },\n { id: 1008n, customer_id: \"C05\", discount: none, total: 1280.3, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 143n, sku: \"BLT-045\" }, { price: 64.5, qty: 10n, sku: \"RAL-900\" }, { price: 3.75, qty: 137n, sku: \"CLP-150\" }] },\n { id: 1009n, customer_id: \"C04\", discount: some(0.05), total: 409.51, status: variant(\"shipped\", { date: new Date(\"2025-11-18T09:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 6n, sku: \"RAL-900\" }, { price: 0.18, qty: 211n, sku: \"WSH-008\" }, { price: 0.32, qty: 19n, sku: \"SCR-012\" }] },\n { id: 1010n, customer_id: \"C05\", discount: some(0.05), total: 142.23, status: variant(\"shipped\", { date: new Date(\"2025-10-14T12:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 189n, sku: \"WSH-008\" }, { price: 8.9, qty: 13n, sku: \"HNG-220\" }] },\n { id: 1011n, customer_id: \"C08\", discount: none, total: 1027.4, status: variant(\"pending\", null),\n lines: [{ price: 8.9, qty: 29n, sku: \"HNG-220\" }, { price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 0.85, qty: 298n, sku: \"BLT-045\" }] },\n { id: 1012n, customer_id: \"C02\", discount: none, total: 1109.6, status: variant(\"shipped\", { date: new Date(\"2026-04-01T08:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 46.0, qty: 19n, sku: \"PLT-310\" }] },\n { id: 1013n, customer_id: \"C08\", discount: some(0.05), total: 311.37, status: variant(\"shipped\", { date: new Date(\"2026-04-27T10:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 4n, sku: \"RAL-900\" }, { price: 0.32, qty: 218n, sku: \"SCR-012\" }] },\n { id: 1014n, customer_id: \"C07\", discount: none, total: 1765.97, status: variant(\"shipped\", { date: new Date(\"2026-03-09T08:00:00.000Z\") }),\n lines: [{ price: 46.0, qty: 30n, sku: \"PLT-310\" }, { price: 0.18, qty: 254n, sku: \"WSH-008\" }, { price: 0.85, qty: 269n, sku: \"BLT-045\" }, { price: 12.4, qty: 9n, sku: \"BRK-100\" }] },\n { id: 1015n, customer_id: \"C03\", discount: none, total: 3646.84, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 19n, sku: \"PLT-310\" }, { price: 64.5, qty: 26n, sku: \"RAL-900\" }, { price: 3.75, qty: 276n, sku: \"CLP-150\" }, { price: 0.18, qty: 338n, sku: \"WSH-008\" }] },\n { id: 1016n, customer_id: \"C02\", discount: none, total: 1882.9, status: variant(\"pending\", null),\n lines: [{ price: 12.4, qty: 1n, sku: \"BRK-100\" }, { price: 64.5, qty: 29n, sku: \"RAL-900\" }] },\n { id: 1017n, customer_id: \"C02\", discount: some(0.05), total: 2005.59, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 89n, sku: \"BLT-045\" }, { price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 64.5, qty: 23n, sku: \"RAL-900\" }] },\n { id: 1018n, customer_id: \"C03\", discount: none, total: 1372.99, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 26n, sku: \"PLT-310\" }, { price: 0.18, qty: 138n, sku: \"WSH-008\" }, { price: 0.85, qty: 179n, sku: \"BLT-045\" }] },\n { id: 1019n, customer_id: \"C05\", discount: none, total: 684.65, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 301n, sku: \"BLT-045\" }, { price: 12.4, qty: 26n, sku: \"BRK-100\" }, { price: 8.9, qty: 8n, sku: \"HNG-220\" }, { price: 0.32, qty: 110n, sku: \"SCR-012\" }] },\n { id: 1020n, customer_id: \"C01\", discount: some(0.05), total: 297.01, status: variant(\"shipped\", { date: new Date(\"2026-02-06T11:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 75n, sku: \"SCR-012\" }, { price: 0.18, qty: 88n, sku: \"WSH-008\" }, { price: 12.4, qty: 22n, sku: \"BRK-100\" }] },\n { id: 1021n, customer_id: \"C07\", discount: none, total: 1225.5, status: variant(\"shipped\", { date: new Date(\"2026-05-18T14:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 19n, sku: \"RAL-900\" }] },\n { id: 1022n, customer_id: \"C07\", discount: some(0.15), total: 36.26, status: variant(\"shipped\", { date: new Date(\"2026-01-03T10:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 237n, sku: \"WSH-008\" }] },\n { id: 1023n, customer_id: \"C01\", discount: some(0.1), total: 1352.32, status: variant(\"shipped\", { date: new Date(\"2026-01-08T12:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 32n, sku: \"SCR-012\" }, { price: 8.9, qty: 13n, sku: \"HNG-220\" }, { price: 0.18, qty: 123n, sku: \"WSH-008\" }, { price: 64.5, qty: 21n, sku: \"RAL-900\" }] },\n { id: 1024n, customer_id: \"C05\", discount: some(0.05), total: 623.52, status: variant(\"cancelled\", { reason: \"Customer request\" }),\n lines: [{ price: 46.0, qty: 4n, sku: \"PLT-310\" }, { price: 0.18, qty: 209n, sku: \"WSH-008\" }, { price: 0.32, qty: 351n, sku: \"SCR-012\" }, { price: 12.4, qty: 26n, sku: \"BRK-100\" }] },\n { id: 1025n, customer_id: \"C01\", discount: some(0.1), total: 2577.23, status: variant(\"cancelled\", { reason: \"Payment failed\" }),\n lines: [{ price: 0.18, qty: 213n, sku: \"WSH-008\" }, { price: 64.5, qty: 27n, sku: \"RAL-900\" }, { price: 3.75, qty: 289n, sku: \"CLP-150\" }] },\n { id: 1026n, customer_id: \"C03\", discount: none, total: 1913.4, status: variant(\"shipped\", { date: new Date(\"2026-03-07T08:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 354n, sku: \"BLT-045\" }, { price: 64.5, qty: 25n, sku: \"RAL-900\" }] },\n { id: 1027n, customer_id: \"C08\", discount: none, total: 808.19, status: variant(\"shipped\", { date: new Date(\"2026-06-26T10:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 3n, sku: \"BLT-045\" }, { price: 8.9, qty: 25n, sku: \"HNG-220\" }, { price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 0.18, qty: 373n, sku: \"WSH-008\" }] },\n { id: 1028n, customer_id: \"C06\", discount: none, total: 173.45, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 47n, sku: \"BLT-045\" }, { price: 8.9, qty: 15n, sku: \"HNG-220\" }] },\n { id: 1029n, customer_id: \"C05\", discount: none, total: 64.96, status: variant(\"shipped\", { date: new Date(\"2026-03-19T16:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 203n, sku: \"SCR-012\" }] },\n { id: 1030n, customer_id: \"C03\", discount: none, total: 913.36, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 380n, sku: \"BLT-045\" }, { price: 3.75, qty: 4n, sku: \"CLP-150\" }, { price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 0.32, qty: 73n, sku: \"SCR-012\" }] },\n { id: 1031n, customer_id: \"C06\", discount: none, total: 1537.52, status: variant(\"shipped\", { date: new Date(\"2026-05-31T13:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 264n, sku: \"WSH-008\" }, { price: 12.4, qty: 20n, sku: \"BRK-100\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1032n, customer_id: \"C02\", discount: none, total: 1892.81, status: variant(\"cancelled\", { reason: \"Out of stock\" }),\n lines: [{ price: 46.0, qty: 26n, sku: \"PLT-310\" }, { price: 3.75, qty: 183n, sku: \"CLP-150\" }, { price: 0.32, qty: 33n, sku: \"SCR-012\" }] },\n { id: 1033n, customer_id: \"C01\", discount: none, total: 1834.15, status: variant(\"pending\", null),\n lines: [{ price: 64.5, qty: 27n, sku: \"RAL-900\" }, { price: 0.85, qty: 109n, sku: \"BLT-045\" }] },\n { id: 1034n, customer_id: \"C03\", discount: none, total: 323.06, status: variant(\"pending\", null),\n lines: [{ price: 0.32, qty: 140n, sku: \"SCR-012\" }, { price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 0.18, qty: 237n, sku: \"WSH-008\" }] },\n { id: 1035n, customer_id: \"C06\", discount: none, total: 2381.61, status: variant(\"shipped\", { date: new Date(\"2026-06-01T14:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 292n, sku: \"WSH-008\" }, { price: 3.75, qty: 279n, sku: \"CLP-150\" }, { price: 0.85, qty: 48n, sku: \"BLT-045\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1036n, customer_id: \"C01\", discount: some(0.05), total: 1041.68, status: variant(\"shipped\", { date: new Date(\"2026-05-26T13:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 17n, sku: \"RAL-900\" }] },\n { id: 1037n, customer_id: \"C08\", discount: none, total: 774.5, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 8.9, qty: 25n, sku: \"HNG-220\" }] },\n { id: 1038n, customer_id: \"C01\", discount: none, total: 1758.0, status: variant(\"shipped\", { date: new Date(\"2025-10-28T08:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1039n, customer_id: \"C06\", discount: none, total: 471.06, status: variant(\"shipped\", { date: new Date(\"2026-04-04T13:00:00.000Z\") }),\n lines: [{ price: 8.9, qty: 15n, sku: \"HNG-220\" }, { price: 0.18, qty: 222n, sku: \"WSH-008\" }, { price: 12.4, qty: 24n, sku: \"BRK-100\" }] },\n { id: 1040n, customer_id: \"C02\", discount: none, total: 884.1, status: variant(\"shipped\", { date: new Date(\"2025-12-08T14:00:00.000Z\") }),\n lines: [{ price: 46.0, qty: 14n, sku: \"PLT-310\" }, { price: 8.9, qty: 18n, sku: \"HNG-220\" }, { price: 0.85, qty: 94n, sku: \"BLT-045\" }] },\n]));\n\n/** The customers, by id. */\nexport const customers = e3.input(\"customers\", DictType(StringType, Customer), variant(\"value\", new SortedMap([\n [\"C01\", { name: \"Harbour Foods\", region: \"NSW\", tier: variant(\"gold\", null) }],\n [\"C02\", { name: \"Coastline Retail\", region: \"NSW\", tier: variant(\"standard\", null) }],\n [\"C03\", { name: \"Ridge Grocers\", region: \"VIC\", tier: variant(\"gold\", null) }],\n [\"C04\", { name: \"Southbank Market\", region: \"VIC\", tier: variant(\"standard\", null) }],\n [\"C05\", { name: \"Sunfield Traders\", region: \"QLD\", tier: variant(\"standard\", null) }],\n [\"C06\", { name: \"Northgate Supply\", region: \"QLD\", tier: variant(\"gold\", null) }],\n [\"C07\", { name: \"Westend Provisions\", region: \"WA\", tier: variant(\"standard\", null) }],\n [\"C08\", { name: \"Ironbark Stores\", region: \"SA\", tier: variant(\"standard\", null) }],\n], compareFor(StringType))));\n\n/** Weekly demand by region: eight weeks of `base × (0.9 + 0.03w + 0.01i)`, to one place, for the region at index i of NSW, VIC, QLD, WA, SA. */\nexport const forecast = e3.input(\"forecast\", Forecast, variant(\"value\", {\n regions: new SortedMap([\n [\"NSW\", { weekly: [1080.0, 1116.0, 1152.0, 1188.0, 1224.0, 1260.0, 1296.0, 1332.0] }],\n [\"QLD\", { weekly: [791.2, 817.0, 842.8, 868.6, 894.4, 920.2, 946.0, 971.8] }],\n [\"SA\", { weekly: [385.4, 397.7, 410.0, 422.3, 434.6, 446.9, 459.2, 471.5] }],\n [\"VIC\", { weekly: [955.5, 987.0, 1018.5, 1050.0, 1081.5, 1113.0, 1144.5, 1176.0] }],\n [\"WA\", { weekly: [502.2, 518.4, 534.6, 550.8, 567.0, 583.2, 599.4, 615.6] }],\n ], compareFor(StringType)),\n}));\n\n/** The demand model, `round₂(base[region] × (price / 10)^−1.4)`: the units sold at a unit price in a region. */\nconst demandModel = East.function([ModelInput], FloatType, ($, input) => {\n const base = $.const(new SortedMap([[\"NSW\", 1200.0], [\"QLD\", 860.0], [\"SA\", 410.0], [\"VIC\", 1050.0], [\"WA\", 540.0]], compareFor(StringType)), DictType(StringType, FloatType));\n // A region the model does not know has a base of 300.\n const demand = base.get(input.region, () => 300.0).multiply(input.price.divide(10.0).pow(-1.4));\n const cents = $.const(demand.multiply(100.0).add(0.5));\n return cents.subtract(cents.remainder(1.0)).divide(100.0);\n});\n\n/** The demand model as data: an East function every runtime can call, which a query tries over a range. */\nexport const model = e3.input(\"model\", Model, variant(\"value\", East.compile(demandModel, [])));\n\n/** The bill of materials for PUMP-A. */\nexport const bom = e3.input(\"bom\", Part, variant(\"value\", {\n sku: \"PUMP-A\", cost: 42.0, children: [\n { sku: \"MOTOR-1\", cost: 120.0, children: [\n { sku: \"ROTOR-1\", cost: 18.5, children: [] }, { sku: \"STATOR-1\", cost: 22.0, children: [] }, { sku: \"BRG-6203\", cost: 3.2, children: [] },\n ] },\n { sku: \"HOUSING-2\", cost: 35.0, children: [{ sku: \"GASKET-9\", cost: 1.1, children: [] }, { sku: \"BOLT-M8\", cost: 0.4, children: [] }] },\n { sku: \"IMPELLER-3\", cost: 27.5, children: [] },\n { sku: \"SEAL-KIT\", cost: 6.8, children: [{ sku: \"ORING-12\", cost: 0.3, children: [] }, { sku: \"ORING-18\", cost: 0.35, children: [] }] },\n ],\n}));\n\n/**\n * The saved queries record: the mock's seven (`Query Editor Spec.md` §6),\n * each its canonical jq — what the builder's steps print — checked against the\n * data sources the builders bind when the package builds, and described where\n * the mock describes it; the rest describe themselves.\n */\nexport const queries = e3.record(\"queries\", Query.Types.Saved, {\n initial: Query.value({ orders, customers, forecast, model, bom }, [\n {\n name: \"Top shipped orders, 2026\",\n jq: `.customers as $customers\n | .orders\n | map(select(.status.type == \"shipped\") | select(.total >= 100 and (.status.value.date | year) == 2026))\n | map(. + {name: $customers[.customer_id].name, region: $customers[.customer_id].region})\n | map({order: .id, customer: .name, region, total, shipped: .status.value.date})\n | sort_by(-.total)\n | .[:10]`,\n savedAt: new Date(\"2026-10-01T09:00:00Z\"),\n },\n {\n name: \"Revenue by region\",\n jq: `.customers as $customers\n | .orders\n | map(select(.status.type == \"shipped\") | select(.total >= 100 and (.status.value.date | year) == 2026))\n | map(. + {region: $customers[.customer_id].region})\n | group_by(.region)\n | map({region: .[0].region, revenue: map(.total) | add, orders: length})\n | sort_by(-.revenue)\n | .[:3]`,\n description: \"Top 3 regions by shipped revenue in 2026, from orders of $100 or more.\",\n savedAt: new Date(\"2026-09-29T09:00:00Z\"),\n },\n {\n name: \"Shipped revenue by month\",\n jq: `.orders\n | map(select(.status.type == \"shipped\"))\n | map(. + {ship_month: .status.value.date | strftime(\"%Y-%m\")})\n | group_by(.ship_month)\n | map({ship_month: .[0].ship_month, revenue: map(.total) | add, orders: length})\n | sort_by(.ship_month)`,\n savedAt: new Date(\"2026-09-12T09:00:00Z\"),\n },\n {\n name: \"Large orders with no discount\",\n jq: `.orders\n | map(select(.total >= 1000 and .discount == null))\n | map({id, customer_id, total, status})\n | sort_by(-.total)`,\n savedAt: new Date(\"2026-09-03T09:00:00Z\"),\n },\n {\n name: \"Units by SKU\",\n jq: `.orders\n | [.[] | . as $order | .lines[] | . + {order_id: $order.id}]\n | group_by(.sku)\n | map({sku: .[0].sku, units: map(.qty) | add, orders: map(.order_id) | unique | length})\n | sort_by(-.units)`,\n savedAt: new Date(\"2026-08-28T09:00:00Z\"),\n },\n {\n name: \"Pump parts cost\",\n jq: `.bom\n | [recurse(.children[]) | {cost, sku}]\n | {total_cost: map(.cost) | add, parts: length, dearest: map(.cost) | max}`,\n description: \"Total cost, part count and dearest part in the PUMP-A bill of materials.\",\n savedAt: new Date(\"2026-08-20T09:00:00Z\"),\n },\n {\n name: \"Demand at $10–$12, NSW\",\n jq: `.model\n | [range(10.0; 12.0 + 0.5 / 2; 0.5) as $price | {price: $price, demand: call(.; {price: $price, region: \"NSW\"})}]`,\n description: \"Modelled demand in NSW at prices from $10 to $12, in $0.50 steps.\",\n savedAt: new Date(\"2026-08-14T09:00:00Z\"),\n },\n ]),\n mutations: (mutation) => ({\n // The record's one write.\n patch: mutation.patch(),\n }),\n});\n\nEast.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const saved = $.let(Record.bind(queries));\n const orderRows = $.let(Data.bind(orders));\n const customerRows = $.let(Data.bind(customers));\n const weekly = $.let(Data.bind(forecast));\n const demand = $.let(Data.bind(model));\n const parts = $.let(Data.bind(bom));\n // The open query is the surface's: the builder shows it, and tells the surface when its own tabs ask for another.\n const open = $.let(State.bind([Query.Types.Open], \"ex.queryBuilderMobile.open\", Query.open.saved(\"Top shipped orders, 2026\")));\n const go = $.const(East.function([Query.Types.Open], NullType, ($2, next) => { $2(open.write(next)); }));\n return (\n <Box width=\"390px\" maxWidth=\"100%\" height=\"760px\">\n <Query.Builder queries={saved} query={open.read()} onOpen={go} id=\"topMobile\"\n datasets={{ orders: orderRows, customers: customerRows, forecast: weekly, model: demand, bom: parts }} />\n </Box>\n );\n }}</Reactive>\n ))"
45440
45492
  },
45441
45493
  {
45442
45494
  "id": "e3-ui:query.examples.tsx:queryBuilderBom",
@@ -45464,7 +45516,7 @@
45464
45516
  "languages": [
45465
45517
  "tsx"
45466
45518
  ],
45467
- "source": "// The same builder open on Pump parts cost: every part of the PUMP-A bill of materials, walked, then totalled — its cost, its part count and its dearest part, one value shown as a Value tree\n// inputs: []\n/** One line of an order: a SKU, its unit price and the quantity ordered. */\nconst Line = StructType({ price: FloatType, qty: IntegerType, sku: StringType });\n\n/** Where an order stands: cancelled for a reason, pending, or shipped on a date. */\nconst Status = VariantType({ cancelled: StructType({ reason: StringType }), pending: NullType, shipped: StructType({ date: DateTimeType }) });\n\n/** An order: `discount` is the fraction taken off, when there is one, and `total` the lines' gross less it, to the cent. */\nconst Order = StructType({\n customer_id: StringType, discount: OptionType(FloatType), id: IntegerType, lines: ArrayType(Line), status: Status, total: FloatType,\n});\n\n/** A customer's tier. */\nconst Tier = VariantType({ gold: NullType, standard: NullType });\n\n/** A customer, and their tier. */\nconst Customer = StructType({ name: StringType, region: StringType, tier: Tier });\n\n/** Weekly demand by region: eight weeks, the first at index 0. */\nconst Forecast = StructType({ regions: DictType(StringType, StructType({ weekly: ArrayType(FloatType) })) });\n\n/** A part and the parts it is built from: a bill of materials. */\nconst Part = RecursiveType(self => StructType({ children: ArrayType(self), cost: FloatType, sku: StringType }));\n\n/** The demand model: units sold at a unit price in a region. */\nconst ModelInput = StructType({ price: FloatType, region: StringType });\n\nconst Model = FunctionType([ModelInput], FloatType);\n\n/** The orders, ids 1001–1040, in id order: the mock's forty, drawn from seed 875 (`Query Editor Spec.md` §6). */\nexport const orders = e3.input(\"orders\", ArrayType(Order), variant(\"value\", [\n { id: 1001n, customer_id: \"C01\", discount: some(0.1), total: 80.1, status: variant(\"shipped\", { date: new Date(\"2026-04-27T09:00:00.000Z\") }),\n lines: [{ price: 8.9, qty: 10n, sku: \"HNG-220\" }] },\n { id: 1002n, customer_id: \"C07\", discount: none, total: 1171.58, status: variant(\"shipped\", { date: new Date(\"2026-01-15T16:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 38n, sku: \"BLT-045\" }, { price: 46.0, qty: 24n, sku: \"PLT-310\" }, { price: 0.18, qty: 196n, sku: \"WSH-008\" }] },\n { id: 1003n, customer_id: \"C02\", discount: none, total: 453.0, status: variant(\"shipped\", { date: new Date(\"2026-04-06T16:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 15n, sku: \"BRK-100\" }, { price: 8.9, qty: 30n, sku: \"HNG-220\" }] },\n { id: 1004n, customer_id: \"C05\", discount: some(0.15), total: 128.61, status: variant(\"pending\", null),\n lines: [{ price: 8.9, qty: 17n, sku: \"HNG-220\" }] },\n { id: 1005n, customer_id: \"C02\", discount: none, total: 520.24, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 6n, sku: \"PLT-310\" }, { price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 0.18, qty: 48n, sku: \"WSH-008\" }] },\n { id: 1006n, customer_id: \"C06\", discount: none, total: 210.8, status: variant(\"shipped\", { date: new Date(\"2026-06-03T14:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 17n, sku: \"BRK-100\" }] },\n { id: 1007n, customer_id: \"C05\", discount: some(0.1), total: 1162.92, status: variant(\"shipped\", { date: new Date(\"2026-04-06T09:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 184n, sku: \"SCR-012\" }, { price: 64.5, qty: 5n, sku: \"RAL-900\" }, { price: 46.0, qty: 7n, sku: \"PLT-310\" }, { price: 3.75, qty: 157n, sku: \"CLP-150\" }] },\n { id: 1008n, customer_id: \"C05\", discount: none, total: 1280.3, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 143n, sku: \"BLT-045\" }, { price: 64.5, qty: 10n, sku: \"RAL-900\" }, { price: 3.75, qty: 137n, sku: \"CLP-150\" }] },\n { id: 1009n, customer_id: \"C04\", discount: some(0.05), total: 409.51, status: variant(\"shipped\", { date: new Date(\"2025-11-18T09:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 6n, sku: \"RAL-900\" }, { price: 0.18, qty: 211n, sku: \"WSH-008\" }, { price: 0.32, qty: 19n, sku: \"SCR-012\" }] },\n { id: 1010n, customer_id: \"C05\", discount: some(0.05), total: 142.23, status: variant(\"shipped\", { date: new Date(\"2025-10-14T12:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 189n, sku: \"WSH-008\" }, { price: 8.9, qty: 13n, sku: \"HNG-220\" }] },\n { id: 1011n, customer_id: \"C08\", discount: none, total: 1027.4, status: variant(\"pending\", null),\n lines: [{ price: 8.9, qty: 29n, sku: \"HNG-220\" }, { price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 0.85, qty: 298n, sku: \"BLT-045\" }] },\n { id: 1012n, customer_id: \"C02\", discount: none, total: 1109.6, status: variant(\"shipped\", { date: new Date(\"2026-04-01T08:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 46.0, qty: 19n, sku: \"PLT-310\" }] },\n { id: 1013n, customer_id: \"C08\", discount: some(0.05), total: 311.37, status: variant(\"shipped\", { date: new Date(\"2026-04-27T10:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 4n, sku: \"RAL-900\" }, { price: 0.32, qty: 218n, sku: \"SCR-012\" }] },\n { id: 1014n, customer_id: \"C07\", discount: none, total: 1765.97, status: variant(\"shipped\", { date: new Date(\"2026-03-09T08:00:00.000Z\") }),\n lines: [{ price: 46.0, qty: 30n, sku: \"PLT-310\" }, { price: 0.18, qty: 254n, sku: \"WSH-008\" }, { price: 0.85, qty: 269n, sku: \"BLT-045\" }, { price: 12.4, qty: 9n, sku: \"BRK-100\" }] },\n { id: 1015n, customer_id: \"C03\", discount: none, total: 3646.84, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 19n, sku: \"PLT-310\" }, { price: 64.5, qty: 26n, sku: \"RAL-900\" }, { price: 3.75, qty: 276n, sku: \"CLP-150\" }, { price: 0.18, qty: 338n, sku: \"WSH-008\" }] },\n { id: 1016n, customer_id: \"C02\", discount: none, total: 1882.9, status: variant(\"pending\", null),\n lines: [{ price: 12.4, qty: 1n, sku: \"BRK-100\" }, { price: 64.5, qty: 29n, sku: \"RAL-900\" }] },\n { id: 1017n, customer_id: \"C02\", discount: some(0.05), total: 2005.59, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 89n, sku: \"BLT-045\" }, { price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 64.5, qty: 23n, sku: \"RAL-900\" }] },\n { id: 1018n, customer_id: \"C03\", discount: none, total: 1372.99, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 26n, sku: \"PLT-310\" }, { price: 0.18, qty: 138n, sku: \"WSH-008\" }, { price: 0.85, qty: 179n, sku: \"BLT-045\" }] },\n { id: 1019n, customer_id: \"C05\", discount: none, total: 684.65, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 301n, sku: \"BLT-045\" }, { price: 12.4, qty: 26n, sku: \"BRK-100\" }, { price: 8.9, qty: 8n, sku: \"HNG-220\" }, { price: 0.32, qty: 110n, sku: \"SCR-012\" }] },\n { id: 1020n, customer_id: \"C01\", discount: some(0.05), total: 297.01, status: variant(\"shipped\", { date: new Date(\"2026-02-06T11:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 75n, sku: \"SCR-012\" }, { price: 0.18, qty: 88n, sku: \"WSH-008\" }, { price: 12.4, qty: 22n, sku: \"BRK-100\" }] },\n { id: 1021n, customer_id: \"C07\", discount: none, total: 1225.5, status: variant(\"shipped\", { date: new Date(\"2026-05-18T14:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 19n, sku: \"RAL-900\" }] },\n { id: 1022n, customer_id: \"C07\", discount: some(0.15), total: 36.26, status: variant(\"shipped\", { date: new Date(\"2026-01-03T10:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 237n, sku: \"WSH-008\" }] },\n { id: 1023n, customer_id: \"C01\", discount: some(0.1), total: 1352.32, status: variant(\"shipped\", { date: new Date(\"2026-01-08T12:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 32n, sku: \"SCR-012\" }, { price: 8.9, qty: 13n, sku: \"HNG-220\" }, { price: 0.18, qty: 123n, sku: \"WSH-008\" }, { price: 64.5, qty: 21n, sku: \"RAL-900\" }] },\n { id: 1024n, customer_id: \"C05\", discount: some(0.05), total: 623.52, status: variant(\"cancelled\", { reason: \"Customer request\" }),\n lines: [{ price: 46.0, qty: 4n, sku: \"PLT-310\" }, { price: 0.18, qty: 209n, sku: \"WSH-008\" }, { price: 0.32, qty: 351n, sku: \"SCR-012\" }, { price: 12.4, qty: 26n, sku: \"BRK-100\" }] },\n { id: 1025n, customer_id: \"C01\", discount: some(0.1), total: 2577.23, status: variant(\"cancelled\", { reason: \"Payment failed\" }),\n lines: [{ price: 0.18, qty: 213n, sku: \"WSH-008\" }, { price: 64.5, qty: 27n, sku: \"RAL-900\" }, { price: 3.75, qty: 289n, sku: \"CLP-150\" }] },\n { id: 1026n, customer_id: \"C03\", discount: none, total: 1913.4, status: variant(\"shipped\", { date: new Date(\"2026-03-07T08:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 354n, sku: \"BLT-045\" }, { price: 64.5, qty: 25n, sku: \"RAL-900\" }] },\n { id: 1027n, customer_id: \"C08\", discount: none, total: 808.19, status: variant(\"shipped\", { date: new Date(\"2026-06-26T10:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 3n, sku: \"BLT-045\" }, { price: 8.9, qty: 25n, sku: \"HNG-220\" }, { price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 0.18, qty: 373n, sku: \"WSH-008\" }] },\n { id: 1028n, customer_id: \"C06\", discount: none, total: 173.45, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 47n, sku: \"BLT-045\" }, { price: 8.9, qty: 15n, sku: \"HNG-220\" }] },\n { id: 1029n, customer_id: \"C05\", discount: none, total: 64.96, status: variant(\"shipped\", { date: new Date(\"2026-03-19T16:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 203n, sku: \"SCR-012\" }] },\n { id: 1030n, customer_id: \"C03\", discount: none, total: 913.36, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 380n, sku: \"BLT-045\" }, { price: 3.75, qty: 4n, sku: \"CLP-150\" }, { price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 0.32, qty: 73n, sku: \"SCR-012\" }] },\n { id: 1031n, customer_id: \"C06\", discount: none, total: 1537.52, status: variant(\"shipped\", { date: new Date(\"2026-05-31T13:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 264n, sku: \"WSH-008\" }, { price: 12.4, qty: 20n, sku: \"BRK-100\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1032n, customer_id: \"C02\", discount: none, total: 1892.81, status: variant(\"cancelled\", { reason: \"Out of stock\" }),\n lines: [{ price: 46.0, qty: 26n, sku: \"PLT-310\" }, { price: 3.75, qty: 183n, sku: \"CLP-150\" }, { price: 0.32, qty: 33n, sku: \"SCR-012\" }] },\n { id: 1033n, customer_id: \"C01\", discount: none, total: 1834.15, status: variant(\"pending\", null),\n lines: [{ price: 64.5, qty: 27n, sku: \"RAL-900\" }, { price: 0.85, qty: 109n, sku: \"BLT-045\" }] },\n { id: 1034n, customer_id: \"C03\", discount: none, total: 323.06, status: variant(\"pending\", null),\n lines: [{ price: 0.32, qty: 140n, sku: \"SCR-012\" }, { price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 0.18, qty: 237n, sku: \"WSH-008\" }] },\n { id: 1035n, customer_id: \"C06\", discount: none, total: 2381.61, status: variant(\"shipped\", { date: new Date(\"2026-06-01T14:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 292n, sku: \"WSH-008\" }, { price: 3.75, qty: 279n, sku: \"CLP-150\" }, { price: 0.85, qty: 48n, sku: \"BLT-045\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1036n, customer_id: \"C01\", discount: some(0.05), total: 1041.68, status: variant(\"shipped\", { date: new Date(\"2026-05-26T13:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 17n, sku: \"RAL-900\" }] },\n { id: 1037n, customer_id: \"C08\", discount: none, total: 774.5, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 8.9, qty: 25n, sku: \"HNG-220\" }] },\n { id: 1038n, customer_id: \"C01\", discount: none, total: 1758.0, status: variant(\"shipped\", { date: new Date(\"2025-10-28T08:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1039n, customer_id: \"C06\", discount: none, total: 471.06, status: variant(\"shipped\", { date: new Date(\"2026-04-04T13:00:00.000Z\") }),\n lines: [{ price: 8.9, qty: 15n, sku: \"HNG-220\" }, { price: 0.18, qty: 222n, sku: \"WSH-008\" }, { price: 12.4, qty: 24n, sku: \"BRK-100\" }] },\n { id: 1040n, customer_id: \"C02\", discount: none, total: 884.1, status: variant(\"shipped\", { date: new Date(\"2025-12-08T14:00:00.000Z\") }),\n lines: [{ price: 46.0, qty: 14n, sku: \"PLT-310\" }, { price: 8.9, qty: 18n, sku: \"HNG-220\" }, { price: 0.85, qty: 94n, sku: \"BLT-045\" }] },\n]));\n\n/** The customers, by id. */\nexport const customers = e3.input(\"customers\", DictType(StringType, Customer), variant(\"value\", new SortedMap([\n [\"C01\", { name: \"Harbour Foods\", region: \"NSW\", tier: variant(\"gold\", null) }],\n [\"C02\", { name: \"Coastline Retail\", region: \"NSW\", tier: variant(\"standard\", null) }],\n [\"C03\", { name: \"Ridge Grocers\", region: \"VIC\", tier: variant(\"gold\", null) }],\n [\"C04\", { name: \"Southbank Market\", region: \"VIC\", tier: variant(\"standard\", null) }],\n [\"C05\", { name: \"Sunfield Traders\", region: \"QLD\", tier: variant(\"standard\", null) }],\n [\"C06\", { name: \"Northgate Supply\", region: \"QLD\", tier: variant(\"gold\", null) }],\n [\"C07\", { name: \"Westend Provisions\", region: \"WA\", tier: variant(\"standard\", null) }],\n [\"C08\", { name: \"Ironbark Stores\", region: \"SA\", tier: variant(\"standard\", null) }],\n], compareFor(StringType))));\n\n/** Weekly demand by region: eight weeks of `base × (0.9 + 0.03w + 0.01i)`, to one place, for the region at index i of NSW, VIC, QLD, WA, SA. */\nexport const forecast = e3.input(\"forecast\", Forecast, variant(\"value\", {\n regions: new SortedMap([\n [\"NSW\", { weekly: [1080.0, 1116.0, 1152.0, 1188.0, 1224.0, 1260.0, 1296.0, 1332.0] }],\n [\"QLD\", { weekly: [791.2, 817.0, 842.8, 868.6, 894.4, 920.2, 946.0, 971.8] }],\n [\"SA\", { weekly: [385.4, 397.7, 410.0, 422.3, 434.6, 446.9, 459.2, 471.5] }],\n [\"VIC\", { weekly: [955.5, 987.0, 1018.5, 1050.0, 1081.5, 1113.0, 1144.5, 1176.0] }],\n [\"WA\", { weekly: [502.2, 518.4, 534.6, 550.8, 567.0, 583.2, 599.4, 615.6] }],\n ], compareFor(StringType)),\n}));\n\n/** The demand model, `round₂(base[region] × (price / 10)^−1.4)`: the units sold at a unit price in a region. */\nconst demandModel = East.function([ModelInput], FloatType, ($, input) => {\n const base = $.const(new SortedMap([[\"NSW\", 1200.0], [\"QLD\", 860.0], [\"SA\", 410.0], [\"VIC\", 1050.0], [\"WA\", 540.0]], compareFor(StringType)), DictType(StringType, FloatType));\n // A region the model does not know has a base of 300.\n const demand = base.get(input.region, () => 300.0).multiply(input.price.divide(10.0).pow(-1.4));\n const cents = $.const(demand.multiply(100.0).add(0.5));\n return cents.subtract(cents.remainder(1.0)).divide(100.0);\n});\n\n/** The demand model as data: an East function every runtime can call, which a query tries over a range. */\nexport const model = e3.input(\"model\", Model, variant(\"value\", East.compile(demandModel, [])));\n\n/** The bill of materials for PUMP-A. */\nexport const bom = e3.input(\"bom\", Part, variant(\"value\", {\n sku: \"PUMP-A\", cost: 42.0, children: [\n { sku: \"MOTOR-1\", cost: 120.0, children: [\n { sku: \"ROTOR-1\", cost: 18.5, children: [] }, { sku: \"STATOR-1\", cost: 22.0, children: [] }, { sku: \"BRG-6203\", cost: 3.2, children: [] },\n ] },\n { sku: \"HOUSING-2\", cost: 35.0, children: [{ sku: \"GASKET-9\", cost: 1.1, children: [] }, { sku: \"BOLT-M8\", cost: 0.4, children: [] }] },\n { sku: \"IMPELLER-3\", cost: 27.5, children: [] },\n { sku: \"SEAL-KIT\", cost: 6.8, children: [{ sku: \"ORING-12\", cost: 0.3, children: [] }, { sku: \"ORING-18\", cost: 0.35, children: [] }] },\n ],\n}));\n\n/**\n * The saved queries record: the mock's seven (`Query Editor Spec.md` §6),\n * each its canonical jq — what the builder's steps print — checked against the\n * data sources the builders bind when the package builds, and described where\n * the mock describes it; the rest describe themselves.\n */\nexport const queries = e3.record(\"queries\", Query.Types.Saved, {\n initial: Query.value({ orders, customers, forecast, model, bom }, [\n {\n name: \"Top shipped orders, 2026\",\n jq: `.customers as $customers\n | .orders\n | map(select(.status.type == \"shipped\") | select(.total >= 100 and (.status.value.date | year) == 2026))\n | map(. + {name: $customers[.customer_id].name, region: $customers[.customer_id].region})\n | map({order: .id, customer: .name, region, total, shipped: .status.value.date})\n | sort_by(-.total)\n | .[:10]`,\n savedAt: new Date(\"2026-10-01T09:00:00Z\"),\n },\n {\n name: \"Revenue by region\",\n jq: `.customers as $customers\n | .orders\n | map(select(.status.type == \"shipped\") | select(.total >= 100 and (.status.value.date | year) == 2026))\n | map(. + {region: $customers[.customer_id].region})\n | group_by(.region)\n | map({region: .[0].region, revenue: map(.total) | add, orders: length})\n | sort_by(-.revenue)\n | .[:3]`,\n description: \"Top 3 regions by shipped revenue in 2026, from orders of $100 or more.\",\n savedAt: new Date(\"2026-09-29T09:00:00Z\"),\n },\n {\n name: \"Shipped revenue by month\",\n jq: `.orders\n | map(select(.status.type == \"shipped\"))\n | map(. + {ship_month: .status.value.date | strftime(\"%Y-%m\")})\n | group_by(.ship_month)\n | map({ship_month: .[0].ship_month, revenue: map(.total) | add, orders: length})\n | sort_by(.ship_month)`,\n savedAt: new Date(\"2026-09-12T09:00:00Z\"),\n },\n {\n name: \"Large orders with no discount\",\n jq: `.orders\n | map(select(.total >= 1000 and .discount == null))\n | map({id, customer_id, total, status})\n | sort_by(-.total)`,\n savedAt: new Date(\"2026-09-03T09:00:00Z\"),\n },\n {\n name: \"Units by SKU\",\n jq: `.orders\n | [.[] | . as $order | .lines[] | . + {order_id: $order.id}]\n | group_by(.sku)\n | map({sku: .[0].sku, units: map(.qty) | add, orders: map(.order_id) | unique | length})\n | sort_by(-.units)`,\n savedAt: new Date(\"2026-08-28T09:00:00Z\"),\n },\n {\n name: \"Pump parts cost\",\n jq: `.bom\n | [recurse(.children[]) | {cost, sku}]\n | {total_cost: map(.cost) | add, parts: length, dearest: map(.cost) | max}`,\n description: \"Total cost, part count and dearest part in the PUMP-A bill of materials.\",\n savedAt: new Date(\"2026-08-20T09:00:00Z\"),\n },\n {\n name: \"Demand at $10–$12, NSW\",\n jq: `.model\n | [range(10.0; 12.0 + 0.5 / 2; 0.5) as $price | {price: $price, demand: call(.; {price: $price, region: \"NSW\"})}]`,\n description: \"Modelled demand in NSW at prices from $10 to $12, in $0.50 steps.\",\n savedAt: new Date(\"2026-08-14T09:00:00Z\"),\n },\n ]),\n mutations: (mutation) => ({\n // The record's one write.\n patch: mutation.patch(),\n }),\n});\n\nEast.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const saved = $.let(Record.bind(queries));\n const orderRows = $.let(Data.bind(orders));\n const customerRows = $.let(Data.bind(customers));\n const weekly = $.let(Data.bind(forecast));\n const demand = $.let(Data.bind(model));\n const parts = $.let(Data.bind(bom));\n return (\n <Box height=\"640px\">\n <Query.Builder queries={saved} query=\"Pump parts cost\" id=\"bom\"\n datasets={{ orders: orderRows, customers: customerRows, forecast: weekly, model: demand, bom: parts }} />\n </Box>\n );\n }}</Reactive>\n ))"
45519
+ "source": "// The same builder open on Pump parts cost: every part of the PUMP-A bill of materials, walked, then totalled — its cost, its part count and its dearest part, one value shown as a Value tree\n// inputs: []\n/** One line of an order: a SKU, its unit price and the quantity ordered. */\nconst Line = StructType({ price: FloatType, qty: IntegerType, sku: StringType });\n\n/** Where an order stands: cancelled for a reason, pending, or shipped on a date. */\nconst Status = VariantType({ cancelled: StructType({ reason: StringType }), pending: NullType, shipped: StructType({ date: DateTimeType }) });\n\n/** An order: `discount` is the fraction taken off, when there is one, and `total` the lines' gross less it, to the cent. */\nconst Order = StructType({\n customer_id: StringType, discount: OptionType(FloatType), id: IntegerType, lines: ArrayType(Line), status: Status, total: FloatType,\n});\n\n/** A customer's tier. */\nconst Tier = VariantType({ gold: NullType, standard: NullType });\n\n/** A customer, and their tier. */\nconst Customer = StructType({ name: StringType, region: StringType, tier: Tier });\n\n/** Weekly demand by region: eight weeks, the first at index 0. */\nconst Forecast = StructType({ regions: DictType(StringType, StructType({ weekly: ArrayType(FloatType) })) });\n\n/** A part and the parts it is built from: a bill of materials. */\nconst Part = RecursiveType(self => StructType({ children: ArrayType(self), cost: FloatType, sku: StringType }));\n\n/** The demand model: units sold at a unit price in a region. */\nconst ModelInput = StructType({ price: FloatType, region: StringType });\n\nconst Model = FunctionType([ModelInput], FloatType);\n\n/** The orders, ids 1001–1040, in id order: the mock's forty, drawn from seed 875 (`Query Editor Spec.md` §6). */\nexport const orders = e3.input(\"orders\", ArrayType(Order), variant(\"value\", [\n { id: 1001n, customer_id: \"C01\", discount: some(0.1), total: 80.1, status: variant(\"shipped\", { date: new Date(\"2026-04-27T09:00:00.000Z\") }),\n lines: [{ price: 8.9, qty: 10n, sku: \"HNG-220\" }] },\n { id: 1002n, customer_id: \"C07\", discount: none, total: 1171.58, status: variant(\"shipped\", { date: new Date(\"2026-01-15T16:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 38n, sku: \"BLT-045\" }, { price: 46.0, qty: 24n, sku: \"PLT-310\" }, { price: 0.18, qty: 196n, sku: \"WSH-008\" }] },\n { id: 1003n, customer_id: \"C02\", discount: none, total: 453.0, status: variant(\"shipped\", { date: new Date(\"2026-04-06T16:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 15n, sku: \"BRK-100\" }, { price: 8.9, qty: 30n, sku: \"HNG-220\" }] },\n { id: 1004n, customer_id: \"C05\", discount: some(0.15), total: 128.61, status: variant(\"pending\", null),\n lines: [{ price: 8.9, qty: 17n, sku: \"HNG-220\" }] },\n { id: 1005n, customer_id: \"C02\", discount: none, total: 520.24, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 6n, sku: \"PLT-310\" }, { price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 0.18, qty: 48n, sku: \"WSH-008\" }] },\n { id: 1006n, customer_id: \"C06\", discount: none, total: 210.8, status: variant(\"shipped\", { date: new Date(\"2026-06-03T14:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 17n, sku: \"BRK-100\" }] },\n { id: 1007n, customer_id: \"C05\", discount: some(0.1), total: 1162.92, status: variant(\"shipped\", { date: new Date(\"2026-04-06T09:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 184n, sku: \"SCR-012\" }, { price: 64.5, qty: 5n, sku: \"RAL-900\" }, { price: 46.0, qty: 7n, sku: \"PLT-310\" }, { price: 3.75, qty: 157n, sku: \"CLP-150\" }] },\n { id: 1008n, customer_id: \"C05\", discount: none, total: 1280.3, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 143n, sku: \"BLT-045\" }, { price: 64.5, qty: 10n, sku: \"RAL-900\" }, { price: 3.75, qty: 137n, sku: \"CLP-150\" }] },\n { id: 1009n, customer_id: \"C04\", discount: some(0.05), total: 409.51, status: variant(\"shipped\", { date: new Date(\"2025-11-18T09:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 6n, sku: \"RAL-900\" }, { price: 0.18, qty: 211n, sku: \"WSH-008\" }, { price: 0.32, qty: 19n, sku: \"SCR-012\" }] },\n { id: 1010n, customer_id: \"C05\", discount: some(0.05), total: 142.23, status: variant(\"shipped\", { date: new Date(\"2025-10-14T12:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 189n, sku: \"WSH-008\" }, { price: 8.9, qty: 13n, sku: \"HNG-220\" }] },\n { id: 1011n, customer_id: \"C08\", discount: none, total: 1027.4, status: variant(\"pending\", null),\n lines: [{ price: 8.9, qty: 29n, sku: \"HNG-220\" }, { price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 0.85, qty: 298n, sku: \"BLT-045\" }] },\n { id: 1012n, customer_id: \"C02\", discount: none, total: 1109.6, status: variant(\"shipped\", { date: new Date(\"2026-04-01T08:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 46.0, qty: 19n, sku: \"PLT-310\" }] },\n { id: 1013n, customer_id: \"C08\", discount: some(0.05), total: 311.37, status: variant(\"shipped\", { date: new Date(\"2026-04-27T10:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 4n, sku: \"RAL-900\" }, { price: 0.32, qty: 218n, sku: \"SCR-012\" }] },\n { id: 1014n, customer_id: \"C07\", discount: none, total: 1765.97, status: variant(\"shipped\", { date: new Date(\"2026-03-09T08:00:00.000Z\") }),\n lines: [{ price: 46.0, qty: 30n, sku: \"PLT-310\" }, { price: 0.18, qty: 254n, sku: \"WSH-008\" }, { price: 0.85, qty: 269n, sku: \"BLT-045\" }, { price: 12.4, qty: 9n, sku: \"BRK-100\" }] },\n { id: 1015n, customer_id: \"C03\", discount: none, total: 3646.84, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 19n, sku: \"PLT-310\" }, { price: 64.5, qty: 26n, sku: \"RAL-900\" }, { price: 3.75, qty: 276n, sku: \"CLP-150\" }, { price: 0.18, qty: 338n, sku: \"WSH-008\" }] },\n { id: 1016n, customer_id: \"C02\", discount: none, total: 1882.9, status: variant(\"pending\", null),\n lines: [{ price: 12.4, qty: 1n, sku: \"BRK-100\" }, { price: 64.5, qty: 29n, sku: \"RAL-900\" }] },\n { id: 1017n, customer_id: \"C02\", discount: some(0.05), total: 2005.59, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 89n, sku: \"BLT-045\" }, { price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 64.5, qty: 23n, sku: \"RAL-900\" }] },\n { id: 1018n, customer_id: \"C03\", discount: none, total: 1372.99, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 26n, sku: \"PLT-310\" }, { price: 0.18, qty: 138n, sku: \"WSH-008\" }, { price: 0.85, qty: 179n, sku: \"BLT-045\" }] },\n { id: 1019n, customer_id: \"C05\", discount: none, total: 684.65, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 301n, sku: \"BLT-045\" }, { price: 12.4, qty: 26n, sku: \"BRK-100\" }, { price: 8.9, qty: 8n, sku: \"HNG-220\" }, { price: 0.32, qty: 110n, sku: \"SCR-012\" }] },\n { id: 1020n, customer_id: \"C01\", discount: some(0.05), total: 297.01, status: variant(\"shipped\", { date: new Date(\"2026-02-06T11:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 75n, sku: \"SCR-012\" }, { price: 0.18, qty: 88n, sku: \"WSH-008\" }, { price: 12.4, qty: 22n, sku: \"BRK-100\" }] },\n { id: 1021n, customer_id: \"C07\", discount: none, total: 1225.5, status: variant(\"shipped\", { date: new Date(\"2026-05-18T14:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 19n, sku: \"RAL-900\" }] },\n { id: 1022n, customer_id: \"C07\", discount: some(0.15), total: 36.26, status: variant(\"shipped\", { date: new Date(\"2026-01-03T10:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 237n, sku: \"WSH-008\" }] },\n { id: 1023n, customer_id: \"C01\", discount: some(0.1), total: 1352.32, status: variant(\"shipped\", { date: new Date(\"2026-01-08T12:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 32n, sku: \"SCR-012\" }, { price: 8.9, qty: 13n, sku: \"HNG-220\" }, { price: 0.18, qty: 123n, sku: \"WSH-008\" }, { price: 64.5, qty: 21n, sku: \"RAL-900\" }] },\n { id: 1024n, customer_id: \"C05\", discount: some(0.05), total: 623.52, status: variant(\"cancelled\", { reason: \"Customer request\" }),\n lines: [{ price: 46.0, qty: 4n, sku: \"PLT-310\" }, { price: 0.18, qty: 209n, sku: \"WSH-008\" }, { price: 0.32, qty: 351n, sku: \"SCR-012\" }, { price: 12.4, qty: 26n, sku: \"BRK-100\" }] },\n { id: 1025n, customer_id: \"C01\", discount: some(0.1), total: 2577.23, status: variant(\"cancelled\", { reason: \"Payment failed\" }),\n lines: [{ price: 0.18, qty: 213n, sku: \"WSH-008\" }, { price: 64.5, qty: 27n, sku: \"RAL-900\" }, { price: 3.75, qty: 289n, sku: \"CLP-150\" }] },\n { id: 1026n, customer_id: \"C03\", discount: none, total: 1913.4, status: variant(\"shipped\", { date: new Date(\"2026-03-07T08:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 354n, sku: \"BLT-045\" }, { price: 64.5, qty: 25n, sku: \"RAL-900\" }] },\n { id: 1027n, customer_id: \"C08\", discount: none, total: 808.19, status: variant(\"shipped\", { date: new Date(\"2026-06-26T10:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 3n, sku: \"BLT-045\" }, { price: 8.9, qty: 25n, sku: \"HNG-220\" }, { price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 0.18, qty: 373n, sku: \"WSH-008\" }] },\n { id: 1028n, customer_id: \"C06\", discount: none, total: 173.45, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 47n, sku: \"BLT-045\" }, { price: 8.9, qty: 15n, sku: \"HNG-220\" }] },\n { id: 1029n, customer_id: \"C05\", discount: none, total: 64.96, status: variant(\"shipped\", { date: new Date(\"2026-03-19T16:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 203n, sku: \"SCR-012\" }] },\n { id: 1030n, customer_id: \"C03\", discount: none, total: 913.36, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 380n, sku: \"BLT-045\" }, { price: 3.75, qty: 4n, sku: \"CLP-150\" }, { price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 0.32, qty: 73n, sku: \"SCR-012\" }] },\n { id: 1031n, customer_id: \"C06\", discount: none, total: 1537.52, status: variant(\"shipped\", { date: new Date(\"2026-05-31T13:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 264n, sku: \"WSH-008\" }, { price: 12.4, qty: 20n, sku: \"BRK-100\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1032n, customer_id: \"C02\", discount: none, total: 1892.81, status: variant(\"cancelled\", { reason: \"Out of stock\" }),\n lines: [{ price: 46.0, qty: 26n, sku: \"PLT-310\" }, { price: 3.75, qty: 183n, sku: \"CLP-150\" }, { price: 0.32, qty: 33n, sku: \"SCR-012\" }] },\n { id: 1033n, customer_id: \"C01\", discount: none, total: 1834.15, status: variant(\"pending\", null),\n lines: [{ price: 64.5, qty: 27n, sku: \"RAL-900\" }, { price: 0.85, qty: 109n, sku: \"BLT-045\" }] },\n { id: 1034n, customer_id: \"C03\", discount: none, total: 323.06, status: variant(\"pending\", null),\n lines: [{ price: 0.32, qty: 140n, sku: \"SCR-012\" }, { price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 0.18, qty: 237n, sku: \"WSH-008\" }] },\n { id: 1035n, customer_id: \"C06\", discount: none, total: 2381.61, status: variant(\"shipped\", { date: new Date(\"2026-06-01T14:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 292n, sku: \"WSH-008\" }, { price: 3.75, qty: 279n, sku: \"CLP-150\" }, { price: 0.85, qty: 48n, sku: \"BLT-045\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1036n, customer_id: \"C01\", discount: some(0.05), total: 1041.68, status: variant(\"shipped\", { date: new Date(\"2026-05-26T13:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 17n, sku: \"RAL-900\" }] },\n { id: 1037n, customer_id: \"C08\", discount: none, total: 774.5, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 8.9, qty: 25n, sku: \"HNG-220\" }] },\n { id: 1038n, customer_id: \"C01\", discount: none, total: 1758.0, status: variant(\"shipped\", { date: new Date(\"2025-10-28T08:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1039n, customer_id: \"C06\", discount: none, total: 471.06, status: variant(\"shipped\", { date: new Date(\"2026-04-04T13:00:00.000Z\") }),\n lines: [{ price: 8.9, qty: 15n, sku: \"HNG-220\" }, { price: 0.18, qty: 222n, sku: \"WSH-008\" }, { price: 12.4, qty: 24n, sku: \"BRK-100\" }] },\n { id: 1040n, customer_id: \"C02\", discount: none, total: 884.1, status: variant(\"shipped\", { date: new Date(\"2025-12-08T14:00:00.000Z\") }),\n lines: [{ price: 46.0, qty: 14n, sku: \"PLT-310\" }, { price: 8.9, qty: 18n, sku: \"HNG-220\" }, { price: 0.85, qty: 94n, sku: \"BLT-045\" }] },\n]));\n\n/** The customers, by id. */\nexport const customers = e3.input(\"customers\", DictType(StringType, Customer), variant(\"value\", new SortedMap([\n [\"C01\", { name: \"Harbour Foods\", region: \"NSW\", tier: variant(\"gold\", null) }],\n [\"C02\", { name: \"Coastline Retail\", region: \"NSW\", tier: variant(\"standard\", null) }],\n [\"C03\", { name: \"Ridge Grocers\", region: \"VIC\", tier: variant(\"gold\", null) }],\n [\"C04\", { name: \"Southbank Market\", region: \"VIC\", tier: variant(\"standard\", null) }],\n [\"C05\", { name: \"Sunfield Traders\", region: \"QLD\", tier: variant(\"standard\", null) }],\n [\"C06\", { name: \"Northgate Supply\", region: \"QLD\", tier: variant(\"gold\", null) }],\n [\"C07\", { name: \"Westend Provisions\", region: \"WA\", tier: variant(\"standard\", null) }],\n [\"C08\", { name: \"Ironbark Stores\", region: \"SA\", tier: variant(\"standard\", null) }],\n], compareFor(StringType))));\n\n/** Weekly demand by region: eight weeks of `base × (0.9 + 0.03w + 0.01i)`, to one place, for the region at index i of NSW, VIC, QLD, WA, SA. */\nexport const forecast = e3.input(\"forecast\", Forecast, variant(\"value\", {\n regions: new SortedMap([\n [\"NSW\", { weekly: [1080.0, 1116.0, 1152.0, 1188.0, 1224.0, 1260.0, 1296.0, 1332.0] }],\n [\"QLD\", { weekly: [791.2, 817.0, 842.8, 868.6, 894.4, 920.2, 946.0, 971.8] }],\n [\"SA\", { weekly: [385.4, 397.7, 410.0, 422.3, 434.6, 446.9, 459.2, 471.5] }],\n [\"VIC\", { weekly: [955.5, 987.0, 1018.5, 1050.0, 1081.5, 1113.0, 1144.5, 1176.0] }],\n [\"WA\", { weekly: [502.2, 518.4, 534.6, 550.8, 567.0, 583.2, 599.4, 615.6] }],\n ], compareFor(StringType)),\n}));\n\n/** The demand model, `round₂(base[region] × (price / 10)^−1.4)`: the units sold at a unit price in a region. */\nconst demandModel = East.function([ModelInput], FloatType, ($, input) => {\n const base = $.const(new SortedMap([[\"NSW\", 1200.0], [\"QLD\", 860.0], [\"SA\", 410.0], [\"VIC\", 1050.0], [\"WA\", 540.0]], compareFor(StringType)), DictType(StringType, FloatType));\n // A region the model does not know has a base of 300.\n const demand = base.get(input.region, () => 300.0).multiply(input.price.divide(10.0).pow(-1.4));\n const cents = $.const(demand.multiply(100.0).add(0.5));\n return cents.subtract(cents.remainder(1.0)).divide(100.0);\n});\n\n/** The demand model as data: an East function every runtime can call, which a query tries over a range. */\nexport const model = e3.input(\"model\", Model, variant(\"value\", East.compile(demandModel, [])));\n\n/** The bill of materials for PUMP-A. */\nexport const bom = e3.input(\"bom\", Part, variant(\"value\", {\n sku: \"PUMP-A\", cost: 42.0, children: [\n { sku: \"MOTOR-1\", cost: 120.0, children: [\n { sku: \"ROTOR-1\", cost: 18.5, children: [] }, { sku: \"STATOR-1\", cost: 22.0, children: [] }, { sku: \"BRG-6203\", cost: 3.2, children: [] },\n ] },\n { sku: \"HOUSING-2\", cost: 35.0, children: [{ sku: \"GASKET-9\", cost: 1.1, children: [] }, { sku: \"BOLT-M8\", cost: 0.4, children: [] }] },\n { sku: \"IMPELLER-3\", cost: 27.5, children: [] },\n { sku: \"SEAL-KIT\", cost: 6.8, children: [{ sku: \"ORING-12\", cost: 0.3, children: [] }, { sku: \"ORING-18\", cost: 0.35, children: [] }] },\n ],\n}));\n\n/**\n * The saved queries record: the mock's seven (`Query Editor Spec.md` §6),\n * each its canonical jq — what the builder's steps print — checked against the\n * data sources the builders bind when the package builds, and described where\n * the mock describes it; the rest describe themselves.\n */\nexport const queries = e3.record(\"queries\", Query.Types.Saved, {\n initial: Query.value({ orders, customers, forecast, model, bom }, [\n {\n name: \"Top shipped orders, 2026\",\n jq: `.customers as $customers\n | .orders\n | map(select(.status.type == \"shipped\") | select(.total >= 100 and (.status.value.date | year) == 2026))\n | map(. + {name: $customers[.customer_id].name, region: $customers[.customer_id].region})\n | map({order: .id, customer: .name, region, total, shipped: .status.value.date})\n | sort_by(-.total)\n | .[:10]`,\n savedAt: new Date(\"2026-10-01T09:00:00Z\"),\n },\n {\n name: \"Revenue by region\",\n jq: `.customers as $customers\n | .orders\n | map(select(.status.type == \"shipped\") | select(.total >= 100 and (.status.value.date | year) == 2026))\n | map(. + {region: $customers[.customer_id].region})\n | group_by(.region)\n | map({region: .[0].region, revenue: map(.total) | add, orders: length})\n | sort_by(-.revenue)\n | .[:3]`,\n description: \"Top 3 regions by shipped revenue in 2026, from orders of $100 or more.\",\n savedAt: new Date(\"2026-09-29T09:00:00Z\"),\n },\n {\n name: \"Shipped revenue by month\",\n jq: `.orders\n | map(select(.status.type == \"shipped\"))\n | map(. + {ship_month: .status.value.date | strftime(\"%Y-%m\")})\n | group_by(.ship_month)\n | map({ship_month: .[0].ship_month, revenue: map(.total) | add, orders: length})\n | sort_by(.ship_month)`,\n savedAt: new Date(\"2026-09-12T09:00:00Z\"),\n },\n {\n name: \"Large orders with no discount\",\n jq: `.orders\n | map(select(.total >= 1000 and .discount == null))\n | map({id, customer_id, total, status})\n | sort_by(-.total)`,\n savedAt: new Date(\"2026-09-03T09:00:00Z\"),\n },\n {\n name: \"Units by SKU\",\n jq: `.orders\n | [.[] | . as $order | .lines[] | . + {order_id: $order.id}]\n | group_by(.sku)\n | map({sku: .[0].sku, units: map(.qty) | add, orders: map(.order_id) | unique | length})\n | sort_by(-.units)`,\n savedAt: new Date(\"2026-08-28T09:00:00Z\"),\n },\n {\n name: \"Pump parts cost\",\n jq: `.bom\n | [recurse(.children[]) | {cost, sku}]\n | {total_cost: map(.cost) | add, parts: length, dearest: map(.cost) | max}`,\n description: \"Total cost, part count and dearest part in the PUMP-A bill of materials.\",\n savedAt: new Date(\"2026-08-20T09:00:00Z\"),\n },\n {\n name: \"Demand at $10–$12, NSW\",\n jq: `.model\n | [range(10.0; 12.0 + 0.5 / 2; 0.5) as $price | {price: $price, demand: call(.; {price: $price, region: \"NSW\"})}]`,\n description: \"Modelled demand in NSW at prices from $10 to $12, in $0.50 steps.\",\n savedAt: new Date(\"2026-08-14T09:00:00Z\"),\n },\n ]),\n mutations: (mutation) => ({\n // The record's one write.\n patch: mutation.patch(),\n }),\n});\n\nEast.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const saved = $.let(Record.bind(queries));\n const orderRows = $.let(Data.bind(orders));\n const customerRows = $.let(Data.bind(customers));\n const weekly = $.let(Data.bind(forecast));\n const demand = $.let(Data.bind(model));\n const parts = $.let(Data.bind(bom));\n // The open query is the surface's: the builder shows it, and tells the surface when its own tabs ask for another.\n const open = $.let(State.bind([Query.Types.Open], \"ex.queryBuilderBom.open\", Query.open.saved(\"Pump parts cost\")));\n const go = $.const(East.function([Query.Types.Open], NullType, ($2, next) => { $2(open.write(next)); }));\n return (\n <Box height=\"640px\">\n <Query.Builder queries={saved} query={open.read()} onOpen={go} id=\"bom\"\n datasets={{ orders: orderRows, customers: customerRows, forecast: weekly, model: demand, bom: parts }} />\n </Box>\n );\n }}</Reactive>\n ))"
45468
45520
  },
45469
45521
  {
45470
45522
  "id": "e3-ui:query.examples.tsx:queryBuilderModel",
@@ -45491,7 +45543,7 @@
45491
45543
  "languages": [
45492
45544
  "tsx"
45493
45545
  ],
45494
- "source": "// The same builder open on Demand at $10–$12, NSW: the demand model, an East function in the data, tried at each price from $10 to $12 in $0.50 steps, one row per price\n// inputs: []\n/** One line of an order: a SKU, its unit price and the quantity ordered. */\nconst Line = StructType({ price: FloatType, qty: IntegerType, sku: StringType });\n\n/** Where an order stands: cancelled for a reason, pending, or shipped on a date. */\nconst Status = VariantType({ cancelled: StructType({ reason: StringType }), pending: NullType, shipped: StructType({ date: DateTimeType }) });\n\n/** An order: `discount` is the fraction taken off, when there is one, and `total` the lines' gross less it, to the cent. */\nconst Order = StructType({\n customer_id: StringType, discount: OptionType(FloatType), id: IntegerType, lines: ArrayType(Line), status: Status, total: FloatType,\n});\n\n/** A customer's tier. */\nconst Tier = VariantType({ gold: NullType, standard: NullType });\n\n/** A customer, and their tier. */\nconst Customer = StructType({ name: StringType, region: StringType, tier: Tier });\n\n/** Weekly demand by region: eight weeks, the first at index 0. */\nconst Forecast = StructType({ regions: DictType(StringType, StructType({ weekly: ArrayType(FloatType) })) });\n\n/** A part and the parts it is built from: a bill of materials. */\nconst Part = RecursiveType(self => StructType({ children: ArrayType(self), cost: FloatType, sku: StringType }));\n\n/** The demand model: units sold at a unit price in a region. */\nconst ModelInput = StructType({ price: FloatType, region: StringType });\n\nconst Model = FunctionType([ModelInput], FloatType);\n\n/** The orders, ids 1001–1040, in id order: the mock's forty, drawn from seed 875 (`Query Editor Spec.md` §6). */\nexport const orders = e3.input(\"orders\", ArrayType(Order), variant(\"value\", [\n { id: 1001n, customer_id: \"C01\", discount: some(0.1), total: 80.1, status: variant(\"shipped\", { date: new Date(\"2026-04-27T09:00:00.000Z\") }),\n lines: [{ price: 8.9, qty: 10n, sku: \"HNG-220\" }] },\n { id: 1002n, customer_id: \"C07\", discount: none, total: 1171.58, status: variant(\"shipped\", { date: new Date(\"2026-01-15T16:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 38n, sku: \"BLT-045\" }, { price: 46.0, qty: 24n, sku: \"PLT-310\" }, { price: 0.18, qty: 196n, sku: \"WSH-008\" }] },\n { id: 1003n, customer_id: \"C02\", discount: none, total: 453.0, status: variant(\"shipped\", { date: new Date(\"2026-04-06T16:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 15n, sku: \"BRK-100\" }, { price: 8.9, qty: 30n, sku: \"HNG-220\" }] },\n { id: 1004n, customer_id: \"C05\", discount: some(0.15), total: 128.61, status: variant(\"pending\", null),\n lines: [{ price: 8.9, qty: 17n, sku: \"HNG-220\" }] },\n { id: 1005n, customer_id: \"C02\", discount: none, total: 520.24, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 6n, sku: \"PLT-310\" }, { price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 0.18, qty: 48n, sku: \"WSH-008\" }] },\n { id: 1006n, customer_id: \"C06\", discount: none, total: 210.8, status: variant(\"shipped\", { date: new Date(\"2026-06-03T14:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 17n, sku: \"BRK-100\" }] },\n { id: 1007n, customer_id: \"C05\", discount: some(0.1), total: 1162.92, status: variant(\"shipped\", { date: new Date(\"2026-04-06T09:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 184n, sku: \"SCR-012\" }, { price: 64.5, qty: 5n, sku: \"RAL-900\" }, { price: 46.0, qty: 7n, sku: \"PLT-310\" }, { price: 3.75, qty: 157n, sku: \"CLP-150\" }] },\n { id: 1008n, customer_id: \"C05\", discount: none, total: 1280.3, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 143n, sku: \"BLT-045\" }, { price: 64.5, qty: 10n, sku: \"RAL-900\" }, { price: 3.75, qty: 137n, sku: \"CLP-150\" }] },\n { id: 1009n, customer_id: \"C04\", discount: some(0.05), total: 409.51, status: variant(\"shipped\", { date: new Date(\"2025-11-18T09:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 6n, sku: \"RAL-900\" }, { price: 0.18, qty: 211n, sku: \"WSH-008\" }, { price: 0.32, qty: 19n, sku: \"SCR-012\" }] },\n { id: 1010n, customer_id: \"C05\", discount: some(0.05), total: 142.23, status: variant(\"shipped\", { date: new Date(\"2025-10-14T12:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 189n, sku: \"WSH-008\" }, { price: 8.9, qty: 13n, sku: \"HNG-220\" }] },\n { id: 1011n, customer_id: \"C08\", discount: none, total: 1027.4, status: variant(\"pending\", null),\n lines: [{ price: 8.9, qty: 29n, sku: \"HNG-220\" }, { price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 0.85, qty: 298n, sku: \"BLT-045\" }] },\n { id: 1012n, customer_id: \"C02\", discount: none, total: 1109.6, status: variant(\"shipped\", { date: new Date(\"2026-04-01T08:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 46.0, qty: 19n, sku: \"PLT-310\" }] },\n { id: 1013n, customer_id: \"C08\", discount: some(0.05), total: 311.37, status: variant(\"shipped\", { date: new Date(\"2026-04-27T10:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 4n, sku: \"RAL-900\" }, { price: 0.32, qty: 218n, sku: \"SCR-012\" }] },\n { id: 1014n, customer_id: \"C07\", discount: none, total: 1765.97, status: variant(\"shipped\", { date: new Date(\"2026-03-09T08:00:00.000Z\") }),\n lines: [{ price: 46.0, qty: 30n, sku: \"PLT-310\" }, { price: 0.18, qty: 254n, sku: \"WSH-008\" }, { price: 0.85, qty: 269n, sku: \"BLT-045\" }, { price: 12.4, qty: 9n, sku: \"BRK-100\" }] },\n { id: 1015n, customer_id: \"C03\", discount: none, total: 3646.84, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 19n, sku: \"PLT-310\" }, { price: 64.5, qty: 26n, sku: \"RAL-900\" }, { price: 3.75, qty: 276n, sku: \"CLP-150\" }, { price: 0.18, qty: 338n, sku: \"WSH-008\" }] },\n { id: 1016n, customer_id: \"C02\", discount: none, total: 1882.9, status: variant(\"pending\", null),\n lines: [{ price: 12.4, qty: 1n, sku: \"BRK-100\" }, { price: 64.5, qty: 29n, sku: \"RAL-900\" }] },\n { id: 1017n, customer_id: \"C02\", discount: some(0.05), total: 2005.59, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 89n, sku: \"BLT-045\" }, { price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 64.5, qty: 23n, sku: \"RAL-900\" }] },\n { id: 1018n, customer_id: \"C03\", discount: none, total: 1372.99, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 26n, sku: \"PLT-310\" }, { price: 0.18, qty: 138n, sku: \"WSH-008\" }, { price: 0.85, qty: 179n, sku: \"BLT-045\" }] },\n { id: 1019n, customer_id: \"C05\", discount: none, total: 684.65, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 301n, sku: \"BLT-045\" }, { price: 12.4, qty: 26n, sku: \"BRK-100\" }, { price: 8.9, qty: 8n, sku: \"HNG-220\" }, { price: 0.32, qty: 110n, sku: \"SCR-012\" }] },\n { id: 1020n, customer_id: \"C01\", discount: some(0.05), total: 297.01, status: variant(\"shipped\", { date: new Date(\"2026-02-06T11:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 75n, sku: \"SCR-012\" }, { price: 0.18, qty: 88n, sku: \"WSH-008\" }, { price: 12.4, qty: 22n, sku: \"BRK-100\" }] },\n { id: 1021n, customer_id: \"C07\", discount: none, total: 1225.5, status: variant(\"shipped\", { date: new Date(\"2026-05-18T14:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 19n, sku: \"RAL-900\" }] },\n { id: 1022n, customer_id: \"C07\", discount: some(0.15), total: 36.26, status: variant(\"shipped\", { date: new Date(\"2026-01-03T10:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 237n, sku: \"WSH-008\" }] },\n { id: 1023n, customer_id: \"C01\", discount: some(0.1), total: 1352.32, status: variant(\"shipped\", { date: new Date(\"2026-01-08T12:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 32n, sku: \"SCR-012\" }, { price: 8.9, qty: 13n, sku: \"HNG-220\" }, { price: 0.18, qty: 123n, sku: \"WSH-008\" }, { price: 64.5, qty: 21n, sku: \"RAL-900\" }] },\n { id: 1024n, customer_id: \"C05\", discount: some(0.05), total: 623.52, status: variant(\"cancelled\", { reason: \"Customer request\" }),\n lines: [{ price: 46.0, qty: 4n, sku: \"PLT-310\" }, { price: 0.18, qty: 209n, sku: \"WSH-008\" }, { price: 0.32, qty: 351n, sku: \"SCR-012\" }, { price: 12.4, qty: 26n, sku: \"BRK-100\" }] },\n { id: 1025n, customer_id: \"C01\", discount: some(0.1), total: 2577.23, status: variant(\"cancelled\", { reason: \"Payment failed\" }),\n lines: [{ price: 0.18, qty: 213n, sku: \"WSH-008\" }, { price: 64.5, qty: 27n, sku: \"RAL-900\" }, { price: 3.75, qty: 289n, sku: \"CLP-150\" }] },\n { id: 1026n, customer_id: \"C03\", discount: none, total: 1913.4, status: variant(\"shipped\", { date: new Date(\"2026-03-07T08:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 354n, sku: \"BLT-045\" }, { price: 64.5, qty: 25n, sku: \"RAL-900\" }] },\n { id: 1027n, customer_id: \"C08\", discount: none, total: 808.19, status: variant(\"shipped\", { date: new Date(\"2026-06-26T10:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 3n, sku: \"BLT-045\" }, { price: 8.9, qty: 25n, sku: \"HNG-220\" }, { price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 0.18, qty: 373n, sku: \"WSH-008\" }] },\n { id: 1028n, customer_id: \"C06\", discount: none, total: 173.45, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 47n, sku: \"BLT-045\" }, { price: 8.9, qty: 15n, sku: \"HNG-220\" }] },\n { id: 1029n, customer_id: \"C05\", discount: none, total: 64.96, status: variant(\"shipped\", { date: new Date(\"2026-03-19T16:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 203n, sku: \"SCR-012\" }] },\n { id: 1030n, customer_id: \"C03\", discount: none, total: 913.36, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 380n, sku: \"BLT-045\" }, { price: 3.75, qty: 4n, sku: \"CLP-150\" }, { price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 0.32, qty: 73n, sku: \"SCR-012\" }] },\n { id: 1031n, customer_id: \"C06\", discount: none, total: 1537.52, status: variant(\"shipped\", { date: new Date(\"2026-05-31T13:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 264n, sku: \"WSH-008\" }, { price: 12.4, qty: 20n, sku: \"BRK-100\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1032n, customer_id: \"C02\", discount: none, total: 1892.81, status: variant(\"cancelled\", { reason: \"Out of stock\" }),\n lines: [{ price: 46.0, qty: 26n, sku: \"PLT-310\" }, { price: 3.75, qty: 183n, sku: \"CLP-150\" }, { price: 0.32, qty: 33n, sku: \"SCR-012\" }] },\n { id: 1033n, customer_id: \"C01\", discount: none, total: 1834.15, status: variant(\"pending\", null),\n lines: [{ price: 64.5, qty: 27n, sku: \"RAL-900\" }, { price: 0.85, qty: 109n, sku: \"BLT-045\" }] },\n { id: 1034n, customer_id: \"C03\", discount: none, total: 323.06, status: variant(\"pending\", null),\n lines: [{ price: 0.32, qty: 140n, sku: \"SCR-012\" }, { price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 0.18, qty: 237n, sku: \"WSH-008\" }] },\n { id: 1035n, customer_id: \"C06\", discount: none, total: 2381.61, status: variant(\"shipped\", { date: new Date(\"2026-06-01T14:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 292n, sku: \"WSH-008\" }, { price: 3.75, qty: 279n, sku: \"CLP-150\" }, { price: 0.85, qty: 48n, sku: \"BLT-045\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1036n, customer_id: \"C01\", discount: some(0.05), total: 1041.68, status: variant(\"shipped\", { date: new Date(\"2026-05-26T13:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 17n, sku: \"RAL-900\" }] },\n { id: 1037n, customer_id: \"C08\", discount: none, total: 774.5, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 8.9, qty: 25n, sku: \"HNG-220\" }] },\n { id: 1038n, customer_id: \"C01\", discount: none, total: 1758.0, status: variant(\"shipped\", { date: new Date(\"2025-10-28T08:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1039n, customer_id: \"C06\", discount: none, total: 471.06, status: variant(\"shipped\", { date: new Date(\"2026-04-04T13:00:00.000Z\") }),\n lines: [{ price: 8.9, qty: 15n, sku: \"HNG-220\" }, { price: 0.18, qty: 222n, sku: \"WSH-008\" }, { price: 12.4, qty: 24n, sku: \"BRK-100\" }] },\n { id: 1040n, customer_id: \"C02\", discount: none, total: 884.1, status: variant(\"shipped\", { date: new Date(\"2025-12-08T14:00:00.000Z\") }),\n lines: [{ price: 46.0, qty: 14n, sku: \"PLT-310\" }, { price: 8.9, qty: 18n, sku: \"HNG-220\" }, { price: 0.85, qty: 94n, sku: \"BLT-045\" }] },\n]));\n\n/** The customers, by id. */\nexport const customers = e3.input(\"customers\", DictType(StringType, Customer), variant(\"value\", new SortedMap([\n [\"C01\", { name: \"Harbour Foods\", region: \"NSW\", tier: variant(\"gold\", null) }],\n [\"C02\", { name: \"Coastline Retail\", region: \"NSW\", tier: variant(\"standard\", null) }],\n [\"C03\", { name: \"Ridge Grocers\", region: \"VIC\", tier: variant(\"gold\", null) }],\n [\"C04\", { name: \"Southbank Market\", region: \"VIC\", tier: variant(\"standard\", null) }],\n [\"C05\", { name: \"Sunfield Traders\", region: \"QLD\", tier: variant(\"standard\", null) }],\n [\"C06\", { name: \"Northgate Supply\", region: \"QLD\", tier: variant(\"gold\", null) }],\n [\"C07\", { name: \"Westend Provisions\", region: \"WA\", tier: variant(\"standard\", null) }],\n [\"C08\", { name: \"Ironbark Stores\", region: \"SA\", tier: variant(\"standard\", null) }],\n], compareFor(StringType))));\n\n/** Weekly demand by region: eight weeks of `base × (0.9 + 0.03w + 0.01i)`, to one place, for the region at index i of NSW, VIC, QLD, WA, SA. */\nexport const forecast = e3.input(\"forecast\", Forecast, variant(\"value\", {\n regions: new SortedMap([\n [\"NSW\", { weekly: [1080.0, 1116.0, 1152.0, 1188.0, 1224.0, 1260.0, 1296.0, 1332.0] }],\n [\"QLD\", { weekly: [791.2, 817.0, 842.8, 868.6, 894.4, 920.2, 946.0, 971.8] }],\n [\"SA\", { weekly: [385.4, 397.7, 410.0, 422.3, 434.6, 446.9, 459.2, 471.5] }],\n [\"VIC\", { weekly: [955.5, 987.0, 1018.5, 1050.0, 1081.5, 1113.0, 1144.5, 1176.0] }],\n [\"WA\", { weekly: [502.2, 518.4, 534.6, 550.8, 567.0, 583.2, 599.4, 615.6] }],\n ], compareFor(StringType)),\n}));\n\n/** The demand model, `round₂(base[region] × (price / 10)^−1.4)`: the units sold at a unit price in a region. */\nconst demandModel = East.function([ModelInput], FloatType, ($, input) => {\n const base = $.const(new SortedMap([[\"NSW\", 1200.0], [\"QLD\", 860.0], [\"SA\", 410.0], [\"VIC\", 1050.0], [\"WA\", 540.0]], compareFor(StringType)), DictType(StringType, FloatType));\n // A region the model does not know has a base of 300.\n const demand = base.get(input.region, () => 300.0).multiply(input.price.divide(10.0).pow(-1.4));\n const cents = $.const(demand.multiply(100.0).add(0.5));\n return cents.subtract(cents.remainder(1.0)).divide(100.0);\n});\n\n/** The demand model as data: an East function every runtime can call, which a query tries over a range. */\nexport const model = e3.input(\"model\", Model, variant(\"value\", East.compile(demandModel, [])));\n\n/** The bill of materials for PUMP-A. */\nexport const bom = e3.input(\"bom\", Part, variant(\"value\", {\n sku: \"PUMP-A\", cost: 42.0, children: [\n { sku: \"MOTOR-1\", cost: 120.0, children: [\n { sku: \"ROTOR-1\", cost: 18.5, children: [] }, { sku: \"STATOR-1\", cost: 22.0, children: [] }, { sku: \"BRG-6203\", cost: 3.2, children: [] },\n ] },\n { sku: \"HOUSING-2\", cost: 35.0, children: [{ sku: \"GASKET-9\", cost: 1.1, children: [] }, { sku: \"BOLT-M8\", cost: 0.4, children: [] }] },\n { sku: \"IMPELLER-3\", cost: 27.5, children: [] },\n { sku: \"SEAL-KIT\", cost: 6.8, children: [{ sku: \"ORING-12\", cost: 0.3, children: [] }, { sku: \"ORING-18\", cost: 0.35, children: [] }] },\n ],\n}));\n\n/**\n * The saved queries record: the mock's seven (`Query Editor Spec.md` §6),\n * each its canonical jq — what the builder's steps print — checked against the\n * data sources the builders bind when the package builds, and described where\n * the mock describes it; the rest describe themselves.\n */\nexport const queries = e3.record(\"queries\", Query.Types.Saved, {\n initial: Query.value({ orders, customers, forecast, model, bom }, [\n {\n name: \"Top shipped orders, 2026\",\n jq: `.customers as $customers\n | .orders\n | map(select(.status.type == \"shipped\") | select(.total >= 100 and (.status.value.date | year) == 2026))\n | map(. + {name: $customers[.customer_id].name, region: $customers[.customer_id].region})\n | map({order: .id, customer: .name, region, total, shipped: .status.value.date})\n | sort_by(-.total)\n | .[:10]`,\n savedAt: new Date(\"2026-10-01T09:00:00Z\"),\n },\n {\n name: \"Revenue by region\",\n jq: `.customers as $customers\n | .orders\n | map(select(.status.type == \"shipped\") | select(.total >= 100 and (.status.value.date | year) == 2026))\n | map(. + {region: $customers[.customer_id].region})\n | group_by(.region)\n | map({region: .[0].region, revenue: map(.total) | add, orders: length})\n | sort_by(-.revenue)\n | .[:3]`,\n description: \"Top 3 regions by shipped revenue in 2026, from orders of $100 or more.\",\n savedAt: new Date(\"2026-09-29T09:00:00Z\"),\n },\n {\n name: \"Shipped revenue by month\",\n jq: `.orders\n | map(select(.status.type == \"shipped\"))\n | map(. + {ship_month: .status.value.date | strftime(\"%Y-%m\")})\n | group_by(.ship_month)\n | map({ship_month: .[0].ship_month, revenue: map(.total) | add, orders: length})\n | sort_by(.ship_month)`,\n savedAt: new Date(\"2026-09-12T09:00:00Z\"),\n },\n {\n name: \"Large orders with no discount\",\n jq: `.orders\n | map(select(.total >= 1000 and .discount == null))\n | map({id, customer_id, total, status})\n | sort_by(-.total)`,\n savedAt: new Date(\"2026-09-03T09:00:00Z\"),\n },\n {\n name: \"Units by SKU\",\n jq: `.orders\n | [.[] | . as $order | .lines[] | . + {order_id: $order.id}]\n | group_by(.sku)\n | map({sku: .[0].sku, units: map(.qty) | add, orders: map(.order_id) | unique | length})\n | sort_by(-.units)`,\n savedAt: new Date(\"2026-08-28T09:00:00Z\"),\n },\n {\n name: \"Pump parts cost\",\n jq: `.bom\n | [recurse(.children[]) | {cost, sku}]\n | {total_cost: map(.cost) | add, parts: length, dearest: map(.cost) | max}`,\n description: \"Total cost, part count and dearest part in the PUMP-A bill of materials.\",\n savedAt: new Date(\"2026-08-20T09:00:00Z\"),\n },\n {\n name: \"Demand at $10–$12, NSW\",\n jq: `.model\n | [range(10.0; 12.0 + 0.5 / 2; 0.5) as $price | {price: $price, demand: call(.; {price: $price, region: \"NSW\"})}]`,\n description: \"Modelled demand in NSW at prices from $10 to $12, in $0.50 steps.\",\n savedAt: new Date(\"2026-08-14T09:00:00Z\"),\n },\n ]),\n mutations: (mutation) => ({\n // The record's one write.\n patch: mutation.patch(),\n }),\n});\n\nEast.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const saved = $.let(Record.bind(queries));\n const orderRows = $.let(Data.bind(orders));\n const customerRows = $.let(Data.bind(customers));\n const weekly = $.let(Data.bind(forecast));\n const demand = $.let(Data.bind(model));\n const parts = $.let(Data.bind(bom));\n return (\n <Box height=\"640px\">\n <Query.Builder queries={saved} query=\"Demand at $10–$12, NSW\" id=\"model\"\n datasets={{ orders: orderRows, customers: customerRows, forecast: weekly, model: demand, bom: parts }} />\n </Box>\n );\n }}</Reactive>\n ))"
45546
+ "source": "// The same builder open on Demand at $10–$12, NSW: the demand model, an East function in the data, tried at each price from $10 to $12 in $0.50 steps, one row per price\n// inputs: []\n/** One line of an order: a SKU, its unit price and the quantity ordered. */\nconst Line = StructType({ price: FloatType, qty: IntegerType, sku: StringType });\n\n/** Where an order stands: cancelled for a reason, pending, or shipped on a date. */\nconst Status = VariantType({ cancelled: StructType({ reason: StringType }), pending: NullType, shipped: StructType({ date: DateTimeType }) });\n\n/** An order: `discount` is the fraction taken off, when there is one, and `total` the lines' gross less it, to the cent. */\nconst Order = StructType({\n customer_id: StringType, discount: OptionType(FloatType), id: IntegerType, lines: ArrayType(Line), status: Status, total: FloatType,\n});\n\n/** A customer's tier. */\nconst Tier = VariantType({ gold: NullType, standard: NullType });\n\n/** A customer, and their tier. */\nconst Customer = StructType({ name: StringType, region: StringType, tier: Tier });\n\n/** Weekly demand by region: eight weeks, the first at index 0. */\nconst Forecast = StructType({ regions: DictType(StringType, StructType({ weekly: ArrayType(FloatType) })) });\n\n/** A part and the parts it is built from: a bill of materials. */\nconst Part = RecursiveType(self => StructType({ children: ArrayType(self), cost: FloatType, sku: StringType }));\n\n/** The demand model: units sold at a unit price in a region. */\nconst ModelInput = StructType({ price: FloatType, region: StringType });\n\nconst Model = FunctionType([ModelInput], FloatType);\n\n/** The orders, ids 1001–1040, in id order: the mock's forty, drawn from seed 875 (`Query Editor Spec.md` §6). */\nexport const orders = e3.input(\"orders\", ArrayType(Order), variant(\"value\", [\n { id: 1001n, customer_id: \"C01\", discount: some(0.1), total: 80.1, status: variant(\"shipped\", { date: new Date(\"2026-04-27T09:00:00.000Z\") }),\n lines: [{ price: 8.9, qty: 10n, sku: \"HNG-220\" }] },\n { id: 1002n, customer_id: \"C07\", discount: none, total: 1171.58, status: variant(\"shipped\", { date: new Date(\"2026-01-15T16:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 38n, sku: \"BLT-045\" }, { price: 46.0, qty: 24n, sku: \"PLT-310\" }, { price: 0.18, qty: 196n, sku: \"WSH-008\" }] },\n { id: 1003n, customer_id: \"C02\", discount: none, total: 453.0, status: variant(\"shipped\", { date: new Date(\"2026-04-06T16:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 15n, sku: \"BRK-100\" }, { price: 8.9, qty: 30n, sku: \"HNG-220\" }] },\n { id: 1004n, customer_id: \"C05\", discount: some(0.15), total: 128.61, status: variant(\"pending\", null),\n lines: [{ price: 8.9, qty: 17n, sku: \"HNG-220\" }] },\n { id: 1005n, customer_id: \"C02\", discount: none, total: 520.24, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 6n, sku: \"PLT-310\" }, { price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 0.18, qty: 48n, sku: \"WSH-008\" }] },\n { id: 1006n, customer_id: \"C06\", discount: none, total: 210.8, status: variant(\"shipped\", { date: new Date(\"2026-06-03T14:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 17n, sku: \"BRK-100\" }] },\n { id: 1007n, customer_id: \"C05\", discount: some(0.1), total: 1162.92, status: variant(\"shipped\", { date: new Date(\"2026-04-06T09:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 184n, sku: \"SCR-012\" }, { price: 64.5, qty: 5n, sku: \"RAL-900\" }, { price: 46.0, qty: 7n, sku: \"PLT-310\" }, { price: 3.75, qty: 157n, sku: \"CLP-150\" }] },\n { id: 1008n, customer_id: \"C05\", discount: none, total: 1280.3, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 143n, sku: \"BLT-045\" }, { price: 64.5, qty: 10n, sku: \"RAL-900\" }, { price: 3.75, qty: 137n, sku: \"CLP-150\" }] },\n { id: 1009n, customer_id: \"C04\", discount: some(0.05), total: 409.51, status: variant(\"shipped\", { date: new Date(\"2025-11-18T09:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 6n, sku: \"RAL-900\" }, { price: 0.18, qty: 211n, sku: \"WSH-008\" }, { price: 0.32, qty: 19n, sku: \"SCR-012\" }] },\n { id: 1010n, customer_id: \"C05\", discount: some(0.05), total: 142.23, status: variant(\"shipped\", { date: new Date(\"2025-10-14T12:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 189n, sku: \"WSH-008\" }, { price: 8.9, qty: 13n, sku: \"HNG-220\" }] },\n { id: 1011n, customer_id: \"C08\", discount: none, total: 1027.4, status: variant(\"pending\", null),\n lines: [{ price: 8.9, qty: 29n, sku: \"HNG-220\" }, { price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 0.85, qty: 298n, sku: \"BLT-045\" }] },\n { id: 1012n, customer_id: \"C02\", discount: none, total: 1109.6, status: variant(\"shipped\", { date: new Date(\"2026-04-01T08:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 46.0, qty: 19n, sku: \"PLT-310\" }] },\n { id: 1013n, customer_id: \"C08\", discount: some(0.05), total: 311.37, status: variant(\"shipped\", { date: new Date(\"2026-04-27T10:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 4n, sku: \"RAL-900\" }, { price: 0.32, qty: 218n, sku: \"SCR-012\" }] },\n { id: 1014n, customer_id: \"C07\", discount: none, total: 1765.97, status: variant(\"shipped\", { date: new Date(\"2026-03-09T08:00:00.000Z\") }),\n lines: [{ price: 46.0, qty: 30n, sku: \"PLT-310\" }, { price: 0.18, qty: 254n, sku: \"WSH-008\" }, { price: 0.85, qty: 269n, sku: \"BLT-045\" }, { price: 12.4, qty: 9n, sku: \"BRK-100\" }] },\n { id: 1015n, customer_id: \"C03\", discount: none, total: 3646.84, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 19n, sku: \"PLT-310\" }, { price: 64.5, qty: 26n, sku: \"RAL-900\" }, { price: 3.75, qty: 276n, sku: \"CLP-150\" }, { price: 0.18, qty: 338n, sku: \"WSH-008\" }] },\n { id: 1016n, customer_id: \"C02\", discount: none, total: 1882.9, status: variant(\"pending\", null),\n lines: [{ price: 12.4, qty: 1n, sku: \"BRK-100\" }, { price: 64.5, qty: 29n, sku: \"RAL-900\" }] },\n { id: 1017n, customer_id: \"C02\", discount: some(0.05), total: 2005.59, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 89n, sku: \"BLT-045\" }, { price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 64.5, qty: 23n, sku: \"RAL-900\" }] },\n { id: 1018n, customer_id: \"C03\", discount: none, total: 1372.99, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 26n, sku: \"PLT-310\" }, { price: 0.18, qty: 138n, sku: \"WSH-008\" }, { price: 0.85, qty: 179n, sku: \"BLT-045\" }] },\n { id: 1019n, customer_id: \"C05\", discount: none, total: 684.65, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 301n, sku: \"BLT-045\" }, { price: 12.4, qty: 26n, sku: \"BRK-100\" }, { price: 8.9, qty: 8n, sku: \"HNG-220\" }, { price: 0.32, qty: 110n, sku: \"SCR-012\" }] },\n { id: 1020n, customer_id: \"C01\", discount: some(0.05), total: 297.01, status: variant(\"shipped\", { date: new Date(\"2026-02-06T11:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 75n, sku: \"SCR-012\" }, { price: 0.18, qty: 88n, sku: \"WSH-008\" }, { price: 12.4, qty: 22n, sku: \"BRK-100\" }] },\n { id: 1021n, customer_id: \"C07\", discount: none, total: 1225.5, status: variant(\"shipped\", { date: new Date(\"2026-05-18T14:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 19n, sku: \"RAL-900\" }] },\n { id: 1022n, customer_id: \"C07\", discount: some(0.15), total: 36.26, status: variant(\"shipped\", { date: new Date(\"2026-01-03T10:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 237n, sku: \"WSH-008\" }] },\n { id: 1023n, customer_id: \"C01\", discount: some(0.1), total: 1352.32, status: variant(\"shipped\", { date: new Date(\"2026-01-08T12:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 32n, sku: \"SCR-012\" }, { price: 8.9, qty: 13n, sku: \"HNG-220\" }, { price: 0.18, qty: 123n, sku: \"WSH-008\" }, { price: 64.5, qty: 21n, sku: \"RAL-900\" }] },\n { id: 1024n, customer_id: \"C05\", discount: some(0.05), total: 623.52, status: variant(\"cancelled\", { reason: \"Customer request\" }),\n lines: [{ price: 46.0, qty: 4n, sku: \"PLT-310\" }, { price: 0.18, qty: 209n, sku: \"WSH-008\" }, { price: 0.32, qty: 351n, sku: \"SCR-012\" }, { price: 12.4, qty: 26n, sku: \"BRK-100\" }] },\n { id: 1025n, customer_id: \"C01\", discount: some(0.1), total: 2577.23, status: variant(\"cancelled\", { reason: \"Payment failed\" }),\n lines: [{ price: 0.18, qty: 213n, sku: \"WSH-008\" }, { price: 64.5, qty: 27n, sku: \"RAL-900\" }, { price: 3.75, qty: 289n, sku: \"CLP-150\" }] },\n { id: 1026n, customer_id: \"C03\", discount: none, total: 1913.4, status: variant(\"shipped\", { date: new Date(\"2026-03-07T08:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 354n, sku: \"BLT-045\" }, { price: 64.5, qty: 25n, sku: \"RAL-900\" }] },\n { id: 1027n, customer_id: \"C08\", discount: none, total: 808.19, status: variant(\"shipped\", { date: new Date(\"2026-06-26T10:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 3n, sku: \"BLT-045\" }, { price: 8.9, qty: 25n, sku: \"HNG-220\" }, { price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 0.18, qty: 373n, sku: \"WSH-008\" }] },\n { id: 1028n, customer_id: \"C06\", discount: none, total: 173.45, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 47n, sku: \"BLT-045\" }, { price: 8.9, qty: 15n, sku: \"HNG-220\" }] },\n { id: 1029n, customer_id: \"C05\", discount: none, total: 64.96, status: variant(\"shipped\", { date: new Date(\"2026-03-19T16:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 203n, sku: \"SCR-012\" }] },\n { id: 1030n, customer_id: \"C03\", discount: none, total: 913.36, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 380n, sku: \"BLT-045\" }, { price: 3.75, qty: 4n, sku: \"CLP-150\" }, { price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 0.32, qty: 73n, sku: \"SCR-012\" }] },\n { id: 1031n, customer_id: \"C06\", discount: none, total: 1537.52, status: variant(\"shipped\", { date: new Date(\"2026-05-31T13:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 264n, sku: \"WSH-008\" }, { price: 12.4, qty: 20n, sku: \"BRK-100\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1032n, customer_id: \"C02\", discount: none, total: 1892.81, status: variant(\"cancelled\", { reason: \"Out of stock\" }),\n lines: [{ price: 46.0, qty: 26n, sku: \"PLT-310\" }, { price: 3.75, qty: 183n, sku: \"CLP-150\" }, { price: 0.32, qty: 33n, sku: \"SCR-012\" }] },\n { id: 1033n, customer_id: \"C01\", discount: none, total: 1834.15, status: variant(\"pending\", null),\n lines: [{ price: 64.5, qty: 27n, sku: \"RAL-900\" }, { price: 0.85, qty: 109n, sku: \"BLT-045\" }] },\n { id: 1034n, customer_id: \"C03\", discount: none, total: 323.06, status: variant(\"pending\", null),\n lines: [{ price: 0.32, qty: 140n, sku: \"SCR-012\" }, { price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 0.18, qty: 237n, sku: \"WSH-008\" }] },\n { id: 1035n, customer_id: \"C06\", discount: none, total: 2381.61, status: variant(\"shipped\", { date: new Date(\"2026-06-01T14:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 292n, sku: \"WSH-008\" }, { price: 3.75, qty: 279n, sku: \"CLP-150\" }, { price: 0.85, qty: 48n, sku: \"BLT-045\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1036n, customer_id: \"C01\", discount: some(0.05), total: 1041.68, status: variant(\"shipped\", { date: new Date(\"2026-05-26T13:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 17n, sku: \"RAL-900\" }] },\n { id: 1037n, customer_id: \"C08\", discount: none, total: 774.5, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 8.9, qty: 25n, sku: \"HNG-220\" }] },\n { id: 1038n, customer_id: \"C01\", discount: none, total: 1758.0, status: variant(\"shipped\", { date: new Date(\"2025-10-28T08:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1039n, customer_id: \"C06\", discount: none, total: 471.06, status: variant(\"shipped\", { date: new Date(\"2026-04-04T13:00:00.000Z\") }),\n lines: [{ price: 8.9, qty: 15n, sku: \"HNG-220\" }, { price: 0.18, qty: 222n, sku: \"WSH-008\" }, { price: 12.4, qty: 24n, sku: \"BRK-100\" }] },\n { id: 1040n, customer_id: \"C02\", discount: none, total: 884.1, status: variant(\"shipped\", { date: new Date(\"2025-12-08T14:00:00.000Z\") }),\n lines: [{ price: 46.0, qty: 14n, sku: \"PLT-310\" }, { price: 8.9, qty: 18n, sku: \"HNG-220\" }, { price: 0.85, qty: 94n, sku: \"BLT-045\" }] },\n]));\n\n/** The customers, by id. */\nexport const customers = e3.input(\"customers\", DictType(StringType, Customer), variant(\"value\", new SortedMap([\n [\"C01\", { name: \"Harbour Foods\", region: \"NSW\", tier: variant(\"gold\", null) }],\n [\"C02\", { name: \"Coastline Retail\", region: \"NSW\", tier: variant(\"standard\", null) }],\n [\"C03\", { name: \"Ridge Grocers\", region: \"VIC\", tier: variant(\"gold\", null) }],\n [\"C04\", { name: \"Southbank Market\", region: \"VIC\", tier: variant(\"standard\", null) }],\n [\"C05\", { name: \"Sunfield Traders\", region: \"QLD\", tier: variant(\"standard\", null) }],\n [\"C06\", { name: \"Northgate Supply\", region: \"QLD\", tier: variant(\"gold\", null) }],\n [\"C07\", { name: \"Westend Provisions\", region: \"WA\", tier: variant(\"standard\", null) }],\n [\"C08\", { name: \"Ironbark Stores\", region: \"SA\", tier: variant(\"standard\", null) }],\n], compareFor(StringType))));\n\n/** Weekly demand by region: eight weeks of `base × (0.9 + 0.03w + 0.01i)`, to one place, for the region at index i of NSW, VIC, QLD, WA, SA. */\nexport const forecast = e3.input(\"forecast\", Forecast, variant(\"value\", {\n regions: new SortedMap([\n [\"NSW\", { weekly: [1080.0, 1116.0, 1152.0, 1188.0, 1224.0, 1260.0, 1296.0, 1332.0] }],\n [\"QLD\", { weekly: [791.2, 817.0, 842.8, 868.6, 894.4, 920.2, 946.0, 971.8] }],\n [\"SA\", { weekly: [385.4, 397.7, 410.0, 422.3, 434.6, 446.9, 459.2, 471.5] }],\n [\"VIC\", { weekly: [955.5, 987.0, 1018.5, 1050.0, 1081.5, 1113.0, 1144.5, 1176.0] }],\n [\"WA\", { weekly: [502.2, 518.4, 534.6, 550.8, 567.0, 583.2, 599.4, 615.6] }],\n ], compareFor(StringType)),\n}));\n\n/** The demand model, `round₂(base[region] × (price / 10)^−1.4)`: the units sold at a unit price in a region. */\nconst demandModel = East.function([ModelInput], FloatType, ($, input) => {\n const base = $.const(new SortedMap([[\"NSW\", 1200.0], [\"QLD\", 860.0], [\"SA\", 410.0], [\"VIC\", 1050.0], [\"WA\", 540.0]], compareFor(StringType)), DictType(StringType, FloatType));\n // A region the model does not know has a base of 300.\n const demand = base.get(input.region, () => 300.0).multiply(input.price.divide(10.0).pow(-1.4));\n const cents = $.const(demand.multiply(100.0).add(0.5));\n return cents.subtract(cents.remainder(1.0)).divide(100.0);\n});\n\n/** The demand model as data: an East function every runtime can call, which a query tries over a range. */\nexport const model = e3.input(\"model\", Model, variant(\"value\", East.compile(demandModel, [])));\n\n/** The bill of materials for PUMP-A. */\nexport const bom = e3.input(\"bom\", Part, variant(\"value\", {\n sku: \"PUMP-A\", cost: 42.0, children: [\n { sku: \"MOTOR-1\", cost: 120.0, children: [\n { sku: \"ROTOR-1\", cost: 18.5, children: [] }, { sku: \"STATOR-1\", cost: 22.0, children: [] }, { sku: \"BRG-6203\", cost: 3.2, children: [] },\n ] },\n { sku: \"HOUSING-2\", cost: 35.0, children: [{ sku: \"GASKET-9\", cost: 1.1, children: [] }, { sku: \"BOLT-M8\", cost: 0.4, children: [] }] },\n { sku: \"IMPELLER-3\", cost: 27.5, children: [] },\n { sku: \"SEAL-KIT\", cost: 6.8, children: [{ sku: \"ORING-12\", cost: 0.3, children: [] }, { sku: \"ORING-18\", cost: 0.35, children: [] }] },\n ],\n}));\n\n/**\n * The saved queries record: the mock's seven (`Query Editor Spec.md` §6),\n * each its canonical jq — what the builder's steps print — checked against the\n * data sources the builders bind when the package builds, and described where\n * the mock describes it; the rest describe themselves.\n */\nexport const queries = e3.record(\"queries\", Query.Types.Saved, {\n initial: Query.value({ orders, customers, forecast, model, bom }, [\n {\n name: \"Top shipped orders, 2026\",\n jq: `.customers as $customers\n | .orders\n | map(select(.status.type == \"shipped\") | select(.total >= 100 and (.status.value.date | year) == 2026))\n | map(. + {name: $customers[.customer_id].name, region: $customers[.customer_id].region})\n | map({order: .id, customer: .name, region, total, shipped: .status.value.date})\n | sort_by(-.total)\n | .[:10]`,\n savedAt: new Date(\"2026-10-01T09:00:00Z\"),\n },\n {\n name: \"Revenue by region\",\n jq: `.customers as $customers\n | .orders\n | map(select(.status.type == \"shipped\") | select(.total >= 100 and (.status.value.date | year) == 2026))\n | map(. + {region: $customers[.customer_id].region})\n | group_by(.region)\n | map({region: .[0].region, revenue: map(.total) | add, orders: length})\n | sort_by(-.revenue)\n | .[:3]`,\n description: \"Top 3 regions by shipped revenue in 2026, from orders of $100 or more.\",\n savedAt: new Date(\"2026-09-29T09:00:00Z\"),\n },\n {\n name: \"Shipped revenue by month\",\n jq: `.orders\n | map(select(.status.type == \"shipped\"))\n | map(. + {ship_month: .status.value.date | strftime(\"%Y-%m\")})\n | group_by(.ship_month)\n | map({ship_month: .[0].ship_month, revenue: map(.total) | add, orders: length})\n | sort_by(.ship_month)`,\n savedAt: new Date(\"2026-09-12T09:00:00Z\"),\n },\n {\n name: \"Large orders with no discount\",\n jq: `.orders\n | map(select(.total >= 1000 and .discount == null))\n | map({id, customer_id, total, status})\n | sort_by(-.total)`,\n savedAt: new Date(\"2026-09-03T09:00:00Z\"),\n },\n {\n name: \"Units by SKU\",\n jq: `.orders\n | [.[] | . as $order | .lines[] | . + {order_id: $order.id}]\n | group_by(.sku)\n | map({sku: .[0].sku, units: map(.qty) | add, orders: map(.order_id) | unique | length})\n | sort_by(-.units)`,\n savedAt: new Date(\"2026-08-28T09:00:00Z\"),\n },\n {\n name: \"Pump parts cost\",\n jq: `.bom\n | [recurse(.children[]) | {cost, sku}]\n | {total_cost: map(.cost) | add, parts: length, dearest: map(.cost) | max}`,\n description: \"Total cost, part count and dearest part in the PUMP-A bill of materials.\",\n savedAt: new Date(\"2026-08-20T09:00:00Z\"),\n },\n {\n name: \"Demand at $10–$12, NSW\",\n jq: `.model\n | [range(10.0; 12.0 + 0.5 / 2; 0.5) as $price | {price: $price, demand: call(.; {price: $price, region: \"NSW\"})}]`,\n description: \"Modelled demand in NSW at prices from $10 to $12, in $0.50 steps.\",\n savedAt: new Date(\"2026-08-14T09:00:00Z\"),\n },\n ]),\n mutations: (mutation) => ({\n // The record's one write.\n patch: mutation.patch(),\n }),\n});\n\nEast.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const saved = $.let(Record.bind(queries));\n const orderRows = $.let(Data.bind(orders));\n const customerRows = $.let(Data.bind(customers));\n const weekly = $.let(Data.bind(forecast));\n const demand = $.let(Data.bind(model));\n const parts = $.let(Data.bind(bom));\n // The open query is the surface's: the builder shows it, and tells the surface when its own tabs ask for another.\n const open = $.let(State.bind([Query.Types.Open], \"ex.queryBuilderModel.open\", Query.open.saved(\"Demand at $10–$12, NSW\")));\n const go = $.const(East.function([Query.Types.Open], NullType, ($2, next) => { $2(open.write(next)); }));\n return (\n <Box height=\"640px\">\n <Query.Builder queries={saved} query={open.read()} onOpen={go} id=\"model\"\n datasets={{ orders: orderRows, customers: customerRows, forecast: weekly, model: demand, bom: parts }} />\n </Box>\n );\n }}</Reactive>\n ))"
45495
45547
  },
45496
45548
  {
45497
45549
  "id": "e3-ui:query.examples.tsx:queryBuilderEmpty",
@@ -45499,14 +45551,17 @@
45499
45551
  "package": "e3-ui",
45500
45552
  "file": "east-ui/packages/e3-ui/test/query/query.examples.tsx",
45501
45553
  "suite": "",
45502
- "test": "A builder over a record with no saved queries: a new query on orders, its Query tab asking for a first step, and nothing run yet",
45554
+ "test": "A builder over a record with no saved queries: a new query on orders — `Query.open.on(\"orders\")`, held by the surface — its Query tab asking for a first step, and nothing run yet",
45503
45555
  "keywords": [
45504
45556
  "Query",
45505
45557
  "Query.Builder",
45506
45558
  "new query",
45507
45559
  "empty",
45508
45560
  "Add a step",
45509
- "Quick add"
45561
+ "Quick add",
45562
+ "Query.open.on",
45563
+ "Query.Types.Open",
45564
+ "onOpen"
45510
45565
  ],
45511
45566
  "imports": [
45512
45567
  "import {",
@@ -45517,7 +45572,7 @@
45517
45572
  "languages": [
45518
45573
  "tsx"
45519
45574
  ],
45520
- "source": "// A builder over a record with no saved queries: a new query on orders, its Query tab asking for a first step, and nothing run yet\n// inputs: []\n/** One line of an order: a SKU, its unit price and the quantity ordered. */\nconst Line = StructType({ price: FloatType, qty: IntegerType, sku: StringType });\n\n/** Where an order stands: cancelled for a reason, pending, or shipped on a date. */\nconst Status = VariantType({ cancelled: StructType({ reason: StringType }), pending: NullType, shipped: StructType({ date: DateTimeType }) });\n\n/** An order: `discount` is the fraction taken off, when there is one, and `total` the lines' gross less it, to the cent. */\nconst Order = StructType({\n customer_id: StringType, discount: OptionType(FloatType), id: IntegerType, lines: ArrayType(Line), status: Status, total: FloatType,\n});\n\n/** A customer's tier. */\nconst Tier = VariantType({ gold: NullType, standard: NullType });\n\n/** A customer, and their tier. */\nconst Customer = StructType({ name: StringType, region: StringType, tier: Tier });\n\n/** The orders, ids 1001–1040, in id order: the mock's forty, drawn from seed 875 (`Query Editor Spec.md` §6). */\nexport const orders = e3.input(\"orders\", ArrayType(Order), variant(\"value\", [\n { id: 1001n, customer_id: \"C01\", discount: some(0.1), total: 80.1, status: variant(\"shipped\", { date: new Date(\"2026-04-27T09:00:00.000Z\") }),\n lines: [{ price: 8.9, qty: 10n, sku: \"HNG-220\" }] },\n { id: 1002n, customer_id: \"C07\", discount: none, total: 1171.58, status: variant(\"shipped\", { date: new Date(\"2026-01-15T16:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 38n, sku: \"BLT-045\" }, { price: 46.0, qty: 24n, sku: \"PLT-310\" }, { price: 0.18, qty: 196n, sku: \"WSH-008\" }] },\n { id: 1003n, customer_id: \"C02\", discount: none, total: 453.0, status: variant(\"shipped\", { date: new Date(\"2026-04-06T16:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 15n, sku: \"BRK-100\" }, { price: 8.9, qty: 30n, sku: \"HNG-220\" }] },\n { id: 1004n, customer_id: \"C05\", discount: some(0.15), total: 128.61, status: variant(\"pending\", null),\n lines: [{ price: 8.9, qty: 17n, sku: \"HNG-220\" }] },\n { id: 1005n, customer_id: \"C02\", discount: none, total: 520.24, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 6n, sku: \"PLT-310\" }, { price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 0.18, qty: 48n, sku: \"WSH-008\" }] },\n { id: 1006n, customer_id: \"C06\", discount: none, total: 210.8, status: variant(\"shipped\", { date: new Date(\"2026-06-03T14:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 17n, sku: \"BRK-100\" }] },\n { id: 1007n, customer_id: \"C05\", discount: some(0.1), total: 1162.92, status: variant(\"shipped\", { date: new Date(\"2026-04-06T09:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 184n, sku: \"SCR-012\" }, { price: 64.5, qty: 5n, sku: \"RAL-900\" }, { price: 46.0, qty: 7n, sku: \"PLT-310\" }, { price: 3.75, qty: 157n, sku: \"CLP-150\" }] },\n { id: 1008n, customer_id: \"C05\", discount: none, total: 1280.3, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 143n, sku: \"BLT-045\" }, { price: 64.5, qty: 10n, sku: \"RAL-900\" }, { price: 3.75, qty: 137n, sku: \"CLP-150\" }] },\n { id: 1009n, customer_id: \"C04\", discount: some(0.05), total: 409.51, status: variant(\"shipped\", { date: new Date(\"2025-11-18T09:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 6n, sku: \"RAL-900\" }, { price: 0.18, qty: 211n, sku: \"WSH-008\" }, { price: 0.32, qty: 19n, sku: \"SCR-012\" }] },\n { id: 1010n, customer_id: \"C05\", discount: some(0.05), total: 142.23, status: variant(\"shipped\", { date: new Date(\"2025-10-14T12:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 189n, sku: \"WSH-008\" }, { price: 8.9, qty: 13n, sku: \"HNG-220\" }] },\n { id: 1011n, customer_id: \"C08\", discount: none, total: 1027.4, status: variant(\"pending\", null),\n lines: [{ price: 8.9, qty: 29n, sku: \"HNG-220\" }, { price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 0.85, qty: 298n, sku: \"BLT-045\" }] },\n { id: 1012n, customer_id: \"C02\", discount: none, total: 1109.6, status: variant(\"shipped\", { date: new Date(\"2026-04-01T08:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 46.0, qty: 19n, sku: \"PLT-310\" }] },\n { id: 1013n, customer_id: \"C08\", discount: some(0.05), total: 311.37, status: variant(\"shipped\", { date: new Date(\"2026-04-27T10:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 4n, sku: \"RAL-900\" }, { price: 0.32, qty: 218n, sku: \"SCR-012\" }] },\n { id: 1014n, customer_id: \"C07\", discount: none, total: 1765.97, status: variant(\"shipped\", { date: new Date(\"2026-03-09T08:00:00.000Z\") }),\n lines: [{ price: 46.0, qty: 30n, sku: \"PLT-310\" }, { price: 0.18, qty: 254n, sku: \"WSH-008\" }, { price: 0.85, qty: 269n, sku: \"BLT-045\" }, { price: 12.4, qty: 9n, sku: \"BRK-100\" }] },\n { id: 1015n, customer_id: \"C03\", discount: none, total: 3646.84, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 19n, sku: \"PLT-310\" }, { price: 64.5, qty: 26n, sku: \"RAL-900\" }, { price: 3.75, qty: 276n, sku: \"CLP-150\" }, { price: 0.18, qty: 338n, sku: \"WSH-008\" }] },\n { id: 1016n, customer_id: \"C02\", discount: none, total: 1882.9, status: variant(\"pending\", null),\n lines: [{ price: 12.4, qty: 1n, sku: \"BRK-100\" }, { price: 64.5, qty: 29n, sku: \"RAL-900\" }] },\n { id: 1017n, customer_id: \"C02\", discount: some(0.05), total: 2005.59, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 89n, sku: \"BLT-045\" }, { price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 64.5, qty: 23n, sku: \"RAL-900\" }] },\n { id: 1018n, customer_id: \"C03\", discount: none, total: 1372.99, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 26n, sku: \"PLT-310\" }, { price: 0.18, qty: 138n, sku: \"WSH-008\" }, { price: 0.85, qty: 179n, sku: \"BLT-045\" }] },\n { id: 1019n, customer_id: \"C05\", discount: none, total: 684.65, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 301n, sku: \"BLT-045\" }, { price: 12.4, qty: 26n, sku: \"BRK-100\" }, { price: 8.9, qty: 8n, sku: \"HNG-220\" }, { price: 0.32, qty: 110n, sku: \"SCR-012\" }] },\n { id: 1020n, customer_id: \"C01\", discount: some(0.05), total: 297.01, status: variant(\"shipped\", { date: new Date(\"2026-02-06T11:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 75n, sku: \"SCR-012\" }, { price: 0.18, qty: 88n, sku: \"WSH-008\" }, { price: 12.4, qty: 22n, sku: \"BRK-100\" }] },\n { id: 1021n, customer_id: \"C07\", discount: none, total: 1225.5, status: variant(\"shipped\", { date: new Date(\"2026-05-18T14:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 19n, sku: \"RAL-900\" }] },\n { id: 1022n, customer_id: \"C07\", discount: some(0.15), total: 36.26, status: variant(\"shipped\", { date: new Date(\"2026-01-03T10:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 237n, sku: \"WSH-008\" }] },\n { id: 1023n, customer_id: \"C01\", discount: some(0.1), total: 1352.32, status: variant(\"shipped\", { date: new Date(\"2026-01-08T12:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 32n, sku: \"SCR-012\" }, { price: 8.9, qty: 13n, sku: \"HNG-220\" }, { price: 0.18, qty: 123n, sku: \"WSH-008\" }, { price: 64.5, qty: 21n, sku: \"RAL-900\" }] },\n { id: 1024n, customer_id: \"C05\", discount: some(0.05), total: 623.52, status: variant(\"cancelled\", { reason: \"Customer request\" }),\n lines: [{ price: 46.0, qty: 4n, sku: \"PLT-310\" }, { price: 0.18, qty: 209n, sku: \"WSH-008\" }, { price: 0.32, qty: 351n, sku: \"SCR-012\" }, { price: 12.4, qty: 26n, sku: \"BRK-100\" }] },\n { id: 1025n, customer_id: \"C01\", discount: some(0.1), total: 2577.23, status: variant(\"cancelled\", { reason: \"Payment failed\" }),\n lines: [{ price: 0.18, qty: 213n, sku: \"WSH-008\" }, { price: 64.5, qty: 27n, sku: \"RAL-900\" }, { price: 3.75, qty: 289n, sku: \"CLP-150\" }] },\n { id: 1026n, customer_id: \"C03\", discount: none, total: 1913.4, status: variant(\"shipped\", { date: new Date(\"2026-03-07T08:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 354n, sku: \"BLT-045\" }, { price: 64.5, qty: 25n, sku: \"RAL-900\" }] },\n { id: 1027n, customer_id: \"C08\", discount: none, total: 808.19, status: variant(\"shipped\", { date: new Date(\"2026-06-26T10:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 3n, sku: \"BLT-045\" }, { price: 8.9, qty: 25n, sku: \"HNG-220\" }, { price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 0.18, qty: 373n, sku: \"WSH-008\" }] },\n { id: 1028n, customer_id: \"C06\", discount: none, total: 173.45, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 47n, sku: \"BLT-045\" }, { price: 8.9, qty: 15n, sku: \"HNG-220\" }] },\n { id: 1029n, customer_id: \"C05\", discount: none, total: 64.96, status: variant(\"shipped\", { date: new Date(\"2026-03-19T16:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 203n, sku: \"SCR-012\" }] },\n { id: 1030n, customer_id: \"C03\", discount: none, total: 913.36, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 380n, sku: \"BLT-045\" }, { price: 3.75, qty: 4n, sku: \"CLP-150\" }, { price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 0.32, qty: 73n, sku: \"SCR-012\" }] },\n { id: 1031n, customer_id: \"C06\", discount: none, total: 1537.52, status: variant(\"shipped\", { date: new Date(\"2026-05-31T13:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 264n, sku: \"WSH-008\" }, { price: 12.4, qty: 20n, sku: \"BRK-100\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1032n, customer_id: \"C02\", discount: none, total: 1892.81, status: variant(\"cancelled\", { reason: \"Out of stock\" }),\n lines: [{ price: 46.0, qty: 26n, sku: \"PLT-310\" }, { price: 3.75, qty: 183n, sku: \"CLP-150\" }, { price: 0.32, qty: 33n, sku: \"SCR-012\" }] },\n { id: 1033n, customer_id: \"C01\", discount: none, total: 1834.15, status: variant(\"pending\", null),\n lines: [{ price: 64.5, qty: 27n, sku: \"RAL-900\" }, { price: 0.85, qty: 109n, sku: \"BLT-045\" }] },\n { id: 1034n, customer_id: \"C03\", discount: none, total: 323.06, status: variant(\"pending\", null),\n lines: [{ price: 0.32, qty: 140n, sku: \"SCR-012\" }, { price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 0.18, qty: 237n, sku: \"WSH-008\" }] },\n { id: 1035n, customer_id: \"C06\", discount: none, total: 2381.61, status: variant(\"shipped\", { date: new Date(\"2026-06-01T14:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 292n, sku: \"WSH-008\" }, { price: 3.75, qty: 279n, sku: \"CLP-150\" }, { price: 0.85, qty: 48n, sku: \"BLT-045\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1036n, customer_id: \"C01\", discount: some(0.05), total: 1041.68, status: variant(\"shipped\", { date: new Date(\"2026-05-26T13:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 17n, sku: \"RAL-900\" }] },\n { id: 1037n, customer_id: \"C08\", discount: none, total: 774.5, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 8.9, qty: 25n, sku: \"HNG-220\" }] },\n { id: 1038n, customer_id: \"C01\", discount: none, total: 1758.0, status: variant(\"shipped\", { date: new Date(\"2025-10-28T08:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1039n, customer_id: \"C06\", discount: none, total: 471.06, status: variant(\"shipped\", { date: new Date(\"2026-04-04T13:00:00.000Z\") }),\n lines: [{ price: 8.9, qty: 15n, sku: \"HNG-220\" }, { price: 0.18, qty: 222n, sku: \"WSH-008\" }, { price: 12.4, qty: 24n, sku: \"BRK-100\" }] },\n { id: 1040n, customer_id: \"C02\", discount: none, total: 884.1, status: variant(\"shipped\", { date: new Date(\"2025-12-08T14:00:00.000Z\") }),\n lines: [{ price: 46.0, qty: 14n, sku: \"PLT-310\" }, { price: 8.9, qty: 18n, sku: \"HNG-220\" }, { price: 0.85, qty: 94n, sku: \"BLT-045\" }] },\n]));\n\n/** The customers, by id. */\nexport const customers = e3.input(\"customers\", DictType(StringType, Customer), variant(\"value\", new SortedMap([\n [\"C01\", { name: \"Harbour Foods\", region: \"NSW\", tier: variant(\"gold\", null) }],\n [\"C02\", { name: \"Coastline Retail\", region: \"NSW\", tier: variant(\"standard\", null) }],\n [\"C03\", { name: \"Ridge Grocers\", region: \"VIC\", tier: variant(\"gold\", null) }],\n [\"C04\", { name: \"Southbank Market\", region: \"VIC\", tier: variant(\"standard\", null) }],\n [\"C05\", { name: \"Sunfield Traders\", region: \"QLD\", tier: variant(\"standard\", null) }],\n [\"C06\", { name: \"Northgate Supply\", region: \"QLD\", tier: variant(\"gold\", null) }],\n [\"C07\", { name: \"Westend Provisions\", region: \"WA\", tier: variant(\"standard\", null) }],\n [\"C08\", { name: \"Ironbark Stores\", region: \"SA\", tier: variant(\"standard\", null) }],\n], compareFor(StringType))));\n\n/** A record no query has been saved to yet. */\nexport const queriesEmpty = e3.record(\"queries_empty\", Query.Types.Saved, {\n initial: new SortedMap([], compareFor(StringType)),\n mutations: (mutation) => ({\n // Its one write.\n patch: mutation.patch(),\n }),\n});\n\nEast.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const saved = $.let(Record.bind(queriesEmpty));\n const orderRows = $.let(Data.bind(orders));\n const customerRows = $.let(Data.bind(customers));\n return (\n <Box height=\"560px\">\n <Query.Builder queries={saved} id=\"empty\" datasets={{ orders: orderRows, customers: customerRows }} />\n </Box>\n );\n }}</Reactive>\n ))"
45575
+ "source": "// A builder over a record with no saved queries: a new query on orders — `Query.open.on(\"orders\")`, held by the surface — its Query tab asking for a first step, and nothing run yet\n// inputs: []\n/** One line of an order: a SKU, its unit price and the quantity ordered. */\nconst Line = StructType({ price: FloatType, qty: IntegerType, sku: StringType });\n\n/** Where an order stands: cancelled for a reason, pending, or shipped on a date. */\nconst Status = VariantType({ cancelled: StructType({ reason: StringType }), pending: NullType, shipped: StructType({ date: DateTimeType }) });\n\n/** An order: `discount` is the fraction taken off, when there is one, and `total` the lines' gross less it, to the cent. */\nconst Order = StructType({\n customer_id: StringType, discount: OptionType(FloatType), id: IntegerType, lines: ArrayType(Line), status: Status, total: FloatType,\n});\n\n/** A customer's tier. */\nconst Tier = VariantType({ gold: NullType, standard: NullType });\n\n/** A customer, and their tier. */\nconst Customer = StructType({ name: StringType, region: StringType, tier: Tier });\n\n/** The orders, ids 1001–1040, in id order: the mock's forty, drawn from seed 875 (`Query Editor Spec.md` §6). */\nexport const orders = e3.input(\"orders\", ArrayType(Order), variant(\"value\", [\n { id: 1001n, customer_id: \"C01\", discount: some(0.1), total: 80.1, status: variant(\"shipped\", { date: new Date(\"2026-04-27T09:00:00.000Z\") }),\n lines: [{ price: 8.9, qty: 10n, sku: \"HNG-220\" }] },\n { id: 1002n, customer_id: \"C07\", discount: none, total: 1171.58, status: variant(\"shipped\", { date: new Date(\"2026-01-15T16:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 38n, sku: \"BLT-045\" }, { price: 46.0, qty: 24n, sku: \"PLT-310\" }, { price: 0.18, qty: 196n, sku: \"WSH-008\" }] },\n { id: 1003n, customer_id: \"C02\", discount: none, total: 453.0, status: variant(\"shipped\", { date: new Date(\"2026-04-06T16:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 15n, sku: \"BRK-100\" }, { price: 8.9, qty: 30n, sku: \"HNG-220\" }] },\n { id: 1004n, customer_id: \"C05\", discount: some(0.15), total: 128.61, status: variant(\"pending\", null),\n lines: [{ price: 8.9, qty: 17n, sku: \"HNG-220\" }] },\n { id: 1005n, customer_id: \"C02\", discount: none, total: 520.24, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 6n, sku: \"PLT-310\" }, { price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 0.18, qty: 48n, sku: \"WSH-008\" }] },\n { id: 1006n, customer_id: \"C06\", discount: none, total: 210.8, status: variant(\"shipped\", { date: new Date(\"2026-06-03T14:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 17n, sku: \"BRK-100\" }] },\n { id: 1007n, customer_id: \"C05\", discount: some(0.1), total: 1162.92, status: variant(\"shipped\", { date: new Date(\"2026-04-06T09:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 184n, sku: \"SCR-012\" }, { price: 64.5, qty: 5n, sku: \"RAL-900\" }, { price: 46.0, qty: 7n, sku: \"PLT-310\" }, { price: 3.75, qty: 157n, sku: \"CLP-150\" }] },\n { id: 1008n, customer_id: \"C05\", discount: none, total: 1280.3, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 143n, sku: \"BLT-045\" }, { price: 64.5, qty: 10n, sku: \"RAL-900\" }, { price: 3.75, qty: 137n, sku: \"CLP-150\" }] },\n { id: 1009n, customer_id: \"C04\", discount: some(0.05), total: 409.51, status: variant(\"shipped\", { date: new Date(\"2025-11-18T09:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 6n, sku: \"RAL-900\" }, { price: 0.18, qty: 211n, sku: \"WSH-008\" }, { price: 0.32, qty: 19n, sku: \"SCR-012\" }] },\n { id: 1010n, customer_id: \"C05\", discount: some(0.05), total: 142.23, status: variant(\"shipped\", { date: new Date(\"2025-10-14T12:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 189n, sku: \"WSH-008\" }, { price: 8.9, qty: 13n, sku: \"HNG-220\" }] },\n { id: 1011n, customer_id: \"C08\", discount: none, total: 1027.4, status: variant(\"pending\", null),\n lines: [{ price: 8.9, qty: 29n, sku: \"HNG-220\" }, { price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 0.85, qty: 298n, sku: \"BLT-045\" }] },\n { id: 1012n, customer_id: \"C02\", discount: none, total: 1109.6, status: variant(\"shipped\", { date: new Date(\"2026-04-01T08:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 46.0, qty: 19n, sku: \"PLT-310\" }] },\n { id: 1013n, customer_id: \"C08\", discount: some(0.05), total: 311.37, status: variant(\"shipped\", { date: new Date(\"2026-04-27T10:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 4n, sku: \"RAL-900\" }, { price: 0.32, qty: 218n, sku: \"SCR-012\" }] },\n { id: 1014n, customer_id: \"C07\", discount: none, total: 1765.97, status: variant(\"shipped\", { date: new Date(\"2026-03-09T08:00:00.000Z\") }),\n lines: [{ price: 46.0, qty: 30n, sku: \"PLT-310\" }, { price: 0.18, qty: 254n, sku: \"WSH-008\" }, { price: 0.85, qty: 269n, sku: \"BLT-045\" }, { price: 12.4, qty: 9n, sku: \"BRK-100\" }] },\n { id: 1015n, customer_id: \"C03\", discount: none, total: 3646.84, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 19n, sku: \"PLT-310\" }, { price: 64.5, qty: 26n, sku: \"RAL-900\" }, { price: 3.75, qty: 276n, sku: \"CLP-150\" }, { price: 0.18, qty: 338n, sku: \"WSH-008\" }] },\n { id: 1016n, customer_id: \"C02\", discount: none, total: 1882.9, status: variant(\"pending\", null),\n lines: [{ price: 12.4, qty: 1n, sku: \"BRK-100\" }, { price: 64.5, qty: 29n, sku: \"RAL-900\" }] },\n { id: 1017n, customer_id: \"C02\", discount: some(0.05), total: 2005.59, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 89n, sku: \"BLT-045\" }, { price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 64.5, qty: 23n, sku: \"RAL-900\" }] },\n { id: 1018n, customer_id: \"C03\", discount: none, total: 1372.99, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 26n, sku: \"PLT-310\" }, { price: 0.18, qty: 138n, sku: \"WSH-008\" }, { price: 0.85, qty: 179n, sku: \"BLT-045\" }] },\n { id: 1019n, customer_id: \"C05\", discount: none, total: 684.65, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 301n, sku: \"BLT-045\" }, { price: 12.4, qty: 26n, sku: \"BRK-100\" }, { price: 8.9, qty: 8n, sku: \"HNG-220\" }, { price: 0.32, qty: 110n, sku: \"SCR-012\" }] },\n { id: 1020n, customer_id: \"C01\", discount: some(0.05), total: 297.01, status: variant(\"shipped\", { date: new Date(\"2026-02-06T11:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 75n, sku: \"SCR-012\" }, { price: 0.18, qty: 88n, sku: \"WSH-008\" }, { price: 12.4, qty: 22n, sku: \"BRK-100\" }] },\n { id: 1021n, customer_id: \"C07\", discount: none, total: 1225.5, status: variant(\"shipped\", { date: new Date(\"2026-05-18T14:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 19n, sku: \"RAL-900\" }] },\n { id: 1022n, customer_id: \"C07\", discount: some(0.15), total: 36.26, status: variant(\"shipped\", { date: new Date(\"2026-01-03T10:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 237n, sku: \"WSH-008\" }] },\n { id: 1023n, customer_id: \"C01\", discount: some(0.1), total: 1352.32, status: variant(\"shipped\", { date: new Date(\"2026-01-08T12:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 32n, sku: \"SCR-012\" }, { price: 8.9, qty: 13n, sku: \"HNG-220\" }, { price: 0.18, qty: 123n, sku: \"WSH-008\" }, { price: 64.5, qty: 21n, sku: \"RAL-900\" }] },\n { id: 1024n, customer_id: \"C05\", discount: some(0.05), total: 623.52, status: variant(\"cancelled\", { reason: \"Customer request\" }),\n lines: [{ price: 46.0, qty: 4n, sku: \"PLT-310\" }, { price: 0.18, qty: 209n, sku: \"WSH-008\" }, { price: 0.32, qty: 351n, sku: \"SCR-012\" }, { price: 12.4, qty: 26n, sku: \"BRK-100\" }] },\n { id: 1025n, customer_id: \"C01\", discount: some(0.1), total: 2577.23, status: variant(\"cancelled\", { reason: \"Payment failed\" }),\n lines: [{ price: 0.18, qty: 213n, sku: \"WSH-008\" }, { price: 64.5, qty: 27n, sku: \"RAL-900\" }, { price: 3.75, qty: 289n, sku: \"CLP-150\" }] },\n { id: 1026n, customer_id: \"C03\", discount: none, total: 1913.4, status: variant(\"shipped\", { date: new Date(\"2026-03-07T08:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 354n, sku: \"BLT-045\" }, { price: 64.5, qty: 25n, sku: \"RAL-900\" }] },\n { id: 1027n, customer_id: \"C08\", discount: none, total: 808.19, status: variant(\"shipped\", { date: new Date(\"2026-06-26T10:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 3n, sku: \"BLT-045\" }, { price: 8.9, qty: 25n, sku: \"HNG-220\" }, { price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 0.18, qty: 373n, sku: \"WSH-008\" }] },\n { id: 1028n, customer_id: \"C06\", discount: none, total: 173.45, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 47n, sku: \"BLT-045\" }, { price: 8.9, qty: 15n, sku: \"HNG-220\" }] },\n { id: 1029n, customer_id: \"C05\", discount: none, total: 64.96, status: variant(\"shipped\", { date: new Date(\"2026-03-19T16:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 203n, sku: \"SCR-012\" }] },\n { id: 1030n, customer_id: \"C03\", discount: none, total: 913.36, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 380n, sku: \"BLT-045\" }, { price: 3.75, qty: 4n, sku: \"CLP-150\" }, { price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 0.32, qty: 73n, sku: \"SCR-012\" }] },\n { id: 1031n, customer_id: \"C06\", discount: none, total: 1537.52, status: variant(\"shipped\", { date: new Date(\"2026-05-31T13:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 264n, sku: \"WSH-008\" }, { price: 12.4, qty: 20n, sku: \"BRK-100\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1032n, customer_id: \"C02\", discount: none, total: 1892.81, status: variant(\"cancelled\", { reason: \"Out of stock\" }),\n lines: [{ price: 46.0, qty: 26n, sku: \"PLT-310\" }, { price: 3.75, qty: 183n, sku: \"CLP-150\" }, { price: 0.32, qty: 33n, sku: \"SCR-012\" }] },\n { id: 1033n, customer_id: \"C01\", discount: none, total: 1834.15, status: variant(\"pending\", null),\n lines: [{ price: 64.5, qty: 27n, sku: \"RAL-900\" }, { price: 0.85, qty: 109n, sku: \"BLT-045\" }] },\n { id: 1034n, customer_id: \"C03\", discount: none, total: 323.06, status: variant(\"pending\", null),\n lines: [{ price: 0.32, qty: 140n, sku: \"SCR-012\" }, { price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 0.18, qty: 237n, sku: \"WSH-008\" }] },\n { id: 1035n, customer_id: \"C06\", discount: none, total: 2381.61, status: variant(\"shipped\", { date: new Date(\"2026-06-01T14:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 292n, sku: \"WSH-008\" }, { price: 3.75, qty: 279n, sku: \"CLP-150\" }, { price: 0.85, qty: 48n, sku: \"BLT-045\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1036n, customer_id: \"C01\", discount: some(0.05), total: 1041.68, status: variant(\"shipped\", { date: new Date(\"2026-05-26T13:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 17n, sku: \"RAL-900\" }] },\n { id: 1037n, customer_id: \"C08\", discount: none, total: 774.5, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 8.9, qty: 25n, sku: \"HNG-220\" }] },\n { id: 1038n, customer_id: \"C01\", discount: none, total: 1758.0, status: variant(\"shipped\", { date: new Date(\"2025-10-28T08:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1039n, customer_id: \"C06\", discount: none, total: 471.06, status: variant(\"shipped\", { date: new Date(\"2026-04-04T13:00:00.000Z\") }),\n lines: [{ price: 8.9, qty: 15n, sku: \"HNG-220\" }, { price: 0.18, qty: 222n, sku: \"WSH-008\" }, { price: 12.4, qty: 24n, sku: \"BRK-100\" }] },\n { id: 1040n, customer_id: \"C02\", discount: none, total: 884.1, status: variant(\"shipped\", { date: new Date(\"2025-12-08T14:00:00.000Z\") }),\n lines: [{ price: 46.0, qty: 14n, sku: \"PLT-310\" }, { price: 8.9, qty: 18n, sku: \"HNG-220\" }, { price: 0.85, qty: 94n, sku: \"BLT-045\" }] },\n]));\n\n/** The customers, by id. */\nexport const customers = e3.input(\"customers\", DictType(StringType, Customer), variant(\"value\", new SortedMap([\n [\"C01\", { name: \"Harbour Foods\", region: \"NSW\", tier: variant(\"gold\", null) }],\n [\"C02\", { name: \"Coastline Retail\", region: \"NSW\", tier: variant(\"standard\", null) }],\n [\"C03\", { name: \"Ridge Grocers\", region: \"VIC\", tier: variant(\"gold\", null) }],\n [\"C04\", { name: \"Southbank Market\", region: \"VIC\", tier: variant(\"standard\", null) }],\n [\"C05\", { name: \"Sunfield Traders\", region: \"QLD\", tier: variant(\"standard\", null) }],\n [\"C06\", { name: \"Northgate Supply\", region: \"QLD\", tier: variant(\"gold\", null) }],\n [\"C07\", { name: \"Westend Provisions\", region: \"WA\", tier: variant(\"standard\", null) }],\n [\"C08\", { name: \"Ironbark Stores\", region: \"SA\", tier: variant(\"standard\", null) }],\n], compareFor(StringType))));\n\n/** A record no query has been saved to yet. */\nexport const queriesEmpty = e3.record(\"queries_empty\", Query.Types.Saved, {\n initial: new SortedMap([], compareFor(StringType)),\n mutations: (mutation) => ({\n // Its one write.\n patch: mutation.patch(),\n }),\n});\n\nEast.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const saved = $.let(Record.bind(queriesEmpty));\n const orderRows = $.let(Data.bind(orders));\n const customerRows = $.let(Data.bind(customers));\n // The open query is the surface's: a new query on orders to begin with.\n const open = $.let(State.bind([Query.Types.Open], \"ex.queryBuilderEmpty.open\", Query.open.on(\"orders\")));\n const go = $.const(East.function([Query.Types.Open], NullType, ($2, next) => { $2(open.write(next)); }));\n return (\n <Box height=\"560px\">\n <Query.Builder queries={saved} query={open.read()} onOpen={go} id=\"empty\" datasets={{ orders: orderRows, customers: customerRows }} />\n </Box>\n );\n }}</Reactive>\n ))"
45521
45576
  },
45522
45577
  {
45523
45578
  "id": "e3-ui:query.examples.tsx:queryConflicts",
@@ -45548,7 +45603,7 @@
45548
45603
  "languages": [
45549
45604
  "tsx"
45550
45605
  ],
45551
- "source": "// Your edits meeting someone else's save, in one window — change the query, then press Someone else saves, which saves the same query again from elsewhere; the query builder has no conflicts to choose: your edit goes out of date, its banner saying so with Discard, your edit shown until you discard it\n// inputs: []\n/** One line of an order: a SKU, its unit price and the quantity ordered. */\nconst Line = StructType({ price: FloatType, qty: IntegerType, sku: StringType });\n\n/** Where an order stands: cancelled for a reason, pending, or shipped on a date. */\nconst Status = VariantType({ cancelled: StructType({ reason: StringType }), pending: NullType, shipped: StructType({ date: DateTimeType }) });\n\n/** An order: `discount` is the fraction taken off, when there is one, and `total` the lines' gross less it, to the cent. */\nconst Order = StructType({\n customer_id: StringType, discount: OptionType(FloatType), id: IntegerType, lines: ArrayType(Line), status: Status, total: FloatType,\n});\n\n/** A customer's tier. */\nconst Tier = VariantType({ gold: NullType, standard: NullType });\n\n/** A customer, and their tier. */\nconst Customer = StructType({ name: StringType, region: StringType, tier: Tier });\n\n/** Weekly demand by region: eight weeks, the first at index 0. */\nconst Forecast = StructType({ regions: DictType(StringType, StructType({ weekly: ArrayType(FloatType) })) });\n\n/** A part and the parts it is built from: a bill of materials. */\nconst Part = RecursiveType(self => StructType({ children: ArrayType(self), cost: FloatType, sku: StringType }));\n\n/** The demand model: units sold at a unit price in a region. */\nconst ModelInput = StructType({ price: FloatType, region: StringType });\n\nconst Model = FunctionType([ModelInput], FloatType);\n\n/** The orders, ids 1001–1040, in id order: the mock's forty, drawn from seed 875 (`Query Editor Spec.md` §6). */\nexport const orders = e3.input(\"orders\", ArrayType(Order), variant(\"value\", [\n { id: 1001n, customer_id: \"C01\", discount: some(0.1), total: 80.1, status: variant(\"shipped\", { date: new Date(\"2026-04-27T09:00:00.000Z\") }),\n lines: [{ price: 8.9, qty: 10n, sku: \"HNG-220\" }] },\n { id: 1002n, customer_id: \"C07\", discount: none, total: 1171.58, status: variant(\"shipped\", { date: new Date(\"2026-01-15T16:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 38n, sku: \"BLT-045\" }, { price: 46.0, qty: 24n, sku: \"PLT-310\" }, { price: 0.18, qty: 196n, sku: \"WSH-008\" }] },\n { id: 1003n, customer_id: \"C02\", discount: none, total: 453.0, status: variant(\"shipped\", { date: new Date(\"2026-04-06T16:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 15n, sku: \"BRK-100\" }, { price: 8.9, qty: 30n, sku: \"HNG-220\" }] },\n { id: 1004n, customer_id: \"C05\", discount: some(0.15), total: 128.61, status: variant(\"pending\", null),\n lines: [{ price: 8.9, qty: 17n, sku: \"HNG-220\" }] },\n { id: 1005n, customer_id: \"C02\", discount: none, total: 520.24, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 6n, sku: \"PLT-310\" }, { price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 0.18, qty: 48n, sku: \"WSH-008\" }] },\n { id: 1006n, customer_id: \"C06\", discount: none, total: 210.8, status: variant(\"shipped\", { date: new Date(\"2026-06-03T14:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 17n, sku: \"BRK-100\" }] },\n { id: 1007n, customer_id: \"C05\", discount: some(0.1), total: 1162.92, status: variant(\"shipped\", { date: new Date(\"2026-04-06T09:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 184n, sku: \"SCR-012\" }, { price: 64.5, qty: 5n, sku: \"RAL-900\" }, { price: 46.0, qty: 7n, sku: \"PLT-310\" }, { price: 3.75, qty: 157n, sku: \"CLP-150\" }] },\n { id: 1008n, customer_id: \"C05\", discount: none, total: 1280.3, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 143n, sku: \"BLT-045\" }, { price: 64.5, qty: 10n, sku: \"RAL-900\" }, { price: 3.75, qty: 137n, sku: \"CLP-150\" }] },\n { id: 1009n, customer_id: \"C04\", discount: some(0.05), total: 409.51, status: variant(\"shipped\", { date: new Date(\"2025-11-18T09:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 6n, sku: \"RAL-900\" }, { price: 0.18, qty: 211n, sku: \"WSH-008\" }, { price: 0.32, qty: 19n, sku: \"SCR-012\" }] },\n { id: 1010n, customer_id: \"C05\", discount: some(0.05), total: 142.23, status: variant(\"shipped\", { date: new Date(\"2025-10-14T12:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 189n, sku: \"WSH-008\" }, { price: 8.9, qty: 13n, sku: \"HNG-220\" }] },\n { id: 1011n, customer_id: \"C08\", discount: none, total: 1027.4, status: variant(\"pending\", null),\n lines: [{ price: 8.9, qty: 29n, sku: \"HNG-220\" }, { price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 0.85, qty: 298n, sku: \"BLT-045\" }] },\n { id: 1012n, customer_id: \"C02\", discount: none, total: 1109.6, status: variant(\"shipped\", { date: new Date(\"2026-04-01T08:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 46.0, qty: 19n, sku: \"PLT-310\" }] },\n { id: 1013n, customer_id: \"C08\", discount: some(0.05), total: 311.37, status: variant(\"shipped\", { date: new Date(\"2026-04-27T10:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 4n, sku: \"RAL-900\" }, { price: 0.32, qty: 218n, sku: \"SCR-012\" }] },\n { id: 1014n, customer_id: \"C07\", discount: none, total: 1765.97, status: variant(\"shipped\", { date: new Date(\"2026-03-09T08:00:00.000Z\") }),\n lines: [{ price: 46.0, qty: 30n, sku: \"PLT-310\" }, { price: 0.18, qty: 254n, sku: \"WSH-008\" }, { price: 0.85, qty: 269n, sku: \"BLT-045\" }, { price: 12.4, qty: 9n, sku: \"BRK-100\" }] },\n { id: 1015n, customer_id: \"C03\", discount: none, total: 3646.84, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 19n, sku: \"PLT-310\" }, { price: 64.5, qty: 26n, sku: \"RAL-900\" }, { price: 3.75, qty: 276n, sku: \"CLP-150\" }, { price: 0.18, qty: 338n, sku: \"WSH-008\" }] },\n { id: 1016n, customer_id: \"C02\", discount: none, total: 1882.9, status: variant(\"pending\", null),\n lines: [{ price: 12.4, qty: 1n, sku: \"BRK-100\" }, { price: 64.5, qty: 29n, sku: \"RAL-900\" }] },\n { id: 1017n, customer_id: \"C02\", discount: some(0.05), total: 2005.59, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 89n, sku: \"BLT-045\" }, { price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 64.5, qty: 23n, sku: \"RAL-900\" }] },\n { id: 1018n, customer_id: \"C03\", discount: none, total: 1372.99, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 26n, sku: \"PLT-310\" }, { price: 0.18, qty: 138n, sku: \"WSH-008\" }, { price: 0.85, qty: 179n, sku: \"BLT-045\" }] },\n { id: 1019n, customer_id: \"C05\", discount: none, total: 684.65, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 301n, sku: \"BLT-045\" }, { price: 12.4, qty: 26n, sku: \"BRK-100\" }, { price: 8.9, qty: 8n, sku: \"HNG-220\" }, { price: 0.32, qty: 110n, sku: \"SCR-012\" }] },\n { id: 1020n, customer_id: \"C01\", discount: some(0.05), total: 297.01, status: variant(\"shipped\", { date: new Date(\"2026-02-06T11:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 75n, sku: \"SCR-012\" }, { price: 0.18, qty: 88n, sku: \"WSH-008\" }, { price: 12.4, qty: 22n, sku: \"BRK-100\" }] },\n { id: 1021n, customer_id: \"C07\", discount: none, total: 1225.5, status: variant(\"shipped\", { date: new Date(\"2026-05-18T14:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 19n, sku: \"RAL-900\" }] },\n { id: 1022n, customer_id: \"C07\", discount: some(0.15), total: 36.26, status: variant(\"shipped\", { date: new Date(\"2026-01-03T10:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 237n, sku: \"WSH-008\" }] },\n { id: 1023n, customer_id: \"C01\", discount: some(0.1), total: 1352.32, status: variant(\"shipped\", { date: new Date(\"2026-01-08T12:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 32n, sku: \"SCR-012\" }, { price: 8.9, qty: 13n, sku: \"HNG-220\" }, { price: 0.18, qty: 123n, sku: \"WSH-008\" }, { price: 64.5, qty: 21n, sku: \"RAL-900\" }] },\n { id: 1024n, customer_id: \"C05\", discount: some(0.05), total: 623.52, status: variant(\"cancelled\", { reason: \"Customer request\" }),\n lines: [{ price: 46.0, qty: 4n, sku: \"PLT-310\" }, { price: 0.18, qty: 209n, sku: \"WSH-008\" }, { price: 0.32, qty: 351n, sku: \"SCR-012\" }, { price: 12.4, qty: 26n, sku: \"BRK-100\" }] },\n { id: 1025n, customer_id: \"C01\", discount: some(0.1), total: 2577.23, status: variant(\"cancelled\", { reason: \"Payment failed\" }),\n lines: [{ price: 0.18, qty: 213n, sku: \"WSH-008\" }, { price: 64.5, qty: 27n, sku: \"RAL-900\" }, { price: 3.75, qty: 289n, sku: \"CLP-150\" }] },\n { id: 1026n, customer_id: \"C03\", discount: none, total: 1913.4, status: variant(\"shipped\", { date: new Date(\"2026-03-07T08:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 354n, sku: \"BLT-045\" }, { price: 64.5, qty: 25n, sku: \"RAL-900\" }] },\n { id: 1027n, customer_id: \"C08\", discount: none, total: 808.19, status: variant(\"shipped\", { date: new Date(\"2026-06-26T10:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 3n, sku: \"BLT-045\" }, { price: 8.9, qty: 25n, sku: \"HNG-220\" }, { price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 0.18, qty: 373n, sku: \"WSH-008\" }] },\n { id: 1028n, customer_id: \"C06\", discount: none, total: 173.45, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 47n, sku: \"BLT-045\" }, { price: 8.9, qty: 15n, sku: \"HNG-220\" }] },\n { id: 1029n, customer_id: \"C05\", discount: none, total: 64.96, status: variant(\"shipped\", { date: new Date(\"2026-03-19T16:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 203n, sku: \"SCR-012\" }] },\n { id: 1030n, customer_id: \"C03\", discount: none, total: 913.36, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 380n, sku: \"BLT-045\" }, { price: 3.75, qty: 4n, sku: \"CLP-150\" }, { price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 0.32, qty: 73n, sku: \"SCR-012\" }] },\n { id: 1031n, customer_id: \"C06\", discount: none, total: 1537.52, status: variant(\"shipped\", { date: new Date(\"2026-05-31T13:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 264n, sku: \"WSH-008\" }, { price: 12.4, qty: 20n, sku: \"BRK-100\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1032n, customer_id: \"C02\", discount: none, total: 1892.81, status: variant(\"cancelled\", { reason: \"Out of stock\" }),\n lines: [{ price: 46.0, qty: 26n, sku: \"PLT-310\" }, { price: 3.75, qty: 183n, sku: \"CLP-150\" }, { price: 0.32, qty: 33n, sku: \"SCR-012\" }] },\n { id: 1033n, customer_id: \"C01\", discount: none, total: 1834.15, status: variant(\"pending\", null),\n lines: [{ price: 64.5, qty: 27n, sku: \"RAL-900\" }, { price: 0.85, qty: 109n, sku: \"BLT-045\" }] },\n { id: 1034n, customer_id: \"C03\", discount: none, total: 323.06, status: variant(\"pending\", null),\n lines: [{ price: 0.32, qty: 140n, sku: \"SCR-012\" }, { price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 0.18, qty: 237n, sku: \"WSH-008\" }] },\n { id: 1035n, customer_id: \"C06\", discount: none, total: 2381.61, status: variant(\"shipped\", { date: new Date(\"2026-06-01T14:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 292n, sku: \"WSH-008\" }, { price: 3.75, qty: 279n, sku: \"CLP-150\" }, { price: 0.85, qty: 48n, sku: \"BLT-045\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1036n, customer_id: \"C01\", discount: some(0.05), total: 1041.68, status: variant(\"shipped\", { date: new Date(\"2026-05-26T13:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 17n, sku: \"RAL-900\" }] },\n { id: 1037n, customer_id: \"C08\", discount: none, total: 774.5, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 8.9, qty: 25n, sku: \"HNG-220\" }] },\n { id: 1038n, customer_id: \"C01\", discount: none, total: 1758.0, status: variant(\"shipped\", { date: new Date(\"2025-10-28T08:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1039n, customer_id: \"C06\", discount: none, total: 471.06, status: variant(\"shipped\", { date: new Date(\"2026-04-04T13:00:00.000Z\") }),\n lines: [{ price: 8.9, qty: 15n, sku: \"HNG-220\" }, { price: 0.18, qty: 222n, sku: \"WSH-008\" }, { price: 12.4, qty: 24n, sku: \"BRK-100\" }] },\n { id: 1040n, customer_id: \"C02\", discount: none, total: 884.1, status: variant(\"shipped\", { date: new Date(\"2025-12-08T14:00:00.000Z\") }),\n lines: [{ price: 46.0, qty: 14n, sku: \"PLT-310\" }, { price: 8.9, qty: 18n, sku: \"HNG-220\" }, { price: 0.85, qty: 94n, sku: \"BLT-045\" }] },\n]));\n\n/** The customers, by id. */\nexport const customers = e3.input(\"customers\", DictType(StringType, Customer), variant(\"value\", new SortedMap([\n [\"C01\", { name: \"Harbour Foods\", region: \"NSW\", tier: variant(\"gold\", null) }],\n [\"C02\", { name: \"Coastline Retail\", region: \"NSW\", tier: variant(\"standard\", null) }],\n [\"C03\", { name: \"Ridge Grocers\", region: \"VIC\", tier: variant(\"gold\", null) }],\n [\"C04\", { name: \"Southbank Market\", region: \"VIC\", tier: variant(\"standard\", null) }],\n [\"C05\", { name: \"Sunfield Traders\", region: \"QLD\", tier: variant(\"standard\", null) }],\n [\"C06\", { name: \"Northgate Supply\", region: \"QLD\", tier: variant(\"gold\", null) }],\n [\"C07\", { name: \"Westend Provisions\", region: \"WA\", tier: variant(\"standard\", null) }],\n [\"C08\", { name: \"Ironbark Stores\", region: \"SA\", tier: variant(\"standard\", null) }],\n], compareFor(StringType))));\n\n/** Weekly demand by region: eight weeks of `base × (0.9 + 0.03w + 0.01i)`, to one place, for the region at index i of NSW, VIC, QLD, WA, SA. */\nexport const forecast = e3.input(\"forecast\", Forecast, variant(\"value\", {\n regions: new SortedMap([\n [\"NSW\", { weekly: [1080.0, 1116.0, 1152.0, 1188.0, 1224.0, 1260.0, 1296.0, 1332.0] }],\n [\"QLD\", { weekly: [791.2, 817.0, 842.8, 868.6, 894.4, 920.2, 946.0, 971.8] }],\n [\"SA\", { weekly: [385.4, 397.7, 410.0, 422.3, 434.6, 446.9, 459.2, 471.5] }],\n [\"VIC\", { weekly: [955.5, 987.0, 1018.5, 1050.0, 1081.5, 1113.0, 1144.5, 1176.0] }],\n [\"WA\", { weekly: [502.2, 518.4, 534.6, 550.8, 567.0, 583.2, 599.4, 615.6] }],\n ], compareFor(StringType)),\n}));\n\n/** The demand model, `round₂(base[region] × (price / 10)^−1.4)`: the units sold at a unit price in a region. */\nconst demandModel = East.function([ModelInput], FloatType, ($, input) => {\n const base = $.const(new SortedMap([[\"NSW\", 1200.0], [\"QLD\", 860.0], [\"SA\", 410.0], [\"VIC\", 1050.0], [\"WA\", 540.0]], compareFor(StringType)), DictType(StringType, FloatType));\n // A region the model does not know has a base of 300.\n const demand = base.get(input.region, () => 300.0).multiply(input.price.divide(10.0).pow(-1.4));\n const cents = $.const(demand.multiply(100.0).add(0.5));\n return cents.subtract(cents.remainder(1.0)).divide(100.0);\n});\n\n/** The demand model as data: an East function every runtime can call, which a query tries over a range. */\nexport const model = e3.input(\"model\", Model, variant(\"value\", East.compile(demandModel, [])));\n\n/** The bill of materials for PUMP-A. */\nexport const bom = e3.input(\"bom\", Part, variant(\"value\", {\n sku: \"PUMP-A\", cost: 42.0, children: [\n { sku: \"MOTOR-1\", cost: 120.0, children: [\n { sku: \"ROTOR-1\", cost: 18.5, children: [] }, { sku: \"STATOR-1\", cost: 22.0, children: [] }, { sku: \"BRG-6203\", cost: 3.2, children: [] },\n ] },\n { sku: \"HOUSING-2\", cost: 35.0, children: [{ sku: \"GASKET-9\", cost: 1.1, children: [] }, { sku: \"BOLT-M8\", cost: 0.4, children: [] }] },\n { sku: \"IMPELLER-3\", cost: 27.5, children: [] },\n { sku: \"SEAL-KIT\", cost: 6.8, children: [{ sku: \"ORING-12\", cost: 0.3, children: [] }, { sku: \"ORING-18\", cost: 0.35, children: [] }] },\n ],\n}));\n\n/**\n * The saved queries record: the mock's seven (`Query Editor Spec.md` §6),\n * each its canonical jq — what the builder's steps print — checked against the\n * data sources the builders bind when the package builds, and described where\n * the mock describes it; the rest describe themselves.\n */\nexport const queries = e3.record(\"queries\", Query.Types.Saved, {\n initial: Query.value({ orders, customers, forecast, model, bom }, [\n {\n name: \"Top shipped orders, 2026\",\n jq: `.customers as $customers\n | .orders\n | map(select(.status.type == \"shipped\") | select(.total >= 100 and (.status.value.date | year) == 2026))\n | map(. + {name: $customers[.customer_id].name, region: $customers[.customer_id].region})\n | map({order: .id, customer: .name, region, total, shipped: .status.value.date})\n | sort_by(-.total)\n | .[:10]`,\n savedAt: new Date(\"2026-10-01T09:00:00Z\"),\n },\n {\n name: \"Revenue by region\",\n jq: `.customers as $customers\n | .orders\n | map(select(.status.type == \"shipped\") | select(.total >= 100 and (.status.value.date | year) == 2026))\n | map(. + {region: $customers[.customer_id].region})\n | group_by(.region)\n | map({region: .[0].region, revenue: map(.total) | add, orders: length})\n | sort_by(-.revenue)\n | .[:3]`,\n description: \"Top 3 regions by shipped revenue in 2026, from orders of $100 or more.\",\n savedAt: new Date(\"2026-09-29T09:00:00Z\"),\n },\n {\n name: \"Shipped revenue by month\",\n jq: `.orders\n | map(select(.status.type == \"shipped\"))\n | map(. + {ship_month: .status.value.date | strftime(\"%Y-%m\")})\n | group_by(.ship_month)\n | map({ship_month: .[0].ship_month, revenue: map(.total) | add, orders: length})\n | sort_by(.ship_month)`,\n savedAt: new Date(\"2026-09-12T09:00:00Z\"),\n },\n {\n name: \"Large orders with no discount\",\n jq: `.orders\n | map(select(.total >= 1000 and .discount == null))\n | map({id, customer_id, total, status})\n | sort_by(-.total)`,\n savedAt: new Date(\"2026-09-03T09:00:00Z\"),\n },\n {\n name: \"Units by SKU\",\n jq: `.orders\n | [.[] | . as $order | .lines[] | . + {order_id: $order.id}]\n | group_by(.sku)\n | map({sku: .[0].sku, units: map(.qty) | add, orders: map(.order_id) | unique | length})\n | sort_by(-.units)`,\n savedAt: new Date(\"2026-08-28T09:00:00Z\"),\n },\n {\n name: \"Pump parts cost\",\n jq: `.bom\n | [recurse(.children[]) | {cost, sku}]\n | {total_cost: map(.cost) | add, parts: length, dearest: map(.cost) | max}`,\n description: \"Total cost, part count and dearest part in the PUMP-A bill of materials.\",\n savedAt: new Date(\"2026-08-20T09:00:00Z\"),\n },\n {\n name: \"Demand at $10–$12, NSW\",\n jq: `.model\n | [range(10.0; 12.0 + 0.5 / 2; 0.5) as $price | {price: $price, demand: call(.; {price: $price, region: \"NSW\"})}]`,\n description: \"Modelled demand in NSW at prices from $10 to $12, in $0.50 steps.\",\n savedAt: new Date(\"2026-08-14T09:00:00Z\"),\n },\n ]),\n mutations: (mutation) => ({\n // The record's one write.\n patch: mutation.patch(),\n }),\n});\n\n/** The saved queries the conflicts example edits, as the builder's start, in a record of their own so no other example's edits meet them. */\nexport const conflictQueries = e3.record(\"query_conflict_queries\", Query.Types.Saved, {\n initial: queries.default!,\n mutations: (mutation) => ({\n // The record's one write.\n patch: mutation.patch(),\n // Someone else's save: every query saved again, its description theirs and saved a minute after it was.\n elsewhere: mutation.reduce(East.function([Query.Types.Saved], Query.Types.Saved, (_$, saved) =>\n saved.map((_$2, query) => ({\n name: query.name,\n description: East.value(some(\"Saved again by someone else\"), OptionType(StringType)),\n program: query.program,\n root: query.root,\n saved_at: query.saved_at.addMinutes(1n),\n })))),\n }),\n});\n\nEast.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const saved = $.let(Record.bind(conflictQueries, [\"patch\"]));\n const others = $.let(Record.bind(conflictQueries, [\"elsewhere\"]));\n const theirs = $.const(East.function([], NullType, ($) => { $(others.mutate.elsewhere()); }));\n const orderRows = $.let(Data.bind(orders));\n const customerRows = $.let(Data.bind(customers));\n const weekly = $.let(Data.bind(forecast));\n const demand = $.let(Data.bind(model));\n const parts = $.let(Data.bind(bom));\n return (\n <VStack gap=\"3\" align=\"stretch\">\n <HStack gap=\"3\">\n <Button variant=\"outline\" onClick={theirs} loading={others.mutate.pending()}>Someone else saves</Button>\n <Text color=\"fg.muted\">Their change: the same query, saved again</Text>\n </HStack>\n <Box height=\"760px\">\n <Query.Builder queries={saved} query=\"Top shipped orders, 2026\" id=\"conflicts\"\n datasets={{ orders: orderRows, customers: customerRows, forecast: weekly, model: demand, bom: parts }} />\n </Box>\n </VStack>\n );\n }}</Reactive>\n ))"
45606
+ "source": "// Your edits meeting someone else's save, in one window — change the query, then press Someone else saves, which saves the same query again from elsewhere; the query builder has no conflicts to choose: your edit goes out of date, its banner saying so with Discard, your edit shown until you discard it\n// inputs: []\n/** One line of an order: a SKU, its unit price and the quantity ordered. */\nconst Line = StructType({ price: FloatType, qty: IntegerType, sku: StringType });\n\n/** Where an order stands: cancelled for a reason, pending, or shipped on a date. */\nconst Status = VariantType({ cancelled: StructType({ reason: StringType }), pending: NullType, shipped: StructType({ date: DateTimeType }) });\n\n/** An order: `discount` is the fraction taken off, when there is one, and `total` the lines' gross less it, to the cent. */\nconst Order = StructType({\n customer_id: StringType, discount: OptionType(FloatType), id: IntegerType, lines: ArrayType(Line), status: Status, total: FloatType,\n});\n\n/** A customer's tier. */\nconst Tier = VariantType({ gold: NullType, standard: NullType });\n\n/** A customer, and their tier. */\nconst Customer = StructType({ name: StringType, region: StringType, tier: Tier });\n\n/** Weekly demand by region: eight weeks, the first at index 0. */\nconst Forecast = StructType({ regions: DictType(StringType, StructType({ weekly: ArrayType(FloatType) })) });\n\n/** A part and the parts it is built from: a bill of materials. */\nconst Part = RecursiveType(self => StructType({ children: ArrayType(self), cost: FloatType, sku: StringType }));\n\n/** The demand model: units sold at a unit price in a region. */\nconst ModelInput = StructType({ price: FloatType, region: StringType });\n\nconst Model = FunctionType([ModelInput], FloatType);\n\n/** The orders, ids 1001–1040, in id order: the mock's forty, drawn from seed 875 (`Query Editor Spec.md` §6). */\nexport const orders = e3.input(\"orders\", ArrayType(Order), variant(\"value\", [\n { id: 1001n, customer_id: \"C01\", discount: some(0.1), total: 80.1, status: variant(\"shipped\", { date: new Date(\"2026-04-27T09:00:00.000Z\") }),\n lines: [{ price: 8.9, qty: 10n, sku: \"HNG-220\" }] },\n { id: 1002n, customer_id: \"C07\", discount: none, total: 1171.58, status: variant(\"shipped\", { date: new Date(\"2026-01-15T16:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 38n, sku: \"BLT-045\" }, { price: 46.0, qty: 24n, sku: \"PLT-310\" }, { price: 0.18, qty: 196n, sku: \"WSH-008\" }] },\n { id: 1003n, customer_id: \"C02\", discount: none, total: 453.0, status: variant(\"shipped\", { date: new Date(\"2026-04-06T16:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 15n, sku: \"BRK-100\" }, { price: 8.9, qty: 30n, sku: \"HNG-220\" }] },\n { id: 1004n, customer_id: \"C05\", discount: some(0.15), total: 128.61, status: variant(\"pending\", null),\n lines: [{ price: 8.9, qty: 17n, sku: \"HNG-220\" }] },\n { id: 1005n, customer_id: \"C02\", discount: none, total: 520.24, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 6n, sku: \"PLT-310\" }, { price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 0.18, qty: 48n, sku: \"WSH-008\" }] },\n { id: 1006n, customer_id: \"C06\", discount: none, total: 210.8, status: variant(\"shipped\", { date: new Date(\"2026-06-03T14:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 17n, sku: \"BRK-100\" }] },\n { id: 1007n, customer_id: \"C05\", discount: some(0.1), total: 1162.92, status: variant(\"shipped\", { date: new Date(\"2026-04-06T09:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 184n, sku: \"SCR-012\" }, { price: 64.5, qty: 5n, sku: \"RAL-900\" }, { price: 46.0, qty: 7n, sku: \"PLT-310\" }, { price: 3.75, qty: 157n, sku: \"CLP-150\" }] },\n { id: 1008n, customer_id: \"C05\", discount: none, total: 1280.3, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 143n, sku: \"BLT-045\" }, { price: 64.5, qty: 10n, sku: \"RAL-900\" }, { price: 3.75, qty: 137n, sku: \"CLP-150\" }] },\n { id: 1009n, customer_id: \"C04\", discount: some(0.05), total: 409.51, status: variant(\"shipped\", { date: new Date(\"2025-11-18T09:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 6n, sku: \"RAL-900\" }, { price: 0.18, qty: 211n, sku: \"WSH-008\" }, { price: 0.32, qty: 19n, sku: \"SCR-012\" }] },\n { id: 1010n, customer_id: \"C05\", discount: some(0.05), total: 142.23, status: variant(\"shipped\", { date: new Date(\"2025-10-14T12:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 189n, sku: \"WSH-008\" }, { price: 8.9, qty: 13n, sku: \"HNG-220\" }] },\n { id: 1011n, customer_id: \"C08\", discount: none, total: 1027.4, status: variant(\"pending\", null),\n lines: [{ price: 8.9, qty: 29n, sku: \"HNG-220\" }, { price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 0.85, qty: 298n, sku: \"BLT-045\" }] },\n { id: 1012n, customer_id: \"C02\", discount: none, total: 1109.6, status: variant(\"shipped\", { date: new Date(\"2026-04-01T08:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 46.0, qty: 19n, sku: \"PLT-310\" }] },\n { id: 1013n, customer_id: \"C08\", discount: some(0.05), total: 311.37, status: variant(\"shipped\", { date: new Date(\"2026-04-27T10:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 4n, sku: \"RAL-900\" }, { price: 0.32, qty: 218n, sku: \"SCR-012\" }] },\n { id: 1014n, customer_id: \"C07\", discount: none, total: 1765.97, status: variant(\"shipped\", { date: new Date(\"2026-03-09T08:00:00.000Z\") }),\n lines: [{ price: 46.0, qty: 30n, sku: \"PLT-310\" }, { price: 0.18, qty: 254n, sku: \"WSH-008\" }, { price: 0.85, qty: 269n, sku: \"BLT-045\" }, { price: 12.4, qty: 9n, sku: \"BRK-100\" }] },\n { id: 1015n, customer_id: \"C03\", discount: none, total: 3646.84, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 19n, sku: \"PLT-310\" }, { price: 64.5, qty: 26n, sku: \"RAL-900\" }, { price: 3.75, qty: 276n, sku: \"CLP-150\" }, { price: 0.18, qty: 338n, sku: \"WSH-008\" }] },\n { id: 1016n, customer_id: \"C02\", discount: none, total: 1882.9, status: variant(\"pending\", null),\n lines: [{ price: 12.4, qty: 1n, sku: \"BRK-100\" }, { price: 64.5, qty: 29n, sku: \"RAL-900\" }] },\n { id: 1017n, customer_id: \"C02\", discount: some(0.05), total: 2005.59, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 89n, sku: \"BLT-045\" }, { price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 64.5, qty: 23n, sku: \"RAL-900\" }] },\n { id: 1018n, customer_id: \"C03\", discount: none, total: 1372.99, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 26n, sku: \"PLT-310\" }, { price: 0.18, qty: 138n, sku: \"WSH-008\" }, { price: 0.85, qty: 179n, sku: \"BLT-045\" }] },\n { id: 1019n, customer_id: \"C05\", discount: none, total: 684.65, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 301n, sku: \"BLT-045\" }, { price: 12.4, qty: 26n, sku: \"BRK-100\" }, { price: 8.9, qty: 8n, sku: \"HNG-220\" }, { price: 0.32, qty: 110n, sku: \"SCR-012\" }] },\n { id: 1020n, customer_id: \"C01\", discount: some(0.05), total: 297.01, status: variant(\"shipped\", { date: new Date(\"2026-02-06T11:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 75n, sku: \"SCR-012\" }, { price: 0.18, qty: 88n, sku: \"WSH-008\" }, { price: 12.4, qty: 22n, sku: \"BRK-100\" }] },\n { id: 1021n, customer_id: \"C07\", discount: none, total: 1225.5, status: variant(\"shipped\", { date: new Date(\"2026-05-18T14:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 19n, sku: \"RAL-900\" }] },\n { id: 1022n, customer_id: \"C07\", discount: some(0.15), total: 36.26, status: variant(\"shipped\", { date: new Date(\"2026-01-03T10:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 237n, sku: \"WSH-008\" }] },\n { id: 1023n, customer_id: \"C01\", discount: some(0.1), total: 1352.32, status: variant(\"shipped\", { date: new Date(\"2026-01-08T12:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 32n, sku: \"SCR-012\" }, { price: 8.9, qty: 13n, sku: \"HNG-220\" }, { price: 0.18, qty: 123n, sku: \"WSH-008\" }, { price: 64.5, qty: 21n, sku: \"RAL-900\" }] },\n { id: 1024n, customer_id: \"C05\", discount: some(0.05), total: 623.52, status: variant(\"cancelled\", { reason: \"Customer request\" }),\n lines: [{ price: 46.0, qty: 4n, sku: \"PLT-310\" }, { price: 0.18, qty: 209n, sku: \"WSH-008\" }, { price: 0.32, qty: 351n, sku: \"SCR-012\" }, { price: 12.4, qty: 26n, sku: \"BRK-100\" }] },\n { id: 1025n, customer_id: \"C01\", discount: some(0.1), total: 2577.23, status: variant(\"cancelled\", { reason: \"Payment failed\" }),\n lines: [{ price: 0.18, qty: 213n, sku: \"WSH-008\" }, { price: 64.5, qty: 27n, sku: \"RAL-900\" }, { price: 3.75, qty: 289n, sku: \"CLP-150\" }] },\n { id: 1026n, customer_id: \"C03\", discount: none, total: 1913.4, status: variant(\"shipped\", { date: new Date(\"2026-03-07T08:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 354n, sku: \"BLT-045\" }, { price: 64.5, qty: 25n, sku: \"RAL-900\" }] },\n { id: 1027n, customer_id: \"C08\", discount: none, total: 808.19, status: variant(\"shipped\", { date: new Date(\"2026-06-26T10:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 3n, sku: \"BLT-045\" }, { price: 8.9, qty: 25n, sku: \"HNG-220\" }, { price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 0.18, qty: 373n, sku: \"WSH-008\" }] },\n { id: 1028n, customer_id: \"C06\", discount: none, total: 173.45, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 47n, sku: \"BLT-045\" }, { price: 8.9, qty: 15n, sku: \"HNG-220\" }] },\n { id: 1029n, customer_id: \"C05\", discount: none, total: 64.96, status: variant(\"shipped\", { date: new Date(\"2026-03-19T16:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 203n, sku: \"SCR-012\" }] },\n { id: 1030n, customer_id: \"C03\", discount: none, total: 913.36, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 380n, sku: \"BLT-045\" }, { price: 3.75, qty: 4n, sku: \"CLP-150\" }, { price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 0.32, qty: 73n, sku: \"SCR-012\" }] },\n { id: 1031n, customer_id: \"C06\", discount: none, total: 1537.52, status: variant(\"shipped\", { date: new Date(\"2026-05-31T13:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 264n, sku: \"WSH-008\" }, { price: 12.4, qty: 20n, sku: \"BRK-100\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1032n, customer_id: \"C02\", discount: none, total: 1892.81, status: variant(\"cancelled\", { reason: \"Out of stock\" }),\n lines: [{ price: 46.0, qty: 26n, sku: \"PLT-310\" }, { price: 3.75, qty: 183n, sku: \"CLP-150\" }, { price: 0.32, qty: 33n, sku: \"SCR-012\" }] },\n { id: 1033n, customer_id: \"C01\", discount: none, total: 1834.15, status: variant(\"pending\", null),\n lines: [{ price: 64.5, qty: 27n, sku: \"RAL-900\" }, { price: 0.85, qty: 109n, sku: \"BLT-045\" }] },\n { id: 1034n, customer_id: \"C03\", discount: none, total: 323.06, status: variant(\"pending\", null),\n lines: [{ price: 0.32, qty: 140n, sku: \"SCR-012\" }, { price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 0.18, qty: 237n, sku: \"WSH-008\" }] },\n { id: 1035n, customer_id: \"C06\", discount: none, total: 2381.61, status: variant(\"shipped\", { date: new Date(\"2026-06-01T14:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 292n, sku: \"WSH-008\" }, { price: 3.75, qty: 279n, sku: \"CLP-150\" }, { price: 0.85, qty: 48n, sku: \"BLT-045\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1036n, customer_id: \"C01\", discount: some(0.05), total: 1041.68, status: variant(\"shipped\", { date: new Date(\"2026-05-26T13:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 17n, sku: \"RAL-900\" }] },\n { id: 1037n, customer_id: \"C08\", discount: none, total: 774.5, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 8.9, qty: 25n, sku: \"HNG-220\" }] },\n { id: 1038n, customer_id: \"C01\", discount: none, total: 1758.0, status: variant(\"shipped\", { date: new Date(\"2025-10-28T08:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1039n, customer_id: \"C06\", discount: none, total: 471.06, status: variant(\"shipped\", { date: new Date(\"2026-04-04T13:00:00.000Z\") }),\n lines: [{ price: 8.9, qty: 15n, sku: \"HNG-220\" }, { price: 0.18, qty: 222n, sku: \"WSH-008\" }, { price: 12.4, qty: 24n, sku: \"BRK-100\" }] },\n { id: 1040n, customer_id: \"C02\", discount: none, total: 884.1, status: variant(\"shipped\", { date: new Date(\"2025-12-08T14:00:00.000Z\") }),\n lines: [{ price: 46.0, qty: 14n, sku: \"PLT-310\" }, { price: 8.9, qty: 18n, sku: \"HNG-220\" }, { price: 0.85, qty: 94n, sku: \"BLT-045\" }] },\n]));\n\n/** The customers, by id. */\nexport const customers = e3.input(\"customers\", DictType(StringType, Customer), variant(\"value\", new SortedMap([\n [\"C01\", { name: \"Harbour Foods\", region: \"NSW\", tier: variant(\"gold\", null) }],\n [\"C02\", { name: \"Coastline Retail\", region: \"NSW\", tier: variant(\"standard\", null) }],\n [\"C03\", { name: \"Ridge Grocers\", region: \"VIC\", tier: variant(\"gold\", null) }],\n [\"C04\", { name: \"Southbank Market\", region: \"VIC\", tier: variant(\"standard\", null) }],\n [\"C05\", { name: \"Sunfield Traders\", region: \"QLD\", tier: variant(\"standard\", null) }],\n [\"C06\", { name: \"Northgate Supply\", region: \"QLD\", tier: variant(\"gold\", null) }],\n [\"C07\", { name: \"Westend Provisions\", region: \"WA\", tier: variant(\"standard\", null) }],\n [\"C08\", { name: \"Ironbark Stores\", region: \"SA\", tier: variant(\"standard\", null) }],\n], compareFor(StringType))));\n\n/** Weekly demand by region: eight weeks of `base × (0.9 + 0.03w + 0.01i)`, to one place, for the region at index i of NSW, VIC, QLD, WA, SA. */\nexport const forecast = e3.input(\"forecast\", Forecast, variant(\"value\", {\n regions: new SortedMap([\n [\"NSW\", { weekly: [1080.0, 1116.0, 1152.0, 1188.0, 1224.0, 1260.0, 1296.0, 1332.0] }],\n [\"QLD\", { weekly: [791.2, 817.0, 842.8, 868.6, 894.4, 920.2, 946.0, 971.8] }],\n [\"SA\", { weekly: [385.4, 397.7, 410.0, 422.3, 434.6, 446.9, 459.2, 471.5] }],\n [\"VIC\", { weekly: [955.5, 987.0, 1018.5, 1050.0, 1081.5, 1113.0, 1144.5, 1176.0] }],\n [\"WA\", { weekly: [502.2, 518.4, 534.6, 550.8, 567.0, 583.2, 599.4, 615.6] }],\n ], compareFor(StringType)),\n}));\n\n/** The demand model, `round₂(base[region] × (price / 10)^−1.4)`: the units sold at a unit price in a region. */\nconst demandModel = East.function([ModelInput], FloatType, ($, input) => {\n const base = $.const(new SortedMap([[\"NSW\", 1200.0], [\"QLD\", 860.0], [\"SA\", 410.0], [\"VIC\", 1050.0], [\"WA\", 540.0]], compareFor(StringType)), DictType(StringType, FloatType));\n // A region the model does not know has a base of 300.\n const demand = base.get(input.region, () => 300.0).multiply(input.price.divide(10.0).pow(-1.4));\n const cents = $.const(demand.multiply(100.0).add(0.5));\n return cents.subtract(cents.remainder(1.0)).divide(100.0);\n});\n\n/** The demand model as data: an East function every runtime can call, which a query tries over a range. */\nexport const model = e3.input(\"model\", Model, variant(\"value\", East.compile(demandModel, [])));\n\n/** The bill of materials for PUMP-A. */\nexport const bom = e3.input(\"bom\", Part, variant(\"value\", {\n sku: \"PUMP-A\", cost: 42.0, children: [\n { sku: \"MOTOR-1\", cost: 120.0, children: [\n { sku: \"ROTOR-1\", cost: 18.5, children: [] }, { sku: \"STATOR-1\", cost: 22.0, children: [] }, { sku: \"BRG-6203\", cost: 3.2, children: [] },\n ] },\n { sku: \"HOUSING-2\", cost: 35.0, children: [{ sku: \"GASKET-9\", cost: 1.1, children: [] }, { sku: \"BOLT-M8\", cost: 0.4, children: [] }] },\n { sku: \"IMPELLER-3\", cost: 27.5, children: [] },\n { sku: \"SEAL-KIT\", cost: 6.8, children: [{ sku: \"ORING-12\", cost: 0.3, children: [] }, { sku: \"ORING-18\", cost: 0.35, children: [] }] },\n ],\n}));\n\n/**\n * The saved queries record: the mock's seven (`Query Editor Spec.md` §6),\n * each its canonical jq — what the builder's steps print — checked against the\n * data sources the builders bind when the package builds, and described where\n * the mock describes it; the rest describe themselves.\n */\nexport const queries = e3.record(\"queries\", Query.Types.Saved, {\n initial: Query.value({ orders, customers, forecast, model, bom }, [\n {\n name: \"Top shipped orders, 2026\",\n jq: `.customers as $customers\n | .orders\n | map(select(.status.type == \"shipped\") | select(.total >= 100 and (.status.value.date | year) == 2026))\n | map(. + {name: $customers[.customer_id].name, region: $customers[.customer_id].region})\n | map({order: .id, customer: .name, region, total, shipped: .status.value.date})\n | sort_by(-.total)\n | .[:10]`,\n savedAt: new Date(\"2026-10-01T09:00:00Z\"),\n },\n {\n name: \"Revenue by region\",\n jq: `.customers as $customers\n | .orders\n | map(select(.status.type == \"shipped\") | select(.total >= 100 and (.status.value.date | year) == 2026))\n | map(. + {region: $customers[.customer_id].region})\n | group_by(.region)\n | map({region: .[0].region, revenue: map(.total) | add, orders: length})\n | sort_by(-.revenue)\n | .[:3]`,\n description: \"Top 3 regions by shipped revenue in 2026, from orders of $100 or more.\",\n savedAt: new Date(\"2026-09-29T09:00:00Z\"),\n },\n {\n name: \"Shipped revenue by month\",\n jq: `.orders\n | map(select(.status.type == \"shipped\"))\n | map(. + {ship_month: .status.value.date | strftime(\"%Y-%m\")})\n | group_by(.ship_month)\n | map({ship_month: .[0].ship_month, revenue: map(.total) | add, orders: length})\n | sort_by(.ship_month)`,\n savedAt: new Date(\"2026-09-12T09:00:00Z\"),\n },\n {\n name: \"Large orders with no discount\",\n jq: `.orders\n | map(select(.total >= 1000 and .discount == null))\n | map({id, customer_id, total, status})\n | sort_by(-.total)`,\n savedAt: new Date(\"2026-09-03T09:00:00Z\"),\n },\n {\n name: \"Units by SKU\",\n jq: `.orders\n | [.[] | . as $order | .lines[] | . + {order_id: $order.id}]\n | group_by(.sku)\n | map({sku: .[0].sku, units: map(.qty) | add, orders: map(.order_id) | unique | length})\n | sort_by(-.units)`,\n savedAt: new Date(\"2026-08-28T09:00:00Z\"),\n },\n {\n name: \"Pump parts cost\",\n jq: `.bom\n | [recurse(.children[]) | {cost, sku}]\n | {total_cost: map(.cost) | add, parts: length, dearest: map(.cost) | max}`,\n description: \"Total cost, part count and dearest part in the PUMP-A bill of materials.\",\n savedAt: new Date(\"2026-08-20T09:00:00Z\"),\n },\n {\n name: \"Demand at $10–$12, NSW\",\n jq: `.model\n | [range(10.0; 12.0 + 0.5 / 2; 0.5) as $price | {price: $price, demand: call(.; {price: $price, region: \"NSW\"})}]`,\n description: \"Modelled demand in NSW at prices from $10 to $12, in $0.50 steps.\",\n savedAt: new Date(\"2026-08-14T09:00:00Z\"),\n },\n ]),\n mutations: (mutation) => ({\n // The record's one write.\n patch: mutation.patch(),\n }),\n});\n\n/** The saved queries the conflicts example edits, as the builder's start, in a record of their own so no other example's edits meet them. */\nexport const conflictQueries = e3.record(\"query_conflict_queries\", Query.Types.Saved, {\n initial: queries.default!,\n mutations: (mutation) => ({\n // The record's one write.\n patch: mutation.patch(),\n // Someone else's save: every query saved again, its description theirs and saved a minute after it was.\n elsewhere: mutation.reduce(East.function([Query.Types.Saved], Query.Types.Saved, (_$, saved) =>\n saved.map((_$2, query) => ({\n name: query.name,\n description: East.value(some(\"Saved again by someone else\"), OptionType(StringType)),\n program: query.program,\n root: query.root,\n saved_at: query.saved_at.addMinutes(1n),\n })))),\n }),\n});\n\nEast.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const saved = $.let(Record.bind(conflictQueries, [\"patch\"]));\n const others = $.let(Record.bind(conflictQueries, [\"elsewhere\"]));\n const theirs = $.const(East.function([], NullType, ($) => { $(others.mutate.elsewhere()); }));\n const orderRows = $.let(Data.bind(orders));\n const customerRows = $.let(Data.bind(customers));\n const weekly = $.let(Data.bind(forecast));\n const demand = $.let(Data.bind(model));\n const parts = $.let(Data.bind(bom));\n // The open query is the surface's: the builder shows it, and tells the surface when its own tabs ask for another.\n const open = $.let(State.bind([Query.Types.Open], \"ex.queryConflicts.open\", Query.open.saved(\"Top shipped orders, 2026\")));\n const go = $.const(East.function([Query.Types.Open], NullType, ($2, next) => { $2(open.write(next)); }));\n return (\n <VStack gap=\"3\" align=\"stretch\">\n <HStack gap=\"3\">\n <Button variant=\"outline\" onClick={theirs} loading={others.mutate.pending()}>Someone else saves</Button>\n <Text color=\"fg.muted\">Their change: the same query, saved again</Text>\n </HStack>\n <Box height=\"760px\">\n <Query.Builder queries={saved} query={open.read()} onOpen={go} id=\"conflicts\"\n datasets={{ orders: orderRows, customers: customerRows, forecast: weekly, model: demand, bom: parts }} />\n </Box>\n </VStack>\n );\n }}</Reactive>\n ))"
45552
45607
  },
45553
45608
  {
45554
45609
  "id": "e3-ui:query.examples.tsx:queryBuilderHistory",
@@ -45583,7 +45638,44 @@
45583
45638
  "languages": [
45584
45639
  "tsx"
45585
45640
  ],
45586
- "source": "// The builder over data too large for one call — an order history of 36,000 orders, the 20,000 accounts that place them and their credit limits, which e3 tasks generate when the dataflow runs, each bound by window and never downloaded — open on History revenue by region: the history joined with the accounts, both large, so the run re-keys it as two split calls, which the results footer's plan read-out says. Its other saved queries run as a split call over the history's pieces, and as a join of two lookups keyed alike, cut at the same keys\n// inputs: []\n/** One line of an order: a SKU, its unit price and the quantity ordered. */\nconst Line = StructType({ price: FloatType, qty: IntegerType, sku: StringType });\n\n/** Where an order stands: cancelled for a reason, pending, or shipped on a date. */\nconst Status = VariantType({ cancelled: StructType({ reason: StringType }), pending: NullType, shipped: StructType({ date: DateTimeType }) });\n\n/** An order: `discount` is the fraction taken off, when there is one, and `total` the lines' gross less it, to the cent. */\nconst Order = StructType({\n customer_id: StringType, discount: OptionType(FloatType), id: IntegerType, lines: ArrayType(Line), status: Status, total: FloatType,\n});\n\n/** A customer's tier. */\nconst Tier = VariantType({ gold: NullType, standard: NullType });\n\n/** A customer, and their tier. */\nconst Customer = StructType({ name: StringType, region: StringType, tier: Tier });\n\n/**\n * How many orders the order history holds: a small authored constant, the\n * orders themselves generated by {@link historyTask} when the dataflow runs —\n * a dataset this size is made where data is made, never written into the\n * package. They weigh more than one of the showcase's pieces, so a query over\n * them runs as a split call.\n */\nexport const historyCount = e3.input(\"history_count\", IntegerType, variant(\"value\", 36_000n));\n\n/** How many accounts place the history's orders. They weigh more than one piece too, so the history joined with them is re-keyed. */\nexport const accountCount = e3.input(\"account_count\", IntegerType, variant(\"value\", 20_000n));\n\n/** An account's key: `A` and its number plus 100,000 — fixed width, so key order is number order. */\nconst accountKey = East.function([IntegerType], StringType, (_$, n) => East.str`A${n.add(100_000n)}`);\n\n/** A number's scramble, 0 to 1,000,002: the same every run, and far from its neighbours'. */\nconst scramble = East.function([IntegerType], IntegerType, (_$, n) => n.multiply(2_654_435n).add(97n).remainder(1_000_003n));\n\n/**\n * The accounts, generated from their count, by key: each named for a trading\n * name and its number, in one of eight regions, one in five gold — each drawn\n * from the account's scrambled number.\n */\nexport const generateAccounts = East.function([IntegerType], DictType(StringType, Customer), ($, count) => {\n const regions = $.const([\"NSW\", \"VIC\", \"QLD\", \"WA\", \"SA\", \"TAS\", \"NT\", \"ACT\"], ArrayType(StringType));\n const names = $.const([\"Harbour Foods\", \"Coastline Retail\", \"Ridge Grocers\", \"Southbank Market\", \"Sunfield Traders\", \"Northgate Supply\"], ArrayType(StringType));\n return East.Array.range(0n, count).toDict(\n (_$, n) => accountKey(n),\n ($2, n) => {\n const h = $2.let(scramble(n));\n const gold = $2.let(h.remainder(5n).equal(0n));\n const tier = $2.let(gold.ifElse(($3) => $3.const(variant(\"gold\", null), Tier), ($3) => $3.const(variant(\"standard\", null), Tier)));\n return $2.const({ name: East.str`${names.get(h.remainder(6n))} ${n.add(1n)}`, region: regions.get(h.remainder(8n)), tier }, Customer);\n },\n );\n});\n\n/** The task that generates the accounts. */\nexport const accountsTask = e3.task(\"accounts\", [accountCount], generateAccounts);\n\n/** Each account's credit limit, by the account's key — $5,000 to $49,950 — but every fifth account's, which has none. */\nexport const generateCredit = East.function([IntegerType], DictType(StringType, FloatType), (_$, count) =>\n East.Array.range(0n, count)\n .filter((_$2, n) => n.remainder(5n).notEqual(0n))\n .toDict((_$2, n) => accountKey(n), (_$2, n) => scramble(n).remainder(900n).add(100n).multiply(50n).toFloat()));\n\n/** The task that generates the credit limits. */\nexport const creditTask = e3.task(\"credit\", [accountCount], generateCredit);\n\n/**\n * The order history, generated from its count and the accounts': orders\n * 100,001 on, each placed by an account, of one to three lines from the\n * fixture's eight SKUs, a tenth of them 10% off and a tenth 5% off, the total\n * to the cent. Seven in ten have shipped — each order 22 minutes after the\n * one before it, from 6 January 2025 to July 2026 — two in ten are pending,\n * and one in ten was cancelled. Each is drawn from the order's scrambled\n * number.\n */\nexport const generateHistory = East.function([IntegerType, IntegerType], ArrayType(Order), ($, count, accounts) => {\n const catalog = $.const([\n { sku: \"BRK-100\", price: 12.4 }, { sku: \"HNG-220\", price: 8.9 }, { sku: \"PLT-310\", price: 46.0 }, { sku: \"RAL-900\", price: 64.5 },\n { sku: \"BLT-045\", price: 0.85 }, { sku: \"WSH-008\", price: 0.18 }, { sku: \"SCR-012\", price: 0.32 }, { sku: \"CLP-150\", price: 3.75 },\n ], ArrayType(StructType({ sku: StringType, price: FloatType })));\n const reasons = $.const([\"Customer request\", \"Payment failed\", \"Out of stock\"], ArrayType(StringType));\n const opened = $.const(new Date(\"2025-01-06T08:00:00.000Z\"), DateTimeType);\n return East.Array.range(0n, count).map(($2, i) => {\n const h = $2.let(scramble(i));\n const lines = $2.let(East.Array.range(0n, h.remainder(3n).add(1n)).map(($3, k) => {\n const item = $3.let(catalog.get(h.add(k.multiply(5n)).remainder(8n)));\n return $3.const({ price: item.price, qty: h.add(k.multiply(3n)).remainder(40n).add(1n), sku: item.sku }, Line);\n }));\n const gross = $2.let(lines.sum(($3, line) => line.price.multiply(line.qty.toFloat())));\n const off = $2.let(h.remainder(10n));\n const discount = $2.let(off.equal(0n).ifElse(\n ($3) => $3.const(some(0.1), OptionType(FloatType)),\n ($3) => off.equal(1n).ifElse(($4) => $4.const(some(0.05), OptionType(FloatType)), ($4) => $4.const(none, OptionType(FloatType))),\n ));\n const kept = $2.let(off.equal(0n).ifElse(($3) => $3.const(0.9), ($3) => off.equal(1n).ifElse(($4) => $4.const(0.95), ($4) => $4.const(1.0))));\n const cents = $2.let(gross.multiply(kept).multiply(100.0).add(0.5));\n const state = $2.let(i.remainder(10n));\n const shipped = $2.let(opened.addMinutes(i.multiply(22n)));\n const status = $2.let(state.lessThan(7n).ifElse(\n ($3) => $3.const(variant(\"shipped\", { date: shipped }), Status),\n ($3) => state.lessThan(9n).ifElse(\n ($4) => $4.const(variant(\"pending\", null), Status),\n ($4) => $4.const(variant(\"cancelled\", { reason: reasons.get(h.remainder(3n)) }), Status),\n ),\n ));\n return $2.const({\n customer_id: accountKey(h.remainder(accounts)), discount, id: i.add(100_001n), lines, status,\n total: cents.subtract(cents.remainder(1.0)).divide(100.0),\n }, Order);\n });\n});\n\n/** The task that generates the order history. */\nexport const historyTask = e3.task(\"order_history\", [historyCount, accountCount], generateHistory);\n\n/**\n * The saved queries over the order history, one of each way a query too large\n * for one call runs: over the history's pieces; the history joined with the\n * accounts, both large, re-keyed; and the accounts joined with their credit\n * limits, keyed alike, cut at the same keys — each checked against the three\n * generated datasets, each a task's output, when the package builds.\n */\nexport const historyQueries = e3.record(\"history_queries\", Query.Types.Saved, {\n initial: Query.value({ order_history: historyTask, accounts: accountsTask, credit: creditTask }, [\n {\n name: \"History revenue by month\",\n jq: `.order_history\n | map(select(.status.type == \"shipped\"))\n | map(. + {ship_month: .status.value.date | strftime(\"%Y-%m\")})\n | group_by(.ship_month)\n | map({ship_month: .[0].ship_month, revenue: map(.total) | add, orders: length})`,\n description: \"Shipped revenue by month over the whole order history, run over its pieces.\",\n savedAt: new Date(\"2026-10-02T09:00:00Z\"),\n },\n {\n name: \"History revenue by region\",\n jq: `.accounts as $accounts\n | .order_history\n | map(select(.status.type == \"shipped\"))\n | map(. + {region: $accounts[.customer_id].region})\n | group_by(.region)\n | map({region: .[0].region, revenue: map(.total) | add, orders: length})`,\n description: \"Shipped revenue by the region of the account that placed each order.\",\n savedAt: new Date(\"2026-10-02T10:00:00Z\"),\n },\n {\n name: \"Credit by region\",\n jq: `.credit as $credit\n | .accounts\n | to_entries\n | map({region: .value.region, limit: ($credit[.key] // 0)})\n | group_by(.region)\n | map({region: .[0].region, limit: map(.limit) | add, accounts: length})`,\n description: \"Each region's accounts and their credit limits added up; an account with no limit counts as none.\",\n savedAt: new Date(\"2026-10-02T11:00:00Z\"),\n },\n ]),\n mutations: (mutation) => ({\n // Its one write.\n patch: mutation.patch(),\n }),\n});\n\nEast.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const saved = $.let(Record.bind(historyQueries));\n const history = $.let(Data.bindPaged(historyTask));\n const accounts = $.let(Data.bindPaged(accountsTask));\n const credit = $.let(Data.bindPaged(creditTask));\n return (\n <Box height=\"760px\">\n <Query.Builder queries={saved} query=\"History revenue by region\" id=\"history\"\n datasets={{ order_history: history, accounts, credit }} />\n </Box>\n );\n }}</Reactive>\n ))"
45641
+ "source": "// The builder over data too large for one call — an order history of 36,000 orders, the 20,000 accounts that place them and their credit limits, which e3 tasks generate when the dataflow runs, each bound by window and never downloaded — open on History revenue by region: the history joined with the accounts, both large, so the run re-keys it as two split calls, which the results footer's plan read-out says. Its other saved queries run as a split call over the history's pieces, and as a join of two lookups keyed alike, cut at the same keys\n// inputs: []\n/** One line of an order: a SKU, its unit price and the quantity ordered. */\nconst Line = StructType({ price: FloatType, qty: IntegerType, sku: StringType });\n\n/** Where an order stands: cancelled for a reason, pending, or shipped on a date. */\nconst Status = VariantType({ cancelled: StructType({ reason: StringType }), pending: NullType, shipped: StructType({ date: DateTimeType }) });\n\n/** An order: `discount` is the fraction taken off, when there is one, and `total` the lines' gross less it, to the cent. */\nconst Order = StructType({\n customer_id: StringType, discount: OptionType(FloatType), id: IntegerType, lines: ArrayType(Line), status: Status, total: FloatType,\n});\n\n/** A customer's tier. */\nconst Tier = VariantType({ gold: NullType, standard: NullType });\n\n/** A customer, and their tier. */\nconst Customer = StructType({ name: StringType, region: StringType, tier: Tier });\n\n/**\n * How many orders the order history holds: a small authored constant, the\n * orders themselves generated by {@link historyTask} when the dataflow runs —\n * a dataset this size is made where data is made, never written into the\n * package. They weigh more than one of the showcase's pieces, so a query over\n * them runs as a split call.\n */\nexport const historyCount = e3.input(\"history_count\", IntegerType, variant(\"value\", 36_000n));\n\n/** How many accounts place the history's orders. They weigh more than one piece too, so the history joined with them is re-keyed. */\nexport const accountCount = e3.input(\"account_count\", IntegerType, variant(\"value\", 20_000n));\n\n/** An account's key: `A` and its number plus 100,000 — fixed width, so key order is number order. */\nconst accountKey = East.function([IntegerType], StringType, (_$, n) => East.str`A${n.add(100_000n)}`);\n\n/** A number's scramble, 0 to 1,000,002: the same every run, and far from its neighbours'. */\nconst scramble = East.function([IntegerType], IntegerType, (_$, n) => n.multiply(2_654_435n).add(97n).remainder(1_000_003n));\n\n/**\n * The accounts, generated from their count, by key: each named for a trading\n * name and its number, in one of eight regions, one in five gold — each drawn\n * from the account's scrambled number.\n */\nexport const generateAccounts = East.function([IntegerType], DictType(StringType, Customer), ($, count) => {\n const regions = $.const([\"NSW\", \"VIC\", \"QLD\", \"WA\", \"SA\", \"TAS\", \"NT\", \"ACT\"], ArrayType(StringType));\n const names = $.const([\"Harbour Foods\", \"Coastline Retail\", \"Ridge Grocers\", \"Southbank Market\", \"Sunfield Traders\", \"Northgate Supply\"], ArrayType(StringType));\n return East.Array.range(0n, count).toDict(\n (_$, n) => accountKey(n),\n ($2, n) => {\n const h = $2.let(scramble(n));\n const gold = $2.let(h.remainder(5n).equal(0n));\n const tier = $2.let(gold.ifElse(($3) => $3.const(variant(\"gold\", null), Tier), ($3) => $3.const(variant(\"standard\", null), Tier)));\n return $2.const({ name: East.str`${names.get(h.remainder(6n))} ${n.add(1n)}`, region: regions.get(h.remainder(8n)), tier }, Customer);\n },\n );\n});\n\n/** The task that generates the accounts. */\nexport const accountsTask = e3.task(\"accounts\", [accountCount], generateAccounts);\n\n/** Each account's credit limit, by the account's key — $5,000 to $49,950 — but every fifth account's, which has none. */\nexport const generateCredit = East.function([IntegerType], DictType(StringType, FloatType), (_$, count) =>\n East.Array.range(0n, count)\n .filter((_$2, n) => n.remainder(5n).notEqual(0n))\n .toDict((_$2, n) => accountKey(n), (_$2, n) => scramble(n).remainder(900n).add(100n).multiply(50n).toFloat()));\n\n/** The task that generates the credit limits. */\nexport const creditTask = e3.task(\"credit\", [accountCount], generateCredit);\n\n/**\n * The order history, generated from its count and the accounts': orders\n * 100,001 on, each placed by an account, of one to three lines from the\n * fixture's eight SKUs, a tenth of them 10% off and a tenth 5% off, the total\n * to the cent. Seven in ten have shipped — each order 22 minutes after the\n * one before it, from 6 January 2025 to July 2026 — two in ten are pending,\n * and one in ten was cancelled. Each is drawn from the order's scrambled\n * number.\n */\nexport const generateHistory = East.function([IntegerType, IntegerType], ArrayType(Order), ($, count, accounts) => {\n const catalog = $.const([\n { sku: \"BRK-100\", price: 12.4 }, { sku: \"HNG-220\", price: 8.9 }, { sku: \"PLT-310\", price: 46.0 }, { sku: \"RAL-900\", price: 64.5 },\n { sku: \"BLT-045\", price: 0.85 }, { sku: \"WSH-008\", price: 0.18 }, { sku: \"SCR-012\", price: 0.32 }, { sku: \"CLP-150\", price: 3.75 },\n ], ArrayType(StructType({ sku: StringType, price: FloatType })));\n const reasons = $.const([\"Customer request\", \"Payment failed\", \"Out of stock\"], ArrayType(StringType));\n const opened = $.const(new Date(\"2025-01-06T08:00:00.000Z\"), DateTimeType);\n return East.Array.range(0n, count).map(($2, i) => {\n const h = $2.let(scramble(i));\n const lines = $2.let(East.Array.range(0n, h.remainder(3n).add(1n)).map(($3, k) => {\n const item = $3.let(catalog.get(h.add(k.multiply(5n)).remainder(8n)));\n return $3.const({ price: item.price, qty: h.add(k.multiply(3n)).remainder(40n).add(1n), sku: item.sku }, Line);\n }));\n const gross = $2.let(lines.sum(($3, line) => line.price.multiply(line.qty.toFloat())));\n const off = $2.let(h.remainder(10n));\n const discount = $2.let(off.equal(0n).ifElse(\n ($3) => $3.const(some(0.1), OptionType(FloatType)),\n ($3) => off.equal(1n).ifElse(($4) => $4.const(some(0.05), OptionType(FloatType)), ($4) => $4.const(none, OptionType(FloatType))),\n ));\n const kept = $2.let(off.equal(0n).ifElse(($3) => $3.const(0.9), ($3) => off.equal(1n).ifElse(($4) => $4.const(0.95), ($4) => $4.const(1.0))));\n const cents = $2.let(gross.multiply(kept).multiply(100.0).add(0.5));\n const state = $2.let(i.remainder(10n));\n const shipped = $2.let(opened.addMinutes(i.multiply(22n)));\n const status = $2.let(state.lessThan(7n).ifElse(\n ($3) => $3.const(variant(\"shipped\", { date: shipped }), Status),\n ($3) => state.lessThan(9n).ifElse(\n ($4) => $4.const(variant(\"pending\", null), Status),\n ($4) => $4.const(variant(\"cancelled\", { reason: reasons.get(h.remainder(3n)) }), Status),\n ),\n ));\n return $2.const({\n customer_id: accountKey(h.remainder(accounts)), discount, id: i.add(100_001n), lines, status,\n total: cents.subtract(cents.remainder(1.0)).divide(100.0),\n }, Order);\n });\n});\n\n/** The task that generates the order history. */\nexport const historyTask = e3.task(\"order_history\", [historyCount, accountCount], generateHistory);\n\n/**\n * The saved queries over the order history, one of each way a query too large\n * for one call runs: over the history's pieces; the history joined with the\n * accounts, both large, re-keyed; and the accounts joined with their credit\n * limits, keyed alike, cut at the same keys — each checked against the three\n * generated datasets, each a task's output, when the package builds.\n */\nexport const historyQueries = e3.record(\"history_queries\", Query.Types.Saved, {\n initial: Query.value({ order_history: historyTask, accounts: accountsTask, credit: creditTask }, [\n {\n name: \"History revenue by month\",\n jq: `.order_history\n | map(select(.status.type == \"shipped\"))\n | map(. + {ship_month: .status.value.date | strftime(\"%Y-%m\")})\n | group_by(.ship_month)\n | map({ship_month: .[0].ship_month, revenue: map(.total) | add, orders: length})`,\n description: \"Shipped revenue by month over the whole order history, run over its pieces.\",\n savedAt: new Date(\"2026-10-02T09:00:00Z\"),\n },\n {\n name: \"History revenue by region\",\n jq: `.accounts as $accounts\n | .order_history\n | map(select(.status.type == \"shipped\"))\n | map(. + {region: $accounts[.customer_id].region})\n | group_by(.region)\n | map({region: .[0].region, revenue: map(.total) | add, orders: length})`,\n description: \"Shipped revenue by the region of the account that placed each order.\",\n savedAt: new Date(\"2026-10-02T10:00:00Z\"),\n },\n {\n name: \"Credit by region\",\n jq: `.credit as $credit\n | .accounts\n | to_entries\n | map({region: .value.region, limit: ($credit[.key] // 0)})\n | group_by(.region)\n | map({region: .[0].region, limit: map(.limit) | add, accounts: length})`,\n description: \"Each region's accounts and their credit limits added up; an account with no limit counts as none.\",\n savedAt: new Date(\"2026-10-02T11:00:00Z\"),\n },\n ]),\n mutations: (mutation) => ({\n // Its one write.\n patch: mutation.patch(),\n }),\n});\n\nEast.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const saved = $.let(Record.bind(historyQueries));\n const history = $.let(Data.bindPaged(historyTask));\n const accounts = $.let(Data.bindPaged(accountsTask));\n const credit = $.let(Data.bindPaged(creditTask));\n // The open query is the surface's: the builder shows it, and tells the surface when its own tabs ask for another.\n const open = $.let(State.bind([Query.Types.Open], \"ex.queryBuilderHistory.open\", Query.open.saved(\"History revenue by region\")));\n const go = $.const(East.function([Query.Types.Open], NullType, ($2, next) => { $2(open.write(next)); }));\n return (\n <Box height=\"760px\">\n <Query.Builder queries={saved} query={open.read()} onOpen={go} id=\"history\"\n datasets={{ order_history: history, accounts, credit }} />\n </Box>\n );\n }}</Reactive>\n ))"
45642
+ },
45643
+ {
45644
+ "id": "e3-ui:query.examples.tsx:queryBuilderSteps",
45645
+ "skill": "e3-ui",
45646
+ "package": "e3-ui",
45647
+ "file": "east-ui/packages/e3-ui/test/query/query.examples.tsx",
45648
+ "suite": "",
45649
+ "test": "The builder open on Revenue per unit, last 52 weeks: its steps keep the sales of the last 52 weeks before the minute the query runs — `.now`, the root's last field, which e3 is given beside the datasets — group them by region and channel together, and total each group's revenue over its units as a ratio. What it gives counts back from the minute it runs, so it changes as time passes",
45650
+ "keywords": [
45651
+ "Query",
45652
+ "Query.Builder",
45653
+ "Query.value",
45654
+ "in the last",
45655
+ "last 7 days",
45656
+ "last 52 weeks",
45657
+ "relative date",
45658
+ "now",
45659
+ ".now",
45660
+ "$now",
45661
+ "datetime_add",
45662
+ "group by several fields",
45663
+ "group_by",
45664
+ "ratio",
45665
+ "per",
45666
+ "revenue per unit",
45667
+ "Group and total"
45668
+ ],
45669
+ "imports": [
45670
+ "import {",
45671
+ "import { Box, Button, HStack, Reactive, Select, State, Text, UIComponentType, VStack } from \"@elaraai/east-ui\";",
45672
+ "import { Data, Query, Record } from \"@elaraai/e3-ui\";",
45673
+ "import e3 from \"@elaraai/e3\";"
45674
+ ],
45675
+ "languages": [
45676
+ "tsx"
45677
+ ],
45678
+ "source": "// The builder open on Revenue per unit, last 52 weeks: its steps keep the sales of the last 52 weeks before the minute the query runs — `.now`, the root's last field, which e3 is given beside the datasets — group them by region and channel together, and total each group's revenue over its units as a ratio. What it gives counts back from the minute it runs, so it changes as time passes\n// inputs: []\n/** A quarter's sales in a region through a channel: the day the quarter opened, its revenue, and the units sold. */\nconst Sale = StructType({ sold_on: DateTimeType, region: StringType, channel: StringType, revenue: FloatType, units: IntegerType });\n\n/** Sales in two regions through two channels, a row a quarter from October 2025 to October 2026: the store's units dearer than online's. */\nexport const sales = e3.input(\"sales\", ArrayType(Sale), variant(\"value\", [\n { sold_on: new Date(\"2025-10-01T00:00:00.000Z\"), region: \"NSW\", channel: \"store\", revenue: 18_400.0, units: 920n },\n { sold_on: new Date(\"2025-10-01T00:00:00.000Z\"), region: \"NSW\", channel: \"online\", revenue: 9_600.0, units: 600n },\n { sold_on: new Date(\"2025-10-01T00:00:00.000Z\"), region: \"VIC\", channel: \"store\", revenue: 15_300.0, units: 850n },\n { sold_on: new Date(\"2025-10-01T00:00:00.000Z\"), region: \"VIC\", channel: \"online\", revenue: 7_040.0, units: 440n },\n { sold_on: new Date(\"2026-04-01T00:00:00.000Z\"), region: \"NSW\", channel: \"store\", revenue: 21_000.0, units: 1_000n },\n { sold_on: new Date(\"2026-04-01T00:00:00.000Z\"), region: \"NSW\", channel: \"online\", revenue: 12_750.0, units: 750n },\n { sold_on: new Date(\"2026-04-01T00:00:00.000Z\"), region: \"VIC\", channel: \"store\", revenue: 16_800.0, units: 875n },\n { sold_on: new Date(\"2026-04-01T00:00:00.000Z\"), region: \"VIC\", channel: \"online\", revenue: 9_180.0, units: 540n },\n { sold_on: new Date(\"2026-10-01T00:00:00.000Z\"), region: \"NSW\", channel: \"store\", revenue: 22_500.0, units: 1_050n },\n { sold_on: new Date(\"2026-10-01T00:00:00.000Z\"), region: \"NSW\", channel: \"online\", revenue: 15_300.0, units: 850n },\n { sold_on: new Date(\"2026-10-01T00:00:00.000Z\"), region: \"VIC\", channel: \"store\", revenue: 18_000.0, units: 900n },\n { sold_on: new Date(\"2026-10-01T00:00:00.000Z\"), region: \"VIC\", channel: \"online\", revenue: 11_050.0, units: 650n },\n]));\n\n/**\n * The saved query over the sales, in its canonical jq: the sales of the last\n * 52 weeks before the minute it runs — `.now`, which e3 is given beside the\n * data — grouped by region and channel together, each group's revenue totalled\n * over its units as a ratio — nothing for a group whose units add up to none,\n * which sorts last, highest first.\n */\nexport const salesQueries = e3.record(\"sales_queries\", Query.Types.Saved, {\n initial: Query.value({ sales }, [\n {\n name: \"Revenue per unit, last 52 weeks\",\n jq: `.now as $now\n | .sales\n | map(select(.sold_on >= ($now | datetime_add(-52; \"week\"))))\n | group_by({region, channel})\n | map({region: .[0].region, channel: .[0].channel, revenue: map(.revenue) | add, units: map(.units) | add, revenue_per_unit: if (map(.units) | add) == 0 then null else (map(.revenue) | add) / (map(.units) | add) end})\n | sort_by(.revenue_per_unit)\n | reverse`,\n description: \"Revenue over units sold in the last 52 weeks, by region and channel.\",\n savedAt: new Date(\"2026-10-05T09:00:00Z\"),\n },\n ]),\n mutations: (mutation) => ({\n // Its one write.\n patch: mutation.patch(),\n }),\n});\n\nEast.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const saved = $.let(Record.bind(salesQueries));\n const rows = $.let(Data.bind(sales));\n // The open query is the surface's: the builder shows it, and tells the surface when its own tabs ask for another.\n const open = $.let(State.bind([Query.Types.Open], \"ex.queryBuilderSteps.open\", Query.open.saved(\"Revenue per unit, last 52 weeks\")));\n const go = $.const(East.function([Query.Types.Open], NullType, ($2, next) => { $2(open.write(next)); }));\n return (\n <Box height=\"640px\">\n <Query.Builder queries={saved} query={open.read()} onOpen={go} id=\"steps\" datasets={{ sales: rows }} />\n </Box>\n );\n }}</Reactive>\n ))"
45587
45679
  },
45588
45680
  {
45589
45681
  "id": "e3-ui:query.examples.tsx:queryLibrary",
@@ -45591,7 +45683,7 @@
45591
45683
  "package": "e3-ui",
45592
45684
  "file": "east-ui/packages/e3-ui/test/query/query.examples.tsx",
45593
45685
  "suite": "",
45594
- "test": "The query library over the same record and data sources: one toolbar — the search, Sort, Grid · List and \"+ New query on orders\" — beside the data sources with their counts of saved queries and this viewer's recent runs; the seven saved queries as a gallery, each card a wireframe of its steps with its name, its description and what it gives, and \"Open in builder →\", which opens the query in the builder that shares its id",
45686
+ "test": "The query library over the same record and data sources: one toolbar — the search, Sort, Grid · List and \"+ New query on orders\" — beside the data sources with their counts of saved queries and this viewer's recent runs; the seven saved queries as a gallery, each card a wireframe of its steps with its name, its description and what it gives, and \"Open in builder →\", which tells the surface in `onOpen`: the surface writes the open query it holds, which the builder above shows and whose card is marked",
45595
45687
  "keywords": [
45596
45688
  "Query",
45597
45689
  "Query.Library",
@@ -45607,7 +45699,13 @@
45607
45699
  "list",
45608
45700
  "recent",
45609
45701
  "Record.bind",
45610
- "Data.bind"
45702
+ "Data.bind",
45703
+ "onOpen",
45704
+ "query",
45705
+ "Query.Types.Open",
45706
+ "Query.open.saved",
45707
+ "State.bind",
45708
+ "navigate"
45611
45709
  ],
45612
45710
  "imports": [
45613
45711
  "import {",
@@ -45618,7 +45716,7 @@
45618
45716
  "languages": [
45619
45717
  "tsx"
45620
45718
  ],
45621
- "source": "// The query library over the same record and data sources: one toolbar — the search, Sort, Grid · List and \"+ New query on orders\" — beside the data sources with their counts of saved queries and this viewer's recent runs; the seven saved queries as a gallery, each card a wireframe of its steps with its name, its description and what it gives, and \"Open in builder →\", which opens the query in the builder that shares its id\n// inputs: []\n/** One line of an order: a SKU, its unit price and the quantity ordered. */\nconst Line = StructType({ price: FloatType, qty: IntegerType, sku: StringType });\n\n/** Where an order stands: cancelled for a reason, pending, or shipped on a date. */\nconst Status = VariantType({ cancelled: StructType({ reason: StringType }), pending: NullType, shipped: StructType({ date: DateTimeType }) });\n\n/** An order: `discount` is the fraction taken off, when there is one, and `total` the lines' gross less it, to the cent. */\nconst Order = StructType({\n customer_id: StringType, discount: OptionType(FloatType), id: IntegerType, lines: ArrayType(Line), status: Status, total: FloatType,\n});\n\n/** A customer's tier. */\nconst Tier = VariantType({ gold: NullType, standard: NullType });\n\n/** A customer, and their tier. */\nconst Customer = StructType({ name: StringType, region: StringType, tier: Tier });\n\n/** Weekly demand by region: eight weeks, the first at index 0. */\nconst Forecast = StructType({ regions: DictType(StringType, StructType({ weekly: ArrayType(FloatType) })) });\n\n/** A part and the parts it is built from: a bill of materials. */\nconst Part = RecursiveType(self => StructType({ children: ArrayType(self), cost: FloatType, sku: StringType }));\n\n/** The demand model: units sold at a unit price in a region. */\nconst ModelInput = StructType({ price: FloatType, region: StringType });\n\nconst Model = FunctionType([ModelInput], FloatType);\n\n/** The orders, ids 1001–1040, in id order: the mock's forty, drawn from seed 875 (`Query Editor Spec.md` §6). */\nexport const orders = e3.input(\"orders\", ArrayType(Order), variant(\"value\", [\n { id: 1001n, customer_id: \"C01\", discount: some(0.1), total: 80.1, status: variant(\"shipped\", { date: new Date(\"2026-04-27T09:00:00.000Z\") }),\n lines: [{ price: 8.9, qty: 10n, sku: \"HNG-220\" }] },\n { id: 1002n, customer_id: \"C07\", discount: none, total: 1171.58, status: variant(\"shipped\", { date: new Date(\"2026-01-15T16:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 38n, sku: \"BLT-045\" }, { price: 46.0, qty: 24n, sku: \"PLT-310\" }, { price: 0.18, qty: 196n, sku: \"WSH-008\" }] },\n { id: 1003n, customer_id: \"C02\", discount: none, total: 453.0, status: variant(\"shipped\", { date: new Date(\"2026-04-06T16:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 15n, sku: \"BRK-100\" }, { price: 8.9, qty: 30n, sku: \"HNG-220\" }] },\n { id: 1004n, customer_id: \"C05\", discount: some(0.15), total: 128.61, status: variant(\"pending\", null),\n lines: [{ price: 8.9, qty: 17n, sku: \"HNG-220\" }] },\n { id: 1005n, customer_id: \"C02\", discount: none, total: 520.24, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 6n, sku: \"PLT-310\" }, { price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 0.18, qty: 48n, sku: \"WSH-008\" }] },\n { id: 1006n, customer_id: \"C06\", discount: none, total: 210.8, status: variant(\"shipped\", { date: new Date(\"2026-06-03T14:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 17n, sku: \"BRK-100\" }] },\n { id: 1007n, customer_id: \"C05\", discount: some(0.1), total: 1162.92, status: variant(\"shipped\", { date: new Date(\"2026-04-06T09:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 184n, sku: \"SCR-012\" }, { price: 64.5, qty: 5n, sku: \"RAL-900\" }, { price: 46.0, qty: 7n, sku: \"PLT-310\" }, { price: 3.75, qty: 157n, sku: \"CLP-150\" }] },\n { id: 1008n, customer_id: \"C05\", discount: none, total: 1280.3, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 143n, sku: \"BLT-045\" }, { price: 64.5, qty: 10n, sku: \"RAL-900\" }, { price: 3.75, qty: 137n, sku: \"CLP-150\" }] },\n { id: 1009n, customer_id: \"C04\", discount: some(0.05), total: 409.51, status: variant(\"shipped\", { date: new Date(\"2025-11-18T09:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 6n, sku: \"RAL-900\" }, { price: 0.18, qty: 211n, sku: \"WSH-008\" }, { price: 0.32, qty: 19n, sku: \"SCR-012\" }] },\n { id: 1010n, customer_id: \"C05\", discount: some(0.05), total: 142.23, status: variant(\"shipped\", { date: new Date(\"2025-10-14T12:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 189n, sku: \"WSH-008\" }, { price: 8.9, qty: 13n, sku: \"HNG-220\" }] },\n { id: 1011n, customer_id: \"C08\", discount: none, total: 1027.4, status: variant(\"pending\", null),\n lines: [{ price: 8.9, qty: 29n, sku: \"HNG-220\" }, { price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 0.85, qty: 298n, sku: \"BLT-045\" }] },\n { id: 1012n, customer_id: \"C02\", discount: none, total: 1109.6, status: variant(\"shipped\", { date: new Date(\"2026-04-01T08:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 46.0, qty: 19n, sku: \"PLT-310\" }] },\n { id: 1013n, customer_id: \"C08\", discount: some(0.05), total: 311.37, status: variant(\"shipped\", { date: new Date(\"2026-04-27T10:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 4n, sku: \"RAL-900\" }, { price: 0.32, qty: 218n, sku: \"SCR-012\" }] },\n { id: 1014n, customer_id: \"C07\", discount: none, total: 1765.97, status: variant(\"shipped\", { date: new Date(\"2026-03-09T08:00:00.000Z\") }),\n lines: [{ price: 46.0, qty: 30n, sku: \"PLT-310\" }, { price: 0.18, qty: 254n, sku: \"WSH-008\" }, { price: 0.85, qty: 269n, sku: \"BLT-045\" }, { price: 12.4, qty: 9n, sku: \"BRK-100\" }] },\n { id: 1015n, customer_id: \"C03\", discount: none, total: 3646.84, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 19n, sku: \"PLT-310\" }, { price: 64.5, qty: 26n, sku: \"RAL-900\" }, { price: 3.75, qty: 276n, sku: \"CLP-150\" }, { price: 0.18, qty: 338n, sku: \"WSH-008\" }] },\n { id: 1016n, customer_id: \"C02\", discount: none, total: 1882.9, status: variant(\"pending\", null),\n lines: [{ price: 12.4, qty: 1n, sku: \"BRK-100\" }, { price: 64.5, qty: 29n, sku: \"RAL-900\" }] },\n { id: 1017n, customer_id: \"C02\", discount: some(0.05), total: 2005.59, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 89n, sku: \"BLT-045\" }, { price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 64.5, qty: 23n, sku: \"RAL-900\" }] },\n { id: 1018n, customer_id: \"C03\", discount: none, total: 1372.99, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 26n, sku: \"PLT-310\" }, { price: 0.18, qty: 138n, sku: \"WSH-008\" }, { price: 0.85, qty: 179n, sku: \"BLT-045\" }] },\n { id: 1019n, customer_id: \"C05\", discount: none, total: 684.65, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 301n, sku: \"BLT-045\" }, { price: 12.4, qty: 26n, sku: \"BRK-100\" }, { price: 8.9, qty: 8n, sku: \"HNG-220\" }, { price: 0.32, qty: 110n, sku: \"SCR-012\" }] },\n { id: 1020n, customer_id: \"C01\", discount: some(0.05), total: 297.01, status: variant(\"shipped\", { date: new Date(\"2026-02-06T11:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 75n, sku: \"SCR-012\" }, { price: 0.18, qty: 88n, sku: \"WSH-008\" }, { price: 12.4, qty: 22n, sku: \"BRK-100\" }] },\n { id: 1021n, customer_id: \"C07\", discount: none, total: 1225.5, status: variant(\"shipped\", { date: new Date(\"2026-05-18T14:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 19n, sku: \"RAL-900\" }] },\n { id: 1022n, customer_id: \"C07\", discount: some(0.15), total: 36.26, status: variant(\"shipped\", { date: new Date(\"2026-01-03T10:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 237n, sku: \"WSH-008\" }] },\n { id: 1023n, customer_id: \"C01\", discount: some(0.1), total: 1352.32, status: variant(\"shipped\", { date: new Date(\"2026-01-08T12:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 32n, sku: \"SCR-012\" }, { price: 8.9, qty: 13n, sku: \"HNG-220\" }, { price: 0.18, qty: 123n, sku: \"WSH-008\" }, { price: 64.5, qty: 21n, sku: \"RAL-900\" }] },\n { id: 1024n, customer_id: \"C05\", discount: some(0.05), total: 623.52, status: variant(\"cancelled\", { reason: \"Customer request\" }),\n lines: [{ price: 46.0, qty: 4n, sku: \"PLT-310\" }, { price: 0.18, qty: 209n, sku: \"WSH-008\" }, { price: 0.32, qty: 351n, sku: \"SCR-012\" }, { price: 12.4, qty: 26n, sku: \"BRK-100\" }] },\n { id: 1025n, customer_id: \"C01\", discount: some(0.1), total: 2577.23, status: variant(\"cancelled\", { reason: \"Payment failed\" }),\n lines: [{ price: 0.18, qty: 213n, sku: \"WSH-008\" }, { price: 64.5, qty: 27n, sku: \"RAL-900\" }, { price: 3.75, qty: 289n, sku: \"CLP-150\" }] },\n { id: 1026n, customer_id: \"C03\", discount: none, total: 1913.4, status: variant(\"shipped\", { date: new Date(\"2026-03-07T08:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 354n, sku: \"BLT-045\" }, { price: 64.5, qty: 25n, sku: \"RAL-900\" }] },\n { id: 1027n, customer_id: \"C08\", discount: none, total: 808.19, status: variant(\"shipped\", { date: new Date(\"2026-06-26T10:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 3n, sku: \"BLT-045\" }, { price: 8.9, qty: 25n, sku: \"HNG-220\" }, { price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 0.18, qty: 373n, sku: \"WSH-008\" }] },\n { id: 1028n, customer_id: \"C06\", discount: none, total: 173.45, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 47n, sku: \"BLT-045\" }, { price: 8.9, qty: 15n, sku: \"HNG-220\" }] },\n { id: 1029n, customer_id: \"C05\", discount: none, total: 64.96, status: variant(\"shipped\", { date: new Date(\"2026-03-19T16:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 203n, sku: \"SCR-012\" }] },\n { id: 1030n, customer_id: \"C03\", discount: none, total: 913.36, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 380n, sku: \"BLT-045\" }, { price: 3.75, qty: 4n, sku: \"CLP-150\" }, { price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 0.32, qty: 73n, sku: \"SCR-012\" }] },\n { id: 1031n, customer_id: \"C06\", discount: none, total: 1537.52, status: variant(\"shipped\", { date: new Date(\"2026-05-31T13:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 264n, sku: \"WSH-008\" }, { price: 12.4, qty: 20n, sku: \"BRK-100\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1032n, customer_id: \"C02\", discount: none, total: 1892.81, status: variant(\"cancelled\", { reason: \"Out of stock\" }),\n lines: [{ price: 46.0, qty: 26n, sku: \"PLT-310\" }, { price: 3.75, qty: 183n, sku: \"CLP-150\" }, { price: 0.32, qty: 33n, sku: \"SCR-012\" }] },\n { id: 1033n, customer_id: \"C01\", discount: none, total: 1834.15, status: variant(\"pending\", null),\n lines: [{ price: 64.5, qty: 27n, sku: \"RAL-900\" }, { price: 0.85, qty: 109n, sku: \"BLT-045\" }] },\n { id: 1034n, customer_id: \"C03\", discount: none, total: 323.06, status: variant(\"pending\", null),\n lines: [{ price: 0.32, qty: 140n, sku: \"SCR-012\" }, { price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 0.18, qty: 237n, sku: \"WSH-008\" }] },\n { id: 1035n, customer_id: \"C06\", discount: none, total: 2381.61, status: variant(\"shipped\", { date: new Date(\"2026-06-01T14:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 292n, sku: \"WSH-008\" }, { price: 3.75, qty: 279n, sku: \"CLP-150\" }, { price: 0.85, qty: 48n, sku: \"BLT-045\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1036n, customer_id: \"C01\", discount: some(0.05), total: 1041.68, status: variant(\"shipped\", { date: new Date(\"2026-05-26T13:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 17n, sku: \"RAL-900\" }] },\n { id: 1037n, customer_id: \"C08\", discount: none, total: 774.5, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 8.9, qty: 25n, sku: \"HNG-220\" }] },\n { id: 1038n, customer_id: \"C01\", discount: none, total: 1758.0, status: variant(\"shipped\", { date: new Date(\"2025-10-28T08:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1039n, customer_id: \"C06\", discount: none, total: 471.06, status: variant(\"shipped\", { date: new Date(\"2026-04-04T13:00:00.000Z\") }),\n lines: [{ price: 8.9, qty: 15n, sku: \"HNG-220\" }, { price: 0.18, qty: 222n, sku: \"WSH-008\" }, { price: 12.4, qty: 24n, sku: \"BRK-100\" }] },\n { id: 1040n, customer_id: \"C02\", discount: none, total: 884.1, status: variant(\"shipped\", { date: new Date(\"2025-12-08T14:00:00.000Z\") }),\n lines: [{ price: 46.0, qty: 14n, sku: \"PLT-310\" }, { price: 8.9, qty: 18n, sku: \"HNG-220\" }, { price: 0.85, qty: 94n, sku: \"BLT-045\" }] },\n]));\n\n/** The customers, by id. */\nexport const customers = e3.input(\"customers\", DictType(StringType, Customer), variant(\"value\", new SortedMap([\n [\"C01\", { name: \"Harbour Foods\", region: \"NSW\", tier: variant(\"gold\", null) }],\n [\"C02\", { name: \"Coastline Retail\", region: \"NSW\", tier: variant(\"standard\", null) }],\n [\"C03\", { name: \"Ridge Grocers\", region: \"VIC\", tier: variant(\"gold\", null) }],\n [\"C04\", { name: \"Southbank Market\", region: \"VIC\", tier: variant(\"standard\", null) }],\n [\"C05\", { name: \"Sunfield Traders\", region: \"QLD\", tier: variant(\"standard\", null) }],\n [\"C06\", { name: \"Northgate Supply\", region: \"QLD\", tier: variant(\"gold\", null) }],\n [\"C07\", { name: \"Westend Provisions\", region: \"WA\", tier: variant(\"standard\", null) }],\n [\"C08\", { name: \"Ironbark Stores\", region: \"SA\", tier: variant(\"standard\", null) }],\n], compareFor(StringType))));\n\n/** Weekly demand by region: eight weeks of `base × (0.9 + 0.03w + 0.01i)`, to one place, for the region at index i of NSW, VIC, QLD, WA, SA. */\nexport const forecast = e3.input(\"forecast\", Forecast, variant(\"value\", {\n regions: new SortedMap([\n [\"NSW\", { weekly: [1080.0, 1116.0, 1152.0, 1188.0, 1224.0, 1260.0, 1296.0, 1332.0] }],\n [\"QLD\", { weekly: [791.2, 817.0, 842.8, 868.6, 894.4, 920.2, 946.0, 971.8] }],\n [\"SA\", { weekly: [385.4, 397.7, 410.0, 422.3, 434.6, 446.9, 459.2, 471.5] }],\n [\"VIC\", { weekly: [955.5, 987.0, 1018.5, 1050.0, 1081.5, 1113.0, 1144.5, 1176.0] }],\n [\"WA\", { weekly: [502.2, 518.4, 534.6, 550.8, 567.0, 583.2, 599.4, 615.6] }],\n ], compareFor(StringType)),\n}));\n\n/** The demand model, `round₂(base[region] × (price / 10)^−1.4)`: the units sold at a unit price in a region. */\nconst demandModel = East.function([ModelInput], FloatType, ($, input) => {\n const base = $.const(new SortedMap([[\"NSW\", 1200.0], [\"QLD\", 860.0], [\"SA\", 410.0], [\"VIC\", 1050.0], [\"WA\", 540.0]], compareFor(StringType)), DictType(StringType, FloatType));\n // A region the model does not know has a base of 300.\n const demand = base.get(input.region, () => 300.0).multiply(input.price.divide(10.0).pow(-1.4));\n const cents = $.const(demand.multiply(100.0).add(0.5));\n return cents.subtract(cents.remainder(1.0)).divide(100.0);\n});\n\n/** The demand model as data: an East function every runtime can call, which a query tries over a range. */\nexport const model = e3.input(\"model\", Model, variant(\"value\", East.compile(demandModel, [])));\n\n/** The bill of materials for PUMP-A. */\nexport const bom = e3.input(\"bom\", Part, variant(\"value\", {\n sku: \"PUMP-A\", cost: 42.0, children: [\n { sku: \"MOTOR-1\", cost: 120.0, children: [\n { sku: \"ROTOR-1\", cost: 18.5, children: [] }, { sku: \"STATOR-1\", cost: 22.0, children: [] }, { sku: \"BRG-6203\", cost: 3.2, children: [] },\n ] },\n { sku: \"HOUSING-2\", cost: 35.0, children: [{ sku: \"GASKET-9\", cost: 1.1, children: [] }, { sku: \"BOLT-M8\", cost: 0.4, children: [] }] },\n { sku: \"IMPELLER-3\", cost: 27.5, children: [] },\n { sku: \"SEAL-KIT\", cost: 6.8, children: [{ sku: \"ORING-12\", cost: 0.3, children: [] }, { sku: \"ORING-18\", cost: 0.35, children: [] }] },\n ],\n}));\n\n/**\n * The saved queries record: the mock's seven (`Query Editor Spec.md` §6),\n * each its canonical jq — what the builder's steps print — checked against the\n * data sources the builders bind when the package builds, and described where\n * the mock describes it; the rest describe themselves.\n */\nexport const queries = e3.record(\"queries\", Query.Types.Saved, {\n initial: Query.value({ orders, customers, forecast, model, bom }, [\n {\n name: \"Top shipped orders, 2026\",\n jq: `.customers as $customers\n | .orders\n | map(select(.status.type == \"shipped\") | select(.total >= 100 and (.status.value.date | year) == 2026))\n | map(. + {name: $customers[.customer_id].name, region: $customers[.customer_id].region})\n | map({order: .id, customer: .name, region, total, shipped: .status.value.date})\n | sort_by(-.total)\n | .[:10]`,\n savedAt: new Date(\"2026-10-01T09:00:00Z\"),\n },\n {\n name: \"Revenue by region\",\n jq: `.customers as $customers\n | .orders\n | map(select(.status.type == \"shipped\") | select(.total >= 100 and (.status.value.date | year) == 2026))\n | map(. + {region: $customers[.customer_id].region})\n | group_by(.region)\n | map({region: .[0].region, revenue: map(.total) | add, orders: length})\n | sort_by(-.revenue)\n | .[:3]`,\n description: \"Top 3 regions by shipped revenue in 2026, from orders of $100 or more.\",\n savedAt: new Date(\"2026-09-29T09:00:00Z\"),\n },\n {\n name: \"Shipped revenue by month\",\n jq: `.orders\n | map(select(.status.type == \"shipped\"))\n | map(. + {ship_month: .status.value.date | strftime(\"%Y-%m\")})\n | group_by(.ship_month)\n | map({ship_month: .[0].ship_month, revenue: map(.total) | add, orders: length})\n | sort_by(.ship_month)`,\n savedAt: new Date(\"2026-09-12T09:00:00Z\"),\n },\n {\n name: \"Large orders with no discount\",\n jq: `.orders\n | map(select(.total >= 1000 and .discount == null))\n | map({id, customer_id, total, status})\n | sort_by(-.total)`,\n savedAt: new Date(\"2026-09-03T09:00:00Z\"),\n },\n {\n name: \"Units by SKU\",\n jq: `.orders\n | [.[] | . as $order | .lines[] | . + {order_id: $order.id}]\n | group_by(.sku)\n | map({sku: .[0].sku, units: map(.qty) | add, orders: map(.order_id) | unique | length})\n | sort_by(-.units)`,\n savedAt: new Date(\"2026-08-28T09:00:00Z\"),\n },\n {\n name: \"Pump parts cost\",\n jq: `.bom\n | [recurse(.children[]) | {cost, sku}]\n | {total_cost: map(.cost) | add, parts: length, dearest: map(.cost) | max}`,\n description: \"Total cost, part count and dearest part in the PUMP-A bill of materials.\",\n savedAt: new Date(\"2026-08-20T09:00:00Z\"),\n },\n {\n name: \"Demand at $10–$12, NSW\",\n jq: `.model\n | [range(10.0; 12.0 + 0.5 / 2; 0.5) as $price | {price: $price, demand: call(.; {price: $price, region: \"NSW\"})}]`,\n description: \"Modelled demand in NSW at prices from $10 to $12, in $0.50 steps.\",\n savedAt: new Date(\"2026-08-14T09:00:00Z\"),\n },\n ]),\n mutations: (mutation) => ({\n // The record's one write.\n patch: mutation.patch(),\n }),\n});\n\nEast.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const saved = $.let(Record.bind(queries));\n const orderRows = $.let(Data.bind(orders));\n const customerRows = $.let(Data.bind(customers));\n const weekly = $.let(Data.bind(forecast));\n const demand = $.let(Data.bind(model));\n const parts = $.let(Data.bind(bom));\n return (\n <Box height=\"720px\">\n <Query.Library queries={saved} id=\"top\"\n datasets={{ orders: orderRows, customers: customerRows, forecast: weekly, model: demand, bom: parts }} />\n </Box>\n );\n }}</Reactive>\n ))"
45719
+ "source": "// The query library over the same record and data sources: one toolbar — the search, Sort, Grid · List and \"+ New query on orders\" — beside the data sources with their counts of saved queries and this viewer's recent runs; the seven saved queries as a gallery, each card a wireframe of its steps with its name, its description and what it gives, and \"Open in builder →\", which tells the surface in `onOpen`: the surface writes the open query it holds, which the builder above shows and whose card is marked\n// inputs: []\n/** One line of an order: a SKU, its unit price and the quantity ordered. */\nconst Line = StructType({ price: FloatType, qty: IntegerType, sku: StringType });\n\n/** Where an order stands: cancelled for a reason, pending, or shipped on a date. */\nconst Status = VariantType({ cancelled: StructType({ reason: StringType }), pending: NullType, shipped: StructType({ date: DateTimeType }) });\n\n/** An order: `discount` is the fraction taken off, when there is one, and `total` the lines' gross less it, to the cent. */\nconst Order = StructType({\n customer_id: StringType, discount: OptionType(FloatType), id: IntegerType, lines: ArrayType(Line), status: Status, total: FloatType,\n});\n\n/** A customer's tier. */\nconst Tier = VariantType({ gold: NullType, standard: NullType });\n\n/** A customer, and their tier. */\nconst Customer = StructType({ name: StringType, region: StringType, tier: Tier });\n\n/** Weekly demand by region: eight weeks, the first at index 0. */\nconst Forecast = StructType({ regions: DictType(StringType, StructType({ weekly: ArrayType(FloatType) })) });\n\n/** A part and the parts it is built from: a bill of materials. */\nconst Part = RecursiveType(self => StructType({ children: ArrayType(self), cost: FloatType, sku: StringType }));\n\n/** The demand model: units sold at a unit price in a region. */\nconst ModelInput = StructType({ price: FloatType, region: StringType });\n\nconst Model = FunctionType([ModelInput], FloatType);\n\n/** The orders, ids 1001–1040, in id order: the mock's forty, drawn from seed 875 (`Query Editor Spec.md` §6). */\nexport const orders = e3.input(\"orders\", ArrayType(Order), variant(\"value\", [\n { id: 1001n, customer_id: \"C01\", discount: some(0.1), total: 80.1, status: variant(\"shipped\", { date: new Date(\"2026-04-27T09:00:00.000Z\") }),\n lines: [{ price: 8.9, qty: 10n, sku: \"HNG-220\" }] },\n { id: 1002n, customer_id: \"C07\", discount: none, total: 1171.58, status: variant(\"shipped\", { date: new Date(\"2026-01-15T16:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 38n, sku: \"BLT-045\" }, { price: 46.0, qty: 24n, sku: \"PLT-310\" }, { price: 0.18, qty: 196n, sku: \"WSH-008\" }] },\n { id: 1003n, customer_id: \"C02\", discount: none, total: 453.0, status: variant(\"shipped\", { date: new Date(\"2026-04-06T16:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 15n, sku: \"BRK-100\" }, { price: 8.9, qty: 30n, sku: \"HNG-220\" }] },\n { id: 1004n, customer_id: \"C05\", discount: some(0.15), total: 128.61, status: variant(\"pending\", null),\n lines: [{ price: 8.9, qty: 17n, sku: \"HNG-220\" }] },\n { id: 1005n, customer_id: \"C02\", discount: none, total: 520.24, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 6n, sku: \"PLT-310\" }, { price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 0.18, qty: 48n, sku: \"WSH-008\" }] },\n { id: 1006n, customer_id: \"C06\", discount: none, total: 210.8, status: variant(\"shipped\", { date: new Date(\"2026-06-03T14:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 17n, sku: \"BRK-100\" }] },\n { id: 1007n, customer_id: \"C05\", discount: some(0.1), total: 1162.92, status: variant(\"shipped\", { date: new Date(\"2026-04-06T09:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 184n, sku: \"SCR-012\" }, { price: 64.5, qty: 5n, sku: \"RAL-900\" }, { price: 46.0, qty: 7n, sku: \"PLT-310\" }, { price: 3.75, qty: 157n, sku: \"CLP-150\" }] },\n { id: 1008n, customer_id: \"C05\", discount: none, total: 1280.3, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 143n, sku: \"BLT-045\" }, { price: 64.5, qty: 10n, sku: \"RAL-900\" }, { price: 3.75, qty: 137n, sku: \"CLP-150\" }] },\n { id: 1009n, customer_id: \"C04\", discount: some(0.05), total: 409.51, status: variant(\"shipped\", { date: new Date(\"2025-11-18T09:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 6n, sku: \"RAL-900\" }, { price: 0.18, qty: 211n, sku: \"WSH-008\" }, { price: 0.32, qty: 19n, sku: \"SCR-012\" }] },\n { id: 1010n, customer_id: \"C05\", discount: some(0.05), total: 142.23, status: variant(\"shipped\", { date: new Date(\"2025-10-14T12:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 189n, sku: \"WSH-008\" }, { price: 8.9, qty: 13n, sku: \"HNG-220\" }] },\n { id: 1011n, customer_id: \"C08\", discount: none, total: 1027.4, status: variant(\"pending\", null),\n lines: [{ price: 8.9, qty: 29n, sku: \"HNG-220\" }, { price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 0.85, qty: 298n, sku: \"BLT-045\" }] },\n { id: 1012n, customer_id: \"C02\", discount: none, total: 1109.6, status: variant(\"shipped\", { date: new Date(\"2026-04-01T08:00:00.000Z\") }),\n lines: [{ price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 46.0, qty: 19n, sku: \"PLT-310\" }] },\n { id: 1013n, customer_id: \"C08\", discount: some(0.05), total: 311.37, status: variant(\"shipped\", { date: new Date(\"2026-04-27T10:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 4n, sku: \"RAL-900\" }, { price: 0.32, qty: 218n, sku: \"SCR-012\" }] },\n { id: 1014n, customer_id: \"C07\", discount: none, total: 1765.97, status: variant(\"shipped\", { date: new Date(\"2026-03-09T08:00:00.000Z\") }),\n lines: [{ price: 46.0, qty: 30n, sku: \"PLT-310\" }, { price: 0.18, qty: 254n, sku: \"WSH-008\" }, { price: 0.85, qty: 269n, sku: \"BLT-045\" }, { price: 12.4, qty: 9n, sku: \"BRK-100\" }] },\n { id: 1015n, customer_id: \"C03\", discount: none, total: 3646.84, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 19n, sku: \"PLT-310\" }, { price: 64.5, qty: 26n, sku: \"RAL-900\" }, { price: 3.75, qty: 276n, sku: \"CLP-150\" }, { price: 0.18, qty: 338n, sku: \"WSH-008\" }] },\n { id: 1016n, customer_id: \"C02\", discount: none, total: 1882.9, status: variant(\"pending\", null),\n lines: [{ price: 12.4, qty: 1n, sku: \"BRK-100\" }, { price: 64.5, qty: 29n, sku: \"RAL-900\" }] },\n { id: 1017n, customer_id: \"C02\", discount: some(0.05), total: 2005.59, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 89n, sku: \"BLT-045\" }, { price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 64.5, qty: 23n, sku: \"RAL-900\" }] },\n { id: 1018n, customer_id: \"C03\", discount: none, total: 1372.99, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 26n, sku: \"PLT-310\" }, { price: 0.18, qty: 138n, sku: \"WSH-008\" }, { price: 0.85, qty: 179n, sku: \"BLT-045\" }] },\n { id: 1019n, customer_id: \"C05\", discount: none, total: 684.65, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 301n, sku: \"BLT-045\" }, { price: 12.4, qty: 26n, sku: \"BRK-100\" }, { price: 8.9, qty: 8n, sku: \"HNG-220\" }, { price: 0.32, qty: 110n, sku: \"SCR-012\" }] },\n { id: 1020n, customer_id: \"C01\", discount: some(0.05), total: 297.01, status: variant(\"shipped\", { date: new Date(\"2026-02-06T11:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 75n, sku: \"SCR-012\" }, { price: 0.18, qty: 88n, sku: \"WSH-008\" }, { price: 12.4, qty: 22n, sku: \"BRK-100\" }] },\n { id: 1021n, customer_id: \"C07\", discount: none, total: 1225.5, status: variant(\"shipped\", { date: new Date(\"2026-05-18T14:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 19n, sku: \"RAL-900\" }] },\n { id: 1022n, customer_id: \"C07\", discount: some(0.15), total: 36.26, status: variant(\"shipped\", { date: new Date(\"2026-01-03T10:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 237n, sku: \"WSH-008\" }] },\n { id: 1023n, customer_id: \"C01\", discount: some(0.1), total: 1352.32, status: variant(\"shipped\", { date: new Date(\"2026-01-08T12:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 32n, sku: \"SCR-012\" }, { price: 8.9, qty: 13n, sku: \"HNG-220\" }, { price: 0.18, qty: 123n, sku: \"WSH-008\" }, { price: 64.5, qty: 21n, sku: \"RAL-900\" }] },\n { id: 1024n, customer_id: \"C05\", discount: some(0.05), total: 623.52, status: variant(\"cancelled\", { reason: \"Customer request\" }),\n lines: [{ price: 46.0, qty: 4n, sku: \"PLT-310\" }, { price: 0.18, qty: 209n, sku: \"WSH-008\" }, { price: 0.32, qty: 351n, sku: \"SCR-012\" }, { price: 12.4, qty: 26n, sku: \"BRK-100\" }] },\n { id: 1025n, customer_id: \"C01\", discount: some(0.1), total: 2577.23, status: variant(\"cancelled\", { reason: \"Payment failed\" }),\n lines: [{ price: 0.18, qty: 213n, sku: \"WSH-008\" }, { price: 64.5, qty: 27n, sku: \"RAL-900\" }, { price: 3.75, qty: 289n, sku: \"CLP-150\" }] },\n { id: 1026n, customer_id: \"C03\", discount: none, total: 1913.4, status: variant(\"shipped\", { date: new Date(\"2026-03-07T08:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 354n, sku: \"BLT-045\" }, { price: 64.5, qty: 25n, sku: \"RAL-900\" }] },\n { id: 1027n, customer_id: \"C08\", discount: none, total: 808.19, status: variant(\"shipped\", { date: new Date(\"2026-06-26T10:00:00.000Z\") }),\n lines: [{ price: 0.85, qty: 3n, sku: \"BLT-045\" }, { price: 8.9, qty: 25n, sku: \"HNG-220\" }, { price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 0.18, qty: 373n, sku: \"WSH-008\" }] },\n { id: 1028n, customer_id: \"C06\", discount: none, total: 173.45, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 47n, sku: \"BLT-045\" }, { price: 8.9, qty: 15n, sku: \"HNG-220\" }] },\n { id: 1029n, customer_id: \"C05\", discount: none, total: 64.96, status: variant(\"shipped\", { date: new Date(\"2026-03-19T16:00:00.000Z\") }),\n lines: [{ price: 0.32, qty: 203n, sku: \"SCR-012\" }] },\n { id: 1030n, customer_id: \"C03\", discount: none, total: 913.36, status: variant(\"pending\", null),\n lines: [{ price: 0.85, qty: 380n, sku: \"BLT-045\" }, { price: 3.75, qty: 4n, sku: \"CLP-150\" }, { price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 0.32, qty: 73n, sku: \"SCR-012\" }] },\n { id: 1031n, customer_id: \"C06\", discount: none, total: 1537.52, status: variant(\"shipped\", { date: new Date(\"2026-05-31T13:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 264n, sku: \"WSH-008\" }, { price: 12.4, qty: 20n, sku: \"BRK-100\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1032n, customer_id: \"C02\", discount: none, total: 1892.81, status: variant(\"cancelled\", { reason: \"Out of stock\" }),\n lines: [{ price: 46.0, qty: 26n, sku: \"PLT-310\" }, { price: 3.75, qty: 183n, sku: \"CLP-150\" }, { price: 0.32, qty: 33n, sku: \"SCR-012\" }] },\n { id: 1033n, customer_id: \"C01\", discount: none, total: 1834.15, status: variant(\"pending\", null),\n lines: [{ price: 64.5, qty: 27n, sku: \"RAL-900\" }, { price: 0.85, qty: 109n, sku: \"BLT-045\" }] },\n { id: 1034n, customer_id: \"C03\", discount: none, total: 323.06, status: variant(\"pending\", null),\n lines: [{ price: 0.32, qty: 140n, sku: \"SCR-012\" }, { price: 12.4, qty: 19n, sku: \"BRK-100\" }, { price: 0.18, qty: 237n, sku: \"WSH-008\" }] },\n { id: 1035n, customer_id: \"C06\", discount: none, total: 2381.61, status: variant(\"shipped\", { date: new Date(\"2026-06-01T14:00:00.000Z\") }),\n lines: [{ price: 0.18, qty: 292n, sku: \"WSH-008\" }, { price: 3.75, qty: 279n, sku: \"CLP-150\" }, { price: 0.85, qty: 48n, sku: \"BLT-045\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1036n, customer_id: \"C01\", discount: some(0.05), total: 1041.68, status: variant(\"shipped\", { date: new Date(\"2026-05-26T13:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 17n, sku: \"RAL-900\" }] },\n { id: 1037n, customer_id: \"C08\", discount: none, total: 774.5, status: variant(\"pending\", null),\n lines: [{ price: 46.0, qty: 12n, sku: \"PLT-310\" }, { price: 8.9, qty: 25n, sku: \"HNG-220\" }] },\n { id: 1038n, customer_id: \"C01\", discount: none, total: 1758.0, status: variant(\"shipped\", { date: new Date(\"2025-10-28T08:00:00.000Z\") }),\n lines: [{ price: 64.5, qty: 8n, sku: \"RAL-900\" }, { price: 46.0, qty: 27n, sku: \"PLT-310\" }] },\n { id: 1039n, customer_id: \"C06\", discount: none, total: 471.06, status: variant(\"shipped\", { date: new Date(\"2026-04-04T13:00:00.000Z\") }),\n lines: [{ price: 8.9, qty: 15n, sku: \"HNG-220\" }, { price: 0.18, qty: 222n, sku: \"WSH-008\" }, { price: 12.4, qty: 24n, sku: \"BRK-100\" }] },\n { id: 1040n, customer_id: \"C02\", discount: none, total: 884.1, status: variant(\"shipped\", { date: new Date(\"2025-12-08T14:00:00.000Z\") }),\n lines: [{ price: 46.0, qty: 14n, sku: \"PLT-310\" }, { price: 8.9, qty: 18n, sku: \"HNG-220\" }, { price: 0.85, qty: 94n, sku: \"BLT-045\" }] },\n]));\n\n/** The customers, by id. */\nexport const customers = e3.input(\"customers\", DictType(StringType, Customer), variant(\"value\", new SortedMap([\n [\"C01\", { name: \"Harbour Foods\", region: \"NSW\", tier: variant(\"gold\", null) }],\n [\"C02\", { name: \"Coastline Retail\", region: \"NSW\", tier: variant(\"standard\", null) }],\n [\"C03\", { name: \"Ridge Grocers\", region: \"VIC\", tier: variant(\"gold\", null) }],\n [\"C04\", { name: \"Southbank Market\", region: \"VIC\", tier: variant(\"standard\", null) }],\n [\"C05\", { name: \"Sunfield Traders\", region: \"QLD\", tier: variant(\"standard\", null) }],\n [\"C06\", { name: \"Northgate Supply\", region: \"QLD\", tier: variant(\"gold\", null) }],\n [\"C07\", { name: \"Westend Provisions\", region: \"WA\", tier: variant(\"standard\", null) }],\n [\"C08\", { name: \"Ironbark Stores\", region: \"SA\", tier: variant(\"standard\", null) }],\n], compareFor(StringType))));\n\n/** Weekly demand by region: eight weeks of `base × (0.9 + 0.03w + 0.01i)`, to one place, for the region at index i of NSW, VIC, QLD, WA, SA. */\nexport const forecast = e3.input(\"forecast\", Forecast, variant(\"value\", {\n regions: new SortedMap([\n [\"NSW\", { weekly: [1080.0, 1116.0, 1152.0, 1188.0, 1224.0, 1260.0, 1296.0, 1332.0] }],\n [\"QLD\", { weekly: [791.2, 817.0, 842.8, 868.6, 894.4, 920.2, 946.0, 971.8] }],\n [\"SA\", { weekly: [385.4, 397.7, 410.0, 422.3, 434.6, 446.9, 459.2, 471.5] }],\n [\"VIC\", { weekly: [955.5, 987.0, 1018.5, 1050.0, 1081.5, 1113.0, 1144.5, 1176.0] }],\n [\"WA\", { weekly: [502.2, 518.4, 534.6, 550.8, 567.0, 583.2, 599.4, 615.6] }],\n ], compareFor(StringType)),\n}));\n\n/** The demand model, `round₂(base[region] × (price / 10)^−1.4)`: the units sold at a unit price in a region. */\nconst demandModel = East.function([ModelInput], FloatType, ($, input) => {\n const base = $.const(new SortedMap([[\"NSW\", 1200.0], [\"QLD\", 860.0], [\"SA\", 410.0], [\"VIC\", 1050.0], [\"WA\", 540.0]], compareFor(StringType)), DictType(StringType, FloatType));\n // A region the model does not know has a base of 300.\n const demand = base.get(input.region, () => 300.0).multiply(input.price.divide(10.0).pow(-1.4));\n const cents = $.const(demand.multiply(100.0).add(0.5));\n return cents.subtract(cents.remainder(1.0)).divide(100.0);\n});\n\n/** The demand model as data: an East function every runtime can call, which a query tries over a range. */\nexport const model = e3.input(\"model\", Model, variant(\"value\", East.compile(demandModel, [])));\n\n/** The bill of materials for PUMP-A. */\nexport const bom = e3.input(\"bom\", Part, variant(\"value\", {\n sku: \"PUMP-A\", cost: 42.0, children: [\n { sku: \"MOTOR-1\", cost: 120.0, children: [\n { sku: \"ROTOR-1\", cost: 18.5, children: [] }, { sku: \"STATOR-1\", cost: 22.0, children: [] }, { sku: \"BRG-6203\", cost: 3.2, children: [] },\n ] },\n { sku: \"HOUSING-2\", cost: 35.0, children: [{ sku: \"GASKET-9\", cost: 1.1, children: [] }, { sku: \"BOLT-M8\", cost: 0.4, children: [] }] },\n { sku: \"IMPELLER-3\", cost: 27.5, children: [] },\n { sku: \"SEAL-KIT\", cost: 6.8, children: [{ sku: \"ORING-12\", cost: 0.3, children: [] }, { sku: \"ORING-18\", cost: 0.35, children: [] }] },\n ],\n}));\n\n/**\n * The saved queries record: the mock's seven (`Query Editor Spec.md` §6),\n * each its canonical jq — what the builder's steps print — checked against the\n * data sources the builders bind when the package builds, and described where\n * the mock describes it; the rest describe themselves.\n */\nexport const queries = e3.record(\"queries\", Query.Types.Saved, {\n initial: Query.value({ orders, customers, forecast, model, bom }, [\n {\n name: \"Top shipped orders, 2026\",\n jq: `.customers as $customers\n | .orders\n | map(select(.status.type == \"shipped\") | select(.total >= 100 and (.status.value.date | year) == 2026))\n | map(. + {name: $customers[.customer_id].name, region: $customers[.customer_id].region})\n | map({order: .id, customer: .name, region, total, shipped: .status.value.date})\n | sort_by(-.total)\n | .[:10]`,\n savedAt: new Date(\"2026-10-01T09:00:00Z\"),\n },\n {\n name: \"Revenue by region\",\n jq: `.customers as $customers\n | .orders\n | map(select(.status.type == \"shipped\") | select(.total >= 100 and (.status.value.date | year) == 2026))\n | map(. + {region: $customers[.customer_id].region})\n | group_by(.region)\n | map({region: .[0].region, revenue: map(.total) | add, orders: length})\n | sort_by(-.revenue)\n | .[:3]`,\n description: \"Top 3 regions by shipped revenue in 2026, from orders of $100 or more.\",\n savedAt: new Date(\"2026-09-29T09:00:00Z\"),\n },\n {\n name: \"Shipped revenue by month\",\n jq: `.orders\n | map(select(.status.type == \"shipped\"))\n | map(. + {ship_month: .status.value.date | strftime(\"%Y-%m\")})\n | group_by(.ship_month)\n | map({ship_month: .[0].ship_month, revenue: map(.total) | add, orders: length})\n | sort_by(.ship_month)`,\n savedAt: new Date(\"2026-09-12T09:00:00Z\"),\n },\n {\n name: \"Large orders with no discount\",\n jq: `.orders\n | map(select(.total >= 1000 and .discount == null))\n | map({id, customer_id, total, status})\n | sort_by(-.total)`,\n savedAt: new Date(\"2026-09-03T09:00:00Z\"),\n },\n {\n name: \"Units by SKU\",\n jq: `.orders\n | [.[] | . as $order | .lines[] | . + {order_id: $order.id}]\n | group_by(.sku)\n | map({sku: .[0].sku, units: map(.qty) | add, orders: map(.order_id) | unique | length})\n | sort_by(-.units)`,\n savedAt: new Date(\"2026-08-28T09:00:00Z\"),\n },\n {\n name: \"Pump parts cost\",\n jq: `.bom\n | [recurse(.children[]) | {cost, sku}]\n | {total_cost: map(.cost) | add, parts: length, dearest: map(.cost) | max}`,\n description: \"Total cost, part count and dearest part in the PUMP-A bill of materials.\",\n savedAt: new Date(\"2026-08-20T09:00:00Z\"),\n },\n {\n name: \"Demand at $10–$12, NSW\",\n jq: `.model\n | [range(10.0; 12.0 + 0.5 / 2; 0.5) as $price | {price: $price, demand: call(.; {price: $price, region: \"NSW\"})}]`,\n description: \"Modelled demand in NSW at prices from $10 to $12, in $0.50 steps.\",\n savedAt: new Date(\"2026-08-14T09:00:00Z\"),\n },\n ]),\n mutations: (mutation) => ({\n // The record's one write.\n patch: mutation.patch(),\n }),\n});\n\nEast.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const saved = $.let(Record.bind(queries));\n const orderRows = $.let(Data.bind(orders));\n const customerRows = $.let(Data.bind(customers));\n const weekly = $.let(Data.bind(forecast));\n const demand = $.let(Data.bind(model));\n const parts = $.let(Data.bind(bom));\n // The open query is the surface's: the builder above shows it. A host with routes navigates here instead.\n const open = $.let(State.bind([Query.Types.Open], \"ex.query.open\", Query.open.saved(\"Top shipped orders, 2026\")));\n const go = $.const(East.function([Query.Types.Open], NullType, ($2, next) => { $2(open.write(next)); }));\n return (\n <Box height=\"720px\">\n <Query.Library queries={saved} query={open.read()} onOpen={go} id=\"top\"\n datasets={{ orders: orderRows, customers: customerRows, forecast: weekly, model: demand, bom: parts }} />\n </Box>\n );\n }}</Reactive>\n ))"
45622
45720
  },
45623
45721
  {
45624
45722
  "id": "e3-ui:record-keys.examples.tsx:recordBuiltKeysSliced",
@@ -48630,6 +48728,89 @@
48630
48728
  ],
48631
48729
  "source": "// Your edits meeting someone else's save, in one window — edit a Qty or a Start, then press Someone else saves, which saves another person's change to the same jobs (every Qty 12 more, every Start a day later), so yours conflict and wait to be chosen; a Task you change combines with theirs. Someone else removes Panel cutting removes that job — changed by you, a conflict of the whole row to choose — and Someone else adds a job adds one under the next key, which the sheet's newKey gives a row of yours too: one you added meanwhile takes the key after it, and both are kept\n// inputs: []\n/** A job — what it is, when it starts and how many. */\nexport const SheetJob = StructType({ task: StringType, start: OptionType(DateTimeType), qty: OptionType(FloatType) });\n\n/** The jobs the conflicts example edits, in a record of their own, so no other example's edits meet them. */\nexport const sheetConflictJobs = e3.record(\"sheet_conflict_jobs\", DictType(StringType, SheetJob), {\n initial: new Map([\n [\"J-0001\", { task: \"Panel cutting\", start: some(new Date(\"2026-10-12T00:00:00Z\")), qty: some(48.0) }],\n [\"J-0002\", { task: \"Edge banding\", start: some(new Date(\"2026-10-13T00:00:00Z\")), qty: some(120.0) }],\n [\"J-0003\", { task: \"CNC routing\", start: some(new Date(\"2026-10-14T00:00:00Z\")), qty: some(48.0) }],\n [\"J-0004\", { task: \"Spray finish\", start: some(new Date(\"2026-10-15T00:00:00Z\")), qty: some(36.0) }],\n ]),\n mutations: (mutation) => ({\n // The jobs' patch door — every Save commits through it.\n patch: mutation.patch(),\n // Someone else's save: every job's quantity 12 more and its start a day later, its task as it was.\n elsewhere: mutation.reduce(East.function([DictType(StringType, SheetJob)], DictType(StringType, SheetJob), (_$, jobs) =>\n jobs.map((_$2, job) => ({\n task: job.task,\n start: job.start.match({\n some: (_$3, at) => East.value(some(at.addDays(1n)), OptionType(DateTimeType)),\n none: (_$3) => East.value(none, OptionType(DateTimeType)),\n }),\n qty: job.qty.match({\n some: (_$3, n) => East.value(some(n.add(12.0)), OptionType(FloatType)),\n none: (_$3) => East.value(none, OptionType(FloatType)),\n }),\n })))),\n // Someone else's save: Panel cutting, J-0001, removed — where the record still holds it.\n removes: mutation.reduce(East.function([DictType(StringType, SheetJob)], DictType(StringType, SheetJob), ($, jobs) => {\n const next = $.let(jobs.copy());\n $(next.tryDelete(\"J-0001\"));\n return next;\n })),\n // Someone else's save: a job added under the next key, J-0005 — where the record holds none there.\n adds: mutation.reduce(East.function([DictType(StringType, SheetJob)], DictType(StringType, SheetJob), ($, jobs) => {\n const next = $.let(jobs.copy());\n $.if(next.has(\"J-0005\").not(), ($2) => {\n const assembly = $2.const({ task: \"Assembly\", start: some(new Date(\"2026-10-16T00:00:00Z\")), qty: some(6.0) }, SheetJob);\n $2(next.insert(\"J-0005\", assembly));\n });\n return next;\n })),\n }),\n});\n\nEast.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const jobs = $.let(Record.bind(sheetConflictJobs, [\"patch\"]));\n const others = $.let(Record.bind(sheetConflictJobs, [\"elsewhere\", \"removes\", \"adds\"]));\n const theirs = $.const(East.function([], NullType, ($) => { $(others.mutate.elsewhere()); }));\n const theirRemoval = $.const(East.function([], NullType, ($) => { $(others.mutate.removes()); }));\n const theirAddition = $.const(East.function([], NullType, ($) => { $(others.mutate.adds()); }));\n // A new job's key in the workshop's own scheme: given every key taken, the first J-000N none of them is.\n const newKey = $.const(East.function([SetType(StringType)], StringType, ($, taken) => {\n const n = $.let(taken.size().add(1n));\n $.while(taken.has(East.str`J-000${n}`), ($2) => {\n $2.assign(n, n.add(1n));\n });\n return East.str`J-000${n}`;\n }));\n return (\n <VStack gap=\"3\" align=\"stretch\">\n <HStack gap=\"3\" wrap=\"wrap\">\n <Button variant=\"outline\" onClick={theirs} loading={others.mutate.pending()}>Someone else saves</Button>\n <Button variant=\"outline\" onClick={theirRemoval} loading={others.mutate.pending()}>Someone else removes Panel cutting</Button>\n <Button variant=\"outline\" onClick={theirAddition} loading={others.mutate.pending()}>Someone else adds a job</Button>\n </HStack>\n <Text color=\"fg.muted\">Someone else saves: every Qty 12 more, every Start a day later. Their removal: J-0001, Panel cutting. Their addition: J-0005, Assembly.</Text>\n <Box height=\"560px\">\n <Sheet\n name=\"conflicts\"\n record={jobs}\n columns={{\n task: Sheet.column.text(SheetJob, { header: \"Task\", width: \"240px\" }),\n start: Sheet.column.date(SheetJob, { header: \"Start\", width: \"96px\" }),\n qty: Sheet.column.quantity(SheetJob, { header: \"Qty\", width: \"96px\" }),\n }}\n newKey={newKey}\n />\n </Box>\n </VStack>\n );\n }}</Reactive>\n ))"
48632
48730
  },
48731
+ {
48732
+ "id": "e3-ui:alerts.examples.tsx:studioAlertsPage",
48733
+ "skill": "e3-ui",
48734
+ "package": "e3-ui",
48735
+ "file": "east-ui/packages/e3-ui/test/studio/alerts.examples.tsx",
48736
+ "suite": "",
48737
+ "test": "Alerts on a published page over two years of orders, every reader starting in the latest quarter: the solution declares an alerts record (`Studio.Types.Alerts`, its one mutation a patch) and passes it bound to `<Studio.Page alerts>`, so each data visual's header carries a bell — marked while one of its alerts fires — whose popover lists them and sets one: its name, a condition on the visual's rows (its groups and values by name, in the query builder's condition rows), the rows that meet it now, pause and delete; a new alert starts from the visual's first value, under its goal where it has one. The page checks its project's alerts as it opens and as the orders change, and writes each one's latest firing; `<Studio.AlertBell>` in the host's bar counts the alerts firing and lists them, and opening one sets the page's filters to the alert's and tells `onOpen` its page, which then draws a banner naming the alert, with Show rows. Four are set: the quarter's revenue under its goal and the months under theirs, both firing; a customer over 50,000, which none is; and a region's margin under 19%, paused",
48738
+ "keywords": [
48739
+ "Studio",
48740
+ "Studio.Page",
48741
+ "Studio.AlertBell",
48742
+ "alerts",
48743
+ "alert",
48744
+ "bell",
48745
+ "notification",
48746
+ "condition",
48747
+ "threshold",
48748
+ "goal",
48749
+ "fires",
48750
+ "firing",
48751
+ "cleared",
48752
+ "paused",
48753
+ "Studio.Types.Alerts",
48754
+ "e3.record",
48755
+ "Record.bind",
48756
+ "mutation.patch",
48757
+ "banner",
48758
+ "Show rows",
48759
+ "onOpen",
48760
+ "State.bind",
48761
+ "Studio.source",
48762
+ "Data.bind"
48763
+ ],
48764
+ "imports": [
48765
+ "import { East, NullType, example, none, parseJq, type ValueTypeOf } from \"@elaraai/east\";",
48766
+ "import { Box, HStack, Reactive, State, Text, UIComponentType, VStack } from \"@elaraai/east-ui\";",
48767
+ "import { Data, Record, Studio } from \"@elaraai/e3-ui\";",
48768
+ "import e3 from \"@elaraai/e3\";",
48769
+ "import { orderFields, studioOrders, studioVisualPages } from \"./studio.examples.js\";"
48770
+ ],
48771
+ "languages": [
48772
+ "tsx"
48773
+ ],
48774
+ "source": "// Alerts on a published page over two years of orders, every reader starting in the latest quarter: the solution declares an alerts record (`Studio.Types.Alerts`, its one mutation a patch) and passes it bound to `<Studio.Page alerts>`, so each data visual's header carries a bell — marked while one of its alerts fires — whose popover lists them and sets one: its name, a condition on the visual's rows (its groups and values by name, in the query builder's condition rows), the rows that meet it now, pause and delete; a new alert starts from the visual's first value, under its goal where it has one. The page checks its project's alerts as it opens and as the orders change, and writes each one's latest firing; `<Studio.AlertBell>` in the host's bar counts the alerts firing and lists them, and opening one sets the page's filters to the alert's and tells `onOpen` its page, which then draws a banner naming the alert, with Show rows. Four are set: the quarter's revenue under its goal and the months under theirs, both firing; a customer over 50,000, which none is; and a region's margin under 19%, paused\n// inputs: []\ntype Alert = ValueTypeOf<typeof Studio.Types.Alert>;\n\n/** The page the alerts are set on: the Visuals page, live as it was drafted. */\nconst VISUALS = { project: \"Sales desk\", page: \"Visuals\" };\n\n/** The latest quarter, as the alerts' filters hold it. */\nconst inQuarter = [{ source: \"orders\", where: quarter!, from: none }];\n\n/**\n * The alerts record: four alerts on the Visuals page, none fired yet — the\n * page writes each one's latest firing as it checks them.\n */\nexport const studioAlerts = e3.record(\"studio_alerts\", Studio.Types.Alerts, {\n initial: new Map<string, Alert>([\n [\"Quarter under goal\", { page: VISUALS, cell: \"v-revenue\", condition: quarterUnderGoal!, filters: inQuarter, paused: false, firing: none }],\n [\"Month under goal\", { page: VISUALS, cell: \"v-trend\", condition: monthUnderGoal!, filters: inQuarter, paused: false, firing: none }],\n [\"Customer over 50,000\", { page: VISUALS, cell: \"v-customers\", condition: customerOver!, filters: inQuarter, paused: false, firing: none }],\n [\"Margin under 19%\", { page: VISUALS, cell: \"v-combo\", condition: marginUnder!, filters: inQuarter, paused: true, firing: none }],\n ]),\n mutations: (mutation) => ({\n // The record's one write: every Save, pause, delete and firing is a patch of it.\n patch: mutation.patch(),\n }),\n});\n\nEast.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const pages = $.let(Data.bind(studioVisualPages));\n const orders = $.let(Data.bind(studioOrders));\n const alerts = $.let(Record.bind(studioAlerts));\n // The open page is the surface's: an alert opened from the bar writes it. A host with routes navigates here instead.\n const open = $.let(State.bind([Studio.Types.Key], \"ex.studio.alerts.open\", VISUALS));\n const go = $.const(East.function([Studio.Types.Key], NullType, ($2, key) => { $2(open.write(key)); }));\n return (\n <VStack gap=\"3\" align=\"stretch\">\n <HStack justify=\"space-between\" align=\"center\">\n <Text>{East.str`${open.read().project} · ${open.read().page}`}</Text>\n <Studio.AlertBell alerts={alerts} onOpen={go} />\n </HStack>\n <Studio.Page pages={pages.read()} components={[]} page={open.read()} onOpen={go} alerts={alerts}\n sources={{\n orders: Studio.source(orders, {\n name: \"Orders\", icon: \"receipt\", description: \"One row per order\",\n fields: orderFields,\n range: \"ordered_at\",\n }),\n }} />\n </VStack>\n );\n }}</Reactive>\n ))"
48775
+ },
48776
+ {
48777
+ "id": "e3-ui:alerts.examples.tsx:studioAlertsBuilder",
48778
+ "skill": "e3-ui",
48779
+ "package": "e3-ui",
48780
+ "file": "east-ui/packages/e3-ui/test/studio/alerts.examples.tsx",
48781
+ "suite": "",
48782
+ "test": "Alerts set from the builder: `<Studio.Builder alerts>` is given the alerts record bound, as the page is, so the selected visual's Configure tab in the inspector ends with Alerts — its alerts listed, each by its name and where it stands, under New alert — and one is written there, in place: its name, a condition on the visual's rows in the query builder's condition rows, pause, the rows that meet it now, Delete, Cancel and Save. Each tile of the canvas carries the same bell as the page's. An alert is the alerts record's, not the page's draft's: Save, pause and Delete are each a patch of the record as they are made, which the page's Undo, Discard and Publish leave as it is; the published page is what checks them",
48783
+ "keywords": [
48784
+ "Studio",
48785
+ "Studio.Builder",
48786
+ "alerts",
48787
+ "alert",
48788
+ "inspector",
48789
+ "Configure",
48790
+ "bell",
48791
+ "condition",
48792
+ "threshold",
48793
+ "goal",
48794
+ "paused",
48795
+ "Studio.Types.Alerts",
48796
+ "e3.record",
48797
+ "Record.bind",
48798
+ "mutation.patch",
48799
+ "Studio.source",
48800
+ "Data.bind"
48801
+ ],
48802
+ "imports": [
48803
+ "import { East, NullType, example, none, parseJq, type ValueTypeOf } from \"@elaraai/east\";",
48804
+ "import { Box, HStack, Reactive, State, Text, UIComponentType, VStack } from \"@elaraai/east-ui\";",
48805
+ "import { Data, Record, Studio } from \"@elaraai/e3-ui\";",
48806
+ "import e3 from \"@elaraai/e3\";",
48807
+ "import { orderFields, studioOrders, studioVisualPages } from \"./studio.examples.js\";"
48808
+ ],
48809
+ "languages": [
48810
+ "tsx"
48811
+ ],
48812
+ "source": "// Alerts set from the builder: `<Studio.Builder alerts>` is given the alerts record bound, as the page is, so the selected visual's Configure tab in the inspector ends with Alerts — its alerts listed, each by its name and where it stands, under New alert — and one is written there, in place: its name, a condition on the visual's rows in the query builder's condition rows, pause, the rows that meet it now, Delete, Cancel and Save. Each tile of the canvas carries the same bell as the page's. An alert is the alerts record's, not the page's draft's: Save, pause and Delete are each a patch of the record as they are made, which the page's Undo, Discard and Publish leave as it is; the published page is what checks them\n// inputs: []\ntype Alert = ValueTypeOf<typeof Studio.Types.Alert>;\n\n/** The page the alerts are set on: the Visuals page, live as it was drafted. */\nconst VISUALS = { project: \"Sales desk\", page: \"Visuals\" };\n\n/** The latest quarter, as the alerts' filters hold it. */\nconst inQuarter = [{ source: \"orders\", where: quarter!, from: none }];\n\n/**\n * The alerts record: four alerts on the Visuals page, none fired yet — the\n * page writes each one's latest firing as it checks them.\n */\nexport const studioAlerts = e3.record(\"studio_alerts\", Studio.Types.Alerts, {\n initial: new Map<string, Alert>([\n [\"Quarter under goal\", { page: VISUALS, cell: \"v-revenue\", condition: quarterUnderGoal!, filters: inQuarter, paused: false, firing: none }],\n [\"Month under goal\", { page: VISUALS, cell: \"v-trend\", condition: monthUnderGoal!, filters: inQuarter, paused: false, firing: none }],\n [\"Customer over 50,000\", { page: VISUALS, cell: \"v-customers\", condition: customerOver!, filters: inQuarter, paused: false, firing: none }],\n [\"Margin under 19%\", { page: VISUALS, cell: \"v-combo\", condition: marginUnder!, filters: inQuarter, paused: true, firing: none }],\n ]),\n mutations: (mutation) => ({\n // The record's one write: every Save, pause, delete and firing is a patch of it.\n patch: mutation.patch(),\n }),\n});\n\nEast.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const pages = $.let(Record.bind(studioVisualPages));\n const orders = $.let(Data.bind(studioOrders));\n const alerts = $.let(Record.bind(studioAlerts));\n return (\n <Box height=\"760px\">\n <Studio.Builder pages={pages} components={[]} project=\"Sales desk\" id=\"studioAlerts\" alerts={alerts}\n sources={{\n orders: Studio.source(orders, {\n name: \"Orders\", icon: \"receipt\", description: \"One row per order\",\n fields: orderFields,\n range: \"ordered_at\",\n }),\n }} />\n </Box>\n );\n }}</Reactive>\n ))"
48813
+ },
48633
48814
  {
48634
48815
  "id": "e3-ui:component.examples.tsx:studioComponent",
48635
48816
  "skill": "e3-ui",
@@ -48661,7 +48842,202 @@
48661
48842
  "languages": [
48662
48843
  "tsx"
48663
48844
  ],
48664
- "source": "// A self-contained component — an East UI function written like a ui() body, declared once with what the palette shows — placed twice on a page, where the two placements share its own state\n// inputs: []\nEast.function([], UIComponentType, ($) => {\n const counter = $.let(Studio.component(\"counter\", {\n name: \"Counter\", category: \"Display\", icon: \"gauge-high\", span: 6n, description: \"Clicks so far\",\n }, East.function([], UIComponentType, _$ => (\n <Reactive>{$2 => {\n const clicks = $2.let(State.bind([IntegerType], \"studio-component.clicks\", 0n));\n const add = $2.const(East.function([], NullType, $3 => { $3(clicks.write(clicks.read().add(1n))); }));\n return (\n <Box padding=\"4\">\n <HStack gap=\"3\" align=\"center\">\n <Text>{East.str`${East.print(clicks.read())} clicks`}</Text>\n <Button size=\"xs\" onClick={add}>Add</Button>\n </HStack>\n </Box>\n );\n }}</Reactive>\n ))));\n const components = $.let([counter]);\n const pages = $.let(new Map([\n [{ project: \"demo\", page: \"counters\" }, variant(\"page\", {\n draft: {\n title: \"Counters\",\n cells: [\n { key: \"c-one\", row: \"r1\", span: 6n, height: none, align: variant(\"top\", null), title: none, component: \"counter\" },\n { key: \"c-two\", row: \"r1\", span: 6n, height: none, align: variant(\"top\", null), title: none, component: \"counter\" },\n ],\n },\n live: none,\n })],\n ]), Studio.Types.Pages);\n return <Studio.Page pages={pages} components={components} page={{ project: \"demo\", page: \"counters\" }} version=\"draft\" />;\n })"
48845
+ "source": "// A self-contained component — an East UI function written like a ui() body, declared once with what the palette shows — placed twice on a page, where the two placements share its own state\n// inputs: []\nEast.function([], UIComponentType, ($) => {\n const counter = $.let(Studio.component(\"counter\", {\n name: \"Counter\", category: \"Display\", icon: \"gauge-high\", span: 6n, description: \"Clicks so far\",\n }, East.function([], UIComponentType, _$ => (\n <Reactive>{$2 => {\n const clicks = $2.let(State.bind([IntegerType], \"studio-component.clicks\", 0n));\n const add = $2.const(East.function([], NullType, $3 => { $3(clicks.write(clicks.read().add(1n))); }));\n return (\n <Box padding=\"4\">\n <HStack gap=\"3\" align=\"center\">\n <Text>{East.str`${East.print(clicks.read())} clicks`}</Text>\n <Button size=\"xs\" onClick={add}>Add</Button>\n </HStack>\n </Box>\n );\n }}</Reactive>\n ))));\n const components = $.let([counter]);\n const pages = $.let(new Map([\n [{ project: \"demo\", page: \"counters\" }, variant(\"page\", {\n draft: {\n title: \"Counters\",\n cells: [\n { key: \"c-one\", row: \"r1\", span: 6n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"counter\") },\n { key: \"c-two\", row: \"r1\", span: 6n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"counter\") },\n ],\n filters: [],\n },\n live: none,\n })],\n ]), Studio.Types.Pages);\n return <Studio.Page pages={pages} components={components} page={{ project: \"demo\", page: \"counters\" }} version=\"draft\" />;\n })"
48846
+ },
48847
+ {
48848
+ "id": "e3-ui:configure.examples.ts:studioPlacedPill",
48849
+ "skill": "e3-ui",
48850
+ "package": "e3-ui",
48851
+ "file": "east-ui/packages/e3-ui/test/studio/configure.examples.ts",
48852
+ "suite": "",
48853
+ "test": "The pill a field makes placed in a well: a number in a value well is summed, over the page's range, higher the better",
48854
+ "keywords": [
48855
+ "Studio",
48856
+ "Configure",
48857
+ "inspector",
48858
+ "placedPill",
48859
+ "well",
48860
+ "pill",
48861
+ "field",
48862
+ "value",
48863
+ "sum",
48864
+ "default",
48865
+ "MOD-6"
48866
+ ],
48867
+ "imports": [
48868
+ "import { ArrayType, East, OptionType, StringType, example, none, some, variant } from \"@elaraai/east\";",
48869
+ "import {"
48870
+ ],
48871
+ "languages": [
48872
+ "typescript"
48873
+ ],
48874
+ "source": "// The pill a field makes placed in a well: a number in a value well is summed, over the page's range, higher the better\n// inputs: [] returns: variant(\"value\", {\n measure: variant(\"sum\", \"revenue\"), label: none, period: variant(\"current\", null), goal: none, better: variant(\"higher\", null), format: none,\n })\nEast.function([], StudioPillType, ($) => {\n const well = $.const({\n field: \"value\", label: \"Value\", holds: variant(\"value\", null), list: false, optional: false, most: none, one: none, accepts: [],\n }, StudioWellType);\n const revenue = $.const({ id: \"revenue\", label: \"Revenue\", kind: variant(\"number\", null), format: none }, StudioFieldType);\n return placedPill(well, revenue);\n })"
48875
+ },
48876
+ {
48877
+ "id": "e3-ui:configure.examples.ts:studioFieldGroup",
48878
+ "skill": "e3-ui",
48879
+ "package": "e3-ui",
48880
+ "file": "east-ui/packages/e3-ui/test/studio/configure.examples.ts",
48881
+ "suite": "",
48882
+ "test": "A field as a group: a date bucketed by month in time order; any other field would sort highest first",
48883
+ "keywords": [
48884
+ "Studio",
48885
+ "Configure",
48886
+ "fieldGroup",
48887
+ "group",
48888
+ "bucket",
48889
+ "month",
48890
+ "date",
48891
+ "sort",
48892
+ "natural",
48893
+ "default",
48894
+ "MOD-6"
48895
+ ],
48896
+ "imports": [
48897
+ "import { ArrayType, East, OptionType, StringType, example, none, some, variant } from \"@elaraai/east\";",
48898
+ "import {"
48899
+ ],
48900
+ "languages": [
48901
+ "typescript"
48902
+ ],
48903
+ "source": "// A field as a group: a date bucketed by month in time order; any other field would sort highest first\n// inputs: [] returns: variant(\"group\", { field: \"ordered_at\", bucket: some(variant(\"month\", null)), sort: variant(\"natural\", null), top: none })\nEast.function([], StudioPillType, ($) => {\n const ordered = $.const({ id: \"ordered_at\", label: \"Ordered\", kind: variant(\"date\", null), format: none }, StudioFieldType);\n return variant(\"group\", fieldGroup(ordered));\n })"
48904
+ },
48905
+ {
48906
+ "id": "e3-ui:configure.examples.ts:studioFieldMeasures",
48907
+ "skill": "e3-ui",
48908
+ "package": "e3-ui",
48909
+ "file": "east-ui/packages/e3-ui/test/studio/configure.examples.ts",
48910
+ "suite": "",
48911
+ "test": "The measures a value of a number may take — its total, mean, least, most, distinct values and the rows; text or a date takes distinct and count only",
48912
+ "keywords": [
48913
+ "Studio",
48914
+ "Configure",
48915
+ "fieldMeasures",
48916
+ "measure",
48917
+ "aggregate",
48918
+ "sum",
48919
+ "mean",
48920
+ "min",
48921
+ "max",
48922
+ "distinct",
48923
+ "count",
48924
+ "EDT-4"
48925
+ ],
48926
+ "imports": [
48927
+ "import { ArrayType, East, OptionType, StringType, example, none, some, variant } from \"@elaraai/east\";",
48928
+ "import {"
48929
+ ],
48930
+ "languages": [
48931
+ "typescript"
48932
+ ],
48933
+ "source": "// The measures a value of a number may take — its total, mean, least, most, distinct values and the rows; text or a date takes distinct and count only\n// inputs: [] returns: [\n variant(\"sum\", \"units\"), variant(\"mean\", \"units\"), variant(\"min\", \"units\"), variant(\"max\", \"units\"),\n variant(\"distinct\", \"units\"), variant(\"count\", null),\n ]\nEast.function([], ArrayType(Studio.Types.Measure), ($) => {\n const units = $.const({ id: \"units\", label: \"Units\", kind: variant(\"number\", null), format: none }, StudioFieldType);\n return fieldMeasures(units);\n })"
48934
+ },
48935
+ {
48936
+ "id": "e3-ui:configure.examples.ts:studioKindOfView",
48937
+ "skill": "e3-ui",
48938
+ "package": "e3-ui",
48939
+ "file": "east-ui/packages/e3-ui/test/studio/configure.examples.ts",
48940
+ "suite": "",
48941
+ "test": "The kind a visual's view is — the segment the Configure tab marks: a column chart's is column",
48942
+ "keywords": [
48943
+ "Studio",
48944
+ "Configure",
48945
+ "kindOfView",
48946
+ "kind",
48947
+ "view",
48948
+ "chart",
48949
+ "column",
48950
+ "segments"
48951
+ ],
48952
+ "imports": [
48953
+ "import { ArrayType, East, OptionType, StringType, example, none, some, variant } from \"@elaraai/east\";",
48954
+ "import {"
48955
+ ],
48956
+ "languages": [
48957
+ "typescript"
48958
+ ],
48959
+ "source": "// The kind a visual's view is — the segment the Configure tab marks: a column chart's is column\n// inputs: [] returns: variant(\"column\", null)\nEast.function([], StudioKindType, ($) => {\n const view = $.const(variant(\"chart\", variant(\"column\", {\n x: { field: \"region\", bucket: none, sort: variant(\"high\", null), top: none },\n values: [],\n split: none,\n stack: variant(\"none\", null),\n legend: variant(\"auto\", null),\n })), StudioViewType);\n return kindOfView(view);\n })"
48960
+ },
48961
+ {
48962
+ "id": "e3-ui:configure.examples.ts:studioEmptyView",
48963
+ "skill": "e3-ui",
48964
+ "package": "e3-ui",
48965
+ "file": "east-ui/packages/e3-ui/test/studio/configure.examples.ts",
48966
+ "suite": "",
48967
+ "test": "A kind with nothing in its wells — what a dropped visual starts as: a pie's slices group no field, and its value counts the rows",
48968
+ "keywords": [
48969
+ "Studio",
48970
+ "Configure",
48971
+ "emptyView",
48972
+ "kind",
48973
+ "empty",
48974
+ "wells",
48975
+ "pie",
48976
+ "dropped visual",
48977
+ "MOD-4"
48978
+ ],
48979
+ "imports": [
48980
+ "import { ArrayType, East, OptionType, StringType, example, none, some, variant } from \"@elaraai/east\";",
48981
+ "import {"
48982
+ ],
48983
+ "languages": [
48984
+ "typescript"
48985
+ ],
48986
+ "source": "// A kind with nothing in its wells — what a dropped visual starts as: a pie's slices group no field, and its value counts the rows\n// inputs: [] returns: variant(\"chart\", variant(\"pie\", {\n slice: { field: \"\", bucket: none, sort: variant(\"natural\", null), top: none },\n value: { measure: variant(\"count\", null), label: none, period: variant(\"current\", null), goal: none, better: variant(\"higher\", null), format: none },\n donut: false,\n legend: variant(\"values\", null),\n }))\nEast.function([], StudioViewType, ($) => {\n const pie = $.const(variant(\"pie\", null), StudioKindType);\n return emptyView(pie);\n })"
48987
+ },
48988
+ {
48989
+ "id": "e3-ui:configure.examples.ts:studioSwitchedView",
48990
+ "skill": "e3-ui",
48991
+ "package": "e3-ui",
48992
+ "file": "east-ui/packages/e3-ui/test/studio/configure.examples.ts",
48993
+ "suite": "",
48994
+ "test": "A change of kind keeps every well that fits: a column chart switched to a line keeps its axis, its values, its split and its stack",
48995
+ "keywords": [
48996
+ "Studio",
48997
+ "Configure",
48998
+ "switchedView",
48999
+ "switch kind",
49000
+ "carry over",
49001
+ "column",
49002
+ "line",
49003
+ "stack",
49004
+ "EDT-8",
49005
+ "CHT-1"
49006
+ ],
49007
+ "imports": [
49008
+ "import { ArrayType, East, OptionType, StringType, example, none, some, variant } from \"@elaraai/east\";",
49009
+ "import {"
49010
+ ],
49011
+ "languages": [
49012
+ "typescript"
49013
+ ],
49014
+ "source": "// A change of kind keeps every well that fits: a column chart switched to a line keeps its axis, its values, its split and its stack\n// inputs: [] returns: variant(\"chart\", variant(\"line\", {\n x: { field: \"region\", bucket: none, sort: variant(\"high\", null), top: none },\n values: [{ measure: variant(\"sum\", \"revenue\"), label: none, period: variant(\"current\", null), goal: none, better: variant(\"higher\", null), format: none }],\n split: some(\"channel\"),\n stack: variant(\"stacked\", null),\n legend: variant(\"auto\", null),\n }))\nEast.function([], StudioViewType, ($) => {\n const column = $.const(variant(\"chart\", variant(\"column\", {\n x: { field: \"region\", bucket: none, sort: variant(\"high\", null), top: none },\n values: [{ measure: variant(\"sum\", \"revenue\"), label: none, period: variant(\"current\", null), goal: none, better: variant(\"higher\", null), format: none }],\n split: some(\"channel\"),\n stack: variant(\"stacked\", null),\n legend: variant(\"auto\", null),\n })), StudioViewType);\n const line = $.const(variant(\"line\", null), StudioKindType);\n return switchedView(column, line, []);\n })"
49015
+ },
49016
+ {
49017
+ "id": "e3-ui:configure.examples.ts:studioMostUsedSource",
49018
+ "skill": "e3-ui",
49019
+ "package": "e3-ui",
49020
+ "file": "east-ui/packages/e3-ui/test/studio/configure.examples.ts",
49021
+ "suite": "",
49022
+ "test": "The source a dropped visual reads: the one the page's visuals read most — here the assets, which two of three read",
49023
+ "keywords": [
49024
+ "Studio",
49025
+ "Configure",
49026
+ "mostUsedSource",
49027
+ "source",
49028
+ "palette",
49029
+ "drop",
49030
+ "most used",
49031
+ "BLD-2"
49032
+ ],
49033
+ "imports": [
49034
+ "import { ArrayType, East, OptionType, StringType, example, none, some, variant } from \"@elaraai/east\";",
49035
+ "import {"
49036
+ ],
49037
+ "languages": [
49038
+ "typescript"
49039
+ ],
49040
+ "source": "// The source a dropped visual reads: the one the page's visuals read most — here the assets, which two of three read\n// inputs: [] returns: some(\"assets\")\nEast.function([], OptionType(StringType), ($) => {\n const sources = $.const([\n {\n key: \"orders\", name: \"Orders\", icon: \"receipt\", description: none,\n binding: { name: \"orders\", source: variant(\"value\", [variant(\"field\", \"inputs\"), variant(\"field\", \"orders\")]), type: variant(\"Array\", variant(\"String\", null)) },\n fields: [], range: none,\n },\n {\n key: \"assets\", name: \"Assets\", icon: \"gears\", description: none,\n binding: { name: \"assets\", source: variant(\"value\", [variant(\"field\", \"inputs\"), variant(\"field\", \"assets\")]), type: variant(\"Array\", variant(\"String\", null)) },\n fields: [], range: none,\n },\n ], ArrayType(StudioSourceType));\n const count = $.const({\n measure: variant(\"count\", null), label: none, period: variant(\"current\", null), goal: none, better: variant(\"higher\", null), format: none,\n }, Studio.Types.Value);\n const cells = $.const([\n {\n key: \"c-assets\", row: \"r1\", span: 3n, height: none, align: variant(\"top\", null), title: none,\n content: variant(\"visual\", { source: \"assets\", where: none, view: variant(\"kpi\", { value: count, compare: none, trend: none }), click: variant(\"filter\", null), follow: none }),\n },\n {\n key: \"c-orders\", row: \"r1\", span: 3n, height: none, align: variant(\"top\", null), title: none,\n content: variant(\"visual\", { source: \"orders\", where: none, view: variant(\"kpi\", { value: count, compare: none, trend: none }), click: variant(\"filter\", null), follow: none }),\n },\n {\n key: \"c-assets-2\", row: \"r1\", span: 3n, height: none, align: variant(\"top\", null), title: none,\n content: variant(\"visual\", { source: \"assets\", where: none, view: variant(\"kpi\", { value: count, compare: none, trend: none }), click: variant(\"filter\", null), follow: none }),\n },\n ], ArrayType(StudioCellType));\n return mostUsedSource(cells, sources);\n })"
48665
49041
  },
48666
49042
  {
48667
49043
  "id": "e3-ui:page.examples.tsx:studioPage",
@@ -48693,7 +49069,7 @@
48693
49069
  "languages": [
48694
49070
  "tsx"
48695
49071
  ],
48696
- "source": "// One page's published layout with no chrome: each placement its component's own UI on the snap grid — a frameless KPI rail, and charts that take a tile's natural height\n// inputs: []\ntype Key = ValueTypeOf<typeof Studio.Types.Key>;\n\ntype Entry = ValueTypeOf<typeof Studio.Types.Entry>;\n\nEast.function([], UIComponentType, ($) => {\n const components = $.let([\n Studio.component(\"kpi_rail\", { name: \"KPI rail\", category: \"Display\", icon: \"gauge-high\", frame: \"none\" },\n East.function([], UIComponentType, (_$) => (\n <HStack gap=\"3\" align=\"stretch\">\n <Stat label=\"Revenue\" value={1280000.0} format={Format.Currency({ currency: \"USD\", compact: \"short\" })} />\n <Stat label=\"Orders\" value={8412.0} format={Format.Number()} />\n <Stat label=\"Avg ticket\" value={152.0} format={Format.Currency({ currency: \"USD\", maximumFractionDigits: 0n })} />\n <Stat label=\"Fill rate\" value={0.94} format={Format.Percent()} />\n </HStack>\n ))),\n Studio.component(\"revenue_trend\", { name: \"Revenue trend\", category: \"Charts\", icon: \"chart-area\", span: 8n },\n East.function([], UIComponentType, ($2) => {\n const days = $2.const([\n { day: \"Mar 1\", revenue: 2.61 }, { day: \"Mar 8\", revenue: 2.84 }, { day: \"Mar 15\", revenue: 3.02 },\n { day: \"Mar 22\", revenue: 2.95 }, { day: \"Mar 29\", revenue: 3.31 }, { day: \"Apr 5\", revenue: 3.48 },\n ], ArrayType(StructType({ day: StringType, revenue: FloatType })));\n return <Chart height=\"fill\" grid layers={Chart.Area(days, { x: r => r.day, y: r => r.revenue })} />;\n })),\n Studio.component(\"breakdown_bars\", { name: \"Breakdown bars\", category: \"Display\", icon: \"chart-bar\", span: 4n },\n East.function([], UIComponentType, ($2) => {\n const regions = $2.const([\n { region: \"North\", share: 42.0 }, { region: \"South\", share: 31.0 }, { region: \"West\", share: 27.0 },\n ], ArrayType(StructType({ region: StringType, share: FloatType })));\n return <Chart height=\"fill\" grid={false} layers={Chart.Bar(regions, { x: r => r.share, y: r => r.region })} />;\n })),\n ]);\n const pages = $.let(new Map<Key, Entry>([\n [{ project: \"ops\", page: \"overview\" }, variant(\"page\", {\n draft: {\n title: \"Overview\",\n cells: [\n { key: \"c-kpi\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, component: \"kpi_rail\" },\n { key: \"c-trend\", row: \"r2\", span: 8n, height: none, align: variant(\"top\", null), title: none, component: \"revenue_trend\" },\n { key: \"c-bars\", row: \"r2\", span: 4n, height: none, align: variant(\"top\", null), title: none, component: \"breakdown_bars\" },\n ],\n },\n live: some({\n version: 1n,\n page: {\n title: \"Overview\",\n cells: [\n { key: \"c-kpi\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, component: \"kpi_rail\" },\n { key: \"c-trend\", row: \"r2\", span: 8n, height: none, align: variant(\"top\", null), title: none, component: \"revenue_trend\" },\n { key: \"c-bars\", row: \"r2\", span: 4n, height: none, align: variant(\"top\", null), title: some(\"Revenue by region\"), component: \"breakdown_bars\" },\n ],\n },\n }),\n })],\n ]), Studio.Types.Pages);\n return <Studio.Page pages={pages} components={components} page={{ project: \"ops\", page: \"overview\" }} />;\n })"
49072
+ "source": "// One page's published layout with no chrome: each placement its component's own UI on the snap grid — a frameless KPI rail, and charts that take a tile's natural height\n// inputs: []\ntype Key = ValueTypeOf<typeof Studio.Types.Key>;\n\ntype Entry = ValueTypeOf<typeof Studio.Types.Entry>;\n\nEast.function([], UIComponentType, ($) => {\n const components = $.let([\n Studio.component(\"kpi_rail\", { name: \"KPI rail\", category: \"Display\", icon: \"gauge-high\", frame: \"none\" },\n East.function([], UIComponentType, (_$) => (\n <HStack gap=\"3\" align=\"stretch\">\n <Stat label=\"Revenue\" value={1280000.0} format={Format.Currency({ currency: \"USD\", compact: \"short\" })} />\n <Stat label=\"Orders\" value={8412.0} format={Format.Number()} />\n <Stat label=\"Avg ticket\" value={152.0} format={Format.Currency({ currency: \"USD\", maximumFractionDigits: 0n })} />\n <Stat label=\"Fill rate\" value={0.94} format={Format.Percent()} />\n </HStack>\n ))),\n Studio.component(\"revenue_trend\", { name: \"Revenue trend\", category: \"Charts\", icon: \"chart-area\", span: 8n },\n East.function([], UIComponentType, ($2) => {\n const days = $2.const([\n { day: \"Mar 1\", revenue: 2.61 }, { day: \"Mar 8\", revenue: 2.84 }, { day: \"Mar 15\", revenue: 3.02 },\n { day: \"Mar 22\", revenue: 2.95 }, { day: \"Mar 29\", revenue: 3.31 }, { day: \"Apr 5\", revenue: 3.48 },\n ], ArrayType(StructType({ day: StringType, revenue: FloatType })));\n return <Chart height=\"fill\" grid layers={Chart.Area(days, { x: r => r.day, y: r => r.revenue })} />;\n })),\n Studio.component(\"breakdown_bars\", { name: \"Breakdown bars\", category: \"Display\", icon: \"chart-bar\", span: 4n },\n East.function([], UIComponentType, ($2) => {\n const regions = $2.const([\n { region: \"North\", share: 42.0 }, { region: \"South\", share: 31.0 }, { region: \"West\", share: 27.0 },\n ], ArrayType(StructType({ region: StringType, share: FloatType })));\n return <Chart height=\"fill\" grid={false} layers={Chart.Bar(regions, { x: r => r.share, y: r => r.region })} />;\n })),\n ]);\n const pages = $.let(new Map<Key, Entry>([\n [{ project: \"ops\", page: \"overview\" }, variant(\"page\", {\n draft: {\n title: \"Overview\",\n cells: [\n { key: \"c-kpi\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"kpi_rail\") },\n { key: \"c-trend\", row: \"r2\", span: 8n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n { key: \"c-bars\", row: \"r2\", span: 4n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"breakdown_bars\") },\n ],\n filters: [],\n },\n live: some({\n version: 1n,\n page: {\n title: \"Overview\",\n cells: [\n { key: \"c-kpi\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"kpi_rail\") },\n { key: \"c-trend\", row: \"r2\", span: 8n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n { key: \"c-bars\", row: \"r2\", span: 4n, height: none, align: variant(\"top\", null), title: some(\"Revenue by region\"), content: variant(\"component\", \"breakdown_bars\") },\n ],\n filters: [],\n },\n }),\n })],\n ]), Studio.Types.Pages);\n return <Studio.Page pages={pages} components={components} page={{ project: \"ops\", page: \"overview\" }} />;\n })"
48697
49073
  },
48698
49074
  {
48699
49075
  "id": "e3-ui:studio.examples.tsx:studioBuilder",
@@ -48701,7 +49077,7 @@
48701
49077
  "package": "e3-ui",
48702
49078
  "file": "east-ui/packages/e3-ui/test/studio/studio.examples.tsx",
48703
49079
  "suite": "",
48704
- "test": "The builder over the pages record: the Ops console's Overview on the canvas under one toolbar — its status, the zoom, the history item, Desktop · Tablet, Save as template, Preview and Publish — the palette of the seven components before it and the inspector after it; Preview and Publish open the publish preview in the canvas's place, its two changes since v3, and Exit returns",
49080
+ "test": "The builder over the pages record: the Ops console's Overview on the canvas under one toolbar — its status, the zoom, the history item, Desktop · Tablet, Save as template, Preview and Publish — the palette of the seven components before it and the inspector after it; Preview and Publish open the publish preview in the canvas's place, its two changes since v3, and Exit returns; the page it shows is the surface's own state, given as `page` and changed in `onOpen` when the palette's Pages tab asks for another",
48705
49081
  "keywords": [
48706
49082
  "Studio",
48707
49083
  "Studio.Builder",
@@ -48735,12 +49111,13 @@
48735
49111
  "import {",
48736
49112
  "import {",
48737
49113
  "import { Data, Record, Studio } from \"@elaraai/e3-ui\";",
48738
- "import e3 from \"@elaraai/e3\";"
49114
+ "import e3 from \"@elaraai/e3\";",
49115
+ "import {"
48739
49116
  ],
48740
49117
  "languages": [
48741
49118
  "tsx"
48742
49119
  ],
48743
- "source": "// The builder over the pages record: the Ops console's Overview on the canvas under one toolbar — its status, the zoom, the history item, Desktop · Tablet, Save as template, Preview and Publish — the palette of the seven components before it and the inspector after it; Preview and Publish open the publish preview in the canvas's place, its two changes since v3, and Exit returns\n// inputs: []\ntype Key = ValueTypeOf<typeof Studio.Types.Key>;\n\ntype Entry = ValueTypeOf<typeof Studio.Types.Entry>;\n\n/** What a KPI measures: an amount of money, a count, a price or a ratio. */\nconst KpiUnit = VariantType({ money: NullType, count: NullType, price: NullType, ratio: NullType });\n\n/** The week's figures, each with its change on last week in percent — what a KPI task writes. */\nexport const studioKpis = e3.input(\"studio_kpis\", ArrayType(StructType({\n label: StringType, value: FloatType, unit: KpiUnit, change: FloatType,\n})), variant(\"value\", [\n { label: \"Revenue\", value: 1284000.0, unit: variant(\"money\", null), change: 6.4 },\n { label: \"Orders\", value: 8412.0, unit: variant(\"count\", null), change: 2.1 },\n { label: \"Avg ticket\", value: 152.0, unit: variant(\"price\", null), change: -1.3 },\n { label: \"Fill rate\", value: 0.94, unit: variant(\"ratio\", null), change: 0.0 },\n]));\n\n/** Revenue by day. */\nexport const studioRevenueDaily = e3.input(\"studio_revenue_daily\", ArrayType(StructType({ day: DateTimeType, revenue: FloatType })), variant(\"value\", [\n { day: new Date(\"2026-02-12T00:00:00Z\"), revenue: 2640000.0 },\n { day: new Date(\"2026-02-19T00:00:00Z\"), revenue: 2710000.0 },\n { day: new Date(\"2026-02-26T00:00:00Z\"), revenue: 2900000.0 },\n { day: new Date(\"2026-03-05T00:00:00Z\"), revenue: 3180000.0 },\n { day: new Date(\"2026-03-12T00:00:00Z\"), revenue: 3300000.0 },\n { day: new Date(\"2026-03-19T00:00:00Z\"), revenue: 3430000.0 },\n]));\n\n/** This week's sales, one row per region per channel. */\nexport const studioSales = e3.input(\"studio_sales\", ArrayType(StructType({ region: StringType, channel: StringType, revenue: FloatType })), variant(\"value\", [\n { region: \"North\", channel: \"Store\", revenue: 331200.0 },\n { region: \"North\", channel: \"Online\", revenue: 208080.0 },\n { region: \"South\", channel: \"Store\", revenue: 238824.0 },\n { region: \"South\", channel: \"Online\", revenue: 159216.0 },\n { region: \"West\", channel: \"Store\", revenue: 197604.0 },\n { region: \"West\", channel: \"Online\", revenue: 149076.0 },\n]));\n\n/** Orders by week. */\nexport const studioOrdersWeekly = e3.input(\"studio_orders_weekly\", ArrayType(StructType({ week: StringType, orders: FloatType })), variant(\"value\", [\n { week: \"W9\", orders: 96.0 }, { week: \"W10\", orders: 158.0 }, { week: \"W11\", orders: 214.0 },\n { week: \"W12\", orders: 271.0 }, { week: \"W13\", orders: 248.0 }, { week: \"W14\", orders: 196.0 },\n]));\n\n/** Visits by day, the last two weeks. */\nexport const studioVisitsDaily = e3.input(\"studio_visits_daily\", ArrayType(StructType({ day: DateTimeType, visits: FloatType })), variant(\"value\", [\n { day: new Date(\"2026-03-06T00:00:00Z\"), visits: 412.0 }, { day: new Date(\"2026-03-07T00:00:00Z\"), visits: 388.0 },\n { day: new Date(\"2026-03-08T00:00:00Z\"), visits: 301.0 }, { day: new Date(\"2026-03-09T00:00:00Z\"), visits: 296.0 },\n { day: new Date(\"2026-03-10T00:00:00Z\"), visits: 455.0 }, { day: new Date(\"2026-03-11T00:00:00Z\"), visits: 471.0 },\n { day: new Date(\"2026-03-12T00:00:00Z\"), visits: 468.0 }, { day: new Date(\"2026-03-13T00:00:00Z\"), visits: 502.0 },\n { day: new Date(\"2026-03-14T00:00:00Z\"), visits: 479.0 }, { day: new Date(\"2026-03-15T00:00:00Z\"), visits: 344.0 },\n { day: new Date(\"2026-03-16T00:00:00Z\"), visits: 327.0 }, { day: new Date(\"2026-03-17T00:00:00Z\"), visits: 518.0 },\n { day: new Date(\"2026-03-18T00:00:00Z\"), visits: 546.0 }, { day: new Date(\"2026-03-19T00:00:00Z\"), visits: 561.0 },\n]));\n\n/** The floor's areas, its shifts and its people. */\nexport const studioAreas = e3.input(\"studio_areas\", ArrayType(StructType({ id: StringType, name: StringType })), variant(\"value\", [\n { id: \"north\", name: \"North\" }, { id: \"south\", name: \"South\" },\n]));\n\nexport const studioShifts = e3.input(\"studio_shifts\", ArrayType(StructType({ id: StringType, name: StringType, window: StringType })), variant(\"value\", [\n { id: \"am\", name: \"AM\", window: \"06–14\" }, { id: \"pm\", name: \"PM\", window: \"14–22\" }, { id: \"night\", name: \"Night\", window: \"22–06\" },\n]));\n\nexport const studioPeople = e3.input(\"studio_people\", ArrayType(StructType({ id: StringType, name: StringType })), variant(\"value\", [\n { id: \"p1\", name: \"Ana Ruiz\" }, { id: \"p2\", name: \"Ben Cole\" }, { id: \"p3\", name: \"Cai Lin\" }, { id: \"p4\", name: \"Dev Rao\" },\n { id: \"p5\", name: \"Eli Moss\" }, { id: \"p6\", name: \"Fay Ong\" }, { id: \"p7\", name: \"Gus Hart\" }, { id: \"p8\", name: \"Hana Ito\" },\n]));\n\n/** Who works where today. */\nexport const studioAssignmentsToday = e3.input(\"studio_assignments_today\", ArrayType(StructType({\n id: StringType, person: StringType, area: StringType, shift: StringType,\n})), variant(\"value\", [\n { id: \"a1\", person: \"p1\", area: \"north\", shift: \"am\" }, { id: \"a2\", person: \"p2\", area: \"north\", shift: \"am\" },\n { id: \"a3\", person: \"p3\", area: \"north\", shift: \"pm\" }, { id: \"a4\", person: \"p4\", area: \"north\", shift: \"night\" },\n { id: \"a5\", person: \"p5\", area: \"south\", shift: \"am\" }, { id: \"a6\", person: \"p6\", area: \"south\", shift: \"pm\" },\n { id: \"a7\", person: \"p7\", area: \"south\", shift: \"pm\" }, { id: \"a8\", person: \"p8\", area: \"south\", shift: \"night\" },\n]));\n\n/** This week's rota. */\nexport const studioRotaWeek = e3.input(\"studio_rota_week\", ArrayType(StructType({\n id: StringType, person: StringType, day: StringType, hours: IntegerType,\n})), variant(\"value\", [\n { id: \"r1\", person: \"p1\", day: \"Mon\", hours: 8n }, { id: \"r2\", person: \"p1\", day: \"Tue\", hours: 8n }, { id: \"r3\", person: \"p1\", day: \"Wed\", hours: 8n },\n { id: \"r4\", person: \"p2\", day: \"Mon\", hours: 8n }, { id: \"r5\", person: \"p2\", day: \"Thu\", hours: 8n }, { id: \"r6\", person: \"p2\", day: \"Fri\", hours: 6n },\n { id: \"r7\", person: \"p3\", day: \"Tue\", hours: 8n }, { id: \"r8\", person: \"p3\", day: \"Wed\", hours: 8n }, { id: \"r9\", person: \"p3\", day: \"Thu\", hours: 8n },\n { id: \"r10\", person: \"p4\", day: \"Mon\", hours: 10n }, { id: \"r11\", person: \"p4\", day: \"Fri\", hours: 10n },\n]));\n\n/** The KPI rail's code: the week's four figures, each with its change on last week. */\nconst kpiRailUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const kpis = $.let(Data.bind(studioKpis).read());\n return (\n <Box background=\"border.subtle\"><Grid gap=\"1px\" templateColumns=\"repeat(auto-fit, minmax(min(calc(50% - 1px), 170px), 1fr))\" items={kpis.map(($2, k) => Grid.Item(\n <Box background=\"bg.surface\"\n padding={{ top: some(\"3\"), right: some(\"4\"), bottom: some(\"3\"), left: some(\"4\") }}>\n <Stat label={k.label} value={k.value}\n format={k.unit.match({\n money: (_$3) => Format.Currency({ currency: \"USD\", compact: \"short\", maximumFractionDigits: 2n }),\n count: (_$3) => Format.Number(),\n price: (_$3) => Format.Currency({ currency: \"USD\", maximumFractionDigits: 0n }),\n ratio: (_$3) => Format.Percent({ maximumFractionDigits: 0n }),\n })}\n baseline={\n <MetricChip tone={k.change.greater(0.0).ifElse(\n _$3 => variant(\"positive\", null),\n _$3 => k.change.less(0.0).ifElse(_$4 => variant(\"negative\", null), _$4 => variant(\"neutral\", null)),\n )}>\n <Text>{k.change.greater(0.0).ifElse(\n _$3 => East.str`▲ ${East.print(k.change)}%`,\n _$3 => k.change.less(0.0).ifElse(\n _$4 => East.str`▼ ${East.print(k.change.negate())}%`,\n _$4 => \"— flat\",\n ),\n )}</Text>\n </MetricChip>\n } />\n </Box>,\n ))} /></Box>\n );\n }}</Reactive>\n));\n\n/** The Revenue trend's code: revenue by day, as an area. */\nconst revenueTrendUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const days = $.let(Data.bind(studioRevenueDaily).read());\n return (\n <Box height=\"168px\" padding={{ top: some(\"4\"), right: some(\"4\"), bottom: some(\"3\"), left: some(\"3\") }}>\n <Chart height=\"fill\" grid\n layers={Chart.Area(days, { x: r => r.day, y: r => r.revenue }, { color: \"brand.solid\", fillOpacity: 0.08, curve: \"linear\" })}\n x={{ format: Chart.format.date(\"MMM D\") }}\n y={{ format: Chart.format.compact() }} />\n </Box>\n );\n }}</Reactive>\n));\n\n/** The Breakdown bars' code: each region's share of this week's revenue, largest first. */\nconst breakdownBarsUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const sales = $.let(Data.bind(studioSales).read());\n const total = $.let(sales.map(($2, r) => r.revenue).sum());\n const regions = $.let(sales\n .groupSum(($2, r) => r.region, ($2, r) => r.revenue)\n .toArray(($2, revenue, region) => ({ region, revenue })));\n return (\n <Box padding=\"4\">\n <BarStrip data={regions} sort=\"desc\" showValues={false}\n item={r => ({\n label: <Text>{r.region}</Text>,\n value: r.revenue,\n trailing: <Text>{East.str`${East.print(East.Float.roundHalf(r.revenue.divide(total).multiply(100.0)))}%`}</Text>,\n })} />\n </Box>\n );\n }}</Reactive>\n));\n\n/** The Orders by week's code: orders placed each week. */\nconst ordersByWeekUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const weeks = $.let(Data.bind(studioOrdersWeekly).read());\n return (\n <Box height=\"168px\" padding={{ top: some(\"4\"), right: some(\"4\"), bottom: some(\"3\"), left: some(\"3\") }}>\n <Chart height=\"fill\" grid layers={Chart.Column(weeks, { x: r => r.week, y: r => r.orders }, { color: \"brand.solid\" })} />\n </Box>\n );\n }}</Reactive>\n));\n\n/** The Visits sparkline's code: visits by day. */\nconst visitsSparklineUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const visits = $.let(Data.bind(studioVisitsDaily).read());\n return (\n <Box padding=\"4\">\n <Sparkline data={visits.map(($2, r) => r.visits)} type=\"area\" width=\"100%\" height=\"48px\" />\n </Box>\n );\n }}</Reactive>\n));\n\n/** Today's assignments as a read-only table using the shared collection. */\nconst assignmentBoardUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const areas = $.let(Data.bind(studioAreas).read().toDict((_$2, area) => area.id, (_$2, area) => area.name));\n const shifts = $.let(Data.bind(studioShifts).read().toDict((_$2, shift) => shift.id, (_$2, shift) => shift.name));\n const people = $.let(Data.bind(studioPeople).read().toDict((_$2, person) => person.id, (_$2, person) => person.name));\n const today = $.let(Data.bind(studioAssignmentsToday).read());\n return <Table data={today.map((_$2, row) => ({ person: people.get(row.person), area: areas.get(row.area), shift: shifts.get(row.shift) }))} columns={[\"person\", \"area\", \"shift\"]} />;\n }}</Reactive>\n));\n\n/** The week's shifts as a read-only table; editable rostering belongs to e3-ui. */\nconst shiftRosterUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const people = $.let(Data.bind(studioPeople).read().toDict((_$2, person) => person.id, (_$2, person) => person.name));\n const rota = $.let(Data.bind(studioRotaWeek).read());\n return <Table data={rota.map((_$2, row) => ({ person: people.get(row.person), day: row.day, hours: row.hours }))} columns={[\"person\", \"day\", \"hours\"]} />;\n }}</Reactive>\n));\n\nexport const kpiRail = Studio.component(\"kpi_rail\", {\n name: \"KPI rail\", category: \"Display\", icon: \"gauge-high\", frame: \"none\",\n description: \"Revenue, orders, average ticket and fill rate this week, each with its change on last week.\",\n tags: [\"kpi\", \"sales\"],\n}, kpiRailUi);\n\nexport const breakdownBars = Studio.component(\"breakdown_bars\", {\n name: \"Breakdown bars\", category: \"Display\", icon: \"chart-bar\", span: 4n,\n description: \"Each region's share of this week's revenue, largest first.\",\n tags: [\"sales\"],\n}, breakdownBarsUi);\n\nexport const revenueTrend = Studio.component(\"revenue_trend\", {\n name: \"Revenue trend\", category: \"Charts\", icon: \"chart-area\", span: 8n,\n description: \"Revenue by day, as an area.\",\n tags: [\"sales\"],\n}, revenueTrendUi);\n\nexport const ordersByWeek = Studio.component(\"orders_by_week\", {\n name: \"Orders by week\", category: \"Charts\", icon: \"chart-column\", span: 6n,\n description: \"Orders placed each week.\",\n tags: [\"orders\"],\n}, ordersByWeekUi);\n\nexport const visitsSparkline = Studio.component(\"visits_sparkline\", {\n name: \"Visits sparkline\", category: \"Charts\", icon: \"chart-line\", span: 4n,\n description: \"Visits by day, the last two weeks.\",\n tags: [\"traffic\"],\n}, visitsSparklineUi);\n\nexport const assignmentBoard = Studio.component(\"assignment_board\", {\n name: \"Assignment board\", category: \"Collections\", icon: \"border-all\", span: 12n,\n description: \"Today: who works where, by shift.\",\n collections: [\"People\"],\n}, assignmentBoardUi);\n\nexport const shiftRoster = Studio.component(\"shift_roster\", {\n name: \"Shift roster\", category: \"Collections\", icon: \"calendar-week\", span: 12n,\n description: \"This week: people, days and their assigned hours.\",\n collections: [\"People\"],\n}, shiftRosterUi);\n\n/**\n * The pages record: the Ops console's pages — the Overview live as v3, its\n * draft resizing the trend and adding the bars beside it — and its templates,\n * and the other projects' pages.\n */\nexport const studioPages = e3.record(\"studio_pages\", Studio.Types.Pages, {\n initial: new SortedMap<Key, Entry>([\n [{ project: \"Ops console\", page: \"Account detail\" }, variant(\"page\", {\n draft: {\n title: \"Account detail\",\n cells: [\n { key: \"a-kpi\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, component: \"kpi_rail\" },\n { key: \"a-orders\", row: \"r2\", span: 8n, height: some(240n), align: variant(\"top\", null), title: none, component: \"orders_by_week\" },\n { key: \"a-bars\", row: \"r2\", span: 4n, height: some(240n), align: variant(\"stretch\", null), title: none, component: \"breakdown_bars\" },\n { key: \"a-trend\", row: \"r3\", span: 12n, height: some(200n), align: variant(\"top\", null), title: none, component: \"revenue_trend\" },\n ],\n },\n live: none,\n })],\n [{ project: \"Ops console\", page: \"Overview\" }, variant(\"page\", {\n draft: {\n title: \"Overview\",\n cells: [\n { key: \"o-kpi\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, component: \"kpi_rail\" },\n { key: \"o-trend\", row: \"r2\", span: 8n, height: none, align: variant(\"stretch\", null), title: none, component: \"revenue_trend\" },\n { key: \"o-bars\", row: \"r2\", span: 4n, height: none, align: variant(\"stretch\", null), title: none, component: \"breakdown_bars\" },\n { key: \"o-board\", row: \"r3\", span: 12n, height: none, align: variant(\"top\", null), title: none, component: \"assignment_board\" },\n ],\n },\n live: some({\n version: 3n,\n page: {\n title: \"Overview\",\n cells: [\n { key: \"o-kpi\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, component: \"kpi_rail\" },\n { key: \"o-trend\", row: \"r2\", span: 12n, height: none, align: variant(\"stretch\", null), title: none, component: \"revenue_trend\" },\n { key: \"o-board\", row: \"r3\", span: 12n, height: none, align: variant(\"top\", null), title: none, component: \"assignment_board\" },\n ],\n },\n }),\n })],\n [{ project: \"Ops console\", page: \"Regional rollup\" }, variant(\"page\", {\n draft: {\n title: \"Regional rollup\",\n cells: [\n { key: \"r-trend\", row: \"r1\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, component: \"revenue_trend\" },\n { key: \"r-bars\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: some(\"By region\"), component: \"breakdown_bars\" },\n { key: \"r-visits\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: none, component: \"visits_sparkline\" },\n ],\n },\n live: some({\n version: 1n,\n page: {\n title: \"Regional rollup\",\n cells: [\n { key: \"r-trend\", row: \"r1\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, component: \"revenue_trend\" },\n { key: \"r-bars\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: some(\"By region\"), component: \"breakdown_bars\" },\n { key: \"r-visits\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: none, component: \"visits_sparkline\" },\n ],\n },\n }),\n })],\n [{ project: \"Ops console\", page: \"Weekly export\" }, variant(\"page\", {\n draft: {\n title: \"Weekly export\",\n cells: [\n { key: \"w-orders\", row: \"r1\", span: 12n, height: some(320n), align: variant(\"top\", null), title: none, component: \"orders_by_week\" },\n { key: \"w-roster\", row: \"r2\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, component: \"shift_roster\" },\n ],\n },\n live: some({ version: 2n, page: { title: \"Weekly export\", cells: [] } }),\n })],\n [{ project: \"Ops console\", page: \"Ops board\" }, variant(\"template\", {\n title: \"Ops board\",\n cells: [\n { key: \"t-orders\", row: \"r1\", span: 8n, height: some(320n), align: variant(\"top\", null), title: none, component: \"orders_by_week\" },\n { key: \"t-bars\", row: \"r1\", span: 4n, height: some(320n), align: variant(\"stretch\", null), title: none, component: \"breakdown_bars\" },\n ],\n })],\n [{ project: \"Ops console\", page: \"Report brief\" }, variant(\"template\", {\n title: \"Report brief\",\n cells: [\n { key: \"t-trend\", row: \"r1\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, component: \"revenue_trend\" },\n { key: \"t-orders\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: none, component: \"orders_by_week\" },\n { key: \"t-visits\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: none, component: \"visits_sparkline\" },\n ],\n })],\n [{ project: \"Ops console\", page: \"Summary\" }, variant(\"template\", {\n title: \"Summary\",\n cells: [\n { key: \"t-kpi\", row: \"r1\", span: 12n, height: some(96n), align: variant(\"top\", null), title: none, component: \"kpi_rail\" },\n { key: \"t-trend\", row: \"r2\", span: 8n, height: some(240n), align: variant(\"top\", null), title: none, component: \"revenue_trend\" },\n { key: \"t-bars\", row: \"r2\", span: 4n, height: some(240n), align: variant(\"stretch\", null), title: none, component: \"breakdown_bars\" },\n ],\n })],\n [{ project: \"Finance portal\", page: \"Ledger\" }, variant(\"page\", {\n draft: {\n title: \"Ledger\",\n cells: [\n { key: \"l-trend\", row: \"r1\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, component: \"revenue_trend\" },\n ],\n },\n live: none,\n })],\n [{ project: \"HR roster\", page: \"Rota\" }, variant(\"page\", {\n draft: {\n title: \"Rota\",\n cells: [\n { key: \"h-roster\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, component: \"shift_roster\" },\n ],\n },\n live: some({\n version: 1n,\n page: {\n title: \"Rota\",\n cells: [\n { key: \"h-roster\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, component: \"shift_roster\" },\n ],\n },\n }),\n })],\n ], compareFor(Studio.Types.Key)),\n mutations: (mutation) => ({\n // The record's one write.\n patch: mutation.patch(),\n }),\n});\n\nEast.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const components = $.let([kpiRail, breakdownBars, revenueTrend, ordersByWeek, visitsSparkline, assignmentBoard, shiftRoster]);\n const pages = $.let(Record.bind(studioPages));\n return (\n <Box height=\"760px\">\n <Studio.Builder pages={pages} components={components} project=\"Ops console\" id=\"studio\"\n env=\"Staging\" audience=\"Field ops · 24 users\" rollout=\"Immediate\" />\n </Box>\n );\n }}</Reactive>\n ))"
49120
+ "source": "// The builder over the pages record: the Ops console's Overview on the canvas under one toolbar — its status, the zoom, the history item, Desktop · Tablet, Save as template, Preview and Publish — the palette of the seven components before it and the inspector after it; Preview and Publish open the publish preview in the canvas's place, its two changes since v3, and Exit returns; the page it shows is the surface's own state, given as `page` and changed in `onOpen` when the palette's Pages tab asks for another\n// inputs: []\ntype Key = ValueTypeOf<typeof Studio.Types.Key>;\n\ntype Entry = ValueTypeOf<typeof Studio.Types.Entry>;\n\n/**\n * The KPI rail's code: the week's four figures, each with its change on last week — four abreast where four of\n * 170px fit, else two and two, else one above another, so no row stands short beside an empty cell.\n */\nconst kpiRailUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const kpis = $.let(Data.bind(studioKpis).read());\n return (\n <Box background=\"border.subtle\"><Grid gap=\"1px\" templateColumns=\"repeat(auto-fit, minmax(max(calc(25% - 1px), min(calc(50% - 1px), calc((683px - 100%) * 999)), min(100%, calc((341px - 100%) * 999))), 1fr))\" items={kpis.map(($2, k) => Grid.Item(\n <Box background=\"bg.surface\"\n padding={{ top: some(\"3\"), right: some(\"4\"), bottom: some(\"3\"), left: some(\"4\") }}>\n <Stat label={k.label} value={k.value}\n format={k.unit.match({\n money: (_$3) => Format.Currency({ currency: \"USD\", compact: \"short\", maximumFractionDigits: 2n }),\n count: (_$3) => Format.Number(),\n price: (_$3) => Format.Currency({ currency: \"USD\", maximumFractionDigits: 0n }),\n ratio: (_$3) => Format.Percent({ maximumFractionDigits: 0n }),\n })}\n baseline={\n <MetricChip tone={k.change.greater(0.0).ifElse(\n _$3 => variant(\"positive\", null),\n _$3 => k.change.less(0.0).ifElse(_$4 => variant(\"negative\", null), _$4 => variant(\"neutral\", null)),\n )}>\n <Text>{k.change.greater(0.0).ifElse(\n _$3 => East.str`▲ ${East.print(k.change)}%`,\n _$3 => k.change.less(0.0).ifElse(\n _$4 => East.str`▼ ${East.print(k.change.negate())}%`,\n _$4 => \"— flat\",\n ),\n )}</Text>\n </MetricChip>\n } />\n </Box>,\n ))} /></Box>\n );\n }}</Reactive>\n));\n\n/** The Revenue trend's code: revenue by day, as an area. */\nconst revenueTrendUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const days = $.let(Data.bind(studioRevenueDaily).read());\n return (\n <Box height=\"168px\" padding={{ top: some(\"4\"), right: some(\"4\"), bottom: some(\"3\"), left: some(\"3\") }}>\n <Chart height=\"fill\" grid\n layers={Chart.Area(days, { x: r => r.day, y: r => r.revenue }, { color: \"brand.solid\", fillOpacity: 0.08, curve: \"linear\" })}\n x={{ format: Chart.format.date(\"MMM D\") }}\n y={{ format: Chart.format.compact() }} />\n </Box>\n );\n }}</Reactive>\n));\n\n/** The Breakdown bars' code: each region's share of this week's revenue, largest first. */\nconst breakdownBarsUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const sales = $.let(Data.bind(studioSales).read());\n const total = $.let(sales.map(($2, r) => r.revenue).sum());\n const regions = $.let(sales\n .groupSum(($2, r) => r.region, ($2, r) => r.revenue)\n .toArray(($2, revenue, region) => ({ region, revenue })));\n return (\n <Box padding=\"4\">\n <BarStrip data={regions} sort=\"desc\" showValues={false}\n item={r => ({\n label: <Text>{r.region}</Text>,\n value: r.revenue,\n trailing: <Text>{East.str`${East.print(East.Float.roundHalf(r.revenue.divide(total).multiply(100.0)))}%`}</Text>,\n })} />\n </Box>\n );\n }}</Reactive>\n));\n\n/** The Orders by week's code: orders placed each week. */\nconst ordersByWeekUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const weeks = $.let(Data.bind(studioOrdersWeekly).read());\n return (\n <Box height=\"168px\" padding={{ top: some(\"4\"), right: some(\"4\"), bottom: some(\"3\"), left: some(\"3\") }}>\n <Chart height=\"fill\" grid layers={Chart.Column(weeks, { x: r => r.week, y: r => r.orders }, { color: \"brand.solid\" })} />\n </Box>\n );\n }}</Reactive>\n));\n\n/** The Visits sparkline's code: visits by day. */\nconst visitsSparklineUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const visits = $.let(Data.bind(studioVisitsDaily).read());\n return (\n <Box padding=\"4\">\n <Sparkline data={visits.map(($2, r) => r.visits)} type=\"area\" width=\"100%\" height=\"48px\" />\n </Box>\n );\n }}</Reactive>\n));\n\n/** Today's assignments as a read-only table using the shared collection. */\nconst assignmentBoardUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const areas = $.let(Data.bind(studioAreas).read().toDict((_$2, area) => area.id, (_$2, area) => area.name));\n const shifts = $.let(Data.bind(studioShifts).read().toDict((_$2, shift) => shift.id, (_$2, shift) => shift.name));\n const people = $.let(Data.bind(studioPeople).read().toDict((_$2, person) => person.id, (_$2, person) => person.name));\n const today = $.let(Data.bind(studioAssignmentsToday).read());\n return <Table data={today.map((_$2, row) => ({ person: people.get(row.person), area: areas.get(row.area), shift: shifts.get(row.shift) }))} columns={[\"person\", \"area\", \"shift\"]} />;\n }}</Reactive>\n));\n\n/** The week's shifts as a read-only table; editable rostering belongs to e3-ui. */\nconst shiftRosterUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const people = $.let(Data.bind(studioPeople).read().toDict((_$2, person) => person.id, (_$2, person) => person.name));\n const rota = $.let(Data.bind(studioRotaWeek).read());\n return <Table data={rota.map((_$2, row) => ({ person: people.get(row.person), day: row.day, hours: row.hours }))} columns={[\"person\", \"day\", \"hours\"]} />;\n }}</Reactive>\n));\n\nexport const kpiRail = Studio.component(\"kpi_rail\", {\n name: \"KPI rail\", category: \"Display\", icon: \"gauge-high\", frame: \"none\",\n description: \"Revenue, orders, average ticket and fill rate this week, each with its change on last week.\",\n tags: [\"kpi\", \"sales\"],\n}, kpiRailUi);\n\nexport const breakdownBars = Studio.component(\"breakdown_bars\", {\n name: \"Breakdown bars\", category: \"Display\", icon: \"chart-bar\", span: 4n,\n description: \"Each region's share of this week's revenue, largest first.\",\n tags: [\"sales\"],\n}, breakdownBarsUi);\n\nexport const revenueTrend = Studio.component(\"revenue_trend\", {\n name: \"Revenue trend\", category: \"Charts\", icon: \"chart-area\", span: 8n,\n description: \"Revenue by day, as an area.\",\n tags: [\"sales\"],\n}, revenueTrendUi);\n\nexport const ordersByWeek = Studio.component(\"orders_by_week\", {\n name: \"Orders by week\", category: \"Charts\", icon: \"chart-column\", span: 6n,\n description: \"Orders placed each week.\",\n tags: [\"orders\"],\n}, ordersByWeekUi);\n\nexport const visitsSparkline = Studio.component(\"visits_sparkline\", {\n name: \"Visits sparkline\", category: \"Charts\", icon: \"chart-line\", span: 4n,\n description: \"Visits by day, the last two weeks.\",\n tags: [\"traffic\"],\n}, visitsSparklineUi);\n\nexport const assignmentBoard = Studio.component(\"assignment_board\", {\n name: \"Assignment board\", category: \"Collections\", icon: \"border-all\", span: 12n,\n description: \"Today: who works where, by shift.\",\n collections: [\"People\"],\n}, assignmentBoardUi);\n\nexport const shiftRoster = Studio.component(\"shift_roster\", {\n name: \"Shift roster\", category: \"Collections\", icon: \"calendar-week\", span: 12n,\n description: \"This week: people, days and their assigned hours.\",\n collections: [\"People\"],\n}, shiftRosterUi);\n\n/**\n * The pages record: the Ops console's pages — the Overview live as v3, its\n * draft resizing the trend and adding the bars beside it — and its templates,\n * and the other projects' pages.\n */\nexport const studioPages = e3.record(\"studio_pages\", Studio.Types.Pages, {\n initial: new SortedMap<Key, Entry>([\n [{ project: \"Ops console\", page: \"Account detail\" }, variant(\"page\", {\n draft: {\n title: \"Account detail\",\n cells: [\n { key: \"a-kpi\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"kpi_rail\") },\n { key: \"a-orders\", row: \"r2\", span: 8n, height: some(240n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"orders_by_week\") },\n { key: \"a-bars\", row: \"r2\", span: 4n, height: some(240n), align: variant(\"stretch\", null), title: none, content: variant(\"component\", \"breakdown_bars\") },\n { key: \"a-trend\", row: \"r3\", span: 12n, height: some(200n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n ],\n filters: [],\n },\n live: none,\n })],\n [{ project: \"Ops console\", page: \"Overview\" }, variant(\"page\", {\n draft: {\n title: \"Overview\",\n cells: [\n { key: \"o-kpi\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"kpi_rail\") },\n { key: \"o-trend\", row: \"r2\", span: 8n, height: none, align: variant(\"stretch\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n { key: \"o-bars\", row: \"r2\", span: 4n, height: none, align: variant(\"stretch\", null), title: none, content: variant(\"component\", \"breakdown_bars\") },\n { key: \"o-board\", row: \"r3\", span: 12n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"assignment_board\") },\n ],\n filters: [],\n },\n live: some({\n version: 3n,\n page: {\n title: \"Overview\",\n cells: [\n { key: \"o-kpi\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"kpi_rail\") },\n { key: \"o-trend\", row: \"r2\", span: 12n, height: none, align: variant(\"stretch\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n { key: \"o-board\", row: \"r3\", span: 12n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"assignment_board\") },\n ],\n filters: [],\n },\n }),\n })],\n [{ project: \"Ops console\", page: \"Regional rollup\" }, variant(\"page\", {\n draft: {\n title: \"Regional rollup\",\n cells: [\n { key: \"r-trend\", row: \"r1\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n { key: \"r-bars\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: some(\"By region\"), content: variant(\"component\", \"breakdown_bars\") },\n { key: \"r-visits\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"visits_sparkline\") },\n ],\n filters: [],\n },\n live: some({\n version: 1n,\n page: {\n title: \"Regional rollup\",\n cells: [\n { key: \"r-trend\", row: \"r1\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n { key: \"r-bars\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: some(\"By region\"), content: variant(\"component\", \"breakdown_bars\") },\n { key: \"r-visits\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"visits_sparkline\") },\n ],\n filters: [],\n },\n }),\n })],\n [{ project: \"Ops console\", page: \"Weekly export\" }, variant(\"page\", {\n draft: {\n title: \"Weekly export\",\n cells: [\n { key: \"w-orders\", row: \"r1\", span: 12n, height: some(320n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"orders_by_week\") },\n { key: \"w-roster\", row: \"r2\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"shift_roster\") },\n ],\n filters: [],\n },\n live: some({ version: 2n, page: { title: \"Weekly export\", cells: [], filters: [] } }),\n })],\n [{ project: \"Ops console\", page: \"Ops board\" }, variant(\"template\", {\n title: \"Ops board\",\n cells: [\n { key: \"t-orders\", row: \"r1\", span: 8n, height: some(320n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"orders_by_week\") },\n { key: \"t-bars\", row: \"r1\", span: 4n, height: some(320n), align: variant(\"stretch\", null), title: none, content: variant(\"component\", \"breakdown_bars\") },\n ],\n filters: [],\n })],\n [{ project: \"Ops console\", page: \"Report brief\" }, variant(\"template\", {\n title: \"Report brief\",\n cells: [\n { key: \"t-trend\", row: \"r1\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n { key: \"t-orders\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"orders_by_week\") },\n { key: \"t-visits\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"visits_sparkline\") },\n ],\n filters: [],\n })],\n [{ project: \"Ops console\", page: \"Summary\" }, variant(\"template\", {\n title: \"Summary\",\n cells: [\n { key: \"t-kpi\", row: \"r1\", span: 12n, height: some(96n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"kpi_rail\") },\n { key: \"t-trend\", row: \"r2\", span: 8n, height: some(240n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n { key: \"t-bars\", row: \"r2\", span: 4n, height: some(240n), align: variant(\"stretch\", null), title: none, content: variant(\"component\", \"breakdown_bars\") },\n ],\n filters: [],\n })],\n [{ project: \"Finance portal\", page: \"Ledger\" }, variant(\"page\", {\n draft: {\n title: \"Ledger\",\n cells: [\n { key: \"l-trend\", row: \"r1\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n ],\n filters: [],\n },\n live: none,\n })],\n [{ project: \"HR roster\", page: \"Rota\" }, variant(\"page\", {\n draft: {\n title: \"Rota\",\n cells: [\n { key: \"h-roster\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"shift_roster\") },\n ],\n filters: [],\n },\n live: some({\n version: 1n,\n page: {\n title: \"Rota\",\n cells: [\n { key: \"h-roster\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"shift_roster\") },\n ],\n filters: [],\n },\n }),\n })],\n ], compareFor(Studio.Types.Key)),\n mutations: (mutation) => ({\n // The record's one write.\n patch: mutation.patch(),\n }),\n});\n\nEast.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const components = $.let([kpiRail, breakdownBars, revenueTrend, ordersByWeek, visitsSparkline, assignmentBoard, shiftRoster]);\n const pages = $.let(Record.bind(studioPages));\n // The open page is the surface's — the project's first to begin with: the builder shows it, and the page library below opens another.\n const open = $.let(State.bind([Studio.Types.Key], \"ex.studio.open\", { project: \"Ops console\", page: \"Account detail\" }));\n const go = $.const(East.function([Studio.Types.Key], NullType, ($2, key) => { $2(open.write(key)); }));\n return (\n <Box height=\"760px\">\n <Studio.Builder pages={pages} components={components} project=\"Ops console\" id=\"studio\"\n page={open.read()} onOpen={go}\n env=\"Staging\" audience=\"Field ops · 24 users\" rollout=\"Immediate\" />\n </Box>\n );\n }}</Reactive>\n ))"
48744
49121
  },
48745
49122
  {
48746
49123
  "id": "e3-ui:studio.examples.tsx:studioBuilderMobile",
@@ -48748,7 +49125,7 @@
48748
49125
  "package": "e3-ui",
48749
49126
  "file": "east-ui/packages/e3-ui/test/studio/studio.examples.tsx",
48750
49127
  "suite": "",
48751
- "test": "The same builder over the pages record in a phone's 390-wide frame: the toolbar over its second row — the history at 44px — the canvas the frame's whole width, and the palette and the inspector a strip of drawers along the bottom edge",
49128
+ "test": "The same builder over the pages record in a phone's 390-wide frame: the toolbar over its second row — the history at 44px — the canvas the frame's whole width, and the palette and the inspector a strip of drawers along the bottom edge; given no `page`, it holds its own open page, the project's first to begin with",
48752
49129
  "keywords": [
48753
49130
  "Studio",
48754
49131
  "Studio.Builder",
@@ -48766,12 +49143,13 @@
48766
49143
  "import {",
48767
49144
  "import {",
48768
49145
  "import { Data, Record, Studio } from \"@elaraai/e3-ui\";",
48769
- "import e3 from \"@elaraai/e3\";"
49146
+ "import e3 from \"@elaraai/e3\";",
49147
+ "import {"
48770
49148
  ],
48771
49149
  "languages": [
48772
49150
  "tsx"
48773
49151
  ],
48774
- "source": "// The same builder over the pages record in a phone's 390-wide frame: the toolbar over its second row — the history at 44px — the canvas the frame's whole width, and the palette and the inspector a strip of drawers along the bottom edge\n// inputs: []\ntype Key = ValueTypeOf<typeof Studio.Types.Key>;\n\ntype Entry = ValueTypeOf<typeof Studio.Types.Entry>;\n\n/** What a KPI measures: an amount of money, a count, a price or a ratio. */\nconst KpiUnit = VariantType({ money: NullType, count: NullType, price: NullType, ratio: NullType });\n\n/** The week's figures, each with its change on last week in percent — what a KPI task writes. */\nexport const studioKpis = e3.input(\"studio_kpis\", ArrayType(StructType({\n label: StringType, value: FloatType, unit: KpiUnit, change: FloatType,\n})), variant(\"value\", [\n { label: \"Revenue\", value: 1284000.0, unit: variant(\"money\", null), change: 6.4 },\n { label: \"Orders\", value: 8412.0, unit: variant(\"count\", null), change: 2.1 },\n { label: \"Avg ticket\", value: 152.0, unit: variant(\"price\", null), change: -1.3 },\n { label: \"Fill rate\", value: 0.94, unit: variant(\"ratio\", null), change: 0.0 },\n]));\n\n/** Revenue by day. */\nexport const studioRevenueDaily = e3.input(\"studio_revenue_daily\", ArrayType(StructType({ day: DateTimeType, revenue: FloatType })), variant(\"value\", [\n { day: new Date(\"2026-02-12T00:00:00Z\"), revenue: 2640000.0 },\n { day: new Date(\"2026-02-19T00:00:00Z\"), revenue: 2710000.0 },\n { day: new Date(\"2026-02-26T00:00:00Z\"), revenue: 2900000.0 },\n { day: new Date(\"2026-03-05T00:00:00Z\"), revenue: 3180000.0 },\n { day: new Date(\"2026-03-12T00:00:00Z\"), revenue: 3300000.0 },\n { day: new Date(\"2026-03-19T00:00:00Z\"), revenue: 3430000.0 },\n]));\n\n/** This week's sales, one row per region per channel. */\nexport const studioSales = e3.input(\"studio_sales\", ArrayType(StructType({ region: StringType, channel: StringType, revenue: FloatType })), variant(\"value\", [\n { region: \"North\", channel: \"Store\", revenue: 331200.0 },\n { region: \"North\", channel: \"Online\", revenue: 208080.0 },\n { region: \"South\", channel: \"Store\", revenue: 238824.0 },\n { region: \"South\", channel: \"Online\", revenue: 159216.0 },\n { region: \"West\", channel: \"Store\", revenue: 197604.0 },\n { region: \"West\", channel: \"Online\", revenue: 149076.0 },\n]));\n\n/** Orders by week. */\nexport const studioOrdersWeekly = e3.input(\"studio_orders_weekly\", ArrayType(StructType({ week: StringType, orders: FloatType })), variant(\"value\", [\n { week: \"W9\", orders: 96.0 }, { week: \"W10\", orders: 158.0 }, { week: \"W11\", orders: 214.0 },\n { week: \"W12\", orders: 271.0 }, { week: \"W13\", orders: 248.0 }, { week: \"W14\", orders: 196.0 },\n]));\n\n/** Visits by day, the last two weeks. */\nexport const studioVisitsDaily = e3.input(\"studio_visits_daily\", ArrayType(StructType({ day: DateTimeType, visits: FloatType })), variant(\"value\", [\n { day: new Date(\"2026-03-06T00:00:00Z\"), visits: 412.0 }, { day: new Date(\"2026-03-07T00:00:00Z\"), visits: 388.0 },\n { day: new Date(\"2026-03-08T00:00:00Z\"), visits: 301.0 }, { day: new Date(\"2026-03-09T00:00:00Z\"), visits: 296.0 },\n { day: new Date(\"2026-03-10T00:00:00Z\"), visits: 455.0 }, { day: new Date(\"2026-03-11T00:00:00Z\"), visits: 471.0 },\n { day: new Date(\"2026-03-12T00:00:00Z\"), visits: 468.0 }, { day: new Date(\"2026-03-13T00:00:00Z\"), visits: 502.0 },\n { day: new Date(\"2026-03-14T00:00:00Z\"), visits: 479.0 }, { day: new Date(\"2026-03-15T00:00:00Z\"), visits: 344.0 },\n { day: new Date(\"2026-03-16T00:00:00Z\"), visits: 327.0 }, { day: new Date(\"2026-03-17T00:00:00Z\"), visits: 518.0 },\n { day: new Date(\"2026-03-18T00:00:00Z\"), visits: 546.0 }, { day: new Date(\"2026-03-19T00:00:00Z\"), visits: 561.0 },\n]));\n\n/** The floor's areas, its shifts and its people. */\nexport const studioAreas = e3.input(\"studio_areas\", ArrayType(StructType({ id: StringType, name: StringType })), variant(\"value\", [\n { id: \"north\", name: \"North\" }, { id: \"south\", name: \"South\" },\n]));\n\nexport const studioShifts = e3.input(\"studio_shifts\", ArrayType(StructType({ id: StringType, name: StringType, window: StringType })), variant(\"value\", [\n { id: \"am\", name: \"AM\", window: \"06–14\" }, { id: \"pm\", name: \"PM\", window: \"14–22\" }, { id: \"night\", name: \"Night\", window: \"22–06\" },\n]));\n\nexport const studioPeople = e3.input(\"studio_people\", ArrayType(StructType({ id: StringType, name: StringType })), variant(\"value\", [\n { id: \"p1\", name: \"Ana Ruiz\" }, { id: \"p2\", name: \"Ben Cole\" }, { id: \"p3\", name: \"Cai Lin\" }, { id: \"p4\", name: \"Dev Rao\" },\n { id: \"p5\", name: \"Eli Moss\" }, { id: \"p6\", name: \"Fay Ong\" }, { id: \"p7\", name: \"Gus Hart\" }, { id: \"p8\", name: \"Hana Ito\" },\n]));\n\n/** Who works where today. */\nexport const studioAssignmentsToday = e3.input(\"studio_assignments_today\", ArrayType(StructType({\n id: StringType, person: StringType, area: StringType, shift: StringType,\n})), variant(\"value\", [\n { id: \"a1\", person: \"p1\", area: \"north\", shift: \"am\" }, { id: \"a2\", person: \"p2\", area: \"north\", shift: \"am\" },\n { id: \"a3\", person: \"p3\", area: \"north\", shift: \"pm\" }, { id: \"a4\", person: \"p4\", area: \"north\", shift: \"night\" },\n { id: \"a5\", person: \"p5\", area: \"south\", shift: \"am\" }, { id: \"a6\", person: \"p6\", area: \"south\", shift: \"pm\" },\n { id: \"a7\", person: \"p7\", area: \"south\", shift: \"pm\" }, { id: \"a8\", person: \"p8\", area: \"south\", shift: \"night\" },\n]));\n\n/** This week's rota. */\nexport const studioRotaWeek = e3.input(\"studio_rota_week\", ArrayType(StructType({\n id: StringType, person: StringType, day: StringType, hours: IntegerType,\n})), variant(\"value\", [\n { id: \"r1\", person: \"p1\", day: \"Mon\", hours: 8n }, { id: \"r2\", person: \"p1\", day: \"Tue\", hours: 8n }, { id: \"r3\", person: \"p1\", day: \"Wed\", hours: 8n },\n { id: \"r4\", person: \"p2\", day: \"Mon\", hours: 8n }, { id: \"r5\", person: \"p2\", day: \"Thu\", hours: 8n }, { id: \"r6\", person: \"p2\", day: \"Fri\", hours: 6n },\n { id: \"r7\", person: \"p3\", day: \"Tue\", hours: 8n }, { id: \"r8\", person: \"p3\", day: \"Wed\", hours: 8n }, { id: \"r9\", person: \"p3\", day: \"Thu\", hours: 8n },\n { id: \"r10\", person: \"p4\", day: \"Mon\", hours: 10n }, { id: \"r11\", person: \"p4\", day: \"Fri\", hours: 10n },\n]));\n\n/** The KPI rail's code: the week's four figures, each with its change on last week. */\nconst kpiRailUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const kpis = $.let(Data.bind(studioKpis).read());\n return (\n <Box background=\"border.subtle\"><Grid gap=\"1px\" templateColumns=\"repeat(auto-fit, minmax(min(calc(50% - 1px), 170px), 1fr))\" items={kpis.map(($2, k) => Grid.Item(\n <Box background=\"bg.surface\"\n padding={{ top: some(\"3\"), right: some(\"4\"), bottom: some(\"3\"), left: some(\"4\") }}>\n <Stat label={k.label} value={k.value}\n format={k.unit.match({\n money: (_$3) => Format.Currency({ currency: \"USD\", compact: \"short\", maximumFractionDigits: 2n }),\n count: (_$3) => Format.Number(),\n price: (_$3) => Format.Currency({ currency: \"USD\", maximumFractionDigits: 0n }),\n ratio: (_$3) => Format.Percent({ maximumFractionDigits: 0n }),\n })}\n baseline={\n <MetricChip tone={k.change.greater(0.0).ifElse(\n _$3 => variant(\"positive\", null),\n _$3 => k.change.less(0.0).ifElse(_$4 => variant(\"negative\", null), _$4 => variant(\"neutral\", null)),\n )}>\n <Text>{k.change.greater(0.0).ifElse(\n _$3 => East.str`▲ ${East.print(k.change)}%`,\n _$3 => k.change.less(0.0).ifElse(\n _$4 => East.str`▼ ${East.print(k.change.negate())}%`,\n _$4 => \"— flat\",\n ),\n )}</Text>\n </MetricChip>\n } />\n </Box>,\n ))} /></Box>\n );\n }}</Reactive>\n));\n\n/** The Revenue trend's code: revenue by day, as an area. */\nconst revenueTrendUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const days = $.let(Data.bind(studioRevenueDaily).read());\n return (\n <Box height=\"168px\" padding={{ top: some(\"4\"), right: some(\"4\"), bottom: some(\"3\"), left: some(\"3\") }}>\n <Chart height=\"fill\" grid\n layers={Chart.Area(days, { x: r => r.day, y: r => r.revenue }, { color: \"brand.solid\", fillOpacity: 0.08, curve: \"linear\" })}\n x={{ format: Chart.format.date(\"MMM D\") }}\n y={{ format: Chart.format.compact() }} />\n </Box>\n );\n }}</Reactive>\n));\n\n/** The Breakdown bars' code: each region's share of this week's revenue, largest first. */\nconst breakdownBarsUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const sales = $.let(Data.bind(studioSales).read());\n const total = $.let(sales.map(($2, r) => r.revenue).sum());\n const regions = $.let(sales\n .groupSum(($2, r) => r.region, ($2, r) => r.revenue)\n .toArray(($2, revenue, region) => ({ region, revenue })));\n return (\n <Box padding=\"4\">\n <BarStrip data={regions} sort=\"desc\" showValues={false}\n item={r => ({\n label: <Text>{r.region}</Text>,\n value: r.revenue,\n trailing: <Text>{East.str`${East.print(East.Float.roundHalf(r.revenue.divide(total).multiply(100.0)))}%`}</Text>,\n })} />\n </Box>\n );\n }}</Reactive>\n));\n\n/** The Orders by week's code: orders placed each week. */\nconst ordersByWeekUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const weeks = $.let(Data.bind(studioOrdersWeekly).read());\n return (\n <Box height=\"168px\" padding={{ top: some(\"4\"), right: some(\"4\"), bottom: some(\"3\"), left: some(\"3\") }}>\n <Chart height=\"fill\" grid layers={Chart.Column(weeks, { x: r => r.week, y: r => r.orders }, { color: \"brand.solid\" })} />\n </Box>\n );\n }}</Reactive>\n));\n\n/** The Visits sparkline's code: visits by day. */\nconst visitsSparklineUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const visits = $.let(Data.bind(studioVisitsDaily).read());\n return (\n <Box padding=\"4\">\n <Sparkline data={visits.map(($2, r) => r.visits)} type=\"area\" width=\"100%\" height=\"48px\" />\n </Box>\n );\n }}</Reactive>\n));\n\n/** Today's assignments as a read-only table using the shared collection. */\nconst assignmentBoardUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const areas = $.let(Data.bind(studioAreas).read().toDict((_$2, area) => area.id, (_$2, area) => area.name));\n const shifts = $.let(Data.bind(studioShifts).read().toDict((_$2, shift) => shift.id, (_$2, shift) => shift.name));\n const people = $.let(Data.bind(studioPeople).read().toDict((_$2, person) => person.id, (_$2, person) => person.name));\n const today = $.let(Data.bind(studioAssignmentsToday).read());\n return <Table data={today.map((_$2, row) => ({ person: people.get(row.person), area: areas.get(row.area), shift: shifts.get(row.shift) }))} columns={[\"person\", \"area\", \"shift\"]} />;\n }}</Reactive>\n));\n\n/** The week's shifts as a read-only table; editable rostering belongs to e3-ui. */\nconst shiftRosterUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const people = $.let(Data.bind(studioPeople).read().toDict((_$2, person) => person.id, (_$2, person) => person.name));\n const rota = $.let(Data.bind(studioRotaWeek).read());\n return <Table data={rota.map((_$2, row) => ({ person: people.get(row.person), day: row.day, hours: row.hours }))} columns={[\"person\", \"day\", \"hours\"]} />;\n }}</Reactive>\n));\n\nexport const kpiRail = Studio.component(\"kpi_rail\", {\n name: \"KPI rail\", category: \"Display\", icon: \"gauge-high\", frame: \"none\",\n description: \"Revenue, orders, average ticket and fill rate this week, each with its change on last week.\",\n tags: [\"kpi\", \"sales\"],\n}, kpiRailUi);\n\nexport const breakdownBars = Studio.component(\"breakdown_bars\", {\n name: \"Breakdown bars\", category: \"Display\", icon: \"chart-bar\", span: 4n,\n description: \"Each region's share of this week's revenue, largest first.\",\n tags: [\"sales\"],\n}, breakdownBarsUi);\n\nexport const revenueTrend = Studio.component(\"revenue_trend\", {\n name: \"Revenue trend\", category: \"Charts\", icon: \"chart-area\", span: 8n,\n description: \"Revenue by day, as an area.\",\n tags: [\"sales\"],\n}, revenueTrendUi);\n\nexport const ordersByWeek = Studio.component(\"orders_by_week\", {\n name: \"Orders by week\", category: \"Charts\", icon: \"chart-column\", span: 6n,\n description: \"Orders placed each week.\",\n tags: [\"orders\"],\n}, ordersByWeekUi);\n\nexport const visitsSparkline = Studio.component(\"visits_sparkline\", {\n name: \"Visits sparkline\", category: \"Charts\", icon: \"chart-line\", span: 4n,\n description: \"Visits by day, the last two weeks.\",\n tags: [\"traffic\"],\n}, visitsSparklineUi);\n\nexport const assignmentBoard = Studio.component(\"assignment_board\", {\n name: \"Assignment board\", category: \"Collections\", icon: \"border-all\", span: 12n,\n description: \"Today: who works where, by shift.\",\n collections: [\"People\"],\n}, assignmentBoardUi);\n\nexport const shiftRoster = Studio.component(\"shift_roster\", {\n name: \"Shift roster\", category: \"Collections\", icon: \"calendar-week\", span: 12n,\n description: \"This week: people, days and their assigned hours.\",\n collections: [\"People\"],\n}, shiftRosterUi);\n\n/**\n * The pages record: the Ops console's pages — the Overview live as v3, its\n * draft resizing the trend and adding the bars beside it — and its templates,\n * and the other projects' pages.\n */\nexport const studioPages = e3.record(\"studio_pages\", Studio.Types.Pages, {\n initial: new SortedMap<Key, Entry>([\n [{ project: \"Ops console\", page: \"Account detail\" }, variant(\"page\", {\n draft: {\n title: \"Account detail\",\n cells: [\n { key: \"a-kpi\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, component: \"kpi_rail\" },\n { key: \"a-orders\", row: \"r2\", span: 8n, height: some(240n), align: variant(\"top\", null), title: none, component: \"orders_by_week\" },\n { key: \"a-bars\", row: \"r2\", span: 4n, height: some(240n), align: variant(\"stretch\", null), title: none, component: \"breakdown_bars\" },\n { key: \"a-trend\", row: \"r3\", span: 12n, height: some(200n), align: variant(\"top\", null), title: none, component: \"revenue_trend\" },\n ],\n },\n live: none,\n })],\n [{ project: \"Ops console\", page: \"Overview\" }, variant(\"page\", {\n draft: {\n title: \"Overview\",\n cells: [\n { key: \"o-kpi\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, component: \"kpi_rail\" },\n { key: \"o-trend\", row: \"r2\", span: 8n, height: none, align: variant(\"stretch\", null), title: none, component: \"revenue_trend\" },\n { key: \"o-bars\", row: \"r2\", span: 4n, height: none, align: variant(\"stretch\", null), title: none, component: \"breakdown_bars\" },\n { key: \"o-board\", row: \"r3\", span: 12n, height: none, align: variant(\"top\", null), title: none, component: \"assignment_board\" },\n ],\n },\n live: some({\n version: 3n,\n page: {\n title: \"Overview\",\n cells: [\n { key: \"o-kpi\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, component: \"kpi_rail\" },\n { key: \"o-trend\", row: \"r2\", span: 12n, height: none, align: variant(\"stretch\", null), title: none, component: \"revenue_trend\" },\n { key: \"o-board\", row: \"r3\", span: 12n, height: none, align: variant(\"top\", null), title: none, component: \"assignment_board\" },\n ],\n },\n }),\n })],\n [{ project: \"Ops console\", page: \"Regional rollup\" }, variant(\"page\", {\n draft: {\n title: \"Regional rollup\",\n cells: [\n { key: \"r-trend\", row: \"r1\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, component: \"revenue_trend\" },\n { key: \"r-bars\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: some(\"By region\"), component: \"breakdown_bars\" },\n { key: \"r-visits\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: none, component: \"visits_sparkline\" },\n ],\n },\n live: some({\n version: 1n,\n page: {\n title: \"Regional rollup\",\n cells: [\n { key: \"r-trend\", row: \"r1\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, component: \"revenue_trend\" },\n { key: \"r-bars\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: some(\"By region\"), component: \"breakdown_bars\" },\n { key: \"r-visits\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: none, component: \"visits_sparkline\" },\n ],\n },\n }),\n })],\n [{ project: \"Ops console\", page: \"Weekly export\" }, variant(\"page\", {\n draft: {\n title: \"Weekly export\",\n cells: [\n { key: \"w-orders\", row: \"r1\", span: 12n, height: some(320n), align: variant(\"top\", null), title: none, component: \"orders_by_week\" },\n { key: \"w-roster\", row: \"r2\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, component: \"shift_roster\" },\n ],\n },\n live: some({ version: 2n, page: { title: \"Weekly export\", cells: [] } }),\n })],\n [{ project: \"Ops console\", page: \"Ops board\" }, variant(\"template\", {\n title: \"Ops board\",\n cells: [\n { key: \"t-orders\", row: \"r1\", span: 8n, height: some(320n), align: variant(\"top\", null), title: none, component: \"orders_by_week\" },\n { key: \"t-bars\", row: \"r1\", span: 4n, height: some(320n), align: variant(\"stretch\", null), title: none, component: \"breakdown_bars\" },\n ],\n })],\n [{ project: \"Ops console\", page: \"Report brief\" }, variant(\"template\", {\n title: \"Report brief\",\n cells: [\n { key: \"t-trend\", row: \"r1\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, component: \"revenue_trend\" },\n { key: \"t-orders\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: none, component: \"orders_by_week\" },\n { key: \"t-visits\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: none, component: \"visits_sparkline\" },\n ],\n })],\n [{ project: \"Ops console\", page: \"Summary\" }, variant(\"template\", {\n title: \"Summary\",\n cells: [\n { key: \"t-kpi\", row: \"r1\", span: 12n, height: some(96n), align: variant(\"top\", null), title: none, component: \"kpi_rail\" },\n { key: \"t-trend\", row: \"r2\", span: 8n, height: some(240n), align: variant(\"top\", null), title: none, component: \"revenue_trend\" },\n { key: \"t-bars\", row: \"r2\", span: 4n, height: some(240n), align: variant(\"stretch\", null), title: none, component: \"breakdown_bars\" },\n ],\n })],\n [{ project: \"Finance portal\", page: \"Ledger\" }, variant(\"page\", {\n draft: {\n title: \"Ledger\",\n cells: [\n { key: \"l-trend\", row: \"r1\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, component: \"revenue_trend\" },\n ],\n },\n live: none,\n })],\n [{ project: \"HR roster\", page: \"Rota\" }, variant(\"page\", {\n draft: {\n title: \"Rota\",\n cells: [\n { key: \"h-roster\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, component: \"shift_roster\" },\n ],\n },\n live: some({\n version: 1n,\n page: {\n title: \"Rota\",\n cells: [\n { key: \"h-roster\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, component: \"shift_roster\" },\n ],\n },\n }),\n })],\n ], compareFor(Studio.Types.Key)),\n mutations: (mutation) => ({\n // The record's one write.\n patch: mutation.patch(),\n }),\n});\n\nEast.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const components = $.let([kpiRail, breakdownBars, revenueTrend, ordersByWeek, visitsSparkline, assignmentBoard, shiftRoster]);\n const pages = $.let(Record.bind(studioPages));\n return (\n <Box width=\"390px\" maxWidth=\"100%\" height=\"760px\">\n <Studio.Builder pages={pages} components={components} project=\"Ops console\" id=\"studioMobile\"\n env=\"Staging\" audience=\"Field ops · 24 users\" rollout=\"Immediate\" />\n </Box>\n );\n }}</Reactive>\n ))"
49152
+ "source": "// The same builder over the pages record in a phone's 390-wide frame: the toolbar over its second row — the history at 44px — the canvas the frame's whole width, and the palette and the inspector a strip of drawers along the bottom edge; given no `page`, it holds its own open page, the project's first to begin with\n// inputs: []\ntype Key = ValueTypeOf<typeof Studio.Types.Key>;\n\ntype Entry = ValueTypeOf<typeof Studio.Types.Entry>;\n\n/**\n * The KPI rail's code: the week's four figures, each with its change on last week — four abreast where four of\n * 170px fit, else two and two, else one above another, so no row stands short beside an empty cell.\n */\nconst kpiRailUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const kpis = $.let(Data.bind(studioKpis).read());\n return (\n <Box background=\"border.subtle\"><Grid gap=\"1px\" templateColumns=\"repeat(auto-fit, minmax(max(calc(25% - 1px), min(calc(50% - 1px), calc((683px - 100%) * 999)), min(100%, calc((341px - 100%) * 999))), 1fr))\" items={kpis.map(($2, k) => Grid.Item(\n <Box background=\"bg.surface\"\n padding={{ top: some(\"3\"), right: some(\"4\"), bottom: some(\"3\"), left: some(\"4\") }}>\n <Stat label={k.label} value={k.value}\n format={k.unit.match({\n money: (_$3) => Format.Currency({ currency: \"USD\", compact: \"short\", maximumFractionDigits: 2n }),\n count: (_$3) => Format.Number(),\n price: (_$3) => Format.Currency({ currency: \"USD\", maximumFractionDigits: 0n }),\n ratio: (_$3) => Format.Percent({ maximumFractionDigits: 0n }),\n })}\n baseline={\n <MetricChip tone={k.change.greater(0.0).ifElse(\n _$3 => variant(\"positive\", null),\n _$3 => k.change.less(0.0).ifElse(_$4 => variant(\"negative\", null), _$4 => variant(\"neutral\", null)),\n )}>\n <Text>{k.change.greater(0.0).ifElse(\n _$3 => East.str`▲ ${East.print(k.change)}%`,\n _$3 => k.change.less(0.0).ifElse(\n _$4 => East.str`▼ ${East.print(k.change.negate())}%`,\n _$4 => \"— flat\",\n ),\n )}</Text>\n </MetricChip>\n } />\n </Box>,\n ))} /></Box>\n );\n }}</Reactive>\n));\n\n/** The Revenue trend's code: revenue by day, as an area. */\nconst revenueTrendUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const days = $.let(Data.bind(studioRevenueDaily).read());\n return (\n <Box height=\"168px\" padding={{ top: some(\"4\"), right: some(\"4\"), bottom: some(\"3\"), left: some(\"3\") }}>\n <Chart height=\"fill\" grid\n layers={Chart.Area(days, { x: r => r.day, y: r => r.revenue }, { color: \"brand.solid\", fillOpacity: 0.08, curve: \"linear\" })}\n x={{ format: Chart.format.date(\"MMM D\") }}\n y={{ format: Chart.format.compact() }} />\n </Box>\n );\n }}</Reactive>\n));\n\n/** The Breakdown bars' code: each region's share of this week's revenue, largest first. */\nconst breakdownBarsUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const sales = $.let(Data.bind(studioSales).read());\n const total = $.let(sales.map(($2, r) => r.revenue).sum());\n const regions = $.let(sales\n .groupSum(($2, r) => r.region, ($2, r) => r.revenue)\n .toArray(($2, revenue, region) => ({ region, revenue })));\n return (\n <Box padding=\"4\">\n <BarStrip data={regions} sort=\"desc\" showValues={false}\n item={r => ({\n label: <Text>{r.region}</Text>,\n value: r.revenue,\n trailing: <Text>{East.str`${East.print(East.Float.roundHalf(r.revenue.divide(total).multiply(100.0)))}%`}</Text>,\n })} />\n </Box>\n );\n }}</Reactive>\n));\n\n/** The Orders by week's code: orders placed each week. */\nconst ordersByWeekUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const weeks = $.let(Data.bind(studioOrdersWeekly).read());\n return (\n <Box height=\"168px\" padding={{ top: some(\"4\"), right: some(\"4\"), bottom: some(\"3\"), left: some(\"3\") }}>\n <Chart height=\"fill\" grid layers={Chart.Column(weeks, { x: r => r.week, y: r => r.orders }, { color: \"brand.solid\" })} />\n </Box>\n );\n }}</Reactive>\n));\n\n/** The Visits sparkline's code: visits by day. */\nconst visitsSparklineUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const visits = $.let(Data.bind(studioVisitsDaily).read());\n return (\n <Box padding=\"4\">\n <Sparkline data={visits.map(($2, r) => r.visits)} type=\"area\" width=\"100%\" height=\"48px\" />\n </Box>\n );\n }}</Reactive>\n));\n\n/** Today's assignments as a read-only table using the shared collection. */\nconst assignmentBoardUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const areas = $.let(Data.bind(studioAreas).read().toDict((_$2, area) => area.id, (_$2, area) => area.name));\n const shifts = $.let(Data.bind(studioShifts).read().toDict((_$2, shift) => shift.id, (_$2, shift) => shift.name));\n const people = $.let(Data.bind(studioPeople).read().toDict((_$2, person) => person.id, (_$2, person) => person.name));\n const today = $.let(Data.bind(studioAssignmentsToday).read());\n return <Table data={today.map((_$2, row) => ({ person: people.get(row.person), area: areas.get(row.area), shift: shifts.get(row.shift) }))} columns={[\"person\", \"area\", \"shift\"]} />;\n }}</Reactive>\n));\n\n/** The week's shifts as a read-only table; editable rostering belongs to e3-ui. */\nconst shiftRosterUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const people = $.let(Data.bind(studioPeople).read().toDict((_$2, person) => person.id, (_$2, person) => person.name));\n const rota = $.let(Data.bind(studioRotaWeek).read());\n return <Table data={rota.map((_$2, row) => ({ person: people.get(row.person), day: row.day, hours: row.hours }))} columns={[\"person\", \"day\", \"hours\"]} />;\n }}</Reactive>\n));\n\nexport const kpiRail = Studio.component(\"kpi_rail\", {\n name: \"KPI rail\", category: \"Display\", icon: \"gauge-high\", frame: \"none\",\n description: \"Revenue, orders, average ticket and fill rate this week, each with its change on last week.\",\n tags: [\"kpi\", \"sales\"],\n}, kpiRailUi);\n\nexport const breakdownBars = Studio.component(\"breakdown_bars\", {\n name: \"Breakdown bars\", category: \"Display\", icon: \"chart-bar\", span: 4n,\n description: \"Each region's share of this week's revenue, largest first.\",\n tags: [\"sales\"],\n}, breakdownBarsUi);\n\nexport const revenueTrend = Studio.component(\"revenue_trend\", {\n name: \"Revenue trend\", category: \"Charts\", icon: \"chart-area\", span: 8n,\n description: \"Revenue by day, as an area.\",\n tags: [\"sales\"],\n}, revenueTrendUi);\n\nexport const ordersByWeek = Studio.component(\"orders_by_week\", {\n name: \"Orders by week\", category: \"Charts\", icon: \"chart-column\", span: 6n,\n description: \"Orders placed each week.\",\n tags: [\"orders\"],\n}, ordersByWeekUi);\n\nexport const visitsSparkline = Studio.component(\"visits_sparkline\", {\n name: \"Visits sparkline\", category: \"Charts\", icon: \"chart-line\", span: 4n,\n description: \"Visits by day, the last two weeks.\",\n tags: [\"traffic\"],\n}, visitsSparklineUi);\n\nexport const assignmentBoard = Studio.component(\"assignment_board\", {\n name: \"Assignment board\", category: \"Collections\", icon: \"border-all\", span: 12n,\n description: \"Today: who works where, by shift.\",\n collections: [\"People\"],\n}, assignmentBoardUi);\n\nexport const shiftRoster = Studio.component(\"shift_roster\", {\n name: \"Shift roster\", category: \"Collections\", icon: \"calendar-week\", span: 12n,\n description: \"This week: people, days and their assigned hours.\",\n collections: [\"People\"],\n}, shiftRosterUi);\n\n/**\n * The pages record: the Ops console's pages — the Overview live as v3, its\n * draft resizing the trend and adding the bars beside it — and its templates,\n * and the other projects' pages.\n */\nexport const studioPages = e3.record(\"studio_pages\", Studio.Types.Pages, {\n initial: new SortedMap<Key, Entry>([\n [{ project: \"Ops console\", page: \"Account detail\" }, variant(\"page\", {\n draft: {\n title: \"Account detail\",\n cells: [\n { key: \"a-kpi\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"kpi_rail\") },\n { key: \"a-orders\", row: \"r2\", span: 8n, height: some(240n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"orders_by_week\") },\n { key: \"a-bars\", row: \"r2\", span: 4n, height: some(240n), align: variant(\"stretch\", null), title: none, content: variant(\"component\", \"breakdown_bars\") },\n { key: \"a-trend\", row: \"r3\", span: 12n, height: some(200n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n ],\n filters: [],\n },\n live: none,\n })],\n [{ project: \"Ops console\", page: \"Overview\" }, variant(\"page\", {\n draft: {\n title: \"Overview\",\n cells: [\n { key: \"o-kpi\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"kpi_rail\") },\n { key: \"o-trend\", row: \"r2\", span: 8n, height: none, align: variant(\"stretch\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n { key: \"o-bars\", row: \"r2\", span: 4n, height: none, align: variant(\"stretch\", null), title: none, content: variant(\"component\", \"breakdown_bars\") },\n { key: \"o-board\", row: \"r3\", span: 12n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"assignment_board\") },\n ],\n filters: [],\n },\n live: some({\n version: 3n,\n page: {\n title: \"Overview\",\n cells: [\n { key: \"o-kpi\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"kpi_rail\") },\n { key: \"o-trend\", row: \"r2\", span: 12n, height: none, align: variant(\"stretch\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n { key: \"o-board\", row: \"r3\", span: 12n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"assignment_board\") },\n ],\n filters: [],\n },\n }),\n })],\n [{ project: \"Ops console\", page: \"Regional rollup\" }, variant(\"page\", {\n draft: {\n title: \"Regional rollup\",\n cells: [\n { key: \"r-trend\", row: \"r1\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n { key: \"r-bars\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: some(\"By region\"), content: variant(\"component\", \"breakdown_bars\") },\n { key: \"r-visits\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"visits_sparkline\") },\n ],\n filters: [],\n },\n live: some({\n version: 1n,\n page: {\n title: \"Regional rollup\",\n cells: [\n { key: \"r-trend\", row: \"r1\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n { key: \"r-bars\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: some(\"By region\"), content: variant(\"component\", \"breakdown_bars\") },\n { key: \"r-visits\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"visits_sparkline\") },\n ],\n filters: [],\n },\n }),\n })],\n [{ project: \"Ops console\", page: \"Weekly export\" }, variant(\"page\", {\n draft: {\n title: \"Weekly export\",\n cells: [\n { key: \"w-orders\", row: \"r1\", span: 12n, height: some(320n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"orders_by_week\") },\n { key: \"w-roster\", row: \"r2\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"shift_roster\") },\n ],\n filters: [],\n },\n live: some({ version: 2n, page: { title: \"Weekly export\", cells: [], filters: [] } }),\n })],\n [{ project: \"Ops console\", page: \"Ops board\" }, variant(\"template\", {\n title: \"Ops board\",\n cells: [\n { key: \"t-orders\", row: \"r1\", span: 8n, height: some(320n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"orders_by_week\") },\n { key: \"t-bars\", row: \"r1\", span: 4n, height: some(320n), align: variant(\"stretch\", null), title: none, content: variant(\"component\", \"breakdown_bars\") },\n ],\n filters: [],\n })],\n [{ project: \"Ops console\", page: \"Report brief\" }, variant(\"template\", {\n title: \"Report brief\",\n cells: [\n { key: \"t-trend\", row: \"r1\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n { key: \"t-orders\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"orders_by_week\") },\n { key: \"t-visits\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"visits_sparkline\") },\n ],\n filters: [],\n })],\n [{ project: \"Ops console\", page: \"Summary\" }, variant(\"template\", {\n title: \"Summary\",\n cells: [\n { key: \"t-kpi\", row: \"r1\", span: 12n, height: some(96n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"kpi_rail\") },\n { key: \"t-trend\", row: \"r2\", span: 8n, height: some(240n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n { key: \"t-bars\", row: \"r2\", span: 4n, height: some(240n), align: variant(\"stretch\", null), title: none, content: variant(\"component\", \"breakdown_bars\") },\n ],\n filters: [],\n })],\n [{ project: \"Finance portal\", page: \"Ledger\" }, variant(\"page\", {\n draft: {\n title: \"Ledger\",\n cells: [\n { key: \"l-trend\", row: \"r1\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n ],\n filters: [],\n },\n live: none,\n })],\n [{ project: \"HR roster\", page: \"Rota\" }, variant(\"page\", {\n draft: {\n title: \"Rota\",\n cells: [\n { key: \"h-roster\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"shift_roster\") },\n ],\n filters: [],\n },\n live: some({\n version: 1n,\n page: {\n title: \"Rota\",\n cells: [\n { key: \"h-roster\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"shift_roster\") },\n ],\n filters: [],\n },\n }),\n })],\n ], compareFor(Studio.Types.Key)),\n mutations: (mutation) => ({\n // The record's one write.\n patch: mutation.patch(),\n }),\n});\n\nEast.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const components = $.let([kpiRail, breakdownBars, revenueTrend, ordersByWeek, visitsSparkline, assignmentBoard, shiftRoster]);\n const pages = $.let(Record.bind(studioPages));\n return (\n <Box width=\"390px\" maxWidth=\"100%\" height=\"760px\">\n <Studio.Builder pages={pages} components={components} project=\"Ops console\" id=\"studioMobile\"\n env=\"Staging\" audience=\"Field ops · 24 users\" rollout=\"Immediate\" />\n </Box>\n );\n }}</Reactive>\n ))"
48775
49153
  },
48776
49154
  {
48777
49155
  "id": "e3-ui:studio.examples.tsx:studioConflicts",
@@ -48799,12 +49177,13 @@
48799
49177
  "import {",
48800
49178
  "import {",
48801
49179
  "import { Data, Record, Studio } from \"@elaraai/e3-ui\";",
48802
- "import e3 from \"@elaraai/e3\";"
49180
+ "import e3 from \"@elaraai/e3\";",
49181
+ "import {"
48803
49182
  ],
48804
49183
  "languages": [
48805
49184
  "tsx"
48806
49185
  ],
48807
- "source": "// Your edits meeting someone else's save, in one window — make a tile wider or narrower, then press Someone else saves, which saves another person's change to the same pages (every tile a column narrower), so yours conflict and wait to be chosen; a tile you move, align or make taller combines with theirs\n// inputs: []\ntype Key = ValueTypeOf<typeof Studio.Types.Key>;\n\ntype Entry = ValueTypeOf<typeof Studio.Types.Entry>;\n\n/** What a KPI measures: an amount of money, a count, a price or a ratio. */\nconst KpiUnit = VariantType({ money: NullType, count: NullType, price: NullType, ratio: NullType });\n\n/** The week's figures, each with its change on last week in percent — what a KPI task writes. */\nexport const studioKpis = e3.input(\"studio_kpis\", ArrayType(StructType({\n label: StringType, value: FloatType, unit: KpiUnit, change: FloatType,\n})), variant(\"value\", [\n { label: \"Revenue\", value: 1284000.0, unit: variant(\"money\", null), change: 6.4 },\n { label: \"Orders\", value: 8412.0, unit: variant(\"count\", null), change: 2.1 },\n { label: \"Avg ticket\", value: 152.0, unit: variant(\"price\", null), change: -1.3 },\n { label: \"Fill rate\", value: 0.94, unit: variant(\"ratio\", null), change: 0.0 },\n]));\n\n/** Revenue by day. */\nexport const studioRevenueDaily = e3.input(\"studio_revenue_daily\", ArrayType(StructType({ day: DateTimeType, revenue: FloatType })), variant(\"value\", [\n { day: new Date(\"2026-02-12T00:00:00Z\"), revenue: 2640000.0 },\n { day: new Date(\"2026-02-19T00:00:00Z\"), revenue: 2710000.0 },\n { day: new Date(\"2026-02-26T00:00:00Z\"), revenue: 2900000.0 },\n { day: new Date(\"2026-03-05T00:00:00Z\"), revenue: 3180000.0 },\n { day: new Date(\"2026-03-12T00:00:00Z\"), revenue: 3300000.0 },\n { day: new Date(\"2026-03-19T00:00:00Z\"), revenue: 3430000.0 },\n]));\n\n/** This week's sales, one row per region per channel. */\nexport const studioSales = e3.input(\"studio_sales\", ArrayType(StructType({ region: StringType, channel: StringType, revenue: FloatType })), variant(\"value\", [\n { region: \"North\", channel: \"Store\", revenue: 331200.0 },\n { region: \"North\", channel: \"Online\", revenue: 208080.0 },\n { region: \"South\", channel: \"Store\", revenue: 238824.0 },\n { region: \"South\", channel: \"Online\", revenue: 159216.0 },\n { region: \"West\", channel: \"Store\", revenue: 197604.0 },\n { region: \"West\", channel: \"Online\", revenue: 149076.0 },\n]));\n\n/** Orders by week. */\nexport const studioOrdersWeekly = e3.input(\"studio_orders_weekly\", ArrayType(StructType({ week: StringType, orders: FloatType })), variant(\"value\", [\n { week: \"W9\", orders: 96.0 }, { week: \"W10\", orders: 158.0 }, { week: \"W11\", orders: 214.0 },\n { week: \"W12\", orders: 271.0 }, { week: \"W13\", orders: 248.0 }, { week: \"W14\", orders: 196.0 },\n]));\n\n/** Visits by day, the last two weeks. */\nexport const studioVisitsDaily = e3.input(\"studio_visits_daily\", ArrayType(StructType({ day: DateTimeType, visits: FloatType })), variant(\"value\", [\n { day: new Date(\"2026-03-06T00:00:00Z\"), visits: 412.0 }, { day: new Date(\"2026-03-07T00:00:00Z\"), visits: 388.0 },\n { day: new Date(\"2026-03-08T00:00:00Z\"), visits: 301.0 }, { day: new Date(\"2026-03-09T00:00:00Z\"), visits: 296.0 },\n { day: new Date(\"2026-03-10T00:00:00Z\"), visits: 455.0 }, { day: new Date(\"2026-03-11T00:00:00Z\"), visits: 471.0 },\n { day: new Date(\"2026-03-12T00:00:00Z\"), visits: 468.0 }, { day: new Date(\"2026-03-13T00:00:00Z\"), visits: 502.0 },\n { day: new Date(\"2026-03-14T00:00:00Z\"), visits: 479.0 }, { day: new Date(\"2026-03-15T00:00:00Z\"), visits: 344.0 },\n { day: new Date(\"2026-03-16T00:00:00Z\"), visits: 327.0 }, { day: new Date(\"2026-03-17T00:00:00Z\"), visits: 518.0 },\n { day: new Date(\"2026-03-18T00:00:00Z\"), visits: 546.0 }, { day: new Date(\"2026-03-19T00:00:00Z\"), visits: 561.0 },\n]));\n\n/** The floor's areas, its shifts and its people. */\nexport const studioAreas = e3.input(\"studio_areas\", ArrayType(StructType({ id: StringType, name: StringType })), variant(\"value\", [\n { id: \"north\", name: \"North\" }, { id: \"south\", name: \"South\" },\n]));\n\nexport const studioShifts = e3.input(\"studio_shifts\", ArrayType(StructType({ id: StringType, name: StringType, window: StringType })), variant(\"value\", [\n { id: \"am\", name: \"AM\", window: \"06–14\" }, { id: \"pm\", name: \"PM\", window: \"14–22\" }, { id: \"night\", name: \"Night\", window: \"22–06\" },\n]));\n\nexport const studioPeople = e3.input(\"studio_people\", ArrayType(StructType({ id: StringType, name: StringType })), variant(\"value\", [\n { id: \"p1\", name: \"Ana Ruiz\" }, { id: \"p2\", name: \"Ben Cole\" }, { id: \"p3\", name: \"Cai Lin\" }, { id: \"p4\", name: \"Dev Rao\" },\n { id: \"p5\", name: \"Eli Moss\" }, { id: \"p6\", name: \"Fay Ong\" }, { id: \"p7\", name: \"Gus Hart\" }, { id: \"p8\", name: \"Hana Ito\" },\n]));\n\n/** Who works where today. */\nexport const studioAssignmentsToday = e3.input(\"studio_assignments_today\", ArrayType(StructType({\n id: StringType, person: StringType, area: StringType, shift: StringType,\n})), variant(\"value\", [\n { id: \"a1\", person: \"p1\", area: \"north\", shift: \"am\" }, { id: \"a2\", person: \"p2\", area: \"north\", shift: \"am\" },\n { id: \"a3\", person: \"p3\", area: \"north\", shift: \"pm\" }, { id: \"a4\", person: \"p4\", area: \"north\", shift: \"night\" },\n { id: \"a5\", person: \"p5\", area: \"south\", shift: \"am\" }, { id: \"a6\", person: \"p6\", area: \"south\", shift: \"pm\" },\n { id: \"a7\", person: \"p7\", area: \"south\", shift: \"pm\" }, { id: \"a8\", person: \"p8\", area: \"south\", shift: \"night\" },\n]));\n\n/** This week's rota. */\nexport const studioRotaWeek = e3.input(\"studio_rota_week\", ArrayType(StructType({\n id: StringType, person: StringType, day: StringType, hours: IntegerType,\n})), variant(\"value\", [\n { id: \"r1\", person: \"p1\", day: \"Mon\", hours: 8n }, { id: \"r2\", person: \"p1\", day: \"Tue\", hours: 8n }, { id: \"r3\", person: \"p1\", day: \"Wed\", hours: 8n },\n { id: \"r4\", person: \"p2\", day: \"Mon\", hours: 8n }, { id: \"r5\", person: \"p2\", day: \"Thu\", hours: 8n }, { id: \"r6\", person: \"p2\", day: \"Fri\", hours: 6n },\n { id: \"r7\", person: \"p3\", day: \"Tue\", hours: 8n }, { id: \"r8\", person: \"p3\", day: \"Wed\", hours: 8n }, { id: \"r9\", person: \"p3\", day: \"Thu\", hours: 8n },\n { id: \"r10\", person: \"p4\", day: \"Mon\", hours: 10n }, { id: \"r11\", person: \"p4\", day: \"Fri\", hours: 10n },\n]));\n\n/** The KPI rail's code: the week's four figures, each with its change on last week. */\nconst kpiRailUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const kpis = $.let(Data.bind(studioKpis).read());\n return (\n <Box background=\"border.subtle\"><Grid gap=\"1px\" templateColumns=\"repeat(auto-fit, minmax(min(calc(50% - 1px), 170px), 1fr))\" items={kpis.map(($2, k) => Grid.Item(\n <Box background=\"bg.surface\"\n padding={{ top: some(\"3\"), right: some(\"4\"), bottom: some(\"3\"), left: some(\"4\") }}>\n <Stat label={k.label} value={k.value}\n format={k.unit.match({\n money: (_$3) => Format.Currency({ currency: \"USD\", compact: \"short\", maximumFractionDigits: 2n }),\n count: (_$3) => Format.Number(),\n price: (_$3) => Format.Currency({ currency: \"USD\", maximumFractionDigits: 0n }),\n ratio: (_$3) => Format.Percent({ maximumFractionDigits: 0n }),\n })}\n baseline={\n <MetricChip tone={k.change.greater(0.0).ifElse(\n _$3 => variant(\"positive\", null),\n _$3 => k.change.less(0.0).ifElse(_$4 => variant(\"negative\", null), _$4 => variant(\"neutral\", null)),\n )}>\n <Text>{k.change.greater(0.0).ifElse(\n _$3 => East.str`▲ ${East.print(k.change)}%`,\n _$3 => k.change.less(0.0).ifElse(\n _$4 => East.str`▼ ${East.print(k.change.negate())}%`,\n _$4 => \"— flat\",\n ),\n )}</Text>\n </MetricChip>\n } />\n </Box>,\n ))} /></Box>\n );\n }}</Reactive>\n));\n\n/** The Revenue trend's code: revenue by day, as an area. */\nconst revenueTrendUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const days = $.let(Data.bind(studioRevenueDaily).read());\n return (\n <Box height=\"168px\" padding={{ top: some(\"4\"), right: some(\"4\"), bottom: some(\"3\"), left: some(\"3\") }}>\n <Chart height=\"fill\" grid\n layers={Chart.Area(days, { x: r => r.day, y: r => r.revenue }, { color: \"brand.solid\", fillOpacity: 0.08, curve: \"linear\" })}\n x={{ format: Chart.format.date(\"MMM D\") }}\n y={{ format: Chart.format.compact() }} />\n </Box>\n );\n }}</Reactive>\n));\n\n/** The Breakdown bars' code: each region's share of this week's revenue, largest first. */\nconst breakdownBarsUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const sales = $.let(Data.bind(studioSales).read());\n const total = $.let(sales.map(($2, r) => r.revenue).sum());\n const regions = $.let(sales\n .groupSum(($2, r) => r.region, ($2, r) => r.revenue)\n .toArray(($2, revenue, region) => ({ region, revenue })));\n return (\n <Box padding=\"4\">\n <BarStrip data={regions} sort=\"desc\" showValues={false}\n item={r => ({\n label: <Text>{r.region}</Text>,\n value: r.revenue,\n trailing: <Text>{East.str`${East.print(East.Float.roundHalf(r.revenue.divide(total).multiply(100.0)))}%`}</Text>,\n })} />\n </Box>\n );\n }}</Reactive>\n));\n\n/** The Orders by week's code: orders placed each week. */\nconst ordersByWeekUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const weeks = $.let(Data.bind(studioOrdersWeekly).read());\n return (\n <Box height=\"168px\" padding={{ top: some(\"4\"), right: some(\"4\"), bottom: some(\"3\"), left: some(\"3\") }}>\n <Chart height=\"fill\" grid layers={Chart.Column(weeks, { x: r => r.week, y: r => r.orders }, { color: \"brand.solid\" })} />\n </Box>\n );\n }}</Reactive>\n));\n\n/** The Visits sparkline's code: visits by day. */\nconst visitsSparklineUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const visits = $.let(Data.bind(studioVisitsDaily).read());\n return (\n <Box padding=\"4\">\n <Sparkline data={visits.map(($2, r) => r.visits)} type=\"area\" width=\"100%\" height=\"48px\" />\n </Box>\n );\n }}</Reactive>\n));\n\n/** Today's assignments as a read-only table using the shared collection. */\nconst assignmentBoardUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const areas = $.let(Data.bind(studioAreas).read().toDict((_$2, area) => area.id, (_$2, area) => area.name));\n const shifts = $.let(Data.bind(studioShifts).read().toDict((_$2, shift) => shift.id, (_$2, shift) => shift.name));\n const people = $.let(Data.bind(studioPeople).read().toDict((_$2, person) => person.id, (_$2, person) => person.name));\n const today = $.let(Data.bind(studioAssignmentsToday).read());\n return <Table data={today.map((_$2, row) => ({ person: people.get(row.person), area: areas.get(row.area), shift: shifts.get(row.shift) }))} columns={[\"person\", \"area\", \"shift\"]} />;\n }}</Reactive>\n));\n\n/** The week's shifts as a read-only table; editable rostering belongs to e3-ui. */\nconst shiftRosterUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const people = $.let(Data.bind(studioPeople).read().toDict((_$2, person) => person.id, (_$2, person) => person.name));\n const rota = $.let(Data.bind(studioRotaWeek).read());\n return <Table data={rota.map((_$2, row) => ({ person: people.get(row.person), day: row.day, hours: row.hours }))} columns={[\"person\", \"day\", \"hours\"]} />;\n }}</Reactive>\n));\n\nexport const kpiRail = Studio.component(\"kpi_rail\", {\n name: \"KPI rail\", category: \"Display\", icon: \"gauge-high\", frame: \"none\",\n description: \"Revenue, orders, average ticket and fill rate this week, each with its change on last week.\",\n tags: [\"kpi\", \"sales\"],\n}, kpiRailUi);\n\nexport const breakdownBars = Studio.component(\"breakdown_bars\", {\n name: \"Breakdown bars\", category: \"Display\", icon: \"chart-bar\", span: 4n,\n description: \"Each region's share of this week's revenue, largest first.\",\n tags: [\"sales\"],\n}, breakdownBarsUi);\n\nexport const revenueTrend = Studio.component(\"revenue_trend\", {\n name: \"Revenue trend\", category: \"Charts\", icon: \"chart-area\", span: 8n,\n description: \"Revenue by day, as an area.\",\n tags: [\"sales\"],\n}, revenueTrendUi);\n\nexport const ordersByWeek = Studio.component(\"orders_by_week\", {\n name: \"Orders by week\", category: \"Charts\", icon: \"chart-column\", span: 6n,\n description: \"Orders placed each week.\",\n tags: [\"orders\"],\n}, ordersByWeekUi);\n\nexport const visitsSparkline = Studio.component(\"visits_sparkline\", {\n name: \"Visits sparkline\", category: \"Charts\", icon: \"chart-line\", span: 4n,\n description: \"Visits by day, the last two weeks.\",\n tags: [\"traffic\"],\n}, visitsSparklineUi);\n\nexport const assignmentBoard = Studio.component(\"assignment_board\", {\n name: \"Assignment board\", category: \"Collections\", icon: \"border-all\", span: 12n,\n description: \"Today: who works where, by shift.\",\n collections: [\"People\"],\n}, assignmentBoardUi);\n\nexport const shiftRoster = Studio.component(\"shift_roster\", {\n name: \"Shift roster\", category: \"Collections\", icon: \"calendar-week\", span: 12n,\n description: \"This week: people, days and their assigned hours.\",\n collections: [\"People\"],\n}, shiftRosterUi);\n\n/**\n * The pages record: the Ops console's pages — the Overview live as v3, its\n * draft resizing the trend and adding the bars beside it — and its templates,\n * and the other projects' pages.\n */\nexport const studioPages = e3.record(\"studio_pages\", Studio.Types.Pages, {\n initial: new SortedMap<Key, Entry>([\n [{ project: \"Ops console\", page: \"Account detail\" }, variant(\"page\", {\n draft: {\n title: \"Account detail\",\n cells: [\n { key: \"a-kpi\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, component: \"kpi_rail\" },\n { key: \"a-orders\", row: \"r2\", span: 8n, height: some(240n), align: variant(\"top\", null), title: none, component: \"orders_by_week\" },\n { key: \"a-bars\", row: \"r2\", span: 4n, height: some(240n), align: variant(\"stretch\", null), title: none, component: \"breakdown_bars\" },\n { key: \"a-trend\", row: \"r3\", span: 12n, height: some(200n), align: variant(\"top\", null), title: none, component: \"revenue_trend\" },\n ],\n },\n live: none,\n })],\n [{ project: \"Ops console\", page: \"Overview\" }, variant(\"page\", {\n draft: {\n title: \"Overview\",\n cells: [\n { key: \"o-kpi\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, component: \"kpi_rail\" },\n { key: \"o-trend\", row: \"r2\", span: 8n, height: none, align: variant(\"stretch\", null), title: none, component: \"revenue_trend\" },\n { key: \"o-bars\", row: \"r2\", span: 4n, height: none, align: variant(\"stretch\", null), title: none, component: \"breakdown_bars\" },\n { key: \"o-board\", row: \"r3\", span: 12n, height: none, align: variant(\"top\", null), title: none, component: \"assignment_board\" },\n ],\n },\n live: some({\n version: 3n,\n page: {\n title: \"Overview\",\n cells: [\n { key: \"o-kpi\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, component: \"kpi_rail\" },\n { key: \"o-trend\", row: \"r2\", span: 12n, height: none, align: variant(\"stretch\", null), title: none, component: \"revenue_trend\" },\n { key: \"o-board\", row: \"r3\", span: 12n, height: none, align: variant(\"top\", null), title: none, component: \"assignment_board\" },\n ],\n },\n }),\n })],\n [{ project: \"Ops console\", page: \"Regional rollup\" }, variant(\"page\", {\n draft: {\n title: \"Regional rollup\",\n cells: [\n { key: \"r-trend\", row: \"r1\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, component: \"revenue_trend\" },\n { key: \"r-bars\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: some(\"By region\"), component: \"breakdown_bars\" },\n { key: \"r-visits\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: none, component: \"visits_sparkline\" },\n ],\n },\n live: some({\n version: 1n,\n page: {\n title: \"Regional rollup\",\n cells: [\n { key: \"r-trend\", row: \"r1\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, component: \"revenue_trend\" },\n { key: \"r-bars\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: some(\"By region\"), component: \"breakdown_bars\" },\n { key: \"r-visits\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: none, component: \"visits_sparkline\" },\n ],\n },\n }),\n })],\n [{ project: \"Ops console\", page: \"Weekly export\" }, variant(\"page\", {\n draft: {\n title: \"Weekly export\",\n cells: [\n { key: \"w-orders\", row: \"r1\", span: 12n, height: some(320n), align: variant(\"top\", null), title: none, component: \"orders_by_week\" },\n { key: \"w-roster\", row: \"r2\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, component: \"shift_roster\" },\n ],\n },\n live: some({ version: 2n, page: { title: \"Weekly export\", cells: [] } }),\n })],\n [{ project: \"Ops console\", page: \"Ops board\" }, variant(\"template\", {\n title: \"Ops board\",\n cells: [\n { key: \"t-orders\", row: \"r1\", span: 8n, height: some(320n), align: variant(\"top\", null), title: none, component: \"orders_by_week\" },\n { key: \"t-bars\", row: \"r1\", span: 4n, height: some(320n), align: variant(\"stretch\", null), title: none, component: \"breakdown_bars\" },\n ],\n })],\n [{ project: \"Ops console\", page: \"Report brief\" }, variant(\"template\", {\n title: \"Report brief\",\n cells: [\n { key: \"t-trend\", row: \"r1\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, component: \"revenue_trend\" },\n { key: \"t-orders\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: none, component: \"orders_by_week\" },\n { key: \"t-visits\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: none, component: \"visits_sparkline\" },\n ],\n })],\n [{ project: \"Ops console\", page: \"Summary\" }, variant(\"template\", {\n title: \"Summary\",\n cells: [\n { key: \"t-kpi\", row: \"r1\", span: 12n, height: some(96n), align: variant(\"top\", null), title: none, component: \"kpi_rail\" },\n { key: \"t-trend\", row: \"r2\", span: 8n, height: some(240n), align: variant(\"top\", null), title: none, component: \"revenue_trend\" },\n { key: \"t-bars\", row: \"r2\", span: 4n, height: some(240n), align: variant(\"stretch\", null), title: none, component: \"breakdown_bars\" },\n ],\n })],\n [{ project: \"Finance portal\", page: \"Ledger\" }, variant(\"page\", {\n draft: {\n title: \"Ledger\",\n cells: [\n { key: \"l-trend\", row: \"r1\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, component: \"revenue_trend\" },\n ],\n },\n live: none,\n })],\n [{ project: \"HR roster\", page: \"Rota\" }, variant(\"page\", {\n draft: {\n title: \"Rota\",\n cells: [\n { key: \"h-roster\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, component: \"shift_roster\" },\n ],\n },\n live: some({\n version: 1n,\n page: {\n title: \"Rota\",\n cells: [\n { key: \"h-roster\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, component: \"shift_roster\" },\n ],\n },\n }),\n })],\n ], compareFor(Studio.Types.Key)),\n mutations: (mutation) => ({\n // The record's one write.\n patch: mutation.patch(),\n }),\n});\n\n/** A page's tiles each a column narrower, one three columns wide or less as it was: what someone else's save changes. */\nconst tilesNarrower = East.function([Studio.Types.Page], Studio.Types.Page, (_$, page) => ({\n title: page.title,\n cells: page.cells.map((_$2, cell) => ({\n key: cell.key, row: cell.row,\n span: cell.span.greater(3n).ifElse(() => cell.span.subtract(1n), () => cell.span),\n height: cell.height, align: cell.align, title: cell.title, component: cell.component,\n })),\n}));\n\n/** The pages the conflicts example edits, as the builder's start, in a record of their own so no other example's edits meet them. */\nexport const studioConflictPages = e3.record(\"studio_conflict_pages\", Studio.Types.Pages, {\n initial: studioPages.default!,\n mutations: (mutation) => ({\n // The record's one write.\n patch: mutation.patch(),\n // Someone else's save: every page's tiles a column narrower in its draft, its templates as they were.\n elsewhere: mutation.reduce(East.function([Studio.Types.Pages], Studio.Types.Pages, ($, pages) => {\n const narrower = $.const(tilesNarrower);\n return pages.map((_$2, entry) => entry.match({\n page: (_$3, held) => East.value(variant(\"page\", { draft: narrower(held.draft), live: held.live }), Studio.Types.Entry),\n template: (_$3, page) => East.value(variant(\"template\", page), Studio.Types.Entry),\n }));\n })),\n }),\n});\n\nEast.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const components = $.let([kpiRail, breakdownBars, revenueTrend, ordersByWeek, visitsSparkline, assignmentBoard, shiftRoster]);\n const pages = $.let(Record.bind(studioConflictPages, [\"patch\"]));\n const others = $.let(Record.bind(studioConflictPages, [\"elsewhere\"]));\n const theirs = $.const(East.function([], NullType, ($) => { $(others.mutate.elsewhere()); }));\n return (\n <VStack gap=\"3\" align=\"stretch\">\n <HStack gap=\"3\">\n <Button variant=\"outline\" onClick={theirs} loading={others.mutate.pending()}>Someone else saves</Button>\n <Text color=\"fg.muted\">Their change: every tile a column narrower</Text>\n </HStack>\n <Box height=\"760px\">\n <Studio.Builder pages={pages} components={components} project=\"Ops console\" id=\"conflicts\"\n env=\"Staging\" audience=\"Field ops · 24 users\" rollout=\"Immediate\" />\n </Box>\n </VStack>\n );\n }}</Reactive>\n ))"
49186
+ "source": "// Your edits meeting someone else's save, in one window — make a tile wider or narrower, then press Someone else saves, which saves another person's change to the same pages (every tile a column narrower), so yours conflict and wait to be chosen; a tile you move, align or make taller combines with theirs\n// inputs: []\ntype Key = ValueTypeOf<typeof Studio.Types.Key>;\n\ntype Entry = ValueTypeOf<typeof Studio.Types.Entry>;\n\n/**\n * The KPI rail's code: the week's four figures, each with its change on last week — four abreast where four of\n * 170px fit, else two and two, else one above another, so no row stands short beside an empty cell.\n */\nconst kpiRailUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const kpis = $.let(Data.bind(studioKpis).read());\n return (\n <Box background=\"border.subtle\"><Grid gap=\"1px\" templateColumns=\"repeat(auto-fit, minmax(max(calc(25% - 1px), min(calc(50% - 1px), calc((683px - 100%) * 999)), min(100%, calc((341px - 100%) * 999))), 1fr))\" items={kpis.map(($2, k) => Grid.Item(\n <Box background=\"bg.surface\"\n padding={{ top: some(\"3\"), right: some(\"4\"), bottom: some(\"3\"), left: some(\"4\") }}>\n <Stat label={k.label} value={k.value}\n format={k.unit.match({\n money: (_$3) => Format.Currency({ currency: \"USD\", compact: \"short\", maximumFractionDigits: 2n }),\n count: (_$3) => Format.Number(),\n price: (_$3) => Format.Currency({ currency: \"USD\", maximumFractionDigits: 0n }),\n ratio: (_$3) => Format.Percent({ maximumFractionDigits: 0n }),\n })}\n baseline={\n <MetricChip tone={k.change.greater(0.0).ifElse(\n _$3 => variant(\"positive\", null),\n _$3 => k.change.less(0.0).ifElse(_$4 => variant(\"negative\", null), _$4 => variant(\"neutral\", null)),\n )}>\n <Text>{k.change.greater(0.0).ifElse(\n _$3 => East.str`▲ ${East.print(k.change)}%`,\n _$3 => k.change.less(0.0).ifElse(\n _$4 => East.str`▼ ${East.print(k.change.negate())}%`,\n _$4 => \"— flat\",\n ),\n )}</Text>\n </MetricChip>\n } />\n </Box>,\n ))} /></Box>\n );\n }}</Reactive>\n));\n\n/** The Revenue trend's code: revenue by day, as an area. */\nconst revenueTrendUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const days = $.let(Data.bind(studioRevenueDaily).read());\n return (\n <Box height=\"168px\" padding={{ top: some(\"4\"), right: some(\"4\"), bottom: some(\"3\"), left: some(\"3\") }}>\n <Chart height=\"fill\" grid\n layers={Chart.Area(days, { x: r => r.day, y: r => r.revenue }, { color: \"brand.solid\", fillOpacity: 0.08, curve: \"linear\" })}\n x={{ format: Chart.format.date(\"MMM D\") }}\n y={{ format: Chart.format.compact() }} />\n </Box>\n );\n }}</Reactive>\n));\n\n/** The Breakdown bars' code: each region's share of this week's revenue, largest first. */\nconst breakdownBarsUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const sales = $.let(Data.bind(studioSales).read());\n const total = $.let(sales.map(($2, r) => r.revenue).sum());\n const regions = $.let(sales\n .groupSum(($2, r) => r.region, ($2, r) => r.revenue)\n .toArray(($2, revenue, region) => ({ region, revenue })));\n return (\n <Box padding=\"4\">\n <BarStrip data={regions} sort=\"desc\" showValues={false}\n item={r => ({\n label: <Text>{r.region}</Text>,\n value: r.revenue,\n trailing: <Text>{East.str`${East.print(East.Float.roundHalf(r.revenue.divide(total).multiply(100.0)))}%`}</Text>,\n })} />\n </Box>\n );\n }}</Reactive>\n));\n\n/** The Orders by week's code: orders placed each week. */\nconst ordersByWeekUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const weeks = $.let(Data.bind(studioOrdersWeekly).read());\n return (\n <Box height=\"168px\" padding={{ top: some(\"4\"), right: some(\"4\"), bottom: some(\"3\"), left: some(\"3\") }}>\n <Chart height=\"fill\" grid layers={Chart.Column(weeks, { x: r => r.week, y: r => r.orders }, { color: \"brand.solid\" })} />\n </Box>\n );\n }}</Reactive>\n));\n\n/** The Visits sparkline's code: visits by day. */\nconst visitsSparklineUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const visits = $.let(Data.bind(studioVisitsDaily).read());\n return (\n <Box padding=\"4\">\n <Sparkline data={visits.map(($2, r) => r.visits)} type=\"area\" width=\"100%\" height=\"48px\" />\n </Box>\n );\n }}</Reactive>\n));\n\n/** Today's assignments as a read-only table using the shared collection. */\nconst assignmentBoardUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const areas = $.let(Data.bind(studioAreas).read().toDict((_$2, area) => area.id, (_$2, area) => area.name));\n const shifts = $.let(Data.bind(studioShifts).read().toDict((_$2, shift) => shift.id, (_$2, shift) => shift.name));\n const people = $.let(Data.bind(studioPeople).read().toDict((_$2, person) => person.id, (_$2, person) => person.name));\n const today = $.let(Data.bind(studioAssignmentsToday).read());\n return <Table data={today.map((_$2, row) => ({ person: people.get(row.person), area: areas.get(row.area), shift: shifts.get(row.shift) }))} columns={[\"person\", \"area\", \"shift\"]} />;\n }}</Reactive>\n));\n\n/** The week's shifts as a read-only table; editable rostering belongs to e3-ui. */\nconst shiftRosterUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const people = $.let(Data.bind(studioPeople).read().toDict((_$2, person) => person.id, (_$2, person) => person.name));\n const rota = $.let(Data.bind(studioRotaWeek).read());\n return <Table data={rota.map((_$2, row) => ({ person: people.get(row.person), day: row.day, hours: row.hours }))} columns={[\"person\", \"day\", \"hours\"]} />;\n }}</Reactive>\n));\n\nexport const kpiRail = Studio.component(\"kpi_rail\", {\n name: \"KPI rail\", category: \"Display\", icon: \"gauge-high\", frame: \"none\",\n description: \"Revenue, orders, average ticket and fill rate this week, each with its change on last week.\",\n tags: [\"kpi\", \"sales\"],\n}, kpiRailUi);\n\nexport const breakdownBars = Studio.component(\"breakdown_bars\", {\n name: \"Breakdown bars\", category: \"Display\", icon: \"chart-bar\", span: 4n,\n description: \"Each region's share of this week's revenue, largest first.\",\n tags: [\"sales\"],\n}, breakdownBarsUi);\n\nexport const revenueTrend = Studio.component(\"revenue_trend\", {\n name: \"Revenue trend\", category: \"Charts\", icon: \"chart-area\", span: 8n,\n description: \"Revenue by day, as an area.\",\n tags: [\"sales\"],\n}, revenueTrendUi);\n\nexport const ordersByWeek = Studio.component(\"orders_by_week\", {\n name: \"Orders by week\", category: \"Charts\", icon: \"chart-column\", span: 6n,\n description: \"Orders placed each week.\",\n tags: [\"orders\"],\n}, ordersByWeekUi);\n\nexport const visitsSparkline = Studio.component(\"visits_sparkline\", {\n name: \"Visits sparkline\", category: \"Charts\", icon: \"chart-line\", span: 4n,\n description: \"Visits by day, the last two weeks.\",\n tags: [\"traffic\"],\n}, visitsSparklineUi);\n\nexport const assignmentBoard = Studio.component(\"assignment_board\", {\n name: \"Assignment board\", category: \"Collections\", icon: \"border-all\", span: 12n,\n description: \"Today: who works where, by shift.\",\n collections: [\"People\"],\n}, assignmentBoardUi);\n\nexport const shiftRoster = Studio.component(\"shift_roster\", {\n name: \"Shift roster\", category: \"Collections\", icon: \"calendar-week\", span: 12n,\n description: \"This week: people, days and their assigned hours.\",\n collections: [\"People\"],\n}, shiftRosterUi);\n\n/**\n * The pages record: the Ops console's pages — the Overview live as v3, its\n * draft resizing the trend and adding the bars beside it — and its templates,\n * and the other projects' pages.\n */\nexport const studioPages = e3.record(\"studio_pages\", Studio.Types.Pages, {\n initial: new SortedMap<Key, Entry>([\n [{ project: \"Ops console\", page: \"Account detail\" }, variant(\"page\", {\n draft: {\n title: \"Account detail\",\n cells: [\n { key: \"a-kpi\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"kpi_rail\") },\n { key: \"a-orders\", row: \"r2\", span: 8n, height: some(240n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"orders_by_week\") },\n { key: \"a-bars\", row: \"r2\", span: 4n, height: some(240n), align: variant(\"stretch\", null), title: none, content: variant(\"component\", \"breakdown_bars\") },\n { key: \"a-trend\", row: \"r3\", span: 12n, height: some(200n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n ],\n filters: [],\n },\n live: none,\n })],\n [{ project: \"Ops console\", page: \"Overview\" }, variant(\"page\", {\n draft: {\n title: \"Overview\",\n cells: [\n { key: \"o-kpi\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"kpi_rail\") },\n { key: \"o-trend\", row: \"r2\", span: 8n, height: none, align: variant(\"stretch\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n { key: \"o-bars\", row: \"r2\", span: 4n, height: none, align: variant(\"stretch\", null), title: none, content: variant(\"component\", \"breakdown_bars\") },\n { key: \"o-board\", row: \"r3\", span: 12n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"assignment_board\") },\n ],\n filters: [],\n },\n live: some({\n version: 3n,\n page: {\n title: \"Overview\",\n cells: [\n { key: \"o-kpi\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"kpi_rail\") },\n { key: \"o-trend\", row: \"r2\", span: 12n, height: none, align: variant(\"stretch\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n { key: \"o-board\", row: \"r3\", span: 12n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"assignment_board\") },\n ],\n filters: [],\n },\n }),\n })],\n [{ project: \"Ops console\", page: \"Regional rollup\" }, variant(\"page\", {\n draft: {\n title: \"Regional rollup\",\n cells: [\n { key: \"r-trend\", row: \"r1\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n { key: \"r-bars\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: some(\"By region\"), content: variant(\"component\", \"breakdown_bars\") },\n { key: \"r-visits\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"visits_sparkline\") },\n ],\n filters: [],\n },\n live: some({\n version: 1n,\n page: {\n title: \"Regional rollup\",\n cells: [\n { key: \"r-trend\", row: \"r1\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n { key: \"r-bars\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: some(\"By region\"), content: variant(\"component\", \"breakdown_bars\") },\n { key: \"r-visits\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"visits_sparkline\") },\n ],\n filters: [],\n },\n }),\n })],\n [{ project: \"Ops console\", page: \"Weekly export\" }, variant(\"page\", {\n draft: {\n title: \"Weekly export\",\n cells: [\n { key: \"w-orders\", row: \"r1\", span: 12n, height: some(320n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"orders_by_week\") },\n { key: \"w-roster\", row: \"r2\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"shift_roster\") },\n ],\n filters: [],\n },\n live: some({ version: 2n, page: { title: \"Weekly export\", cells: [], filters: [] } }),\n })],\n [{ project: \"Ops console\", page: \"Ops board\" }, variant(\"template\", {\n title: \"Ops board\",\n cells: [\n { key: \"t-orders\", row: \"r1\", span: 8n, height: some(320n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"orders_by_week\") },\n { key: \"t-bars\", row: \"r1\", span: 4n, height: some(320n), align: variant(\"stretch\", null), title: none, content: variant(\"component\", \"breakdown_bars\") },\n ],\n filters: [],\n })],\n [{ project: \"Ops console\", page: \"Report brief\" }, variant(\"template\", {\n title: \"Report brief\",\n cells: [\n { key: \"t-trend\", row: \"r1\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n { key: \"t-orders\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"orders_by_week\") },\n { key: \"t-visits\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"visits_sparkline\") },\n ],\n filters: [],\n })],\n [{ project: \"Ops console\", page: \"Summary\" }, variant(\"template\", {\n title: \"Summary\",\n cells: [\n { key: \"t-kpi\", row: \"r1\", span: 12n, height: some(96n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"kpi_rail\") },\n { key: \"t-trend\", row: \"r2\", span: 8n, height: some(240n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n { key: \"t-bars\", row: \"r2\", span: 4n, height: some(240n), align: variant(\"stretch\", null), title: none, content: variant(\"component\", \"breakdown_bars\") },\n ],\n filters: [],\n })],\n [{ project: \"Finance portal\", page: \"Ledger\" }, variant(\"page\", {\n draft: {\n title: \"Ledger\",\n cells: [\n { key: \"l-trend\", row: \"r1\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n ],\n filters: [],\n },\n live: none,\n })],\n [{ project: \"HR roster\", page: \"Rota\" }, variant(\"page\", {\n draft: {\n title: \"Rota\",\n cells: [\n { key: \"h-roster\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"shift_roster\") },\n ],\n filters: [],\n },\n live: some({\n version: 1n,\n page: {\n title: \"Rota\",\n cells: [\n { key: \"h-roster\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"shift_roster\") },\n ],\n filters: [],\n },\n }),\n })],\n ], compareFor(Studio.Types.Key)),\n mutations: (mutation) => ({\n // The record's one write.\n patch: mutation.patch(),\n }),\n});\n\n/** A page's tiles each a column narrower, one three columns wide or less as it was: what someone else's save changes. */\nconst tilesNarrower = East.function([Studio.Types.Page], Studio.Types.Page, (_$, page) => ({\n title: page.title,\n cells: page.cells.map((_$2, cell) => ({\n key: cell.key, row: cell.row,\n span: cell.span.greater(3n).ifElse(() => cell.span.subtract(1n), () => cell.span),\n height: cell.height, align: cell.align, title: cell.title, content: cell.content,\n })),\n filters: page.filters,\n}));\n\n/** The pages the conflicts example edits, as the builder's start, in a record of their own so no other example's edits meet them. */\nexport const studioConflictPages = e3.record(\"studio_conflict_pages\", Studio.Types.Pages, {\n initial: studioPages.default!,\n mutations: (mutation) => ({\n // The record's one write.\n patch: mutation.patch(),\n // Someone else's save: every page's tiles a column narrower in its draft, its templates as they were.\n elsewhere: mutation.reduce(East.function([Studio.Types.Pages], Studio.Types.Pages, ($, pages) => {\n const narrower = $.const(tilesNarrower);\n return pages.map((_$2, entry) => entry.match({\n page: (_$3, held) => East.value(variant(\"page\", { draft: narrower(held.draft), live: held.live }), Studio.Types.Entry),\n template: (_$3, page) => East.value(variant(\"template\", page), Studio.Types.Entry),\n }));\n })),\n }),\n});\n\nEast.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const components = $.let([kpiRail, breakdownBars, revenueTrend, ordersByWeek, visitsSparkline, assignmentBoard, shiftRoster]);\n const pages = $.let(Record.bind(studioConflictPages, [\"patch\"]));\n const others = $.let(Record.bind(studioConflictPages, [\"elsewhere\"]));\n const theirs = $.const(East.function([], NullType, ($) => { $(others.mutate.elsewhere()); }));\n return (\n <VStack gap=\"3\" align=\"stretch\">\n <HStack gap=\"3\">\n <Button variant=\"outline\" onClick={theirs} loading={others.mutate.pending()}>Someone else saves</Button>\n <Text color=\"fg.muted\">Their change: every tile a column narrower</Text>\n </HStack>\n <Box height=\"760px\">\n <Studio.Builder pages={pages} components={components} project=\"Ops console\" id=\"conflicts\"\n env=\"Staging\" audience=\"Field ops · 24 users\" rollout=\"Immediate\" />\n </Box>\n </VStack>\n );\n }}</Reactive>\n ))"
48808
49187
  },
48809
49188
  {
48810
49189
  "id": "e3-ui:studio.examples.tsx:studioLibrary",
@@ -48812,7 +49191,7 @@
48812
49191
  "package": "e3-ui",
48813
49192
  "file": "east-ui/packages/e3-ui/test/studio/studio.examples.tsx",
48814
49193
  "suite": "",
48815
- "test": "The page library over the same record: one toolbar — the search over templates and pages, Sort · Name, Grid · List and \"+ New page in Ops console\" — beside the projects and the project's pages with their status; the Templates row starts with Blank grid, each card a wireframe of its layout; the Pages row shows each page's wireframe, status and component count with \"Open in builder →\", which opens the page in the builder above; a new page takes a name and a template and is one patch commit",
49194
+ "test": "The page library over the same record: one toolbar — the search over templates and pages, Sort · Name, Grid · List and \"+ New page in Ops console\" — beside the projects and the project's pages with their status; the Templates row starts with Blank grid, each card a wireframe of its layout; the Pages row shows each page's wireframe, status and component count with \"Open in builder →\", which tells the surface in `onOpen`: the surface writes the open page it holds, which the builder above shows and the pane marks; a new page takes a name and a template and is one patch commit",
48816
49195
  "keywords": [
48817
49196
  "Studio",
48818
49197
  "Studio.Library",
@@ -48835,18 +49214,204 @@
48835
49214
  "Draft",
48836
49215
  "Record.bind",
48837
49216
  "patch",
48838
- "e3.record"
49217
+ "e3.record",
49218
+ "onOpen",
49219
+ "page",
49220
+ "State.bind",
49221
+ "navigate"
48839
49222
  ],
48840
49223
  "imports": [
48841
49224
  "import {",
48842
49225
  "import {",
48843
49226
  "import { Data, Record, Studio } from \"@elaraai/e3-ui\";",
48844
- "import e3 from \"@elaraai/e3\";"
49227
+ "import e3 from \"@elaraai/e3\";",
49228
+ "import {"
48845
49229
  ],
48846
49230
  "languages": [
48847
49231
  "tsx"
48848
49232
  ],
48849
- "source": "// The page library over the same record: one toolbar — the search over templates and pages, Sort · Name, Grid · List and \"+ New page in Ops console\" — beside the projects and the project's pages with their status; the Templates row starts with Blank grid, each card a wireframe of its layout; the Pages row shows each page's wireframe, status and component count with \"Open in builder →\", which opens the page in the builder above; a new page takes a name and a template and is one patch commit\n// inputs: []\ntype Key = ValueTypeOf<typeof Studio.Types.Key>;\n\ntype Entry = ValueTypeOf<typeof Studio.Types.Entry>;\n\n/** What a KPI measures: an amount of money, a count, a price or a ratio. */\nconst KpiUnit = VariantType({ money: NullType, count: NullType, price: NullType, ratio: NullType });\n\n/** The week's figures, each with its change on last week in percent — what a KPI task writes. */\nexport const studioKpis = e3.input(\"studio_kpis\", ArrayType(StructType({\n label: StringType, value: FloatType, unit: KpiUnit, change: FloatType,\n})), variant(\"value\", [\n { label: \"Revenue\", value: 1284000.0, unit: variant(\"money\", null), change: 6.4 },\n { label: \"Orders\", value: 8412.0, unit: variant(\"count\", null), change: 2.1 },\n { label: \"Avg ticket\", value: 152.0, unit: variant(\"price\", null), change: -1.3 },\n { label: \"Fill rate\", value: 0.94, unit: variant(\"ratio\", null), change: 0.0 },\n]));\n\n/** Revenue by day. */\nexport const studioRevenueDaily = e3.input(\"studio_revenue_daily\", ArrayType(StructType({ day: DateTimeType, revenue: FloatType })), variant(\"value\", [\n { day: new Date(\"2026-02-12T00:00:00Z\"), revenue: 2640000.0 },\n { day: new Date(\"2026-02-19T00:00:00Z\"), revenue: 2710000.0 },\n { day: new Date(\"2026-02-26T00:00:00Z\"), revenue: 2900000.0 },\n { day: new Date(\"2026-03-05T00:00:00Z\"), revenue: 3180000.0 },\n { day: new Date(\"2026-03-12T00:00:00Z\"), revenue: 3300000.0 },\n { day: new Date(\"2026-03-19T00:00:00Z\"), revenue: 3430000.0 },\n]));\n\n/** This week's sales, one row per region per channel. */\nexport const studioSales = e3.input(\"studio_sales\", ArrayType(StructType({ region: StringType, channel: StringType, revenue: FloatType })), variant(\"value\", [\n { region: \"North\", channel: \"Store\", revenue: 331200.0 },\n { region: \"North\", channel: \"Online\", revenue: 208080.0 },\n { region: \"South\", channel: \"Store\", revenue: 238824.0 },\n { region: \"South\", channel: \"Online\", revenue: 159216.0 },\n { region: \"West\", channel: \"Store\", revenue: 197604.0 },\n { region: \"West\", channel: \"Online\", revenue: 149076.0 },\n]));\n\n/** Orders by week. */\nexport const studioOrdersWeekly = e3.input(\"studio_orders_weekly\", ArrayType(StructType({ week: StringType, orders: FloatType })), variant(\"value\", [\n { week: \"W9\", orders: 96.0 }, { week: \"W10\", orders: 158.0 }, { week: \"W11\", orders: 214.0 },\n { week: \"W12\", orders: 271.0 }, { week: \"W13\", orders: 248.0 }, { week: \"W14\", orders: 196.0 },\n]));\n\n/** Visits by day, the last two weeks. */\nexport const studioVisitsDaily = e3.input(\"studio_visits_daily\", ArrayType(StructType({ day: DateTimeType, visits: FloatType })), variant(\"value\", [\n { day: new Date(\"2026-03-06T00:00:00Z\"), visits: 412.0 }, { day: new Date(\"2026-03-07T00:00:00Z\"), visits: 388.0 },\n { day: new Date(\"2026-03-08T00:00:00Z\"), visits: 301.0 }, { day: new Date(\"2026-03-09T00:00:00Z\"), visits: 296.0 },\n { day: new Date(\"2026-03-10T00:00:00Z\"), visits: 455.0 }, { day: new Date(\"2026-03-11T00:00:00Z\"), visits: 471.0 },\n { day: new Date(\"2026-03-12T00:00:00Z\"), visits: 468.0 }, { day: new Date(\"2026-03-13T00:00:00Z\"), visits: 502.0 },\n { day: new Date(\"2026-03-14T00:00:00Z\"), visits: 479.0 }, { day: new Date(\"2026-03-15T00:00:00Z\"), visits: 344.0 },\n { day: new Date(\"2026-03-16T00:00:00Z\"), visits: 327.0 }, { day: new Date(\"2026-03-17T00:00:00Z\"), visits: 518.0 },\n { day: new Date(\"2026-03-18T00:00:00Z\"), visits: 546.0 }, { day: new Date(\"2026-03-19T00:00:00Z\"), visits: 561.0 },\n]));\n\n/** The floor's areas, its shifts and its people. */\nexport const studioAreas = e3.input(\"studio_areas\", ArrayType(StructType({ id: StringType, name: StringType })), variant(\"value\", [\n { id: \"north\", name: \"North\" }, { id: \"south\", name: \"South\" },\n]));\n\nexport const studioShifts = e3.input(\"studio_shifts\", ArrayType(StructType({ id: StringType, name: StringType, window: StringType })), variant(\"value\", [\n { id: \"am\", name: \"AM\", window: \"06–14\" }, { id: \"pm\", name: \"PM\", window: \"14–22\" }, { id: \"night\", name: \"Night\", window: \"22–06\" },\n]));\n\nexport const studioPeople = e3.input(\"studio_people\", ArrayType(StructType({ id: StringType, name: StringType })), variant(\"value\", [\n { id: \"p1\", name: \"Ana Ruiz\" }, { id: \"p2\", name: \"Ben Cole\" }, { id: \"p3\", name: \"Cai Lin\" }, { id: \"p4\", name: \"Dev Rao\" },\n { id: \"p5\", name: \"Eli Moss\" }, { id: \"p6\", name: \"Fay Ong\" }, { id: \"p7\", name: \"Gus Hart\" }, { id: \"p8\", name: \"Hana Ito\" },\n]));\n\n/** Who works where today. */\nexport const studioAssignmentsToday = e3.input(\"studio_assignments_today\", ArrayType(StructType({\n id: StringType, person: StringType, area: StringType, shift: StringType,\n})), variant(\"value\", [\n { id: \"a1\", person: \"p1\", area: \"north\", shift: \"am\" }, { id: \"a2\", person: \"p2\", area: \"north\", shift: \"am\" },\n { id: \"a3\", person: \"p3\", area: \"north\", shift: \"pm\" }, { id: \"a4\", person: \"p4\", area: \"north\", shift: \"night\" },\n { id: \"a5\", person: \"p5\", area: \"south\", shift: \"am\" }, { id: \"a6\", person: \"p6\", area: \"south\", shift: \"pm\" },\n { id: \"a7\", person: \"p7\", area: \"south\", shift: \"pm\" }, { id: \"a8\", person: \"p8\", area: \"south\", shift: \"night\" },\n]));\n\n/** This week's rota. */\nexport const studioRotaWeek = e3.input(\"studio_rota_week\", ArrayType(StructType({\n id: StringType, person: StringType, day: StringType, hours: IntegerType,\n})), variant(\"value\", [\n { id: \"r1\", person: \"p1\", day: \"Mon\", hours: 8n }, { id: \"r2\", person: \"p1\", day: \"Tue\", hours: 8n }, { id: \"r3\", person: \"p1\", day: \"Wed\", hours: 8n },\n { id: \"r4\", person: \"p2\", day: \"Mon\", hours: 8n }, { id: \"r5\", person: \"p2\", day: \"Thu\", hours: 8n }, { id: \"r6\", person: \"p2\", day: \"Fri\", hours: 6n },\n { id: \"r7\", person: \"p3\", day: \"Tue\", hours: 8n }, { id: \"r8\", person: \"p3\", day: \"Wed\", hours: 8n }, { id: \"r9\", person: \"p3\", day: \"Thu\", hours: 8n },\n { id: \"r10\", person: \"p4\", day: \"Mon\", hours: 10n }, { id: \"r11\", person: \"p4\", day: \"Fri\", hours: 10n },\n]));\n\n/** The KPI rail's code: the week's four figures, each with its change on last week. */\nconst kpiRailUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const kpis = $.let(Data.bind(studioKpis).read());\n return (\n <Box background=\"border.subtle\"><Grid gap=\"1px\" templateColumns=\"repeat(auto-fit, minmax(min(calc(50% - 1px), 170px), 1fr))\" items={kpis.map(($2, k) => Grid.Item(\n <Box background=\"bg.surface\"\n padding={{ top: some(\"3\"), right: some(\"4\"), bottom: some(\"3\"), left: some(\"4\") }}>\n <Stat label={k.label} value={k.value}\n format={k.unit.match({\n money: (_$3) => Format.Currency({ currency: \"USD\", compact: \"short\", maximumFractionDigits: 2n }),\n count: (_$3) => Format.Number(),\n price: (_$3) => Format.Currency({ currency: \"USD\", maximumFractionDigits: 0n }),\n ratio: (_$3) => Format.Percent({ maximumFractionDigits: 0n }),\n })}\n baseline={\n <MetricChip tone={k.change.greater(0.0).ifElse(\n _$3 => variant(\"positive\", null),\n _$3 => k.change.less(0.0).ifElse(_$4 => variant(\"negative\", null), _$4 => variant(\"neutral\", null)),\n )}>\n <Text>{k.change.greater(0.0).ifElse(\n _$3 => East.str`▲ ${East.print(k.change)}%`,\n _$3 => k.change.less(0.0).ifElse(\n _$4 => East.str`▼ ${East.print(k.change.negate())}%`,\n _$4 => \"— flat\",\n ),\n )}</Text>\n </MetricChip>\n } />\n </Box>,\n ))} /></Box>\n );\n }}</Reactive>\n));\n\n/** The Revenue trend's code: revenue by day, as an area. */\nconst revenueTrendUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const days = $.let(Data.bind(studioRevenueDaily).read());\n return (\n <Box height=\"168px\" padding={{ top: some(\"4\"), right: some(\"4\"), bottom: some(\"3\"), left: some(\"3\") }}>\n <Chart height=\"fill\" grid\n layers={Chart.Area(days, { x: r => r.day, y: r => r.revenue }, { color: \"brand.solid\", fillOpacity: 0.08, curve: \"linear\" })}\n x={{ format: Chart.format.date(\"MMM D\") }}\n y={{ format: Chart.format.compact() }} />\n </Box>\n );\n }}</Reactive>\n));\n\n/** The Breakdown bars' code: each region's share of this week's revenue, largest first. */\nconst breakdownBarsUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const sales = $.let(Data.bind(studioSales).read());\n const total = $.let(sales.map(($2, r) => r.revenue).sum());\n const regions = $.let(sales\n .groupSum(($2, r) => r.region, ($2, r) => r.revenue)\n .toArray(($2, revenue, region) => ({ region, revenue })));\n return (\n <Box padding=\"4\">\n <BarStrip data={regions} sort=\"desc\" showValues={false}\n item={r => ({\n label: <Text>{r.region}</Text>,\n value: r.revenue,\n trailing: <Text>{East.str`${East.print(East.Float.roundHalf(r.revenue.divide(total).multiply(100.0)))}%`}</Text>,\n })} />\n </Box>\n );\n }}</Reactive>\n));\n\n/** The Orders by week's code: orders placed each week. */\nconst ordersByWeekUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const weeks = $.let(Data.bind(studioOrdersWeekly).read());\n return (\n <Box height=\"168px\" padding={{ top: some(\"4\"), right: some(\"4\"), bottom: some(\"3\"), left: some(\"3\") }}>\n <Chart height=\"fill\" grid layers={Chart.Column(weeks, { x: r => r.week, y: r => r.orders }, { color: \"brand.solid\" })} />\n </Box>\n );\n }}</Reactive>\n));\n\n/** The Visits sparkline's code: visits by day. */\nconst visitsSparklineUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const visits = $.let(Data.bind(studioVisitsDaily).read());\n return (\n <Box padding=\"4\">\n <Sparkline data={visits.map(($2, r) => r.visits)} type=\"area\" width=\"100%\" height=\"48px\" />\n </Box>\n );\n }}</Reactive>\n));\n\n/** Today's assignments as a read-only table using the shared collection. */\nconst assignmentBoardUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const areas = $.let(Data.bind(studioAreas).read().toDict((_$2, area) => area.id, (_$2, area) => area.name));\n const shifts = $.let(Data.bind(studioShifts).read().toDict((_$2, shift) => shift.id, (_$2, shift) => shift.name));\n const people = $.let(Data.bind(studioPeople).read().toDict((_$2, person) => person.id, (_$2, person) => person.name));\n const today = $.let(Data.bind(studioAssignmentsToday).read());\n return <Table data={today.map((_$2, row) => ({ person: people.get(row.person), area: areas.get(row.area), shift: shifts.get(row.shift) }))} columns={[\"person\", \"area\", \"shift\"]} />;\n }}</Reactive>\n));\n\n/** The week's shifts as a read-only table; editable rostering belongs to e3-ui. */\nconst shiftRosterUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const people = $.let(Data.bind(studioPeople).read().toDict((_$2, person) => person.id, (_$2, person) => person.name));\n const rota = $.let(Data.bind(studioRotaWeek).read());\n return <Table data={rota.map((_$2, row) => ({ person: people.get(row.person), day: row.day, hours: row.hours }))} columns={[\"person\", \"day\", \"hours\"]} />;\n }}</Reactive>\n));\n\nexport const kpiRail = Studio.component(\"kpi_rail\", {\n name: \"KPI rail\", category: \"Display\", icon: \"gauge-high\", frame: \"none\",\n description: \"Revenue, orders, average ticket and fill rate this week, each with its change on last week.\",\n tags: [\"kpi\", \"sales\"],\n}, kpiRailUi);\n\nexport const breakdownBars = Studio.component(\"breakdown_bars\", {\n name: \"Breakdown bars\", category: \"Display\", icon: \"chart-bar\", span: 4n,\n description: \"Each region's share of this week's revenue, largest first.\",\n tags: [\"sales\"],\n}, breakdownBarsUi);\n\nexport const revenueTrend = Studio.component(\"revenue_trend\", {\n name: \"Revenue trend\", category: \"Charts\", icon: \"chart-area\", span: 8n,\n description: \"Revenue by day, as an area.\",\n tags: [\"sales\"],\n}, revenueTrendUi);\n\nexport const ordersByWeek = Studio.component(\"orders_by_week\", {\n name: \"Orders by week\", category: \"Charts\", icon: \"chart-column\", span: 6n,\n description: \"Orders placed each week.\",\n tags: [\"orders\"],\n}, ordersByWeekUi);\n\nexport const visitsSparkline = Studio.component(\"visits_sparkline\", {\n name: \"Visits sparkline\", category: \"Charts\", icon: \"chart-line\", span: 4n,\n description: \"Visits by day, the last two weeks.\",\n tags: [\"traffic\"],\n}, visitsSparklineUi);\n\nexport const assignmentBoard = Studio.component(\"assignment_board\", {\n name: \"Assignment board\", category: \"Collections\", icon: \"border-all\", span: 12n,\n description: \"Today: who works where, by shift.\",\n collections: [\"People\"],\n}, assignmentBoardUi);\n\nexport const shiftRoster = Studio.component(\"shift_roster\", {\n name: \"Shift roster\", category: \"Collections\", icon: \"calendar-week\", span: 12n,\n description: \"This week: people, days and their assigned hours.\",\n collections: [\"People\"],\n}, shiftRosterUi);\n\n/**\n * The pages record: the Ops console's pages — the Overview live as v3, its\n * draft resizing the trend and adding the bars beside it — and its templates,\n * and the other projects' pages.\n */\nexport const studioPages = e3.record(\"studio_pages\", Studio.Types.Pages, {\n initial: new SortedMap<Key, Entry>([\n [{ project: \"Ops console\", page: \"Account detail\" }, variant(\"page\", {\n draft: {\n title: \"Account detail\",\n cells: [\n { key: \"a-kpi\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, component: \"kpi_rail\" },\n { key: \"a-orders\", row: \"r2\", span: 8n, height: some(240n), align: variant(\"top\", null), title: none, component: \"orders_by_week\" },\n { key: \"a-bars\", row: \"r2\", span: 4n, height: some(240n), align: variant(\"stretch\", null), title: none, component: \"breakdown_bars\" },\n { key: \"a-trend\", row: \"r3\", span: 12n, height: some(200n), align: variant(\"top\", null), title: none, component: \"revenue_trend\" },\n ],\n },\n live: none,\n })],\n [{ project: \"Ops console\", page: \"Overview\" }, variant(\"page\", {\n draft: {\n title: \"Overview\",\n cells: [\n { key: \"o-kpi\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, component: \"kpi_rail\" },\n { key: \"o-trend\", row: \"r2\", span: 8n, height: none, align: variant(\"stretch\", null), title: none, component: \"revenue_trend\" },\n { key: \"o-bars\", row: \"r2\", span: 4n, height: none, align: variant(\"stretch\", null), title: none, component: \"breakdown_bars\" },\n { key: \"o-board\", row: \"r3\", span: 12n, height: none, align: variant(\"top\", null), title: none, component: \"assignment_board\" },\n ],\n },\n live: some({\n version: 3n,\n page: {\n title: \"Overview\",\n cells: [\n { key: \"o-kpi\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, component: \"kpi_rail\" },\n { key: \"o-trend\", row: \"r2\", span: 12n, height: none, align: variant(\"stretch\", null), title: none, component: \"revenue_trend\" },\n { key: \"o-board\", row: \"r3\", span: 12n, height: none, align: variant(\"top\", null), title: none, component: \"assignment_board\" },\n ],\n },\n }),\n })],\n [{ project: \"Ops console\", page: \"Regional rollup\" }, variant(\"page\", {\n draft: {\n title: \"Regional rollup\",\n cells: [\n { key: \"r-trend\", row: \"r1\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, component: \"revenue_trend\" },\n { key: \"r-bars\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: some(\"By region\"), component: \"breakdown_bars\" },\n { key: \"r-visits\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: none, component: \"visits_sparkline\" },\n ],\n },\n live: some({\n version: 1n,\n page: {\n title: \"Regional rollup\",\n cells: [\n { key: \"r-trend\", row: \"r1\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, component: \"revenue_trend\" },\n { key: \"r-bars\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: some(\"By region\"), component: \"breakdown_bars\" },\n { key: \"r-visits\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: none, component: \"visits_sparkline\" },\n ],\n },\n }),\n })],\n [{ project: \"Ops console\", page: \"Weekly export\" }, variant(\"page\", {\n draft: {\n title: \"Weekly export\",\n cells: [\n { key: \"w-orders\", row: \"r1\", span: 12n, height: some(320n), align: variant(\"top\", null), title: none, component: \"orders_by_week\" },\n { key: \"w-roster\", row: \"r2\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, component: \"shift_roster\" },\n ],\n },\n live: some({ version: 2n, page: { title: \"Weekly export\", cells: [] } }),\n })],\n [{ project: \"Ops console\", page: \"Ops board\" }, variant(\"template\", {\n title: \"Ops board\",\n cells: [\n { key: \"t-orders\", row: \"r1\", span: 8n, height: some(320n), align: variant(\"top\", null), title: none, component: \"orders_by_week\" },\n { key: \"t-bars\", row: \"r1\", span: 4n, height: some(320n), align: variant(\"stretch\", null), title: none, component: \"breakdown_bars\" },\n ],\n })],\n [{ project: \"Ops console\", page: \"Report brief\" }, variant(\"template\", {\n title: \"Report brief\",\n cells: [\n { key: \"t-trend\", row: \"r1\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, component: \"revenue_trend\" },\n { key: \"t-orders\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: none, component: \"orders_by_week\" },\n { key: \"t-visits\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: none, component: \"visits_sparkline\" },\n ],\n })],\n [{ project: \"Ops console\", page: \"Summary\" }, variant(\"template\", {\n title: \"Summary\",\n cells: [\n { key: \"t-kpi\", row: \"r1\", span: 12n, height: some(96n), align: variant(\"top\", null), title: none, component: \"kpi_rail\" },\n { key: \"t-trend\", row: \"r2\", span: 8n, height: some(240n), align: variant(\"top\", null), title: none, component: \"revenue_trend\" },\n { key: \"t-bars\", row: \"r2\", span: 4n, height: some(240n), align: variant(\"stretch\", null), title: none, component: \"breakdown_bars\" },\n ],\n })],\n [{ project: \"Finance portal\", page: \"Ledger\" }, variant(\"page\", {\n draft: {\n title: \"Ledger\",\n cells: [\n { key: \"l-trend\", row: \"r1\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, component: \"revenue_trend\" },\n ],\n },\n live: none,\n })],\n [{ project: \"HR roster\", page: \"Rota\" }, variant(\"page\", {\n draft: {\n title: \"Rota\",\n cells: [\n { key: \"h-roster\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, component: \"shift_roster\" },\n ],\n },\n live: some({\n version: 1n,\n page: {\n title: \"Rota\",\n cells: [\n { key: \"h-roster\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, component: \"shift_roster\" },\n ],\n },\n }),\n })],\n ], compareFor(Studio.Types.Key)),\n mutations: (mutation) => ({\n // The record's one write.\n patch: mutation.patch(),\n }),\n});\n\nEast.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const components = $.let([kpiRail, breakdownBars, revenueTrend, ordersByWeek, visitsSparkline, assignmentBoard, shiftRoster]);\n const pages = $.let(Record.bind(studioPages));\n return (\n <Box height=\"764px\">\n <Studio.Library pages={pages} components={components} project=\"Ops console\" id=\"studio\" />\n </Box>\n );\n }}</Reactive>\n ))"
49233
+ "source": "// The page library over the same record: one toolbar — the search over templates and pages, Sort · Name, Grid · List and \"+ New page in Ops console\" — beside the projects and the project's pages with their status; the Templates row starts with Blank grid, each card a wireframe of its layout; the Pages row shows each page's wireframe, status and component count with \"Open in builder →\", which tells the surface in `onOpen`: the surface writes the open page it holds, which the builder above shows and the pane marks; a new page takes a name and a template and is one patch commit\n// inputs: []\ntype Key = ValueTypeOf<typeof Studio.Types.Key>;\n\ntype Entry = ValueTypeOf<typeof Studio.Types.Entry>;\n\n/**\n * The KPI rail's code: the week's four figures, each with its change on last week — four abreast where four of\n * 170px fit, else two and two, else one above another, so no row stands short beside an empty cell.\n */\nconst kpiRailUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const kpis = $.let(Data.bind(studioKpis).read());\n return (\n <Box background=\"border.subtle\"><Grid gap=\"1px\" templateColumns=\"repeat(auto-fit, minmax(max(calc(25% - 1px), min(calc(50% - 1px), calc((683px - 100%) * 999)), min(100%, calc((341px - 100%) * 999))), 1fr))\" items={kpis.map(($2, k) => Grid.Item(\n <Box background=\"bg.surface\"\n padding={{ top: some(\"3\"), right: some(\"4\"), bottom: some(\"3\"), left: some(\"4\") }}>\n <Stat label={k.label} value={k.value}\n format={k.unit.match({\n money: (_$3) => Format.Currency({ currency: \"USD\", compact: \"short\", maximumFractionDigits: 2n }),\n count: (_$3) => Format.Number(),\n price: (_$3) => Format.Currency({ currency: \"USD\", maximumFractionDigits: 0n }),\n ratio: (_$3) => Format.Percent({ maximumFractionDigits: 0n }),\n })}\n baseline={\n <MetricChip tone={k.change.greater(0.0).ifElse(\n _$3 => variant(\"positive\", null),\n _$3 => k.change.less(0.0).ifElse(_$4 => variant(\"negative\", null), _$4 => variant(\"neutral\", null)),\n )}>\n <Text>{k.change.greater(0.0).ifElse(\n _$3 => East.str`▲ ${East.print(k.change)}%`,\n _$3 => k.change.less(0.0).ifElse(\n _$4 => East.str`▼ ${East.print(k.change.negate())}%`,\n _$4 => \"— flat\",\n ),\n )}</Text>\n </MetricChip>\n } />\n </Box>,\n ))} /></Box>\n );\n }}</Reactive>\n));\n\n/** The Revenue trend's code: revenue by day, as an area. */\nconst revenueTrendUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const days = $.let(Data.bind(studioRevenueDaily).read());\n return (\n <Box height=\"168px\" padding={{ top: some(\"4\"), right: some(\"4\"), bottom: some(\"3\"), left: some(\"3\") }}>\n <Chart height=\"fill\" grid\n layers={Chart.Area(days, { x: r => r.day, y: r => r.revenue }, { color: \"brand.solid\", fillOpacity: 0.08, curve: \"linear\" })}\n x={{ format: Chart.format.date(\"MMM D\") }}\n y={{ format: Chart.format.compact() }} />\n </Box>\n );\n }}</Reactive>\n));\n\n/** The Breakdown bars' code: each region's share of this week's revenue, largest first. */\nconst breakdownBarsUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const sales = $.let(Data.bind(studioSales).read());\n const total = $.let(sales.map(($2, r) => r.revenue).sum());\n const regions = $.let(sales\n .groupSum(($2, r) => r.region, ($2, r) => r.revenue)\n .toArray(($2, revenue, region) => ({ region, revenue })));\n return (\n <Box padding=\"4\">\n <BarStrip data={regions} sort=\"desc\" showValues={false}\n item={r => ({\n label: <Text>{r.region}</Text>,\n value: r.revenue,\n trailing: <Text>{East.str`${East.print(East.Float.roundHalf(r.revenue.divide(total).multiply(100.0)))}%`}</Text>,\n })} />\n </Box>\n );\n }}</Reactive>\n));\n\n/** The Orders by week's code: orders placed each week. */\nconst ordersByWeekUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const weeks = $.let(Data.bind(studioOrdersWeekly).read());\n return (\n <Box height=\"168px\" padding={{ top: some(\"4\"), right: some(\"4\"), bottom: some(\"3\"), left: some(\"3\") }}>\n <Chart height=\"fill\" grid layers={Chart.Column(weeks, { x: r => r.week, y: r => r.orders }, { color: \"brand.solid\" })} />\n </Box>\n );\n }}</Reactive>\n));\n\n/** The Visits sparkline's code: visits by day. */\nconst visitsSparklineUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const visits = $.let(Data.bind(studioVisitsDaily).read());\n return (\n <Box padding=\"4\">\n <Sparkline data={visits.map(($2, r) => r.visits)} type=\"area\" width=\"100%\" height=\"48px\" />\n </Box>\n );\n }}</Reactive>\n));\n\n/** Today's assignments as a read-only table using the shared collection. */\nconst assignmentBoardUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const areas = $.let(Data.bind(studioAreas).read().toDict((_$2, area) => area.id, (_$2, area) => area.name));\n const shifts = $.let(Data.bind(studioShifts).read().toDict((_$2, shift) => shift.id, (_$2, shift) => shift.name));\n const people = $.let(Data.bind(studioPeople).read().toDict((_$2, person) => person.id, (_$2, person) => person.name));\n const today = $.let(Data.bind(studioAssignmentsToday).read());\n return <Table data={today.map((_$2, row) => ({ person: people.get(row.person), area: areas.get(row.area), shift: shifts.get(row.shift) }))} columns={[\"person\", \"area\", \"shift\"]} />;\n }}</Reactive>\n));\n\n/** The week's shifts as a read-only table; editable rostering belongs to e3-ui. */\nconst shiftRosterUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const people = $.let(Data.bind(studioPeople).read().toDict((_$2, person) => person.id, (_$2, person) => person.name));\n const rota = $.let(Data.bind(studioRotaWeek).read());\n return <Table data={rota.map((_$2, row) => ({ person: people.get(row.person), day: row.day, hours: row.hours }))} columns={[\"person\", \"day\", \"hours\"]} />;\n }}</Reactive>\n));\n\nexport const kpiRail = Studio.component(\"kpi_rail\", {\n name: \"KPI rail\", category: \"Display\", icon: \"gauge-high\", frame: \"none\",\n description: \"Revenue, orders, average ticket and fill rate this week, each with its change on last week.\",\n tags: [\"kpi\", \"sales\"],\n}, kpiRailUi);\n\nexport const breakdownBars = Studio.component(\"breakdown_bars\", {\n name: \"Breakdown bars\", category: \"Display\", icon: \"chart-bar\", span: 4n,\n description: \"Each region's share of this week's revenue, largest first.\",\n tags: [\"sales\"],\n}, breakdownBarsUi);\n\nexport const revenueTrend = Studio.component(\"revenue_trend\", {\n name: \"Revenue trend\", category: \"Charts\", icon: \"chart-area\", span: 8n,\n description: \"Revenue by day, as an area.\",\n tags: [\"sales\"],\n}, revenueTrendUi);\n\nexport const ordersByWeek = Studio.component(\"orders_by_week\", {\n name: \"Orders by week\", category: \"Charts\", icon: \"chart-column\", span: 6n,\n description: \"Orders placed each week.\",\n tags: [\"orders\"],\n}, ordersByWeekUi);\n\nexport const visitsSparkline = Studio.component(\"visits_sparkline\", {\n name: \"Visits sparkline\", category: \"Charts\", icon: \"chart-line\", span: 4n,\n description: \"Visits by day, the last two weeks.\",\n tags: [\"traffic\"],\n}, visitsSparklineUi);\n\nexport const assignmentBoard = Studio.component(\"assignment_board\", {\n name: \"Assignment board\", category: \"Collections\", icon: \"border-all\", span: 12n,\n description: \"Today: who works where, by shift.\",\n collections: [\"People\"],\n}, assignmentBoardUi);\n\nexport const shiftRoster = Studio.component(\"shift_roster\", {\n name: \"Shift roster\", category: \"Collections\", icon: \"calendar-week\", span: 12n,\n description: \"This week: people, days and their assigned hours.\",\n collections: [\"People\"],\n}, shiftRosterUi);\n\n/**\n * The pages record: the Ops console's pages — the Overview live as v3, its\n * draft resizing the trend and adding the bars beside it — and its templates,\n * and the other projects' pages.\n */\nexport const studioPages = e3.record(\"studio_pages\", Studio.Types.Pages, {\n initial: new SortedMap<Key, Entry>([\n [{ project: \"Ops console\", page: \"Account detail\" }, variant(\"page\", {\n draft: {\n title: \"Account detail\",\n cells: [\n { key: \"a-kpi\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"kpi_rail\") },\n { key: \"a-orders\", row: \"r2\", span: 8n, height: some(240n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"orders_by_week\") },\n { key: \"a-bars\", row: \"r2\", span: 4n, height: some(240n), align: variant(\"stretch\", null), title: none, content: variant(\"component\", \"breakdown_bars\") },\n { key: \"a-trend\", row: \"r3\", span: 12n, height: some(200n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n ],\n filters: [],\n },\n live: none,\n })],\n [{ project: \"Ops console\", page: \"Overview\" }, variant(\"page\", {\n draft: {\n title: \"Overview\",\n cells: [\n { key: \"o-kpi\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"kpi_rail\") },\n { key: \"o-trend\", row: \"r2\", span: 8n, height: none, align: variant(\"stretch\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n { key: \"o-bars\", row: \"r2\", span: 4n, height: none, align: variant(\"stretch\", null), title: none, content: variant(\"component\", \"breakdown_bars\") },\n { key: \"o-board\", row: \"r3\", span: 12n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"assignment_board\") },\n ],\n filters: [],\n },\n live: some({\n version: 3n,\n page: {\n title: \"Overview\",\n cells: [\n { key: \"o-kpi\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"kpi_rail\") },\n { key: \"o-trend\", row: \"r2\", span: 12n, height: none, align: variant(\"stretch\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n { key: \"o-board\", row: \"r3\", span: 12n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"assignment_board\") },\n ],\n filters: [],\n },\n }),\n })],\n [{ project: \"Ops console\", page: \"Regional rollup\" }, variant(\"page\", {\n draft: {\n title: \"Regional rollup\",\n cells: [\n { key: \"r-trend\", row: \"r1\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n { key: \"r-bars\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: some(\"By region\"), content: variant(\"component\", \"breakdown_bars\") },\n { key: \"r-visits\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"visits_sparkline\") },\n ],\n filters: [],\n },\n live: some({\n version: 1n,\n page: {\n title: \"Regional rollup\",\n cells: [\n { key: \"r-trend\", row: \"r1\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n { key: \"r-bars\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: some(\"By region\"), content: variant(\"component\", \"breakdown_bars\") },\n { key: \"r-visits\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"visits_sparkline\") },\n ],\n filters: [],\n },\n }),\n })],\n [{ project: \"Ops console\", page: \"Weekly export\" }, variant(\"page\", {\n draft: {\n title: \"Weekly export\",\n cells: [\n { key: \"w-orders\", row: \"r1\", span: 12n, height: some(320n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"orders_by_week\") },\n { key: \"w-roster\", row: \"r2\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"shift_roster\") },\n ],\n filters: [],\n },\n live: some({ version: 2n, page: { title: \"Weekly export\", cells: [], filters: [] } }),\n })],\n [{ project: \"Ops console\", page: \"Ops board\" }, variant(\"template\", {\n title: \"Ops board\",\n cells: [\n { key: \"t-orders\", row: \"r1\", span: 8n, height: some(320n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"orders_by_week\") },\n { key: \"t-bars\", row: \"r1\", span: 4n, height: some(320n), align: variant(\"stretch\", null), title: none, content: variant(\"component\", \"breakdown_bars\") },\n ],\n filters: [],\n })],\n [{ project: \"Ops console\", page: \"Report brief\" }, variant(\"template\", {\n title: \"Report brief\",\n cells: [\n { key: \"t-trend\", row: \"r1\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n { key: \"t-orders\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"orders_by_week\") },\n { key: \"t-visits\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"visits_sparkline\") },\n ],\n filters: [],\n })],\n [{ project: \"Ops console\", page: \"Summary\" }, variant(\"template\", {\n title: \"Summary\",\n cells: [\n { key: \"t-kpi\", row: \"r1\", span: 12n, height: some(96n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"kpi_rail\") },\n { key: \"t-trend\", row: \"r2\", span: 8n, height: some(240n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n { key: \"t-bars\", row: \"r2\", span: 4n, height: some(240n), align: variant(\"stretch\", null), title: none, content: variant(\"component\", \"breakdown_bars\") },\n ],\n filters: [],\n })],\n [{ project: \"Finance portal\", page: \"Ledger\" }, variant(\"page\", {\n draft: {\n title: \"Ledger\",\n cells: [\n { key: \"l-trend\", row: \"r1\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n ],\n filters: [],\n },\n live: none,\n })],\n [{ project: \"HR roster\", page: \"Rota\" }, variant(\"page\", {\n draft: {\n title: \"Rota\",\n cells: [\n { key: \"h-roster\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"shift_roster\") },\n ],\n filters: [],\n },\n live: some({\n version: 1n,\n page: {\n title: \"Rota\",\n cells: [\n { key: \"h-roster\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"shift_roster\") },\n ],\n filters: [],\n },\n }),\n })],\n ], compareFor(Studio.Types.Key)),\n mutations: (mutation) => ({\n // The record's one write.\n patch: mutation.patch(),\n }),\n});\n\nEast.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const components = $.let([kpiRail, breakdownBars, revenueTrend, ordersByWeek, visitsSparkline, assignmentBoard, shiftRoster]);\n const pages = $.let(Record.bind(studioPages));\n // The open page is the surface's: the builder above shows it. A host with routes navigates here instead.\n const open = $.let(State.bind([Studio.Types.Key], \"ex.studio.open\", { project: \"Ops console\", page: \"Account detail\" }));\n const go = $.const(East.function([Studio.Types.Key], NullType, ($2, key) => { $2(open.write(key)); }));\n return (\n <Box height=\"764px\">\n <Studio.Library pages={pages} components={components} project=\"Ops console\" page={open.read()} onOpen={go} />\n </Box>\n );\n }}</Reactive>\n ))"
49234
+ },
49235
+ {
49236
+ "id": "e3-ui:studio.examples.tsx:studioContent",
49237
+ "skill": "e3-ui",
49238
+ "package": "e3-ui",
49239
+ "file": "east-ui/packages/e3-ui/test/studio/studio.examples.tsx",
49240
+ "suite": "",
49241
+ "test": "A page whose placements hold content: a text block, visuals over the two sources the surface lists — over the sales, revenue by region as stacked columns and the top regions as a list; over the returns, refunds by reason as bars and the items returned as a KPI — and a developer's component. The surface lists its sources with Studio.source — a bound handle, a name, an icon and its fields' labels and formats — and a filter is on one of the sources the page's visuals read: here two, so a new starting filter's editor asks which, and the rail names each source once before its chips. The page's seeds are built with Studio.visual, and its pages record declares Studio.migrations.cellContent, the one step that carries pages stored before a placement held content",
49242
+ "keywords": [
49243
+ "Studio",
49244
+ "Studio.source",
49245
+ "sources",
49246
+ "source",
49247
+ "fields",
49248
+ "Studio.visual",
49249
+ "visual",
49250
+ "KPI",
49251
+ "chart",
49252
+ "column",
49253
+ "list",
49254
+ "table",
49255
+ "text block",
49256
+ "text",
49257
+ "content",
49258
+ "Studio.Types.Content",
49259
+ "Studio.migrations",
49260
+ "cellContent",
49261
+ "migration.rows",
49262
+ "migrations",
49263
+ "Data.bind",
49264
+ "Studio.Builder",
49265
+ "e3.record",
49266
+ "two sources",
49267
+ "datasets",
49268
+ "starting filters",
49269
+ "filter"
49270
+ ],
49271
+ "imports": [
49272
+ "import {",
49273
+ "import {",
49274
+ "import { Data, Record, Studio } from \"@elaraai/e3-ui\";",
49275
+ "import e3 from \"@elaraai/e3\";",
49276
+ "import {"
49277
+ ],
49278
+ "languages": [
49279
+ "tsx"
49280
+ ],
49281
+ "source": "// A page whose placements hold content: a text block, visuals over the two sources the surface lists — over the sales, revenue by region as stacked columns and the top regions as a list; over the returns, refunds by reason as bars and the items returned as a KPI — and a developer's component. The surface lists its sources with Studio.source — a bound handle, a name, an icon and its fields' labels and formats — and a filter is on one of the sources the page's visuals read: here two, so a new starting filter's editor asks which, and the rail names each source once before its chips. The page's seeds are built with Studio.visual, and its pages record declares Studio.migrations.cellContent, the one step that carries pages stored before a placement held content\n// inputs: []\ntype Key = ValueTypeOf<typeof Studio.Types.Key>;\n\ntype Entry = ValueTypeOf<typeof Studio.Types.Entry>;\n\n/**\n * The KPI rail's code: the week's four figures, each with its change on last week — four abreast where four of\n * 170px fit, else two and two, else one above another, so no row stands short beside an empty cell.\n */\nconst kpiRailUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const kpis = $.let(Data.bind(studioKpis).read());\n return (\n <Box background=\"border.subtle\"><Grid gap=\"1px\" templateColumns=\"repeat(auto-fit, minmax(max(calc(25% - 1px), min(calc(50% - 1px), calc((683px - 100%) * 999)), min(100%, calc((341px - 100%) * 999))), 1fr))\" items={kpis.map(($2, k) => Grid.Item(\n <Box background=\"bg.surface\"\n padding={{ top: some(\"3\"), right: some(\"4\"), bottom: some(\"3\"), left: some(\"4\") }}>\n <Stat label={k.label} value={k.value}\n format={k.unit.match({\n money: (_$3) => Format.Currency({ currency: \"USD\", compact: \"short\", maximumFractionDigits: 2n }),\n count: (_$3) => Format.Number(),\n price: (_$3) => Format.Currency({ currency: \"USD\", maximumFractionDigits: 0n }),\n ratio: (_$3) => Format.Percent({ maximumFractionDigits: 0n }),\n })}\n baseline={\n <MetricChip tone={k.change.greater(0.0).ifElse(\n _$3 => variant(\"positive\", null),\n _$3 => k.change.less(0.0).ifElse(_$4 => variant(\"negative\", null), _$4 => variant(\"neutral\", null)),\n )}>\n <Text>{k.change.greater(0.0).ifElse(\n _$3 => East.str`▲ ${East.print(k.change)}%`,\n _$3 => k.change.less(0.0).ifElse(\n _$4 => East.str`▼ ${East.print(k.change.negate())}%`,\n _$4 => \"— flat\",\n ),\n )}</Text>\n </MetricChip>\n } />\n </Box>,\n ))} /></Box>\n );\n }}</Reactive>\n));\n\nexport const kpiRail = Studio.component(\"kpi_rail\", {\n name: \"KPI rail\", category: \"Display\", icon: \"gauge-high\", frame: \"none\",\n description: \"Revenue, orders, average ticket and fill rate this week, each with its change on last week.\",\n tags: [\"kpi\", \"sales\"],\n}, kpiRailUi);\n\n/** This week's revenue by region, as columns split by channel. */\nconst revenueByRegion = Studio.visual.of(\"sales\", Studio.visual.column({\n x: Studio.visual.group(\"region\"),\n values: [Studio.visual.sum(\"revenue\", { label: \"Revenue\" })],\n split: \"channel\",\n stack: \"stacked\",\n}));\n\n/** The regions by revenue, largest first, each with a bar. */\nconst topRegions = Studio.visual.of(\"sales\", Studio.visual.list({\n item: Studio.visual.group(\"region\", { sort: \"high\", top: 5n }),\n values: [Studio.visual.sum(\"revenue\")],\n bar: true,\n}));\n\n/** This week's refunds by why the items came back, the largest first. */\nconst refundsByReason = Studio.visual.of(\"returns\", Studio.visual.bar({\n x: Studio.visual.group(\"reason\", { sort: \"high\" }),\n values: [Studio.visual.sum(\"refunded\")],\n}));\n\n/** How many items came back this week. */\nconst itemsReturned = Studio.visual.of(\"returns\", Studio.visual.kpi({\n value: Studio.visual.sum(\"items\", { label: \"Items returned\" }),\n}));\n\n/**\n * The pages of a project whose placements hold content: a text block, two\n * visuals over the sales, a developer's component, and two visuals over the\n * returns — so a filter's editor asks which dataset it is on. Its one migration step\n * carries a workspace whose pages were stored before a placement held content\n * — each component key becomes `component(key)` — and a workspace deployed\n * fresh counts it applied.\n */\nexport const studioContentPages = e3.record(\"studio_content_pages\", Studio.Types.Pages, {\n initial: new SortedMap<Key, Entry>([\n [{ project: \"Sales desk\", page: \"This week\" }, variant(\"page\", {\n draft: {\n title: \"This week\",\n cells: [\n { key: \"s-note\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none,\n content: Studio.visual.text(\"Figures are to last night's close.\\n\\nRevenue is in US dollars, before returns.\", \"About these numbers\") },\n { key: \"s-revenue\", row: \"r2\", span: 8n, height: some(240n), align: variant(\"top\", null), title: some(\"Revenue by region\"), content: revenueByRegion },\n { key: \"s-top\", row: \"r2\", span: 4n, height: some(240n), align: variant(\"stretch\", null), title: none, content: topRegions },\n { key: \"s-kpi\", row: \"r3\", span: 12n, height: none, align: variant(\"top\", null), title: none, content: Studio.visual.component(\"kpi_rail\") },\n { key: \"s-reasons\", row: \"r4\", span: 8n, height: some(220n), align: variant(\"top\", null), title: some(\"Refunds by reason\"), content: refundsByReason },\n { key: \"s-returned\", row: \"r4\", span: 4n, height: none, align: variant(\"stretch\", null), title: none, content: itemsReturned },\n ],\n filters: [],\n },\n live: none,\n })],\n ], compareFor(Studio.Types.Key)),\n mutations: (mutation) => ({\n // The record's one write.\n patch: mutation.patch(),\n }),\n // Pages stored before a placement held content are carried by this one step.\n migrations: (migration) => [migration.rows(\"cell_content\", Studio.migrations.cellContent)],\n});\n\nEast.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const components = $.let([kpiRail]);\n const pages = $.let(Record.bind(studioContentPages));\n const sales = $.let(Data.bind(studioSales));\n const returns = $.let(Data.bind(studioReturns));\n return (\n <Box height=\"760px\">\n <Studio.Builder pages={pages} components={components} project=\"Sales desk\" id=\"studioContent\"\n sources={{\n sales: Studio.source(sales, {\n name: \"Sales\", icon: \"receipt\", description: \"One row per region per channel\",\n fields: {\n region: { label: \"Region\" },\n channel: { label: \"Channel\" },\n revenue: { label: \"Revenue\", format: { currency: { code: \"USD\" } } },\n },\n }),\n returns: Studio.source(returns, {\n name: \"Returns\", icon: \"rotate-left\", description: \"One row per region, channel and reason\",\n fields: {\n region: { label: \"Region\" },\n channel: { label: \"Channel\" },\n reason: { label: \"Reason\" },\n items: { label: \"Items\" },\n refunded: { label: \"Refunded\", format: { currency: { code: \"USD\" } } },\n },\n }),\n }} />\n </Box>\n );\n }}</Reactive>\n ))"
49282
+ },
49283
+ {
49284
+ "id": "e3-ui:studio.examples.tsx:studioVisuals",
49285
+ "skill": "e3-ui",
49286
+ "package": "e3-ui",
49287
+ "file": "east-ui/packages/e3-ui/test/studio/studio.examples.tsx",
49288
+ "suite": "",
49289
+ "test": "Every form a visual draws, on a published page over two years of orders, every reader starting in the latest quarter — the page's starting filter on the orders' dates, its window: the quarter's revenue as a KPI with its goal, its change on a year ago (`period: \"year_ago\"`) and its trend, and its orders' count against the quarter before (`period: \"previous\"`); a donut of revenue by category; columns stacked by region, the top customers' bars, a line, an area and a scatter; a combo of revenue against margin on its right axis; the customers as a list with ranking bars; a summary of regions over categories with its total row and a goal its cells are marked against; a pivot of orders by region and month on the heat ramp; and the latest orders, a page at a time",
49290
+ "keywords": [
49291
+ "Studio",
49292
+ "Studio.Page",
49293
+ "Studio.visual",
49294
+ "visual",
49295
+ "KPI",
49296
+ "goal",
49297
+ "trend",
49298
+ "chart",
49299
+ "column",
49300
+ "bar",
49301
+ "line",
49302
+ "area",
49303
+ "combo",
49304
+ "scatter",
49305
+ "pie",
49306
+ "donut",
49307
+ "list",
49308
+ "ranking bar",
49309
+ "table",
49310
+ "records",
49311
+ "summary",
49312
+ "total",
49313
+ "pivot",
49314
+ "heat",
49315
+ "Studio.source",
49316
+ "Data.bind"
49317
+ ],
49318
+ "imports": [
49319
+ "import {",
49320
+ "import {",
49321
+ "import { Data, Record, Studio } from \"@elaraai/e3-ui\";",
49322
+ "import e3 from \"@elaraai/e3\";",
49323
+ "import {"
49324
+ ],
49325
+ "languages": [
49326
+ "tsx"
49327
+ ],
49328
+ "source": "// Every form a visual draws, on a published page over two years of orders, every reader starting in the latest quarter — the page's starting filter on the orders' dates, its window: the quarter's revenue as a KPI with its goal, its change on a year ago (`period: \"year_ago\"`) and its trend, and its orders' count against the quarter before (`period: \"previous\"`); a donut of revenue by category; columns stacked by region, the top customers' bars, a line, an area and a scatter; a combo of revenue against margin on its right axis; the customers as a list with ranking bars; a summary of regions over categories with its total row and a goal its cells are marked against; a pivot of orders by region and month on the heat ramp; and the latest orders, a page at a time\n// inputs: []\ntype Key = ValueTypeOf<typeof Studio.Types.Key>;\n\ntype Entry = ValueTypeOf<typeof Studio.Types.Entry>;\n\n/** One order: when it was placed, its region, category and customer, its revenue and units, and its margin — none where none was recorded. */\nconst OrderType = StructType({\n ordered_at: DateTimeType, region: StringType, category: StringType, customer: StringType, revenue: FloatType, units: IntegerType, margin: OptionType(FloatType),\n});\n\n/** One part of an order, drawn from its number: the number through the part's own stride, modulo a prime — so no two parts move in step. */\nconst drawPart = East.function([IntegerType, IntegerType], IntegerType, (_$, n, stride) => n.multiply(stride).add(stride.remainder(9_973n)).remainder(1_000_003n));\n\n/**\n * A trade supplier's orders over two years, made from each order's number\n * alone — the same rows every time, varied as real ones are:\n *\n * - placed on a working day from 1 October 2024 to 30 September 2026, spread\n * a couple of days either way, so no two weeks are alike;\n * - for one of fourteen customers, each as often as it buys, each in its own\n * region — New South Wales sells the most, South Australia the least — and\n * of one of three categories: Tools the most, then Electrical, then Garden;\n * - its units following its category's season — the garden's spring, the end\n * of the financial year in June, the trades' summer break — and its prices\n * rising about a tenth a year;\n * - its margin its category's, give or take, with one order in about a\n * hundred recording none.\n */\nconst generateOrders = East.function([IntegerType], ArrayType(OrderType), ($, count) => {\n const draw = $.const(drawPart);\n // The Monday before the first working day, Tuesday 1 October 2024, and the working days from it to Wednesday 30 September 2026.\n const monday = $.const(new Date(\"2024-09-30T00:00:00Z\"), DateTimeType);\n const workdays = $.const(522n);\n // The customers, each in its region, and how often each buys: of forty orders, Harbour five, Northwind four, …\n const customers = $.const([\"Harbour\", \"Northwind\", \"Ironbark\", \"Bluewater\", \"Summit\", \"Redgum\", \"Kestrel\", \"Coastline\", \"Tallowood\", \"Saltbush\", \"Granite Peak\", \"Banksia\", \"Acme\", \"Mallee\"]);\n const regions = $.const([\"NSW\", \"NSW\", \"NSW\", \"NSW\", \"VIC\", \"VIC\", \"VIC\", \"QLD\", \"QLD\", \"QLD\", \"WA\", \"WA\", \"SA\", \"SA\"]);\n const buyers = $.const([0n, 0n, 0n, 0n, 0n, 1n, 1n, 1n, 1n, 2n, 2n, 3n, 4n, 4n, 4n, 4n, 5n, 5n, 5n, 6n, 6n, 6n, 7n, 7n, 7n, 7n, 8n, 8n, 9n, 9n, 10n, 10n, 10n, 10n, 11n, 11n, 12n, 12n, 12n, 13n]);\n // The categories, how often each sells — of twenty orders, Tools nine, Electrical seven, Garden four — a unit's price and the margin of each.\n const categories = $.const([\"Tools\", \"Electrical\", \"Garden\"]);\n const sold = $.const([0n, 0n, 0n, 0n, 0n, 0n, 0n, 0n, 0n, 1n, 1n, 1n, 1n, 1n, 1n, 1n, 2n, 2n, 2n, 2n]);\n const prices = $.const([11.8, 10.9, 8.7]);\n const margins = $.const([0.22, 0.16, 0.19]);\n // Each category's season, January to December: the trades slow over summer and busy before the financial year ends in June; the garden's spring.\n const seasons = $.const([\n [0.8, 0.95, 1.05, 1.0, 1.05, 1.3, 0.95, 1.0, 1.05, 1.05, 1.1, 0.75],\n [0.8, 0.95, 1.0, 1.0, 1.05, 1.25, 1.0, 1.0, 1.0, 1.05, 1.1, 0.8],\n [0.9, 0.85, 0.95, 0.85, 0.7, 0.6, 0.6, 0.85, 1.35, 1.45, 1.4, 1.05],\n ]);\n return East.Array.generate(count, OrderType, ($2, i) => {\n // Its working day: spread evenly over the two years, then a couple either way.\n const spread = $2.let(i.multiply(workdays).divide(count).add(draw(i, 390_383n).remainder(5n)).subtract(1n));\n const day = $2.let(spread.less(1n).ifElse(() => 1n, () => spread.greater(workdays).ifElse(() => workdays, () => spread)));\n const at = $2.let(monday.addDays(day.divide(5n).multiply(7n).add(day.remainder(5n))));\n const buyer = $2.let(buyers.get(draw(i, 479_909n).remainder(40n)));\n const category = $2.let(sold.get(draw(i, 350_377n).remainder(20n)));\n const season = $2.let(seasons.get(category).get(at.getMonth().subtract(1n)));\n const units = $2.let(East.Float.roundHalf(draw(i, 611_953n).remainder(150n).add(8n).toFloat().multiply(season)));\n // Prices about a tenth higher a year on, each order give or take eight in a hundred.\n const growth = $2.let(day.toFloat().divide(261.0).multiply(0.1).add(1.0));\n const noise = $2.let(draw(i, 104_729n).remainder(17n).toFloat().divide(100.0).add(0.92));\n const revenue = $2.let(East.Float.roundHalf(units.toFloat().multiply(prices.get(category)).multiply(noise).multiply(growth).multiply(100.0)).toFloat().divide(100.0));\n const margin = $2.let(East.Float.roundHalf(margins.get(category).add(draw(i, 746_773n).remainder(11n).subtract(5n).toFloat().divide(100.0)).multiply(100.0)).toFloat().divide(100.0));\n return {\n ordered_at: at,\n region: regions.get(buyer),\n category: categories.get(category),\n customer: customers.get(buyer),\n revenue,\n units,\n margin: draw(i, 821_641n).remainder(97n).equal(0n).ifElse(() => East.value(none, OptionType(FloatType)), () => some(margin)),\n };\n });\n});\n\n/** The supplier's orders, two years of them: each one's date, region, category, customer, revenue, units and margin. */\nexport const studioOrders = e3.input(\"studio_orders\", ArrayType(OrderType), variant(\"value\", East.compile(generateOrders, [])(2_920n)));\n\nconst vis = Studio.visual;\n\n/** The orders' fields, as every page over them lists them: each one's label, and how a number of it prints. */\nexport const orderFields = {\n ordered_at: { label: \"Ordered\" },\n region: { label: \"Region\" },\n category: { label: \"Category\" },\n customer: { label: \"Customer\" },\n revenue: { label: \"Revenue\", format: { currency: { code: \"AUD\" } } },\n units: { label: \"Units\" },\n margin: { label: \"Margin\", format: \"percent\" },\n} as const;\n\n/**\n * The Visuals page's placements: the quarter's revenue against its goal and\n * a year ago, and its orders against the quarter before, and a donut; the\n * series charts, the combo and the scatter; the list; the summary and the\n * pivot; and the records.\n */\nconst visualCells = [\n { key: \"v-revenue\", row: \"r1\", span: 4n, height: none, align: variant(\"stretch\", null), title: none, content: vis.of(\"orders\", vis.kpi({\n value: vis.sum(\"revenue\", { goal: 400000 }), compare: vis.sum(\"revenue\", { period: \"year_ago\" }), trend: \"ordered_at\",\n })) },\n { key: \"v-orders\", row: \"r1\", span: 4n, height: none, align: variant(\"stretch\", null), title: none, content: vis.of(\"orders\", vis.kpi({\n value: vis.count(), compare: vis.count({ period: \"previous\" }), trend: \"ordered_at\",\n })) },\n { key: \"v-share\", row: \"r1\", span: 4n, height: some(240n), align: variant(\"stretch\", null), title: none, content: vis.of(\"orders\", vis.pie({ slice: vis.group(\"category\"), value: vis.sum(\"revenue\"), donut: true })) },\n { key: \"v-months\", row: \"r2\", span: 6n, height: some(240n), align: variant(\"stretch\", null), title: none, content: vis.of(\"orders\", vis.column({ x: vis.group(\"ordered_at\", { bucket: \"month\" }), values: [vis.sum(\"revenue\")], split: \"region\", stack: \"stacked\" })) },\n { key: \"v-customers\", row: \"r2\", span: 6n, height: some(240n), align: variant(\"stretch\", null), title: none, content: vis.of(\"orders\", vis.bar({ x: vis.group(\"customer\", { sort: \"high\", top: 4n }), values: [vis.sum(\"revenue\")] })) },\n { key: \"v-units\", row: \"r3\", span: 4n, height: some(220n), align: variant(\"stretch\", null), title: none, content: vis.of(\"orders\", vis.line({ x: vis.group(\"ordered_at\", { bucket: \"week\" }), values: [vis.sum(\"units\")] })) },\n { key: \"v-trend\", row: \"r3\", span: 4n, height: some(220n), align: variant(\"stretch\", null), title: none, content: vis.of(\"orders\", vis.area({ x: vis.group(\"ordered_at\", { bucket: \"month\" }), values: [vis.sum(\"revenue\", { goal: 130000 })] })) },\n { key: \"v-scatter\", row: \"r3\", span: 4n, height: some(220n), align: variant(\"stretch\", null), title: none, content: vis.of(\"orders\", vis.scatter({ point: \"customer\", x: vis.sum(\"units\"), y: vis.sum(\"revenue\"), split: \"region\" })) },\n { key: \"v-combo\", row: \"r4\", span: 6n, height: some(240n), align: variant(\"stretch\", null), title: none, content: vis.of(\"orders\", vis.combo({\n x: vis.group(\"region\"), columns: [vis.left(vis.sum(\"revenue\"))], lines: [vis.right(vis.mean(\"margin\"))],\n })) },\n { key: \"v-list\", row: \"r4\", span: 6n, height: some(240n), align: variant(\"stretch\", null), title: none, content: vis.of(\"orders\", vis.list({ item: vis.group(\"customer\", { sort: \"high\" }), caption: \"region\", values: [vis.sum(\"revenue\"), vis.count()], bar: true })) },\n { key: \"v-summary\", row: \"r5\", span: 6n, height: some(300n), align: variant(\"stretch\", null), title: none, content: vis.of(\"orders\", vis.summary({\n rows: [vis.group(\"region\", { sort: \"high\" }), vis.group(\"category\")],\n values: [vis.sum(\"revenue\"), vis.ratio(\"revenue\", \"units\", { goal: 13.5 })], total: true,\n })) },\n { key: \"v-pivot\", row: \"r5\", span: 6n, height: some(300n), align: variant(\"stretch\", null), title: none, content: vis.of(\"orders\", vis.pivot({\n rows: vis.group(\"region\"), columns: vis.group(\"ordered_at\", { bucket: \"month\" }), value: vis.count(), heat: true,\n })) },\n { key: \"v-records\", row: \"r6\", span: 12n, height: some(320n), align: variant(\"stretch\", null), title: none, content: vis.of(\"orders\", vis.records({ columns: [\"ordered_at\", \"customer\", \"region\", \"revenue\", \"units\", \"margin\"], sort: \"ordered_at\", descending: true })) },\n];\n\n/**\n * Where every reader of the Visuals page starts: the latest quarter, July to\n * September 2026 — the page's window on the orders' dates, which a value over\n * another period moves.\n */\nconst latestQuarter = parseJq(`.ordered_at >= \"2026-07-01\" and .ordered_at < \"2026-10-01\"`).program;\n\nconst visualFilters = [{ key: \"f-quarter\", source: \"orders\", where: latestQuarter.value }];\n\n/** The pages of the visuals' project: one page, Visuals, live as it was drafted, its readers starting in the latest quarter. */\nexport const studioVisualPages = e3.record(\"studio_visual_pages\", Studio.Types.Pages, {\n initial: new SortedMap<Key, Entry>([\n [{ project: \"Sales desk\", page: \"Visuals\" }, variant(\"page\", {\n draft: { title: \"Visuals\", cells: visualCells, filters: visualFilters },\n live: some({ version: 1n, page: { title: \"Visuals\", cells: visualCells, filters: visualFilters } }),\n })],\n ], compareFor(Studio.Types.Key)),\n mutations: (mutation) => ({\n // The record's one write.\n patch: mutation.patch(),\n }),\n});\n\nEast.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const pages = $.let(Data.bind(studioVisualPages));\n const orders = $.let(Data.bind(studioOrders));\n return (\n <Studio.Page pages={pages.read()} components={[]} page={{ project: \"Sales desk\", page: \"Visuals\" }}\n sources={{\n orders: Studio.source(orders, {\n name: \"Orders\", icon: \"receipt\", description: \"One row per order\",\n fields: orderFields,\n range: \"ordered_at\",\n }),\n }} />\n );\n }}</Reactive>\n ))"
49329
+ },
49330
+ {
49331
+ "id": "e3-ui:studio.examples.tsx:studioChartOptions",
49332
+ "skill": "e3-ui",
49333
+ "package": "e3-ui",
49334
+ "file": "east-ui/packages/e3-ui/test/studio/studio.examples.tsx",
49335
+ "suite": "",
49336
+ "test": "The options a chart and a value take, on a published page over two years of orders: a pie whose legend names its slices alone (`legend: \"names\"`), a donut with no legend (`\"hidden\"`) — a pie's legend shows each slice's value and share unless it says otherwise — stacked columns with their legend hidden (a chart draws its legend where it names more than one series, `\"auto\"`, or never, `\"hidden\"`), and a summary whose average order and margin are each printed as its field's format says — a currency, a percentage — beside the same value as a plain number (`format: \"number\"`) — a value's `format` (`\"number\"`, `\"percent\"`, `{ currency: { code: \"AUD\" } }`) takes the place of its field's wherever its numbers are printed",
49337
+ "keywords": [
49338
+ "Studio",
49339
+ "Studio.Page",
49340
+ "Studio.visual",
49341
+ "visual",
49342
+ "chart",
49343
+ "options",
49344
+ "legend",
49345
+ "hidden",
49346
+ "names",
49347
+ "values",
49348
+ "no legend",
49349
+ "pie",
49350
+ "donut",
49351
+ "column",
49352
+ "format",
49353
+ "value format",
49354
+ "number",
49355
+ "percent",
49356
+ "currency",
49357
+ "summary",
49358
+ "Studio.source",
49359
+ "Data.bind"
49360
+ ],
49361
+ "imports": [
49362
+ "import {",
49363
+ "import {",
49364
+ "import { Data, Record, Studio } from \"@elaraai/e3-ui\";",
49365
+ "import e3 from \"@elaraai/e3\";",
49366
+ "import {"
49367
+ ],
49368
+ "languages": [
49369
+ "tsx"
49370
+ ],
49371
+ "source": "// The options a chart and a value take, on a published page over two years of orders: a pie whose legend names its slices alone (`legend: \"names\"`), a donut with no legend (`\"hidden\"`) — a pie's legend shows each slice's value and share unless it says otherwise — stacked columns with their legend hidden (a chart draws its legend where it names more than one series, `\"auto\"`, or never, `\"hidden\"`), and a summary whose average order and margin are each printed as its field's format says — a currency, a percentage — beside the same value as a plain number (`format: \"number\"`) — a value's `format` (`\"number\"`, `\"percent\"`, `{ currency: { code: \"AUD\" } }`) takes the place of its field's wherever its numbers are printed\n// inputs: []\ntype Key = ValueTypeOf<typeof Studio.Types.Key>;\n\ntype Entry = ValueTypeOf<typeof Studio.Types.Entry>;\n\n/** One order: when it was placed, its region, category and customer, its revenue and units, and its margin — none where none was recorded. */\nconst OrderType = StructType({\n ordered_at: DateTimeType, region: StringType, category: StringType, customer: StringType, revenue: FloatType, units: IntegerType, margin: OptionType(FloatType),\n});\n\n/** One part of an order, drawn from its number: the number through the part's own stride, modulo a prime — so no two parts move in step. */\nconst drawPart = East.function([IntegerType, IntegerType], IntegerType, (_$, n, stride) => n.multiply(stride).add(stride.remainder(9_973n)).remainder(1_000_003n));\n\n/**\n * A trade supplier's orders over two years, made from each order's number\n * alone — the same rows every time, varied as real ones are:\n *\n * - placed on a working day from 1 October 2024 to 30 September 2026, spread\n * a couple of days either way, so no two weeks are alike;\n * - for one of fourteen customers, each as often as it buys, each in its own\n * region — New South Wales sells the most, South Australia the least — and\n * of one of three categories: Tools the most, then Electrical, then Garden;\n * - its units following its category's season — the garden's spring, the end\n * of the financial year in June, the trades' summer break — and its prices\n * rising about a tenth a year;\n * - its margin its category's, give or take, with one order in about a\n * hundred recording none.\n */\nconst generateOrders = East.function([IntegerType], ArrayType(OrderType), ($, count) => {\n const draw = $.const(drawPart);\n // The Monday before the first working day, Tuesday 1 October 2024, and the working days from it to Wednesday 30 September 2026.\n const monday = $.const(new Date(\"2024-09-30T00:00:00Z\"), DateTimeType);\n const workdays = $.const(522n);\n // The customers, each in its region, and how often each buys: of forty orders, Harbour five, Northwind four, …\n const customers = $.const([\"Harbour\", \"Northwind\", \"Ironbark\", \"Bluewater\", \"Summit\", \"Redgum\", \"Kestrel\", \"Coastline\", \"Tallowood\", \"Saltbush\", \"Granite Peak\", \"Banksia\", \"Acme\", \"Mallee\"]);\n const regions = $.const([\"NSW\", \"NSW\", \"NSW\", \"NSW\", \"VIC\", \"VIC\", \"VIC\", \"QLD\", \"QLD\", \"QLD\", \"WA\", \"WA\", \"SA\", \"SA\"]);\n const buyers = $.const([0n, 0n, 0n, 0n, 0n, 1n, 1n, 1n, 1n, 2n, 2n, 3n, 4n, 4n, 4n, 4n, 5n, 5n, 5n, 6n, 6n, 6n, 7n, 7n, 7n, 7n, 8n, 8n, 9n, 9n, 10n, 10n, 10n, 10n, 11n, 11n, 12n, 12n, 12n, 13n]);\n // The categories, how often each sells — of twenty orders, Tools nine, Electrical seven, Garden four — a unit's price and the margin of each.\n const categories = $.const([\"Tools\", \"Electrical\", \"Garden\"]);\n const sold = $.const([0n, 0n, 0n, 0n, 0n, 0n, 0n, 0n, 0n, 1n, 1n, 1n, 1n, 1n, 1n, 1n, 2n, 2n, 2n, 2n]);\n const prices = $.const([11.8, 10.9, 8.7]);\n const margins = $.const([0.22, 0.16, 0.19]);\n // Each category's season, January to December: the trades slow over summer and busy before the financial year ends in June; the garden's spring.\n const seasons = $.const([\n [0.8, 0.95, 1.05, 1.0, 1.05, 1.3, 0.95, 1.0, 1.05, 1.05, 1.1, 0.75],\n [0.8, 0.95, 1.0, 1.0, 1.05, 1.25, 1.0, 1.0, 1.0, 1.05, 1.1, 0.8],\n [0.9, 0.85, 0.95, 0.85, 0.7, 0.6, 0.6, 0.85, 1.35, 1.45, 1.4, 1.05],\n ]);\n return East.Array.generate(count, OrderType, ($2, i) => {\n // Its working day: spread evenly over the two years, then a couple either way.\n const spread = $2.let(i.multiply(workdays).divide(count).add(draw(i, 390_383n).remainder(5n)).subtract(1n));\n const day = $2.let(spread.less(1n).ifElse(() => 1n, () => spread.greater(workdays).ifElse(() => workdays, () => spread)));\n const at = $2.let(monday.addDays(day.divide(5n).multiply(7n).add(day.remainder(5n))));\n const buyer = $2.let(buyers.get(draw(i, 479_909n).remainder(40n)));\n const category = $2.let(sold.get(draw(i, 350_377n).remainder(20n)));\n const season = $2.let(seasons.get(category).get(at.getMonth().subtract(1n)));\n const units = $2.let(East.Float.roundHalf(draw(i, 611_953n).remainder(150n).add(8n).toFloat().multiply(season)));\n // Prices about a tenth higher a year on, each order give or take eight in a hundred.\n const growth = $2.let(day.toFloat().divide(261.0).multiply(0.1).add(1.0));\n const noise = $2.let(draw(i, 104_729n).remainder(17n).toFloat().divide(100.0).add(0.92));\n const revenue = $2.let(East.Float.roundHalf(units.toFloat().multiply(prices.get(category)).multiply(noise).multiply(growth).multiply(100.0)).toFloat().divide(100.0));\n const margin = $2.let(East.Float.roundHalf(margins.get(category).add(draw(i, 746_773n).remainder(11n).subtract(5n).toFloat().divide(100.0)).multiply(100.0)).toFloat().divide(100.0));\n return {\n ordered_at: at,\n region: regions.get(buyer),\n category: categories.get(category),\n customer: customers.get(buyer),\n revenue,\n units,\n margin: draw(i, 821_641n).remainder(97n).equal(0n).ifElse(() => East.value(none, OptionType(FloatType)), () => some(margin)),\n };\n });\n});\n\n/** The supplier's orders, two years of them: each one's date, region, category, customer, revenue, units and margin. */\nexport const studioOrders = e3.input(\"studio_orders\", ArrayType(OrderType), variant(\"value\", East.compile(generateOrders, [])(2_920n)));\n\nconst vis = Studio.visual;\n\n/** The orders' fields, as every page over them lists them: each one's label, and how a number of it prints. */\nexport const orderFields = {\n ordered_at: { label: \"Ordered\" },\n region: { label: \"Region\" },\n category: { label: \"Category\" },\n customer: { label: \"Customer\" },\n revenue: { label: \"Revenue\", format: { currency: { code: \"AUD\" } } },\n units: { label: \"Units\" },\n margin: { label: \"Margin\", format: \"percent\" },\n} as const;\n\n/** The Chart options page's placements: a pie whose legend names its slices alone, a donut with no legend, stacked columns with their legend hidden, and a summary whose average order and margin are each printed as its field's format says and in a format of its own. */\nconst chartOptionCells = [\n { key: \"c-names\", row: \"r1\", span: 4n, height: some(240n), align: variant(\"stretch\", null), title: none, content: vis.of(\"orders\", vis.pie({ slice: vis.group(\"category\"), value: vis.sum(\"revenue\"), legend: \"names\" })) },\n { key: \"c-alone\", row: \"r1\", span: 4n, height: some(240n), align: variant(\"stretch\", null), title: none, content: vis.of(\"orders\", vis.pie({ slice: vis.group(\"region\"), value: vis.sum(\"revenue\"), donut: true, legend: \"hidden\" })) },\n { key: \"c-columns\", row: \"r1\", span: 4n, height: some(240n), align: variant(\"stretch\", null), title: none, content: vis.of(\"orders\", vis.column({ x: vis.group(\"ordered_at\", { bucket: \"month\" }), values: [vis.sum(\"revenue\")], split: \"region\", stack: \"stacked\", legend: \"hidden\" })) },\n { key: \"c-formats\", row: \"r2\", span: 12n, height: some(260n), align: variant(\"stretch\", null), title: none, content: vis.of(\"orders\", vis.summary({\n rows: [vis.group(\"region\", { sort: \"high\" })],\n values: [\n vis.mean(\"revenue\", { label: \"Average order\" }), vis.mean(\"revenue\", { label: \"Average order, as a number\", format: \"number\" }),\n vis.mean(\"margin\"), vis.mean(\"margin\", { label: \"Margin, as a number\", format: \"number\" }),\n ],\n })) },\n];\n\n/** The pages of the chart options' project: one page, Chart options, live as it was drafted. */\nexport const studioChartOptionPages = e3.record(\"studio_chart_option_pages\", Studio.Types.Pages, {\n initial: new SortedMap<Key, Entry>([\n [{ project: \"Sales desk\", page: \"Chart options\" }, variant(\"page\", {\n draft: { title: \"Chart options\", cells: chartOptionCells, filters: [] },\n live: some({ version: 1n, page: { title: \"Chart options\", cells: chartOptionCells, filters: [] } }),\n })],\n ], compareFor(Studio.Types.Key)),\n mutations: (mutation) => ({\n // The record's one write.\n patch: mutation.patch(),\n }),\n});\n\nEast.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const pages = $.let(Data.bind(studioChartOptionPages));\n const orders = $.let(Data.bind(studioOrders));\n return (\n <Studio.Page pages={pages.read()} components={[]} page={{ project: \"Sales desk\", page: \"Chart options\" }}\n sources={{\n orders: Studio.source(orders, {\n name: \"Orders\", icon: \"receipt\", description: \"One row per order\",\n fields: orderFields,\n }),\n }} />\n );\n }}</Reactive>\n ))"
49372
+ },
49373
+ {
49374
+ "id": "e3-ui:studio.examples.tsx:studioClicks",
49375
+ "skill": "e3-ui",
49376
+ "package": "e3-ui",
49377
+ "file": "east-ui/packages/e3-ui/test/studio/studio.examples.tsx",
49378
+ "suite": "",
49379
+ "test": "What a click on a visual does, on a published page over two years of orders: a list of customers whose click selects (a list's and a table's click, unless it says otherwise) — ⌘-click adds, Esc or a click on the selection again clears; revenue by month follows it (`follow: { leader, from, to, empty: \"all\" }`), showing every customer until one is picked, its eyebrow then saying whom; the mean margin follows it too and asks for a pick first (`empty: \"prompt\"`); a donut whose click filters the page (`click: \"filter\"`, a chart's and a KPI's unless it says otherwise) — the slice joins the page's filters as a chip over the grid, which every visual of the source reads; and the regions' bars, whose click opens the Region orders page (`click: { open: key }`) narrowed to that region: the page's `onOpen` is told its key, and the surface, which holds the open page in a State, shows it — its filter chip the reader's to clear",
49380
+ "keywords": [
49381
+ "Studio",
49382
+ "Studio.Page",
49383
+ "Studio.visual",
49384
+ "visual",
49385
+ "click",
49386
+ "select",
49387
+ "selection",
49388
+ "filter",
49389
+ "open",
49390
+ "onOpen",
49391
+ "follow",
49392
+ "follower",
49393
+ "leader",
49394
+ "linked visuals",
49395
+ "master detail",
49396
+ "drill through",
49397
+ "page filters",
49398
+ "filter chip",
49399
+ "State.bind",
49400
+ "navigate",
49401
+ "Studio.source",
49402
+ "Data.bind"
49403
+ ],
49404
+ "imports": [
49405
+ "import {",
49406
+ "import {",
49407
+ "import { Data, Record, Studio } from \"@elaraai/e3-ui\";",
49408
+ "import e3 from \"@elaraai/e3\";",
49409
+ "import {"
49410
+ ],
49411
+ "languages": [
49412
+ "tsx"
49413
+ ],
49414
+ "source": "// What a click on a visual does, on a published page over two years of orders: a list of customers whose click selects (a list's and a table's click, unless it says otherwise) — ⌘-click adds, Esc or a click on the selection again clears; revenue by month follows it (`follow: { leader, from, to, empty: \"all\" }`), showing every customer until one is picked, its eyebrow then saying whom; the mean margin follows it too and asks for a pick first (`empty: \"prompt\"`); a donut whose click filters the page (`click: \"filter\"`, a chart's and a KPI's unless it says otherwise) — the slice joins the page's filters as a chip over the grid, which every visual of the source reads; and the regions' bars, whose click opens the Region orders page (`click: { open: key }`) narrowed to that region: the page's `onOpen` is told its key, and the surface, which holds the open page in a State, shows it — its filter chip the reader's to clear\n// inputs: []\ntype Key = ValueTypeOf<typeof Studio.Types.Key>;\n\ntype Entry = ValueTypeOf<typeof Studio.Types.Entry>;\n\n/** One order: when it was placed, its region, category and customer, its revenue and units, and its margin — none where none was recorded. */\nconst OrderType = StructType({\n ordered_at: DateTimeType, region: StringType, category: StringType, customer: StringType, revenue: FloatType, units: IntegerType, margin: OptionType(FloatType),\n});\n\n/** One part of an order, drawn from its number: the number through the part's own stride, modulo a prime — so no two parts move in step. */\nconst drawPart = East.function([IntegerType, IntegerType], IntegerType, (_$, n, stride) => n.multiply(stride).add(stride.remainder(9_973n)).remainder(1_000_003n));\n\n/**\n * A trade supplier's orders over two years, made from each order's number\n * alone — the same rows every time, varied as real ones are:\n *\n * - placed on a working day from 1 October 2024 to 30 September 2026, spread\n * a couple of days either way, so no two weeks are alike;\n * - for one of fourteen customers, each as often as it buys, each in its own\n * region — New South Wales sells the most, South Australia the least — and\n * of one of three categories: Tools the most, then Electrical, then Garden;\n * - its units following its category's season — the garden's spring, the end\n * of the financial year in June, the trades' summer break — and its prices\n * rising about a tenth a year;\n * - its margin its category's, give or take, with one order in about a\n * hundred recording none.\n */\nconst generateOrders = East.function([IntegerType], ArrayType(OrderType), ($, count) => {\n const draw = $.const(drawPart);\n // The Monday before the first working day, Tuesday 1 October 2024, and the working days from it to Wednesday 30 September 2026.\n const monday = $.const(new Date(\"2024-09-30T00:00:00Z\"), DateTimeType);\n const workdays = $.const(522n);\n // The customers, each in its region, and how often each buys: of forty orders, Harbour five, Northwind four, …\n const customers = $.const([\"Harbour\", \"Northwind\", \"Ironbark\", \"Bluewater\", \"Summit\", \"Redgum\", \"Kestrel\", \"Coastline\", \"Tallowood\", \"Saltbush\", \"Granite Peak\", \"Banksia\", \"Acme\", \"Mallee\"]);\n const regions = $.const([\"NSW\", \"NSW\", \"NSW\", \"NSW\", \"VIC\", \"VIC\", \"VIC\", \"QLD\", \"QLD\", \"QLD\", \"WA\", \"WA\", \"SA\", \"SA\"]);\n const buyers = $.const([0n, 0n, 0n, 0n, 0n, 1n, 1n, 1n, 1n, 2n, 2n, 3n, 4n, 4n, 4n, 4n, 5n, 5n, 5n, 6n, 6n, 6n, 7n, 7n, 7n, 7n, 8n, 8n, 9n, 9n, 10n, 10n, 10n, 10n, 11n, 11n, 12n, 12n, 12n, 13n]);\n // The categories, how often each sells — of twenty orders, Tools nine, Electrical seven, Garden four — a unit's price and the margin of each.\n const categories = $.const([\"Tools\", \"Electrical\", \"Garden\"]);\n const sold = $.const([0n, 0n, 0n, 0n, 0n, 0n, 0n, 0n, 0n, 1n, 1n, 1n, 1n, 1n, 1n, 1n, 2n, 2n, 2n, 2n]);\n const prices = $.const([11.8, 10.9, 8.7]);\n const margins = $.const([0.22, 0.16, 0.19]);\n // Each category's season, January to December: the trades slow over summer and busy before the financial year ends in June; the garden's spring.\n const seasons = $.const([\n [0.8, 0.95, 1.05, 1.0, 1.05, 1.3, 0.95, 1.0, 1.05, 1.05, 1.1, 0.75],\n [0.8, 0.95, 1.0, 1.0, 1.05, 1.25, 1.0, 1.0, 1.0, 1.05, 1.1, 0.8],\n [0.9, 0.85, 0.95, 0.85, 0.7, 0.6, 0.6, 0.85, 1.35, 1.45, 1.4, 1.05],\n ]);\n return East.Array.generate(count, OrderType, ($2, i) => {\n // Its working day: spread evenly over the two years, then a couple either way.\n const spread = $2.let(i.multiply(workdays).divide(count).add(draw(i, 390_383n).remainder(5n)).subtract(1n));\n const day = $2.let(spread.less(1n).ifElse(() => 1n, () => spread.greater(workdays).ifElse(() => workdays, () => spread)));\n const at = $2.let(monday.addDays(day.divide(5n).multiply(7n).add(day.remainder(5n))));\n const buyer = $2.let(buyers.get(draw(i, 479_909n).remainder(40n)));\n const category = $2.let(sold.get(draw(i, 350_377n).remainder(20n)));\n const season = $2.let(seasons.get(category).get(at.getMonth().subtract(1n)));\n const units = $2.let(East.Float.roundHalf(draw(i, 611_953n).remainder(150n).add(8n).toFloat().multiply(season)));\n // Prices about a tenth higher a year on, each order give or take eight in a hundred.\n const growth = $2.let(day.toFloat().divide(261.0).multiply(0.1).add(1.0));\n const noise = $2.let(draw(i, 104_729n).remainder(17n).toFloat().divide(100.0).add(0.92));\n const revenue = $2.let(East.Float.roundHalf(units.toFloat().multiply(prices.get(category)).multiply(noise).multiply(growth).multiply(100.0)).toFloat().divide(100.0));\n const margin = $2.let(East.Float.roundHalf(margins.get(category).add(draw(i, 746_773n).remainder(11n).subtract(5n).toFloat().divide(100.0)).multiply(100.0)).toFloat().divide(100.0));\n return {\n ordered_at: at,\n region: regions.get(buyer),\n category: categories.get(category),\n customer: customers.get(buyer),\n revenue,\n units,\n margin: draw(i, 821_641n).remainder(97n).equal(0n).ifElse(() => East.value(none, OptionType(FloatType)), () => some(margin)),\n };\n });\n});\n\n/** The supplier's orders, two years of them: each one's date, region, category, customer, revenue, units and margin. */\nexport const studioOrders = e3.input(\"studio_orders\", ArrayType(OrderType), variant(\"value\", East.compile(generateOrders, [])(2_920n)));\n\nconst vis = Studio.visual;\n\n/** The orders' fields, as every page over them lists them: each one's label, and how a number of it prints. */\nexport const orderFields = {\n ordered_at: { label: \"Ordered\" },\n region: { label: \"Region\" },\n category: { label: \"Category\" },\n customer: { label: \"Customer\" },\n revenue: { label: \"Revenue\", format: { currency: { code: \"AUD\" } } },\n units: { label: \"Units\" },\n margin: { label: \"Margin\", format: \"percent\" },\n} as const;\n\n/** The customers list a click selects in: what the Customers page's other visuals follow. */\nconst followCustomers = { leader: \"k-customers\", from: \"customer\", to: \"customer\" } as const;\n\n/**\n * The Customers page's placements: a list of customers, whose click selects;\n * revenue by month, which follows it and shows every customer until one is\n * picked; the mean margin, which follows it and asks for a pick; a donut of\n * revenue by category, whose click filters the page; and the regions' bars,\n * whose click opens the Region orders page.\n */\nconst customerCells = [\n { key: \"k-customers\", row: \"r1\", span: 4n, height: some(300n), align: variant(\"stretch\", null), title: none, content: vis.of(\"orders\", vis.list({ item: vis.group(\"customer\", { sort: \"high\" }), values: [vis.sum(\"revenue\"), vis.count()], bar: true })) },\n { key: \"k-months\", row: \"r1\", span: 8n, height: some(300n), align: variant(\"stretch\", null), title: none, content: vis.of(\"orders\", vis.column({ x: vis.group(\"ordered_at\", { bucket: \"month\" }), values: [vis.sum(\"revenue\")] }), {\n follow: { ...followCustomers, empty: variant(\"all\", null) },\n }) },\n { key: \"k-margin\", row: \"r2\", span: 4n, height: some(240n), align: variant(\"stretch\", null), title: none, content: vis.of(\"orders\", vis.kpi({ value: vis.mean(\"margin\") }), {\n follow: { ...followCustomers, empty: variant(\"prompt\", null) },\n }) },\n { key: \"k-category\", row: \"r2\", span: 4n, height: some(240n), align: variant(\"stretch\", null), title: none, content: vis.of(\"orders\", vis.pie({ slice: vis.group(\"category\"), value: vis.sum(\"revenue\"), donut: true }), {\n click: variant(\"filter\", null),\n }) },\n { key: \"k-regions\", row: \"r2\", span: 4n, height: some(240n), align: variant(\"stretch\", null), title: none, content: vis.of(\"orders\", vis.bar({ x: vis.group(\"region\", { sort: \"high\" }), values: [vis.sum(\"revenue\")] }), {\n click: variant(\"open\", { project: \"Sales desk\", page: \"Region orders\" }),\n }) },\n];\n\n/** The Region orders page's placements: the orders' revenue and count, and the orders themselves — narrowed to the region whose bar opened it. */\nconst regionCells = [\n { key: \"g-revenue\", row: \"r1\", span: 6n, height: none, align: variant(\"stretch\", null), title: none, content: vis.of(\"orders\", vis.kpi({ value: vis.sum(\"revenue\") })) },\n { key: \"g-orders\", row: \"r1\", span: 6n, height: none, align: variant(\"stretch\", null), title: none, content: vis.of(\"orders\", vis.kpi({ value: vis.count() })) },\n { key: \"g-records\", row: \"r2\", span: 12n, height: some(320n), align: variant(\"stretch\", null), title: none, content: vis.of(\"orders\", vis.records({ columns: [\"ordered_at\", \"customer\", \"region\", \"category\", \"revenue\"], sort: \"ordered_at\", descending: true })) },\n];\n\n/** The pages of the clicks' project: Customers, and Region orders, each live as it was drafted. */\nexport const studioClickPages = e3.record(\"studio_click_pages\", Studio.Types.Pages, {\n initial: new SortedMap<Key, Entry>([\n [{ project: \"Sales desk\", page: \"Customers\" }, variant(\"page\", {\n draft: { title: \"Customers\", cells: customerCells, filters: [] },\n live: some({ version: 1n, page: { title: \"Customers\", cells: customerCells, filters: [] } }),\n })],\n [{ project: \"Sales desk\", page: \"Region orders\" }, variant(\"page\", {\n draft: { title: \"Region orders\", cells: regionCells, filters: [] },\n live: some({ version: 1n, page: { title: \"Region orders\", cells: regionCells, filters: [] } }),\n })],\n ], compareFor(Studio.Types.Key)),\n mutations: (mutation) => ({\n // The record's one write.\n patch: mutation.patch(),\n }),\n});\n\nEast.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const pages = $.let(Data.bind(studioClickPages));\n const orders = $.let(Data.bind(studioOrders));\n // The open page is the surface's: a click that opens a page writes it. A host with routes navigates here instead.\n const open = $.let(State.bind([Studio.Types.Key], \"ex.studio.clicks.open\", { project: \"Sales desk\", page: \"Customers\" }));\n const go = $.const(East.function([Studio.Types.Key], NullType, ($2, key) => { $2(open.write(key)); }));\n return (\n <Studio.Page pages={pages.read()} components={[]} page={open.read()} onOpen={go}\n sources={{\n orders: Studio.source(orders, {\n name: \"Orders\", icon: \"receipt\", description: \"One row per order\",\n fields: orderFields,\n range: \"ordered_at\",\n }),\n }} />\n );\n }}</Reactive>\n ))"
48850
49415
  },
48851
49416
  {
48852
49417
  "id": "e3-ui:studio.examples.tsx:studioOpsConsole",
@@ -48869,12 +49434,13 @@
48869
49434
  "import {",
48870
49435
  "import {",
48871
49436
  "import { Data, Record, Studio } from \"@elaraai/e3-ui\";",
48872
- "import e3 from \"@elaraai/e3\";"
49437
+ "import e3 from \"@elaraai/e3\";",
49438
+ "import {"
48873
49439
  ],
48874
49440
  "languages": [
48875
49441
  "tsx"
48876
49442
  ],
48877
- "source": "// A published page, for everyone else: the Overview's live version, v3, each placement its component's own UI — the page reads the record and writes nothing\n// inputs: []\ntype Key = ValueTypeOf<typeof Studio.Types.Key>;\n\ntype Entry = ValueTypeOf<typeof Studio.Types.Entry>;\n\n/** What a KPI measures: an amount of money, a count, a price or a ratio. */\nconst KpiUnit = VariantType({ money: NullType, count: NullType, price: NullType, ratio: NullType });\n\n/** The week's figures, each with its change on last week in percent — what a KPI task writes. */\nexport const studioKpis = e3.input(\"studio_kpis\", ArrayType(StructType({\n label: StringType, value: FloatType, unit: KpiUnit, change: FloatType,\n})), variant(\"value\", [\n { label: \"Revenue\", value: 1284000.0, unit: variant(\"money\", null), change: 6.4 },\n { label: \"Orders\", value: 8412.0, unit: variant(\"count\", null), change: 2.1 },\n { label: \"Avg ticket\", value: 152.0, unit: variant(\"price\", null), change: -1.3 },\n { label: \"Fill rate\", value: 0.94, unit: variant(\"ratio\", null), change: 0.0 },\n]));\n\n/** Revenue by day. */\nexport const studioRevenueDaily = e3.input(\"studio_revenue_daily\", ArrayType(StructType({ day: DateTimeType, revenue: FloatType })), variant(\"value\", [\n { day: new Date(\"2026-02-12T00:00:00Z\"), revenue: 2640000.0 },\n { day: new Date(\"2026-02-19T00:00:00Z\"), revenue: 2710000.0 },\n { day: new Date(\"2026-02-26T00:00:00Z\"), revenue: 2900000.0 },\n { day: new Date(\"2026-03-05T00:00:00Z\"), revenue: 3180000.0 },\n { day: new Date(\"2026-03-12T00:00:00Z\"), revenue: 3300000.0 },\n { day: new Date(\"2026-03-19T00:00:00Z\"), revenue: 3430000.0 },\n]));\n\n/** This week's sales, one row per region per channel. */\nexport const studioSales = e3.input(\"studio_sales\", ArrayType(StructType({ region: StringType, channel: StringType, revenue: FloatType })), variant(\"value\", [\n { region: \"North\", channel: \"Store\", revenue: 331200.0 },\n { region: \"North\", channel: \"Online\", revenue: 208080.0 },\n { region: \"South\", channel: \"Store\", revenue: 238824.0 },\n { region: \"South\", channel: \"Online\", revenue: 159216.0 },\n { region: \"West\", channel: \"Store\", revenue: 197604.0 },\n { region: \"West\", channel: \"Online\", revenue: 149076.0 },\n]));\n\n/** Orders by week. */\nexport const studioOrdersWeekly = e3.input(\"studio_orders_weekly\", ArrayType(StructType({ week: StringType, orders: FloatType })), variant(\"value\", [\n { week: \"W9\", orders: 96.0 }, { week: \"W10\", orders: 158.0 }, { week: \"W11\", orders: 214.0 },\n { week: \"W12\", orders: 271.0 }, { week: \"W13\", orders: 248.0 }, { week: \"W14\", orders: 196.0 },\n]));\n\n/** Visits by day, the last two weeks. */\nexport const studioVisitsDaily = e3.input(\"studio_visits_daily\", ArrayType(StructType({ day: DateTimeType, visits: FloatType })), variant(\"value\", [\n { day: new Date(\"2026-03-06T00:00:00Z\"), visits: 412.0 }, { day: new Date(\"2026-03-07T00:00:00Z\"), visits: 388.0 },\n { day: new Date(\"2026-03-08T00:00:00Z\"), visits: 301.0 }, { day: new Date(\"2026-03-09T00:00:00Z\"), visits: 296.0 },\n { day: new Date(\"2026-03-10T00:00:00Z\"), visits: 455.0 }, { day: new Date(\"2026-03-11T00:00:00Z\"), visits: 471.0 },\n { day: new Date(\"2026-03-12T00:00:00Z\"), visits: 468.0 }, { day: new Date(\"2026-03-13T00:00:00Z\"), visits: 502.0 },\n { day: new Date(\"2026-03-14T00:00:00Z\"), visits: 479.0 }, { day: new Date(\"2026-03-15T00:00:00Z\"), visits: 344.0 },\n { day: new Date(\"2026-03-16T00:00:00Z\"), visits: 327.0 }, { day: new Date(\"2026-03-17T00:00:00Z\"), visits: 518.0 },\n { day: new Date(\"2026-03-18T00:00:00Z\"), visits: 546.0 }, { day: new Date(\"2026-03-19T00:00:00Z\"), visits: 561.0 },\n]));\n\n/** The floor's areas, its shifts and its people. */\nexport const studioAreas = e3.input(\"studio_areas\", ArrayType(StructType({ id: StringType, name: StringType })), variant(\"value\", [\n { id: \"north\", name: \"North\" }, { id: \"south\", name: \"South\" },\n]));\n\nexport const studioShifts = e3.input(\"studio_shifts\", ArrayType(StructType({ id: StringType, name: StringType, window: StringType })), variant(\"value\", [\n { id: \"am\", name: \"AM\", window: \"06–14\" }, { id: \"pm\", name: \"PM\", window: \"14–22\" }, { id: \"night\", name: \"Night\", window: \"22–06\" },\n]));\n\nexport const studioPeople = e3.input(\"studio_people\", ArrayType(StructType({ id: StringType, name: StringType })), variant(\"value\", [\n { id: \"p1\", name: \"Ana Ruiz\" }, { id: \"p2\", name: \"Ben Cole\" }, { id: \"p3\", name: \"Cai Lin\" }, { id: \"p4\", name: \"Dev Rao\" },\n { id: \"p5\", name: \"Eli Moss\" }, { id: \"p6\", name: \"Fay Ong\" }, { id: \"p7\", name: \"Gus Hart\" }, { id: \"p8\", name: \"Hana Ito\" },\n]));\n\n/** Who works where today. */\nexport const studioAssignmentsToday = e3.input(\"studio_assignments_today\", ArrayType(StructType({\n id: StringType, person: StringType, area: StringType, shift: StringType,\n})), variant(\"value\", [\n { id: \"a1\", person: \"p1\", area: \"north\", shift: \"am\" }, { id: \"a2\", person: \"p2\", area: \"north\", shift: \"am\" },\n { id: \"a3\", person: \"p3\", area: \"north\", shift: \"pm\" }, { id: \"a4\", person: \"p4\", area: \"north\", shift: \"night\" },\n { id: \"a5\", person: \"p5\", area: \"south\", shift: \"am\" }, { id: \"a6\", person: \"p6\", area: \"south\", shift: \"pm\" },\n { id: \"a7\", person: \"p7\", area: \"south\", shift: \"pm\" }, { id: \"a8\", person: \"p8\", area: \"south\", shift: \"night\" },\n]));\n\n/** This week's rota. */\nexport const studioRotaWeek = e3.input(\"studio_rota_week\", ArrayType(StructType({\n id: StringType, person: StringType, day: StringType, hours: IntegerType,\n})), variant(\"value\", [\n { id: \"r1\", person: \"p1\", day: \"Mon\", hours: 8n }, { id: \"r2\", person: \"p1\", day: \"Tue\", hours: 8n }, { id: \"r3\", person: \"p1\", day: \"Wed\", hours: 8n },\n { id: \"r4\", person: \"p2\", day: \"Mon\", hours: 8n }, { id: \"r5\", person: \"p2\", day: \"Thu\", hours: 8n }, { id: \"r6\", person: \"p2\", day: \"Fri\", hours: 6n },\n { id: \"r7\", person: \"p3\", day: \"Tue\", hours: 8n }, { id: \"r8\", person: \"p3\", day: \"Wed\", hours: 8n }, { id: \"r9\", person: \"p3\", day: \"Thu\", hours: 8n },\n { id: \"r10\", person: \"p4\", day: \"Mon\", hours: 10n }, { id: \"r11\", person: \"p4\", day: \"Fri\", hours: 10n },\n]));\n\n/** The KPI rail's code: the week's four figures, each with its change on last week. */\nconst kpiRailUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const kpis = $.let(Data.bind(studioKpis).read());\n return (\n <Box background=\"border.subtle\"><Grid gap=\"1px\" templateColumns=\"repeat(auto-fit, minmax(min(calc(50% - 1px), 170px), 1fr))\" items={kpis.map(($2, k) => Grid.Item(\n <Box background=\"bg.surface\"\n padding={{ top: some(\"3\"), right: some(\"4\"), bottom: some(\"3\"), left: some(\"4\") }}>\n <Stat label={k.label} value={k.value}\n format={k.unit.match({\n money: (_$3) => Format.Currency({ currency: \"USD\", compact: \"short\", maximumFractionDigits: 2n }),\n count: (_$3) => Format.Number(),\n price: (_$3) => Format.Currency({ currency: \"USD\", maximumFractionDigits: 0n }),\n ratio: (_$3) => Format.Percent({ maximumFractionDigits: 0n }),\n })}\n baseline={\n <MetricChip tone={k.change.greater(0.0).ifElse(\n _$3 => variant(\"positive\", null),\n _$3 => k.change.less(0.0).ifElse(_$4 => variant(\"negative\", null), _$4 => variant(\"neutral\", null)),\n )}>\n <Text>{k.change.greater(0.0).ifElse(\n _$3 => East.str`▲ ${East.print(k.change)}%`,\n _$3 => k.change.less(0.0).ifElse(\n _$4 => East.str`▼ ${East.print(k.change.negate())}%`,\n _$4 => \"— flat\",\n ),\n )}</Text>\n </MetricChip>\n } />\n </Box>,\n ))} /></Box>\n );\n }}</Reactive>\n));\n\n/** The Revenue trend's code: revenue by day, as an area. */\nconst revenueTrendUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const days = $.let(Data.bind(studioRevenueDaily).read());\n return (\n <Box height=\"168px\" padding={{ top: some(\"4\"), right: some(\"4\"), bottom: some(\"3\"), left: some(\"3\") }}>\n <Chart height=\"fill\" grid\n layers={Chart.Area(days, { x: r => r.day, y: r => r.revenue }, { color: \"brand.solid\", fillOpacity: 0.08, curve: \"linear\" })}\n x={{ format: Chart.format.date(\"MMM D\") }}\n y={{ format: Chart.format.compact() }} />\n </Box>\n );\n }}</Reactive>\n));\n\n/** The Breakdown bars' code: each region's share of this week's revenue, largest first. */\nconst breakdownBarsUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const sales = $.let(Data.bind(studioSales).read());\n const total = $.let(sales.map(($2, r) => r.revenue).sum());\n const regions = $.let(sales\n .groupSum(($2, r) => r.region, ($2, r) => r.revenue)\n .toArray(($2, revenue, region) => ({ region, revenue })));\n return (\n <Box padding=\"4\">\n <BarStrip data={regions} sort=\"desc\" showValues={false}\n item={r => ({\n label: <Text>{r.region}</Text>,\n value: r.revenue,\n trailing: <Text>{East.str`${East.print(East.Float.roundHalf(r.revenue.divide(total).multiply(100.0)))}%`}</Text>,\n })} />\n </Box>\n );\n }}</Reactive>\n));\n\n/** The Orders by week's code: orders placed each week. */\nconst ordersByWeekUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const weeks = $.let(Data.bind(studioOrdersWeekly).read());\n return (\n <Box height=\"168px\" padding={{ top: some(\"4\"), right: some(\"4\"), bottom: some(\"3\"), left: some(\"3\") }}>\n <Chart height=\"fill\" grid layers={Chart.Column(weeks, { x: r => r.week, y: r => r.orders }, { color: \"brand.solid\" })} />\n </Box>\n );\n }}</Reactive>\n));\n\n/** The Visits sparkline's code: visits by day. */\nconst visitsSparklineUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const visits = $.let(Data.bind(studioVisitsDaily).read());\n return (\n <Box padding=\"4\">\n <Sparkline data={visits.map(($2, r) => r.visits)} type=\"area\" width=\"100%\" height=\"48px\" />\n </Box>\n );\n }}</Reactive>\n));\n\n/** Today's assignments as a read-only table using the shared collection. */\nconst assignmentBoardUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const areas = $.let(Data.bind(studioAreas).read().toDict((_$2, area) => area.id, (_$2, area) => area.name));\n const shifts = $.let(Data.bind(studioShifts).read().toDict((_$2, shift) => shift.id, (_$2, shift) => shift.name));\n const people = $.let(Data.bind(studioPeople).read().toDict((_$2, person) => person.id, (_$2, person) => person.name));\n const today = $.let(Data.bind(studioAssignmentsToday).read());\n return <Table data={today.map((_$2, row) => ({ person: people.get(row.person), area: areas.get(row.area), shift: shifts.get(row.shift) }))} columns={[\"person\", \"area\", \"shift\"]} />;\n }}</Reactive>\n));\n\n/** The week's shifts as a read-only table; editable rostering belongs to e3-ui. */\nconst shiftRosterUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const people = $.let(Data.bind(studioPeople).read().toDict((_$2, person) => person.id, (_$2, person) => person.name));\n const rota = $.let(Data.bind(studioRotaWeek).read());\n return <Table data={rota.map((_$2, row) => ({ person: people.get(row.person), day: row.day, hours: row.hours }))} columns={[\"person\", \"day\", \"hours\"]} />;\n }}</Reactive>\n));\n\nexport const kpiRail = Studio.component(\"kpi_rail\", {\n name: \"KPI rail\", category: \"Display\", icon: \"gauge-high\", frame: \"none\",\n description: \"Revenue, orders, average ticket and fill rate this week, each with its change on last week.\",\n tags: [\"kpi\", \"sales\"],\n}, kpiRailUi);\n\nexport const breakdownBars = Studio.component(\"breakdown_bars\", {\n name: \"Breakdown bars\", category: \"Display\", icon: \"chart-bar\", span: 4n,\n description: \"Each region's share of this week's revenue, largest first.\",\n tags: [\"sales\"],\n}, breakdownBarsUi);\n\nexport const revenueTrend = Studio.component(\"revenue_trend\", {\n name: \"Revenue trend\", category: \"Charts\", icon: \"chart-area\", span: 8n,\n description: \"Revenue by day, as an area.\",\n tags: [\"sales\"],\n}, revenueTrendUi);\n\nexport const ordersByWeek = Studio.component(\"orders_by_week\", {\n name: \"Orders by week\", category: \"Charts\", icon: \"chart-column\", span: 6n,\n description: \"Orders placed each week.\",\n tags: [\"orders\"],\n}, ordersByWeekUi);\n\nexport const visitsSparkline = Studio.component(\"visits_sparkline\", {\n name: \"Visits sparkline\", category: \"Charts\", icon: \"chart-line\", span: 4n,\n description: \"Visits by day, the last two weeks.\",\n tags: [\"traffic\"],\n}, visitsSparklineUi);\n\nexport const assignmentBoard = Studio.component(\"assignment_board\", {\n name: \"Assignment board\", category: \"Collections\", icon: \"border-all\", span: 12n,\n description: \"Today: who works where, by shift.\",\n collections: [\"People\"],\n}, assignmentBoardUi);\n\nexport const shiftRoster = Studio.component(\"shift_roster\", {\n name: \"Shift roster\", category: \"Collections\", icon: \"calendar-week\", span: 12n,\n description: \"This week: people, days and their assigned hours.\",\n collections: [\"People\"],\n}, shiftRosterUi);\n\n/**\n * The pages record: the Ops console's pages — the Overview live as v3, its\n * draft resizing the trend and adding the bars beside it — and its templates,\n * and the other projects' pages.\n */\nexport const studioPages = e3.record(\"studio_pages\", Studio.Types.Pages, {\n initial: new SortedMap<Key, Entry>([\n [{ project: \"Ops console\", page: \"Account detail\" }, variant(\"page\", {\n draft: {\n title: \"Account detail\",\n cells: [\n { key: \"a-kpi\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, component: \"kpi_rail\" },\n { key: \"a-orders\", row: \"r2\", span: 8n, height: some(240n), align: variant(\"top\", null), title: none, component: \"orders_by_week\" },\n { key: \"a-bars\", row: \"r2\", span: 4n, height: some(240n), align: variant(\"stretch\", null), title: none, component: \"breakdown_bars\" },\n { key: \"a-trend\", row: \"r3\", span: 12n, height: some(200n), align: variant(\"top\", null), title: none, component: \"revenue_trend\" },\n ],\n },\n live: none,\n })],\n [{ project: \"Ops console\", page: \"Overview\" }, variant(\"page\", {\n draft: {\n title: \"Overview\",\n cells: [\n { key: \"o-kpi\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, component: \"kpi_rail\" },\n { key: \"o-trend\", row: \"r2\", span: 8n, height: none, align: variant(\"stretch\", null), title: none, component: \"revenue_trend\" },\n { key: \"o-bars\", row: \"r2\", span: 4n, height: none, align: variant(\"stretch\", null), title: none, component: \"breakdown_bars\" },\n { key: \"o-board\", row: \"r3\", span: 12n, height: none, align: variant(\"top\", null), title: none, component: \"assignment_board\" },\n ],\n },\n live: some({\n version: 3n,\n page: {\n title: \"Overview\",\n cells: [\n { key: \"o-kpi\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, component: \"kpi_rail\" },\n { key: \"o-trend\", row: \"r2\", span: 12n, height: none, align: variant(\"stretch\", null), title: none, component: \"revenue_trend\" },\n { key: \"o-board\", row: \"r3\", span: 12n, height: none, align: variant(\"top\", null), title: none, component: \"assignment_board\" },\n ],\n },\n }),\n })],\n [{ project: \"Ops console\", page: \"Regional rollup\" }, variant(\"page\", {\n draft: {\n title: \"Regional rollup\",\n cells: [\n { key: \"r-trend\", row: \"r1\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, component: \"revenue_trend\" },\n { key: \"r-bars\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: some(\"By region\"), component: \"breakdown_bars\" },\n { key: \"r-visits\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: none, component: \"visits_sparkline\" },\n ],\n },\n live: some({\n version: 1n,\n page: {\n title: \"Regional rollup\",\n cells: [\n { key: \"r-trend\", row: \"r1\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, component: \"revenue_trend\" },\n { key: \"r-bars\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: some(\"By region\"), component: \"breakdown_bars\" },\n { key: \"r-visits\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: none, component: \"visits_sparkline\" },\n ],\n },\n }),\n })],\n [{ project: \"Ops console\", page: \"Weekly export\" }, variant(\"page\", {\n draft: {\n title: \"Weekly export\",\n cells: [\n { key: \"w-orders\", row: \"r1\", span: 12n, height: some(320n), align: variant(\"top\", null), title: none, component: \"orders_by_week\" },\n { key: \"w-roster\", row: \"r2\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, component: \"shift_roster\" },\n ],\n },\n live: some({ version: 2n, page: { title: \"Weekly export\", cells: [] } }),\n })],\n [{ project: \"Ops console\", page: \"Ops board\" }, variant(\"template\", {\n title: \"Ops board\",\n cells: [\n { key: \"t-orders\", row: \"r1\", span: 8n, height: some(320n), align: variant(\"top\", null), title: none, component: \"orders_by_week\" },\n { key: \"t-bars\", row: \"r1\", span: 4n, height: some(320n), align: variant(\"stretch\", null), title: none, component: \"breakdown_bars\" },\n ],\n })],\n [{ project: \"Ops console\", page: \"Report brief\" }, variant(\"template\", {\n title: \"Report brief\",\n cells: [\n { key: \"t-trend\", row: \"r1\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, component: \"revenue_trend\" },\n { key: \"t-orders\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: none, component: \"orders_by_week\" },\n { key: \"t-visits\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: none, component: \"visits_sparkline\" },\n ],\n })],\n [{ project: \"Ops console\", page: \"Summary\" }, variant(\"template\", {\n title: \"Summary\",\n cells: [\n { key: \"t-kpi\", row: \"r1\", span: 12n, height: some(96n), align: variant(\"top\", null), title: none, component: \"kpi_rail\" },\n { key: \"t-trend\", row: \"r2\", span: 8n, height: some(240n), align: variant(\"top\", null), title: none, component: \"revenue_trend\" },\n { key: \"t-bars\", row: \"r2\", span: 4n, height: some(240n), align: variant(\"stretch\", null), title: none, component: \"breakdown_bars\" },\n ],\n })],\n [{ project: \"Finance portal\", page: \"Ledger\" }, variant(\"page\", {\n draft: {\n title: \"Ledger\",\n cells: [\n { key: \"l-trend\", row: \"r1\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, component: \"revenue_trend\" },\n ],\n },\n live: none,\n })],\n [{ project: \"HR roster\", page: \"Rota\" }, variant(\"page\", {\n draft: {\n title: \"Rota\",\n cells: [\n { key: \"h-roster\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, component: \"shift_roster\" },\n ],\n },\n live: some({\n version: 1n,\n page: {\n title: \"Rota\",\n cells: [\n { key: \"h-roster\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, component: \"shift_roster\" },\n ],\n },\n }),\n })],\n ], compareFor(Studio.Types.Key)),\n mutations: (mutation) => ({\n // The record's one write.\n patch: mutation.patch(),\n }),\n});\n\nEast.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const components = $.let([kpiRail, breakdownBars, revenueTrend, ordersByWeek, visitsSparkline, assignmentBoard, shiftRoster]);\n const pages = $.let(Data.bind(studioPages));\n return <Studio.Page pages={pages.read()} components={components} page={{ project: \"Ops console\", page: \"Overview\" }} />;\n }}</Reactive>\n ))"
49443
+ "source": "// A published page, for everyone else: the Overview's live version, v3, each placement its component's own UI — the page reads the record and writes nothing\n// inputs: []\ntype Key = ValueTypeOf<typeof Studio.Types.Key>;\n\ntype Entry = ValueTypeOf<typeof Studio.Types.Entry>;\n\n/**\n * The KPI rail's code: the week's four figures, each with its change on last week — four abreast where four of\n * 170px fit, else two and two, else one above another, so no row stands short beside an empty cell.\n */\nconst kpiRailUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const kpis = $.let(Data.bind(studioKpis).read());\n return (\n <Box background=\"border.subtle\"><Grid gap=\"1px\" templateColumns=\"repeat(auto-fit, minmax(max(calc(25% - 1px), min(calc(50% - 1px), calc((683px - 100%) * 999)), min(100%, calc((341px - 100%) * 999))), 1fr))\" items={kpis.map(($2, k) => Grid.Item(\n <Box background=\"bg.surface\"\n padding={{ top: some(\"3\"), right: some(\"4\"), bottom: some(\"3\"), left: some(\"4\") }}>\n <Stat label={k.label} value={k.value}\n format={k.unit.match({\n money: (_$3) => Format.Currency({ currency: \"USD\", compact: \"short\", maximumFractionDigits: 2n }),\n count: (_$3) => Format.Number(),\n price: (_$3) => Format.Currency({ currency: \"USD\", maximumFractionDigits: 0n }),\n ratio: (_$3) => Format.Percent({ maximumFractionDigits: 0n }),\n })}\n baseline={\n <MetricChip tone={k.change.greater(0.0).ifElse(\n _$3 => variant(\"positive\", null),\n _$3 => k.change.less(0.0).ifElse(_$4 => variant(\"negative\", null), _$4 => variant(\"neutral\", null)),\n )}>\n <Text>{k.change.greater(0.0).ifElse(\n _$3 => East.str`▲ ${East.print(k.change)}%`,\n _$3 => k.change.less(0.0).ifElse(\n _$4 => East.str`▼ ${East.print(k.change.negate())}%`,\n _$4 => \"— flat\",\n ),\n )}</Text>\n </MetricChip>\n } />\n </Box>,\n ))} /></Box>\n );\n }}</Reactive>\n));\n\n/** The Revenue trend's code: revenue by day, as an area. */\nconst revenueTrendUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const days = $.let(Data.bind(studioRevenueDaily).read());\n return (\n <Box height=\"168px\" padding={{ top: some(\"4\"), right: some(\"4\"), bottom: some(\"3\"), left: some(\"3\") }}>\n <Chart height=\"fill\" grid\n layers={Chart.Area(days, { x: r => r.day, y: r => r.revenue }, { color: \"brand.solid\", fillOpacity: 0.08, curve: \"linear\" })}\n x={{ format: Chart.format.date(\"MMM D\") }}\n y={{ format: Chart.format.compact() }} />\n </Box>\n );\n }}</Reactive>\n));\n\n/** The Breakdown bars' code: each region's share of this week's revenue, largest first. */\nconst breakdownBarsUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const sales = $.let(Data.bind(studioSales).read());\n const total = $.let(sales.map(($2, r) => r.revenue).sum());\n const regions = $.let(sales\n .groupSum(($2, r) => r.region, ($2, r) => r.revenue)\n .toArray(($2, revenue, region) => ({ region, revenue })));\n return (\n <Box padding=\"4\">\n <BarStrip data={regions} sort=\"desc\" showValues={false}\n item={r => ({\n label: <Text>{r.region}</Text>,\n value: r.revenue,\n trailing: <Text>{East.str`${East.print(East.Float.roundHalf(r.revenue.divide(total).multiply(100.0)))}%`}</Text>,\n })} />\n </Box>\n );\n }}</Reactive>\n));\n\n/** The Orders by week's code: orders placed each week. */\nconst ordersByWeekUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const weeks = $.let(Data.bind(studioOrdersWeekly).read());\n return (\n <Box height=\"168px\" padding={{ top: some(\"4\"), right: some(\"4\"), bottom: some(\"3\"), left: some(\"3\") }}>\n <Chart height=\"fill\" grid layers={Chart.Column(weeks, { x: r => r.week, y: r => r.orders }, { color: \"brand.solid\" })} />\n </Box>\n );\n }}</Reactive>\n));\n\n/** The Visits sparkline's code: visits by day. */\nconst visitsSparklineUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const visits = $.let(Data.bind(studioVisitsDaily).read());\n return (\n <Box padding=\"4\">\n <Sparkline data={visits.map(($2, r) => r.visits)} type=\"area\" width=\"100%\" height=\"48px\" />\n </Box>\n );\n }}</Reactive>\n));\n\n/** Today's assignments as a read-only table using the shared collection. */\nconst assignmentBoardUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const areas = $.let(Data.bind(studioAreas).read().toDict((_$2, area) => area.id, (_$2, area) => area.name));\n const shifts = $.let(Data.bind(studioShifts).read().toDict((_$2, shift) => shift.id, (_$2, shift) => shift.name));\n const people = $.let(Data.bind(studioPeople).read().toDict((_$2, person) => person.id, (_$2, person) => person.name));\n const today = $.let(Data.bind(studioAssignmentsToday).read());\n return <Table data={today.map((_$2, row) => ({ person: people.get(row.person), area: areas.get(row.area), shift: shifts.get(row.shift) }))} columns={[\"person\", \"area\", \"shift\"]} />;\n }}</Reactive>\n));\n\n/** The week's shifts as a read-only table; editable rostering belongs to e3-ui. */\nconst shiftRosterUi = East.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const people = $.let(Data.bind(studioPeople).read().toDict((_$2, person) => person.id, (_$2, person) => person.name));\n const rota = $.let(Data.bind(studioRotaWeek).read());\n return <Table data={rota.map((_$2, row) => ({ person: people.get(row.person), day: row.day, hours: row.hours }))} columns={[\"person\", \"day\", \"hours\"]} />;\n }}</Reactive>\n));\n\nexport const kpiRail = Studio.component(\"kpi_rail\", {\n name: \"KPI rail\", category: \"Display\", icon: \"gauge-high\", frame: \"none\",\n description: \"Revenue, orders, average ticket and fill rate this week, each with its change on last week.\",\n tags: [\"kpi\", \"sales\"],\n}, kpiRailUi);\n\nexport const breakdownBars = Studio.component(\"breakdown_bars\", {\n name: \"Breakdown bars\", category: \"Display\", icon: \"chart-bar\", span: 4n,\n description: \"Each region's share of this week's revenue, largest first.\",\n tags: [\"sales\"],\n}, breakdownBarsUi);\n\nexport const revenueTrend = Studio.component(\"revenue_trend\", {\n name: \"Revenue trend\", category: \"Charts\", icon: \"chart-area\", span: 8n,\n description: \"Revenue by day, as an area.\",\n tags: [\"sales\"],\n}, revenueTrendUi);\n\nexport const ordersByWeek = Studio.component(\"orders_by_week\", {\n name: \"Orders by week\", category: \"Charts\", icon: \"chart-column\", span: 6n,\n description: \"Orders placed each week.\",\n tags: [\"orders\"],\n}, ordersByWeekUi);\n\nexport const visitsSparkline = Studio.component(\"visits_sparkline\", {\n name: \"Visits sparkline\", category: \"Charts\", icon: \"chart-line\", span: 4n,\n description: \"Visits by day, the last two weeks.\",\n tags: [\"traffic\"],\n}, visitsSparklineUi);\n\nexport const assignmentBoard = Studio.component(\"assignment_board\", {\n name: \"Assignment board\", category: \"Collections\", icon: \"border-all\", span: 12n,\n description: \"Today: who works where, by shift.\",\n collections: [\"People\"],\n}, assignmentBoardUi);\n\nexport const shiftRoster = Studio.component(\"shift_roster\", {\n name: \"Shift roster\", category: \"Collections\", icon: \"calendar-week\", span: 12n,\n description: \"This week: people, days and their assigned hours.\",\n collections: [\"People\"],\n}, shiftRosterUi);\n\n/**\n * The pages record: the Ops console's pages — the Overview live as v3, its\n * draft resizing the trend and adding the bars beside it — and its templates,\n * and the other projects' pages.\n */\nexport const studioPages = e3.record(\"studio_pages\", Studio.Types.Pages, {\n initial: new SortedMap<Key, Entry>([\n [{ project: \"Ops console\", page: \"Account detail\" }, variant(\"page\", {\n draft: {\n title: \"Account detail\",\n cells: [\n { key: \"a-kpi\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"kpi_rail\") },\n { key: \"a-orders\", row: \"r2\", span: 8n, height: some(240n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"orders_by_week\") },\n { key: \"a-bars\", row: \"r2\", span: 4n, height: some(240n), align: variant(\"stretch\", null), title: none, content: variant(\"component\", \"breakdown_bars\") },\n { key: \"a-trend\", row: \"r3\", span: 12n, height: some(200n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n ],\n filters: [],\n },\n live: none,\n })],\n [{ project: \"Ops console\", page: \"Overview\" }, variant(\"page\", {\n draft: {\n title: \"Overview\",\n cells: [\n { key: \"o-kpi\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"kpi_rail\") },\n { key: \"o-trend\", row: \"r2\", span: 8n, height: none, align: variant(\"stretch\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n { key: \"o-bars\", row: \"r2\", span: 4n, height: none, align: variant(\"stretch\", null), title: none, content: variant(\"component\", \"breakdown_bars\") },\n { key: \"o-board\", row: \"r3\", span: 12n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"assignment_board\") },\n ],\n filters: [],\n },\n live: some({\n version: 3n,\n page: {\n title: \"Overview\",\n cells: [\n { key: \"o-kpi\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"kpi_rail\") },\n { key: \"o-trend\", row: \"r2\", span: 12n, height: none, align: variant(\"stretch\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n { key: \"o-board\", row: \"r3\", span: 12n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"assignment_board\") },\n ],\n filters: [],\n },\n }),\n })],\n [{ project: \"Ops console\", page: \"Regional rollup\" }, variant(\"page\", {\n draft: {\n title: \"Regional rollup\",\n cells: [\n { key: \"r-trend\", row: \"r1\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n { key: \"r-bars\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: some(\"By region\"), content: variant(\"component\", \"breakdown_bars\") },\n { key: \"r-visits\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"visits_sparkline\") },\n ],\n filters: [],\n },\n live: some({\n version: 1n,\n page: {\n title: \"Regional rollup\",\n cells: [\n { key: \"r-trend\", row: \"r1\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n { key: \"r-bars\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: some(\"By region\"), content: variant(\"component\", \"breakdown_bars\") },\n { key: \"r-visits\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"visits_sparkline\") },\n ],\n filters: [],\n },\n }),\n })],\n [{ project: \"Ops console\", page: \"Weekly export\" }, variant(\"page\", {\n draft: {\n title: \"Weekly export\",\n cells: [\n { key: \"w-orders\", row: \"r1\", span: 12n, height: some(320n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"orders_by_week\") },\n { key: \"w-roster\", row: \"r2\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"shift_roster\") },\n ],\n filters: [],\n },\n live: some({ version: 2n, page: { title: \"Weekly export\", cells: [], filters: [] } }),\n })],\n [{ project: \"Ops console\", page: \"Ops board\" }, variant(\"template\", {\n title: \"Ops board\",\n cells: [\n { key: \"t-orders\", row: \"r1\", span: 8n, height: some(320n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"orders_by_week\") },\n { key: \"t-bars\", row: \"r1\", span: 4n, height: some(320n), align: variant(\"stretch\", null), title: none, content: variant(\"component\", \"breakdown_bars\") },\n ],\n filters: [],\n })],\n [{ project: \"Ops console\", page: \"Report brief\" }, variant(\"template\", {\n title: \"Report brief\",\n cells: [\n { key: \"t-trend\", row: \"r1\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n { key: \"t-orders\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"orders_by_week\") },\n { key: \"t-visits\", row: \"r2\", span: 6n, height: some(200n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"visits_sparkline\") },\n ],\n filters: [],\n })],\n [{ project: \"Ops console\", page: \"Summary\" }, variant(\"template\", {\n title: \"Summary\",\n cells: [\n { key: \"t-kpi\", row: \"r1\", span: 12n, height: some(96n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"kpi_rail\") },\n { key: \"t-trend\", row: \"r2\", span: 8n, height: some(240n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n { key: \"t-bars\", row: \"r2\", span: 4n, height: some(240n), align: variant(\"stretch\", null), title: none, content: variant(\"component\", \"breakdown_bars\") },\n ],\n filters: [],\n })],\n [{ project: \"Finance portal\", page: \"Ledger\" }, variant(\"page\", {\n draft: {\n title: \"Ledger\",\n cells: [\n { key: \"l-trend\", row: \"r1\", span: 12n, height: some(240n), align: variant(\"top\", null), title: none, content: variant(\"component\", \"revenue_trend\") },\n ],\n filters: [],\n },\n live: none,\n })],\n [{ project: \"HR roster\", page: \"Rota\" }, variant(\"page\", {\n draft: {\n title: \"Rota\",\n cells: [\n { key: \"h-roster\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"shift_roster\") },\n ],\n filters: [],\n },\n live: some({\n version: 1n,\n page: {\n title: \"Rota\",\n cells: [\n { key: \"h-roster\", row: \"r1\", span: 12n, height: none, align: variant(\"top\", null), title: none, content: variant(\"component\", \"shift_roster\") },\n ],\n filters: [],\n },\n }),\n })],\n ], compareFor(Studio.Types.Key)),\n mutations: (mutation) => ({\n // The record's one write.\n patch: mutation.patch(),\n }),\n});\n\nEast.function([], UIComponentType, (_$) => (\n <Reactive>{$ => {\n const components = $.let([kpiRail, breakdownBars, revenueTrend, ordersByWeek, visitsSparkline, assignmentBoard, shiftRoster]);\n const pages = $.let(Data.bind(studioPages));\n return <Studio.Page pages={pages.read()} components={components} page={{ project: \"Ops console\", page: \"Overview\" }} />;\n }}</Reactive>\n ))"
48878
49444
  },
48879
49445
  {
48880
49446
  "id": "e3:records.examples.ts:recordMutations",