{"id":45484876,"url":"https://github.com/tiagocpeixoto/factsory","last_synced_at":"2026-02-22T16:39:57.665Z","repository":{"id":42694521,"uuid":"307790866","full_name":"tiagocpeixoto/factsory","owner":"tiagocpeixoto","description":"A kind of factory and DI patterns library targeted to Typescript (w/o decorators).","archived":false,"fork":false,"pushed_at":"2023-10-21T19:46:50.000Z","size":4395,"stargazers_count":2,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-05T16:51:34.606Z","etag":null,"topics":["factory","factory-pattern","gof","gof-factory","gof-factory-pattern","gof-patterns","pattern","pattern-lib","pattern-library","typescript"],"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/tiagocpeixoto.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2020-10-27T18:20:36.000Z","updated_at":"2023-03-23T21:35:36.000Z","dependencies_parsed_at":"2023-02-18T18:46:05.884Z","dependency_job_id":null,"html_url":"https://github.com/tiagocpeixoto/factsory","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"purl":"pkg:github/tiagocpeixoto/factsory","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiagocpeixoto%2Ffactsory","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiagocpeixoto%2Ffactsory/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiagocpeixoto%2Ffactsory/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiagocpeixoto%2Ffactsory/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tiagocpeixoto","download_url":"https://codeload.github.com/tiagocpeixoto/factsory/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiagocpeixoto%2Ffactsory/sbom","scorecard":{"id":884084,"data":{"date":"2025-08-11","repo":{"name":"github.com/tiagocpeixoto/factsory","commit":"71255a1e37da3693a9ab4a4bc78fa8160fd6513d"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.8,"checks":[{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","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":"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":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/validate.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":"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":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"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":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/validate.yml:40: update your workflow using https://app.stepsecurity.io/secureworkflow/tiagocpeixoto/factsory/validate.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/validate.yml:49: update your workflow using https://app.stepsecurity.io/secureworkflow/tiagocpeixoto/factsory/validate.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/validate.yml:60: update your workflow using https://app.stepsecurity.io/secureworkflow/tiagocpeixoto/factsory/validate.yml/main?enable=pin","Info:   0 out of   3 GitHub-owned GitHubAction 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":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"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":"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:0","Info: FSF or OSI recognized license: MIT License: LICENSE: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":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"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"}},{"name":"Vulnerabilities","score":0,"reason":"16 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-4q6p-r6v2-jvc5","Warn: Project is vulnerable to: GHSA-rc47-6667-2j5j","Warn: Project is vulnerable to: GHSA-78xj-cgh5-2h22","Warn: Project is vulnerable to: GHSA-2p57-rm9w-gvfp","Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-24T09:22:22.154Z","repository_id":42694521,"created_at":"2025-08-24T09:22:22.155Z","updated_at":"2025-08-24T09:22:22.155Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29718517,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-22T15:10:41.462Z","status":"ssl_error","status_checked_at":"2026-02-22T15:10:04.636Z","response_time":110,"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":["factory","factory-pattern","gof","gof-factory","gof-factory-pattern","gof-patterns","pattern","pattern-lib","pattern-library","typescript"],"created_at":"2026-02-22T16:39:57.582Z","updated_at":"2026-02-22T16:39:57.652Z","avatar_url":"https://github.com/tiagocpeixoto.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# factsory \u003csup\u003e[![Version Badge][npm-version-svg]][package-url]\u003c/sup\u003e\n\n[badge.fury.io]: \u003c\u003e \"[![npm version](https://badge.fury.io/js/factsory.svg)](https://badge.fury.io/js/factsory)\"\n[badge.fury.io]: \u003c\u003e \"[![GitHub version](https://badge.fury.io/gh/tiagocpeixoto%2Ffactsory.svg)](https://badge.fury.io/gh/tiagocpeixoto%2Ffactsory)\"\n[GitHub badge]: \u003c\u003e \"![validate](https://github.com/tiagocpeixoto/factsory/workflows/validate/badge.svg)\"\n![npm version](https://img.shields.io/npm/v/factsory)\n![GitHub package.json version](https://img.shields.io/github/package-json/v/tiagocpeixoto/factsory)\n![GitHub Workflow Status](https://img.shields.io/github/workflow/status/tiagocpeixoto/factsory/validate)\n![dependencies](https://img.shields.io/librariesio/github/tiagocpeixoto/factsory)\n![minzipped](https://img.shields.io/bundlephobia/minzip/factsory)\n![license](https://img.shields.io/github/license/tiagocpeixoto/factsory)\n\nA kind of factory and DI patterns library targeted to Typescript (w/o decorators).\n\n\n## Topics\n\n[Installation](#installation)  \n[How to use](#how-to-use)  \n[License](#license)  \n\n\n## Installation\n\nTo install **Factsory**, type the following:\n\n- with NPM:\n\n``` bash\nnpm install factsory\n```\n\n- with YARN:\n\n``` bash\nyarn add factsory\n```\n\n\n## How to use\n\n  \n### Factory definition\n\n- It's possible to define a factory in two ways:\n\n1. extending the `DefaultFactory` class:\n\n    ``` ts\n      class MyFactory extends DefaultFactory\u003cstring\u003e {\n        instantiate(): string {\n          return \"value\";\n        }\n      }\n    ```\n\n1. implementing the `Factory` interface:\n\n   ``` ts\n      class MyFactory implements Factory\u003cstring\u003e {\n        create(): string {\n          return \"value\";\n        }\n      }\n   ```\n\n\n### Container instance\n\n- To access the Container instance, just call the `Container.I` static method\n\n- It's possible to define a customized Container implementation, useful for testing. You just need to implement \n  the `ContainerSpec` interface as in the following example (based on [jest-mock-extended](https://www.npmjs.com/package/jest-mock-extended)):\n\n   ``` ts\n   // using jest-mock-extended package\n   const mockedSpec = mock\u003cContainerSpec\u003e();\n   Container.impl = mockedSpec;\n  \n   // To reset to the default implementation, just call reset()\n   Container.reset();\n   ```\n\n\n### Container registration\n\n- A class or almost any other object can be registered in the Container, which can be done in two ways:\n\n1. registering a class (e.g. a factory class - see [Factory definition](#factory-definition) section):\n\n   ``` ts\n   // id = \"MyFactory\"\n   Container.I.register(MyFactory);\n   \n   // or\n   Container.I.register(MyFactory, { id: \"MyFactoryCustomId\" });\n   ```\n\n1. registering a creation function (factory method) using the ```createFactoryMethod```:\n\n   ``` ts\n   // id will be set to \"\"\n   Container.I.register(createFactoryMethod(() =\u003e \"value\"));\n   \n   // or\n   Container.I.register(createFactoryMethod(() =\u003e \"value\"), { id: \"MyFactoryWithValue\" });\n   \n   // or\n   Container.I.register(createFactoryMethod((params?: CreationParameters) =\u003e params?.args), { id: \"MyFactoryWithArgs\", args: \"value\" });\n   ```\n   \n- It's also possible to define dependencies, which will be injected during the object creation:\n \n   ``` ts\n    // the dependency\n    class MyFactory extends DefaultFactory\u003cstring\u003e {\n      instantiate(): string {\n        return \"aValue\";\n      }\n    }\n  \n    // the target of the dependency injection\n    class MyFactoryWithDependencies extends DefaultFactory\u003cstring\u003e {\n      protected readonly myFactory: MyFactory;\n\n      constructor(\n        params?: ContainerItemCreationDependencies\u003c{\n          MyFactory: MyFactory;\n        }\u003e\n      ) {\n        super();\n        if (params?.dependencies) {\n          this.myFactory = params.dependencies.MyFactory;\n        } else {\n          throw new Error(\"Invalid dependencies\");\n        }\n\n        if (!this.myFactory) {\n          throw new Error(\"Invalid MyFactory dependency\");\n        }\n      }\n  \n      get dep(): MyFactory {\n        return this.myFactory;\n      }\n\n      instantiate(): string {\n        return \"MyuFactoryWithDependencies\";\n      }\n    }  \n  \n    // registering objects\n    Container.I.register(MyFactory);\n    Container.I.register(MyFactoryWithDependencies, {\n      dependencies: [MyFactory],\n    });\n  \n    // will print 'aValue'\n    console.log(Container.I.get(MyFactoryWithDependencies)?.dep.create());\n   ```\n\n\n### Object claim from Container\n\n- After registering a class or a creation function (factory method), it can also be claimed in two ways: \n\n1. If it is a class, it can be claimed by the `Container.I.get` method using the class name as a parameter:\n\n   ``` ts\n   Container.I.get(MyFactory);\n   ```\n\n1. If it is a creation function, it can be claimed by the `Container.I.get` method using the registered name as a parameter:\n\n   ``` ts\n   Container.I.get(\"MyFactory\");\n   ```\n\n\n### Lazy instance \n\n- It's possible to use the `LazyInstance` class to lazy initialize an object:\n\n    ``` ts\n    let value = \"\";\n\n    const lazyInstance = new LazyInstance(() =\u003e (value = \"initialized\"));\n\n    console.log(value);          // prints \"\"\n    console.log(lazyInstance.I); // prints \"initialized\"\n    // or \n    console.log(lazyInstance.getI()); // prints \"initialized\"\n    console.log(value);               // prints \"initialized\"\n    ```\n\n\n### Async Lazy instance\n\n- It's possible to use the `AsyncLazyInstance` class to lazy initialize an object:\n\n    ``` ts\n    let value = \"\";\n\n    const asyncLazyInstance = new AsyncLazyInstance(async () =\u003e (value = \"initialized\"));\n\n    console.log(value);                     // prints \"\"\n    console.log(await asyncLazyInstance.I); // prints \"initialized\"\n    // or \n    console.log(await asyncLazyInstance.getI()); // prints \"initialized\"\n    console.log(value);                          // prints \"initialized\"\n    ```\n\n- It's also possible to use the `AsyncLazyInstance` class to lazy initialize an object with concurrency lock (mutex-like) control:\n\n    ``` ts\n    let value = \"\";\n\n    const asyncLazyInstance = new AsyncLazyInstance(\n      async () =\u003e (value = \"initialized\"),\n      /** \n       * Using async-mutex lib as an example \n       * @see https://www.npmjs.com/package/async-mutex\n       */\n      { lock: new Mutex() }\n    );\n\n    console.log(value);                     // prints \"\"\n    console.log(await asyncLazyInstance.I); // prints \"initialized\"\n    // or \n    console.log(await asyncLazyInstance.getI()); // prints \"initialized\"\n    console.log(value);                          // prints \"initialized\"\n\n## License\n\nCopyright (c) 2022 Tiago da Costa Peixoto \u003ctiagocpeixoto@gmail.com\u003e\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n[package-url]: https://npmjs.org/package/factsory\n[npm-version-svg]: https://versionbadg.es/tiagocpeixoto/factsory.svg","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftiagocpeixoto%2Ffactsory","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftiagocpeixoto%2Ffactsory","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftiagocpeixoto%2Ffactsory/lists"}