Skip to content

Commit 265a9ed

Browse files
refactor(analytics): accept legacy "JSON"/"ARROW" format aliases
Widen AnalyticsFormat to also include the pre-rename "JSON" and "ARROW" spellings, both marked @deprecated with a JSDoc note describing the removal condition (no consumer on appkit/appkit-ui < 0.33.0). Add a normalizeAnalyticsFormat helper and call it at the analytics route handler entry point so all downstream code (cache key, format branching, formatParameters) continues to operate on the canonical "JSON_ARRAY" | "ARROW_STREAM" values. InferResultByFormat is widened to also match "ARROW" so callers passing the legacy spelling still get TypedArrowTable<...> inferred. This lifts the breaking-change carve-out from the rename, so callers of useAnalyticsQuery({ format: "JSON" | "ARROW" }) keep working with only an IDE deprecation hint. Signed-off-by: James Broadhead <jamesbroadhead@gmail.com>
1 parent dd2bd65 commit 265a9ed

3 files changed

Lines changed: 53 additions & 5 deletions

File tree

packages/appkit-ui/src/react/hooks/types.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,20 @@ import type { Table } from "apache-arrow";
44
// Data Format Types
55
// ============================================================================
66

7-
/** Supported response formats for analytics queries */
8-
export type AnalyticsFormat = "JSON_ARRAY" | "ARROW_STREAM";
7+
/**
8+
* Supported response formats for analytics queries.
9+
*
10+
* "JSON" and "ARROW" are legacy aliases kept for backwards compatibility
11+
* with appkit/appkit-ui < 0.33.0 — safe to remove once no consumer is on
12+
* a pre-0.33.0 version.
13+
*/
14+
export type AnalyticsFormat =
15+
| "JSON_ARRAY"
16+
| "ARROW_STREAM"
17+
/** @deprecated Use "JSON_ARRAY". Safe to remove once no consumer is on appkit-ui < 0.33.0. */
18+
| "JSON"
19+
/** @deprecated Use "ARROW_STREAM". Safe to remove once no consumer is on appkit-ui < 0.33.0. */
20+
| "ARROW";
921

1022
/**
1123
* Typed Arrow Table - preserves row type information for type inference.
@@ -120,7 +132,9 @@ export type InferResultByFormat<
120132
T,
121133
K,
122134
F extends AnalyticsFormat,
123-
> = F extends "ARROW_STREAM" ? TypedArrowTable<InferRowType<K>> : InferResult<T, K>;
135+
> = F extends "ARROW_STREAM" | "ARROW"
136+
? TypedArrowTable<InferRowType<K>>
137+
: InferResult<T, K>;
124138

125139
/**
126140
* Infers parameters type from QueryRegistry[K]["parameters"]

packages/appkit/src/plugins/analytics/analytics.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import type { PluginManifest } from "../../registry";
2424
import { queryDefaults } from "./defaults";
2525
import manifest from "./manifest.json";
2626
import { QueryProcessor } from "./query";
27+
import { normalizeAnalyticsFormat } from "./types";
2728
import type {
2829
AnalyticsQueryResponse,
2930
IAnalyticsConfig,
@@ -128,7 +129,9 @@ export class AnalyticsPlugin extends Plugin implements ToolProvider {
128129
res: express.Response,
129130
): Promise<void> {
130131
const { query_key } = req.params;
131-
const { parameters, format = "JSON_ARRAY" } = req.body as IAnalyticsQueryRequest;
132+
const { parameters, format: rawFormat = "JSON_ARRAY" } =
133+
req.body as IAnalyticsQueryRequest;
134+
const format = normalizeAnalyticsFormat(rawFormat);
132135

133136
// Request-scoped logging with WideEvent tracking
134137
logger.debug(req, "Executing query: %s (format=%s)", query_key, format);

packages/appkit/src/plugins/analytics/types.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,38 @@ export interface IAnalyticsConfig extends BasePluginConfig {
44
timeout?: number;
55
}
66

7-
export type AnalyticsFormat = "JSON_ARRAY" | "ARROW_STREAM";
7+
/**
8+
* Supported response formats for analytics queries.
9+
*
10+
* "JSON" and "ARROW" are legacy aliases kept for backwards compatibility
11+
* with appkit/appkit-ui < 0.33.0 — safe to remove once no consumer is on
12+
* a pre-0.33.0 version. The route handler normalizes them to their
13+
* canonical equivalents before any downstream code reads the value.
14+
*/
15+
export type AnalyticsFormat =
16+
| "JSON_ARRAY"
17+
| "ARROW_STREAM"
18+
/** @deprecated Use "JSON_ARRAY". Safe to remove once no consumer is on appkit < 0.33.0. */
19+
| "JSON"
20+
/** @deprecated Use "ARROW_STREAM". Safe to remove once no consumer is on appkit < 0.33.0. */
21+
| "ARROW";
22+
23+
/** Canonical (post-normalization) analytics format values. */
24+
export type CanonicalAnalyticsFormat = "JSON_ARRAY" | "ARROW_STREAM";
25+
26+
/**
27+
* Map a (possibly legacy) AnalyticsFormat to its canonical form.
28+
* Legacy values come from appkit/appkit-ui < 0.33.0 and can be removed
29+
* along with the deprecated aliases once no such consumer remains.
30+
*/
31+
export function normalizeAnalyticsFormat(
32+
f: AnalyticsFormat,
33+
): CanonicalAnalyticsFormat {
34+
if (f === "JSON") return "JSON_ARRAY";
35+
if (f === "ARROW") return "ARROW_STREAM";
36+
return f;
37+
}
38+
839
export interface IAnalyticsQueryRequest {
940
parameters?: Record<string, any>;
1041
format?: AnalyticsFormat;

0 commit comments

Comments
 (0)