promise-logic 1.3.2 β 2.4.3
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 +213 -227
- package/dist/factory.cjs.js +15 -2
- package/dist/factory.esm.js +15 -2
- package/dist/index.cjs.js +15 -2
- package/dist/index.esm.js +15 -2
- package/dist/v2/factory.cjs.js +286 -0
- package/dist/v2/factory.esm.js +284 -0
- package/dist/v2/index.cjs.js +288 -0
- package/dist/v2/index.esm.js +284 -0
- package/dist/v2/types/factory.d.ts +10 -0
- package/dist/v2/types/index.d.ts +85 -0
- package/package.json +17 -11
- package/dist/factory.cjs.js.map +0 -1
- package/dist/factory.esm.js.map +0 -1
- package/dist/index.cjs.js.map +0 -1
- package/dist/index.esm.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,21 +1,48 @@
|
|
|
1
|
-
# PromiseLogic
|
|
2
1
|
|
|
3
|
-
|
|
2
|
+
# Promise Logic - Advanced Promise Logic Gates for Async Programming
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
Compose promises with logic gate semantics (AND, OR, NOT, XOR, NAND, NOR, XNOR, Majority). Forget APIs, remember logic.
|
|
6
5
|
|
|
7
|
-
##
|
|
6
|
+
## Features
|
|
8
7
|
|
|
9
|
-
**
|
|
8
|
+
- **Logic Gate Semantics**: Extend Promise API with AND, OR, NOT, XOR, NAND, NOR, XNOR, Majority operations
|
|
9
|
+
- **Dual Entry Points**: Choose between JavaScript or enhanced TypeScript experience
|
|
10
|
+
- **Type Safety**: Complete TypeScript definitions with strict type checking
|
|
11
|
+
- **Promise Utilities**: Additional utilities like Flip-Flop state management
|
|
12
|
+
- **Zero Dependencies**: Pure JavaScript/TypeScript implementation
|
|
13
|
+
- **Tree Shakeable**: Optimized for modern bundlers
|
|
10
14
|
|
|
11
|
-
##
|
|
15
|
+
## Recent Updates
|
|
16
|
+
|
|
17
|
+
### Version 2.3.2 Highlights
|
|
18
|
+
|
|
19
|
+
**π NOT Gate Implementation**
|
|
20
|
+
Introduced the NOT logic gate for promise inversion, enabling flexible negation patterns in asynchronous workflows:
|
|
21
|
+
|
|
22
|
+
```javascript
|
|
23
|
+
// Success -> Failure transformation
|
|
24
|
+
await PromiseLogic.not(Promise.resolve('success')); // Rejects with 'success'
|
|
12
25
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
26
|
+
// Failure -> Success transformation
|
|
27
|
+
const result = await PromiseLogic.not(Promise.reject('error')); // Resolves with 'error'
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
**π¦ Enhanced TypeScript System**
|
|
31
|
+
Completely revamped TypeScript architecture with:
|
|
32
|
+
- Full generic type propagation
|
|
33
|
+
- Strict type checking with zero `any` types
|
|
34
|
+
- Advanced type inference for all operations
|
|
35
|
+
- Seamless IDE integration with IntelliSense
|
|
36
|
+
|
|
37
|
+
**β‘ Performance Optimizations**
|
|
38
|
+
- Optimized internal logic for better efficiency
|
|
39
|
+
- Reduced memory overhead in gate operations
|
|
40
|
+
- Improved error handling and edge case management
|
|
41
|
+
|
|
42
|
+
**π Documentation Enhancements**
|
|
43
|
+
- Comprehensive API reference with TypeScript examples
|
|
44
|
+
- Better usage guidelines and best practices
|
|
45
|
+
- Clear entry point documentation for different environments
|
|
19
46
|
|
|
20
47
|
## Installation
|
|
21
48
|
|
|
@@ -25,290 +52,249 @@ npm install promise-logic
|
|
|
25
52
|
|
|
26
53
|
## Quick Start
|
|
27
54
|
|
|
28
|
-
###
|
|
55
|
+
### JavaScript (Default)
|
|
29
56
|
|
|
30
57
|
```javascript
|
|
58
|
+
// ES Modules
|
|
31
59
|
import { PromiseLogic } from 'promise-logic';
|
|
32
60
|
|
|
33
|
-
//
|
|
34
|
-
const
|
|
35
|
-
fetch('/api/users'),
|
|
36
|
-
fetch('/api/posts'),
|
|
37
|
-
fetch('/api/comments')
|
|
38
|
-
]);
|
|
61
|
+
// CommonJS
|
|
62
|
+
const { PromiseLogic } = require('promise-logic');
|
|
39
63
|
|
|
40
|
-
//
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
]);
|
|
45
|
-
|
|
46
|
-
// XOR logic - Exactly one promise must succeed
|
|
47
|
-
const uniqueResult = await PromiseLogic.xor([
|
|
48
|
-
cacheLookup(),
|
|
49
|
-
databaseQuery()
|
|
64
|
+
// Use logic gates
|
|
65
|
+
const results = await PromiseLogic.and([
|
|
66
|
+
Promise.resolve('data1'),
|
|
67
|
+
Promise.resolve('data2')
|
|
50
68
|
]);
|
|
69
|
+
// results = ['data1', 'data2']
|
|
51
70
|
```
|
|
52
71
|
|
|
53
|
-
###
|
|
72
|
+
### TypeScript (Enhanced)
|
|
54
73
|
|
|
55
|
-
```
|
|
56
|
-
//
|
|
57
|
-
|
|
58
|
-
validateInput(),
|
|
59
|
-
checkPermissions(),
|
|
60
|
-
verifyResources()
|
|
61
|
-
]);
|
|
74
|
+
```typescript
|
|
75
|
+
// TypeScript version with full type inference
|
|
76
|
+
import { PromiseLogic } from 'promise-logic/typescript';
|
|
62
77
|
|
|
63
|
-
//
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
]);
|
|
78
|
+
// Type-safe operations with automatic inference
|
|
79
|
+
const numbers = await PromiseLogic.and<number>([
|
|
80
|
+
Promise.resolve(1),
|
|
81
|
+
Promise.resolve(2)
|
|
82
|
+
]);
|
|
68
83
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
server3.query()
|
|
74
|
-
]);
|
|
84
|
+
const strings = await PromiseLogic.or<string>([
|
|
85
|
+
Promise.resolve('hello'),
|
|
86
|
+
Promise.resolve('world')
|
|
87
|
+
]);
|
|
75
88
|
```
|
|
76
89
|
|
|
77
|
-
|
|
90
|
+
## Core Logic Gates
|
|
91
|
+
|
|
92
|
+
### `and(promises)`
|
|
93
|
+
Resolves with all values when all promises fulfill. Equivalent to `Promise.all()`.
|
|
78
94
|
|
|
79
95
|
```javascript
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
apiCall3()
|
|
96
|
+
const results = await PromiseLogic.and([
|
|
97
|
+
Promise.resolve(1),
|
|
98
|
+
Promise.resolve(2),
|
|
99
|
+
Promise.resolve(3)
|
|
85
100
|
]);
|
|
101
|
+
// results = [1, 2, 3]
|
|
102
|
+
```
|
|
86
103
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
riskyOperation1(),
|
|
90
|
-
riskyOperation2()
|
|
91
|
-
]);
|
|
104
|
+
### `or(promises)`
|
|
105
|
+
Resolves with the first fulfilled promise. Equivalent to `Promise.any()`.
|
|
92
106
|
|
|
107
|
+
```javascript
|
|
108
|
+
const result = await PromiseLogic.or([
|
|
109
|
+
Promise.reject('error'),
|
|
110
|
+
Promise.resolve('success')
|
|
111
|
+
]);
|
|
112
|
+
// result = 'success'
|
|
93
113
|
```
|
|
94
114
|
|
|
95
|
-
|
|
115
|
+
### `xor(promises)`
|
|
116
|
+
Exclusive OR - resolves only when exactly one promise fulfills.
|
|
96
117
|
|
|
97
|
-
|
|
118
|
+
```javascript
|
|
119
|
+
try {
|
|
120
|
+
const result = await PromiseLogic.xor([
|
|
121
|
+
Promise.reject('error1'),
|
|
122
|
+
Promise.resolve('success'),
|
|
123
|
+
Promise.reject('error2')
|
|
124
|
+
]);
|
|
125
|
+
// result = 'success'
|
|
126
|
+
} catch (error) {
|
|
127
|
+
// Throws if zero or multiple promises fulfill
|
|
128
|
+
}
|
|
129
|
+
```
|
|
98
130
|
|
|
99
|
-
|
|
100
|
-
|
|
131
|
+
### `nand(promises)`
|
|
132
|
+
Not AND - resolves when not all promises fulfill.
|
|
101
133
|
|
|
102
|
-
|
|
103
|
-
|
|
134
|
+
```javascript
|
|
135
|
+
const results = await PromiseLogic.nand([
|
|
136
|
+
Promise.resolve('success'),
|
|
137
|
+
Promise.reject('error')
|
|
138
|
+
]);
|
|
139
|
+
// results = ['success']
|
|
140
|
+
```
|
|
104
141
|
|
|
105
|
-
|
|
106
|
-
|
|
142
|
+
### `nor(promises)`
|
|
143
|
+
Not OR - resolves only when all promises reject.
|
|
107
144
|
|
|
108
|
-
|
|
109
|
-
|
|
145
|
+
```javascript
|
|
146
|
+
const results = await PromiseLogic.nor([
|
|
147
|
+
Promise.reject('error1'),
|
|
148
|
+
Promise.reject('error2')
|
|
149
|
+
]);
|
|
150
|
+
// results = []
|
|
151
|
+
```
|
|
110
152
|
|
|
111
|
-
|
|
112
|
-
|
|
153
|
+
### `xnor(promises)`
|
|
154
|
+
Exclusive NOR - resolves when all promises have the same outcome.
|
|
113
155
|
|
|
114
|
-
|
|
115
|
-
|
|
156
|
+
```javascript
|
|
157
|
+
const results = await PromiseLogic.xnor([
|
|
158
|
+
Promise.resolve('a'),
|
|
159
|
+
Promise.resolve('b')
|
|
160
|
+
]);
|
|
161
|
+
// results = ['a', 'b']
|
|
162
|
+
```
|
|
116
163
|
|
|
117
|
-
|
|
118
|
-
Resolves when
|
|
164
|
+
### `majority(promises)`
|
|
165
|
+
Resolves when majority (>50%) of promises fulfill.
|
|
119
166
|
|
|
120
|
-
|
|
167
|
+
```javascript
|
|
168
|
+
const results = await PromiseLogic.majority([
|
|
169
|
+
Promise.resolve('a'),
|
|
170
|
+
Promise.resolve('b'),
|
|
171
|
+
Promise.reject('error')
|
|
172
|
+
]);
|
|
173
|
+
// results = ['a', 'b']
|
|
174
|
+
```
|
|
121
175
|
|
|
122
|
-
|
|
123
|
-
Always resolves with an array of fulfilled values (empty if none).
|
|
176
|
+
## NOT Gate - New in v2.3.2
|
|
124
177
|
|
|
125
|
-
|
|
126
|
-
|
|
178
|
+
### `not(promise)`
|
|
179
|
+
Inverts promise resolution - successful promises become rejections, and vice versa.
|
|
127
180
|
|
|
128
|
-
|
|
181
|
+
```javascript
|
|
182
|
+
// Success -> Failure
|
|
183
|
+
try {
|
|
184
|
+
await PromiseLogic.not(Promise.resolve('success'));
|
|
185
|
+
} catch (error) {
|
|
186
|
+
console.log(error); // 'success'
|
|
187
|
+
}
|
|
129
188
|
|
|
130
|
-
|
|
131
|
-
|
|
189
|
+
// Failure -> Success
|
|
190
|
+
const result = await PromiseLogic.not(Promise.reject('error'));
|
|
191
|
+
console.log(result); // 'error'
|
|
192
|
+
```
|
|
132
193
|
|
|
133
|
-
|
|
134
|
-
|
|
194
|
+
**Use Cases:**
|
|
195
|
+
- Transform error handling patterns
|
|
196
|
+
- Create conditional promise flows
|
|
197
|
+
- Implement retry logic with inverted conditions
|
|
198
|
+
- Build fallback mechanisms
|
|
135
199
|
|
|
136
|
-
|
|
137
|
-
Creates a stateful flip-flop utility for managing boolean state transitions.
|
|
200
|
+
## Advanced Utilities
|
|
138
201
|
|
|
139
|
-
|
|
202
|
+
### `race(promises)`
|
|
203
|
+
Equivalent to `Promise.race()`.
|
|
140
204
|
|
|
141
|
-
|
|
205
|
+
### `allSettled(promises)`
|
|
206
|
+
Equivalent to `Promise.allSettled()`.
|
|
142
207
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
// Default naming
|
|
147
|
-
const logic = createPromiseLogic();
|
|
148
|
-
await logic.and([promise1, promise2]);
|
|
149
|
-
|
|
150
|
-
// With prefix
|
|
151
|
-
const asyncLogic = createPromiseLogic({ prefix: 'async' });
|
|
152
|
-
await asyncLogic.asyncand([promise1, promise2]);
|
|
153
|
-
|
|
154
|
-
// With suffix
|
|
155
|
-
const logicUtils = createPromiseLogic({ suffix: 'Logic' });
|
|
156
|
-
await logicUtils.andLogic([promise1, promise2]);
|
|
157
|
-
|
|
158
|
-
// With custom renaming
|
|
159
|
-
const customLogic = createPromiseLogic({
|
|
160
|
-
rename: {
|
|
161
|
-
and: 'conjunction',
|
|
162
|
-
or: 'disjunction',
|
|
163
|
-
xor: 'exclusiveOr'
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
await customLogic.conjunction([promise1, promise2]);
|
|
167
|
-
|
|
168
|
-
// Combined transformations
|
|
169
|
-
const advancedLogic = createPromiseLogic({
|
|
170
|
-
prefix: 'async',
|
|
171
|
-
suffix: 'Logic',
|
|
172
|
-
rename: { and: 'conjunction' }
|
|
173
|
-
});
|
|
174
|
-
await advancedLogic.asyncconjunctionLogic([promise1, promise2]);
|
|
175
|
-
```
|
|
208
|
+
### `allFulfilled(promises)`
|
|
209
|
+
Resolves with all fulfilled values, ignoring rejections.
|
|
176
210
|
|
|
177
|
-
|
|
211
|
+
### `allRejected(promises)`
|
|
212
|
+
Resolves with all rejection reasons, ignoring fulfillments.
|
|
178
213
|
|
|
179
|
-
###
|
|
214
|
+
### `createFlipFlop(initialState?)`
|
|
215
|
+
Creates a stateful flip-flop for managing boolean state across async operations.
|
|
180
216
|
|
|
181
217
|
```javascript
|
|
182
|
-
|
|
183
|
-
const userData = await PromiseLogic.or([
|
|
184
|
-
primaryUserService.getUser(id),
|
|
185
|
-
secondaryUserService.getUser(id),
|
|
186
|
-
cacheService.getUser(id)
|
|
187
|
-
]);
|
|
218
|
+
const flipFlop = PromiseLogic.createFlipFlop(false);
|
|
188
219
|
|
|
189
|
-
//
|
|
190
|
-
|
|
191
|
-
validateEmail(email),
|
|
192
|
-
validatePassword(password),
|
|
193
|
-
checkRateLimit(ipAddress)
|
|
194
|
-
]);
|
|
220
|
+
// Get current state
|
|
221
|
+
console.log(flipFlop.getState()); // false
|
|
195
222
|
|
|
196
|
-
//
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
configServer2.getConfig(),
|
|
200
|
-
configServer3.getConfig()
|
|
201
|
-
]);
|
|
202
|
-
```
|
|
223
|
+
// Toggle state
|
|
224
|
+
await flipFlop.toggle();
|
|
225
|
+
console.log(flipFlop.getState()); // true
|
|
203
226
|
|
|
204
|
-
|
|
227
|
+
// Wait for specific state
|
|
228
|
+
await flipFlop.waitFor(true); // Resolves immediately if already true
|
|
205
229
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
PromiseLogic.allFulfilled(operations),
|
|
210
|
-
PromiseLogic.allRejected(operations)
|
|
211
|
-
]);
|
|
230
|
+
// Async state change
|
|
231
|
+
setTimeout(() => flipFlop.set(false), 100);
|
|
232
|
+
await flipFlop.waitForChange(); // Waits for state change
|
|
212
233
|
```
|
|
213
234
|
|
|
214
|
-
|
|
235
|
+
## TypeScript Support - Enhanced in v2.3.2
|
|
215
236
|
|
|
216
|
-
|
|
217
|
-
// Flip-flop for toggle operations
|
|
218
|
-
const toggle = PromiseLogic.createFlipFlop(false);
|
|
237
|
+
The TypeScript version (`promise-logic/typescript`) provides:
|
|
219
238
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
239
|
+
- **Full Type Inference**: Automatic type deduction for all operations
|
|
240
|
+
- **Strict Type Checking**: Zero `any` types, complete type safety
|
|
241
|
+
- **IDE Support**: Enhanced IntelliSense and code completion
|
|
242
|
+
- **Generic Type Propagation**: Proper handling of complex generic scenarios
|
|
223
243
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
```
|
|
227
|
-
|
|
228
|
-
## Error Handling
|
|
244
|
+
```typescript
|
|
245
|
+
import { PromiseLogic } from 'promise-logic/typescript';
|
|
229
246
|
|
|
230
|
-
|
|
247
|
+
// TypeScript infers everything
|
|
248
|
+
const result = await PromiseLogic.and([
|
|
249
|
+
Promise.resolve({ id: 1, name: 'Alice' }),
|
|
250
|
+
Promise.resolve({ id: 2, name: 'Bob' })
|
|
251
|
+
]);
|
|
252
|
+
// result type: Array<{ id: number, name: string }>
|
|
231
253
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
await PromiseLogic.
|
|
235
|
-
} catch (error) {
|
|
236
|
-
if (error.type === 'XOR_ERROR') {
|
|
237
|
-
console.log('Expected exactly one successful call');
|
|
238
|
-
}
|
|
239
|
-
console.log('Failed promises:', error.results);
|
|
254
|
+
// Complex generic types work seamlessly
|
|
255
|
+
async function processPromises<T>(promises: Promise<T>[]): Promise<T[]> {
|
|
256
|
+
return await PromiseLogic.and(promises);
|
|
240
257
|
}
|
|
241
258
|
```
|
|
242
259
|
|
|
243
|
-
##
|
|
260
|
+
## Entry Points
|
|
244
261
|
|
|
245
|
-
|
|
262
|
+
| Import Path | Purpose | Recommended For |
|
|
263
|
+
|------------|---------|----------------|
|
|
264
|
+
| `promise-logic` | Default JavaScript version | General use, mixed codebases |
|
|
265
|
+
| `promise-logic/typescript` | Enhanced TypeScript version | TypeScript projects, strict type safety |
|
|
246
266
|
|
|
247
|
-
|
|
248
|
-
import { PromiseLogic } from 'promise-logic';
|
|
267
|
+
## Migration Note
|
|
249
268
|
|
|
250
|
-
|
|
251
|
-
const numbers: number[] = await PromiseLogic.and([
|
|
252
|
-
Promise.resolve(1),
|
|
253
|
-
Promise.resolve(2),
|
|
254
|
-
Promise.resolve(3)
|
|
255
|
-
]);
|
|
256
|
-
|
|
257
|
-
// Type-safe error handling
|
|
258
|
-
try {
|
|
259
|
-
await PromiseLogic.nand(operations);
|
|
260
|
-
} catch (error: PromiseLogicError) {
|
|
261
|
-
// error has full type information
|
|
262
|
-
}
|
|
263
|
-
```
|
|
269
|
+
If you're upgrading from earlier versions, note that the TypeScript system has been completely redesigned for better type safety and developer experience. All existing APIs remain compatible.
|
|
264
270
|
|
|
265
|
-
##
|
|
271
|
+
## Development
|
|
266
272
|
|
|
267
|
-
|
|
273
|
+
```bash
|
|
274
|
+
# Install dependencies
|
|
275
|
+
npm install
|
|
268
276
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
async function advancedOperation(promises) {
|
|
272
|
-
const [successes, failures] = await Promise.all([
|
|
273
|
-
PromiseLogic.allFulfilled(promises),
|
|
274
|
-
PromiseLogic.allRejected(promises)
|
|
275
|
-
]);
|
|
277
|
+
# Build the project
|
|
278
|
+
npm run build
|
|
276
279
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
} else {
|
|
280
|
-
throw new Error('Operation mostly failed');
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
```
|
|
280
|
+
# Run tests
|
|
281
|
+
npm test
|
|
284
282
|
|
|
285
|
-
|
|
283
|
+
# Run tests in watch mode
|
|
284
|
+
npm run test:watch
|
|
286
285
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
const batches = chunkArray(operations, BATCH_SIZE);
|
|
290
|
-
const batchResults = await PromiseLogic.allFulfilled(
|
|
291
|
-
batches.map(batch => PromiseLogic.and(batch))
|
|
292
|
-
);
|
|
293
|
-
|
|
294
|
-
// Flatten results
|
|
295
|
-
const allResults = batchResults.flat();
|
|
286
|
+
# Check code coverage
|
|
287
|
+
npm run test:coverage
|
|
296
288
|
```
|
|
297
289
|
|
|
298
290
|
## Contributing
|
|
299
291
|
|
|
300
|
-
|
|
292
|
+
1. Fork the repository
|
|
293
|
+
2. Create a feature branch
|
|
294
|
+
3. Make your changes
|
|
295
|
+
4. Add tests for new functionality
|
|
296
|
+
5. Submit a pull request
|
|
301
297
|
|
|
302
298
|
## License
|
|
303
299
|
|
|
304
|
-
MIT
|
|
305
|
-
|
|
306
|
-
## Links
|
|
307
|
-
|
|
308
|
-
- GitHub Repository: https://github.com/xier123456/promise-logic
|
|
309
|
-
- npm Package: https://www.npmjs.com/package/promise-logic
|
|
310
|
-
- Issue Tracker: https://github.com/xier123456/promise-logic/issues
|
|
311
|
-
|
|
312
|
-
---
|
|
313
|
-
|
|
314
|
-
**PromiseLogic** - Making asynchronous logic as simple as digital circuits.
|
|
300
|
+
MIT Β© 2026
|
package/dist/factory.cjs.js
CHANGED
|
@@ -14,6 +14,7 @@ function createLogicError(type, fulfilledCount, total, results) {
|
|
|
14
14
|
const messages = {
|
|
15
15
|
XOR_ERROR: `XOR condition failed: expected exactly 1 promise to fulfill, but ${fulfilledCount} fulfilled.`,
|
|
16
16
|
NAND_ERROR: `NAND condition failed: all ${total} promises fulfilled (expected at least one rejection).`,
|
|
17
|
+
NOT_ERROR: `NOT condition failed: promise resolved (expected rejection).`,
|
|
17
18
|
NOR_ERROR: `NOR condition failed: ${fulfilledCount} promises fulfilled (expected all rejected).`,
|
|
18
19
|
MAJORITY_ERROR: `Majority condition failed: ${fulfilledCount}/${total} fulfilled (need majority).`,
|
|
19
20
|
ALL_SUCCESSFUL_ERROR: `All successful condition failed: ${fulfilledCount}/${total} promises fulfilled (expected all to succeed).`,
|
|
@@ -32,6 +33,15 @@ class PromiseLogic {
|
|
|
32
33
|
return Promise.any(iterable);
|
|
33
34
|
}
|
|
34
35
|
|
|
36
|
+
|
|
37
|
+
static not(promise) {
|
|
38
|
+
return Promise.resolve(promise).then(
|
|
39
|
+
(value) => Promise.reject(value),
|
|
40
|
+
(reason) => Promise.resolve(reason)
|
|
41
|
+
)
|
|
42
|
+
.catch((error) => Promise.resolve(error));
|
|
43
|
+
}
|
|
44
|
+
|
|
35
45
|
static race(iterable) {
|
|
36
46
|
return Promise.race(iterable);
|
|
37
47
|
}
|
|
@@ -121,6 +131,7 @@ class PromiseLogic {
|
|
|
121
131
|
});
|
|
122
132
|
}
|
|
123
133
|
|
|
134
|
+
|
|
124
135
|
// θΏεζζζεηPromiseη»ζ
|
|
125
136
|
static allFulfilled(iterable) {
|
|
126
137
|
return Promise.allSettled(iterable).then((results) => {
|
|
@@ -203,10 +214,13 @@ function createPromiseLogic(options = {}) {
|
|
|
203
214
|
race: PromiseLogic.race,
|
|
204
215
|
allSettled: PromiseLogic.allSettled,
|
|
205
216
|
xor: PromiseLogic.xor,
|
|
217
|
+
not: PromiseLogic.not,
|
|
206
218
|
nand: PromiseLogic.nand,
|
|
207
219
|
nor: PromiseLogic.nor,
|
|
208
220
|
xnor: PromiseLogic.xnor,
|
|
209
|
-
majority: PromiseLogic.majority
|
|
221
|
+
majority: PromiseLogic.majority,
|
|
222
|
+
allFulfilled: PromiseLogic.allFulfilled,
|
|
223
|
+
allRejected: PromiseLogic.allRejected
|
|
210
224
|
};
|
|
211
225
|
|
|
212
226
|
// εΊη¨ε½ε转ζ’
|
|
@@ -222,4 +236,3 @@ function createPromiseLogic(options = {}) {
|
|
|
222
236
|
}
|
|
223
237
|
|
|
224
238
|
exports.createPromiseLogic = createPromiseLogic;
|
|
225
|
-
//# sourceMappingURL=factory.cjs.js.map
|
package/dist/factory.esm.js
CHANGED
|
@@ -12,6 +12,7 @@ function createLogicError(type, fulfilledCount, total, results) {
|
|
|
12
12
|
const messages = {
|
|
13
13
|
XOR_ERROR: `XOR condition failed: expected exactly 1 promise to fulfill, but ${fulfilledCount} fulfilled.`,
|
|
14
14
|
NAND_ERROR: `NAND condition failed: all ${total} promises fulfilled (expected at least one rejection).`,
|
|
15
|
+
NOT_ERROR: `NOT condition failed: promise resolved (expected rejection).`,
|
|
15
16
|
NOR_ERROR: `NOR condition failed: ${fulfilledCount} promises fulfilled (expected all rejected).`,
|
|
16
17
|
MAJORITY_ERROR: `Majority condition failed: ${fulfilledCount}/${total} fulfilled (need majority).`,
|
|
17
18
|
ALL_SUCCESSFUL_ERROR: `All successful condition failed: ${fulfilledCount}/${total} promises fulfilled (expected all to succeed).`,
|
|
@@ -30,6 +31,15 @@ class PromiseLogic {
|
|
|
30
31
|
return Promise.any(iterable);
|
|
31
32
|
}
|
|
32
33
|
|
|
34
|
+
|
|
35
|
+
static not(promise) {
|
|
36
|
+
return Promise.resolve(promise).then(
|
|
37
|
+
(value) => Promise.reject(value),
|
|
38
|
+
(reason) => Promise.resolve(reason)
|
|
39
|
+
)
|
|
40
|
+
.catch((error) => Promise.resolve(error));
|
|
41
|
+
}
|
|
42
|
+
|
|
33
43
|
static race(iterable) {
|
|
34
44
|
return Promise.race(iterable);
|
|
35
45
|
}
|
|
@@ -119,6 +129,7 @@ class PromiseLogic {
|
|
|
119
129
|
});
|
|
120
130
|
}
|
|
121
131
|
|
|
132
|
+
|
|
122
133
|
// θΏεζζζεηPromiseη»ζ
|
|
123
134
|
static allFulfilled(iterable) {
|
|
124
135
|
return Promise.allSettled(iterable).then((results) => {
|
|
@@ -201,10 +212,13 @@ function createPromiseLogic(options = {}) {
|
|
|
201
212
|
race: PromiseLogic.race,
|
|
202
213
|
allSettled: PromiseLogic.allSettled,
|
|
203
214
|
xor: PromiseLogic.xor,
|
|
215
|
+
not: PromiseLogic.not,
|
|
204
216
|
nand: PromiseLogic.nand,
|
|
205
217
|
nor: PromiseLogic.nor,
|
|
206
218
|
xnor: PromiseLogic.xnor,
|
|
207
|
-
majority: PromiseLogic.majority
|
|
219
|
+
majority: PromiseLogic.majority,
|
|
220
|
+
allFulfilled: PromiseLogic.allFulfilled,
|
|
221
|
+
allRejected: PromiseLogic.allRejected
|
|
208
222
|
};
|
|
209
223
|
|
|
210
224
|
// εΊη¨ε½ε转ζ’
|
|
@@ -220,4 +234,3 @@ function createPromiseLogic(options = {}) {
|
|
|
220
234
|
}
|
|
221
235
|
|
|
222
236
|
export { createPromiseLogic };
|
|
223
|
-
//# sourceMappingURL=factory.esm.js.map
|
package/dist/index.cjs.js
CHANGED
|
@@ -14,6 +14,7 @@ function createLogicError(type, fulfilledCount, total, results) {
|
|
|
14
14
|
const messages = {
|
|
15
15
|
XOR_ERROR: `XOR condition failed: expected exactly 1 promise to fulfill, but ${fulfilledCount} fulfilled.`,
|
|
16
16
|
NAND_ERROR: `NAND condition failed: all ${total} promises fulfilled (expected at least one rejection).`,
|
|
17
|
+
NOT_ERROR: `NOT condition failed: promise resolved (expected rejection).`,
|
|
17
18
|
NOR_ERROR: `NOR condition failed: ${fulfilledCount} promises fulfilled (expected all rejected).`,
|
|
18
19
|
MAJORITY_ERROR: `Majority condition failed: ${fulfilledCount}/${total} fulfilled (need majority).`,
|
|
19
20
|
ALL_SUCCESSFUL_ERROR: `All successful condition failed: ${fulfilledCount}/${total} promises fulfilled (expected all to succeed).`,
|
|
@@ -32,6 +33,15 @@ class PromiseLogic {
|
|
|
32
33
|
return Promise.any(iterable);
|
|
33
34
|
}
|
|
34
35
|
|
|
36
|
+
|
|
37
|
+
static not(promise) {
|
|
38
|
+
return Promise.resolve(promise).then(
|
|
39
|
+
(value) => Promise.reject(value),
|
|
40
|
+
(reason) => Promise.resolve(reason)
|
|
41
|
+
)
|
|
42
|
+
.catch((error) => Promise.resolve(error));
|
|
43
|
+
}
|
|
44
|
+
|
|
35
45
|
static race(iterable) {
|
|
36
46
|
return Promise.race(iterable);
|
|
37
47
|
}
|
|
@@ -121,6 +131,7 @@ class PromiseLogic {
|
|
|
121
131
|
});
|
|
122
132
|
}
|
|
123
133
|
|
|
134
|
+
|
|
124
135
|
// θΏεζζζεηPromiseη»ζ
|
|
125
136
|
static allFulfilled(iterable) {
|
|
126
137
|
return Promise.allSettled(iterable).then((results) => {
|
|
@@ -203,10 +214,13 @@ function createPromiseLogic(options = {}) {
|
|
|
203
214
|
race: PromiseLogic.race,
|
|
204
215
|
allSettled: PromiseLogic.allSettled,
|
|
205
216
|
xor: PromiseLogic.xor,
|
|
217
|
+
not: PromiseLogic.not,
|
|
206
218
|
nand: PromiseLogic.nand,
|
|
207
219
|
nor: PromiseLogic.nor,
|
|
208
220
|
xnor: PromiseLogic.xnor,
|
|
209
|
-
majority: PromiseLogic.majority
|
|
221
|
+
majority: PromiseLogic.majority,
|
|
222
|
+
allFulfilled: PromiseLogic.allFulfilled,
|
|
223
|
+
allRejected: PromiseLogic.allRejected
|
|
210
224
|
};
|
|
211
225
|
|
|
212
226
|
// εΊη¨ε½ε转ζ’
|
|
@@ -225,4 +239,3 @@ exports.PromiseLogic = PromiseLogic;
|
|
|
225
239
|
exports.PromiseLogicError = PromiseLogicError;
|
|
226
240
|
exports.createLogicError = createLogicError;
|
|
227
241
|
exports.createPromiseLogic = createPromiseLogic;
|
|
228
|
-
//# sourceMappingURL=index.cjs.js.map
|