{"id":47910228,"url":"https://github.com/avidianity/firestore-eloquent","last_synced_at":"2026-04-04T05:15:56.797Z","repository":{"id":57236820,"uuid":"319055212","full_name":"avidianity/firestore-eloquent","owner":"avidianity","description":"A library for creating eloquent models in firestore inspired heavily by Laravel's Eloquent ORM.","archived":false,"fork":false,"pushed_at":"2021-11-19T01:50:11.000Z","size":892,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-08-09T06:27:48.628Z","etag":null,"topics":["eloquent","eloquent-models","eloquent-orm","firebase","firestore","laravel"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/avidianity.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-12-06T14:40:30.000Z","updated_at":"2025-02-10T07:01:31.000Z","dependencies_parsed_at":"2022-08-26T15:11:38.789Z","dependency_job_id":null,"html_url":"https://github.com/avidianity/firestore-eloquent","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/avidianity/firestore-eloquent","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avidianity%2Ffirestore-eloquent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avidianity%2Ffirestore-eloquent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avidianity%2Ffirestore-eloquent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avidianity%2Ffirestore-eloquent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/avidianity","download_url":"https://codeload.github.com/avidianity/firestore-eloquent/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avidianity%2Ffirestore-eloquent/sbom","scorecard":{"id":218153,"data":{"date":"2025-08-11","repo":{"name":"github.com/avidianity/firestore-eloquent","commit":"02795cc9bebc7d227a2cd9366b91ba49662b5cb3"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-17T02:01:39.449Z","repository_id":57236820,"created_at":"2025-08-17T02:01:39.449Z","updated_at":"2025-08-17T02:01:39.449Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31388419,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-04T04:26:24.776Z","status":"ssl_error","status_checked_at":"2026-04-04T04:23:34.147Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["eloquent","eloquent-models","eloquent-orm","firebase","firestore","laravel"],"created_at":"2026-04-04T05:15:55.213Z","updated_at":"2026-04-04T05:15:56.788Z","avatar_url":"https://github.com/avidianity.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# firestore-eloquent\n\nA library for creating eloquent models in firestore inspired heavily by Laravel's Eloquent ORM.\n\n[![tested with jest](https://img.shields.io/badge/tested_with-jest-99424f.svg)](https://github.com/facebook/jest)\n[![jest](https://jestjs.io/img/jest-badge.svg)](https://github.com/facebook/jest)\n\n## Setup\n\n### Installation\n\n__npm:__\n\n```npm\nnpm install firestore-eloquent\n```\n\n__yarn:__\n\n```yarn\nyarn add firestore-eloquent\n```\n\n### Usage\n\n__Note:__ Firebase must be initialized before using these models.\n\nExample:\n\n```javascript\nconst app = firebase.initializeApp({\n  apiKey: \"AIza....\",\n  appId: \"1:27992087142:web:ce....\",\n  projectId: \"my-firebase-project\",\n  authDomain: \"YOUR_APP.firebaseapp.com\",\n  databaseURL: \"https://YOUR_APP.firebaseio.com\",\n  storageBucket: \"YOUR_APP.appspot.com\",\n  messagingSenderId: \"123456789\",\n  measurementId: \"G-12345\",\n});\n```\n\nIf you have an already existing firestore instance:\n\n```javascript\nimport { setFirestore } from 'firestore-eloquent';\n\nconst firestore = app.firestore();\n\nsetFirestore(firestore);\n```\n\nYou can also get the firestore instance that is being used:\n\n```javascript\nimport { getFirestore } from 'firestore-eloquent';\n\n// returns firebase.firestore.Firestore\nconst firestore = getFirestore();\n```\n\nMaking Models:\n\nUsing and creating models should be similar to using Laravel Eloquent Models.\n\nNotes:\n\n- The Authenticatable class for user models is still under development.\n- It's possible to not override the constructor of the class, the library will try to infer the collection name according to the name of the class (ex: model `Post` will have a collection name of `post`). But this is not recommended because building a production version of an app that is using this library will most likely rename these classes due to minification of the code from webpack or other module bundlers.\n\n```typescript\nimport { Model, ModelData } from 'firestore-eloquent';\n\n// Optional\nexport interface PostData extends ModelData {\n    title: string;\n    description: string;\n}\n\nexport class Post extends Model\u003cPostData\u003e {\n    type = Post;\n\n    constructor(data?: Partial\u003cPostData\u003e) {\n        super(data);\n        // explicitly set collection name\n        this.name = 'posts';\n    }\n    \n    protected fillable() {\n        return ['title', 'description'];\n    }\n}\n```\n\nCRUD Examples:\n\n```typescript\nimport { Post } from 'path/to/models';\n\nconst post = new Post({\n    title: 'My Title',\n    description: 'My Description',\n});\n\n// You can also use fill() or forceFill()\npost.fill({\n    title: 'My Title',\n    description: 'My Description',\n});\n\n// create\nawait post.create(); /* or */ post.create(data);\n\n// update\nawait post.update(); /* or */ post.update(data);\n\n// delete\nawait post.delete();\n\n// save\nawait post.save(); /* or */ post.save(data);\n\n// fetching\nawait post.all();\n\n// get one\nawait post.first();\n\n// find one by id\nawait post.findOne(id);\n\n// Reading data\n\n// get a specific key\nconsole.log(post.get('title')) // My Title\n\n// get all data\nconsole.log(post.getData()) // { title: 'My Title', description: 'My Description' }\n\n// set data\npost.set('title', 'My New Title');\n\nawait post.save();\n\n```\n\n### Events\n\nEvents are also supported.\n\nExample:\n\n```typescript\nexport class Post extends Model\u003cPostData\u003e {\n    type = Post;\n\n    constructor(data?: Partial\u003cPostData\u003e) {\n        super(data);\n        this.name = 'posts';\n    }\n\n    protected fillable() {\n        return ['title', 'description'];\n    }\n\n    // register events here\n    protected booted() {\n        this.creating((post) =\u003e {});\n        this.created((post) =\u003e {});\n\n        this.updating((post) =\u003e {});\n        this.updated((post) =\u003e {});\n\n        this.deleting((post) =\u003e {});\n        this.deleted((post) =\u003e {});\n\n        this.saving((post) =\u003e {});\n        this.saved((post) =\u003e {});\n    }\n}\n```\n\n### Relationships\n\nCurrently, only `hasOne`, `hasMany` and `belongsTo` are supported.\n\nExample:\n\n```typescript\nexport class Post extends Model\u003cPostData\u003e {\n    type = Post;\n\n    constructor(data?: Partial\u003cPostData\u003e) {\n        super(data);\n        this.name = 'posts';\n    }\n    \n    protected fillable() {\n        return ['title', 'description'];\n    }\n\n    comments() {\n        return this.hasMany(Comment);\n    }\n}\n\nexport class Comment extends Model\u003cCommentData\u003e {\n    type = Comment;\n\n    constructor(data?: Partial\u003cCommentData\u003e) {\n        super(data);\n        this.name = 'comments';\n    }\n    \n    protected fillable() {\n        return ['body'];\n    }\n\n    post() {\n        return this.belongsTo(Post);\n    }\n}\n\nconst post = new Post(data);\nawait post.save();\n\n// saving\npost.comments().save(new Comment({\n    body: 'My comment',\n}));\n\n// creating\nconst comment = await post.comments().create(data);\n\n// fetching\nconst comments = await post.comments().getAll();\n\n// loading\nawait post.load(['comments']);\n```\n\n### Collections\n\nCollections extend the `Array` class and has several methods added to it. `Model.all()` and `hasMany` relationships all return Collections of that model. Some of the methods are overriden to improve their functionality such as `collection.includes(model)` and `collection.indexOf(model)`.\n\n```typescript\nconst posts = await new Post().all(); // Collection\u003cPost\u003e\n\n// call methods from `Array`\nconst post = posts.pop();\n\npost.set('title', 'Another Title');\n\n// pushes the post if it does not exist, otherwise it replaces with it's index\nposts.set(post);\n\n// or do this instead\nposts.replace(post)\n\n// find by id\nconst newPost = posts.get(id);\n\n// load relationships of all posts\nawait posts.load(['comments']);\nconst comments = posts.map(post =\u003e post.get('comments')); // CommentData[]\n\n// turn into a normal `Array`\nconst array = posts.toArray();\n```\n\n### JSON\n\nCalling `JSON.stringify` on models will automatically call `getData()` on them, this applies to collections as well.\n\n### Observers and Listeners\n\nThere are wrapper methods available to make use of firestore's onSnapshot method.\n\n```typescript\nimport { listen, addListener, removeListener, clearListeners } from 'firestore-eloquent';\n\n// add a listener\nconst handle = addListener(Post, (posts) =\u003e {\n    console.log(posts) // Post[]\n});\n\n// remove a listener\nremoveListener(Post, handle);\n\n// tell the library to actually start listening to onSnapshot methods\nlisten(Post)\n\n// remove all registered listeners\nclearListeners(Post)\n\n```\n\n#### Example in React\n\n```typescript\nconst [posts, setPosts] = useState\u003cPost[]\u003e([]);\n\nuseEffect(() =\u003e {\n    const handle = addListener(Post, setPosts);\n    listen(Post);\n\n    return () =\u003e {\n        removeListener(Post, handle);\n    };\n}, []);\n```\n\n### Contributing\n\nContributions are welcome! Just fork the project and make a pull request.\n\n### License\n\nThis library is open-sourced software licensed under the [MIT license](LICENSE.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favidianity%2Ffirestore-eloquent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Favidianity%2Ffirestore-eloquent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favidianity%2Ffirestore-eloquent/lists"}