decs / ruls Goto Github PK
View Code? Open in Web Editor NEWπ Typesafe rules engine with JSON encoding.
License: MIT License
π Typesafe rules engine with JSON encoding.
License: MIT License
Hi AndrΓ©!
Just sharing some nits in the API and docs:
For the number signal, I expected the operator lessThan
to be available, given the existence of greaterThan
. However, what's offered instead is lowerThan
.
What do you think about exposing a builder function for signals instead of requiring users to repeat the context value for all signals?
type Context = {
user: { name: string, age: number }
}
const signals = buildSignals<Context>((signal) => ({
// context is automatically inferred
name: signal.string.value(context => context.user.name),
age: signal.number.value(context => context.user.age)
})
import { rule, signal } from "ruls";
type Context = {
transaction: { amountInCents: number; name: string };
};
const signals = {
amountInCents: signal.number.value<Context>(
(ctx) => ctx.transaction.amountInCents
),
name: signal.string.value<Context>(({ transaction }) => transaction.name),
};
const betweenSignal = (min: number, max: number) => [
signals.amountInCents.greaterThanOrEquals(min),
signals.amountInCents.lowerThan(max),
];
const starbucksRule = rule.every([
...betweenSignal(300, 1000),
signals.name.equals("Starbucks"),
]);
const philzCoffeeRule = rule.every([
...betweenSignal(300, 1000),
signals.name.equals("Philz Coffee"),
]);
const ruleDef = rule.some([starbucksRule, philzCoffeeRule]);
/**
* A coffee transaction is a transaction between $3 and $10 at Starbucks or
* Philz Coffee
*/
export const isCoffeeTransaction = async (transaction: {
amountInCents: number;
name: string;
}) => await ruleDef.evaluate({ transaction });
After reading the Custom Type docs, I tried creating a custom date
signal. I'm not sure the right way of injecting custom assert functions. For example, the number operator adds its own set of functions. I would like to do the same for my types.
For example:
const dateSignal = signal.type<Date>(z.date().parse)
I'm trying to understand how to enhance its types to support operations besides the basic ones:
Given dates are a non-trivial type, it would be awesome if I could add operations like isSameDay
, isAfter
, isBefore
, etc.
Hi, thank you for your great work.
I have just attempted to install this library (version 1.0.4 and newer) and got following error:
error /.../node_modules/ruls: Command failed.
Exit code: 127
Command: husky install
Arguments:
Directory: /.../node_modules/ruls
Output:
/bin/sh: husky: command not found
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
Seem there is problem with postinstal hook "postinstall": "husky install", which should not run in production but runs.
By removing this hook, everything works as intended.
Thank you in advance for fixing this issue.
would it be possible to build a "signal" factory that would let me feed it zod schema and it would automatically infer signals?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.