Skip to content

Commit

Permalink
feat: add typescript types
Browse files Browse the repository at this point in the history
  • Loading branch information
snyamathi committed Sep 6, 2024
1 parent e9ba8f6 commit dcf4f9f
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 11 deletions.
58 changes: 58 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
type Bundle<T> = Array<Main<T> | Delta<T> | { dimensions: [{ [dimension: string]: Dimension }] }>;

type Context = { [dimension: string]: string };

type Delta<T> = {
settings: Settings<[`${string}:${string}`, ...Array<`${string}:${string}`>]>;
} & DeepPartial<T>;

type DeepPartial<T> = T extends object
? {
[P in keyof T]?: DeepPartial<T[P]>;
}
: T;

type Dimension = { [dimension: string]: Dimension | null };

type Main<T> = { settings: Settings<['main' | 'master']> } & T;

type Schedule = { start?: string; end?: string };

type Settings<T> = T | { dimensions: T; schedule?: Schedule };

declare module 'ycb' {
class Ycb<T extends Object> {
constructor(bundle: Bundle<T>, 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<T>(bundle: Bundle<T>, context: Context, validate?: boolean, debug?: boolean): T;
function readNoMerge<T>(bundle: Bundle<T>, context: Context, validate?: boolean, debug?: boolean): T;
}
23 changes: 12 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,37 @@
"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 <[email protected]>",
"bugs": "https://github.com/yahoo/ycb/issues",
"repository": {
"type": "git",
"url": "git://github.com/yahoo/ycb.git"
},
"license": "BSD",
"author": "Ric Allinson <[email protected]>",
"contributors": [
"Drew Folta <[email protected]>",
"Michael Ridgway <[email protected]>",
"Caridy Patino <[email protected]>",
"Isao Yagi <[email protected]>"
],
"main": "index",
"types": "index.d.ts",
"scripts": {
"cover": "nyc npm run test",
"lint": "eslint . && prettier --check .",
"lint:fix": "eslint . --fix && prettier --write .",
"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
}
}

0 comments on commit dcf4f9f

Please sign in to comment.