{"id":20482061,"url":"https://github.com/leaonline/method-factory","last_synced_at":"2026-03-12T06:01:42.512Z","repository":{"id":113209553,"uuid":"259637680","full_name":"leaonline/method-factory","owner":"leaonline","description":"Create validated Meteor methods. Lightweight. Simple.","archived":false,"fork":false,"pushed_at":"2025-04-11T06:54:15.000Z","size":286,"stargazers_count":3,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-13T14:14:01.206Z","etag":null,"topics":["factory","hacktoberfest","meteor","meteorjs","method","validated-method"],"latest_commit_sha":null,"homepage":"","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/leaonline.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-04-28T12:58:54.000Z","updated_at":"2025-04-11T06:54:19.000Z","dependencies_parsed_at":null,"dependency_job_id":"3298405a-fb83-4379-b576-e99bfed4497f","html_url":"https://github.com/leaonline/method-factory","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/leaonline/method-factory","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leaonline%2Fmethod-factory","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leaonline%2Fmethod-factory/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leaonline%2Fmethod-factory/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leaonline%2Fmethod-factory/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leaonline","download_url":"https://codeload.github.com/leaonline/method-factory/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leaonline%2Fmethod-factory/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30416733,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-12T04:41:02.746Z","status":"ssl_error","status_checked_at":"2026-03-12T04:40:12.571Z","response_time":114,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":["factory","hacktoberfest","meteor","meteorjs","method","validated-method"],"created_at":"2024-11-15T16:11:17.300Z","updated_at":"2026-03-12T06:01:42.492Z","avatar_url":"https://github.com/leaonline.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Meteor ValidatedMethod Factory\n\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)\n![GitHub file size in bytes](https://img.shields.io/github/size/leaonline/method-factory/method-factory.js)\n![GitHub](https://img.shields.io/github/license/leaonline/method-factory)\n\nCreate validated Meteor methods. Lightweight. Simple.\n\nWith this package you can define factory functions to create a variety of Meteor methods.\nDecouples definition from instantiation (also for the schema) and allows different configurations for different\ntypes of methods.\n\n**Minified size \u003c 2KB!**\n\n## Why do I want this?\n\n* Decouple definition from instantiation\n* Just pass in the schema as plain object, instead of manually instantiating `SimpleSchema`\n* Create fixed mixins on the abstract factory level, on the factory level, or both (see mixins section)\n\n## Installation\n\nSimply add this package to your meteor packages\n\n```bash\n$ meteor add leaonline:method-factory\n```\n\n## Usage\n\nImport the `createMethodFactory` method and create the factory function from it:\n\n```javascript\nimport { createMethodFactory } from 'meteor/leaonline:method-factory'\n\nconst createMethod = createMethodFactory() // no params = use defaults\nconst fancyMethod = createMethod({ name: 'fancy', validate: () =\u003e {}, run: () =\u003e 'fancy' }) // minimal required\nfancyMethod.call() // 'fancy'\n```\n\n### With schema\n\nWe support various ways to validate an input schema. To **decouple** schema definition from instantiation, we introduced a `shemaFactory`, which\nis basically a function that creates your schema for this collection. This also ensures, that\nmethods don't share the same schema instances.\n\n#### Using SimpleSchema\n\n```javascript\nimport { createMethodFactory } from 'meteor/leaonline:method-factory'\nimport SimpleSchema from 'simpl-schema'\n\nconst schemaFactory = definitions =\u003e new SimpleSchema(definitions)\n\nconst createMethod = createMethodFactory({ schemaFactory })\nconst fancyMethod = createMethod({\n  name: 'fancy',\n  schema: { title: String },\n  run: function({ title }) {\n    return `Hello, ${title}`\n  }\n})\nfancyMethod.call({ title: 'Mr.x' }) // Hello, Mr.x\n```\n\nAs you can see, there is **no need to pass a `validate` function** as it is internally built using the `schemaFactory`\nand the given `schema`.\n\n#### Overriding `validate` when using schema\n\nYou can also override the internal `validate` when using `schema` by passing a `validate` function.\nThis, however, disables the schema validation and is then your responsibility:\n\n\n```javascript\nimport { createMethodFactory } from 'meteor/leaonline:method-factory'\nimport SimpleSchema from 'simpl-schema'\n\nconst schemaFactory = definitions =\u003e new SimpleSchema(definitions)\n\nconst createMethod = createMethodFactory({ schemaFactory })\nconst customValidationMethod = createMethod({\n  name: 'customValidation',\n  schema: { title: String },\n  validate(document) {\n    if (!['Mrs.y', 'Mr.x'].includes(document.title)) {\n     throw new Error()\n    }\n  },\n  run: function({ title }) {\n    return `Hello, ${title}`\n  }\n})\ncustomValidationMethod.call({ title: 'Dr.z' }) // err\n```\n\nIf none of these cover your use case, you can still use mixins.\n\n#### Using check\n\nYou can also use Meteor's builtin `check` and `Match` for schema validation:\n\n```javascript\nimport { check } from 'meteor/check'\nimport { createMethodFactory } from 'meteor/leaonline:method-factory'\n\nconst schemaFactory = schema =\u003e ({\n  validate (args) {\n    check(args, schema)\n  }\n})\n\nconst createMethod = createMethodFactory({ schemaFactory })\nconst fancyMethod = createMethod({\n  name: 'fancyMethod',\n  schema: { title: String },\n  run: function({ title }) {\n    return `Hello, ${title}`\n  }\n})\nfancyMethod.call({ title: 'Mr.x' }) // Hello, Mr.x\n```\n\nNote, that some definitions for \n`SimpleSchema` and `check`/`Match` may differ.\n\n### With custom `ValidatedMethod`\n\nYou can extend the `ValidatedMethod` and pass it to the factory as well.\nNote, that you need to inherit from `ValidatedMethod`. Fully custom classes are not\nsupported.\n\n```javascript\nimport { createMethodFactory } from 'meteor/leaonline:method-factory'\nimport { ValidatedMethod } from 'meteor/mdg:validated-method'\nimport { myDefaultMixin } from '/path/to/myDefaultMixin'\n\nclass CustomMethod extends ValidatedMethod {\n  constructor (options) {\n    if (options.mixins \u0026\u0026 options.mixins.length \u003e 0) {\n      options.mixins = options.mixins.concat([myDefaultMixin])\n    }  else {\n      options.mixins = [myDefaultMixin]\n    }\n    super(options)\n  }\n}\n\nconst createMethod = createMethodFactory({ custom: CustomMethod })\nconst customMethod = createMethod({ ... })\n```\n\n\n### With mixins\n\nThere are three ways to define [mixins](https://github.com/meteor/validated-method#mixins):\n\n- on the abstract factory function level, all methods created by the factory will contain these mixins\n- on the factory level, you basically pass mixins the a single method\n- on both levels, where mixins from the abstract factory function are executed first; no overrides\n\n#### Abstract factory level mixins\n\nIf you want a certain mixin to be included for all methods created by the factory just pass them to the\n`createMethodFactory` function:\n\n```javascript\nimport { createMethodFactory } from 'meteor/leaonline:method-factory'\nimport { ValidatedMethod } from 'meteor/mdg:validated-method'\nimport { myDefaultMixin } from '/path/to/myDefaultMixin'\n\nconst createMethod = createMethodFactory({ mixins: [myDefaultMixin] })\nconst someMethod = createMethod({ \n  name: 'methodWithMixin', \n  validate: () =\u003e {}, \n  run: () =\u003e 'result', \n  foo: 'bar' // assuming your mixin requires foo \n})\n```\n\n#### Factory level mixins\n\nYou can also define mixins for each method. This is the same as passing mixins to the `ValidatedMethod`:\n\n```javascript\nimport { createMethodFactory } from 'meteor/leaonline:method-factory'\nimport { ValidatedMethod } from 'meteor/mdg:validated-method'\nimport { myDefaultMixin } from '/path/to/myDefaultMixin'\n\nconst createMethod = createMethodFactory() // use defaults\n\nconst methodWithMixin = createMethod({ \n  name: 'methodWithMixin',\n  mixins: [myDefaultMixin],\n  validate: () =\u003e {}, \n  run: () =\u003e 'result', \n  foo: 'bar' // assuming your mixin requires foo \n})\n\nconst methodWithoutMixin = createMethod({\n  name: 'methodWithoutMixin',\n  validate: () =\u003e {}, \n  run: () =\u003e 'result', \n})\n```\n\n##### Use mixins on both levels\n\nOf course you can define mixins on both levels, so that you have a certain set of default mixins and method-specific \nmixins:\n\n```javascript\nimport { createMethodFactory } from 'meteor/leaonline:method-factory'\nimport { ValidatedMethod } from 'meteor/mdg:validated-method'\nimport { myDefaultMixin } from '/path/to/myDefaultMixin'\nimport { someOtherMixin } from '/path/to/someOtherMixin'\n\nconst createMethod = createMethodFactory({ mixins: [myDefaultMixin] })\n\nconst methodWithMixin = createMethod({ \n  name: 'methodWithMixin', \n  validate: () =\u003e {}, \n  run: () =\u003e 'result', \n  foo: 'bar' // assuming your mixin requires foo \n})\n\nconst methodWithMixins = createMethod({\n  name: 'methodWithMixin', \n  mixins: [someOtherMixin],\n  validate: () =\u003e {}, \n  run: () =\u003e 'result', \n  foo: 'bar', // assuming your mixin requires foo\n  bar: 'baz', // assuming the other mixin requires bar \n})\n```\n\n## Codestyle\n\nWe use `standard` as code style and for linting.\n\n##### via npm\n\n```bash\n$ npm install --global standard snazzy\n$ standard | snazzy\n```\n\n##### via Meteor npm\n\n```bash\n$ meteor npm install --global standard snazzy\n$ standard | snazzy\n```\n\n\n## Test\n\nWe use `meteortesting:mocha` to run our tests on the package.\n\n##### Watch mode\n\n```bash\n$ TEST_WATCH=1 TEST_CLIENT=0 meteor test-packages ./ --driver-package meteortesting:mocha\n```\n\n##### Cli mode\n\n## License\n\nMIT, see [LICENSE](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleaonline%2Fmethod-factory","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleaonline%2Fmethod-factory","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleaonline%2Fmethod-factory/lists"}