Comparing version 0.0.2 to 0.0.3
@@ -18,2 +18,3 @@ export type Equals<X, Y> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? true : false; | ||
export interface ActionBuilderParam<V = any> { | ||
readonly name: string; | ||
readonly order: number; | ||
@@ -33,3 +34,6 @@ readonly pattern: string; | ||
getParam<K extends keyof P>(param: K): { [K_1 in keyof P]: ActionBuilderParam<P[K_1]>; }[K]; | ||
getParamOrder<K extends keyof P>(param: K): number; | ||
getParamValue<K extends keyof P>(param: K): P[K] | undefined; | ||
withParamValue<K extends keyof P, V extends P[K]>(param: K, value: V): ActionBuilder<P>; | ||
withParamPattern<K extends keyof P>(param: K, pattern: string): ActionBuilder<P>; | ||
withAnyParams(): ActionBuilder<P>; | ||
@@ -36,0 +40,0 @@ fromStart(): ActionBuilder<P>; |
32
index.js
@@ -48,6 +48,8 @@ (function (factory) { | ||
withParam(param, pattern) { | ||
return this.new(Object.assign(Object.assign({}, this.state), { params: Object.assign(Object.assign({}, this.state.params), { [param]: { | ||
pattern, | ||
order: this.getNextParamOrderCounter(), | ||
} }) })); | ||
const paramState = { | ||
name: param, | ||
pattern, | ||
order: this.getNextParamOrderCounter() | ||
}; | ||
return this.new(Object.assign(Object.assign({}, this.state), { params: Object.assign(Object.assign({}, this.state.params), { [param]: paramState }) })); | ||
} | ||
@@ -57,9 +59,27 @@ getParam(param) { | ||
} | ||
getParamOrder(param) { | ||
const paramState = this.state.params[param]; | ||
if (!paramState) { | ||
throw new Error(`Unknown param. Received ${String(param)}`); | ||
} | ||
return paramState.order; | ||
} | ||
getParamValue(param) { | ||
var _a; | ||
return (_a = this.state.params[param]) === null || _a === void 0 ? void 0 : _a.value; | ||
} | ||
withParamValue(param, value) { | ||
const paramState = this.state.params[param]; | ||
if (!param) { | ||
throw new Error(`Unknown param. Received ${String(name)}. Expected one of ${this.state.params}`); | ||
if (!paramState) { | ||
throw new Error(`Unknown param. Received ${String(param)}`); | ||
} | ||
return this.new(Object.assign(Object.assign({}, this.state), { params: Object.assign(Object.assign({}, this.state.params), { [param]: Object.assign(Object.assign({}, paramState), { value }) }) })); | ||
} | ||
withParamPattern(param, pattern) { | ||
const paramState = this.state.params[param]; | ||
if (!paramState) { | ||
throw new Error(`Unknown param. Received ${String(param)}`); | ||
} | ||
return this.new(Object.assign(Object.assign({}, this.state), { params: Object.assign(Object.assign({}, this.state.params), { [param]: Object.assign(Object.assign({}, paramState), { pattern }) }) })); | ||
} | ||
withAnyParams() { | ||
@@ -66,0 +86,0 @@ return this.new(Object.assign(Object.assign({}, this.state), { isAnyParams: true })); |
{ | ||
"name": "bot-action", | ||
"version": "0.0.2", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "jest", | ||
"build": "tsc", | ||
"prepublishOnly": "npm run build" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/A5KET/action-builder.git" | ||
}, | ||
"keywords": [ | ||
"action", | ||
"builder", | ||
"telegram", | ||
"bot", | ||
"api" | ||
], | ||
"author": "Max Kotsiuruba", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/A5KET/bot-action/issues" | ||
}, | ||
"homepage": "https://github.com/A5KET/bot-action#readme", | ||
"description": "", | ||
"devDependencies": { | ||
"@types/jest": "^29.5.14", | ||
"@types/node": "^22.9.0", | ||
"jest": "^29.7.0", | ||
"ts-jest": "^29.2.5", | ||
"typescript": "^5.6.3" | ||
}, | ||
"type": "module", | ||
"types": "./index.d.ts", | ||
"files": [ | ||
"index.js", | ||
"index.d.ts", | ||
"README.md" | ||
] | ||
} | ||
"name": "bot-action", | ||
"version": "0.0.3", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "jest", | ||
"build": "tsc", | ||
"prepublishOnly": "npm run build" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/A5KET/action-builder.git" | ||
}, | ||
"keywords": [ | ||
"action", | ||
"builder", | ||
"telegram", | ||
"bot", | ||
"api" | ||
], | ||
"author": "Max Kotsiuruba", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/A5KET/bot-action/issues" | ||
}, | ||
"homepage": "https://github.com/A5KET/bot-action#readme", | ||
"description": "", | ||
"devDependencies": { | ||
"@types/jest": "^29.5.14", | ||
"@types/node": "^22.9.0", | ||
"jest": "^29.7.0", | ||
"ts-jest": "^29.2.5", | ||
"typescript": "^5.6.3" | ||
}, | ||
"type": "module", | ||
"types": "./index.d.ts", | ||
"files": [ | ||
"index.js", | ||
"index.d.ts", | ||
"README.md" | ||
] | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
9528
169