{"id":22501257,"url":"https://github.com/poppinss/macroable","last_synced_at":"2026-03-09T07:05:55.119Z","repository":{"id":21484674,"uuid":"93030615","full_name":"poppinss/macroable","owner":"poppinss","description":"Extend classes from outside in using Macros and getters","archived":false,"fork":false,"pushed_at":"2025-09-11T06:00:42.000Z","size":857,"stargazers_count":40,"open_issues_count":0,"forks_count":2,"subscribers_count":5,"default_branch":"1.x","last_synced_at":"2026-01-27T03:12:03.430Z","etag":null,"topics":["extend","macroable"],"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/poppinss.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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},"funding":{"github":"thetutlage"}},"created_at":"2017-06-01T07:44:09.000Z","updated_at":"2026-01-10T03:42:58.000Z","dependencies_parsed_at":"2024-03-28T06:28:34.814Z","dependency_job_id":"4fcdf224-a8b4-4eac-aa85-a08c4932f78f","html_url":"https://github.com/poppinss/macroable","commit_stats":{"total_commits":89,"total_committers":3,"mean_commits":"29.666666666666668","dds":0.0337078651685393,"last_synced_commit":"62ec0ddc51b71cbe100f82c2e51addbc6427fc26"},"previous_names":[],"tags_count":40,"template":false,"template_full_name":null,"purl":"pkg:github/poppinss/macroable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poppinss%2Fmacroable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poppinss%2Fmacroable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poppinss%2Fmacroable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poppinss%2Fmacroable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/poppinss","download_url":"https://codeload.github.com/poppinss/macroable/tar.gz/refs/heads/1.x","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poppinss%2Fmacroable/sbom","scorecard":{"id":741208,"data":{"date":"2025-08-11","repo":{"name":"github.com/poppinss/macroable","commit":"cf4c7d4edc8a976fb5af03bea03169439ec45cc0"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":4.2,"checks":[{"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":"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":"Maintained","score":2,"reason":"3 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 2","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"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":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","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":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: third-party GitHubAction not pinned by hash: .github/workflows/checks.yml:8: update your workflow using https://app.stepsecurity.io/secureworkflow/poppinss/macroable/checks.yml/1.x?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/checks.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/poppinss/macroable/checks.yml/1.x?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/checks.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/poppinss/macroable/checks.yml/1.x?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/labels.yml:10: update your workflow using https://app.stepsecurity.io/secureworkflow/poppinss/macroable/labels.yml/1.x?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/labels.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/poppinss/macroable/labels.yml/1.x?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/poppinss/macroable/release.yml/1.x?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/poppinss/macroable/release.yml/1.x?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/stale.yml:10: update your workflow using https://app.stepsecurity.io/secureworkflow/poppinss/macroable/stale.yml/1.x?enable=pin","Warn: npmCommand not pinned by hash: .github/workflows/release.yml:32","Info:   0 out of   4 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   4 third-party GitHubAction dependencies pinned","Info:   0 out of   1 npmCommand dependencies pinned"],"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":"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":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/checks.yml:1","Warn: topLevel 'contents' permission set to 'write': .github/workflows/release.yml:4","Warn: no topLevel permission defined: .github/workflows/stale.yml:1","Info: no jobLevel write permissions found"],"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":"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.md:0","Info: FSF or OSI recognized license: MIT License: LICENSE.md: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":"Security-Policy","score":10,"reason":"security policy file detected","details":["Info: security policy file detected: github.com/poppinss/.github/docs/SECURITY.md:1","Info: Found linked content: github.com/poppinss/.github/docs/SECURITY.md:1","Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/poppinss/.github/docs/SECURITY.md:1","Info: Found text in security policy: github.com/poppinss/.github/docs/SECURITY.md:1"],"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":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 1 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch '1.x'"],"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-22T17:31:24.563Z","repository_id":21484674,"created_at":"2025-08-22T17:31:24.563Z","updated_at":"2025-08-22T17:31:24.563Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30283783,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-09T02:57:19.223Z","status":"ssl_error","status_checked_at":"2026-03-09T02:56:26.373Z","response_time":61,"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":["extend","macroable"],"created_at":"2024-12-06T23:02:03.622Z","updated_at":"2026-03-09T07:05:55.111Z","avatar_url":"https://github.com/poppinss.png","language":"TypeScript","funding_links":["https://github.com/sponsors/thetutlage"],"categories":["TypeScript"],"sub_categories":[],"readme":"# @poppinss/macroable\n\u003e Extend classes from outside in using Macros and getters\n\n[![gh-workflow-image]][gh-workflow-url] [![typescript-image]][typescript-url] [![npm-image]][npm-url] [![license-image]][license-url]\n\nMacroable offers a simple API for adding properties and getters to the class prototype. You might not even need this package, if you are happy writing `Object.defineProperty` calls yourself.\n\n## Usage\nInstall the package from npm packages registry as follows.\n\n```sh\nnpm i @poppinss/macroable\n\n# yarn lovers\nyarn add @poppinss/macroable\n```\n\nAnd import the `Macroable` class.\n\n```ts\nimport Macroable from '@poppinss/macroable'\nexport class Route extends Macroable {}\n```\n\nNow, you can add properties to the Route class from outside-in. This is usually needed, when you want the consumer of your classes to be able to extend them by adding custom properties.\n\n## Macros\nGetters are added to the class prototype directly.\n\n```ts\nRoute.macro('head', function (uri, callback) {\n  return this.route(['HEAD'], uri, callback)\n})\n```\n\nAnd now, you can will be use the `head` method from an instance of the `Route` class.\n\n```ts\nconst route = new Route()\nroute.head('/', () =\u003e {})\n```\n\nAdding a macro is same as writing the following code in JavaScript.\n\n```ts\nRoute.prototype.head = function () {\n}\n```\n\n## Instance properties\nSince, macros are defined on the prototype of the class and therefore they loose the `this` context when destructured from the class instance. For example:\n\n```ts\nHttpContext.macro('getUser', function (this: HttpContext) {\n  return this.auth.user\n})\n\nconst { getUser } = ctx\ngetUser() // ❌ Error: Cannot read property auth of undefined\n```\n\nIn order to fix this issue, the properties that can be destructured must be defined as instance properties on the class.\n\n```ts\nHttpContext.instanceProperty('getUser', function (this: HttpContext) {\n  return this.auth.user\n})\n\nconst { getUser } = ctx\ngetUser() // ✅ Works fine\n```\n\n## Getters\nGetters are added to the class prototype using the `Object.defineProperty`. The implementation of a getter is always a function.\n\n```ts\nRoute.getter('version', function () {\n  return 'v1'\n})\n```\n\nAnd now access the version as follows.\n\n```ts\nconst route = new Route()\nroute.version // v1\n```\n\nAdding a getter is same as writing the following code in JavaScript.\n\n```ts\nObject.defineProperty(Route.prototype, 'version', {\n  get() {\n    const value = callback()\n    return value\n  },\n  configurable: false,\n  enumerable: false,\n})\n```\n\n## Singleton getters\nSingleton getters are also defined on the class prototype. However, their values are cached after the first access.\n\n```ts\nconst singleton = true\n\nMysql.getter('version', function () {\n  return this.config.driver.split('-')[1]\n}, singleton)\n```\n\nAdding a singleton getter is same as writing the following code in JavaScript.\n\n```ts\nObject.defineProperty(Mysql.prototype, 'version', {\n  get() {\n    const value = callback()\n\n    // Cache value on the class instance\n    Object.defineProperty(this, 'version', {\n      configurable: false,\n      enumerable: false,\n      value: value,\n      writable: false,\n    })\n\n    return value\n  },\n  configurable: false,\n  enumerable: false,\n})\n```\n\n## TypeScript types\nYou will have to use [module augmentation](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation) in order to define the types for the dynamically added properties.\n\n## Contributing\n\nOne of our primary goals is to have a vibrant community of users and contributors who believes in the principles of the framework.\n\nWe encourage you to read the [contribution guide](https://github.com/poppinss/.github/blob/main/docs/CONTRIBUTING.md) before contributing to the framework.\n\n## Code of Conduct\n\nIn order to ensure that the community is welcoming to all, please review and abide by the [Code of Conduct](https://github.com/poppinss/.github/blob/main/docs/CODE_OF_CONDUCT.md).\n\n## License\n\nPoppinss macroable is open-sourced software licensed under the [MIT license](LICENSE.md).\n\n[gh-workflow-image]: https://img.shields.io/github/actions/workflow/status/poppinss/macroable/checks.yml?style=for-the-badge\n[gh-workflow-url]: https://github.com/poppinss/macroable/actions/workflows/checks.yml \"Github action\"\n\n[typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge\u0026logo=typescript\n[typescript-url]: \"typescript\"\n\n[npm-image]: https://img.shields.io/npm/v/@poppinss/macroable.svg?style=for-the-badge\u0026logo=npm\n[npm-url]: https://npmjs.org/package/@poppinss/macroable 'npm'\n\n[license-image]: https://img.shields.io/npm/l/@poppinss/macroable?color=blueviolet\u0026style=for-the-badge\n[license-url]: LICENSE.md 'license'\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpoppinss%2Fmacroable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpoppinss%2Fmacroable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpoppinss%2Fmacroable/lists"}