{"id":21575557,"url":"https://github.com/rangle/hack-stack","last_synced_at":"2025-03-18T06:45:45.043Z","repository":{"id":45030011,"uuid":"37537049","full_name":"rangle/hack-stack","owner":"rangle","description":"Deprecated. Please use https://github.com/rangle/hackstack","archived":false,"fork":false,"pushed_at":"2021-03-25T05:48:31.000Z","size":101,"stargazers_count":0,"open_issues_count":10,"forks_count":3,"subscribers_count":5,"default_branch":"future","last_synced_at":"2025-01-24T13:32:14.614Z","etag":null,"topics":[],"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/rangle.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":"2015-06-16T14:58:34.000Z","updated_at":"2015-06-16T15:27:30.000Z","dependencies_parsed_at":"2022-07-31T16:39:01.988Z","dependency_job_id":null,"html_url":"https://github.com/rangle/hack-stack","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/rangle%2Fhack-stack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rangle%2Fhack-stack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rangle%2Fhack-stack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rangle%2Fhack-stack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rangle","download_url":"https://codeload.github.com/rangle/hack-stack/tar.gz/refs/heads/future","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244173507,"owners_count":20410295,"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-24T12:13:36.958Z","updated_at":"2025-03-18T06:45:45.022Z","avatar_url":"https://github.com/rangle.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HackStack [![Build status](https://circleci.com/gh/rangle/hack-stack.svg?style=svg\u0026circle-token=4e9f2c3295779e2494abbf8fc84a8aa4f4da0c3f)](https://circleci.com/gh/rangle/hack-stack)\n\n## What is HackStack?\n\n**HackStack** is an Angular module that lets you develop against APIs that\ndon't exist yet or that aren't complete.\n\nAt Rangle.io we spend a lot of time building against API's that are either \nnon-existent or partially existent.  \n\nOur CEO and CTO gave a talk about a method of getting around this \nproblem by creating mock API end points that your app can run against.  \nYou can see the full presentation [here]\n(http://yto.io/slides/Building-an-AngularJS-Hack-Stack-2015.pdf)\n\nWhile the presentation specifies that the HackStack is a methodology, not a \nlibrary, the enthusiasm we saw for a library could not be ignored.  This is the\nlibrary.\n\n## Installing the service\n\nThis needs work, but for now take the HackStack folder out of the core \ndirectory and add it into your project.  You will need to change the module \nnames appropriately.\n\nCurrently the module has it living in the showcase app.\n\nTODO: Make this a bower installable stand alone library.\n\n## Using HackStack\n\nTo create a new HackStack endpoint.  Simply call\n`hackstack.mock(data)`\nOR\n`hackstack.wrap(endpoint, mockObject)` if you have a part of an endpoint.\n \nwhere data is either an array of items or a path to a json file.  That's it,\nnow you have your mock end point that you can use just like a regular endpoint.\n\nNote that the `hackstack.wrap` service requires that you inject an `API_BASE`\nvariable that contains the base URL for the API you're wrapping.\n\n### Accessing HackStack from the chrome console\n\nWhile you're working if you want to force a particular error you can call\n`window.hsUtils.forceError(\u003cHTTP ERROR CODE\u003e)` and the next request will\nmagically return that error.\n\nSimilarly, if random errors are entirely too frequent for you, you can disable\nthem by calling `window.hsUtils.disableErrors(true)`.  Once you decide you\nwant errors back, you can call `window.hsUtils.disableErrors(false)`.\n\n## Assumptions\n\nThis library makes a couple of assumptions:\n\n* You're using AngularJS.  It's designed using AngularJS services.\n\n* You're using an abstraction factory to wrap your end points.  This service \nwill provide you an object that has methods for getting all records, getting a \nsingle record, creating a record, etc.\n\n## Architecture\n\n### `hackstack.utils`\n\nThis service provides methods that are used by both `hackstack.mock` and `hackstack.wrap`\nservices.  Those functions are:\n\n* `disableErrors(value)`: Disable random error generation. \u003cbr/\u003e\n  `value` : {boolean}\n* `forceError(errorCode)`: Reject with this error code in the next response.\n  \u003cbr/\u003e\n  `errorCode` : {integer}\n* `produceError(errorArray)`: Return either an error object or null depending \n  on the probability distribution defined in the errorArray \u003cbr/\u003e\n  `errorArray` : {\\[object]} (optional) an array of error objects\n* `getErrorByCode(errorCode)`: Returns an error object with error code matching\n  `errorCode`. \u003cbr/\u003e\n  `errorCode` : {integer}\n* `randomInt()`: Returns a random integer. \u003cbr/\u003e\n* `waitForTime()`: Returns a promise that resolves after some time. Used to\n  mimic latency \u003cbr/\u003e\n\n### `hackstack.mock`\n\n`hackstack.mock` is a service that creates a mock backend from scratch.\nTo create a HackStack instance, call `hackstack.mock(mockData, options)` where `mockData` \nis an array of objects and `options` is an optional argument of type `Object`\n\nA `hackstack.mock` object contains the following methods:\n\n* `getAll()`: Get all results (equivalent to requesting `API_BASE/endpoint/`)\n* `get(id)`: Get a single result (equivalent to requesting `API_BASE/endpoint/id`)\n* `query()`: Issue a filter against a result set (For now just works the same as\n  getAll.\n* `create(object, createIdFn)`: Create a new record \u003cbr/\u003e\n  `object` : {object} \u003cbr/\u003e\n  `createIdFn` {() -\u003e int} Function that returns an integer to be used as an id\n* `update(object, createIdFn)`: Update a record. \u003cbr/\u003e\n  signature is identical to `create`\n* `save(object, createIdFn)`: a method that will call create or update \n  depending on presence of an id. \u003cbr/\u003e\n  signature is identical to `create`\n\n### `hackstack.wrap`\n\n`hackstack.wrap` is a service that wraps a real backend with a local mock object.\nIt can be useful if the backend is buggy, returns incomplete data, or is yet to \nbe fully implemented.\n\nTo create a `hackstack.wrap` instance, call `hackstack.wrap(endpoint, mockObject, options)`\nwhere:\n\n* `endpoint` is a string that contains the location of the endpoint\n* `mockObject` is a single object used to complete responses from the backend\n* `options` is a an object (optional argument)\n\nNote that unlike `hackstack.mock`, you only pass a single object to `hackstack.wrap`.\nIt will use that one object to complete all of the responses your backend\nreturns by deep merging the response's properties with the objects\n\n`hackstack.wrap` also requires that you make `API_BASE` available through Angular's\ninjector. `API_BASE` should be a string that contains the base URL for your\nAPI.\n\nthe `hackstack.wrap` factory returns an object which contains the same methods as\na `hackstack.mock` object. Keep in mind however, that `hackstack.wrap` will relay all\nrequests to the backend, including `post` requests.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frangle%2Fhack-stack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frangle%2Fhack-stack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frangle%2Fhack-stack/lists"}