Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@types/mongoose-patch-history #95

Open
danielbayerlein opened this issue Feb 9, 2022 · 4 comments
Open

@types/mongoose-patch-history #95

danielbayerlein opened this issue Feb 9, 2022 · 4 comments

Comments

@danielbayerlein
Copy link
Contributor

Has anyone created types for mongoose-patch-history? Or is something planned?

@vinerich
Copy link
Collaborator

Hey there @danielbayerlein,
I created some types for my own use.

mongoose-patch-history.d.ts

declare module "mongoose-patch-history" {
  import mongoose = require("mongoose");

  export default function (schema: mongoose.Schema, opts: { mongoose: mongoose.Mongoose; name: string }): void;
}

This is the easiest to get it working quickly.

If you want to put some work in and provide typings I'd be happy to review them or extend the missing parts. Unfortunately I don't have that much time currently to implement them myself.

@danielbayerlein
Copy link
Contributor Author

More types added:

declare module 'mongoose-patch-history' {
  import type { Operation } from 'fast-json-patch';
  import type { Schema } from 'mongoose';

  export type MongoosePatchHistoryPatch = {
    ops: Operation & { originalValue?: any; }[];
    ref: Types.ObjectId;
    date: Date;
  };

  export type MongoosePatchHistoryOptions = {
    mongoose: Mongoose;
    name: string;
    removePatches?: boolean;
    transforms?: [(name: string) => string, (name: string) => string];
    includes?: Record<string, Record<string, unknown>>;
    excludes?: string[];
    trackOriginalValue?: boolean;
  };

  export default function (
    schema: Schema,
    options: MongoosePatchHistoryOptions,
  ): void;
}

@vinerich
Copy link
Collaborator

Thanks for you input! Looks good.

If I might ask for you opinion:

  • Further enhance the types to support access on patches for each mongoose.document
  • Use this as a starting point to do a typescript rewrite of the code

This might be checked with @codepunkt too.

@danielbayerlein
Copy link
Contributor Author

@vinerich I think both points make a lot of sense! Sounds like version 3 of mongoose-patch-history.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants