@malloy-publisher/sdk 0.9.11 → 0.9.13

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 (74) hide show
  1. package/README.md +5 -7
  2. package/dist/{RenderedResult-Cmx8sX8d.es.js → RenderedResult-DnBtf-cI.es.js} +2 -2
  3. package/dist/{RenderedResult-BlNoIiSi.cjs.js → RenderedResult-DtQtNV0d.cjs.js} +1 -1
  4. package/dist/ServerProvider-BIFPCzTD.cjs.js +1 -0
  5. package/dist/{ServerProvider-azXLkk1q.es.js → ServerProvider-BV7IoDMR.es.js} +808 -607
  6. package/dist/builder/index.cjs.js +72 -72
  7. package/dist/builder/index.es.js +4156 -4219
  8. package/dist/builder-entry.d.ts +1 -0
  9. package/dist/client/api.d.ts +224 -1
  10. package/dist/client/index.cjs.js +1 -1
  11. package/dist/client/index.es.js +41 -37
  12. package/dist/components/Connections/common.d.ts +11 -3
  13. package/dist/components/Report/telemetry.d.ts +0 -5
  14. package/dist/components/ReportBuilder/BuilderBar.d.ts +1 -1
  15. package/dist/components/ReportBuilder/BuilderToolbar.d.ts +14 -10
  16. package/dist/components/ReportBuilder/EditorSurface.d.ts +1 -2
  17. package/dist/components/ReportBuilder/ReportBuilder.d.ts +3 -10
  18. package/dist/components/ReportBuilder/ReportEditor.d.ts +2 -9
  19. package/dist/components/ReportBuilder/SaveStatus.d.ts +16 -0
  20. package/dist/components/ReportBuilder/TileFrame.d.ts +9 -2
  21. package/dist/components/ReportBuilder/builderControls.d.ts +14 -6
  22. package/dist/components/ReportBuilder/useBuilderSession.d.ts +1 -1
  23. package/dist/components/ReportBuilder/useReportDraft.d.ts +6 -2
  24. package/dist/components/given/GivenInput.d.ts +18 -1
  25. package/dist/components/given/GivensPanel.d.ts +12 -1
  26. package/dist/components/given/useOptionSearch.d.ts +30 -0
  27. package/dist/hooks/index.d.ts +1 -1
  28. package/dist/hooks/useDocumentControls.d.ts +5 -0
  29. package/dist/hooks/useGivensState.d.ts +7 -0
  30. package/dist/hooks/useSuggestOptions.d.ts +60 -4
  31. package/dist/index.cjs.js +9 -9
  32. package/dist/index.es.js +2541 -2400
  33. package/dist/{useCompiledDocument-7j5cBjQd.es.js → useCompiledDocument-B4QF1mIl.es.js} +6912 -6759
  34. package/dist/useCompiledDocument-D0OAMejE.cjs.js +142 -0
  35. package/package.json +1 -1
  36. package/src/builder-entry.ts +1 -0
  37. package/src/components/Connections/AddConnectionDialog.tsx +34 -2
  38. package/src/components/Connections/EditConnectionDialog.tsx +45 -3
  39. package/src/components/Connections/common.spec.ts +69 -0
  40. package/src/components/Connections/common.ts +132 -0
  41. package/src/components/Environment/Connections.tsx +1 -0
  42. package/src/components/Report/ReportPage.tsx +5 -1
  43. package/src/components/Report/telemetry.ts +0 -6
  44. package/src/components/ReportBuilder/AddTileDialog.tsx +2 -2
  45. package/src/components/ReportBuilder/BuilderBar.tsx +5 -256
  46. package/src/components/ReportBuilder/BuilderHeader.tsx +9 -3
  47. package/src/components/ReportBuilder/BuilderToolbar.tsx +15 -38
  48. package/src/components/ReportBuilder/EditorSurface.tsx +0 -3
  49. package/src/components/ReportBuilder/FilterDialog.tsx +1 -1
  50. package/src/components/ReportBuilder/ReportBuilder.controls.spec.tsx +210 -24
  51. package/src/components/ReportBuilder/ReportBuilder.tsx +43 -85
  52. package/src/components/ReportBuilder/ReportEditor.package.spec.tsx +0 -36
  53. package/src/components/ReportBuilder/ReportEditor.tsx +2 -13
  54. package/src/components/ReportBuilder/SaveStatus.tsx +271 -0
  55. package/src/components/ReportBuilder/TileFrame.spec.ts +34 -0
  56. package/src/components/ReportBuilder/TileFrame.tsx +10 -3
  57. package/src/components/ReportBuilder/builderControls.ts +39 -13
  58. package/src/components/ReportBuilder/emptyStart.spec.ts +1 -1
  59. package/src/components/ReportBuilder/useReportDraft.ts +38 -4
  60. package/src/components/given/GivenInput.tsx +219 -104
  61. package/src/components/given/GivensPanel.spec.tsx +19 -0
  62. package/src/components/given/GivensPanel.tsx +31 -1
  63. package/src/components/given/useOptionSearch.spec.tsx +218 -0
  64. package/src/components/given/useOptionSearch.ts +100 -0
  65. package/src/hooks/index.ts +5 -1
  66. package/src/hooks/useDocumentControls.ts +12 -1
  67. package/src/hooks/useGivensState.spec.ts +54 -0
  68. package/src/hooks/useGivensState.ts +21 -1
  69. package/src/hooks/useSuggestOptions.dom.spec.ts +125 -4
  70. package/src/hooks/useSuggestOptions.spec.ts +73 -2
  71. package/src/hooks/useSuggestOptions.ts +234 -62
  72. package/dist/ServerProvider-BOgiW8MX.cjs.js +0 -1
  73. package/dist/useCompiledDocument-B21sVbb4.cjs.js +0 -141
  74. package/src/components/ReportBuilder/ReportBuilder.layoutSwitch.spec.tsx +0 -145
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@malloy-publisher/sdk",
3
3
  "description": "Malloy Publisher SDK",
4
- "version": "0.9.11",
4
+ "version": "0.9.13",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs.js",
7
7
  "module": "dist/index.es.js",
@@ -31,6 +31,7 @@ export type {
31
31
  BuilderControls,
32
32
  BuilderControlsHandler,
33
33
  } from "./components/ReportBuilder/builderControls";
34
+ export type { RestoredDraft } from "./components/ReportBuilder/useReportDraft";
34
35
  export type {
35
36
  BuilderGiven,
36
37
  ReportBuilderProps,
@@ -25,6 +25,7 @@ import {
25
25
  attachedDatabaseConnectionFieldName,
26
26
  attributesFieldName,
27
27
  connectionFieldsByType,
28
+ typedConnectionConfig,
28
29
  gcsAttachedDatabaseFields,
29
30
  getAttachedDatabaseFields,
30
31
  s3AttachedDatabaseFields,
@@ -345,6 +346,22 @@ export default function AddConnectionDialog({
345
346
  );
346
347
  }
347
348
  }
349
+ } else if (type === "sqlserver") {
350
+ const requiredFields = ["server", "database", "user", "password"];
351
+ // A named instance is located through SQL Browser and the port is
352
+ // then not used; otherwise the driver needs one.
353
+ if (!connectionConfig.instanceName && !connectionConfig.port) {
354
+ throw new Error(
355
+ "Port is required unless an instance name is given",
356
+ );
357
+ }
358
+ for (const fieldName of requiredFields) {
359
+ if (!connectionConfig[fieldName]) {
360
+ throw new Error(
361
+ `${fields.find((f) => f.name === fieldName)?.label || fieldName} is required`,
362
+ );
363
+ }
364
+ }
348
365
  } else if (type === "motherduck") {
349
366
  if (!connectionConfig.accessToken) {
350
367
  throw new Error("Access Token is required");
@@ -369,7 +386,10 @@ export default function AddConnectionDialog({
369
386
  connectionPayload = {
370
387
  name,
371
388
  type,
372
- [attributesFieldName[type]]: connectionConfig,
389
+ [attributesFieldName[type]]: typedConnectionConfig(
390
+ type,
391
+ connectionConfig,
392
+ ),
373
393
  } satisfies Connection;
374
394
  }
375
395
 
@@ -814,7 +834,19 @@ export default function AddConnectionDialog({
814
834
  fullWidth
815
835
  size="small"
816
836
  required={field.required}
817
- />
837
+ select={!!field.selectOptions}
838
+ defaultValue={
839
+ field.selectOptions
840
+ ? field.selectOptions[0]?.value
841
+ : undefined
842
+ }
843
+ >
844
+ {field.selectOptions?.map((option) => (
845
+ <MenuItem key={option.value} value={option.value}>
846
+ {option.label}
847
+ </MenuItem>
848
+ ))}
849
+ </TextField>
818
850
  ))
819
851
  )}
820
852
  </Stack>
@@ -26,6 +26,7 @@ import {
26
26
  attachedDatabaseConnectionFieldName,
27
27
  attributesFieldName,
28
28
  connectionFieldsByType,
29
+ typedConnectionConfig,
29
30
  gcsAttachedDatabaseFields,
30
31
  getAttachedDatabaseFields,
31
32
  s3AttachedDatabaseFields,
@@ -429,6 +430,22 @@ export default function EditConnectionDialog({
429
430
  );
430
431
  }
431
432
  }
433
+ } else if (type === "sqlserver") {
434
+ const requiredFields = ["server", "database", "user"];
435
+ // A named instance is located through SQL Browser and the port is
436
+ // then not used; otherwise the driver needs one.
437
+ if (!connectionConfig.instanceName && !connectionConfig.port) {
438
+ throw new Error(
439
+ "Port is required unless an instance name is given",
440
+ );
441
+ }
442
+ for (const fieldName of requiredFields) {
443
+ if (!connectionConfig[fieldName]) {
444
+ throw new Error(
445
+ `${fields.find((f) => f.name === fieldName)?.label || fieldName} is required`,
446
+ );
447
+ }
448
+ }
432
449
  } else if (type === "databricks") {
433
450
  if (!connectionConfig.host) {
434
451
  throw new Error("Host is required");
@@ -441,7 +458,10 @@ export default function EditConnectionDialog({
441
458
  connectionPayload = {
442
459
  name,
443
460
  type,
444
- [attributesFieldName[type]]: connectionConfig,
461
+ [attributesFieldName[type]]: typedConnectionConfig(
462
+ type,
463
+ connectionConfig,
464
+ ),
445
465
  } satisfies Connection;
446
466
  }
447
467
 
@@ -987,6 +1007,14 @@ export default function EditConnectionDialog({
987
1007
  const isStored = withheldFields.has(
988
1008
  `${attributesFieldName[type] ?? ""}.${field.name}`,
989
1009
  );
1010
+ // A select shows the stored value as the option it
1011
+ // names (a boolean reads back as `true`/`false`), and
1012
+ // the first option when nothing is stored.
1013
+ const selectValue = field.selectOptions
1014
+ ? existingValue === "" || existingValue === undefined
1015
+ ? field.selectOptions[0]?.value
1016
+ : String(existingValue)
1017
+ : undefined;
990
1018
  return (
991
1019
  <TextField
992
1020
  key={field.name}
@@ -1001,7 +1029,12 @@ export default function EditConnectionDialog({
1001
1029
  !isPasswordField &&
1002
1030
  !existingValue
1003
1031
  }
1004
- defaultValue={existingValue}
1032
+ select={!!field.selectOptions}
1033
+ defaultValue={
1034
+ field.selectOptions
1035
+ ? selectValue
1036
+ : existingValue
1037
+ }
1005
1038
  placeholder={
1006
1039
  isStored
1007
1040
  ? "Leave empty to keep existing"
@@ -1014,7 +1047,16 @@ export default function EditConnectionDialog({
1014
1047
  : "No value stored."
1015
1048
  : undefined
1016
1049
  }
1017
- />
1050
+ >
1051
+ {field.selectOptions?.map((option) => (
1052
+ <MenuItem
1053
+ key={option.value}
1054
+ value={option.value}
1055
+ >
1056
+ {option.label}
1057
+ </MenuItem>
1058
+ ))}
1059
+ </TextField>
1018
1060
  );
1019
1061
  })
1020
1062
  )}
@@ -0,0 +1,69 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { describe, expect, it } from "bun:test";
5
+ import { typedConnectionConfig } from "./common";
6
+
7
+ describe("typedConnectionConfig", () => {
8
+ it("sends a SQL Server port as an integer and its TLS switches as booleans", () => {
9
+ // FormData yields strings; the connector reads port as a number and
10
+ // encrypt/trustServerCertificate as booleans, and drops a string.
11
+ expect(
12
+ typedConnectionConfig("sqlserver", {
13
+ server: "db.example",
14
+ port: "1433",
15
+ encrypt: "true",
16
+ trustServerCertificate: "false",
17
+ instanceName: "SQLEXPRESS",
18
+ }),
19
+ ).toEqual({
20
+ server: "db.example",
21
+ port: 1433,
22
+ encrypt: true,
23
+ trustServerCertificate: false,
24
+ instanceName: "SQLEXPRESS",
25
+ });
26
+ });
27
+
28
+ it("leaves out a blank optional name rather than storing an empty one", () => {
29
+ // The edit form submits "" for an untouched optional field; stored, the
30
+ // connector would read a defined instanceName and drop the port.
31
+ expect(
32
+ typedConnectionConfig("sqlserver", {
33
+ server: "db.example",
34
+ port: "1434",
35
+ hostNameInCertificate: "",
36
+ instanceName: "",
37
+ }),
38
+ ).toEqual({ server: "db.example", port: 1434 });
39
+ });
40
+
41
+ it("leaves out a blank port rather than sending 0", () => {
42
+ // A named instance needs no port; Number("") would send 0.
43
+ expect(
44
+ typedConnectionConfig("sqlserver", {
45
+ server: "db.example",
46
+ port: "",
47
+ instanceName: "SQLEXPRESS",
48
+ }),
49
+ ).toEqual({ server: "db.example", instanceName: "SQLEXPRESS" });
50
+ });
51
+
52
+ it("leaves a value that does not parse for the server to name", () => {
53
+ expect(typedConnectionConfig("sqlserver", { port: "14x3" })).toEqual({
54
+ port: "14x3",
55
+ });
56
+ });
57
+
58
+ it("leaves out a field the form did not collect", () => {
59
+ // An edit that leaves encrypt untouched must not send `encrypt: false`.
60
+ expect(typedConnectionConfig("sqlserver", { server: "x" })).toEqual({
61
+ server: "x",
62
+ });
63
+ });
64
+
65
+ it("passes a type with no typed fields through unchanged", () => {
66
+ const config = { host: "h", port: "3306" };
67
+ expect(typedConnectionConfig("mysql", config)).toBe(config);
68
+ });
69
+ });
@@ -14,6 +14,7 @@ import type {
14
14
  PostgresConnection,
15
15
  S3Connection,
16
16
  SnowflakeConnection,
17
+ SqlserverConnection,
17
18
  TrinoConnection,
18
19
  } from "../../client/api";
19
20
 
@@ -25,6 +26,7 @@ type ConnectionField = {
25
26
  TrinoConnection &
26
27
  DatabricksConnection &
27
28
  MysqlConnection &
29
+ SqlserverConnection &
28
30
  MotherDuckConnection &
29
31
  S3Connection &
30
32
  GCSConnection &
@@ -298,6 +300,70 @@ export const connectionFieldsByType: Record<
298
300
  required: true, // Always required
299
301
  },
300
302
  ],
303
+ sqlserver: [
304
+ {
305
+ label: "Server",
306
+ name: "server",
307
+ type: "text",
308
+ required: true, // Always required
309
+ },
310
+ {
311
+ label: "Port",
312
+ name: "port",
313
+ type: "number",
314
+ required: false, // Required unless an instance name locates the server
315
+ },
316
+ {
317
+ label: "Database",
318
+ name: "database",
319
+ type: "text",
320
+ required: true, // Always required
321
+ },
322
+ {
323
+ label: "User",
324
+ name: "user",
325
+ type: "text",
326
+ required: true, // Always required
327
+ },
328
+ {
329
+ label: "Password",
330
+ name: "password",
331
+ type: "password",
332
+ required: true, // Always required
333
+ },
334
+ {
335
+ label: "Encrypt",
336
+ name: "encrypt",
337
+ type: "text",
338
+ required: false,
339
+ selectOptions: [
340
+ { label: "Yes", value: "true" },
341
+ { label: "No", value: "false" },
342
+ ],
343
+ },
344
+ {
345
+ label: "Trust server certificate",
346
+ name: "trustServerCertificate",
347
+ type: "text",
348
+ required: false,
349
+ selectOptions: [
350
+ { label: "No", value: "false" },
351
+ { label: "Yes", value: "true" },
352
+ ],
353
+ },
354
+ {
355
+ label: "Host name in certificate",
356
+ name: "hostNameInCertificate",
357
+ type: "text",
358
+ required: false,
359
+ },
360
+ {
361
+ label: "Instance name",
362
+ name: "instanceName",
363
+ type: "text",
364
+ required: false,
365
+ },
366
+ ],
301
367
  // DuckDB connections use attached databases configured via duckdbConnection.attachedDatabases
302
368
  duckdb: [],
303
369
  motherduck: [
@@ -328,12 +394,78 @@ export const attributesFieldName: Record<ConnectionTypeEnum, string> = {
328
394
  trino: "trinoConnection",
329
395
  databricks: "databricksConnection",
330
396
  mysql: "mysqlConnection",
397
+ sqlserver: "sqlserverConnection",
331
398
  duckdb: "duckdbConnection",
332
399
  motherduck: "motherduckConnection",
333
400
  ducklake: "ducklakeConnection",
334
401
  publisher: "publisherConnection",
335
402
  };
336
403
 
404
+ /**
405
+ * Fields the form collects as text that the API declares as another type.
406
+ * `FormData` yields strings, and the server passes a connection's fields to
407
+ * its driver unchanged, so a port of "1433" or an encrypt of "true" would
408
+ * reach a driver that reads only a number or a boolean. Keyed by connection
409
+ * type; a type absent here sends what the form collected.
410
+ */
411
+ const TYPED_FIELDS: Partial<
412
+ Record<ConnectionTypeEnum, Record<string, "integer" | "boolean">>
413
+ > = {
414
+ sqlserver: {
415
+ port: "integer",
416
+ encrypt: "boolean",
417
+ trustServerCertificate: "boolean",
418
+ },
419
+ };
420
+
421
+ /**
422
+ * Optional text fields the edit form submits as "" when left empty, which
423
+ * the server must not store as a value: the SQL Server connector treats a
424
+ * defined `instanceName` as "locate through SQL Browser" and drops the port,
425
+ * and a defined `hostNameInCertificate` as the name to check the certificate
426
+ * against. An empty one is left out of the payload instead.
427
+ */
428
+ const BLANK_MEANS_UNSET: Partial<Record<ConnectionTypeEnum, string[]>> = {
429
+ sqlserver: ["hostNameInCertificate", "instanceName"],
430
+ };
431
+
432
+ /**
433
+ * The connection config to send, with each field the API types as an integer
434
+ * or a boolean converted from the form's string, and each optional field in
435
+ * {@link BLANK_MEANS_UNSET} left out when blank. A value that does not parse
436
+ * is sent as collected, so the server's validation names it rather than a
437
+ * silent `NaN`.
438
+ */
439
+ export function typedConnectionConfig(
440
+ type: ConnectionTypeEnum,
441
+ config: Record<string, string>,
442
+ ): Record<string, unknown> {
443
+ const typed = TYPED_FIELDS[type];
444
+ const blankMeansUnset = BLANK_MEANS_UNSET[type];
445
+ if (!typed && !blankMeansUnset) return config;
446
+ const out: Record<string, unknown> = { ...config };
447
+ for (const name of blankMeansUnset ?? []) {
448
+ if (out[name] === "") delete out[name];
449
+ }
450
+ for (const [name, kind] of Object.entries(typed ?? {})) {
451
+ const value = config[name];
452
+ if (value === undefined) continue;
453
+ // The edit form submits "" for a field left empty, and Number("") is
454
+ // 0, which the server would read as a port.
455
+ if (value === "") {
456
+ delete out[name];
457
+ continue;
458
+ }
459
+ if (kind === "integer") {
460
+ const n = Number(value);
461
+ if (Number.isInteger(n)) out[name] = n;
462
+ } else if (value === "true" || value === "false") {
463
+ out[name] = value === "true";
464
+ }
465
+ }
466
+ return out;
467
+ }
468
+
337
469
  /**
338
470
  * Connection types the Add/Edit dialogs offer as creatable. `publisher` proxy
339
471
  * connections are configured in publisher.config.json rather than through the
@@ -29,6 +29,7 @@ const CONNECTION_TYPE_LABELS: Record<string, string> = {
29
29
  snowflake: "Snowflake",
30
30
  postgres: "PostgreSQL",
31
31
  mysql: "MySQL",
32
+ sqlserver: "SQL Server",
32
33
  trino: "Trino",
33
34
  databricks: "Databricks",
34
35
  duckdb: "DuckDB",
@@ -143,7 +143,11 @@ export function StickyControls({ children }: { children: ReactNode }) {
143
143
  position: "sticky",
144
144
  top: `${STUCK_TOP_PX}px`,
145
145
  zIndex: STICKY_CONTROLS_Z,
146
- bgcolor: "background.default",
146
+ // Filled only while pinned, when the tiles pass under it. Unpinned
147
+ // nothing does, and the fill, reaching up over the gap by the room
148
+ // below, painted over what stands into that gap from above: the
149
+ // halo of the description's selection ring.
150
+ bgcolor: stuck ? "background.default" : "transparent",
147
151
  // Room under the bar for the edge, so the line never sits on the
148
152
  // controls themselves.
149
153
  pb: 1,
@@ -130,12 +130,6 @@ export type ReportEvent =
130
130
  durationMs: number;
131
131
  }
132
132
  | { type: "report.create_refused"; reason: string }
133
- | {
134
- /** The author switched the report between Linear and Grid; `layout` is `to`. */
135
- type: "report.layout_changed";
136
- from: ReportLayout;
137
- to: ReportLayout;
138
- }
139
133
  | {
140
134
  type: "report.drill";
141
135
  /** `self` filtered this report; `report` went to another. */
@@ -421,8 +421,8 @@ export function AddTileDialog({
421
421
  next as ChartPick | "none" | "default",
422
422
  );
423
423
  }}
424
- // The builder's own segmented control, as the bar's
425
- // layout switch is, so it takes the host's tokens.
424
+ // The builder's own segmented control, as the
425
+ // filter window's is, so it takes the host's tokens.
426
426
  sx={{
427
427
  ...segmentedSx(edge, ui),
428
428
  "& .MuiToggleButton-root": {