codeant-ai-for-open-source[bot] commented on code in PR #39171:
URL: https://github.com/apache/superset/pull/39171#discussion_r3561221885


##########
superset-frontend/packages/superset-core/src/storage/index.ts:
##########
@@ -0,0 +1,208 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * @fileoverview Shared types for extension storage APIs.
+ *
+ * These types are shared across all storage tiers (local, session, ephemeral,
+ * persistent) to ensure a consistent API pattern.
+ */
+
+/**
+ * JSON-compatible value type.
+ * These are the only values that can be safely serialized/deserialized via 
JSON.
+ */
+export type JsonValue =
+  string | number | boolean | null | JsonValue[] | { [key: string]: JsonValue 
};
+
+/**
+ * Base interface for a storage accessor.
+ * All storage tiers implement this interface for both user-scoped and shared 
access.
+ */
+export interface StorageAccessor {
+  /**
+   * Get a value from storage.
+   *
+   * @param key The key to retrieve.
+   * @returns The stored value, or null if not found.
+   */
+  get<T = JsonValue>(key: string): Promise<T | null>;
+
+  /**
+   * Set a value in storage.
+   *
+   * @param key The key to store.
+   * @param value The value to store (must be JSON-serializable).
+   */
+  set<T = JsonValue>(key: string, value: T): Promise<void>;

Review Comment:
   ✅ **Customized review instruction saved!**
   
   **Instruction:**
   > Do not flag unconstrained generic storage `set()`/`get()` signatures as 
API mismatches when the method intentionally supports non-JSON values via a 
`codec` option; only enforce JSON-compatible constraints where no such codec 
path exists.
   
   **Applied to:**
     - `superset-frontend/packages/superset-core/src/storage/**`
   
   ---
   💡 *To manage or update this instruction, visit: [CodeAnt AI 
Settings](https://app.codeant.ai/org/settings/learnings)*



##########
superset-frontend/src/core/storage/binaryCodec.ts:
##########
@@ -0,0 +1,70 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/** Convert bytes to a base64 string, for transport over the JSON REST API. */
+export function bytesToBase64(bytes: Uint8Array): string {
+  let binary = '';
+  bytes.forEach(byte => {
+    binary += String.fromCharCode(byte);
+  });
+  return btoa(binary);
+}
+
+function isBinaryValue(value: unknown): value is Uint8Array | ArrayBuffer {
+  return value instanceof Uint8Array || value instanceof ArrayBuffer;
+}
+
+/**
+ * Infer which codec to use for `value` when the caller didn't specify one.
+ *
+ * "json" names the serialization format applied to encode the value for
+ * storage/transport -- it is not a claim about the value's shape. Per
+ * RFC 8259, a JSON text may be any JSON value (object, array, string,
+ * number, boolean, or null), so scalars like `1` or `"foo"` are encoded
+ * with the "json" codec too, alongside objects and arrays.
+ *
+ * Binary values (Uint8Array/ArrayBuffer) are the one case JSON cannot
+ * represent, so they're base64-encoded instead.
+ */
+function inferDefaultCodec(value: unknown): 'json' | 'base64' {
+  return isBinaryValue(value) ? 'base64' : 'json';
+}
+
+/**
+ * Resolve the codec and request-body value for a `set()` call.
+ *
+ * If the caller explicitly set `options.codec`, it is always respected
+ * as-is and `value` is passed through untouched -- the caller is
+ * responsible for encoding it correctly (e.g. base64-encoding it
+ * themselves before calling `set()`). Auto base64-encoding only happens
+ * when no codec was specified and `value` is binary.
+ */
+export function resolveSetPayload<T>(
+  value: T,
+  explicitCodec: string | undefined,
+): { value: unknown; codec: string } {
+  if (explicitCodec !== undefined) {
+    return { value, codec: explicitCodec };

Review Comment:
   ✅ **Customized review instruction saved!**
   
   **Instruction:**
   > Do not flag the explicit-codec fast path in storage binary codec helpers: 
when a caller supplies `codec`, pass `value` through unchanged and let the 
caller be responsible for encoding it correctly.
   
   **Applied to:**
     - `superset-frontend/src/core/storage/**`
   
   ---
   💡 *To manage or update this instruction, visit: [CodeAnt AI 
Settings](https://app.codeant.ai/org/settings/learnings)*



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to