Skip to content

transforms between snake/camel cased field names #2

@altintx

Description

@altintx

Looking for a way to use snake_case on the server side and camelCase on the client. Put together a POC at https://github.com/altintx/jsonapi-client/pull/1/files but do not believe it to be right. Specifically, I believe schema.ts:30: is expecting the names to be the same between the interface and the schema. For the linked implementation, I imagined doing something like

interface INotification {
  subject: Person;
  id: string;
  subjectId: string;
  sentAt: Date;
  contentJson: Json;
  status: 'error' | 'draft' | 'sent' | 'ready';
  createdAt: Date;
  updatedAt: Date;
}
const NotificationSchema = new Schema<INotification>({
  attributes: {
    subjectId: {},
    sentAt: {},
    contentJson: {},
    status: {},
    createdAt: {},
    updatedAt: {},
  },
  relationships: {
    subject: {},
  }
}, { serverTransform: "snake_case", clientTransform: "camelCase" }); // <---------
export class Notification extends model(NotificationSchema) { }

but like I said, my approach is hardly an ideal starting ground

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions