From dcf4f9fcfb9b222efe5269efb2bd9e21baf898ec Mon Sep 17 00:00:00 2001 From: Suneil Nyamathi Date: Fri, 6 Sep 2024 14:16:37 -0700 Subject: [PATCH] feat: add typescript types --- index.d.ts | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 23 +++++++++++---------- 2 files changed, 70 insertions(+), 11 deletions(-) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..c00f5ca --- /dev/null +++ b/index.d.ts @@ -0,0 +1,58 @@ +type Bundle = Array | Delta | { dimensions: [{ [dimension: string]: Dimension }] }>; + +type Context = { [dimension: string]: string }; + +type Delta = { + settings: Settings<[`${string}:${string}`, ...Array<`${string}:${string}`>]>; +} & DeepPartial; + +type DeepPartial = T extends object + ? { + [P in keyof T]?: DeepPartial; + } + : T; + +type Dimension = { [dimension: string]: Dimension | null }; + +type Main = { settings: Settings<['main' | 'master']> } & T; + +type Schedule = { start?: string; end?: string }; + +type Settings = T | { dimensions: T; schedule?: Schedule }; + +declare module 'ycb' { + class Ycb { + constructor(bundle: Bundle, options?: { logContext?: string }); + read( + context: Context, + options?: { + applySubstitutions?: boolean; + }, + ): T; + readNoMerge( + context: Context, + options?: { + applySubstitutions?: boolean; + }, + ): T[]; + readTimeAware( + context: Context, + time: number, + options?: { + applySubstitutions?: boolean; + cacheInfo?: boolean; + }, + ): T; + readNoMergeTimeAware( + context: Context, + time: number, + options?: { + applySubstitutions?: boolean; + cacheInfo?: boolean; + }, + ): T[]; + } + + function read(bundle: Bundle, context: Context, validate?: boolean, debug?: boolean): T; + function readNoMerge(bundle: Bundle, context: Context, validate?: boolean, debug?: boolean): T; +} diff --git a/package.json b/package.json index aeb2670..9ee79cd 100644 --- a/package.json +++ b/package.json @@ -2,8 +2,13 @@ "name": "ycb", "version": "2.2.0", "description": "YCB is a multi-dimensional configuration library that builds bundles from resource files describing a variety of values.", - "author": "Ric Allinson ", + "bugs": "https://github.com/yahoo/ycb/issues", + "repository": { + "type": "git", + "url": "git://github.com/yahoo/ycb.git" + }, "license": "BSD", + "author": "Ric Allinson ", "contributors": [ "Drew Folta ", "Michael Ridgway ", @@ -11,6 +16,7 @@ "Isao Yagi " ], "main": "index", + "types": "index.d.ts", "scripts": { "cover": "nyc npm run test", "lint": "eslint . && prettier --check .", @@ -18,20 +24,15 @@ "pretest": "npm run lint", "test": "mocha tests/unit --recursive --reporter spec" }, + "prettier": { + "printWidth": 120, + "singleQuote": true, + "tabWidth": 4 + }, "devDependencies": { "eslint": "^9.0.0", "mocha": "^10.0.0", "nyc": "^17.0.0", "prettier": "^3.0.0" - }, - "repository": { - "type": "git", - "url": "git://github.com/yahoo/ycb.git" - }, - "bugs": "https://github.com/yahoo/ycb/issues", - "prettier": { - "printWidth": 120, - "singleQuote": true, - "tabWidth": 4 } }