@databricks/appkit 0.5.0 → 0.5.2

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 (183) hide show
  1. package/dist/app/index.d.ts +11 -2
  2. package/dist/app/index.d.ts.map +1 -1
  3. package/dist/app/index.js +51 -37
  4. package/dist/app/index.js.map +1 -1
  5. package/dist/appkit/package.js +1 -1
  6. package/dist/cli/commands/docs.js +1 -1
  7. package/dist/cli/commands/docs.js.map +1 -1
  8. package/dist/cli/commands/generate-types.js +5 -0
  9. package/dist/cli/commands/generate-types.js.map +1 -1
  10. package/dist/cli/commands/lint.js.map +1 -1
  11. package/dist/cli/commands/setup.js.map +1 -1
  12. package/dist/cli/index.js +3 -3
  13. package/dist/cli/index.js.map +1 -1
  14. package/dist/context/execution-context.js.map +1 -1
  15. package/dist/context/index.js +1 -1
  16. package/dist/context/index.js.map +1 -1
  17. package/dist/index.d.ts +5 -5
  18. package/dist/index.js +6 -6
  19. package/dist/index.js.map +1 -1
  20. package/dist/plugin/dev-reader.d.ts +1 -0
  21. package/dist/plugin/dev-reader.d.ts.map +1 -1
  22. package/dist/plugin/dev-reader.js +39 -1
  23. package/dist/plugin/dev-reader.js.map +1 -1
  24. package/dist/plugin/plugin.d.ts +2 -2
  25. package/dist/plugin/plugin.js +1 -1
  26. package/dist/{analytics → plugins/analytics}/analytics.d.ts +4 -4
  27. package/dist/plugins/analytics/analytics.d.ts.map +1 -0
  28. package/dist/{analytics → plugins/analytics}/analytics.js +9 -9
  29. package/dist/plugins/analytics/analytics.js.map +1 -0
  30. package/dist/{analytics → plugins/analytics}/defaults.js +1 -1
  31. package/dist/plugins/analytics/defaults.js.map +1 -0
  32. package/dist/{analytics → plugins/analytics}/query.js +6 -6
  33. package/dist/plugins/analytics/query.js.map +1 -0
  34. package/dist/plugins/analytics/types.d.ts +9 -0
  35. package/dist/plugins/analytics/types.d.ts.map +1 -0
  36. package/dist/plugins/index.js +5 -0
  37. package/dist/{server → plugins/server}/base-server.js +1 -1
  38. package/dist/plugins/server/base-server.js.map +1 -0
  39. package/dist/{server → plugins/server}/index.d.ts +3 -3
  40. package/dist/plugins/server/index.d.ts.map +1 -0
  41. package/dist/{server → plugins/server}/index.js +10 -10
  42. package/dist/plugins/server/index.js.map +1 -0
  43. package/dist/{server → plugins/server}/remote-tunnel/gate.js +1 -1
  44. package/dist/plugins/server/remote-tunnel/gate.js.map +1 -0
  45. package/dist/{server → plugins/server}/remote-tunnel/remote-tunnel-controller.js +2 -2
  46. package/dist/plugins/server/remote-tunnel/remote-tunnel-controller.js.map +1 -0
  47. package/dist/{server → plugins/server}/remote-tunnel/remote-tunnel-manager.js +24 -3
  48. package/dist/plugins/server/remote-tunnel/remote-tunnel-manager.js.map +1 -0
  49. package/dist/{server → plugins/server}/static-server.js +1 -1
  50. package/dist/plugins/server/static-server.js.map +1 -0
  51. package/dist/{server → plugins/server}/types.d.ts +3 -3
  52. package/dist/plugins/server/types.d.ts.map +1 -0
  53. package/dist/{server → plugins/server}/utils.js +1 -1
  54. package/dist/plugins/server/utils.js.map +1 -0
  55. package/dist/{server → plugins/server}/vite-dev-server.js +6 -6
  56. package/dist/plugins/server/vite-dev-server.js.map +1 -0
  57. package/dist/telemetry/telemetry-provider.js.map +1 -1
  58. package/docs/docs/api/appkit/Class.AppKitError/index.html +3 -3
  59. package/docs/docs/api/appkit/Class.AuthenticationError/index.html +3 -3
  60. package/docs/docs/api/appkit/Class.ConfigurationError/index.html +3 -3
  61. package/docs/docs/api/appkit/Class.ConnectionError/index.html +3 -3
  62. package/docs/docs/api/appkit/Class.ExecutionError/index.html +3 -3
  63. package/docs/docs/api/appkit/Class.InitializationError/index.html +3 -3
  64. package/docs/docs/api/appkit/Class.Plugin/index.html +3 -3
  65. package/docs/docs/api/appkit/Class.ServerError/index.html +3 -3
  66. package/docs/docs/api/appkit/Class.TunnelError/index.html +3 -3
  67. package/docs/docs/api/appkit/Class.ValidationError/index.html +3 -3
  68. package/docs/docs/api/appkit/Function.appKitTypesPlugin/index.html +3 -3
  69. package/docs/docs/api/appkit/Function.createApp/index.html +3 -3
  70. package/docs/docs/api/appkit/Function.getExecutionContext/index.html +3 -3
  71. package/docs/docs/api/appkit/Function.isSQLTypeMarker/index.html +3 -3
  72. package/docs/docs/api/appkit/Interface.BasePluginConfig/index.html +3 -3
  73. package/docs/docs/api/appkit/Interface.CacheConfig/index.html +3 -3
  74. package/docs/docs/api/appkit/Interface.ITelemetry/index.html +3 -3
  75. package/docs/docs/api/appkit/Interface.StreamExecutionSettings/index.html +3 -3
  76. package/docs/docs/api/appkit/Interface.TelemetryConfig/index.html +3 -3
  77. package/docs/docs/api/appkit/TypeAlias.IAppRouter/index.html +3 -3
  78. package/docs/docs/api/appkit/Variable.sql/index.html +3 -3
  79. package/docs/docs/api/appkit/index.html +3 -3
  80. package/docs/docs/api/appkit-ui/data/AreaChart/index.html +3 -3
  81. package/docs/docs/api/appkit-ui/data/BarChart/index.html +3 -3
  82. package/docs/docs/api/appkit-ui/data/DataTable/index.html +3 -3
  83. package/docs/docs/api/appkit-ui/data/DonutChart/index.html +3 -3
  84. package/docs/docs/api/appkit-ui/data/HeatmapChart/index.html +3 -3
  85. package/docs/docs/api/appkit-ui/data/LineChart/index.html +3 -3
  86. package/docs/docs/api/appkit-ui/data/PieChart/index.html +3 -3
  87. package/docs/docs/api/appkit-ui/data/RadarChart/index.html +3 -3
  88. package/docs/docs/api/appkit-ui/data/ScatterChart/index.html +3 -3
  89. package/docs/docs/api/appkit-ui/index.html +3 -3
  90. package/docs/docs/api/appkit-ui/styling/index.html +3 -3
  91. package/docs/docs/api/appkit-ui/ui/Accordion/index.html +3 -3
  92. package/docs/docs/api/appkit-ui/ui/Alert/index.html +3 -3
  93. package/docs/docs/api/appkit-ui/ui/AlertDialog/index.html +3 -3
  94. package/docs/docs/api/appkit-ui/ui/AspectRatio/index.html +3 -3
  95. package/docs/docs/api/appkit-ui/ui/Avatar/index.html +3 -3
  96. package/docs/docs/api/appkit-ui/ui/Badge/index.html +3 -3
  97. package/docs/docs/api/appkit-ui/ui/Breadcrumb/index.html +3 -3
  98. package/docs/docs/api/appkit-ui/ui/Button/index.html +3 -3
  99. package/docs/docs/api/appkit-ui/ui/ButtonGroup/index.html +3 -3
  100. package/docs/docs/api/appkit-ui/ui/Calendar/index.html +3 -3
  101. package/docs/docs/api/appkit-ui/ui/Card/index.html +3 -3
  102. package/docs/docs/api/appkit-ui/ui/Carousel/index.html +3 -3
  103. package/docs/docs/api/appkit-ui/ui/ChartContainer/index.html +3 -3
  104. package/docs/docs/api/appkit-ui/ui/Checkbox/index.html +3 -3
  105. package/docs/docs/api/appkit-ui/ui/Collapsible/index.html +3 -3
  106. package/docs/docs/api/appkit-ui/ui/Command/index.html +3 -3
  107. package/docs/docs/api/appkit-ui/ui/ContextMenu/index.html +3 -3
  108. package/docs/docs/api/appkit-ui/ui/Dialog/index.html +3 -3
  109. package/docs/docs/api/appkit-ui/ui/Drawer/index.html +3 -3
  110. package/docs/docs/api/appkit-ui/ui/DropdownMenu/index.html +3 -3
  111. package/docs/docs/api/appkit-ui/ui/Empty/index.html +3 -3
  112. package/docs/docs/api/appkit-ui/ui/Field/index.html +3 -3
  113. package/docs/docs/api/appkit-ui/ui/FormControl/index.html +3 -3
  114. package/docs/docs/api/appkit-ui/ui/HoverCard/index.html +3 -3
  115. package/docs/docs/api/appkit-ui/ui/Input/index.html +3 -3
  116. package/docs/docs/api/appkit-ui/ui/InputGroup/index.html +3 -3
  117. package/docs/docs/api/appkit-ui/ui/InputOTP/index.html +3 -3
  118. package/docs/docs/api/appkit-ui/ui/Item/index.html +3 -3
  119. package/docs/docs/api/appkit-ui/ui/Kbd/index.html +3 -3
  120. package/docs/docs/api/appkit-ui/ui/Label/index.html +3 -3
  121. package/docs/docs/api/appkit-ui/ui/Menubar/index.html +3 -3
  122. package/docs/docs/api/appkit-ui/ui/NavigationMenu/index.html +3 -3
  123. package/docs/docs/api/appkit-ui/ui/Pagination/index.html +3 -3
  124. package/docs/docs/api/appkit-ui/ui/Popover/index.html +3 -3
  125. package/docs/docs/api/appkit-ui/ui/Progress/index.html +3 -3
  126. package/docs/docs/api/appkit-ui/ui/RadioGroup/index.html +3 -3
  127. package/docs/docs/api/appkit-ui/ui/ResizableHandle/index.html +3 -3
  128. package/docs/docs/api/appkit-ui/ui/ScrollArea/index.html +3 -3
  129. package/docs/docs/api/appkit-ui/ui/Select/index.html +3 -3
  130. package/docs/docs/api/appkit-ui/ui/Separator/index.html +3 -3
  131. package/docs/docs/api/appkit-ui/ui/Sheet/index.html +3 -3
  132. package/docs/docs/api/appkit-ui/ui/Sidebar/index.html +3 -3
  133. package/docs/docs/api/appkit-ui/ui/Skeleton/index.html +3 -3
  134. package/docs/docs/api/appkit-ui/ui/Slider/index.html +3 -3
  135. package/docs/docs/api/appkit-ui/ui/Spinner/index.html +3 -3
  136. package/docs/docs/api/appkit-ui/ui/Switch/index.html +3 -3
  137. package/docs/docs/api/appkit-ui/ui/Table/index.html +3 -3
  138. package/docs/docs/api/appkit-ui/ui/Tabs/index.html +3 -3
  139. package/docs/docs/api/appkit-ui/ui/Textarea/index.html +3 -3
  140. package/docs/docs/api/appkit-ui/ui/Toaster/index.html +3 -3
  141. package/docs/docs/api/appkit-ui/ui/Toggle/index.html +3 -3
  142. package/docs/docs/api/appkit-ui/ui/ToggleGroup/index.html +3 -3
  143. package/docs/docs/api/appkit-ui/ui/Tooltip/index.html +3 -3
  144. package/docs/docs/api/index.html +3 -3
  145. package/docs/docs/app-management/index.html +5 -5
  146. package/docs/docs/app-management.md +2 -2
  147. package/docs/docs/architecture/index.html +3 -3
  148. package/docs/docs/category/development/index.html +3 -3
  149. package/docs/docs/configuration/index.html +3 -3
  150. package/docs/docs/core-principles/index.html +3 -3
  151. package/docs/docs/development/index.html +5 -5
  152. package/docs/docs/development/llm-guide/index.html +3 -3
  153. package/docs/docs/development/local-development/index.html +5 -5
  154. package/docs/docs/development/local-development.md +2 -2
  155. package/docs/docs/development/project-setup/index.html +3 -3
  156. package/docs/docs/development/remote-bridge/index.html +5 -5
  157. package/docs/docs/development/remote-bridge.md +2 -2
  158. package/docs/docs/development/type-generation/index.html +3 -3
  159. package/docs/docs/development.md +2 -2
  160. package/docs/docs/index.html +5 -5
  161. package/docs/docs/plugins/index.html +3 -3
  162. package/docs/docs.md +2 -2
  163. package/package.json +1 -1
  164. package/dist/analytics/analytics.d.ts.map +0 -1
  165. package/dist/analytics/analytics.js.map +0 -1
  166. package/dist/analytics/defaults.js.map +0 -1
  167. package/dist/analytics/query.js.map +0 -1
  168. package/dist/analytics/types.d.ts +0 -9
  169. package/dist/analytics/types.d.ts.map +0 -1
  170. package/dist/server/base-server.js.map +0 -1
  171. package/dist/server/index.d.ts.map +0 -1
  172. package/dist/server/index.js.map +0 -1
  173. package/dist/server/remote-tunnel/gate.js.map +0 -1
  174. package/dist/server/remote-tunnel/remote-tunnel-controller.js.map +0 -1
  175. package/dist/server/remote-tunnel/remote-tunnel-manager.js.map +0 -1
  176. package/dist/server/static-server.js.map +0 -1
  177. package/dist/server/types.d.ts.map +0 -1
  178. package/dist/server/utils.js.map +0 -1
  179. package/dist/server/vite-dev-server.js.map +0 -1
  180. /package/dist/{analytics → plugins/analytics}/index.js +0 -0
  181. /package/dist/{server → plugins/server}/remote-tunnel/denied.html +0 -0
  182. /package/dist/{server → plugins/server}/remote-tunnel/index.html +0 -0
  183. /package/dist/{server → plugins/server}/remote-tunnel/wait.html +0 -0
@@ -5,20 +5,29 @@ interface RequestLike {
5
5
  }
6
6
  interface DevFileReader {
7
7
  readFile(filePath: string, req: RequestLike): Promise<string>;
8
+ readdir(dirPath: string, req: RequestLike): Promise<string[]>;
8
9
  }
9
10
  interface QueryResult {
10
11
  query: string;
11
12
  isAsUser: boolean;
12
13
  }
13
14
  declare class AppManager {
15
+ private readonly queriesDir;
16
+ /**
17
+ * Validates that a file path is within the queries directory
18
+ */
19
+ private validatePath;
20
+ /**
21
+ * Creates a filesystem adapter based on dev mode or production mode
22
+ */
23
+ private createFsAdapter;
14
24
  /**
15
25
  * Retrieves a query file by key from the queries directory
16
26
  * In dev mode with a request context, reads from local filesystem via WebSocket
17
27
  * @param queryKey - The query file name (without extension)
18
28
  * @param req - Optional request object to detect dev mode
19
29
  * @param devFileReader - Optional DevFileReader instance to read files from local filesystem
20
- * @returns The query content as a string
21
- * @throws Error if query key is invalid or file not found
30
+ * @returns The query content and execution mode (as user or as service principal)
22
31
  */
23
32
  getAppQuery(queryKey: string, req?: RequestLike, devFileReader?: DevFileReader): Promise<QueryResult | null>;
24
33
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/app/index.ts"],"sourcesContent":[],"mappings":";UAMU,WAAA;EAAA,KAAA,CAAA,EACA,MADW,CAAA,MAAA,EAAA,GAAA,CAAA;EAAA,OAAA,EAEV,MAFU,CAAA,MAAA,EAAA,MAAA,GAAA,MAAA,EAAA,GAAA,SAAA,CAAA;;UAKX,aAAA,CAHC;EAAM,QAAA,CAAA,QAAA,EAAA,MAAA,EAAA,GAAA,EAIiB,WAJjB,CAAA,EAI+B,OAJ/B,CAAA,MAAA,CAAA;AAAA;UAOP,WAAA,CAJa;OACW,EAAA,MAAA;UAAc,EAAA,OAAA;;AAGtC,cAKG,UAAA,CALQ;EAKR;;;;;;;;;sCAYH,6BACU,gBACf,QAAQ"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/app/index.ts"],"sourcesContent":[],"mappings":";UAMU,WAAA;EAAA,KAAA,CAAA,EACA,MADW,CAAA,MAAA,EAAA,GAAA,CAAA;EAAA,OAAA,EAEV,MAFU,CAAA,MAAA,EAAA,MAAA,GAAA,MAAA,EAAA,GAAA,SAAA,CAAA;;UAKX,aAAA,CAHC;EAAM,QAAA,CAAA,QAAA,EAAA,MAAA,EAAA,GAAA,EAIiB,WAJjB,CAAA,EAI+B,OAJ/B,CAAA,MAAA,CAAA;EAGP,OAAA,CAAA,OAAA,EAAa,MAAA,EAAA,GAAA,EAES,WAFT,CAAA,EAEuB,OAFvB,CAAA,MAAA,EAAA,CAAA;;UAKb,WAAA,CAJwB;OAAc,EAAA,MAAA;UAChB,EAAA,OAAA;;AAAqB,cAgBxC,UAAA,CAhBwC;EAG3C,iBAAW,UAAA;EAaR;;;UA4DO,YAAA;;;;;;;;;;;;;sCADV,6BACU,gBACf,QAAQ"}
package/dist/app/index.js CHANGED
@@ -5,71 +5,85 @@ import path from "node:path";
5
5
  //#region src/app/index.ts
6
6
  const logger = createLogger("app");
7
7
  var AppManager = class {
8
+ queriesDir = path.resolve(process.cwd(), "config/queries");
9
+ /**
10
+ * Validates that a file path is within the queries directory
11
+ */
12
+ validatePath(fileName) {
13
+ const queryFilePath = path.join(this.queriesDir, fileName);
14
+ const resolvedPath = path.resolve(queryFilePath);
15
+ const resolvedQueriesDir = path.resolve(this.queriesDir);
16
+ if (!resolvedPath.startsWith(resolvedQueriesDir)) {
17
+ logger.error("Invalid query path: path traversal detected");
18
+ return null;
19
+ }
20
+ return resolvedPath;
21
+ }
22
+ /**
23
+ * Creates a filesystem adapter based on dev mode or production mode
24
+ */
25
+ createFsAdapter(req, devFileReader) {
26
+ if (req?.query?.dev !== void 0 && devFileReader && req) return {
27
+ readdir: async (dirPath) => {
28
+ const relativePath = path.relative(process.cwd(), dirPath);
29
+ return devFileReader.readdir(relativePath, req);
30
+ },
31
+ readFile: async (filePath) => {
32
+ const relativePath = path.relative(process.cwd(), filePath);
33
+ return devFileReader.readFile(relativePath, req);
34
+ }
35
+ };
36
+ return {
37
+ readdir: (dirPath) => fs.readdir(dirPath),
38
+ readFile: (filePath) => fs.readFile(filePath, "utf8")
39
+ };
40
+ }
8
41
  /**
9
42
  * Retrieves a query file by key from the queries directory
10
43
  * In dev mode with a request context, reads from local filesystem via WebSocket
11
44
  * @param queryKey - The query file name (without extension)
12
45
  * @param req - Optional request object to detect dev mode
13
46
  * @param devFileReader - Optional DevFileReader instance to read files from local filesystem
14
- * @returns The query content as a string
15
- * @throws Error if query key is invalid or file not found
47
+ * @returns The query content and execution mode (as user or as service principal)
16
48
  */
17
49
  async getAppQuery(queryKey, req, devFileReader) {
18
50
  if (!queryKey || !/^[a-zA-Z0-9_-]+$/.test(queryKey)) {
19
51
  logger.error("Invalid query key format: %s. Only alphanumeric characters, underscores, and hyphens are allowed.", queryKey);
20
52
  return null;
21
53
  }
22
- const queriesDir = path.resolve(process.cwd(), "config/queries");
54
+ const fsAdapter = this.createFsAdapter(req, devFileReader);
23
55
  const oboFileName = `${queryKey}.obo.sql`;
24
56
  const defaultFileName = `${queryKey}.sql`;
25
- let queryFileName = null;
26
- let isAsUser = false;
57
+ let files;
27
58
  try {
28
- const files = await fs.readdir(queriesDir);
29
- if (files.includes(oboFileName)) {
30
- queryFileName = oboFileName;
31
- isAsUser = true;
32
- if (files.includes(defaultFileName)) logger.warn(`Both ${oboFileName} and ${defaultFileName} found for query ${queryKey}. Using ${oboFileName}.`);
33
- } else if (files.includes(defaultFileName)) {
34
- queryFileName = defaultFileName;
35
- isAsUser = false;
36
- }
59
+ files = await fsAdapter.readdir(this.queriesDir);
37
60
  } catch (error) {
38
61
  logger.error(`Failed to read queries directory: ${error.message}`);
39
62
  return null;
40
63
  }
64
+ let queryFileName = null;
65
+ let isAsUser = false;
66
+ if (files.includes(oboFileName)) {
67
+ queryFileName = oboFileName;
68
+ isAsUser = true;
69
+ if (files.includes(defaultFileName)) logger.warn(`Both ${oboFileName} and ${defaultFileName} found for query ${queryKey}. Using ${oboFileName}.`);
70
+ } else if (files.includes(defaultFileName)) {
71
+ queryFileName = defaultFileName;
72
+ isAsUser = false;
73
+ }
41
74
  if (!queryFileName) {
42
75
  logger.error(`Query file not found: ${queryKey}`);
43
76
  return null;
44
77
  }
45
- const queryFilePath = path.join(queriesDir, queryFileName);
46
- const resolvedPath = path.resolve(queryFilePath);
47
- const resolvedQueriesDir = path.resolve(queriesDir);
48
- if (!resolvedPath.startsWith(resolvedQueriesDir)) {
49
- logger.error(`Invalid query path: path traversal detected`);
50
- return null;
51
- }
52
- if (req?.query?.dev !== void 0 && devFileReader && req) try {
53
- const relativePath = path.relative(process.cwd(), resolvedPath);
54
- return {
55
- query: await devFileReader.readFile(relativePath, req),
56
- isAsUser
57
- };
58
- } catch (error) {
59
- logger.error(`Failed to read query from dev tunnel: ${error.message}`);
60
- return null;
61
- }
78
+ const resolvedPath = this.validatePath(queryFileName);
79
+ if (!resolvedPath) return null;
62
80
  try {
63
81
  return {
64
- query: await fs.readFile(resolvedPath, "utf8"),
82
+ query: await fsAdapter.readFile(resolvedPath),
65
83
  isAsUser
66
84
  };
67
85
  } catch (error) {
68
- if (error.code === "ENOENT") {
69
- logger.error(`Failed to read query from server filesystem: ${error.message}`);
70
- return null;
71
- }
72
- logger.error(`Failed to read query from server filesystem: ${error.message}`);
86
+ logger.error(`Failed to read query file: ${error.message}`);
73
87
  return null;
74
88
  }
75
89
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/app/index.ts"],"sourcesContent":["import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { createLogger } from \"../logging/logger\";\n\nconst logger = createLogger(\"app\");\n\ninterface RequestLike {\n query?: Record<string, any>;\n headers: Record<string, string | string[] | undefined>;\n}\n\ninterface DevFileReader {\n readFile(filePath: string, req: RequestLike): Promise<string>;\n}\n\ninterface QueryResult {\n query: string;\n isAsUser: boolean;\n}\n\nexport class AppManager {\n /**\n * Retrieves a query file by key from the queries directory\n * In dev mode with a request context, reads from local filesystem via WebSocket\n * @param queryKey - The query file name (without extension)\n * @param req - Optional request object to detect dev mode\n * @param devFileReader - Optional DevFileReader instance to read files from local filesystem\n * @returns The query content as a string\n * @throws Error if query key is invalid or file not found\n */\n async getAppQuery(\n queryKey: string,\n req?: RequestLike,\n devFileReader?: DevFileReader,\n ): Promise<QueryResult | null> {\n // Security: Sanitize query key to prevent path traversal\n if (!queryKey || !/^[a-zA-Z0-9_-]+$/.test(queryKey)) {\n logger.error(\n \"Invalid query key format: %s. Only alphanumeric characters, underscores, and hyphens are allowed.\",\n queryKey,\n );\n return null;\n }\n\n const queriesDir = path.resolve(process.cwd(), \"config/queries\");\n\n // priority order: .obo.sql first (asUser), then .sql (default)\n const oboFileName = `${queryKey}.obo.sql`;\n const defaultFileName = `${queryKey}.sql`;\n\n let queryFileName: string | null = null;\n let isAsUser: boolean = false;\n\n try {\n const files = await fs.readdir(queriesDir);\n\n // check for OBO query first\n if (files.includes(oboFileName)) {\n queryFileName = oboFileName;\n isAsUser = true;\n\n // check for both files and warn if both are present\n if (files.includes(defaultFileName)) {\n logger.warn(\n `Both ${oboFileName} and ${defaultFileName} found for query ${queryKey}. Using ${oboFileName}.`,\n );\n }\n // check for default query if OBO query is not present\n } else if (files.includes(defaultFileName)) {\n queryFileName = defaultFileName;\n isAsUser = false;\n }\n } catch (error) {\n logger.error(\n `Failed to read queries directory: ${(error as Error).message}`,\n );\n return null;\n }\n\n if (!queryFileName) {\n logger.error(`Query file not found: ${queryKey}`);\n return null;\n }\n\n const queryFilePath = path.join(queriesDir, queryFileName);\n\n // security: validate resolved path is within queries directory\n const resolvedPath = path.resolve(queryFilePath);\n const resolvedQueriesDir = path.resolve(queriesDir);\n\n if (!resolvedPath.startsWith(resolvedQueriesDir)) {\n logger.error(`Invalid query path: path traversal detected`);\n return null;\n }\n\n // check if we're in dev mode and should use WebSocket\n const isDevMode = req?.query?.dev !== undefined;\n if (isDevMode && devFileReader && req) {\n try {\n const relativePath = path.relative(process.cwd(), resolvedPath);\n return {\n query: await devFileReader.readFile(relativePath, req),\n isAsUser,\n };\n } catch (error) {\n logger.error(\n `Failed to read query from dev tunnel: ${(error as Error).message}`,\n );\n return null;\n }\n }\n\n // production mode: read from server filesystem\n try {\n const query = await fs.readFile(resolvedPath, \"utf8\");\n return { query, isAsUser };\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === \"ENOENT\") {\n logger.error(\n `Failed to read query from server filesystem: ${(error as Error).message}`,\n );\n return null;\n }\n\n logger.error(\n `Failed to read query from server filesystem: ${(error as Error).message}`,\n );\n return null;\n }\n }\n}\n\nexport type { DevFileReader, QueryResult, RequestLike };\n"],"mappings":";;;;;AAIA,MAAM,SAAS,aAAa,MAAM;AAgBlC,IAAa,aAAb,MAAwB;;;;;;;;;;CAUtB,MAAM,YACJ,UACA,KACA,eAC6B;AAE7B,MAAI,CAAC,YAAY,CAAC,mBAAmB,KAAK,SAAS,EAAE;AACnD,UAAO,MACL,qGACA,SACD;AACD,UAAO;;EAGT,MAAM,aAAa,KAAK,QAAQ,QAAQ,KAAK,EAAE,iBAAiB;EAGhE,MAAM,cAAc,GAAG,SAAS;EAChC,MAAM,kBAAkB,GAAG,SAAS;EAEpC,IAAI,gBAA+B;EACnC,IAAI,WAAoB;AAExB,MAAI;GACF,MAAM,QAAQ,MAAM,GAAG,QAAQ,WAAW;AAG1C,OAAI,MAAM,SAAS,YAAY,EAAE;AAC/B,oBAAgB;AAChB,eAAW;AAGX,QAAI,MAAM,SAAS,gBAAgB,CACjC,QAAO,KACL,QAAQ,YAAY,OAAO,gBAAgB,mBAAmB,SAAS,UAAU,YAAY,GAC9F;cAGM,MAAM,SAAS,gBAAgB,EAAE;AAC1C,oBAAgB;AAChB,eAAW;;WAEN,OAAO;AACd,UAAO,MACL,qCAAsC,MAAgB,UACvD;AACD,UAAO;;AAGT,MAAI,CAAC,eAAe;AAClB,UAAO,MAAM,yBAAyB,WAAW;AACjD,UAAO;;EAGT,MAAM,gBAAgB,KAAK,KAAK,YAAY,cAAc;EAG1D,MAAM,eAAe,KAAK,QAAQ,cAAc;EAChD,MAAM,qBAAqB,KAAK,QAAQ,WAAW;AAEnD,MAAI,CAAC,aAAa,WAAW,mBAAmB,EAAE;AAChD,UAAO,MAAM,8CAA8C;AAC3D,UAAO;;AAKT,MADkB,KAAK,OAAO,QAAQ,UACrB,iBAAiB,IAChC,KAAI;GACF,MAAM,eAAe,KAAK,SAAS,QAAQ,KAAK,EAAE,aAAa;AAC/D,UAAO;IACL,OAAO,MAAM,cAAc,SAAS,cAAc,IAAI;IACtD;IACD;WACM,OAAO;AACd,UAAO,MACL,yCAA0C,MAAgB,UAC3D;AACD,UAAO;;AAKX,MAAI;AAEF,UAAO;IAAE,OADK,MAAM,GAAG,SAAS,cAAc,OAAO;IACrC;IAAU;WACnB,OAAO;AACd,OAAK,MAAgC,SAAS,UAAU;AACtD,WAAO,MACL,gDAAiD,MAAgB,UAClE;AACD,WAAO;;AAGT,UAAO,MACL,gDAAiD,MAAgB,UAClE;AACD,UAAO"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/app/index.ts"],"sourcesContent":["import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { createLogger } from \"../logging/logger\";\n\nconst logger = createLogger(\"app\");\n\ninterface RequestLike {\n query?: Record<string, any>;\n headers: Record<string, string | string[] | undefined>;\n}\n\ninterface DevFileReader {\n readFile(filePath: string, req: RequestLike): Promise<string>;\n readdir(dirPath: string, req: RequestLike): Promise<string[]>;\n}\n\ninterface QueryResult {\n query: string;\n isAsUser: boolean;\n}\n\n/**\n * Abstraction for filesystem operations that works in both dev and production modes\n */\ninterface FileSystemAdapter {\n readdir(dirPath: string): Promise<string[]>;\n readFile(filePath: string): Promise<string>;\n}\n\nexport class AppManager {\n private readonly queriesDir = path.resolve(process.cwd(), \"config/queries\");\n\n /**\n * Validates that a file path is within the queries directory\n */\n private validatePath(fileName: string): string | null {\n const queryFilePath = path.join(this.queriesDir, fileName);\n const resolvedPath = path.resolve(queryFilePath);\n const resolvedQueriesDir = path.resolve(this.queriesDir);\n\n if (!resolvedPath.startsWith(resolvedQueriesDir)) {\n logger.error(\"Invalid query path: path traversal detected\");\n return null;\n }\n\n return resolvedPath;\n }\n\n /**\n * Creates a filesystem adapter based on dev mode or production mode\n */\n private createFsAdapter(\n req?: RequestLike,\n devFileReader?: DevFileReader,\n ): FileSystemAdapter {\n const isDevMode = req?.query?.dev !== undefined;\n\n if (isDevMode && devFileReader && req) {\n // Dev mode: use WebSocket tunnel to read from local filesystem\n return {\n readdir: async (dirPath: string) => {\n const relativePath = path.relative(process.cwd(), dirPath);\n return devFileReader.readdir(relativePath, req);\n },\n readFile: async (filePath: string) => {\n const relativePath = path.relative(process.cwd(), filePath);\n return devFileReader.readFile(relativePath, req);\n },\n };\n }\n\n // Production mode: use server filesystem\n return {\n readdir: (dirPath: string) => fs.readdir(dirPath),\n readFile: (filePath: string) => fs.readFile(filePath, \"utf8\"),\n };\n }\n\n /**\n * Retrieves a query file by key from the queries directory\n * In dev mode with a request context, reads from local filesystem via WebSocket\n * @param queryKey - The query file name (without extension)\n * @param req - Optional request object to detect dev mode\n * @param devFileReader - Optional DevFileReader instance to read files from local filesystem\n * @returns The query content and execution mode (as user or as service principal)\n */\n async getAppQuery(\n queryKey: string,\n req?: RequestLike,\n devFileReader?: DevFileReader,\n ): Promise<QueryResult | null> {\n // Security: Sanitize query key to prevent path traversal\n if (!queryKey || !/^[a-zA-Z0-9_-]+$/.test(queryKey)) {\n logger.error(\n \"Invalid query key format: %s. Only alphanumeric characters, underscores, and hyphens are allowed.\",\n queryKey,\n );\n return null;\n }\n\n // Create filesystem adapter for dev or production mode\n const fsAdapter = this.createFsAdapter(req, devFileReader);\n\n // Priority order: .obo.sql first (as user), then .sql (as service principal)\n const oboFileName = `${queryKey}.obo.sql`;\n const defaultFileName = `${queryKey}.sql`;\n\n // List directory to find which query file exists\n let files: string[];\n try {\n files = await fsAdapter.readdir(this.queriesDir);\n } catch (error) {\n logger.error(\n `Failed to read queries directory: ${(error as Error).message}`,\n );\n return null;\n }\n\n // Determine which query file to use\n let queryFileName: string | null = null;\n let isAsUser = false;\n\n if (files.includes(oboFileName)) {\n queryFileName = oboFileName;\n isAsUser = true;\n\n // Warn if both variants exist\n if (files.includes(defaultFileName)) {\n logger.warn(\n `Both ${oboFileName} and ${defaultFileName} found for query ${queryKey}. Using ${oboFileName}.`,\n );\n }\n } else if (files.includes(defaultFileName)) {\n queryFileName = defaultFileName;\n isAsUser = false;\n }\n\n if (!queryFileName) {\n logger.error(`Query file not found: ${queryKey}`);\n return null;\n }\n\n // Validate and resolve the file path\n const resolvedPath = this.validatePath(queryFileName);\n if (!resolvedPath) {\n return null;\n }\n\n // Read the query file\n try {\n const query = await fsAdapter.readFile(resolvedPath);\n return { query, isAsUser };\n } catch (error) {\n logger.error(`Failed to read query file: ${(error as Error).message}`);\n return null;\n }\n }\n}\n\nexport type { DevFileReader, QueryResult, RequestLike };\n"],"mappings":";;;;;AAIA,MAAM,SAAS,aAAa,MAAM;AAyBlC,IAAa,aAAb,MAAwB;CACtB,AAAiB,aAAa,KAAK,QAAQ,QAAQ,KAAK,EAAE,iBAAiB;;;;CAK3E,AAAQ,aAAa,UAAiC;EACpD,MAAM,gBAAgB,KAAK,KAAK,KAAK,YAAY,SAAS;EAC1D,MAAM,eAAe,KAAK,QAAQ,cAAc;EAChD,MAAM,qBAAqB,KAAK,QAAQ,KAAK,WAAW;AAExD,MAAI,CAAC,aAAa,WAAW,mBAAmB,EAAE;AAChD,UAAO,MAAM,8CAA8C;AAC3D,UAAO;;AAGT,SAAO;;;;;CAMT,AAAQ,gBACN,KACA,eACmB;AAGnB,MAFkB,KAAK,OAAO,QAAQ,UAErB,iBAAiB,IAEhC,QAAO;GACL,SAAS,OAAO,YAAoB;IAClC,MAAM,eAAe,KAAK,SAAS,QAAQ,KAAK,EAAE,QAAQ;AAC1D,WAAO,cAAc,QAAQ,cAAc,IAAI;;GAEjD,UAAU,OAAO,aAAqB;IACpC,MAAM,eAAe,KAAK,SAAS,QAAQ,KAAK,EAAE,SAAS;AAC3D,WAAO,cAAc,SAAS,cAAc,IAAI;;GAEnD;AAIH,SAAO;GACL,UAAU,YAAoB,GAAG,QAAQ,QAAQ;GACjD,WAAW,aAAqB,GAAG,SAAS,UAAU,OAAO;GAC9D;;;;;;;;;;CAWH,MAAM,YACJ,UACA,KACA,eAC6B;AAE7B,MAAI,CAAC,YAAY,CAAC,mBAAmB,KAAK,SAAS,EAAE;AACnD,UAAO,MACL,qGACA,SACD;AACD,UAAO;;EAIT,MAAM,YAAY,KAAK,gBAAgB,KAAK,cAAc;EAG1D,MAAM,cAAc,GAAG,SAAS;EAChC,MAAM,kBAAkB,GAAG,SAAS;EAGpC,IAAI;AACJ,MAAI;AACF,WAAQ,MAAM,UAAU,QAAQ,KAAK,WAAW;WACzC,OAAO;AACd,UAAO,MACL,qCAAsC,MAAgB,UACvD;AACD,UAAO;;EAIT,IAAI,gBAA+B;EACnC,IAAI,WAAW;AAEf,MAAI,MAAM,SAAS,YAAY,EAAE;AAC/B,mBAAgB;AAChB,cAAW;AAGX,OAAI,MAAM,SAAS,gBAAgB,CACjC,QAAO,KACL,QAAQ,YAAY,OAAO,gBAAgB,mBAAmB,SAAS,UAAU,YAAY,GAC9F;aAEM,MAAM,SAAS,gBAAgB,EAAE;AAC1C,mBAAgB;AAChB,cAAW;;AAGb,MAAI,CAAC,eAAe;AAClB,UAAO,MAAM,yBAAyB,WAAW;AACjD,UAAO;;EAIT,MAAM,eAAe,KAAK,aAAa,cAAc;AACrD,MAAI,CAAC,aACH,QAAO;AAIT,MAAI;AAEF,UAAO;IAAE,OADK,MAAM,UAAU,SAAS,aAAa;IACpC;IAAU;WACnB,OAAO;AACd,UAAO,MAAM,8BAA+B,MAAgB,UAAU;AACtE,UAAO"}
@@ -1,6 +1,6 @@
1
1
  //#region package.json
2
2
  var name = "@databricks/appkit";
3
- var version = "0.5.0";
3
+ var version = "0.5.2";
4
4
 
5
5
  //#endregion
6
6
  export { name, version };
@@ -1,6 +1,6 @@
1
1
  import fs from "node:fs";
2
- import { fileURLToPath } from "node:url";
3
2
  import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
4
  import { Command } from "commander";
5
5
 
6
6
  //#region src/cli/commands/docs.ts
@@ -1 +1 @@
1
- {"version":3,"file":"docs.js","names":[],"sources":["../../../src/cli/commands/docs.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\n\nfunction findPackageRoot(): string {\n let dir = __dirname;\n while (dir !== path.parse(dir).root) {\n if (fs.existsSync(path.join(dir, \"package.json\"))) {\n return dir;\n }\n dir = path.dirname(dir);\n }\n throw new Error(\"Could not find package root\");\n}\n\nfunction runDocs(docPath?: string) {\n const packageRoot = findPackageRoot();\n\n if (!docPath) {\n // Display llms.txt by default\n const llmsPath = path.join(packageRoot, \"llms.txt\");\n\n if (!fs.existsSync(llmsPath)) {\n console.error(\"Error: llms.txt not found in package\");\n process.exit(1);\n }\n\n const content = fs.readFileSync(llmsPath, \"utf-8\");\n console.log(content);\n return;\n }\n\n // Handle path - remove leading ./ and / first, then strip prefixes\n let normalizedPath = docPath;\n\n // Strip leading ./ or /\n normalizedPath = normalizedPath.replace(/^\\.\\//, \"\");\n normalizedPath = normalizedPath.replace(/^\\//, \"\");\n\n // Remove /appkit/docs/ or docs/ prefix since files are in packageRoot/docs/\n normalizedPath = normalizedPath.replace(/^appkit\\/docs\\//, \"\");\n normalizedPath = normalizedPath.replace(/^docs\\//, \"\");\n\n const fullPath = path.join(packageRoot, \"docs\", normalizedPath);\n\n if (!fs.existsSync(fullPath)) {\n console.error(`Error: Documentation file not found: ${docPath}`);\n console.error(`Tried: ${fullPath}`);\n process.exit(1);\n }\n\n const content = fs.readFileSync(fullPath, \"utf-8\");\n console.log(content);\n}\n\nexport const docsCommand = new Command(\"docs\")\n .description(\"Display embedded documentation\")\n .argument(\n \"[path]\",\n \"Path to specific documentation file (e.g., /appkit/docs/api/appkit-ui/components/Sidebar.md)\",\n )\n .action(runDocs);\n"],"mappings":";;;;;;AAKA,MAAM,aAAa,cAAc,OAAO,KAAK,IAAI;AACjD,MAAM,YAAY,KAAK,QAAQ,WAAW;AAE1C,SAAS,kBAA0B;CACjC,IAAI,MAAM;AACV,QAAO,QAAQ,KAAK,MAAM,IAAI,CAAC,MAAM;AACnC,MAAI,GAAG,WAAW,KAAK,KAAK,KAAK,eAAe,CAAC,CAC/C,QAAO;AAET,QAAM,KAAK,QAAQ,IAAI;;AAEzB,OAAM,IAAI,MAAM,8BAA8B;;AAGhD,SAAS,QAAQ,SAAkB;CACjC,MAAM,cAAc,iBAAiB;AAErC,KAAI,CAAC,SAAS;EAEZ,MAAM,WAAW,KAAK,KAAK,aAAa,WAAW;AAEnD,MAAI,CAAC,GAAG,WAAW,SAAS,EAAE;AAC5B,WAAQ,MAAM,uCAAuC;AACrD,WAAQ,KAAK,EAAE;;EAGjB,MAAM,UAAU,GAAG,aAAa,UAAU,QAAQ;AAClD,UAAQ,IAAI,QAAQ;AACpB;;CAIF,IAAI,iBAAiB;AAGrB,kBAAiB,eAAe,QAAQ,SAAS,GAAG;AACpD,kBAAiB,eAAe,QAAQ,OAAO,GAAG;AAGlD,kBAAiB,eAAe,QAAQ,mBAAmB,GAAG;AAC9D,kBAAiB,eAAe,QAAQ,WAAW,GAAG;CAEtD,MAAM,WAAW,KAAK,KAAK,aAAa,QAAQ,eAAe;AAE/D,KAAI,CAAC,GAAG,WAAW,SAAS,EAAE;AAC5B,UAAQ,MAAM,wCAAwC,UAAU;AAChE,UAAQ,MAAM,UAAU,WAAW;AACnC,UAAQ,KAAK,EAAE;;CAGjB,MAAM,UAAU,GAAG,aAAa,UAAU,QAAQ;AAClD,SAAQ,IAAI,QAAQ;;AAGtB,MAAa,cAAc,IAAI,QAAQ,OAAO,CAC3C,YAAY,iCAAiC,CAC7C,SACC,UACA,+FACD,CACA,OAAO,QAAQ"}
1
+ {"version":3,"file":"docs.js","names":[],"sources":["../../../src/cli/commands/docs.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { Command } from \"commander\";\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\n\nfunction findPackageRoot(): string {\n let dir = __dirname;\n while (dir !== path.parse(dir).root) {\n if (fs.existsSync(path.join(dir, \"package.json\"))) {\n return dir;\n }\n dir = path.dirname(dir);\n }\n throw new Error(\"Could not find package root\");\n}\n\nfunction runDocs(docPath?: string) {\n const packageRoot = findPackageRoot();\n\n if (!docPath) {\n // Display llms.txt by default\n const llmsPath = path.join(packageRoot, \"llms.txt\");\n\n if (!fs.existsSync(llmsPath)) {\n console.error(\"Error: llms.txt not found in package\");\n process.exit(1);\n }\n\n const content = fs.readFileSync(llmsPath, \"utf-8\");\n console.log(content);\n return;\n }\n\n // Handle path - remove leading ./ and / first, then strip prefixes\n let normalizedPath = docPath;\n\n // Strip leading ./ or /\n normalizedPath = normalizedPath.replace(/^\\.\\//, \"\");\n normalizedPath = normalizedPath.replace(/^\\//, \"\");\n\n // Remove /appkit/docs/ or docs/ prefix since files are in packageRoot/docs/\n normalizedPath = normalizedPath.replace(/^appkit\\/docs\\//, \"\");\n normalizedPath = normalizedPath.replace(/^docs\\//, \"\");\n\n const fullPath = path.join(packageRoot, \"docs\", normalizedPath);\n\n if (!fs.existsSync(fullPath)) {\n console.error(`Error: Documentation file not found: ${docPath}`);\n console.error(`Tried: ${fullPath}`);\n process.exit(1);\n }\n\n const content = fs.readFileSync(fullPath, \"utf-8\");\n console.log(content);\n}\n\nexport const docsCommand = new Command(\"docs\")\n .description(\"Display embedded documentation\")\n .argument(\n \"[path]\",\n \"Path to specific documentation file (e.g., /appkit/docs/api/appkit-ui/components/Sidebar.md)\",\n )\n .action(runDocs);\n"],"mappings":";;;;;;AAKA,MAAM,aAAa,cAAc,OAAO,KAAK,IAAI;AACjD,MAAM,YAAY,KAAK,QAAQ,WAAW;AAE1C,SAAS,kBAA0B;CACjC,IAAI,MAAM;AACV,QAAO,QAAQ,KAAK,MAAM,IAAI,CAAC,MAAM;AACnC,MAAI,GAAG,WAAW,KAAK,KAAK,KAAK,eAAe,CAAC,CAC/C,QAAO;AAET,QAAM,KAAK,QAAQ,IAAI;;AAEzB,OAAM,IAAI,MAAM,8BAA8B;;AAGhD,SAAS,QAAQ,SAAkB;CACjC,MAAM,cAAc,iBAAiB;AAErC,KAAI,CAAC,SAAS;EAEZ,MAAM,WAAW,KAAK,KAAK,aAAa,WAAW;AAEnD,MAAI,CAAC,GAAG,WAAW,SAAS,EAAE;AAC5B,WAAQ,MAAM,uCAAuC;AACrD,WAAQ,KAAK,EAAE;;EAGjB,MAAM,UAAU,GAAG,aAAa,UAAU,QAAQ;AAClD,UAAQ,IAAI,QAAQ;AACpB;;CAIF,IAAI,iBAAiB;AAGrB,kBAAiB,eAAe,QAAQ,SAAS,GAAG;AACpD,kBAAiB,eAAe,QAAQ,OAAO,GAAG;AAGlD,kBAAiB,eAAe,QAAQ,mBAAmB,GAAG;AAC9D,kBAAiB,eAAe,QAAQ,WAAW,GAAG;CAEtD,MAAM,WAAW,KAAK,KAAK,aAAa,QAAQ,eAAe;AAE/D,KAAI,CAAC,GAAG,WAAW,SAAS,EAAE;AAC5B,UAAQ,MAAM,wCAAwC,UAAU;AAChE,UAAQ,MAAM,UAAU,WAAW;AACnC,UAAQ,KAAK,EAAE;;CAGjB,MAAM,UAAU,GAAG,aAAa,UAAU,QAAQ;AAClD,SAAQ,IAAI,QAAQ;;AAGtB,MAAa,cAAc,IAAI,QAAQ,OAAO,CAC3C,YAAY,iCAAiC,CAC7C,SACC,UACA,+FACD,CACA,OAAO,QAAQ"}
@@ -1,3 +1,4 @@
1
+ import fs from "node:fs";
1
2
  import path from "node:path";
2
3
  import { Command } from "commander";
3
4
 
@@ -11,6 +12,10 @@ async function runGenerateTypes(rootDir, outFile, warehouseId, options) {
11
12
  const resolvedRootDir = rootDir || process.cwd();
12
13
  const resolvedOutFile = outFile || path.join(process.cwd(), "client/src/appKitTypes.d.ts");
13
14
  const queryFolder = path.join(resolvedRootDir, "config/queries");
15
+ if (!fs.existsSync(queryFolder)) {
16
+ console.warn(`Warning: No queries found at ${queryFolder}. Skipping type generation.`);
17
+ return;
18
+ }
14
19
  const resolvedWarehouseId = warehouseId || process.env.DATABRICKS_WAREHOUSE_ID;
15
20
  if (!resolvedWarehouseId) {
16
21
  console.error("Error: DATABRICKS_WAREHOUSE_ID is not set. Please provide it as an argument or environment variable.");
@@ -1 +1 @@
1
- {"version":3,"file":"generate-types.js","names":[],"sources":["../../../src/cli/commands/generate-types.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport path from \"node:path\";\n\n/**\n * Generate types command implementation\n */\nasync function runGenerateTypes(\n rootDir?: string,\n outFile?: string,\n warehouseId?: string,\n options?: { noCache?: boolean },\n) {\n try {\n // Try to import the type generator from @databricks/appkit\n const { generateFromEntryPoint } = await import(\n \"@databricks/appkit/type-generator\"\n );\n\n const resolvedRootDir = rootDir || process.cwd();\n const resolvedOutFile =\n outFile || path.join(process.cwd(), \"client/src/appKitTypes.d.ts\");\n\n const queryFolder = path.join(resolvedRootDir, \"config/queries\");\n\n const resolvedWarehouseId =\n warehouseId || process.env.DATABRICKS_WAREHOUSE_ID;\n if (!resolvedWarehouseId) {\n console.error(\n \"Error: DATABRICKS_WAREHOUSE_ID is not set. Please provide it as an argument or environment variable.\",\n );\n process.exit(1);\n }\n\n await generateFromEntryPoint({\n queryFolder,\n outFile: resolvedOutFile,\n warehouseId: resolvedWarehouseId,\n noCache: options?.noCache || false,\n });\n } catch (error) {\n if (\n error instanceof Error &&\n error.message.includes(\"Cannot find module\")\n ) {\n console.error(\n \"Error: The 'generate-types' command is only available in @databricks/appkit.\",\n );\n console.error(\"Please install @databricks/appkit to use this command.\");\n process.exit(1);\n }\n throw error;\n }\n}\n\nexport const generateTypesCommand = new Command(\"generate-types\")\n .description(\"Generate TypeScript types from SQL queries\")\n .argument(\"[rootDir]\", \"Root directory of the project\", process.cwd())\n .argument(\n \"[outFile]\",\n \"Output file path\",\n path.join(process.cwd(), \"client/src/appKitTypes.d.ts\"),\n )\n .argument(\"[warehouseId]\", \"Databricks warehouse ID\")\n .option(\"--no-cache\", \"Disable caching for type generation\")\n .action(runGenerateTypes);\n"],"mappings":";;;;;;;AAMA,eAAe,iBACb,SACA,SACA,aACA,SACA;AACA,KAAI;EAEF,MAAM,EAAE,2BAA2B,MAAM,OACvC;EAGF,MAAM,kBAAkB,WAAW,QAAQ,KAAK;EAChD,MAAM,kBACJ,WAAW,KAAK,KAAK,QAAQ,KAAK,EAAE,8BAA8B;EAEpE,MAAM,cAAc,KAAK,KAAK,iBAAiB,iBAAiB;EAEhE,MAAM,sBACJ,eAAe,QAAQ,IAAI;AAC7B,MAAI,CAAC,qBAAqB;AACxB,WAAQ,MACN,uGACD;AACD,WAAQ,KAAK,EAAE;;AAGjB,QAAM,uBAAuB;GAC3B;GACA,SAAS;GACT,aAAa;GACb,SAAS,SAAS,WAAW;GAC9B,CAAC;UACK,OAAO;AACd,MACE,iBAAiB,SACjB,MAAM,QAAQ,SAAS,qBAAqB,EAC5C;AACA,WAAQ,MACN,+EACD;AACD,WAAQ,MAAM,yDAAyD;AACvE,WAAQ,KAAK,EAAE;;AAEjB,QAAM;;;AAIV,MAAa,uBAAuB,IAAI,QAAQ,iBAAiB,CAC9D,YAAY,6CAA6C,CACzD,SAAS,aAAa,iCAAiC,QAAQ,KAAK,CAAC,CACrE,SACC,aACA,oBACA,KAAK,KAAK,QAAQ,KAAK,EAAE,8BAA8B,CACxD,CACA,SAAS,iBAAiB,0BAA0B,CACpD,OAAO,cAAc,sCAAsC,CAC3D,OAAO,iBAAiB"}
1
+ {"version":3,"file":"generate-types.js","names":[],"sources":["../../../src/cli/commands/generate-types.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { Command } from \"commander\";\n\n/**\n * Generate types command implementation\n */\nasync function runGenerateTypes(\n rootDir?: string,\n outFile?: string,\n warehouseId?: string,\n options?: { noCache?: boolean },\n) {\n try {\n // Try to import the type generator from @databricks/appkit\n const { generateFromEntryPoint } = await import(\n \"@databricks/appkit/type-generator\"\n );\n\n const resolvedRootDir = rootDir || process.cwd();\n const resolvedOutFile =\n outFile || path.join(process.cwd(), \"client/src/appKitTypes.d.ts\");\n\n const queryFolder = path.join(resolvedRootDir, \"config/queries\");\n if (!fs.existsSync(queryFolder)) {\n console.warn(\n `Warning: No queries found at ${queryFolder}. Skipping type generation.`,\n );\n return;\n }\n\n const resolvedWarehouseId =\n warehouseId || process.env.DATABRICKS_WAREHOUSE_ID;\n if (!resolvedWarehouseId) {\n console.error(\n \"Error: DATABRICKS_WAREHOUSE_ID is not set. Please provide it as an argument or environment variable.\",\n );\n process.exit(1);\n }\n\n await generateFromEntryPoint({\n queryFolder,\n outFile: resolvedOutFile,\n warehouseId: resolvedWarehouseId,\n noCache: options?.noCache || false,\n });\n } catch (error) {\n if (\n error instanceof Error &&\n error.message.includes(\"Cannot find module\")\n ) {\n console.error(\n \"Error: The 'generate-types' command is only available in @databricks/appkit.\",\n );\n console.error(\"Please install @databricks/appkit to use this command.\");\n process.exit(1);\n }\n throw error;\n }\n}\n\nexport const generateTypesCommand = new Command(\"generate-types\")\n .description(\"Generate TypeScript types from SQL queries\")\n .argument(\"[rootDir]\", \"Root directory of the project\", process.cwd())\n .argument(\n \"[outFile]\",\n \"Output file path\",\n path.join(process.cwd(), \"client/src/appKitTypes.d.ts\"),\n )\n .argument(\"[warehouseId]\", \"Databricks warehouse ID\")\n .option(\"--no-cache\", \"Disable caching for type generation\")\n .action(runGenerateTypes);\n"],"mappings":";;;;;;;;AAOA,eAAe,iBACb,SACA,SACA,aACA,SACA;AACA,KAAI;EAEF,MAAM,EAAE,2BAA2B,MAAM,OACvC;EAGF,MAAM,kBAAkB,WAAW,QAAQ,KAAK;EAChD,MAAM,kBACJ,WAAW,KAAK,KAAK,QAAQ,KAAK,EAAE,8BAA8B;EAEpE,MAAM,cAAc,KAAK,KAAK,iBAAiB,iBAAiB;AAChE,MAAI,CAAC,GAAG,WAAW,YAAY,EAAE;AAC/B,WAAQ,KACN,gCAAgC,YAAY,6BAC7C;AACD;;EAGF,MAAM,sBACJ,eAAe,QAAQ,IAAI;AAC7B,MAAI,CAAC,qBAAqB;AACxB,WAAQ,MACN,uGACD;AACD,WAAQ,KAAK,EAAE;;AAGjB,QAAM,uBAAuB;GAC3B;GACA,SAAS;GACT,aAAa;GACb,SAAS,SAAS,WAAW;GAC9B,CAAC;UACK,OAAO;AACd,MACE,iBAAiB,SACjB,MAAM,QAAQ,SAAS,qBAAqB,EAC5C;AACA,WAAQ,MACN,+EACD;AACD,WAAQ,MAAM,yDAAyD;AACvE,WAAQ,KAAK,EAAE;;AAEjB,QAAM;;;AAIV,MAAa,uBAAuB,IAAI,QAAQ,iBAAiB,CAC9D,YAAY,6CAA6C,CACzD,SAAS,aAAa,iCAAiC,QAAQ,KAAK,CAAC,CACrE,SACC,aACA,oBACA,KAAK,KAAK,QAAQ,KAAK,EAAE,8BAA8B,CACxD,CACA,SAAS,iBAAiB,0BAA0B,CACpD,OAAO,cAAc,sCAAsC,CAC3D,OAAO,iBAAiB"}
@@ -1 +1 @@
1
- {"version":3,"file":"lint.js","names":[],"sources":["../../../src/cli/commands/lint.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport { parse, Lang } from \"@ast-grep/napi\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\n\ninterface Rule {\n id: string;\n pattern: string;\n message: string;\n includeTests?: boolean;\n filter?: (code: string) => boolean;\n}\n\nconst rules: Rule[] = [\n {\n id: \"no-double-type-assertion\",\n pattern: \"$X as unknown as $Y\",\n message:\n \"Avoid double type assertion (as unknown as). Use proper type guards or fix the source type.\",\n },\n {\n id: \"no-as-any\",\n pattern: \"$X as any\",\n message:\n 'Avoid \"as any\" type assertion. Use proper typing or unknown with type guards.',\n includeTests: false, // acceptable in test mocks\n },\n {\n id: \"no-array-index-key\",\n pattern: \"key={$IDX}\",\n message:\n \"Avoid using array index as React key. Use a stable unique identifier.\",\n filter: (code) => /key=\\{(idx|index|i)\\}/.test(code),\n },\n {\n id: \"no-parse-float-without-validation\",\n pattern: \"parseFloat($X).toFixed($Y)\",\n message:\n \"parseFloat can return NaN. Validate input or use toNumber() helper from shared/types.ts.\",\n },\n];\n\nfunction isTestFile(filePath: string): boolean {\n return (\n /\\.(test|spec)\\.(ts|tsx)$/.test(filePath) || filePath.includes(\"/tests/\")\n );\n}\n\nfunction findTsFiles(dir: string, files: string[] = []): string[] {\n const entries = fs.readdirSync(dir, { withFileTypes: true });\n\n for (const entry of entries) {\n const fullPath = path.join(dir, entry.name);\n\n if (entry.isDirectory()) {\n if ([\"node_modules\", \"dist\", \"build\", \".git\"].includes(entry.name))\n continue;\n findTsFiles(fullPath, files);\n } else if (entry.isFile() && /\\.(ts|tsx)$/.test(entry.name)) {\n files.push(fullPath);\n }\n }\n\n return files;\n}\n\ninterface Violation {\n file: string;\n line: number;\n column: number;\n rule: string;\n message: string;\n code: string;\n}\n\nfunction lintFile(filePath: string, rules: Rule[]): Violation[] {\n const violations: Violation[] = [];\n const content = fs.readFileSync(filePath, \"utf-8\");\n const lang = filePath.endsWith(\".tsx\") ? Lang.Tsx : Lang.TypeScript;\n const testFile = isTestFile(filePath);\n\n const ast = parse(lang, content);\n const root = ast.root();\n\n for (const rule of rules) {\n // skip rules that don't apply to test files\n if (testFile && rule.includeTests === false) continue;\n\n const matches = root.findAll(rule.pattern);\n\n for (const match of matches) {\n const code = match.text();\n\n if (rule.filter && !rule.filter(code)) continue;\n\n const range = match.range();\n violations.push({\n file: filePath,\n line: range.start.line + 1,\n column: range.start.column + 1,\n rule: rule.id,\n message: rule.message,\n code: code.length > 80 ? `${code.slice(0, 77)}...` : code,\n });\n }\n }\n\n return violations;\n}\n\n/**\n * Lint command implementation\n */\nfunction runLint() {\n const rootDir = process.cwd();\n const files = findTsFiles(rootDir);\n\n console.log(`Scanning ${files.length} TypeScript files...\\n`);\n\n const allViolations: Violation[] = [];\n\n for (const file of files) {\n const violations = lintFile(file, rules);\n allViolations.push(...violations);\n }\n\n if (allViolations.length === 0) {\n console.log(\"No ast-grep lint violations found.\");\n process.exit(0);\n }\n\n console.log(`Found ${allViolations.length} violation(s):\\n`);\n\n for (const v of allViolations) {\n const relPath = path.relative(rootDir, v.file);\n console.log(`${relPath}:${v.line}:${v.column}`);\n console.log(` ${v.rule}: ${v.message}`);\n console.log(` > ${v.code}\\n`);\n }\n\n process.exit(1);\n}\n\nexport const lintCommand = new Command(\"lint\")\n .description(\"Run AST-based linting on TypeScript files\")\n .action(runLint);\n"],"mappings":";;;;;;AAaA,MAAM,QAAgB;CACpB;EACE,IAAI;EACJ,SAAS;EACT,SACE;EACH;CACD;EACE,IAAI;EACJ,SAAS;EACT,SACE;EACF,cAAc;EACf;CACD;EACE,IAAI;EACJ,SAAS;EACT,SACE;EACF,SAAS,SAAS,wBAAwB,KAAK,KAAK;EACrD;CACD;EACE,IAAI;EACJ,SAAS;EACT,SACE;EACH;CACF;AAED,SAAS,WAAW,UAA2B;AAC7C,QACE,2BAA2B,KAAK,SAAS,IAAI,SAAS,SAAS,UAAU;;AAI7E,SAAS,YAAY,KAAa,QAAkB,EAAE,EAAY;CAChE,MAAM,UAAU,GAAG,YAAY,KAAK,EAAE,eAAe,MAAM,CAAC;AAE5D,MAAK,MAAM,SAAS,SAAS;EAC3B,MAAM,WAAW,KAAK,KAAK,KAAK,MAAM,KAAK;AAE3C,MAAI,MAAM,aAAa,EAAE;AACvB,OAAI;IAAC;IAAgB;IAAQ;IAAS;IAAO,CAAC,SAAS,MAAM,KAAK,CAChE;AACF,eAAY,UAAU,MAAM;aACnB,MAAM,QAAQ,IAAI,cAAc,KAAK,MAAM,KAAK,CACzD,OAAM,KAAK,SAAS;;AAIxB,QAAO;;AAYT,SAAS,SAAS,UAAkB,OAA4B;CAC9D,MAAM,aAA0B,EAAE;CAClC,MAAM,UAAU,GAAG,aAAa,UAAU,QAAQ;CAClD,MAAM,OAAO,SAAS,SAAS,OAAO,GAAG,KAAK,MAAM,KAAK;CACzD,MAAM,WAAW,WAAW,SAAS;CAGrC,MAAM,OADM,MAAM,MAAM,QAAQ,CACf,MAAM;AAEvB,MAAK,MAAM,QAAQ,OAAO;AAExB,MAAI,YAAY,KAAK,iBAAiB,MAAO;EAE7C,MAAM,UAAU,KAAK,QAAQ,KAAK,QAAQ;AAE1C,OAAK,MAAM,SAAS,SAAS;GAC3B,MAAM,OAAO,MAAM,MAAM;AAEzB,OAAI,KAAK,UAAU,CAAC,KAAK,OAAO,KAAK,CAAE;GAEvC,MAAM,QAAQ,MAAM,OAAO;AAC3B,cAAW,KAAK;IACd,MAAM;IACN,MAAM,MAAM,MAAM,OAAO;IACzB,QAAQ,MAAM,MAAM,SAAS;IAC7B,MAAM,KAAK;IACX,SAAS,KAAK;IACd,MAAM,KAAK,SAAS,KAAK,GAAG,KAAK,MAAM,GAAG,GAAG,CAAC,OAAO;IACtD,CAAC;;;AAIN,QAAO;;;;;AAMT,SAAS,UAAU;CACjB,MAAM,UAAU,QAAQ,KAAK;CAC7B,MAAM,QAAQ,YAAY,QAAQ;AAElC,SAAQ,IAAI,YAAY,MAAM,OAAO,wBAAwB;CAE7D,MAAM,gBAA6B,EAAE;AAErC,MAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,aAAa,SAAS,MAAM,MAAM;AACxC,gBAAc,KAAK,GAAG,WAAW;;AAGnC,KAAI,cAAc,WAAW,GAAG;AAC9B,UAAQ,IAAI,qCAAqC;AACjD,UAAQ,KAAK,EAAE;;AAGjB,SAAQ,IAAI,SAAS,cAAc,OAAO,kBAAkB;AAE5D,MAAK,MAAM,KAAK,eAAe;EAC7B,MAAM,UAAU,KAAK,SAAS,SAAS,EAAE,KAAK;AAC9C,UAAQ,IAAI,GAAG,QAAQ,GAAG,EAAE,KAAK,GAAG,EAAE,SAAS;AAC/C,UAAQ,IAAI,KAAK,EAAE,KAAK,IAAI,EAAE,UAAU;AACxC,UAAQ,IAAI,OAAO,EAAE,KAAK,IAAI;;AAGhC,SAAQ,KAAK,EAAE;;AAGjB,MAAa,cAAc,IAAI,QAAQ,OAAO,CAC3C,YAAY,4CAA4C,CACxD,OAAO,QAAQ"}
1
+ {"version":3,"file":"lint.js","names":[],"sources":["../../../src/cli/commands/lint.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { Lang, parse } from \"@ast-grep/napi\";\nimport { Command } from \"commander\";\n\ninterface Rule {\n id: string;\n pattern: string;\n message: string;\n includeTests?: boolean;\n filter?: (code: string) => boolean;\n}\n\nconst rules: Rule[] = [\n {\n id: \"no-double-type-assertion\",\n pattern: \"$X as unknown as $Y\",\n message:\n \"Avoid double type assertion (as unknown as). Use proper type guards or fix the source type.\",\n },\n {\n id: \"no-as-any\",\n pattern: \"$X as any\",\n message:\n 'Avoid \"as any\" type assertion. Use proper typing or unknown with type guards.',\n includeTests: false, // acceptable in test mocks\n },\n {\n id: \"no-array-index-key\",\n pattern: \"key={$IDX}\",\n message:\n \"Avoid using array index as React key. Use a stable unique identifier.\",\n filter: (code) => /key=\\{(idx|index|i)\\}/.test(code),\n },\n {\n id: \"no-parse-float-without-validation\",\n pattern: \"parseFloat($X).toFixed($Y)\",\n message:\n \"parseFloat can return NaN. Validate input or use toNumber() helper from shared/types.ts.\",\n },\n];\n\nfunction isTestFile(filePath: string): boolean {\n return (\n /\\.(test|spec)\\.(ts|tsx)$/.test(filePath) || filePath.includes(\"/tests/\")\n );\n}\n\nfunction findTsFiles(dir: string, files: string[] = []): string[] {\n const entries = fs.readdirSync(dir, { withFileTypes: true });\n\n for (const entry of entries) {\n const fullPath = path.join(dir, entry.name);\n\n if (entry.isDirectory()) {\n if ([\"node_modules\", \"dist\", \"build\", \".git\"].includes(entry.name))\n continue;\n findTsFiles(fullPath, files);\n } else if (entry.isFile() && /\\.(ts|tsx)$/.test(entry.name)) {\n files.push(fullPath);\n }\n }\n\n return files;\n}\n\ninterface Violation {\n file: string;\n line: number;\n column: number;\n rule: string;\n message: string;\n code: string;\n}\n\nfunction lintFile(filePath: string, rules: Rule[]): Violation[] {\n const violations: Violation[] = [];\n const content = fs.readFileSync(filePath, \"utf-8\");\n const lang = filePath.endsWith(\".tsx\") ? Lang.Tsx : Lang.TypeScript;\n const testFile = isTestFile(filePath);\n\n const ast = parse(lang, content);\n const root = ast.root();\n\n for (const rule of rules) {\n // skip rules that don't apply to test files\n if (testFile && rule.includeTests === false) continue;\n\n const matches = root.findAll(rule.pattern);\n\n for (const match of matches) {\n const code = match.text();\n\n if (rule.filter && !rule.filter(code)) continue;\n\n const range = match.range();\n violations.push({\n file: filePath,\n line: range.start.line + 1,\n column: range.start.column + 1,\n rule: rule.id,\n message: rule.message,\n code: code.length > 80 ? `${code.slice(0, 77)}...` : code,\n });\n }\n }\n\n return violations;\n}\n\n/**\n * Lint command implementation\n */\nfunction runLint() {\n const rootDir = process.cwd();\n const files = findTsFiles(rootDir);\n\n console.log(`Scanning ${files.length} TypeScript files...\\n`);\n\n const allViolations: Violation[] = [];\n\n for (const file of files) {\n const violations = lintFile(file, rules);\n allViolations.push(...violations);\n }\n\n if (allViolations.length === 0) {\n console.log(\"No ast-grep lint violations found.\");\n process.exit(0);\n }\n\n console.log(`Found ${allViolations.length} violation(s):\\n`);\n\n for (const v of allViolations) {\n const relPath = path.relative(rootDir, v.file);\n console.log(`${relPath}:${v.line}:${v.column}`);\n console.log(` ${v.rule}: ${v.message}`);\n console.log(` > ${v.code}\\n`);\n }\n\n process.exit(1);\n}\n\nexport const lintCommand = new Command(\"lint\")\n .description(\"Run AST-based linting on TypeScript files\")\n .action(runLint);\n"],"mappings":";;;;;;AAaA,MAAM,QAAgB;CACpB;EACE,IAAI;EACJ,SAAS;EACT,SACE;EACH;CACD;EACE,IAAI;EACJ,SAAS;EACT,SACE;EACF,cAAc;EACf;CACD;EACE,IAAI;EACJ,SAAS;EACT,SACE;EACF,SAAS,SAAS,wBAAwB,KAAK,KAAK;EACrD;CACD;EACE,IAAI;EACJ,SAAS;EACT,SACE;EACH;CACF;AAED,SAAS,WAAW,UAA2B;AAC7C,QACE,2BAA2B,KAAK,SAAS,IAAI,SAAS,SAAS,UAAU;;AAI7E,SAAS,YAAY,KAAa,QAAkB,EAAE,EAAY;CAChE,MAAM,UAAU,GAAG,YAAY,KAAK,EAAE,eAAe,MAAM,CAAC;AAE5D,MAAK,MAAM,SAAS,SAAS;EAC3B,MAAM,WAAW,KAAK,KAAK,KAAK,MAAM,KAAK;AAE3C,MAAI,MAAM,aAAa,EAAE;AACvB,OAAI;IAAC;IAAgB;IAAQ;IAAS;IAAO,CAAC,SAAS,MAAM,KAAK,CAChE;AACF,eAAY,UAAU,MAAM;aACnB,MAAM,QAAQ,IAAI,cAAc,KAAK,MAAM,KAAK,CACzD,OAAM,KAAK,SAAS;;AAIxB,QAAO;;AAYT,SAAS,SAAS,UAAkB,OAA4B;CAC9D,MAAM,aAA0B,EAAE;CAClC,MAAM,UAAU,GAAG,aAAa,UAAU,QAAQ;CAClD,MAAM,OAAO,SAAS,SAAS,OAAO,GAAG,KAAK,MAAM,KAAK;CACzD,MAAM,WAAW,WAAW,SAAS;CAGrC,MAAM,OADM,MAAM,MAAM,QAAQ,CACf,MAAM;AAEvB,MAAK,MAAM,QAAQ,OAAO;AAExB,MAAI,YAAY,KAAK,iBAAiB,MAAO;EAE7C,MAAM,UAAU,KAAK,QAAQ,KAAK,QAAQ;AAE1C,OAAK,MAAM,SAAS,SAAS;GAC3B,MAAM,OAAO,MAAM,MAAM;AAEzB,OAAI,KAAK,UAAU,CAAC,KAAK,OAAO,KAAK,CAAE;GAEvC,MAAM,QAAQ,MAAM,OAAO;AAC3B,cAAW,KAAK;IACd,MAAM;IACN,MAAM,MAAM,MAAM,OAAO;IACzB,QAAQ,MAAM,MAAM,SAAS;IAC7B,MAAM,KAAK;IACX,SAAS,KAAK;IACd,MAAM,KAAK,SAAS,KAAK,GAAG,KAAK,MAAM,GAAG,GAAG,CAAC,OAAO;IACtD,CAAC;;;AAIN,QAAO;;;;;AAMT,SAAS,UAAU;CACjB,MAAM,UAAU,QAAQ,KAAK;CAC7B,MAAM,QAAQ,YAAY,QAAQ;AAElC,SAAQ,IAAI,YAAY,MAAM,OAAO,wBAAwB;CAE7D,MAAM,gBAA6B,EAAE;AAErC,MAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,aAAa,SAAS,MAAM,MAAM;AACxC,gBAAc,KAAK,GAAG,WAAW;;AAGnC,KAAI,cAAc,WAAW,GAAG;AAC9B,UAAQ,IAAI,qCAAqC;AACjD,UAAQ,KAAK,EAAE;;AAGjB,SAAQ,IAAI,SAAS,cAAc,OAAO,kBAAkB;AAE5D,MAAK,MAAM,KAAK,eAAe;EAC7B,MAAM,UAAU,KAAK,SAAS,SAAS,EAAE,KAAK;AAC9C,UAAQ,IAAI,GAAG,QAAQ,GAAG,EAAE,KAAK,GAAG,EAAE,SAAS;AAC/C,UAAQ,IAAI,KAAK,EAAE,KAAK,IAAI,EAAE,UAAU;AACxC,UAAQ,IAAI,OAAO,EAAE,KAAK,IAAI;;AAGhC,SAAQ,KAAK,EAAE;;AAGjB,MAAa,cAAc,IAAI,QAAQ,OAAO,CAC3C,YAAY,4CAA4C,CACxD,OAAO,QAAQ"}
@@ -1 +1 @@
1
- {"version":3,"file":"setup.js","names":[],"sources":["../../../src/cli/commands/setup.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\n\nconst PACKAGES = [\n { name: \"@databricks/appkit\", description: \"Backend SDK\" },\n {\n name: \"@databricks/appkit-ui\",\n description: \"UI Integration, Charts, Tables, SSE, and more.\",\n },\n];\n\nconst SECTION_START = \"<!-- appkit-instructions-start -->\";\nconst SECTION_END = \"<!-- appkit-instructions-end -->\";\n\n/**\n * Find which AppKit packages are installed by checking for package.json\n */\nfunction findInstalledPackages() {\n const cwd = process.cwd();\n const installed = [];\n\n for (const pkg of PACKAGES) {\n const packagePath = path.join(\n cwd,\n \"node_modules\",\n pkg.name,\n \"package.json\",\n );\n if (fs.existsSync(packagePath)) {\n installed.push(pkg);\n }\n }\n\n return installed;\n}\n\n/**\n * Generate the AppKit section content\n */\nfunction generateSection(packages: typeof PACKAGES) {\n const links = packages\n .map((pkg) => {\n const docPath = `./node_modules/${pkg.name}/CLAUDE.md`;\n return `- **${pkg.name}** (${pkg.description}): [${docPath}](${docPath})`;\n })\n .join(\"\\n\");\n\n return `${SECTION_START}\n## Databricks AppKit\n\nThis project uses Databricks AppKit packages. For AI assistant guidance on using these packages, refer to:\n\n${links}\n${SECTION_END}`;\n}\n\n/**\n * Generate standalone CLAUDE.md content (when no existing file)\n */\nfunction generateStandalone(packages: typeof PACKAGES) {\n const links = packages\n .map((pkg) => {\n const docPath = `./node_modules/${pkg.name}/CLAUDE.md`;\n return `- **${pkg.name}** (${pkg.description}): [${docPath}](${docPath})`;\n })\n .join(\"\\n\");\n\n return `# AI Assistant Instructions\n\n${SECTION_START}\n## Databricks AppKit\n\nThis project uses Databricks AppKit packages. For AI assistant guidance on using these packages, refer to:\n\n${links}\n${SECTION_END}\n`;\n}\n\n/**\n * Update existing content with AppKit section\n */\nfunction updateContent(existingContent: string, packages: typeof PACKAGES) {\n const newSection = generateSection(packages);\n\n // Check if AppKit section already exists\n const startIndex = existingContent.indexOf(SECTION_START);\n const endIndex = existingContent.indexOf(SECTION_END);\n\n if (startIndex !== -1 && endIndex !== -1) {\n // Replace existing section\n const before = existingContent.substring(0, startIndex);\n const after = existingContent.substring(endIndex + SECTION_END.length);\n return before + newSection + after;\n }\n\n // Append section to end\n return `${existingContent.trimEnd()}\\n\\n${newSection}\\n`;\n}\n\n/**\n * Setup command implementation\n */\nfunction runSetup(options: { write?: boolean }) {\n const shouldWrite = options.write;\n\n // Find installed packages\n const installed = findInstalledPackages();\n\n if (installed.length === 0) {\n console.log(\"No @databricks/appkit packages found in node_modules.\");\n console.log(\"\\nMake sure you've installed at least one of:\");\n PACKAGES.forEach((pkg) => {\n console.log(` - ${pkg.name}`);\n });\n process.exit(1);\n }\n\n console.log(\"Detected packages:\");\n installed.forEach((pkg) => {\n console.log(` ✓ ${pkg.name}`);\n });\n\n const claudePath = path.join(process.cwd(), \"CLAUDE.md\");\n const existingContent = fs.existsSync(claudePath)\n ? fs.readFileSync(claudePath, \"utf-8\")\n : null;\n\n let finalContent: string;\n let action: string;\n\n if (existingContent) {\n finalContent = updateContent(existingContent, installed);\n action = existingContent.includes(SECTION_START) ? \"Updated\" : \"Added to\";\n } else {\n finalContent = generateStandalone(installed);\n action = \"Created\";\n }\n\n if (shouldWrite) {\n fs.writeFileSync(claudePath, finalContent);\n console.log(`\\n✓ ${action} CLAUDE.md`);\n console.log(` Path: ${claudePath}`);\n } else {\n console.log(\"\\nTo create/update CLAUDE.md, run:\");\n console.log(\" npx appkit setup --write\\n\");\n\n if (existingContent) {\n console.log(\n `This will ${\n existingContent.includes(SECTION_START)\n ? \"update the existing\"\n : \"add a new\"\n } AppKit section.\\n`,\n );\n }\n\n console.log(\"Preview of AppKit section:\\n\");\n console.log(\"─\".repeat(50));\n console.log(generateSection(installed));\n console.log(\"─\".repeat(50));\n }\n}\n\nexport const setupCommand = new Command(\"setup\")\n .description(\"Setup CLAUDE.md with AppKit package references\")\n .option(\"-w, --write\", \"Create or update CLAUDE.md file in current directory\")\n .action(runSetup);\n"],"mappings":"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"}
1
+ {"version":3,"file":"setup.js","names":[],"sources":["../../../src/cli/commands/setup.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { Command } from \"commander\";\n\nconst PACKAGES = [\n { name: \"@databricks/appkit\", description: \"Backend SDK\" },\n {\n name: \"@databricks/appkit-ui\",\n description: \"UI Integration, Charts, Tables, SSE, and more.\",\n },\n];\n\nconst SECTION_START = \"<!-- appkit-instructions-start -->\";\nconst SECTION_END = \"<!-- appkit-instructions-end -->\";\n\n/**\n * Find which AppKit packages are installed by checking for package.json\n */\nfunction findInstalledPackages() {\n const cwd = process.cwd();\n const installed = [];\n\n for (const pkg of PACKAGES) {\n const packagePath = path.join(\n cwd,\n \"node_modules\",\n pkg.name,\n \"package.json\",\n );\n if (fs.existsSync(packagePath)) {\n installed.push(pkg);\n }\n }\n\n return installed;\n}\n\n/**\n * Generate the AppKit section content\n */\nfunction generateSection(packages: typeof PACKAGES) {\n const links = packages\n .map((pkg) => {\n const docPath = `./node_modules/${pkg.name}/CLAUDE.md`;\n return `- **${pkg.name}** (${pkg.description}): [${docPath}](${docPath})`;\n })\n .join(\"\\n\");\n\n return `${SECTION_START}\n## Databricks AppKit\n\nThis project uses Databricks AppKit packages. For AI assistant guidance on using these packages, refer to:\n\n${links}\n${SECTION_END}`;\n}\n\n/**\n * Generate standalone CLAUDE.md content (when no existing file)\n */\nfunction generateStandalone(packages: typeof PACKAGES) {\n const links = packages\n .map((pkg) => {\n const docPath = `./node_modules/${pkg.name}/CLAUDE.md`;\n return `- **${pkg.name}** (${pkg.description}): [${docPath}](${docPath})`;\n })\n .join(\"\\n\");\n\n return `# AI Assistant Instructions\n\n${SECTION_START}\n## Databricks AppKit\n\nThis project uses Databricks AppKit packages. For AI assistant guidance on using these packages, refer to:\n\n${links}\n${SECTION_END}\n`;\n}\n\n/**\n * Update existing content with AppKit section\n */\nfunction updateContent(existingContent: string, packages: typeof PACKAGES) {\n const newSection = generateSection(packages);\n\n // Check if AppKit section already exists\n const startIndex = existingContent.indexOf(SECTION_START);\n const endIndex = existingContent.indexOf(SECTION_END);\n\n if (startIndex !== -1 && endIndex !== -1) {\n // Replace existing section\n const before = existingContent.substring(0, startIndex);\n const after = existingContent.substring(endIndex + SECTION_END.length);\n return before + newSection + after;\n }\n\n // Append section to end\n return `${existingContent.trimEnd()}\\n\\n${newSection}\\n`;\n}\n\n/**\n * Setup command implementation\n */\nfunction runSetup(options: { write?: boolean }) {\n const shouldWrite = options.write;\n\n // Find installed packages\n const installed = findInstalledPackages();\n\n if (installed.length === 0) {\n console.log(\"No @databricks/appkit packages found in node_modules.\");\n console.log(\"\\nMake sure you've installed at least one of:\");\n PACKAGES.forEach((pkg) => {\n console.log(` - ${pkg.name}`);\n });\n process.exit(1);\n }\n\n console.log(\"Detected packages:\");\n installed.forEach((pkg) => {\n console.log(` ✓ ${pkg.name}`);\n });\n\n const claudePath = path.join(process.cwd(), \"CLAUDE.md\");\n const existingContent = fs.existsSync(claudePath)\n ? fs.readFileSync(claudePath, \"utf-8\")\n : null;\n\n let finalContent: string;\n let action: string;\n\n if (existingContent) {\n finalContent = updateContent(existingContent, installed);\n action = existingContent.includes(SECTION_START) ? \"Updated\" : \"Added to\";\n } else {\n finalContent = generateStandalone(installed);\n action = \"Created\";\n }\n\n if (shouldWrite) {\n fs.writeFileSync(claudePath, finalContent);\n console.log(`\\n✓ ${action} CLAUDE.md`);\n console.log(` Path: ${claudePath}`);\n } else {\n console.log(\"\\nTo create/update CLAUDE.md, run:\");\n console.log(\" npx appkit setup --write\\n\");\n\n if (existingContent) {\n console.log(\n `This will ${\n existingContent.includes(SECTION_START)\n ? \"update the existing\"\n : \"add a new\"\n } AppKit section.\\n`,\n );\n }\n\n console.log(\"Preview of AppKit section:\\n\");\n console.log(\"─\".repeat(50));\n console.log(generateSection(installed));\n console.log(\"─\".repeat(50));\n }\n}\n\nexport const setupCommand = new Command(\"setup\")\n .description(\"Setup CLAUDE.md with AppKit package references\")\n .option(\"-w, --write\", \"Create or update CLAUDE.md file in current directory\")\n .action(runSetup);\n"],"mappings":"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"}
package/dist/cli/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
- import { setupCommand } from "./commands/setup.js";
2
+ import { docsCommand } from "./commands/docs.js";
3
3
  import { generateTypesCommand } from "./commands/generate-types.js";
4
4
  import { lintCommand } from "./commands/lint.js";
5
- import { docsCommand } from "./commands/docs.js";
5
+ import { setupCommand } from "./commands/setup.js";
6
6
  import { readFileSync } from "node:fs";
7
- import { fileURLToPath } from "node:url";
8
7
  import { dirname, join } from "node:path";
8
+ import { fileURLToPath } from "node:url";
9
9
  import { Command } from "commander";
10
10
 
11
11
  //#region src/cli/index.ts
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/cli/index.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { readFileSync } from \"node:fs\";\nimport { fileURLToPath } from \"node:url\";\nimport { dirname, join } from \"node:path\";\nimport { Command } from \"commander\";\nimport { setupCommand } from \"./commands/setup.js\";\nimport { generateTypesCommand } from \"./commands/generate-types.js\";\nimport { lintCommand } from \"./commands/lint.js\";\nimport { docsCommand } from \"./commands/docs.js\";\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\nconst pkgPath = join(__dirname, \"../../package.json\");\nconst pkg = JSON.parse(readFileSync(pkgPath, \"utf-8\"));\n\nconst cmd = new Command();\n\ncmd\n .name(\"appkit\")\n .description(\"CLI tools for Databricks AppKit\")\n .version(pkg.version);\n\ncmd.addCommand(setupCommand);\ncmd.addCommand(generateTypesCommand);\ncmd.addCommand(lintCommand);\ncmd.addCommand(docsCommand);\n\ncmd.parse();\n"],"mappings":";;;;;;;;;;;AAYA,MAAM,UAAU,KADE,QAAQ,cAAc,OAAO,KAAK,IAAI,CAAC,EACzB,qBAAqB;AACrD,MAAM,MAAM,KAAK,MAAM,aAAa,SAAS,QAAQ,CAAC;AAEtD,MAAM,MAAM,IAAI,SAAS;AAEzB,IACG,KAAK,SAAS,CACd,YAAY,kCAAkC,CAC9C,QAAQ,IAAI,QAAQ;AAEvB,IAAI,WAAW,aAAa;AAC5B,IAAI,WAAW,qBAAqB;AACpC,IAAI,WAAW,YAAY;AAC3B,IAAI,WAAW,YAAY;AAE3B,IAAI,OAAO"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/cli/index.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { readFileSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { Command } from \"commander\";\nimport { docsCommand } from \"./commands/docs.js\";\nimport { generateTypesCommand } from \"./commands/generate-types.js\";\nimport { lintCommand } from \"./commands/lint.js\";\nimport { setupCommand } from \"./commands/setup.js\";\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\nconst pkgPath = join(__dirname, \"../../package.json\");\nconst pkg = JSON.parse(readFileSync(pkgPath, \"utf-8\"));\n\nconst cmd = new Command();\n\ncmd\n .name(\"appkit\")\n .description(\"CLI tools for Databricks AppKit\")\n .version(pkg.version);\n\ncmd.addCommand(setupCommand);\ncmd.addCommand(generateTypesCommand);\ncmd.addCommand(lintCommand);\ncmd.addCommand(docsCommand);\n\ncmd.parse();\n"],"mappings":";;;;;;;;;;;AAYA,MAAM,UAAU,KADE,QAAQ,cAAc,OAAO,KAAK,IAAI,CAAC,EACzB,qBAAqB;AACrD,MAAM,MAAM,KAAK,MAAM,aAAa,SAAS,QAAQ,CAAC;AAEtD,MAAM,MAAM,IAAI,SAAS;AAEzB,IACG,KAAK,SAAS,CACd,YAAY,kCAAkC,CAC9C,QAAQ,IAAI,QAAQ;AAEvB,IAAI,WAAW,aAAa;AAC5B,IAAI,WAAW,qBAAqB;AACpC,IAAI,WAAW,YAAY;AAC3B,IAAI,WAAW,YAAY;AAE3B,IAAI,OAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"execution-context.js","names":[],"sources":["../../src/context/execution-context.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\nimport { ServiceContext } from \"./service-context\";\nimport {\n isUserContext,\n type ExecutionContext,\n type UserContext,\n} from \"./user-context\";\n\n/**\n * AsyncLocalStorage for execution context.\n * Used to pass user context through the call stack without explicit parameters.\n */\nconst executionContextStorage = new AsyncLocalStorage<UserContext>();\n\n/**\n * Run a function in the context of a user.\n * All calls within the function will have access to the user context.\n *\n * @param userContext - The user context to use\n * @param fn - The function to run\n * @returns The result of the function\n */\nexport function runInUserContext<T>(userContext: UserContext, fn: () => T): T {\n return executionContextStorage.run(userContext, fn);\n}\n\n/**\n * Get the current execution context.\n *\n * - If running inside a user context (via asUser), returns the user context\n * - Otherwise, returns the service context\n *\n * @throws Error if ServiceContext is not initialized\n */\nexport function getExecutionContext(): ExecutionContext {\n const userContext = executionContextStorage.getStore();\n if (userContext) {\n return userContext;\n }\n return ServiceContext.get();\n}\n\n/**\n * Get the current user ID for cache keying and telemetry.\n *\n * Returns the user ID if in user context, otherwise the service user ID.\n */\nexport function getCurrentUserId(): string {\n const ctx = getExecutionContext();\n if (isUserContext(ctx)) {\n return ctx.userId;\n }\n return ctx.serviceUserId;\n}\n\n/**\n * Get the WorkspaceClient for the current execution context.\n */\nexport function getWorkspaceClient() {\n return getExecutionContext().client;\n}\n\n/**\n * Get the warehouse ID promise.\n */\nexport function getWarehouseId(): Promise<string> {\n return getExecutionContext().warehouseId;\n}\n\n/**\n * Get the workspace ID promise.\n */\nexport function getWorkspaceId(): Promise<string> {\n return getExecutionContext().workspaceId;\n}\n\n/**\n * Check if currently running in a user context.\n */\nexport function isInUserContext(): boolean {\n const ctx = executionContextStorage.getStore();\n return ctx !== undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;AAsBA,SAAgB,iBAAoB,aAA0B,IAAgB;AAC5E,QAAO,wBAAwB,IAAI,aAAa,GAAG;;;;;;;;;;AAWrD,SAAgB,sBAAwC;CACtD,MAAM,cAAc,wBAAwB,UAAU;AACtD,KAAI,YACF,QAAO;AAET,QAAO,eAAe,KAAK;;;;;;;AAQ7B,SAAgB,mBAA2B;CACzC,MAAM,MAAM,qBAAqB;AACjC,KAAI,cAAc,IAAI,CACpB,QAAO,IAAI;AAEb,QAAO,IAAI;;;;;AAMb,SAAgB,qBAAqB;AACnC,QAAO,qBAAqB,CAAC;;;;;AAM/B,SAAgB,iBAAkC;AAChD,QAAO,qBAAqB,CAAC;;;;;AAM/B,SAAgB,iBAAkC;AAChD,QAAO,qBAAqB,CAAC;;;;;AAM/B,SAAgB,kBAA2B;AAEzC,QADY,wBAAwB,UAAU,KAC/B;;;;uBAhFkC;oBAK3B;CAMlB,0BAA0B,IAAI,mBAAgC"}
1
+ {"version":3,"file":"execution-context.js","names":[],"sources":["../../src/context/execution-context.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\nimport { ServiceContext } from \"./service-context\";\nimport {\n type ExecutionContext,\n isUserContext,\n type UserContext,\n} from \"./user-context\";\n\n/**\n * AsyncLocalStorage for execution context.\n * Used to pass user context through the call stack without explicit parameters.\n */\nconst executionContextStorage = new AsyncLocalStorage<UserContext>();\n\n/**\n * Run a function in the context of a user.\n * All calls within the function will have access to the user context.\n *\n * @param userContext - The user context to use\n * @param fn - The function to run\n * @returns The result of the function\n */\nexport function runInUserContext<T>(userContext: UserContext, fn: () => T): T {\n return executionContextStorage.run(userContext, fn);\n}\n\n/**\n * Get the current execution context.\n *\n * - If running inside a user context (via asUser), returns the user context\n * - Otherwise, returns the service context\n *\n * @throws Error if ServiceContext is not initialized\n */\nexport function getExecutionContext(): ExecutionContext {\n const userContext = executionContextStorage.getStore();\n if (userContext) {\n return userContext;\n }\n return ServiceContext.get();\n}\n\n/**\n * Get the current user ID for cache keying and telemetry.\n *\n * Returns the user ID if in user context, otherwise the service user ID.\n */\nexport function getCurrentUserId(): string {\n const ctx = getExecutionContext();\n if (isUserContext(ctx)) {\n return ctx.userId;\n }\n return ctx.serviceUserId;\n}\n\n/**\n * Get the WorkspaceClient for the current execution context.\n */\nexport function getWorkspaceClient() {\n return getExecutionContext().client;\n}\n\n/**\n * Get the warehouse ID promise.\n */\nexport function getWarehouseId(): Promise<string> {\n return getExecutionContext().warehouseId;\n}\n\n/**\n * Get the workspace ID promise.\n */\nexport function getWorkspaceId(): Promise<string> {\n return getExecutionContext().workspaceId;\n}\n\n/**\n * Check if currently running in a user context.\n */\nexport function isInUserContext(): boolean {\n const ctx = executionContextStorage.getStore();\n return ctx !== undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;AAsBA,SAAgB,iBAAoB,aAA0B,IAAgB;AAC5E,QAAO,wBAAwB,IAAI,aAAa,GAAG;;;;;;;;;;AAWrD,SAAgB,sBAAwC;CACtD,MAAM,cAAc,wBAAwB,UAAU;AACtD,KAAI,YACF,QAAO;AAET,QAAO,eAAe,KAAK;;;;;;;AAQ7B,SAAgB,mBAA2B;CACzC,MAAM,MAAM,qBAAqB;AACjC,KAAI,cAAc,IAAI,CACpB,QAAO,IAAI;AAEb,QAAO,IAAI;;;;;AAMb,SAAgB,qBAAqB;AACnC,QAAO,qBAAqB,CAAC;;;;;AAM/B,SAAgB,iBAAkC;AAChD,QAAO,qBAAqB,CAAC;;;;;AAM/B,SAAgB,iBAAkC;AAChD,QAAO,qBAAqB,CAAC;;;;;AAM/B,SAAgB,kBAA2B;AAEzC,QADY,wBAAwB,UAAU,KAC/B;;;;uBAhFkC;oBAK3B;CAMlB,0BAA0B,IAAI,mBAAgC"}
@@ -16,9 +16,9 @@ var context_exports = /* @__PURE__ */ __exportAll({
16
16
  runInUserContext: () => runInUserContext
17
17
  });
18
18
  var init_context = __esmMin((() => {
19
+ init_execution_context();
19
20
  init_service_context();
20
21
  init_user_context();
21
- init_execution_context();
22
22
  }));
23
23
 
24
24
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/context/index.ts"],"sourcesContent":["export { ServiceContext, type ServiceContextState } from \"./service-context\";\n\nexport {\n isUserContext,\n type ExecutionContext,\n type UserContext,\n} from \"./user-context\";\n\nexport {\n getExecutionContext,\n getCurrentUserId,\n getWorkspaceClient,\n getWarehouseId,\n getWorkspaceId,\n isInUserContext,\n runInUserContext,\n} from \"./execution-context\";\n"],"mappings":";;;;;;;;;;;;;;;;;;uBAA6E;oBAMrD;yBAUK"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/context/index.ts"],"sourcesContent":["export {\n getCurrentUserId,\n getExecutionContext,\n getWarehouseId,\n getWorkspaceClient,\n getWorkspaceId,\n isInUserContext,\n runInUserContext,\n} from \"./execution-context\";\nexport { ServiceContext, type ServiceContextState } from \"./service-context\";\nexport {\n type ExecutionContext,\n isUserContext,\n type UserContext,\n} from \"./user-context\";\n"],"mappings":";;;;;;;;;;;;;;;;;;yBAQ6B;uBACgD;oBAKrD"}
package/dist/index.d.ts CHANGED
@@ -3,11 +3,9 @@ import { CacheConfig } from "./shared/src/cache.js";
3
3
  import { StreamExecutionSettings } from "./shared/src/execute.js";
4
4
  import { isSQLTypeMarker, sql } from "./shared/src/sql/helpers.js";
5
5
  import { CacheManager } from "./cache/index.js";
6
+ import { getExecutionContext } from "./context/execution-context.js";
6
7
  import { ITelemetry, TelemetryConfig } from "./telemetry/types.js";
7
8
  import { Counter, Histogram, SeverityNumber, Span, SpanStatusCode } from "./telemetry/index.js";
8
- import { Plugin } from "./plugin/plugin.js";
9
- import { toPlugin } from "./plugin/to-plugin.js";
10
- import { analytics } from "./analytics/analytics.js";
11
9
  import { createApp } from "./core/appkit.js";
12
10
  import { AppKitError } from "./errors/base.js";
13
11
  import { AuthenticationError } from "./errors/authentication.js";
@@ -18,7 +16,9 @@ import { InitializationError } from "./errors/initialization.js";
18
16
  import { ServerError } from "./errors/server.js";
19
17
  import { TunnelError } from "./errors/tunnel.js";
20
18
  import { ValidationError } from "./errors/validation.js";
21
- import { server } from "./server/index.js";
19
+ import { Plugin } from "./plugin/plugin.js";
20
+ import { toPlugin } from "./plugin/to-plugin.js";
21
+ import { analytics } from "./plugins/analytics/analytics.js";
22
+ import { server } from "./plugins/server/index.js";
22
23
  import { appKitTypesPlugin } from "./type-generator/vite-plugin.js";
23
- import { getExecutionContext } from "./context/execution-context.js";
24
24
  export { AppKitError, AuthenticationError, type BasePluginConfig, type CacheConfig, CacheManager, ConfigurationError, ConnectionError, type Counter, ExecutionError, type Histogram, type IAppRouter, type ITelemetry, InitializationError, Plugin, ServerError, SeverityNumber, type Span, SpanStatusCode, type StreamExecutionSettings, type TelemetryConfig, TunnelError, ValidationError, analytics, appKitTypesPlugin, createApp, getExecutionContext, isSQLTypeMarker, server, sql, toPlugin };
package/dist/index.js CHANGED
@@ -13,19 +13,19 @@ import { init_errors } from "./errors/index.js";
13
13
  import { getExecutionContext } from "./context/execution-context.js";
14
14
  import { init_context } from "./context/index.js";
15
15
  import { CacheManager } from "./cache/index.js";
16
+ import { createApp } from "./core/appkit.js";
17
+ import "./core/index.js";
16
18
  import { Plugin } from "./plugin/plugin.js";
17
19
  import { toPlugin } from "./plugin/to-plugin.js";
18
20
  import "./plugin/index.js";
19
- import { analytics } from "./analytics/analytics.js";
20
- import "./analytics/index.js";
21
- import { createApp } from "./core/appkit.js";
22
- import "./core/index.js";
21
+ import { analytics } from "./plugins/analytics/analytics.js";
23
22
  import { appKitTypesPlugin } from "./type-generator/vite-plugin.js";
24
- import { server } from "./server/index.js";
23
+ import { server } from "./plugins/server/index.js";
24
+ import "./plugins/index.js";
25
25
 
26
26
  //#region src/index.ts
27
- init_errors();
28
27
  init_context();
28
+ init_errors();
29
29
 
30
30
  //#endregion
31
31
  export { AppKitError, AuthenticationError, CacheManager, ConfigurationError, ConnectionError, ExecutionError, InitializationError, Plugin, ServerError, SeverityNumber, SpanStatusCode, TunnelError, ValidationError, analytics, appKitTypesPlugin, createApp, getExecutionContext, isSQLTypeMarker, server, sql, toPlugin };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["/**\n * @packageDocumentation\n *\n * Core library for building Databricks applications with type-safe SQL queries,\n * plugin architecture, and React integration.\n */\n\n// Types from shared\nexport type {\n BasePluginConfig,\n CacheConfig,\n IAppRouter,\n StreamExecutionSettings,\n} from \"shared\";\nexport { isSQLTypeMarker, sql } from \"shared\";\nexport { analytics } from \"./analytics\";\nexport { CacheManager } from \"./cache\";\nexport { createApp } from \"./core\";\n// Errors\nexport {\n AppKitError,\n AuthenticationError,\n ConfigurationError,\n ConnectionError,\n ExecutionError,\n InitializationError,\n ServerError,\n TunnelError,\n ValidationError,\n} from \"./errors\";\n// Plugin authoring\nexport { Plugin, toPlugin } from \"./plugin\";\nexport { server } from \"./server\";\n// Telemetry (for advanced custom telemetry)\nexport {\n type Counter,\n type Histogram,\n type ITelemetry,\n SeverityNumber,\n type Span,\n SpanStatusCode,\n type TelemetryConfig,\n} from \"./telemetry\";\n\n// Vite plugin and type generation\nexport { appKitTypesPlugin } from \"./type-generator/vite-plugin\";\nexport { getExecutionContext } from \"./context\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;aA6BkB;cAiB8B"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["/**\n * @packageDocumentation\n *\n * Core library for building Databricks applications with type-safe SQL queries,\n * plugin architecture, and React integration.\n */\n\n// Types from shared\nexport type {\n BasePluginConfig,\n CacheConfig,\n IAppRouter,\n StreamExecutionSettings,\n} from \"shared\";\nexport { isSQLTypeMarker, sql } from \"shared\";\nexport { CacheManager } from \"./cache\";\nexport { getExecutionContext } from \"./context\";\nexport { createApp } from \"./core\";\n// Errors\nexport {\n AppKitError,\n AuthenticationError,\n ConfigurationError,\n ConnectionError,\n ExecutionError,\n InitializationError,\n ServerError,\n TunnelError,\n ValidationError,\n} from \"./errors\";\n// Plugin authoring\nexport { Plugin, toPlugin } from \"./plugin\";\nexport { analytics, server } from \"./plugins\";\n// Telemetry (for advanced custom telemetry)\nexport {\n type Counter,\n type Histogram,\n type ITelemetry,\n SeverityNumber,\n type Span,\n SpanStatusCode,\n type TelemetryConfig,\n} from \"./telemetry\";\n// Vite plugin and type generation\nexport { appKitTypesPlugin } from \"./type-generator/vite-plugin\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;cAgBgD;aAa9B"}
@@ -14,6 +14,7 @@ declare class DevFileReader {
14
14
  static getInstance(): DevFileReader;
15
15
  registerTunnelGetter(getter: TunnelConnectionGetter): void;
16
16
  readFile(filePath: string, req: express0.Request): Promise<string>;
17
+ readdir(dirPath: string, req: express0.Request): Promise<string[]>;
17
18
  }
18
19
  //#endregion
19
20
  export { DevFileReader };
@@ -1 +1 @@
1
- {"version":3,"file":"dev-reader.d.ts","names":[],"sources":["../../src/plugin/dev-reader.ts"],"sourcesContent":[],"mappings":";;;;KAQK,sBAAA,SAAsB,QAAA,CACF,YACpB;;;AAT0C;;AAOpB,cAQd,aAAA,CAPY;iBACpB,QAAA;EAAgB,QAAA,mBAAA;EAMR,QAAA,WAAa,CAAA;EAAA,OAAA,WAAA,CAAA,CAAA,EAMF,aANE;sBAMF,CAAA,MAAA,EA+BO,sBA/BP,CAAA,EAAA,IAAA;UA+BO,CAAA,QAAA,EAAA,MAAA,EAAA,GAAA,EAAsB,QAAA,CAM1B,OANI,CAAA,EAO1B,OAP0B,CAAA,MAAA,CAAA"}
1
+ {"version":3,"file":"dev-reader.d.ts","names":[],"sources":["../../src/plugin/dev-reader.ts"],"sourcesContent":[],"mappings":";;;;KAQK,sBAAA,SAAsB,QAAA,CACF,YACpB;;;AAT0C;;AAOpB,cAQd,aAAA,CAPY;iBACpB,QAAA;EAAgB,QAAA,mBAAA;EAMR,QAAA,WAAa,CAAA;EAAA,OAAA,WAAA,CAAA,CAAA,EAMF,aANE;sBAMF,CAAA,MAAA,EA+BO,sBA/BP,CAAA,EAAA,IAAA;UA+BO,CAAA,QAAA,EAAA,MAAA,EAAA,GAAA,EAAsB,QAAA,CAM1B,OANI,CAAA,EAO1B,OAP0B,CAAA,MAAA,CAAA;SAAsB,CAAA,OAM1B,EAAA,MAAA,EAAA,GAAA,EACf,QAAA,CAiCe,OAlCA,CAAA,EAmCtB,OAnCsB,CAAA,MAAA,EAAA,CAAA"}
@@ -1,7 +1,7 @@
1
1
  import { createLogger } from "../logging/logger.js";
2
2
  import { TunnelError } from "../errors/tunnel.js";
3
3
  import { init_errors } from "../errors/index.js";
4
- import { isRemoteTunnelAllowedByEnv } from "../server/remote-tunnel/gate.js";
4
+ import { isRemoteTunnelAllowedByEnv } from "../plugins/server/remote-tunnel/gate.js";
5
5
  import { randomUUID } from "node:crypto";
6
6
 
7
7
  //#region src/plugin/dev-reader.ts
@@ -58,6 +58,44 @@ var DevFileReader = class DevFileReader {
58
58
  }));
59
59
  });
60
60
  }
61
+ async readdir(dirPath, req) {
62
+ if (!this.getTunnelForRequest) throw TunnelError.getterNotRegistered();
63
+ const tunnel = this.getTunnelForRequest(req);
64
+ if (!tunnel) throw TunnelError.noConnection();
65
+ const { ws, pendingFileReads } = tunnel;
66
+ const requestId = randomUUID();
67
+ return new Promise((resolve, reject) => {
68
+ const timeout = setTimeout(() => {
69
+ pendingFileReads.delete(requestId);
70
+ reject(/* @__PURE__ */ new Error(`Directory read timeout: ${dirPath}`));
71
+ }, 1e4);
72
+ pendingFileReads.set(requestId, {
73
+ resolve: (data) => {
74
+ try {
75
+ const files = JSON.parse(data);
76
+ if (!Array.isArray(files)) {
77
+ reject(/* @__PURE__ */ new Error("Invalid directory listing format: expected array, got " + typeof files));
78
+ return;
79
+ }
80
+ if (!files.every((f) => typeof f === "string")) {
81
+ reject(/* @__PURE__ */ new Error("Invalid directory listing format: expected array of strings"));
82
+ return;
83
+ }
84
+ resolve(files);
85
+ } catch (error) {
86
+ reject(/* @__PURE__ */ new Error(`Failed to parse directory listing: ${error.message}`));
87
+ }
88
+ },
89
+ reject,
90
+ timeout
91
+ });
92
+ ws.send(JSON.stringify({
93
+ type: "dir:list",
94
+ requestId,
95
+ path: dirPath
96
+ }));
97
+ });
98
+ }
61
99
  };
62
100
 
63
101
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"dev-reader.js","names":[],"sources":["../../src/plugin/dev-reader.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport type { TunnelConnection } from \"shared\";\nimport { isRemoteTunnelAllowedByEnv } from \"@/server/remote-tunnel/gate\";\nimport { TunnelError } from \"../errors\";\nimport { createLogger } from \"../logging/logger\";\n\nconst logger = createLogger(\"plugin:dev-reader\");\n\ntype TunnelConnectionGetter = (\n req: import(\"express\").Request,\n) => TunnelConnection | null;\n\n/**\n * This class is used to read files from the local filesystem in dev mode\n * through the WebSocket tunnel.\n */\nexport class DevFileReader {\n private static instance: DevFileReader | null = null;\n private getTunnelForRequest: TunnelConnectionGetter | null = null;\n\n private constructor() {}\n\n static getInstance(): DevFileReader {\n if (!DevFileReader.instance) {\n DevFileReader.instance = new Proxy(new DevFileReader(), {\n /**\n * We proxy the reader to return a noop function if the remote server is disabled.\n */\n get(target, prop, receiver) {\n if (isRemoteTunnelAllowedByEnv()) {\n return Reflect.get(target, prop, receiver);\n }\n\n const value = Reflect.get(target, prop, receiver);\n\n if (typeof value === \"function\") {\n return function noop() {\n logger.debug(\"Noop: %s (remote server disabled)\", String(prop));\n return Promise.resolve(\"\");\n };\n }\n\n return value;\n },\n set(target, prop, value, receiver) {\n return Reflect.set(target, prop, value, receiver);\n },\n });\n }\n\n return DevFileReader.instance;\n }\n\n registerTunnelGetter(getter: TunnelConnectionGetter) {\n this.getTunnelForRequest = getter;\n }\n\n async readFile(\n filePath: string,\n req: import(\"express\").Request,\n ): Promise<string> {\n if (!this.getTunnelForRequest) {\n throw TunnelError.getterNotRegistered();\n }\n const tunnel = this.getTunnelForRequest(req);\n\n if (!tunnel) {\n throw TunnelError.noConnection();\n }\n\n const { ws, pendingFileReads } = tunnel;\n const requestId = randomUUID();\n\n return new Promise((resolve, reject) => {\n const timeout = setTimeout(() => {\n pendingFileReads.delete(requestId);\n reject(new Error(`File read timeout: ${filePath}`));\n }, 10000);\n\n pendingFileReads.set(requestId, { resolve, reject, timeout });\n\n ws.send(\n JSON.stringify({\n type: \"file:read\",\n requestId,\n path: filePath,\n }),\n );\n });\n }\n}\n"],"mappings":";;;;;;;aAGwC;AAGxC,MAAM,SAAS,aAAa,oBAAoB;;;;;AAUhD,IAAa,gBAAb,MAAa,cAAc;CACzB,OAAe,WAAiC;CAChD,AAAQ,sBAAqD;CAE7D,AAAQ,cAAc;CAEtB,OAAO,cAA6B;AAClC,MAAI,CAAC,cAAc,SACjB,eAAc,WAAW,IAAI,MAAM,IAAI,eAAe,EAAE;GAItD,IAAI,QAAQ,MAAM,UAAU;AAC1B,QAAI,4BAA4B,CAC9B,QAAO,QAAQ,IAAI,QAAQ,MAAM,SAAS;IAG5C,MAAM,QAAQ,QAAQ,IAAI,QAAQ,MAAM,SAAS;AAEjD,QAAI,OAAO,UAAU,WACnB,QAAO,SAAS,OAAO;AACrB,YAAO,MAAM,qCAAqC,OAAO,KAAK,CAAC;AAC/D,YAAO,QAAQ,QAAQ,GAAG;;AAI9B,WAAO;;GAET,IAAI,QAAQ,MAAM,OAAO,UAAU;AACjC,WAAO,QAAQ,IAAI,QAAQ,MAAM,OAAO,SAAS;;GAEpD,CAAC;AAGJ,SAAO,cAAc;;CAGvB,qBAAqB,QAAgC;AACnD,OAAK,sBAAsB;;CAG7B,MAAM,SACJ,UACA,KACiB;AACjB,MAAI,CAAC,KAAK,oBACR,OAAM,YAAY,qBAAqB;EAEzC,MAAM,SAAS,KAAK,oBAAoB,IAAI;AAE5C,MAAI,CAAC,OACH,OAAM,YAAY,cAAc;EAGlC,MAAM,EAAE,IAAI,qBAAqB;EACjC,MAAM,YAAY,YAAY;AAE9B,SAAO,IAAI,SAAS,SAAS,WAAW;GACtC,MAAM,UAAU,iBAAiB;AAC/B,qBAAiB,OAAO,UAAU;AAClC,2BAAO,IAAI,MAAM,sBAAsB,WAAW,CAAC;MAClD,IAAM;AAET,oBAAiB,IAAI,WAAW;IAAE;IAAS;IAAQ;IAAS,CAAC;AAE7D,MAAG,KACD,KAAK,UAAU;IACb,MAAM;IACN;IACA,MAAM;IACP,CAAC,CACH;IACD"}
1
+ {"version":3,"file":"dev-reader.js","names":[],"sources":["../../src/plugin/dev-reader.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport type { TunnelConnection } from \"shared\";\nimport { isRemoteTunnelAllowedByEnv } from \"@/plugins/server/remote-tunnel/gate\";\nimport { TunnelError } from \"../errors\";\nimport { createLogger } from \"../logging/logger\";\n\nconst logger = createLogger(\"plugin:dev-reader\");\n\ntype TunnelConnectionGetter = (\n req: import(\"express\").Request,\n) => TunnelConnection | null;\n\n/**\n * This class is used to read files from the local filesystem in dev mode\n * through the WebSocket tunnel.\n */\nexport class DevFileReader {\n private static instance: DevFileReader | null = null;\n private getTunnelForRequest: TunnelConnectionGetter | null = null;\n\n private constructor() {}\n\n static getInstance(): DevFileReader {\n if (!DevFileReader.instance) {\n DevFileReader.instance = new Proxy(new DevFileReader(), {\n /**\n * We proxy the reader to return a noop function if the remote server is disabled.\n */\n get(target, prop, receiver) {\n if (isRemoteTunnelAllowedByEnv()) {\n return Reflect.get(target, prop, receiver);\n }\n\n const value = Reflect.get(target, prop, receiver);\n\n if (typeof value === \"function\") {\n return function noop() {\n logger.debug(\"Noop: %s (remote server disabled)\", String(prop));\n return Promise.resolve(\"\");\n };\n }\n\n return value;\n },\n set(target, prop, value, receiver) {\n return Reflect.set(target, prop, value, receiver);\n },\n });\n }\n\n return DevFileReader.instance;\n }\n\n registerTunnelGetter(getter: TunnelConnectionGetter) {\n this.getTunnelForRequest = getter;\n }\n\n async readFile(\n filePath: string,\n req: import(\"express\").Request,\n ): Promise<string> {\n if (!this.getTunnelForRequest) {\n throw TunnelError.getterNotRegistered();\n }\n const tunnel = this.getTunnelForRequest(req);\n\n if (!tunnel) {\n throw TunnelError.noConnection();\n }\n\n const { ws, pendingFileReads } = tunnel;\n const requestId = randomUUID();\n\n return new Promise((resolve, reject) => {\n const timeout = setTimeout(() => {\n pendingFileReads.delete(requestId);\n reject(new Error(`File read timeout: ${filePath}`));\n }, 10000);\n\n pendingFileReads.set(requestId, { resolve, reject, timeout });\n\n ws.send(\n JSON.stringify({\n type: \"file:read\",\n requestId,\n path: filePath,\n }),\n );\n });\n }\n\n async readdir(\n dirPath: string,\n req: import(\"express\").Request,\n ): Promise<string[]> {\n if (!this.getTunnelForRequest) {\n throw TunnelError.getterNotRegistered();\n }\n const tunnel = this.getTunnelForRequest(req);\n\n if (!tunnel) {\n throw TunnelError.noConnection();\n }\n\n const { ws, pendingFileReads } = tunnel;\n const requestId = randomUUID();\n\n return new Promise((resolve, reject) => {\n const timeout = setTimeout(() => {\n pendingFileReads.delete(requestId);\n reject(new Error(`Directory read timeout: ${dirPath}`));\n }, 10000);\n\n pendingFileReads.set(requestId, {\n resolve: (data: string) => {\n try {\n const files = JSON.parse(data);\n // Validate it's an array of strings\n if (!Array.isArray(files)) {\n reject(\n new Error(\n \"Invalid directory listing format: expected array, got \" +\n typeof files,\n ),\n );\n return;\n }\n if (!files.every((f) => typeof f === \"string\")) {\n reject(\n new Error(\n \"Invalid directory listing format: expected array of strings\",\n ),\n );\n return;\n }\n resolve(files);\n } catch (error) {\n reject(\n new Error(\n `Failed to parse directory listing: ${(error as Error).message}`,\n ),\n );\n }\n },\n reject,\n timeout,\n });\n\n ws.send(\n JSON.stringify({\n type: \"dir:list\",\n requestId,\n path: dirPath,\n }),\n );\n });\n }\n}\n"],"mappings":";;;;;;;aAGwC;AAGxC,MAAM,SAAS,aAAa,oBAAoB;;;;;AAUhD,IAAa,gBAAb,MAAa,cAAc;CACzB,OAAe,WAAiC;CAChD,AAAQ,sBAAqD;CAE7D,AAAQ,cAAc;CAEtB,OAAO,cAA6B;AAClC,MAAI,CAAC,cAAc,SACjB,eAAc,WAAW,IAAI,MAAM,IAAI,eAAe,EAAE;GAItD,IAAI,QAAQ,MAAM,UAAU;AAC1B,QAAI,4BAA4B,CAC9B,QAAO,QAAQ,IAAI,QAAQ,MAAM,SAAS;IAG5C,MAAM,QAAQ,QAAQ,IAAI,QAAQ,MAAM,SAAS;AAEjD,QAAI,OAAO,UAAU,WACnB,QAAO,SAAS,OAAO;AACrB,YAAO,MAAM,qCAAqC,OAAO,KAAK,CAAC;AAC/D,YAAO,QAAQ,QAAQ,GAAG;;AAI9B,WAAO;;GAET,IAAI,QAAQ,MAAM,OAAO,UAAU;AACjC,WAAO,QAAQ,IAAI,QAAQ,MAAM,OAAO,SAAS;;GAEpD,CAAC;AAGJ,SAAO,cAAc;;CAGvB,qBAAqB,QAAgC;AACnD,OAAK,sBAAsB;;CAG7B,MAAM,SACJ,UACA,KACiB;AACjB,MAAI,CAAC,KAAK,oBACR,OAAM,YAAY,qBAAqB;EAEzC,MAAM,SAAS,KAAK,oBAAoB,IAAI;AAE5C,MAAI,CAAC,OACH,OAAM,YAAY,cAAc;EAGlC,MAAM,EAAE,IAAI,qBAAqB;EACjC,MAAM,YAAY,YAAY;AAE9B,SAAO,IAAI,SAAS,SAAS,WAAW;GACtC,MAAM,UAAU,iBAAiB;AAC/B,qBAAiB,OAAO,UAAU;AAClC,2BAAO,IAAI,MAAM,sBAAsB,WAAW,CAAC;MAClD,IAAM;AAET,oBAAiB,IAAI,WAAW;IAAE;IAAS;IAAQ;IAAS,CAAC;AAE7D,MAAG,KACD,KAAK,UAAU;IACb,MAAM;IACN;IACA,MAAM;IACP,CAAC,CACH;IACD;;CAGJ,MAAM,QACJ,SACA,KACmB;AACnB,MAAI,CAAC,KAAK,oBACR,OAAM,YAAY,qBAAqB;EAEzC,MAAM,SAAS,KAAK,oBAAoB,IAAI;AAE5C,MAAI,CAAC,OACH,OAAM,YAAY,cAAc;EAGlC,MAAM,EAAE,IAAI,qBAAqB;EACjC,MAAM,YAAY,YAAY;AAE9B,SAAO,IAAI,SAAS,SAAS,WAAW;GACtC,MAAM,UAAU,iBAAiB;AAC/B,qBAAiB,OAAO,UAAU;AAClC,2BAAO,IAAI,MAAM,2BAA2B,UAAU,CAAC;MACtD,IAAM;AAET,oBAAiB,IAAI,WAAW;IAC9B,UAAU,SAAiB;AACzB,SAAI;MACF,MAAM,QAAQ,KAAK,MAAM,KAAK;AAE9B,UAAI,CAAC,MAAM,QAAQ,MAAM,EAAE;AACzB,8BACE,IAAI,MACF,2DACE,OAAO,MACV,CACF;AACD;;AAEF,UAAI,CAAC,MAAM,OAAO,MAAM,OAAO,MAAM,SAAS,EAAE;AAC9C,8BACE,IAAI,MACF,8DACD,CACF;AACD;;AAEF,cAAQ,MAAM;cACP,OAAO;AACd,6BACE,IAAI,MACF,sCAAuC,MAAgB,UACxD,CACF;;;IAGL;IACA;IACD,CAAC;AAEF,MAAG,KACD,KAAK,UAAU;IACb,MAAM;IACN;IACA,MAAM;IACP,CAAC,CACH;IACD"}
@@ -1,9 +1,9 @@
1
1
  import { BasePlugin, BasePluginConfig, IAppResponse, PluginEndpointMap, PluginPhase, RouteConfig } from "../shared/src/plugin.js";
2
2
  import { PluginExecutionSettings, StreamExecuteHandler, StreamExecutionSettings } from "../shared/src/execute.js";
3
- import { AppManager } from "../app/index.js";
4
3
  import { CacheManager } from "../cache/index.js";
5
- import { StreamManager } from "../stream/stream-manager.js";
6
4
  import { ITelemetry } from "../telemetry/types.js";
5
+ import { AppManager } from "../app/index.js";
6
+ import { StreamManager } from "../stream/stream-manager.js";
7
7
  import { DevFileReader } from "./dev-reader.js";
8
8
  import express from "express";
9
9
 
@@ -9,8 +9,8 @@ import { deepMerge } from "../utils/merge.js";
9
9
  import { ServiceContext } from "../context/service-context.js";
10
10
  import { getCurrentUserId, runInUserContext } from "../context/execution-context.js";
11
11
  import { init_context } from "../context/index.js";
12
- import { AppManager } from "../app/index.js";
13
12
  import { CacheManager } from "../cache/index.js";
13
+ import { AppManager } from "../app/index.js";
14
14
  import { StreamManager } from "../stream/stream-manager.js";
15
15
  import "../stream/index.js";
16
16
  import { DevFileReader } from "./dev-reader.js";
@@ -1,11 +1,11 @@
1
- import { IAppRouter, ToPlugin } from "../shared/src/plugin.js";
2
- import { SQLTypeMarker } from "../shared/src/sql/types.js";
3
- import { Plugin } from "../plugin/plugin.js";
1
+ import { IAppRouter, ToPlugin } from "../../shared/src/plugin.js";
2
+ import { SQLTypeMarker } from "../../shared/src/sql/types.js";
3
+ import { Plugin } from "../../plugin/plugin.js";
4
4
  import { IAnalyticsConfig } from "./types.js";
5
5
  import { WorkspaceClient } from "@databricks/sdk-experimental";
6
6
  import express from "express";
7
7
 
8
- //#region src/analytics/analytics.d.ts
8
+ //#region src/plugins/analytics/analytics.d.ts
9
9
  declare class AnalyticsPlugin extends Plugin {
10
10
  name: string;
11
11
  protected envVars: string[];