{"id":23174244,"url":"https://github.com/coursedesign/conev-sync","last_synced_at":"2025-08-18T09:30:56.188Z","repository":{"id":36976720,"uuid":"291404581","full_name":"CourseDesign/conev-sync","owner":"CourseDesign","description":null,"archived":false,"fork":false,"pushed_at":"2023-03-07T04:59:19.000Z","size":86,"stargazers_count":1,"open_issues_count":15,"forks_count":2,"subscribers_count":1,"default_branch":"develop","last_synced_at":"2024-05-28T20:49:05.854Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/conev-sync","language":"TypeScript","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/CourseDesign.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":"2020-08-30T05:11:47.000Z","updated_at":"2023-01-31T18:29:36.000Z","dependencies_parsed_at":"2023-02-16T03:46:07.481Z","dependency_job_id":null,"html_url":"https://github.com/CourseDesign/conev-sync","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":"CourseDesign/node-boilerplate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CourseDesign%2Fconev-sync","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CourseDesign%2Fconev-sync/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CourseDesign%2Fconev-sync/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CourseDesign%2Fconev-sync/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CourseDesign","download_url":"https://codeload.github.com/CourseDesign/conev-sync/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230220158,"owners_count":18192228,"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-12-18T05:19:40.942Z","updated_at":"2024-12-18T05:19:41.557Z","avatar_url":"https://github.com/CourseDesign.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# conev-sync\nConev-sync is a synchronous version of [conev](#reference). You can save, manage and use configuration through it.\n\n## Contents\n\n - [Install](#install)\n - [Usage](#usage)\n   - [ConfigBuilder](#configbuilder)\n   - [Config](#config)\n   - [Source](#source)\n   - [Sources](#sources)\n   - [JsonSource](#jsonsource)\n - [Example](#example)\n - [Reference](#reference)\n## Install\n```shell\nnpm install conev-sync\n```\n\n## Usage\n\nGet ConfigBuilder from conev-sync and one or more Sources to use. In this example, the built-in JsonSource is used.\n\n```typescript\nimport { ConfigBuilder, JsonSource } from 'conev-sync';\n```\n\n\nThen, create Sources and set up.\n\n```typescript\nconst jsonSource = new JsonSource();\n\njsonSource\n    .set('basic', basic) //basic is JSON\n    .set('dev', dev) //dev is JSON\n    .set('prd', prd); //prd is JSON\n```\n\n\nCreate ConfigBuilder and add Environment, Source.\n\n```typescript\nconst builder = new ConfigBuilder();\n\nbuilder\n    .addEnv('dev', 'basic')\n    .addSource(jsonSource);\n```\n\n\nBuild configuration.\n\n```typescript\nconst config = builder.build(); // This is the result of combining dev and basic.\n```\n\n\nUse configuration.\n\n```typescript\nconfig.get(); // The whole configuration created comes out\nconfig.get('a.b.c'); // Is same as config.get().a.b.c\n ```\n\n\n\n*Each of Environments and Sources are merged by [deepmerge](#reference).(What is added first has high priority)*\nYou can set deepmerge options as follow :\n\n```typescript\nbuilder.setOptions(options);\n```\n\n### ConfigBuilder\n\n```typescript\nclass ConfigBuilder {\n    addSource(...sources: Source[]): ConfigBuilder;\n    addEnv(...envs: string[]): ConfigBuilder;\n    setOptions(options?: Options): ConfigBuilder;\n    build(): Config;\n}\n```\n`ConfigBuilder` takes a configuration from the source and creates a new configuration according to the environment. `Env` and `Source` have priority. If priority is not defined, highest priority is added first.\n\n### Config\n\n```typescript\nclass Config {\n    constructor(sources: Source[], envs: string[], options?: Options);\n    sync(): Config;\n    get(key = ''): unknown | undefined;\n}\n```\n`config`  is a container for configuration.  `config`  is provided by creating a new configuration from the configuration and environment obtained from  `source`.\n\n### Source\n\n```typescript\ninterface Source {\n    export(): Map\u003cstring, Record\u003cstring, unknown\u003e\u003e;\n}\n```\n`Source` defines the source from which to get the configuration. Map is returned as the result value of `export`. The key of this map is environment and the value is the configuration when environment.\n\nYou can make custom `Source` and use that.\n\n### Sources\n\n```typescript\nclass Sources implements Source {\n    constructor(sources: Source[], options?: Options);\n    add(source: Source, priority = -1): Sources;\n    export(): Map\u003cstring, Record\u003cstring, unknown\u003e\u003e;\n}\n```\n`Sources` defines the source by merging several sources. Use `add` to add source for new source. Map is returned as the result value of `export`. The key of this map is environment and the value is the configuration when environment.\n\n\n### JsonSource\n\n```typescript\nexport default class JsonSource {\n    constructor();\n    set(env: string, json: Record\u003cstring, unknown\u003e): JsonSource;\n    export(): Map\u003cstring, Record\u003cstring, unknown\u003e\u003e;\n}\n```\n`JsonSource` defines the source from JSON. Use `set` to add a configuration for a new environment. Map is returned as the result value of `export`. The key of this map is environment and the value is the configuration when environment.\n\n## Example\n\n## Reference\n\n - [conev](https://github.com/CourseDesign/conev)\n - [deepmerge](https://github.com/TehShrike/deepmerge)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoursedesign%2Fconev-sync","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoursedesign%2Fconev-sync","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoursedesign%2Fconev-sync/lists"}