{"id":19681367,"url":"https://github.com/romansky/contractor","last_synced_at":"2025-10-09T18:08:16.032Z","repository":{"id":4673680,"uuid":"5820024","full_name":"romansky/Contractor","owner":"romansky","description":"Stricter messages in Javascript","archived":false,"fork":false,"pushed_at":"2012-10-07T00:17:48.000Z","size":120,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-10T05:36:45.819Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"CoffeeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/romansky.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-09-15T12:31:52.000Z","updated_at":"2014-05-19T15:21:44.000Z","dependencies_parsed_at":"2022-08-05T11:00:06.485Z","dependency_job_id":null,"html_url":"https://github.com/romansky/Contractor","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romansky%2FContractor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romansky%2FContractor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romansky%2FContractor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romansky%2FContractor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/romansky","download_url":"https://codeload.github.com/romansky/Contractor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240990774,"owners_count":19889942,"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":[],"created_at":"2024-11-11T18:07:39.370Z","updated_at":"2025-10-09T18:08:10.997Z","avatar_url":"https://github.com/romansky.png","language":"CoffeeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Contractor\n====\n\nStricter messages in Javascript\n\n## Why?\n\nIn a dynamic language world, you might need to declare a contract for communicating with your APIs, create contracts with Contractor and use them, with:\n\n * server + client side\n * pub / sub implementation\n * external API's\n * Socket.IO communication\n\nContractor will generate a wrapper function for this \"contract\" and make sure the api is used as designed, no more, no less.\n\n## Installation\n\n\tnpm install contractor\n\n## Usage\n\n\t{Contractor} = require 'contractor'\n\n\nCreate a \"contract\" with two required parameters\n\n**Create** Contractor.Create(String, \u003cContractor.Required / Contractor.Optional\u003e..)\n\n\tLoginMessageContract = Contractor.Create(\"LoginMessage\", Contractor.Required(\"user name\"), Contractor.Required(\"password\"))\n\nExecute the contract\n\n\tconsole.log LoginMessageContract(\"knock-knock\",\"itsme!\")\n\t=\u003e [\"LoginMessage\", \"knock-knock\",\"itsme!\"]\n\nBad contract, bad!\n\n\tconsole.log LoginMessageContract(\"knock-knock\")\n\t=\u003e null\n\nAlso, you can always check the name of the contract by calling the toString method\n\n\tLoginMessageContract.toString()\n\t=\u003e \"LoginMessage\"\n\n\n## Lawyer\n\nOne option to use Contracts is to get yourself a Laweyer\n\n\tLawyer = require('contractor').Lawyer\n\nCreate an object that will handle the different events\n\n\tclient = {\n\t\tLoginMessage : (userName, password)-\u003e # do something here...\n\t}\n\nUse the lawyer on the contract and client\n\n\tLayer.Read LoginMessageContract(\"its me!\",\"white rabbit\"), client","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fromansky%2Fcontractor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fromansky%2Fcontractor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fromansky%2Fcontractor/lists"}