Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

prague

Package Overview
Dependencies
Maintainers
1
Versions
91
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prague - npm Package Compare versions

Comparing version 0.6.2 to 0.6.3

core/Konsole.ts

2

core/Dialogs.ts

@@ -20,3 +20,3 @@ import { IRule, SimpleRule, Observizeable, RuleResult, BaseRule, Matcher, Handler, Match, observize, combineMatchers } from './Rules';

return Observable.of(this.getDialogStack(match))
.do(promptKey => console.log("promptKey", promptKey))
.do(promptKey => konsole.log("promptKey", promptKey))
.filter(promptKey => promptKey !== undefined)

@@ -23,0 +23,0 @@ .map(promptKey => this.rules[promptKey])

import { Observable } from 'rxjs';
import { ITextMatch } from './Text';
import { konsole } from './Konsole';
import { IRule, RuleResult, BaseRule, SimpleRule, Matcher, Handler, Match, Observizeable, observize, ruleize } from './Rules';

@@ -138,6 +139,6 @@

public call(utterance: string): Observable<LuisResponse> {
console.log("calling LUIS");
konsole.log("calling LUIS");
const response = this.cache[utterance];
if (response)
return Observable.of(response).do(_ => console.log("from cache!!"));
return Observable.of(response).do(_ => konsole.log("from cache!!"));
if (this.url === 'testData') {

@@ -148,3 +149,3 @@ const luisResponse = this.testData[utterance];

return Observable.of(luisResponse)
.do(luisResponse => console.log("LUIS test data!", luisResponse))
.do(luisResponse => konsole.log("LUIS test data!", luisResponse))
.do(luisResponse => this.cache[utterance] = luisResponse);

@@ -154,3 +155,3 @@ }

.do(luisResponse => {
console.log("LUIS response!", luisResponse);
konsole.log("LUIS response!", luisResponse);
this.cache[utterance] = luisResponse;

@@ -157,0 +158,0 @@ });

@@ -0,1 +1,2 @@

import { konsole } from './Konsole';
import { IRule, SimpleRule, Observizeable, RuleResult, BaseRule, Matcher, Handler, Match, observize, combineMatchers } from './Rules';

@@ -20,3 +21,3 @@ import { Observable } from 'rxjs';

return Observable.of(this.getPromptKey(match))
.do(promptKey => console.log("promptKey", promptKey))
.do(promptKey => konsole.log("promptKey", promptKey))
.filter(promptKey => promptKey !== undefined)

@@ -23,0 +24,0 @@ .map(promptKey => this.rules[promptKey])

import { Observable } from 'rxjs';
import { konsole } from './Konsole';
import { ITextMatch } from './Text';

@@ -12,8 +13,8 @@ import { IRule, SimpleRule, Matcher, Handler, arrayize } from './Rules';

Observable.from(arrayize(intents))
.do(_ => console.log("RegExp.match matching", match))
.do(_ => konsole.log("RegExp.match matching", match))
.map(regexp => regexp.exec(match.text))
.do(groups => console.log("RegExp.match result", groups))
.do(groups => konsole.log("RegExp.match result", groups))
.filter(groups => groups && groups[0] === match.text)
.take(1)
.do(groups => console.log("RegExp.match returning", groups))
.do(groups => konsole.log("RegExp.match returning", groups))
.map(groups => ({

@@ -20,0 +21,0 @@ ... match as any, // remove "as any" when TypeScript fixes this bug,

@@ -0,1 +1,2 @@

import { konsole } from './Konsole';
import { Observable } from 'rxjs';

@@ -61,5 +62,5 @@

return this.tryMatch(match)
.do(result => console.log("handle: matched a rule", result))
.do(result => konsole.log("handle: matched a rule", result))
.flatMap(result => observize(result.action()))
.do(_ => console.log("handle: called action"));
.do(_ => konsole.log("handle: called action"));
}

@@ -78,3 +79,3 @@

export function combineMatchers<M extends Match = any>(... args: Matcher[]): Matcher<M, any> {
console.log("combineMatchers", args);
konsole.log("combineMatchers", args);
return match =>

@@ -86,5 +87,5 @@ Observable.from(args)

.flatMap(prevMatch => {
console.log(`calling matcher #${i}`, currentMatcher);
konsole.log(`calling matcher #${i}`, currentMatcher);
return matchize(currentMatcher, prevMatch)
.do(result => console.log("result", result));
.do(result => konsole.log("result", result));
}),

@@ -103,3 +104,3 @@ Observable.of(match)

if (args.length < 1) {
console.error("rules must at least have a handler");
konsole.error("rules must at least have a handler");
return;

@@ -113,3 +114,3 @@ }

tryMatch(match: M): Observable<RuleResult> {
console.log("SimpleRule.tryMatch", this.matchers);
konsole.log("SimpleRule.tryMatch", this.matchers);

@@ -127,3 +128,3 @@ if (this.matchers.length === 0)

)
.do(m => console.log("match", m))
.do(m => konsole.log("match", m))
.map(m => ({

@@ -136,3 +137,3 @@ score: m.score,

prependMatcher<L extends Match = any>(matcher: Matcher<L, M>) {
console.log("SimpleRule.prependMatcher", matcher);
konsole.log("SimpleRule.prependMatcher", matcher);
return new SimpleRule<L>(

@@ -151,3 +152,3 @@ matcher,

super();
console.log("FirstMatchingRule.constructor: rules", rules);
konsole.log("FirstMatchingRule.constructor: rules", rules);
this.rule$ = Observable.from(rules)

@@ -159,9 +160,9 @@ .filter(rule => !!rule)

tryMatch(match: M): Observable<RuleResult> {
console.log("FirstMatchingRule.tryMatch", match);
konsole.log("FirstMatchingRule.tryMatch", match);
return this.rule$
.flatMap(
(rule, i) => {
console.log(`Rule.first: trying rule #${i}`);
konsole.log(`Rule.first: trying rule #${i}`);
return rule.tryMatch(match)
.do(m => console.log(`Rule.first: rule #${i} succeeded`, m));
.do(m => konsole.log(`Rule.first: rule #${i} succeeded`, m));
},

@@ -204,3 +205,3 @@ 1

// rule$
// .do(_ => console.log("Rule.best: trying rule"))
// .do(_ => konsole.log("Rule.best: trying rule"))
// .flatMap(rule =>

@@ -226,3 +227,3 @@ // rule.recognize(match)

// rule$
// .do(_ => console.log("everyMatch$: trying rule"))
// .do(_ => konsole.log("everyMatch$: trying rule"))
// .flatMap(rule => observize(rule(input)))

@@ -229,0 +230,0 @@ // .reduce((prev, current) => (current.score || 1) < scoreThreshold ? prev : {

@@ -22,2 +22,3 @@ "use strict";

var rxjs_1 = require("rxjs");
var Konsole_1 = require("./Konsole");
var Rules_1 = require("./Rules");

@@ -114,6 +115,6 @@ var entityFields = function (entities) { return ({

var _this = this;
console.log("calling LUIS");
Konsole_1.konsole.log("calling LUIS");
var response = this.cache[utterance];
if (response)
return rxjs_1.Observable.of(response).do(function (_) { return console.log("from cache!!"); });
return rxjs_1.Observable.of(response).do(function (_) { return Konsole_1.konsole.log("from cache!!"); });
if (this.url === 'testData') {

@@ -124,3 +125,3 @@ var luisResponse = this.testData[utterance];

return rxjs_1.Observable.of(luisResponse)
.do(function (luisResponse) { return console.log("LUIS test data!", luisResponse); })
.do(function (luisResponse) { return Konsole_1.konsole.log("LUIS test data!", luisResponse); })
.do(function (luisResponse) { return _this.cache[utterance] = luisResponse; });

@@ -130,3 +131,3 @@ }

.do(function (luisResponse) {
console.log("LUIS response!", luisResponse);
Konsole_1.konsole.log("LUIS response!", luisResponse);
_this.cache[utterance] = luisResponse;

@@ -133,0 +134,0 @@ });

@@ -21,2 +21,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var Konsole_1 = require("./Konsole");
var Rules_1 = require("./Rules");

@@ -36,3 +37,3 @@ var rxjs_1 = require("rxjs");

return rxjs_1.Observable.of(this.getPromptKey(match))
.do(function (promptKey) { return console.log("promptKey", promptKey); })
.do(function (promptKey) { return Konsole_1.konsole.log("promptKey", promptKey); })
.filter(function (promptKey) { return promptKey !== undefined; })

@@ -39,0 +40,0 @@ .map(function (promptKey) { return _this.rules[promptKey]; })

@@ -12,2 +12,3 @@ "use strict";

var rxjs_1 = require("rxjs");
var Konsole_1 = require("./Konsole");
var Rules_1 = require("./Rules");

@@ -17,8 +18,8 @@ exports.matchRegExp = function (intents) {

return rxjs_1.Observable.from(Rules_1.arrayize(intents))
.do(function (_) { return console.log("RegExp.match matching", match); })
.do(function (_) { return Konsole_1.konsole.log("RegExp.match matching", match); })
.map(function (regexp) { return regexp.exec(match.text); })
.do(function (groups) { return console.log("RegExp.match result", groups); })
.do(function (groups) { return Konsole_1.konsole.log("RegExp.match result", groups); })
.filter(function (groups) { return groups && groups[0] === match.text; })
.take(1)
.do(function (groups) { return console.log("RegExp.match returning", groups); })
.do(function (groups) { return Konsole_1.konsole.log("RegExp.match returning", groups); })
.map(function (groups) { return (__assign({}, match, { // remove "as any" when TypeScript fixes this bug,

@@ -25,0 +26,0 @@ groups: groups })); });

@@ -13,2 +13,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var Konsole_1 = require("./Konsole");
var rxjs_1 = require("rxjs");

@@ -47,5 +48,5 @@ var minMatch = {

return this.tryMatch(match)
.do(function (result) { return console.log("handle: matched a rule", result); })
.do(function (result) { return Konsole_1.konsole.log("handle: matched a rule", result); })
.flatMap(function (result) { return exports.observize(result.action()); })
.do(function (_) { return console.log("handle: called action"); });
.do(function (_) { return Konsole_1.konsole.log("handle: called action"); });
};

@@ -63,3 +64,3 @@ BaseRule.prototype.prependMatcher = function (matcher) {

}
console.log("combineMatchers", args);
Konsole_1.konsole.log("combineMatchers", args);
return function (match) {

@@ -70,5 +71,5 @@ return rxjs_1.Observable.from(args)

.flatMap(function (prevMatch) {
console.log("calling matcher #" + i, currentMatcher);
Konsole_1.konsole.log("calling matcher #" + i, currentMatcher);
return exports.matchize(currentMatcher, prevMatch)
.do(function (result) { return console.log("result", result); });
.do(function (result) { return Konsole_1.konsole.log("result", result); });
});

@@ -90,3 +91,3 @@ }, rxjs_1.Observable.of(match))

if (args.length < 1) {
console.error("rules must at least have a handler");
Konsole_1.konsole.error("rules must at least have a handler");
return _this;

@@ -101,3 +102,3 @@ }

var _this = this;
console.log("SimpleRule.tryMatch", this.matchers);
Konsole_1.konsole.log("SimpleRule.tryMatch", this.matchers);
if (this.matchers.length === 0)

@@ -111,3 +112,3 @@ return rxjs_1.Observable.of({

: combineMatchers.apply(void 0, this.matchers)(match))
.do(function (m) { return console.log("match", m); })
.do(function (m) { return Konsole_1.konsole.log("match", m); })
.map(function (m) { return ({

@@ -119,3 +120,3 @@ score: m.score,

SimpleRule.prototype.prependMatcher = function (matcher) {
console.log("SimpleRule.prependMatcher", matcher);
Konsole_1.konsole.log("SimpleRule.prependMatcher", matcher);
return new (SimpleRule.bind.apply(SimpleRule, [void 0, matcher].concat(this.matchers, [this.handler])))();

@@ -134,3 +135,3 @@ };

var _this = _super.call(this) || this;
console.log("FirstMatchingRule.constructor: rules", rules);
Konsole_1.konsole.log("FirstMatchingRule.constructor: rules", rules);
_this.rule$ = rxjs_1.Observable.from(rules)

@@ -142,8 +143,8 @@ .filter(function (rule) { return !!rule; })

FirstMatchingRule.prototype.tryMatch = function (match) {
console.log("FirstMatchingRule.tryMatch", match);
Konsole_1.konsole.log("FirstMatchingRule.tryMatch", match);
return this.rule$
.flatMap(function (rule, i) {
console.log("Rule.first: trying rule #" + i);
Konsole_1.konsole.log("Rule.first: trying rule #" + i);
return rule.tryMatch(match)
.do(function (m) { return console.log("Rule.first: rule #" + i + " succeeded", m); });
.do(function (m) { return Konsole_1.konsole.log("Rule.first: rule #" + i + " succeeded", m); });
}, 1)

@@ -150,0 +151,0 @@ .take(1); // so that we don't keep going through rules after we find one that matches

@@ -29,7 +29,7 @@ # Prague 101

greetGuest({ name: "Brandon", reply: console.log });
greetGuest({ name: "Brandon", reply: konsole.log });
>> "Hi there, Brandon! Welcome to CafeBot."
```
By convention, a Handler has one parameter, an object called `match` because it is the output of a Matcher. Also by convention, `match` includes the common tools (like `reply`) that a handler might need. By including those tools in `match` we can easily use dependency injection to replace `console.log` with a function that sends a reply to a chat app, or a function that returns text to a testing harness, allowing us to validate our business logic.
By convention, a Handler has one parameter, an object called `match` because it is the output of a Matcher. Also by convention, `match` includes the common tools (like `reply`) that a handler might need. By including those tools in `match` we can easily use dependency injection to replace `konsole.log` with a function that sends a reply to a chat app, or a function that returns text to a testing harness, allowing us to validate our business logic.

@@ -63,3 +63,3 @@ It already sounds like this approach might be a little error-prone. What if we pass the wrong kind of object? Let's use TypeScript to help protect ourselves from simple coding errors by adding type annotations.

```typescript
greetGuest({ name: "Brandon", reply: console.log, cafe });
greetGuest({ name: "Brandon", reply: konsole.log, cafe });
>> "Hi there, Brandon! Welcome to CafeBot."

@@ -89,3 +89,3 @@ ```

text,
reply: console.log
reply: konsole.log
}));

@@ -92,0 +92,0 @@ }

@@ -6,3 +6,3 @@ {

},
"version": "0.6.2",
"version": "0.6.3",
"description": "rules-based app engine",

@@ -9,0 +9,0 @@ "main": "dist/prague.js",

@@ -18,4 +18,2 @@ # Prague

# Getting up and Running
## Building Prague

@@ -27,8 +25,12 @@

## Using Prague in your app
## Prague recipes
* `npm install prague -S`
* or, if you're building your own, `npm install file:../path/to/your/repo`
* `import { the, stuff, you, want } from 'prague'` or `import * as Prague from 'prague'`
Prague is a low-level framework. If you want to build an app you will want to use (or create) a `recipe`, which is a set of functionality that allows you to exchange messages with a given channel, using a given state store, etc. Here is a list of available recipes. Please post your own!
* [prague-botframework-browserbot](https://www.npmjs.com/package/prague-botframework-browserbot) - Build
## Prague samples
* [BrowserBot](https://github.com/billba/BrowserBot)
# Prague 101

@@ -35,0 +37,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc