Skip to content

Commit

Permalink
Update generated files
Browse files Browse the repository at this point in the history
  • Loading branch information
joheredi committed Jun 25, 2024
1 parent 3f3bcf4 commit ef68d29
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Licensed under the MIT license.

export function serializeRecord<
T extends string | number | boolean | Date | null,
R,
>(item: Record<string, T>): Record<string, R>;
export function serializeRecord<T, R>(
item: Record<string, T>,
serializer: (item: T) => R,
): Record<string, R>;
export function serializeRecord<T, R>(
item: Record<string, T>,
serializer?: (item: T) => R,
): Record<string, R> {
return Object.keys(item).reduce(
(acc, key) => {
if (isSupportedRecordType(item[key])) {
acc[key] = item[key] as any;
} else if (serializer) {
const value = item[key];
if (value !== undefined) {
acc[key] = serializer(value);
}
} else {
console.warn(`Don't know how to serialize ${item[key]}`);
acc[key] = item[key] as any;
}
return acc;
},
{} as Record<string, R>,
);
}

function isSupportedRecordType(t: any) {
return (
["number", "string", "boolean", "null"].includes(typeof t) ||
t instanceof Date
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

export { UsageClient, UsageClientOptions } from "./usageClient.js";
export {
inputRecordSerializer,
inputOutputRecordSerializer,
InputRecord,
OutputRecord,
InputOutputRecord,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
// Licensed under the MIT license.

export { InputRecord, OutputRecord, InputOutputRecord } from "./models.js";
export {
inputRecordSerializer,
inputOutputRecordSerializer,
InputRecord,
OutputRecord,
InputOutputRecord,
} from "./models.js";
export {
InputOptionalParams,
OutputOptionalParams,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
// Licensed under the MIT license.

import {
InputRecord as InputRecordRest,
InputOutputRecord as InputOutputRecordRest,
} from "../rest/index.js";

/** Record used in operation parameters */
export interface InputRecord {
requiredProp: string;
}

export function inputRecordSerializer(item: InputRecord): InputRecordRest {
return {
requiredProp: item["requiredProp"],
};
}

/** Record used in operation return type */
export interface OutputRecord {
requiredProp: string;
Expand All @@ -14,3 +25,11 @@ export interface OutputRecord {
export interface InputOutputRecord {
requiredProp: string;
}

export function inputOutputRecordSerializer(
item: InputOutputRecord,
): InputOutputRecordRest {
return {
requiredProp: item["requiredProp"],
};
}

0 comments on commit ef68d29

Please sign in to comment.