{"id":13804116,"url":"https://github.com/jagi/meteor-astronomy","last_synced_at":"2025-04-04T09:08:16.332Z","repository":{"id":27059934,"uuid":"30525892","full_name":"jagi/meteor-astronomy","owner":"jagi","description":"Model layer for Meteor","archived":false,"fork":false,"pushed_at":"2023-08-24T08:22:39.000Z","size":2050,"stargazers_count":605,"open_issues_count":47,"forks_count":66,"subscribers_count":26,"default_branch":"v2","last_synced_at":"2025-03-28T08:05:52.050Z","etag":null,"topics":["astronomy","javascript","meteor","model","mongodb","mvc","schema","validation"],"latest_commit_sha":null,"homepage":"https://atmospherejs.com/jagi/astronomy","language":"JavaScript","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/jagi.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2015-02-09T08:30:24.000Z","updated_at":"2024-12-09T16:55:56.000Z","dependencies_parsed_at":"2022-09-02T02:41:47.102Z","dependency_job_id":"adc968f3-cb6a-445f-bf80-53189ec78ad4","html_url":"https://github.com/jagi/meteor-astronomy","commit_stats":null,"previous_names":[],"tags_count":81,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jagi%2Fmeteor-astronomy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jagi%2Fmeteor-astronomy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jagi%2Fmeteor-astronomy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jagi%2Fmeteor-astronomy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jagi","download_url":"https://codeload.github.com/jagi/meteor-astronomy/tar.gz/refs/heads/v2","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247149501,"owners_count":20891954,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["astronomy","javascript","meteor","model","mongodb","mvc","schema","validation"],"created_at":"2024-08-04T01:00:41.970Z","updated_at":"2025-04-04T09:08:16.313Z","avatar_url":"https://github.com/jagi.png","language":"JavaScript","funding_links":["https://www.patreon.com/jagi"],"categories":["Collections","Repositories"],"sub_categories":["Other"],"readme":"# Astronomy for Meteor\n\n[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/jagi/meteor-astronomy?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=body_badge)\n\n\u003cimg src=\"http://jagi.github.io/meteor-astronomy/images/logo.png\" /\u003e\n\nThe [Astronomy](https://atmospherejs.com/jagi/astronomy) package introduces the [Model Layer](http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller) into Meteor applications. It can also be named the Object Document Mapping system (ODM) or for people coming from relational database environments the Object-Relational Mapping system (ORM). Astronomy extends MongoDB documents with functionalities defined in a schema.\n\n## Documentation\n\nAstronomy documentation can be found [here](http://jagi.github.io/meteor-astronomy/).\n\n## Tutorials\n\nYou can learn more about Astronomy by watching video tutorials that I'm creating. I'm trying to add a new one every week. You can access them here https://goo.gl/9gnrav\n\n## Installation\n\n```sh\n$ meteor add jagi:astronomy\n```\n\n## Support Astronomy development\n\n[\u003cimg src=\"https://www.patreon.com/images/patreon_navigation_logo_mini_orange.png\" width=\"100\" /\u003e](https://www.patreon.com/jagi)\n\nI've decided to start [Patreon](https://www.patreon.com/jagi) page. If you enjoy using Astronomy and want to support development of future versions, then any donation will be welcome :).\n\n## Introduction\n\nWhen fetching documents from Mongo collections, you get plain JavaScript objects without any logic. You have to validate values of objects' properties, check what fields have changed, save only modified fields, transform values coming from forms, in every place you are playing with a document; a lot of things to do. Wouldn't it be great if you could define some simple rules and leave everything else to framework? It's actually possible thanks to Astronomy. But first let's take a look at how your code would look like without using Astronomy.\n\n```js\nvar post = Posts.findOne(id);\n// Assign values manually instead doing it automatically.\npost.createdAt = new Date();\npost.userId = Meteor.userId();\n// Manually convert values coming from the form.\npost.title = tmpl.find('input[name=title]').value;\npost.publishedAt = new Date(tmpl.find('input[name=publishedAt]').value);\n// Every time implement custom validation logic.\nif (post.title.length \u003c 3) {\n  // Implement an error messages system.\n  throw new Error('The \"title\" field has to be at least 3 characters long');\n} else {\n  // Detect what fields have changed and update only those.\n  // Access collection directly.\n  Posts.update({\n    _id: post._id\n  }, {\n    $set: {\n      title: post.title,\n      publishedAt: post.publishedAt,\n      createdAt: post.updateAt\n    }\n  });\n}\n```\n\nWith Astronomy and defined schema your code would look like follows:\n```js\n// Notice that we call the \"findOne\" method\n// from the \"Post\" class not from the \"Posts\" collection.\nvar post = Post.findOne(id);\n// Auto convert a string input value to a number.\npost.title = tmpl.find('input[name=title]').value;\npost.publishedAt = new Date(tmpl.find('input[name=publishedAt]').value);\n// Check if all fields are valid and update document\n// with only the fields that have changed.\npost.save();\n```\n\nWhat approach is simpler? I think the choice is obvious.\n\nFor clarity, here is a sample schema that allows that. May seem to be a lot of\ncode but have in mind that you write it only once.\n\n```js\nimport { Class } from 'meteor/jagi:astronomy';\n\nconst Posts = new Mongo.Collection('posts');\nconst Post = Class.create({\n  name: 'Post',\n  collection: Posts,\n  fields: {\n    title: {\n      type: String,\n      validators: [{\n        type: 'minLength',\n        param: 3\n      }]\n    },\n    userId: String,\n    publishedAt: Date\n  },\n  behaviors: {\n    timestamp: {}\n  }\n});\n```\n\n## Supporters\n\n[\u003cimg src=\"http://jagi.github.io/meteor-astronomy/images/usefulio.png\" /\u003e](http://useful.io/)\n\n## Contribution\n\nBigs thanks for all the [contributions](https://github.com/jagi/meteor-astronomy/graphs/contributors) in form of commits and bug reports. Without you it would not be possible to improve Astronomy. Special thanks to:\n- [Faberle](https://github.com/Faberle) - for help with Meteor methods feature\n- [Ben305](https://github.com/Ben305) - for several PRs\n- [peterchoo](https://github.com/peterchoo) - for several PRs\n- [talha-asad](https://github.com/talha-asad) - for updating History of changes\n- all other commiters that I forgot to mention\n\nIf you have any suggestions or want to write new features or behaviors please contact me, or just create an issue or a pull request. If you found any error please create a reproduction repository and create an issue. Thanks to that it will be easier for me to tell what is wrong. Please, don't use CoffeeScript for creating a reproduction.\n\n## License\n\nAstronomy is released under the [MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjagi%2Fmeteor-astronomy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjagi%2Fmeteor-astronomy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjagi%2Fmeteor-astronomy/lists"}