@pulse-js/core 0.2.1 → 0.2.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.
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  # Pulse-JS
6
6
 
7
- [![npm version](https://img.shields.io/npm/v/@pulse-js/core.svg)](https://www.npmjs.com/package/@pulse-js/core)
7
+ [![npm version](https://img.shields.io/npm/v/@pulse-js/core.svg?color=blue)](https://www.npmjs.com/package/@pulse-js/core)
8
8
 
9
9
  > A semantic reactivity system for modern applications. Separate reactive data (sources) from business conditions (guards) with a declarative, composable, and observable approach.
10
10
 
package/dist/index.cjs CHANGED
@@ -138,7 +138,12 @@ function guard(nameOrFn, fn) {
138
138
  if (currentId === evaluationId) {
139
139
  persistDependencies();
140
140
  if (resolved === false) {
141
- const reason = name ? `${name} failed` : "condition failed";
141
+ const message = name ? `${name} failed` : "condition failed";
142
+ const reason = {
143
+ code: "GUARD_FAIL",
144
+ message,
145
+ toString: () => message
146
+ };
142
147
  state = { status: "fail", reason, lastReason: reason, updatedAt: Date.now() };
143
148
  } else if (resolved === void 0) {
144
149
  state = { ...state, status: "pending", updatedAt: Date.now() };
@@ -150,13 +155,22 @@ function guard(nameOrFn, fn) {
150
155
  }).catch((err) => {
151
156
  if (currentId === evaluationId) {
152
157
  persistDependencies();
153
- const message = err instanceof Error ? err.message : String(err);
154
- const reason = err.meta ? {
155
- code: err.code || "ERROR",
156
- message,
157
- meta: err.meta,
158
- toString: () => message
159
- } : message;
158
+ let reason;
159
+ if (err && err._pulseFail) {
160
+ reason = err._reason;
161
+ } else {
162
+ const message = err instanceof Error ? err.message : String(err);
163
+ reason = err && err.meta ? {
164
+ code: err.code || "ERROR",
165
+ message,
166
+ meta: err.meta,
167
+ toString: () => message
168
+ } : {
169
+ code: "ERROR",
170
+ message,
171
+ toString: () => message
172
+ };
173
+ }
160
174
  state = {
161
175
  status: "fail",
162
176
  reason,
@@ -169,7 +183,12 @@ function guard(nameOrFn, fn) {
169
183
  } else {
170
184
  persistDependencies();
171
185
  if (result === false) {
172
- const reason = name ? `${name} failed` : "condition failed";
186
+ const message = name ? `${name} failed` : "condition failed";
187
+ const reason = {
188
+ code: "GUARD_FAIL",
189
+ message,
190
+ toString: () => message
191
+ };
173
192
  state = { status: "fail", reason, lastReason: reason, updatedAt: Date.now() };
174
193
  } else if (result === void 0) {
175
194
  state = { ...state, status: "pending", updatedAt: Date.now() };
@@ -198,7 +217,11 @@ function guard(nameOrFn, fn) {
198
217
  message,
199
218
  meta: err.meta,
200
219
  toString: () => message
201
- } : message;
220
+ } : {
221
+ code: "ERROR",
222
+ message,
223
+ toString: () => message
224
+ };
202
225
  state = {
203
226
  status: "fail",
204
227
  reason,
package/dist/index.d.cts CHANGED
@@ -179,9 +179,9 @@ interface GuardState<T> {
179
179
  /** The value returned by the evaluator (only if status is 'ok'). */
180
180
  value?: T;
181
181
  /** The reason why the guard failed. */
182
- reason?: string | GuardReason;
182
+ reason?: GuardReason;
183
183
  /** The last known failure reason, persisted even during 'pending'. */
184
- lastReason?: string | GuardReason;
184
+ lastReason?: GuardReason;
185
185
  /** The timestamp when the status last changed. */
186
186
  updatedAt?: number;
187
187
  }
@@ -191,14 +191,14 @@ interface GuardState<T> {
191
191
  interface GuardExplanation {
192
192
  name: string;
193
193
  status: GuardStatus;
194
- reason?: string | GuardReason;
195
- lastReason?: string | GuardReason;
194
+ reason?: GuardReason;
195
+ lastReason?: GuardReason;
196
196
  value?: any;
197
197
  dependencies: Array<{
198
198
  name: string;
199
199
  type: 'source' | 'guard';
200
200
  status?: GuardStatus;
201
- reason?: string | GuardReason;
201
+ reason?: GuardReason;
202
202
  }>;
203
203
  }
204
204
  /**
@@ -237,9 +237,9 @@ interface Guard<T = boolean> {
237
237
  * Returns the failure reason message if the guard is in the 'fail' state.
238
238
  * Useful for displaying semantic error messages in the UI.
239
239
  *
240
- * @returns The error message or undefined.
240
+ * @returns The error message object or undefined.
241
241
  */
242
- reason(): string | GuardReason | undefined;
242
+ reason(): GuardReason | undefined;
243
243
  /**
244
244
  * Returns a snapshot of the full internal state of the guard.
245
245
  * Useful for adapters (like React) to synchronize with the guard.
package/dist/index.d.ts CHANGED
@@ -179,9 +179,9 @@ interface GuardState<T> {
179
179
  /** The value returned by the evaluator (only if status is 'ok'). */
180
180
  value?: T;
181
181
  /** The reason why the guard failed. */
182
- reason?: string | GuardReason;
182
+ reason?: GuardReason;
183
183
  /** The last known failure reason, persisted even during 'pending'. */
184
- lastReason?: string | GuardReason;
184
+ lastReason?: GuardReason;
185
185
  /** The timestamp when the status last changed. */
186
186
  updatedAt?: number;
187
187
  }
@@ -191,14 +191,14 @@ interface GuardState<T> {
191
191
  interface GuardExplanation {
192
192
  name: string;
193
193
  status: GuardStatus;
194
- reason?: string | GuardReason;
195
- lastReason?: string | GuardReason;
194
+ reason?: GuardReason;
195
+ lastReason?: GuardReason;
196
196
  value?: any;
197
197
  dependencies: Array<{
198
198
  name: string;
199
199
  type: 'source' | 'guard';
200
200
  status?: GuardStatus;
201
- reason?: string | GuardReason;
201
+ reason?: GuardReason;
202
202
  }>;
203
203
  }
204
204
  /**
@@ -237,9 +237,9 @@ interface Guard<T = boolean> {
237
237
  * Returns the failure reason message if the guard is in the 'fail' state.
238
238
  * Useful for displaying semantic error messages in the UI.
239
239
  *
240
- * @returns The error message or undefined.
240
+ * @returns The error message object or undefined.
241
241
  */
242
- reason(): string | GuardReason | undefined;
242
+ reason(): GuardReason | undefined;
243
243
  /**
244
244
  * Returns a snapshot of the full internal state of the guard.
245
245
  * Useful for adapters (like React) to synchronize with the guard.
package/dist/index.js CHANGED
@@ -102,7 +102,12 @@ function guard(nameOrFn, fn) {
102
102
  if (currentId === evaluationId) {
103
103
  persistDependencies();
104
104
  if (resolved === false) {
105
- const reason = name ? `${name} failed` : "condition failed";
105
+ const message = name ? `${name} failed` : "condition failed";
106
+ const reason = {
107
+ code: "GUARD_FAIL",
108
+ message,
109
+ toString: () => message
110
+ };
106
111
  state = { status: "fail", reason, lastReason: reason, updatedAt: Date.now() };
107
112
  } else if (resolved === void 0) {
108
113
  state = { ...state, status: "pending", updatedAt: Date.now() };
@@ -114,13 +119,22 @@ function guard(nameOrFn, fn) {
114
119
  }).catch((err) => {
115
120
  if (currentId === evaluationId) {
116
121
  persistDependencies();
117
- const message = err instanceof Error ? err.message : String(err);
118
- const reason = err.meta ? {
119
- code: err.code || "ERROR",
120
- message,
121
- meta: err.meta,
122
- toString: () => message
123
- } : message;
122
+ let reason;
123
+ if (err && err._pulseFail) {
124
+ reason = err._reason;
125
+ } else {
126
+ const message = err instanceof Error ? err.message : String(err);
127
+ reason = err && err.meta ? {
128
+ code: err.code || "ERROR",
129
+ message,
130
+ meta: err.meta,
131
+ toString: () => message
132
+ } : {
133
+ code: "ERROR",
134
+ message,
135
+ toString: () => message
136
+ };
137
+ }
124
138
  state = {
125
139
  status: "fail",
126
140
  reason,
@@ -133,7 +147,12 @@ function guard(nameOrFn, fn) {
133
147
  } else {
134
148
  persistDependencies();
135
149
  if (result === false) {
136
- const reason = name ? `${name} failed` : "condition failed";
150
+ const message = name ? `${name} failed` : "condition failed";
151
+ const reason = {
152
+ code: "GUARD_FAIL",
153
+ message,
154
+ toString: () => message
155
+ };
137
156
  state = { status: "fail", reason, lastReason: reason, updatedAt: Date.now() };
138
157
  } else if (result === void 0) {
139
158
  state = { ...state, status: "pending", updatedAt: Date.now() };
@@ -162,7 +181,11 @@ function guard(nameOrFn, fn) {
162
181
  message,
163
182
  meta: err.meta,
164
183
  toString: () => message
165
- } : message;
184
+ } : {
185
+ code: "ERROR",
186
+ message,
187
+ toString: () => message
188
+ };
166
189
  state = {
167
190
  status: "fail",
168
191
  reason,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pulse-js/core",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "module": "dist/index.js",
5
5
  "main": "dist/index.cjs",
6
6
  "types": "dist/index.d.ts",