pure-effect 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +11 -12
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -26,15 +26,15 @@ const validateRegistration = (input) => {
26
26
  // These functions do NOT run the DB call. They return a Command object.
27
27
  // The 'next' function defines what happens with the result of the async call.
28
28
  const findUser = (email) => {
29
- const cmd = () => db.findUser(email); // The work to do later
29
+ const cmdFindUser = () => db.findUser(email); // The work to do later
30
30
  const next = (user) => Success(user); // Wrap result in Success
31
- return Command(cmd, next);
31
+ return Command(cmdFindUser, next);
32
32
  };
33
33
 
34
34
  const saveUser = (input) => {
35
- const cmd = () => db.saveUser(input);
35
+ const cmdSaveUser = () => db.saveUser(input);
36
36
  const next = (saved) => Success(saved);
37
- return Command(cmd, next);
37
+ return Command(cmdSaveUser, next);
38
38
  };
39
39
 
40
40
  const ensureEmailAvailable = (user) => {
@@ -51,9 +51,7 @@ const registerUserFlow = (input) =>
51
51
  )(input);
52
52
 
53
53
  // The Imperative Shell
54
- async function main() {
55
- const input = { email: 'new@test.com', password: 'password123' };
56
-
54
+ async function registerUser() {
57
55
  // logic is just a data structure until we pass it to runEffect
58
56
  const logic = registerUserFlow(input);
59
57
 
@@ -66,8 +64,6 @@ async function main() {
66
64
  console.error('Error:', result.error);
67
65
  }
68
66
  }
69
-
70
- main();
71
67
  ```
72
68
 
73
69
  ## Testing Without Mocks
@@ -75,8 +71,6 @@ main();
75
71
  The biggest benefit of **Pure Effect** is testability. Because `registerUserFlow` returns a data structure (a tree of objects) instead of running a Promise, you can test your logic without mocking the database.
76
72
 
77
73
  ```js
78
- import assert from 'assert';
79
-
80
74
  // 1. Test Validation Failure
81
75
  const badInput = { email: 'bad-email', password: '123' };
82
76
  const result = registerUserFlow(badInput);
@@ -90,7 +84,12 @@ const step1 = registerUserFlow(goodInput);
90
84
 
91
85
  // Check if the first thing the code does is try to find a user
92
86
  assert.equal(step1.type, 'Command');
93
- assert.equal(step1.cmd.name, 'findUser');
87
+ assert.equal(step1.cmd.name, 'cmdFindUser');
88
+
89
+ // Check if the next thing the code will do is to save a user
90
+ const step2 = step1.next(null);
91
+ assert.equal(step2.type, 'Command');
92
+ assert.equal(step2.cmd.name, 'cmdSaveUser');
94
93
  // ✅ We verified the *intent* of the code without touching a real DB.
95
94
  ```
96
95
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pure-effect",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "A tiny, zero-dependency effect system for writing pure, testable JavaScript without mocks.",
5
5
  "type": "module",
6
6
  "exports": "./index.js",