{"_id":"@chubbyts/chubbyts-dic-config-factory","name":"@chubbyts/chubbyts-dic-config-factory","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@chubbyts/chubbyts-dic-config-factory","type":"module","version":"1.0.0","description":"An abstract service factory for the dependency injection container, usable with chubbyts-dic-config, inspired by chubbyphp-laminas-config-factory.","keywords":["chubbyts","dic","dependency-injection-container","dependency-injection","container","config","factory","abstract-factory","service-factory","psr-11"],"author":"Dominik Zogg","license":"MIT","repository":{"type":"git","url":"chubbyts/chubbyts-dic-config-factory"},"prettier":{"printWidth":120,"tabWidth":2,"singleQuote":true,"trailingComma":"all"},"exports":{"./*":{"types":"./*.d.ts","import":"./*.js","default":"./*.js"}},"engines":{"node":">=22"},"dependencies":{"@chubbyts/chubbyts-dic-types":"^2.3.0"},"devDependencies":{"@chubbyts/chubbyts-dic":"^2.3.0","@chubbyts/chubbyts-dic-config":"^2.3.0","@chubbyts/chubbyts-oxlint":"^1.0.0","@stryker-mutator/core":"^9.6.1","@stryker-mutator/vitest-runner":"^9.6.1","@types/node":"^26.1.2","@vitest/coverage-v8":"^4.1.10","oxlint":"^1.76.0","prettier":"^3.9.6","typescript":"^7.0.2","vitest":"^4.1.10"},"publishConfig":{"access":"public"},"scripts":{"build":"rm -Rf dist && tsc","cs-fix":"prettier --write src tests","cs":"prettier --check src tests","infection":"stryker run","lint-fix":"oxlint --fix src tests vitest.config.ts","lint":"oxlint src tests vitest.config.ts","test":"vitest"},"_nodeVersion":"24.19.0","_id":"@chubbyts/chubbyts-dic-config-factory@1.0.0","dist":{"integrity":"sha512-h3ov2nY0a9kVuPZv0GxhS5XI9Uh+aBBMOZ0fSzQvrD+zuOe+NTLggjU+5rbDNqnZtZHzIzDUiXmbSAcVtxIN7A==","shasum":"db529f75f75f3ea2f7e8734c70da59711b18b48d","tarball":"https://registry.npmjs.org/@chubbyts/chubbyts-dic-config-factory/-/chubbyts-dic-config-factory-1.0.0.tgz","fileCount":5,"unpackedSize":11863,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIDyCPefpZ3NCEJBRhzot1BKee2gddzfkklXQKd7YNH+iAiEAlxzHjUYh2FX0ZMEigRX5qjECy78FqwqdbATLrJfsLDg="}]},"_npmUser":{"name":"dominikzogg","email":"dominik.zogg@ikmail.com"},"directories":{},"maintainers":[{"name":"dominikzogg","email":"dominik.zogg@ikmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/chubbyts-dic-config-factory_1.0.0_1787492241489_0.04951563870137066"},"_hasShrinkwrap":false}},"time":{"created":"2026-08-23T13:37:21.341Z","1.0.0":"2026-08-23T13:37:21.628Z","modified":"2026-08-23T13:37:21.952Z"},"maintainers":[{"name":"dominikzogg","email":"dominik.zogg@ikmail.com"}],"description":"An abstract service factory for the dependency injection container, usable with chubbyts-dic-config, inspired by chubbyphp-laminas-config-factory.","keywords":["chubbyts","dic","dependency-injection-container","dependency-injection","container","config","factory","abstract-factory","service-factory","psr-11"],"repository":{"type":"git","url":"chubbyts/chubbyts-dic-config-factory"},"author":"Dominik Zogg","license":"MIT","readme":"# chubbyts-dic-config-factory\n\n[![CI](https://github.com/chubbyts/chubbyts-dic-config-factory/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/chubbyts/chubbyts-dic-config-factory/actions/workflows/ci.yml)\n[![Coverage Status](https://coveralls.io/repos/github/chubbyts/chubbyts-dic-config-factory/badge.svg?branch=master)](https://coveralls.io/github/chubbyts/chubbyts-dic-config-factory?branch=master)\n[![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fchubbyts%2Fchubbyts-dic-config-factory%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/chubbyts/chubbyts-dic-config-factory/master)\n[![npm-version](https://img.shields.io/npm/v/@chubbyts/chubbyts-dic-config-factory.svg)](https://www.npmjs.com/package/@chubbyts/chubbyts-dic-config-factory)\n\n[![bugs](https://sonarcloud.io/api/project_badges/measure?project=chubbyts_chubbyts-dic-config-factory&metric=bugs)](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-dic-config-factory)\n[![code_smells](https://sonarcloud.io/api/project_badges/measure?project=chubbyts_chubbyts-dic-config-factory&metric=code_smells)](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-dic-config-factory)\n[![coverage](https://sonarcloud.io/api/project_badges/measure?project=chubbyts_chubbyts-dic-config-factory&metric=coverage)](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-dic-config-factory)\n[![duplicated_lines_density](https://sonarcloud.io/api/project_badges/measure?project=chubbyts_chubbyts-dic-config-factory&metric=duplicated_lines_density)](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-dic-config-factory)\n[![ncloc](https://sonarcloud.io/api/project_badges/measure?project=chubbyts_chubbyts-dic-config-factory&metric=ncloc)](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-dic-config-factory)\n[![sqale_rating](https://sonarcloud.io/api/project_badges/measure?project=chubbyts_chubbyts-dic-config-factory&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-dic-config-factory)\n[![alert_status](https://sonarcloud.io/api/project_badges/measure?project=chubbyts_chubbyts-dic-config-factory&metric=alert_status)](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-dic-config-factory)\n[![reliability_rating](https://sonarcloud.io/api/project_badges/measure?project=chubbyts_chubbyts-dic-config-factory&metric=reliability_rating)](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-dic-config-factory)\n[![security_rating](https://sonarcloud.io/api/project_badges/measure?project=chubbyts_chubbyts-dic-config-factory&metric=security_rating)](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-dic-config-factory)\n[![sqale_index](https://sonarcloud.io/api/project_badges/measure?project=chubbyts_chubbyts-dic-config-factory&metric=sqale_index)](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-dic-config-factory)\n[![vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=chubbyts_chubbyts-dic-config-factory&metric=vulnerabilities)](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-dic-config-factory)\n\n## Description\n\nAn abstract service factory for the dependency injection container, usable with [@chubbyts/chubbyts-dic-config][2],\ninspired by [chubbyphp-laminas-config-factory][5].\n\nIt reduces the boilerplate within config based service factories:\n\n * `resolveConfig`: resolves the (named) config of the current service\n * `resolveDependency`: resolves a dependency via the container if present, or creates it via the given abstract factory\n * `resolveValue`: resolves a value, replacing strings (recursively within arrays / objects) by matching services\n\n## Requirements\n\n * node: 22\n * [@chubbyts/chubbyts-dic-types][4]: ^2.3.0\n\n## Installation\n\nThrough [NPM](https://www.npmjs.com) as [@chubbyts/chubbyts-dic-config-factory][1].\n\n```ts\nnpm i @chubbyts/chubbyts-dic-config-factory@^1.0.0\n```\n\n## Usage\n\n### Factory\n\n```ts\nimport { createAbstractFactory } from '@chubbyts/chubbyts-dic-config-factory/dist/dic-config-factory';\nimport { ServiceA } from '../service/service-a';\nimport type { Config } from '../config';\nimport { serviceBFactory } from './service-b-factory';\n\nexport const serviceAFactory = createAbstractFactory((container, { resolveConfig, resolveDependency }): ServiceA => {\n  return new ServiceA(\n    resolveConfig(container.get<Config>('config').serviceA ?? {}),\n    resolveDependency(container, 'serviceB', serviceBFactory),\n  );\n});\n```\n\n### With [@chubbyts/chubbyts-dic-config][2]\n\n```ts\nimport { createContainerByConfigFactory } from '@chubbyts/chubbyts-dic-config/dist/dic-config';\nimport type { ServiceA } from './service/service-a';\nimport { serviceAFactory } from './factory/service-a-factory';\nimport { serviceBFactory } from './factory/service-b-factory';\n\nconst containerByConfigFactory = createContainerByConfigFactory({\n  serviceA: { key: 'value' },\n  serviceB: { key2: 'value2' },\n  dependencies: {\n    factories: new Map([\n      ['serviceA', serviceAFactory()],\n      ['serviceB', serviceBFactory()],\n    ]),\n  },\n});\n\nconst container = containerByConfigFactory();\n\nconst serviceA = container.get<ServiceA>('serviceA');\n```\n\n### With names\n\nThe same abstract factory can be reused for multiple services of the same kind, for example a `read` and a `write`\ndatabase connection. The given name resolves the related sub config (`resolveConfig`) and gets appended to the id of\neach dependency (`resolveDependency`).\n\n```ts\nimport { createContainerByConfigFactory } from '@chubbyts/chubbyts-dic-config/dist/dic-config';\nimport type { ServiceA } from './service/service-a';\nimport { serviceAFactory } from './factory/service-a-factory';\nimport { serviceBFactory } from './factory/service-b-factory';\n\nconst containerByConfigFactory = createContainerByConfigFactory({\n  serviceA: { read: { key: 'valueRead' }, write: { key: 'valueWrite' } },\n  serviceB: { read: { key2: 'value2Read' }, write: { key2: 'value2Write' } },\n  dependencies: {\n    factories: new Map([\n      ['serviceAread', serviceAFactory('read')],\n      ['serviceAwrite', serviceAFactory('write')],\n      ['serviceBread', serviceBFactory('read')],\n      ['serviceBwrite', serviceBFactory('write')],\n    ]),\n  },\n});\n\nconst container = containerByConfigFactory();\n\nconst serviceARead = container.get<ServiceA>('serviceAread');\nconst serviceAWrite = container.get<ServiceA>('serviceAwrite');\n```\n\n## Copyright\n\n2026 Dominik Zogg\n\n[1]: https://www.npmjs.com/package/@chubbyts/chubbyts-dic-config-factory\n[2]: https://www.npmjs.com/package/@chubbyts/chubbyts-dic-config\n[3]: https://www.npmjs.com/package/@chubbyts/chubbyts-dic\n[4]: https://www.npmjs.com/package/@chubbyts/chubbyts-dic-types\n[5]: https://github.com/chubbyphp/chubbyphp-laminas-config-factory\n","readmeFilename":"","_rev":"1-876e2649b5165865359f494cddf74a9b"}