@malloy-publisher/server 0.0.200 → 0.0.202

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 (28) hide show
  1. package/dist/app/api-doc.yaml +34 -7
  2. package/dist/app/assets/{EnvironmentPage-CgKNjySu.js → EnvironmentPage-CNQYDaxR.js} +1 -1
  3. package/dist/app/assets/HomePage-DBFTIoD8.js +1 -0
  4. package/dist/app/assets/MainPage-B0kNpkxT.js +2 -0
  5. package/dist/app/assets/{ModelPage-C0Uevsw9.js → ModelPage-DcVElc9L.js} +1 -1
  6. package/dist/app/assets/{PackagePage-Cu-u9k1g.js → PackagePage-yAh0TrOV.js} +1 -1
  7. package/dist/app/assets/{RouteError-DVwPh2Ql.js → RouteError-DknUbx_s.js} +1 -1
  8. package/dist/app/assets/{WorkbookPage-DW38R2Zv.js → WorkbookPage-CCqc8otA.js} +1 -1
  9. package/dist/app/assets/{core-C0vCMRDQ.es-D_ytHhjS.js → core-B3A61KGJ.es-iOUZ6RJL.js} +10 -10
  10. package/dist/app/assets/index-F_o127LC.js +454 -0
  11. package/dist/app/assets/{index-BGdcKsFF.js → index-QeX_e740.js} +1 -1
  12. package/dist/app/assets/{index-CTx4v4_3.js → index-W0bOLKGl.js} +1 -1
  13. package/dist/app/assets/{index.umd-C1Mi1uRm.js → index.umd-CEDRw4TK.js} +1 -1
  14. package/dist/app/index.html +1 -1
  15. package/dist/server.mjs +74 -8
  16. package/package.json +1 -1
  17. package/publisher.config.json +4 -0
  18. package/src/filter_deprecation.spec.ts +64 -0
  19. package/src/filter_deprecation.ts +42 -0
  20. package/src/server.ts +32 -25
  21. package/src/service/connection.spec.ts +244 -0
  22. package/src/service/connection.ts +6 -2
  23. package/src/service/environment.ts +42 -2
  24. package/src/service/filter_integration.spec.ts +69 -0
  25. package/src/service/model.ts +15 -2
  26. package/dist/app/assets/HomePage-BPIpMBjW.js +0 -1
  27. package/dist/app/assets/MainPage-CAwb8U82.js +0 -2
  28. package/dist/app/assets/index-DE6d5jEy.js +0 -452
@@ -95,7 +95,9 @@ async function isDatabaseAttached(
95
95
  ? existingDatabases
96
96
  : existingDatabases.rows || [];
97
97
 
98
- logger.debug(`Existing databases:`, rows);
98
+ logger.debug("connection.duckdb.databases.queried", {
99
+ count: rows.length,
100
+ });
99
101
 
100
102
  return rows.some((row: Record<string, unknown>) =>
101
103
  Object.values(row).some(
@@ -1132,7 +1134,9 @@ export async function createEnvironmentConnections(
1132
1134
 
1133
1135
  for (const connection of environmentConfig.apiConnections) {
1134
1136
  if (!connection.name) continue;
1135
- logger.info(`Adding connection ${connection.name}`, { connection });
1137
+ logger.info(`Adding connection ${connection.name}`, {
1138
+ type: connection.type,
1139
+ });
1136
1140
  const malloyConnection =
1137
1141
  await environmentConfig.malloyConfig.connections.lookupConnection(
1138
1142
  connection.name,
@@ -236,7 +236,10 @@ export class Environment {
236
236
  logger.info(
237
237
  `Loaded ${malloyConfig.apiConnections.length} connections for environment ${environmentName}`,
238
238
  {
239
- apiConnections: malloyConfig.apiConnections,
239
+ connections: malloyConfig.apiConnections.map((c) => ({
240
+ name: c.name,
241
+ type: c.type,
242
+ })),
240
243
  },
241
244
  );
242
245
 
@@ -776,7 +779,6 @@ export class Environment {
776
779
  `Adding package ${packageName} to environment ${this.environmentName}`,
777
780
  {
778
781
  packagePath,
779
- malloyConfig: this.malloyConfig.malloyConfig,
780
782
  },
781
783
  );
782
784
 
@@ -842,6 +844,12 @@ export class Environment {
842
844
  const stagingPath = this.allocateStagingPath(packageName);
843
845
  await fs.promises.mkdir(path.dirname(stagingPath), { recursive: true });
844
846
 
847
+ logger.debug("install.phase1.download.started", {
848
+ environmentName: this.environmentName,
849
+ packageName,
850
+ stagingPath,
851
+ });
852
+ const downloadStartedAt = performance.now();
845
853
  try {
846
854
  await downloader(stagingPath);
847
855
  } catch (err) {
@@ -850,8 +858,17 @@ export class Environment {
850
858
  .catch(() => {});
851
859
  throw err;
852
860
  }
861
+ logger.debug("install.phase1.download.completed", {
862
+ environmentName: this.environmentName,
863
+ packageName,
864
+ durationMs: performance.now() - downloadStartedAt,
865
+ });
853
866
 
854
867
  return this.withPackageLock(packageName, async () => {
868
+ logger.debug("install.phase2.swap.started", {
869
+ environmentName: this.environmentName,
870
+ packageName,
871
+ });
855
872
  const canonicalPath = safeJoinUnderRoot(
856
873
  this.environmentPath,
857
874
  packageName,
@@ -870,6 +887,11 @@ export class Environment {
870
887
  recursive: true,
871
888
  });
872
889
  await fs.promises.rename(canonicalPath, retiredPath);
890
+ logger.debug("install.phase2.retired_old", {
891
+ environmentName: this.environmentName,
892
+ packageName,
893
+ retiredPath,
894
+ });
873
895
  }
874
896
 
875
897
  let newPackage: Package;
@@ -883,6 +905,11 @@ export class Environment {
883
905
  canonicalPath,
884
906
  () => this.malloyConfig.malloyConfig,
885
907
  );
908
+ logger.debug("install.phase2.committed", {
909
+ environmentName: this.environmentName,
910
+ packageName,
911
+ canonicalPath,
912
+ });
886
913
  } catch (err) {
887
914
  // Rollback: clobber whatever (partial) content sits at canonical
888
915
  // — Package.create's own failure-cleanup may have already rm'd
@@ -894,9 +921,11 @@ export class Environment {
894
921
  await fs.promises
895
922
  .rm(canonicalPath, { recursive: true, force: true })
896
923
  .catch(() => {});
924
+ let restored = false;
897
925
  if (retiredPath) {
898
926
  try {
899
927
  await fs.promises.rename(retiredPath, canonicalPath);
928
+ restored = true;
900
929
  } catch (restoreErr) {
901
930
  logger.error(
902
931
  "Failed to restore retired package after install rollback",
@@ -912,6 +941,12 @@ export class Environment {
912
941
  .rm(stagingPath, { recursive: true, force: true })
913
942
  .catch(() => {});
914
943
  this.deletePackageStatus(packageName);
944
+ logger.debug("install.phase2.rollback", {
945
+ environmentName: this.environmentName,
946
+ packageName,
947
+ restored,
948
+ errorName: err instanceof Error ? err.name : "Unknown",
949
+ });
915
950
  throw err;
916
951
  }
917
952
 
@@ -927,6 +962,11 @@ export class Environment {
927
962
  if (retiredPath) {
928
963
  const pathToClean = retiredPath;
929
964
  setImmediate(() => {
965
+ logger.debug("install.phase3.retired_cleanup", {
966
+ environmentName: this.environmentName,
967
+ packageName,
968
+ retiredPath: pathToClean,
969
+ });
930
970
  void fs.promises
931
971
  .rm(pathToClean, { recursive: true, force: true })
932
972
  .catch((err) => {
@@ -485,6 +485,75 @@ describe("filter integration", () => {
485
485
  });
486
486
  });
487
487
 
488
+ // -----------------------------------------------------------------------
489
+ // Mixed givens + #(filter) composition on the query-results path
490
+ //
491
+ // PR 5/6 of the givens migration deprecates `#(filter)` but keeps both
492
+ // injection paths working independently and in combination. These tests
493
+ // assert that `model.getQueryResults` (the path behind POST /…/query)
494
+ // composes a `given:` substitution with a `filterParams` WHERE-injection
495
+ // — same model, same call, both effects apply.
496
+ // -----------------------------------------------------------------------
497
+ describe("givens + filterParams composition", () => {
498
+ it("composes a given override with filterParams on getQueryResults", async () => {
499
+ await writeFile(
500
+ "orders_givens_filter.malloy",
501
+ MODEL_WITH_GIVENS_AND_FILTER,
502
+ );
503
+ const model = await Model.create(
504
+ "test-pkg",
505
+ TEST_PKG_DIR,
506
+ "orders_givens_filter.malloy",
507
+ getConnections(),
508
+ );
509
+
510
+ // given restricts to APAC; filterParam restricts to active.
511
+ // APAC + active: only (5,'APAC','active',300) → order_count=1, total_amount=300.
512
+ const { compactResult } = await model.getQueryResults(
513
+ "orders",
514
+ "by_given_region",
515
+ undefined,
516
+ { status: "active" },
517
+ undefined,
518
+ { target_region: "APAC" },
519
+ );
520
+
521
+ const r = asRows(compactResult);
522
+ expect(r.length).toBe(1);
523
+ expect(Number(r[0].order_count)).toBe(1);
524
+ expect(Number(r[0].total_amount)).toBe(300);
525
+ });
526
+
527
+ it("falls back to the given default when no override is supplied", async () => {
528
+ await writeFile(
529
+ "orders_givens_filter.malloy",
530
+ MODEL_WITH_GIVENS_AND_FILTER,
531
+ );
532
+ const model = await Model.create(
533
+ "test-pkg",
534
+ TEST_PKG_DIR,
535
+ "orders_givens_filter.malloy",
536
+ getConnections(),
537
+ );
538
+
539
+ // Default given target_region='US'; filterParam restricts to active.
540
+ // US + active: (1,'US','active',100) and (2,'US','active',200) → order_count=2, total_amount=300.
541
+ const { compactResult } = await model.getQueryResults(
542
+ "orders",
543
+ "by_given_region",
544
+ undefined,
545
+ { status: "active" },
546
+ undefined,
547
+ undefined,
548
+ );
549
+
550
+ const r = asRows(compactResult);
551
+ expect(r.length).toBe(1);
552
+ expect(Number(r[0].order_count)).toBe(2);
553
+ expect(Number(r[0].total_amount)).toBe(300);
554
+ });
555
+ });
556
+
488
557
  // -----------------------------------------------------------------------
489
558
  // Required filter enforcement
490
559
  // -----------------------------------------------------------------------
@@ -166,6 +166,21 @@ export class Model {
166
166
  this.modelInfo =
167
167
  modelInfo ??
168
168
  (this.modelDef ? modelDefToModelInfo(this.modelDef) : undefined);
169
+
170
+ // One-time deprecation notice per Model instance. Surfaces only when
171
+ // the model declares `#(filter)` annotations so operators migrating
172
+ // toward `given:` see a clear pointer in the server log without
173
+ // spamming for models that have already moved over.
174
+ if (this.filterMap.size > 0) {
175
+ logger.warn(
176
+ `Model "${packageName}/${modelPath}" uses deprecated #(filter) annotations. Migrate to given: — see https://github.com/malloydata/publisher/blob/main/docs/givens.md`,
177
+ {
178
+ packageName,
179
+ modelPath,
180
+ filterSourceCount: this.filterMap.size,
181
+ },
182
+ );
183
+ }
169
184
  }
170
185
 
171
186
  /**
@@ -717,7 +732,6 @@ export class Model {
717
732
  const notebookCells: ApiNotebookCell[] = (
718
733
  this.runnableNotebookCells as RunnableNotebookCell[]
719
734
  ).map((cell) => {
720
- logger.debug("cell.queryInfo", cell.queryInfo);
721
735
  return {
722
736
  type: cell.type,
723
737
  text: cell.text,
@@ -887,7 +901,6 @@ export class Model {
887
901
  } else {
888
902
  logger.error("Error message: ", errorMessage);
889
903
  }
890
- logger.debug("Cell content: ", cellIndex, cell.type, cell.text);
891
904
  throw new BadRequestError(`Cell execution failed: ${errorMessage}`);
892
905
  }
893
906
  }
@@ -1 +0,0 @@
1
- import{M as t,j as o,r}from"./index-DE6d5jEy.js";function e(){const n=t();return o.jsx(r,{onClickEnvironment:n})}export{e as default};
@@ -1,2 +0,0 @@
1
- import{u as we,g as ke,a as u,R as Se,b as Pe,c as $,j as t,s as I,B as Ce,m as _,e as re,d as oe,f as se,h as ae,i as Ee,k as O,l as ie,T as K,n as G,o as Ie,p as Me,q as Re,t as le,v as ze,w as ne,x as De,y as Te,z as Be,A,C as H,D as $e,P as Le,E as He,F as Ne,S as Ae,G as ce,M as J,H as x,I as We,J as X,K as Oe,L as Z,X as Ve,N as Ue,O as de,Q as pe,U as ue,V as he,W as Qe,Y as Fe,Z as Xe}from"./index-DE6d5jEy.js";function Ye(e,r,n,o,s){const[a,i]=u.useState(()=>s&&n?n(e).matches:o?o(e).matches:r);return Pe(()=>{if(!n)return;const c=n(e),h=()=>{i(c.matches)};return h(),c.addEventListener("change",h),()=>{c.removeEventListener("change",h)}},[e,n]),a}const _e={...Se},fe=_e.useSyncExternalStore;function Ke(e,r,n,o,s){const a=u.useCallback(()=>r,[r]),i=u.useMemo(()=>{if(s&&n)return()=>n(e).matches;if(o!==null){const{matches:p}=o(e);return()=>p}return a},[a,e,o,s,n]),[c,h]=u.useMemo(()=>{if(n===null)return[a,()=>()=>{}];const p=n(e);return[()=>p.matches,m=>(p.addEventListener("change",m),()=>{p.removeEventListener("change",m)})]},[a,n,e]);return fe(h,c,i)}function me(e={}){const{themeId:r}=e;return function(o,s={}){let a=we();a&&r&&(a=a[r]||a);const i=typeof window<"u"&&typeof window.matchMedia<"u",{defaultMatches:c=!1,matchMedia:h=i?window.matchMedia:null,ssrMatchMedia:f=null,noSsr:p=!1}=ke({name:"MuiUseMediaQuery",props:s,theme:a});let m=typeof o=="function"?o(a):o;return m=m.replace(/^@media( ?)/m,""),m.includes("print")&&console.warn(["MUI: You have provided a `print` query to the `useMediaQuery` hook.","Using the print media query to modify print styles can lead to unexpected results.","Consider using the `displayPrint` field in the `sx` prop instead.","More information about `displayPrint` on our docs: https://mui.com/system/display/#display-in-print."].join(`
2
- `)),(fe!==void 0?Ke:Ye)(m,c,h,f,p)}}me();const Ge=$(t.jsx("path",{d:"M6 10c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm12 0c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm-6 0c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"})),Je=I(Ce,{name:"MuiBreadcrumbCollapsed"})(_(({theme:e})=>({display:"flex",marginLeft:`calc(${e.spacing(1)} * 0.5)`,marginRight:`calc(${e.spacing(1)} * 0.5)`,...e.palette.mode==="light"?{backgroundColor:e.palette.grey[100],color:e.palette.grey[700]}:{backgroundColor:e.palette.grey[700],color:e.palette.grey[100]},borderRadius:2,"&:hover, &:focus":{...e.palette.mode==="light"?{backgroundColor:e.palette.grey[200]}:{backgroundColor:e.palette.grey[600]}},"&:active":{boxShadow:e.shadows[0],...e.palette.mode==="light"?{backgroundColor:re(e.palette.grey[200],.12)}:{backgroundColor:re(e.palette.grey[600],.12)}}}))),Ze=I(Ge)({width:24,height:16});function qe(e){const{slots:r={},slotProps:n={},...o}=e,s=e;return t.jsx("li",{children:t.jsx(Je,{focusRipple:!0,...o,ownerState:s,children:t.jsx(Ze,{as:r.CollapsedIcon,ownerState:s,...n.collapsedIcon})})})}function et(e){return se("MuiBreadcrumbs",e)}const tt=oe("MuiBreadcrumbs",["root","ol","li","separator"]),rt=e=>{const{classes:r}=e;return ie({root:["root"],li:["li"],ol:["ol"],separator:["separator"]},et,r)},nt=I(K,{name:"MuiBreadcrumbs",slot:"Root",overridesResolver:(e,r)=>[{[`& .${tt.li}`]:r.li},r.root]})({}),ot=I("ol",{name:"MuiBreadcrumbs",slot:"Ol"})({display:"flex",flexWrap:"wrap",alignItems:"center",padding:0,margin:0,listStyle:"none"}),st=I("li",{name:"MuiBreadcrumbs",slot:"Separator"})({display:"flex",userSelect:"none",marginLeft:8,marginRight:8});function at(e,r,n,o){return e.reduce((s,a,i)=>(i<e.length-1?s=s.concat(a,t.jsx(st,{"aria-hidden":!0,className:r,ownerState:o,children:n},`separator-${i}`)):s.push(a),s),[])}const it=u.forwardRef(function(r,n){const o=ae({props:r,name:"MuiBreadcrumbs"}),{children:s,className:a,component:i="nav",slots:c={},slotProps:h={},expandText:f="Show path",itemsAfterCollapse:p=1,itemsBeforeCollapse:m=1,maxItems:y=8,separator:S="/",...L}=o,[M,P]=u.useState(!1),v={...o,component:i,expanded:M,expandText:f,itemsAfterCollapse:p,itemsBeforeCollapse:m,maxItems:y,separator:S},C=rt(v),R=Ee({elementType:c.CollapsedIcon,externalSlotProps:h.collapsedIcon,ownerState:v}),j=u.useRef(null),w=d=>{const k=()=>{P(!0);const b=j.current.querySelector("a[href],button,[tabindex]");b&&b.focus()};return m+p>=d.length?d:[...d.slice(0,m),t.jsx(qe,{"aria-label":f,slots:{CollapsedIcon:c.CollapsedIcon},slotProps:{collapsedIcon:R},onClick:k},"ellipsis"),...d.slice(d.length-p,d.length)]},z=u.Children.toArray(s).filter(d=>u.isValidElement(d)).map((d,k)=>t.jsx("li",{className:C.li,children:d},`child-${k}`));return t.jsx(nt,{ref:n,component:i,color:"textSecondary",className:O(C.root,a),ownerState:v,...L,children:t.jsx(ot,{className:C.ol,ref:j,ownerState:v,children:at(M||y&&z.length<=y?z:w(z),C.separator,S,v)})})});function lt(e,r,n){const o=r.getBoundingClientRect(),s=n&&n.getBoundingClientRect(),a=le(r);let i;if(r.fakeTransform)i=r.fakeTransform;else{const f=a.getComputedStyle(r);i=f.getPropertyValue("-webkit-transform")||f.getPropertyValue("transform")}let c=0,h=0;if(i&&i!=="none"&&typeof i=="string"){const f=i.split("(")[1].split(")")[0].split(",");c=parseInt(f[4],10),h=parseInt(f[5],10)}return e==="left"?s?`translateX(${s.right+c-o.left}px)`:`translateX(${a.innerWidth+c-o.left}px)`:e==="right"?s?`translateX(-${o.right-s.left-c}px)`:`translateX(-${o.left+o.width-c}px)`:e==="up"?s?`translateY(${s.bottom+h-o.top}px)`:`translateY(${a.innerHeight+h-o.top}px)`:s?`translateY(-${o.top-s.top+o.height-h}px)`:`translateY(-${o.top+o.height-h}px)`}function ct(e){return typeof e=="function"?e():e}function W(e,r,n){const o=ct(n),s=lt(e,r,o);s&&(r.style.webkitTransform=s,r.style.transform=s)}const dt=u.forwardRef(function(r,n){const o=G(),s={enter:o.transitions.easing.easeOut,exit:o.transitions.easing.sharp},a={enter:o.transitions.duration.enteringScreen,exit:o.transitions.duration.leavingScreen},{addEndListener:i,appear:c=!0,children:h,container:f,direction:p="down",easing:m=s,in:y,onEnter:S,onEntered:L,onEntering:M,onExit:P,onExited:v,onExiting:C,style:R,timeout:j=a,TransitionComponent:w=Ie,...z}=r,d=u.useRef(null),k=Me(Re(h),d,n),b=l=>g=>{l&&(g===void 0?l(d.current):l(d.current,g))},V=b((l,g)=>{W(p,l,f),De(l),S&&S(l,g)}),q=b((l,g)=>{const B=ne({timeout:j,style:R,easing:m},{mode:"enter"});l.style.webkitTransition=o.transitions.create("-webkit-transform",{...B}),l.style.transition=o.transitions.create("transform",{...B}),l.style.webkitTransform="none",l.style.transform="none",M&&M(l,g)}),D=b(L),T=b(C),E=b(l=>{const g=ne({timeout:j,style:R,easing:m},{mode:"exit"});l.style.webkitTransition=o.transitions.create("-webkit-transform",g),l.style.transition=o.transitions.create("transform",g),W(p,l,f),P&&P(l)}),U=b(l=>{l.style.webkitTransition="",l.style.transition="",v&&v(l)}),Q=l=>{i&&i(d.current,l)},N=u.useCallback(()=>{d.current&&W(p,d.current,f)},[p,f]);return u.useEffect(()=>{if(y||p==="down"||p==="right")return;const l=ze(()=>{d.current&&W(p,d.current,f)}),g=le(d.current);return g.addEventListener("resize",l),()=>{l.clear(),g.removeEventListener("resize",l)}},[p,y,f]),u.useEffect(()=>{y||N()},[y,N]),t.jsx(w,{nodeRef:d,onEnter:V,onEntered:D,onEntering:q,onExit:E,onExited:U,onExiting:T,addEndListener:Q,appear:c,in:y,timeout:j,...z,children:(l,{ownerState:g,...B})=>u.cloneElement(h,{ref:k,style:{visibility:l==="exited"&&!y?"hidden":void 0,...R,...h.props.style},...B})})});function pt(e){return se("MuiDrawer",e)}oe("MuiDrawer",["root","docked","paper","anchorLeft","anchorRight","anchorTop","anchorBottom","paperAnchorLeft","paperAnchorRight","paperAnchorTop","paperAnchorBottom","paperAnchorDockedLeft","paperAnchorDockedRight","paperAnchorDockedTop","paperAnchorDockedBottom","modal"]);const xe=(e,r)=>{const{ownerState:n}=e;return[r.root,(n.variant==="permanent"||n.variant==="persistent")&&r.docked,r.modal]},ut=e=>{const{classes:r,anchor:n,variant:o}=e,s={root:["root",`anchor${H(n)}`],docked:[(o==="permanent"||o==="persistent")&&"docked"],modal:["modal"],paper:["paper",`paperAnchor${H(n)}`,o!=="temporary"&&`paperAnchorDocked${H(n)}`]};return ie(s,pt,r)},ht=I($e,{name:"MuiDrawer",slot:"Root",overridesResolver:xe})(_(({theme:e})=>({zIndex:(e.vars||e).zIndex.drawer}))),ft=I("div",{shouldForwardProp:He,name:"MuiDrawer",slot:"Docked",skipVariantsResolver:!1,overridesResolver:xe})({flex:"0 0 auto"}),mt=I(Le,{name:"MuiDrawer",slot:"Paper",overridesResolver:(e,r)=>{const{ownerState:n}=e;return[r.paper,r[`paperAnchor${H(n.anchor)}`],n.variant!=="temporary"&&r[`paperAnchorDocked${H(n.anchor)}`]]}})(_(({theme:e})=>({overflowY:"auto",display:"flex",flexDirection:"column",height:"100%",flex:"1 0 auto",zIndex:(e.vars||e).zIndex.drawer,WebkitOverflowScrolling:"touch",position:"fixed",top:0,outline:0,variants:[{props:{anchor:"left"},style:{left:0}},{props:{anchor:"top"},style:{top:0,left:0,right:0,height:"auto",maxHeight:"100%"}},{props:{anchor:"right"},style:{right:0}},{props:{anchor:"bottom"},style:{top:"auto",left:0,bottom:0,right:0,height:"auto",maxHeight:"100%"}},{props:({ownerState:r})=>r.anchor==="left"&&r.variant!=="temporary",style:{borderRight:`1px solid ${(e.vars||e).palette.divider}`}},{props:({ownerState:r})=>r.anchor==="top"&&r.variant!=="temporary",style:{borderBottom:`1px solid ${(e.vars||e).palette.divider}`}},{props:({ownerState:r})=>r.anchor==="right"&&r.variant!=="temporary",style:{borderLeft:`1px solid ${(e.vars||e).palette.divider}`}},{props:({ownerState:r})=>r.anchor==="bottom"&&r.variant!=="temporary",style:{borderTop:`1px solid ${(e.vars||e).palette.divider}`}}]}))),ge={left:"right",right:"left",top:"down",bottom:"up"};function xt(e){return["left","right"].includes(e)}function gt({direction:e},r){return e==="rtl"&&xt(r)?ge[r]:r}const yt=u.forwardRef(function(r,n){const o=ae({props:r,name:"MuiDrawer"}),s=G(),a=Te(),i={enter:s.transitions.duration.enteringScreen,exit:s.transitions.duration.leavingScreen},{anchor:c="left",BackdropProps:h,children:f,className:p,elevation:m=16,hideBackdrop:y=!1,ModalProps:{BackdropProps:S,...L}={},onClose:M,open:P=!1,PaperProps:v={},SlideProps:C,TransitionComponent:R,transitionDuration:j=i,variant:w="temporary",slots:z={},slotProps:d={},...k}=o,b=u.useRef(!1);u.useEffect(()=>{b.current=!0},[]);const V=gt({direction:a?"rtl":"ltr"},c),D={...o,anchor:c,elevation:m,open:P,variant:w,...k},T=ut(D),E={slots:{transition:R,...z},slotProps:{paper:v,transition:C,...d,backdrop:Be(d.backdrop||{...h,...S},{transitionDuration:j})}},[U,Q]=A("root",{ref:n,elementType:ht,className:O(T.root,T.modal,p),shouldForwardComponentProp:!0,ownerState:D,externalForwardedProps:{...E,...k,...L},additionalProps:{open:P,onClose:M,hideBackdrop:y,slots:{backdrop:E.slots.backdrop},slotProps:{backdrop:E.slotProps.backdrop}}}),[N,l]=A("paper",{elementType:mt,shouldForwardComponentProp:!0,className:O(T.paper,v.className),ownerState:D,externalForwardedProps:E,additionalProps:{elevation:w==="temporary"?m:0,square:!0,...w==="temporary"&&{role:"dialog","aria-modal":"true"}}}),[g,B]=A("docked",{elementType:ft,ref:n,className:O(T.root,T.docked,p),ownerState:D,externalForwardedProps:E,additionalProps:k}),[ve,je]=A("transition",{elementType:dt,ownerState:D,externalForwardedProps:E,additionalProps:{in:P,direction:ge[V],timeout:j,appear:b.current}}),ee=t.jsx(N,{...l,children:f});if(w==="permanent")return t.jsx(g,{...B,children:ee});const te=t.jsx(ve,{...je,children:ee});return w==="persistent"?t.jsx(g,{...B,children:te}):t.jsx(U,{...Q,children:te})}),bt=me({themeId:Ne}),vt=$([t.jsx("path",{d:"M19 5v14H5V5zm0-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2"},"0"),t.jsx("path",{d:"M14 17H7v-2h7zm3-4H7v-2h10zm0-4H7V7h10z"},"1")]),jt=$(t.jsx("path",{d:"M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"})),wt=$(t.jsx("path",{d:"M9.4 16.6 4.8 12l4.6-4.6L8 6l-6 6 6 6zm5.2 0 4.6-4.6-4.6-4.6L16 6l6 6-6 6z"})),kt=$(t.jsx("path",{d:"m9.17 6 2 2H20v10H4V6zM10 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8z"})),St=$(t.jsx("path",{d:"m12 5.69 5 4.5V18h-2v-6H9v6H7v-7.81zM12 3 2 12h3v8h6v-6h2v6h6v-8h3z"})),Pt=$(t.jsx("path",{d:"M19 19H5V5h7V3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2v-7h-2zM14 3v2h3.59l-9.83 9.83 1.41 1.41L19 6.41V10h2V3z"}));function Y(e){return t.jsxs(Ae,{...e,viewBox:"0 0 24 24",sx:{fill:"none",...e.sx},children:[t.jsx("rect",{x:"3.25",y:"4.75",width:"17.5",height:"14.5",rx:"2.25",stroke:"currentColor",strokeWidth:"1.5"}),t.jsx("line",{x1:"8.5",y1:"5",x2:"8.5",y2:"19",stroke:"currentColor",strokeWidth:"1.5"})]})}function F({label:e,onClick:r}){return t.jsx(We,{clickable:!0,onClick:r,label:e,size:"small","aria-label":`Navigate to ${e}`,sx:{backgroundColor:"background.paper",color:"text.primary",fontWeight:500,fontSize:"0.875rem",height:32,cursor:"pointer",borderRadius:"4px",maxWidth:320,"& .MuiChip-label":{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},"&:hover":{backgroundColor:"grey.100"}}})}function Ct(){const e=ce(),r=e["*"],n=J();return!e.environmentName&&!e.packageName&&!r?null:t.jsx(x,{sx:{display:"flex",alignItems:"center",minWidth:0},children:t.jsxs(it,{"aria-label":"breadcrumb",separator:t.jsx(jt,{sx:{fontSize:14,color:"text.secondary"}}),children:[e.environmentName&&t.jsx(F,{label:e.environmentName,onClick:o=>n(`/${e.environmentName}/`,o)}),e.packageName&&t.jsx(F,{label:e.packageName,onClick:o=>n(`/${e.environmentName}/${e.packageName}/`,o)}),r&&t.jsx(F,{label:r,onClick:o=>n(`/${e.environmentName}/${e.packageName}/${r}`,o)})]})})}const Et=260,It=64;function ye({isCollapsed:e,onToggleCollapse:r,logoHeader:n}){return t.jsxs(x,{sx:{height:"100dvh",width:e?It:Et,flexShrink:0,display:"flex",flexDirection:"column",backgroundColor:"background.paper",transition:"width 0.2s cubic-bezier(0.4, 0, 0.2, 1)",overflow:"hidden"},children:[t.jsx(Mt,{isCollapsed:e,onToggleCollapse:r,logoHeader:n}),t.jsxs(x,{sx:{flex:1,overflowY:"auto",overflowX:"hidden",py:1},children:[t.jsx(Rt,{isCollapsed:e}),t.jsx(zt,{isCollapsed:e})]}),t.jsx(Dt,{isCollapsed:e})]})}function Mt({isCollapsed:e,onToggleCollapse:r,logoHeader:n}){const o=J();return n?t.jsxs(x,{sx:{height:56,display:"flex",alignItems:"center",justifyContent:"space-between",px:e?0:2,flexShrink:0},children:[n,t.jsx(X,{size:"small",onClick:r,"aria-label":e?"Expand sidebar":"Collapse sidebar",children:t.jsx(Y,{fontSize:"small"})})]}):t.jsxs(x,{sx:{height:56,display:"flex",alignItems:"center",justifyContent:e?"center":"space-between",px:e?0:2,flexShrink:0},children:[t.jsxs(x,{onClick:s=>o("/",s),sx:{display:"flex",alignItems:"center",gap:1,cursor:"pointer",minWidth:0},children:[t.jsx(x,{component:"img",src:"/logo.svg",alt:"Malloy",sx:{width:24,height:24,flexShrink:0}}),!e&&t.jsx(K,{variant:"subtitle1",sx:{color:"text.primary",fontWeight:500,letterSpacing:"-0.025em",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:"Malloy Publisher"})]}),!e&&t.jsx(X,{size:"small",onClick:r,"aria-label":"Collapse sidebar",children:t.jsx(Y,{fontSize:"small"})})]})}function Rt({isCollapsed:e}){const n=Oe().pathname==="/";return t.jsx(Z,{sx:{py:0},children:t.jsx(be,{icon:t.jsx(St,{fontSize:"small"}),label:"Home",to:"/",selected:n,isCollapsed:e})})}function zt({isCollapsed:e}){const{apiClients:r}=Ve(),n=ce(),{data:o}=Ue({queryKey:["environments"],queryFn:()=>r.environments.listEnvironments()}),s=o?.data??[];return s.length===0?null:t.jsxs(x,{sx:{mt:1},children:[!e&&t.jsx(K,{variant:"caption",sx:{display:"block",px:3,py:1,color:"text.secondary",fontWeight:500,textTransform:"uppercase",fontSize:"0.6875rem",letterSpacing:"0.5px"},children:"Environments"}),t.jsx(Z,{sx:{py:0},children:s.map(a=>{const i=a.name??"";return t.jsx(be,{icon:t.jsx(kt,{fontSize:"small"}),label:i,to:`/${i}`,selected:n.environmentName===i,isCollapsed:e},i)})})]})}function Dt({isCollapsed:e}){const r=[{label:"Malloy Docs",href:"https://docs.malloydata.dev/documentation/",icon:t.jsx(vt,{fontSize:"small"}),external:!0},{label:"Publisher Docs",href:"https://github.com/malloydata/publisher/blob/main/README.md",icon:t.jsx(Pt,{fontSize:"small"}),external:!0},{label:"Publisher API",href:"/api-doc.html",icon:t.jsx(wt,{fontSize:"small"}),external:!1}];return t.jsx(Z,{sx:{py:1},children:r.map(n=>t.jsx(Tt,{label:n.label,href:n.href,icon:n.icon,external:n.external,isCollapsed:e},n.label))})}function be({icon:e,label:r,to:n,selected:o,isCollapsed:s}){const a=J(),i=t.jsxs(pe,{selected:o,onClick:c=>a(n,c),sx:{justifyContent:s?"center":"flex-start",px:s?0:2},children:[t.jsx(ue,{sx:{minWidth:s?0:36,justifyContent:"center",color:o?"text.primary":"text.secondary"},children:e}),!s&&t.jsx(he,{primary:r,primaryTypographyProps:{variant:"body2",sx:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}}})]});return s?t.jsx(de,{title:r,placement:"right",children:t.jsx(x,{children:i})}):i}function Tt({label:e,href:r,icon:n,external:o,isCollapsed:s}){const a=t.jsxs(pe,{component:"a",href:r,target:o?"_blank":void 0,rel:o?"noopener noreferrer":void 0,sx:{justifyContent:s?"center":"flex-start",px:s?0:2},children:[t.jsx(ue,{sx:{minWidth:s?0:36,justifyContent:"center",color:"text.secondary"},children:n}),!s&&t.jsx(he,{primary:e,primaryTypographyProps:{variant:"body2",sx:{color:"text.secondary",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}}})]});return s?t.jsx(de,{title:e,placement:"right",children:t.jsx(x,{children:a})}):a}function Bt({open:e,onClose:r,logoHeader:n}){return t.jsx(yt,{anchor:"left",open:e,onClose:r,ModalProps:{keepMounted:!0},sx:{display:{xs:"block",md:"none"},"& .MuiDrawer-paper":{boxSizing:"border-box",width:260}},children:t.jsx(ye,{isCollapsed:!1,onToggleCollapse:r,logoHeader:n})})}function Lt({headerProps:e}){const r=G(),n=bt(r.breakpoints.up("md")),[o,s]=u.useState(!1),[a,i]=u.useState(!1);return u.useEffect(()=>{n&&o&&s(!1)},[n,o]),t.jsxs(x,{sx:{height:"100dvh",display:"flex",flexDirection:"row",bgcolor:"background.default"},children:[n&&t.jsx(ye,{isCollapsed:a,onToggleCollapse:()=>i(c=>!c),logoHeader:e?.logoHeader}),t.jsxs(x,{component:"main",sx:{flex:1,display:"flex",flexDirection:"column",minWidth:0},children:[t.jsxs(x,{sx:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"space-between",height:Qe.headerHeight,px:{xs:1,md:3},backgroundColor:"background.default"},children:[t.jsx(x,{sx:{display:{xs:"flex",md:"none"},alignItems:"center",mr:1},children:t.jsx(X,{size:"small",onClick:()=>s(!0),"aria-label":"Open navigation",children:t.jsx(Y,{fontSize:"small"})})}),t.jsx(x,{sx:{flex:1,minWidth:0,display:"flex",alignItems:"center"},children:t.jsx(Ct,{})}),t.jsx(x,{id:"header-actions-portal",sx:{display:"flex",alignItems:"center",flexShrink:0,gap:1},children:e?.endCap})]}),t.jsx(x,{sx:{flex:1,overflow:"auto",minWidth:320,minHeight:0},children:t.jsx(u.Suspense,{fallback:t.jsx(Xe,{}),children:t.jsx(Fe,{})})})]}),t.jsx(Bt,{open:o,onClose:()=>s(!1),logoHeader:e?.logoHeader})]})}export{Lt as default};