promise-logic 1.3.2 → 2.3.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.
Files changed (60) hide show
  1. package/README.md +213 -227
  2. package/dist/factory.cjs.js +15 -1
  3. package/dist/factory.cjs.js.map +1 -1
  4. package/dist/factory.esm.js +15 -1
  5. package/dist/factory.esm.js.map +1 -1
  6. package/dist/index.cjs.js +15 -1
  7. package/dist/index.cjs.js.map +1 -1
  8. package/dist/index.esm.js +15 -1
  9. package/dist/index.esm.js.map +1 -1
  10. package/dist/v2/factory.cjs.js +287 -0
  11. package/dist/v2/factory.cjs.js.map +1 -0
  12. package/dist/v2/factory.esm.js +285 -0
  13. package/dist/v2/factory.esm.js.map +1 -0
  14. package/dist/v2/gates/BaseGate.d.ts +6 -0
  15. package/dist/v2/gates/BaseGate.d.ts.map +1 -0
  16. package/dist/v2/gates/and.d.ts +5 -0
  17. package/dist/v2/gates/and.d.ts.map +1 -0
  18. package/dist/v2/gates/majority.d.ts +5 -0
  19. package/dist/v2/gates/majority.d.ts.map +1 -0
  20. package/dist/v2/gates/nand.d.ts +5 -0
  21. package/dist/v2/gates/nand.d.ts.map +1 -0
  22. package/dist/v2/gates/nor.d.ts +5 -0
  23. package/dist/v2/gates/nor.d.ts.map +1 -0
  24. package/dist/v2/gates/or.d.ts +5 -0
  25. package/dist/v2/gates/or.d.ts.map +1 -0
  26. package/dist/v2/gates/xnor.d.ts +5 -0
  27. package/dist/v2/gates/xnor.d.ts.map +1 -0
  28. package/dist/v2/gates/xor.d.ts +5 -0
  29. package/dist/v2/gates/xor.d.ts.map +1 -0
  30. package/dist/v2/index.cjs.js +289 -0
  31. package/dist/v2/index.cjs.js.map +1 -0
  32. package/dist/v2/index.esm.js +285 -0
  33. package/dist/v2/index.esm.js.map +1 -0
  34. package/dist/v2/ts/gates/BaseGate.d.ts +6 -0
  35. package/dist/v2/ts/gates/BaseGate.d.ts.map +1 -0
  36. package/dist/v2/ts/gates/and.d.ts +5 -0
  37. package/dist/v2/ts/gates/and.d.ts.map +1 -0
  38. package/dist/v2/ts/gates/majority.d.ts +5 -0
  39. package/dist/v2/ts/gates/majority.d.ts.map +1 -0
  40. package/dist/v2/ts/gates/nand.d.ts +5 -0
  41. package/dist/v2/ts/gates/nand.d.ts.map +1 -0
  42. package/dist/v2/ts/gates/nor.d.ts +5 -0
  43. package/dist/v2/ts/gates/nor.d.ts.map +1 -0
  44. package/dist/v2/ts/gates/or.d.ts +5 -0
  45. package/dist/v2/ts/gates/or.d.ts.map +1 -0
  46. package/dist/v2/ts/gates/xnor.d.ts +5 -0
  47. package/dist/v2/ts/gates/xnor.d.ts.map +1 -0
  48. package/dist/v2/ts/gates/xor.d.ts +5 -0
  49. package/dist/v2/ts/gates/xor.d.ts.map +1 -0
  50. package/dist/v2/types/factory.d.ts +10 -0
  51. package/dist/v2/types/index.d.ts +85 -0
  52. package/dist/v2/utils/v2/errors.d.ts +7 -0
  53. package/dist/v2/utils/v2/errors.d.ts.map +1 -0
  54. package/dist/v2/v2/PromiseLogic.d.ts +29 -0
  55. package/dist/v2/v2/PromiseLogic.d.ts.map +1 -0
  56. package/dist/v2/v2/factory.d.ts +7 -0
  57. package/dist/v2/v2/factory.d.ts.map +1 -0
  58. package/dist/v2/v2/index.d.ts +6 -0
  59. package/dist/v2/v2/index.d.ts.map +1 -0
  60. package/package.json +14 -10
@@ -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
  // 应用命名转换
@@ -1 +1 @@
1
- {"version":3,"file":"factory.esm.js","sources":["../src/utils/errors.js","../src/PromiseLogic.js","../src/factory.js"],"sourcesContent":["export class PromiseLogicError extends Error {\r\n constructor(type, message, results) {\r\n super(message);\r\n this.name = 'PromiseLogicError';\r\n this.type = type; // 'XOR_ERROR', 'NAND_ERROR', etc.\r\n this.results = results; // settlement results of all Promises\r\n }\r\n}\r\n\r\n// Error factory function\r\nexport function createLogicError(type, fulfilledCount, total, results) {\r\n const messages = {\r\n XOR_ERROR: `XOR condition failed: expected exactly 1 promise to fulfill, but ${fulfilledCount} fulfilled.`,\r\n NAND_ERROR: `NAND condition failed: all ${total} promises fulfilled (expected at least one rejection).`,\r\n NOR_ERROR: `NOR condition failed: ${fulfilledCount} promises fulfilled (expected all rejected).`,\r\n MAJORITY_ERROR: `Majority condition failed: ${fulfilledCount}/${total} fulfilled (need majority).`,\r\n ALL_SUCCESSFUL_ERROR: `All successful condition failed: ${fulfilledCount}/${total} promises fulfilled (expected all to succeed).`,\r\n ALL_FAILED_ERROR: `All failed condition failed: ${total - fulfilledCount}/${total} promises rejected (expected all to fail).`\r\n };\r\n \r\n return new PromiseLogicError(type, messages[type] || 'Logic condition failed', results);\r\n}","import { createLogicError } from './utils/errors.js';\r\n\r\nexport class PromiseLogic {\r\n static and(iterable) {\r\n return Promise.all(iterable);\r\n }\r\n\r\n static or(iterable) {\r\n return Promise.any(iterable);\r\n }\r\n\r\n static race(iterable) {\r\n return Promise.race(iterable);\r\n }\r\n\r\n static allSettled(iterable) {\r\n return Promise.allSettled(iterable);\r\n }\r\n\r\n static xor(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const fulfilled = results.filter(result => result.status === 'fulfilled');\r\n const fulfilledCount = fulfilled.length;\r\n const total = results.length;\r\n \r\n if (fulfilledCount === 1) {\r\n // 恰好一个成功,返回成功的值\r\n return fulfilled[0].value;\r\n } else {\r\n // 0个或多个(>1)成功,抛出XOR_ERROR\r\n throw createLogicError('XOR_ERROR', fulfilledCount, total, results);\r\n }\r\n });\r\n }\r\n\r\n static nand(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const fulfilled = results.filter(result => result.status === 'fulfilled');\r\n const fulfilledCount = fulfilled.length;\r\n const total = results.length;\r\n \r\n if (fulfilledCount === total) {\r\n // 全部成功,抛出NAND_ERROR\r\n throw createLogicError('NAND_ERROR', fulfilledCount, total, results);\r\n } else {\r\n // 不是所有都成功,返回成功的值数组\r\n return fulfilled.map(result => result.value);\r\n }\r\n });\r\n }\r\n\r\n static nor(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const fulfilled = results.filter(result => result.status === 'fulfilled');\r\n const fulfilledCount = fulfilled.length;\r\n const total = results.length;\r\n \r\n if (fulfilledCount === 0) {\r\n // 全部失败,返回空数组表示成功\r\n return [];\r\n } else {\r\n // 任意成功,抛出NOR_ERROR\r\n throw createLogicError('NOR_ERROR', fulfilledCount, total, results);\r\n }\r\n });\r\n }\r\n\r\n static xnor(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const fulfilled = results.filter(result => result.status === 'fulfilled');\r\n const fulfilledCount = fulfilled.length;\r\n const total = results.length;\r\n \r\n if (fulfilledCount === 0 || fulfilledCount === total) {\r\n // 全部成功或全部失败,返回成功的值数组\r\n return fulfilled.map(result => result.value);\r\n } else {\r\n // 部分成功部分失败,抛出XNOR_ERROR\r\n throw createLogicError('XNOR_ERROR', fulfilledCount, total, results);\r\n }\r\n });\r\n }\r\n\r\n static majority(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const fulfilled = results.filter(result => result.status === 'fulfilled');\r\n const fulfilledCount = fulfilled.length;\r\n const total = results.length;\r\n \r\n // 多数逻辑:成功数 > 失败数\r\n if (fulfilledCount > total - fulfilledCount) {\r\n // 超过半数成功,返回成功的值数组\r\n return fulfilled.map(result => result.value);\r\n } else {\r\n // 未达到多数,抛出MAJORITY_ERROR\r\n throw createLogicError('MAJORITY_ERROR', fulfilledCount, total, results);\r\n }\r\n });\r\n }\r\n\r\n // 返回所有成功的Promise结果\r\n static allFulfilled(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const fulfilled = results.filter(result => result.status === 'fulfilled');\r\n return fulfilled.map(result => result.value);\r\n });\r\n }\r\n\r\n // 返回所有失败的Promise结果\r\n static allRejected(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const rejected = results.filter(result => result.status === 'rejected');\r\n return rejected.map(result => result.reason);\r\n });\r\n }\r\n static createFlipFlop(initialState = false) {\r\n let state = initialState;\r\n let resolveCurrent = null;\r\n let currentPromise = Promise.resolve(state);\r\n \r\n return {\r\n // 获取当前状态\r\n getState() {\r\n return state;\r\n },\r\n \r\n // 异步设置状态\r\n set(newState) {\r\n state = newState;\r\n if (resolveCurrent) {\r\n resolveCurrent(state);\r\n resolveCurrent = null;\r\n }\r\n currentPromise = Promise.resolve(state);\r\n return this;\r\n },\r\n \r\n // 切换状态\r\n toggle() {\r\n return this.set(!state);\r\n },\r\n \r\n // 等待状态变化\r\n waitForChange() {\r\n if (!resolveCurrent) {\r\n currentPromise = new Promise((resolve) => {\r\n resolveCurrent = resolve;\r\n });\r\n }\r\n return currentPromise;\r\n },\r\n \r\n // 等待特定状态\r\n waitFor(targetState) {\r\n if (state === targetState) {\r\n return Promise.resolve(state);\r\n }\r\n return new Promise((resolve) => {\r\n const checkState = () => {\r\n if (state === targetState) {\r\n resolve(state);\r\n } else {\r\n this.waitForChange().then(checkState);\r\n }\r\n };\r\n checkState();\r\n });\r\n }\r\n };\r\n }\r\n}","import { PromiseLogic } from './PromiseLogic.js';\n\nexport function createPromiseLogic(options = {}) {\n const { prefix = '', suffix = '', rename = {} } = options;\n \n // 基础方法映射\n const methods = {\n and: PromiseLogic.and,\n or: PromiseLogic.or,\n race: PromiseLogic.race,\n allSettled: PromiseLogic.allSettled,\n xor: PromiseLogic.xor,\n nand: PromiseLogic.nand,\n nor: PromiseLogic.nor,\n xnor: PromiseLogic.xnor,\n majority: PromiseLogic.majority\n };\n \n // 应用命名转换\n const result = {};\n Object.entries(methods).forEach(([key, fn]) => {\n // 优先使用rename映射,然后应用prefix和suffix\n const baseName = rename[key] || key;\n const finalName = `${prefix}${baseName}${suffix}`;\n result[finalName] = fn;\n });\n \n return result;\n}"],"names":[],"mappings":"AAAO,MAAM,iBAAiB,SAAS,KAAK,CAAC;AAC7C,EAAE,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE;AACtC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;AACnB,IAAI,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;AACpC,IAAI,IAAI,CAAC,IAAI,GAAG,IAA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AAE,YAAY,CAAC,EAAE;AACvB,IAAI,IAAI,EAAE,YAAY,CAAC,IAAI;AAC3B,IAAI,UAAU,EAAE,YAAY,CAAC,UAAU;AACvC,IAAI,GAAG,EAAE,YAAY,CAAC,GAAG;AACzB,IAAI,IAAI,EAAE,YAAY,CAAC,IAAI;AAC3B,IAAI,GAAG,EAAE,YAAY,CAAC,GAAG;AACzB,IAAI,IAAI,EAAE,YAAY,CAAC,IAAI;AAC3B,IAAI,QAAQ,EAAE,YAAY,CAAC;AAC3B,GAAG;AACH;AACA;AACA,EAAE,MAAM,MAAM,GAAG,EAAE;AACnB,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK;AACjD;AACA,IAAI,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,GAAG;AACvC,IAAI,MAAM,SAAS,GAAG,CAAC,EAAE,MAAM,CAAC,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,CAAC;AACrD,IAAI,MAAM,CAAC,SAAS,CAAC,GAAG,EAAE;AAC1B,EAAE,CAAC,CAAC;AACJ;AACA,EAAE,OAAO,MAAM;AACf;;;;"}
1
+ {"version":3,"file":"factory.esm.js","sources":["../src/utils/v1/errors.js","../src/v1/PromiseLogic.js","../src/v1/factory.js"],"sourcesContent":["export class PromiseLogicError extends Error {\r\n constructor(type, message, results) {\r\n super(message);\r\n this.name = 'PromiseLogicError';\r\n this.type = type; // 'XOR_ERROR', 'NAND_ERROR', etc.\r\n this.results = results; // settlement results of all Promises\r\n }\r\n}\r\n\r\n// Error factory function\r\nexport function createLogicError(type, fulfilledCount, total, results) {\r\n const messages = {\r\n XOR_ERROR: `XOR condition failed: expected exactly 1 promise to fulfill, but ${fulfilledCount} fulfilled.`,\r\n NAND_ERROR: `NAND condition failed: all ${total} promises fulfilled (expected at least one rejection).`,\r\n NOT_ERROR: `NOT condition failed: promise resolved (expected rejection).`,\r\n NOR_ERROR: `NOR condition failed: ${fulfilledCount} promises fulfilled (expected all rejected).`,\r\n MAJORITY_ERROR: `Majority condition failed: ${fulfilledCount}/${total} fulfilled (need majority).`,\r\n ALL_SUCCESSFUL_ERROR: `All successful condition failed: ${fulfilledCount}/${total} promises fulfilled (expected all to succeed).`,\r\n ALL_FAILED_ERROR: `All failed condition failed: ${total - fulfilledCount}/${total} promises rejected (expected all to fail).`\r\n };\r\n \r\n return new PromiseLogicError(type, messages[type] || 'Logic condition failed', results);\r\n}","import { createLogicError } from '../utils/v1/errors.js';\r\n\r\nexport class PromiseLogic {\r\n static and(iterable) {\r\n return Promise.all(iterable);\r\n }\r\n\r\n static or(iterable) {\r\n return Promise.any(iterable);\r\n }\r\n\r\n \r\nstatic not(promise) {\r\n return Promise.resolve(promise).then(\r\n (value) => Promise.reject(value),\r\n (reason) => Promise.resolve(reason)\r\n )\r\n .catch((error) => Promise.resolve(error));\r\n}\r\n\r\n static race(iterable) {\r\n return Promise.race(iterable);\r\n }\r\n\r\n static allSettled(iterable) {\r\n return Promise.allSettled(iterable);\r\n }\r\n\r\n static xor(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const fulfilled = results.filter(result => result.status === 'fulfilled');\r\n const fulfilledCount = fulfilled.length;\r\n const total = results.length;\r\n \r\n if (fulfilledCount === 1) {\r\n // 恰好一个成功,返回成功的值\r\n return fulfilled[0].value;\r\n } else {\r\n // 0个或多个(>1)成功,抛出XOR_ERROR\r\n throw createLogicError('XOR_ERROR', fulfilledCount, total, results);\r\n }\r\n });\r\n }\r\n\r\n static nand(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const fulfilled = results.filter(result => result.status === 'fulfilled');\r\n const fulfilledCount = fulfilled.length;\r\n const total = results.length;\r\n \r\n if (fulfilledCount === total) {\r\n // 全部成功,抛出NAND_ERROR\r\n throw createLogicError('NAND_ERROR', fulfilledCount, total, results);\r\n } else {\r\n // 不是所有都成功,返回成功的值数组\r\n return fulfilled.map(result => result.value);\r\n }\r\n });\r\n }\r\n\r\n static nor(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const fulfilled = results.filter(result => result.status === 'fulfilled');\r\n const fulfilledCount = fulfilled.length;\r\n const total = results.length;\r\n \r\n if (fulfilledCount === 0) {\r\n // 全部失败,返回空数组表示成功\r\n return [];\r\n } else {\r\n // 任意成功,抛出NOR_ERROR\r\n throw createLogicError('NOR_ERROR', fulfilledCount, total, results);\r\n }\r\n });\r\n }\r\n\r\n static xnor(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const fulfilled = results.filter(result => result.status === 'fulfilled');\r\n const fulfilledCount = fulfilled.length;\r\n const total = results.length;\r\n \r\n if (fulfilledCount === 0 || fulfilledCount === total) {\r\n // 全部成功或全部失败,返回成功的值数组\r\n return fulfilled.map(result => result.value);\r\n } else {\r\n // 部分成功部分失败,抛出XNOR_ERROR\r\n throw createLogicError('XNOR_ERROR', fulfilledCount, total, results);\r\n }\r\n });\r\n }\r\n\r\n static majority(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const fulfilled = results.filter(result => result.status === 'fulfilled');\r\n const fulfilledCount = fulfilled.length;\r\n const total = results.length;\r\n \r\n // 多数逻辑:成功数 > 失败数\r\n if (fulfilledCount > total - fulfilledCount) {\r\n // 超过半数成功,返回成功的值数组\r\n return fulfilled.map(result => result.value);\r\n } else {\r\n // 未达到多数,抛出MAJORITY_ERROR\r\n throw createLogicError('MAJORITY_ERROR', fulfilledCount, total, results);\r\n }\r\n });\r\n }\r\n\r\n\r\n // 返回所有成功的Promise结果\r\n static allFulfilled(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const fulfilled = results.filter(result => result.status === 'fulfilled');\r\n return fulfilled.map(result => result.value);\r\n });\r\n }\r\n\r\n // 返回所有失败的Promise结果\r\n static allRejected(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const rejected = results.filter(result => result.status === 'rejected');\r\n return rejected.map(result => result.reason);\r\n });\r\n }\r\n static createFlipFlop(initialState = false) {\r\n let state = initialState;\r\n let resolveCurrent = null;\r\n let currentPromise = Promise.resolve(state);\r\n \r\n return {\r\n // 获取当前状态\r\n getState() {\r\n return state;\r\n },\r\n \r\n // 异步设置状态\r\n set(newState) {\r\n state = newState;\r\n if (resolveCurrent) {\r\n resolveCurrent(state);\r\n resolveCurrent = null;\r\n }\r\n currentPromise = Promise.resolve(state);\r\n return this;\r\n },\r\n \r\n // 切换状态\r\n toggle() {\r\n return this.set(!state);\r\n },\r\n \r\n // 等待状态变化\r\n waitForChange() {\r\n if (!resolveCurrent) {\r\n currentPromise = new Promise((resolve) => {\r\n resolveCurrent = resolve;\r\n });\r\n }\r\n return currentPromise;\r\n },\r\n \r\n // 等待特定状态\r\n waitFor(targetState) {\r\n if (state === targetState) {\r\n return Promise.resolve(state);\r\n }\r\n return new Promise((resolve) => {\r\n const checkState = () => {\r\n if (state === targetState) {\r\n resolve(state);\r\n } else {\r\n this.waitForChange().then(checkState);\r\n }\r\n };\r\n checkState();\r\n });\r\n }\r\n };\r\n }\r\n}","import { PromiseLogic } from './PromiseLogic.js';\n\nexport function createPromiseLogic(options = {}) {\n const { prefix = '', suffix = '', rename = {} } = options;\n \n // 基础方法映射\n const methods = {\n and: PromiseLogic.and,\n or: PromiseLogic.or,\n race: PromiseLogic.race,\n allSettled: PromiseLogic.allSettled,\n xor: PromiseLogic.xor,\n not: PromiseLogic.not,\n nand: PromiseLogic.nand,\n nor: PromiseLogic.nor,\n xnor: PromiseLogic.xnor,\n majority: PromiseLogic.majority,\n allFulfilled: PromiseLogic.allFulfilled,\n allRejected: PromiseLogic.allRejected\n };\n \n // 应用命名转换\n const result = {};\n Object.entries(methods).forEach(([key, fn]) => {\n // 优先使用rename映射,然后应用prefix和suffix\n const baseName = rename[key] || key;\n const finalName = `${prefix}${baseName}${suffix}`;\n result[finalName] = fn;\n });\n \n return result;\n}"],"names":[],"mappings":"AAAO,MAAM,iBAAiB,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ACjD;AACA,IAAI,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,GAAG;AACvC,IAAI,MAAM,SAAS,GAAG,CAAC,EAAE,MAAM,CAAC,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,CAAC;AACrD,IAAI,MAAM,CAAC,SAAS,CAAC,GAAG,EAAE;AAC1B,EAAE,CAAC,CAAC;AACJ;AACA,EAAE,OAAO,MAAM;AACf;;;;"}
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
  // 应用命名转换
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../src/utils/errors.js","../src/PromiseLogic.js","../src/factory.js"],"sourcesContent":["export class PromiseLogicError extends Error {\r\n constructor(type, message, results) {\r\n super(message);\r\n this.name = 'PromiseLogicError';\r\n this.type = type; // 'XOR_ERROR', 'NAND_ERROR', etc.\r\n this.results = results; // settlement results of all Promises\r\n }\r\n}\r\n\r\n// Error factory function\r\nexport function createLogicError(type, fulfilledCount, total, results) {\r\n const messages = {\r\n XOR_ERROR: `XOR condition failed: expected exactly 1 promise to fulfill, but ${fulfilledCount} fulfilled.`,\r\n NAND_ERROR: `NAND condition failed: all ${total} promises fulfilled (expected at least one rejection).`,\r\n NOR_ERROR: `NOR condition failed: ${fulfilledCount} promises fulfilled (expected all rejected).`,\r\n MAJORITY_ERROR: `Majority condition failed: ${fulfilledCount}/${total} fulfilled (need majority).`,\r\n ALL_SUCCESSFUL_ERROR: `All successful condition failed: ${fulfilledCount}/${total} promises fulfilled (expected all to succeed).`,\r\n ALL_FAILED_ERROR: `All failed condition failed: ${total - fulfilledCount}/${total} promises rejected (expected all to fail).`\r\n };\r\n \r\n return new PromiseLogicError(type, messages[type] || 'Logic condition failed', results);\r\n}","import { createLogicError } from './utils/errors.js';\r\n\r\nexport class PromiseLogic {\r\n static and(iterable) {\r\n return Promise.all(iterable);\r\n }\r\n\r\n static or(iterable) {\r\n return Promise.any(iterable);\r\n }\r\n\r\n static race(iterable) {\r\n return Promise.race(iterable);\r\n }\r\n\r\n static allSettled(iterable) {\r\n return Promise.allSettled(iterable);\r\n }\r\n\r\n static xor(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const fulfilled = results.filter(result => result.status === 'fulfilled');\r\n const fulfilledCount = fulfilled.length;\r\n const total = results.length;\r\n \r\n if (fulfilledCount === 1) {\r\n // 恰好一个成功,返回成功的值\r\n return fulfilled[0].value;\r\n } else {\r\n // 0个或多个(>1)成功,抛出XOR_ERROR\r\n throw createLogicError('XOR_ERROR', fulfilledCount, total, results);\r\n }\r\n });\r\n }\r\n\r\n static nand(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const fulfilled = results.filter(result => result.status === 'fulfilled');\r\n const fulfilledCount = fulfilled.length;\r\n const total = results.length;\r\n \r\n if (fulfilledCount === total) {\r\n // 全部成功,抛出NAND_ERROR\r\n throw createLogicError('NAND_ERROR', fulfilledCount, total, results);\r\n } else {\r\n // 不是所有都成功,返回成功的值数组\r\n return fulfilled.map(result => result.value);\r\n }\r\n });\r\n }\r\n\r\n static nor(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const fulfilled = results.filter(result => result.status === 'fulfilled');\r\n const fulfilledCount = fulfilled.length;\r\n const total = results.length;\r\n \r\n if (fulfilledCount === 0) {\r\n // 全部失败,返回空数组表示成功\r\n return [];\r\n } else {\r\n // 任意成功,抛出NOR_ERROR\r\n throw createLogicError('NOR_ERROR', fulfilledCount, total, results);\r\n }\r\n });\r\n }\r\n\r\n static xnor(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const fulfilled = results.filter(result => result.status === 'fulfilled');\r\n const fulfilledCount = fulfilled.length;\r\n const total = results.length;\r\n \r\n if (fulfilledCount === 0 || fulfilledCount === total) {\r\n // 全部成功或全部失败,返回成功的值数组\r\n return fulfilled.map(result => result.value);\r\n } else {\r\n // 部分成功部分失败,抛出XNOR_ERROR\r\n throw createLogicError('XNOR_ERROR', fulfilledCount, total, results);\r\n }\r\n });\r\n }\r\n\r\n static majority(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const fulfilled = results.filter(result => result.status === 'fulfilled');\r\n const fulfilledCount = fulfilled.length;\r\n const total = results.length;\r\n \r\n // 多数逻辑:成功数 > 失败数\r\n if (fulfilledCount > total - fulfilledCount) {\r\n // 超过半数成功,返回成功的值数组\r\n return fulfilled.map(result => result.value);\r\n } else {\r\n // 未达到多数,抛出MAJORITY_ERROR\r\n throw createLogicError('MAJORITY_ERROR', fulfilledCount, total, results);\r\n }\r\n });\r\n }\r\n\r\n // 返回所有成功的Promise结果\r\n static allFulfilled(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const fulfilled = results.filter(result => result.status === 'fulfilled');\r\n return fulfilled.map(result => result.value);\r\n });\r\n }\r\n\r\n // 返回所有失败的Promise结果\r\n static allRejected(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const rejected = results.filter(result => result.status === 'rejected');\r\n return rejected.map(result => result.reason);\r\n });\r\n }\r\n static createFlipFlop(initialState = false) {\r\n let state = initialState;\r\n let resolveCurrent = null;\r\n let currentPromise = Promise.resolve(state);\r\n \r\n return {\r\n // 获取当前状态\r\n getState() {\r\n return state;\r\n },\r\n \r\n // 异步设置状态\r\n set(newState) {\r\n state = newState;\r\n if (resolveCurrent) {\r\n resolveCurrent(state);\r\n resolveCurrent = null;\r\n }\r\n currentPromise = Promise.resolve(state);\r\n return this;\r\n },\r\n \r\n // 切换状态\r\n toggle() {\r\n return this.set(!state);\r\n },\r\n \r\n // 等待状态变化\r\n waitForChange() {\r\n if (!resolveCurrent) {\r\n currentPromise = new Promise((resolve) => {\r\n resolveCurrent = resolve;\r\n });\r\n }\r\n return currentPromise;\r\n },\r\n \r\n // 等待特定状态\r\n waitFor(targetState) {\r\n if (state === targetState) {\r\n return Promise.resolve(state);\r\n }\r\n return new Promise((resolve) => {\r\n const checkState = () => {\r\n if (state === targetState) {\r\n resolve(state);\r\n } else {\r\n this.waitForChange().then(checkState);\r\n }\r\n };\r\n checkState();\r\n });\r\n }\r\n };\r\n }\r\n}","import { PromiseLogic } from './PromiseLogic.js';\n\nexport function createPromiseLogic(options = {}) {\n const { prefix = '', suffix = '', rename = {} } = options;\n \n // 基础方法映射\n const methods = {\n and: PromiseLogic.and,\n or: PromiseLogic.or,\n race: PromiseLogic.race,\n allSettled: PromiseLogic.allSettled,\n xor: PromiseLogic.xor,\n nand: PromiseLogic.nand,\n nor: PromiseLogic.nor,\n xnor: PromiseLogic.xnor,\n majority: PromiseLogic.majority\n };\n \n // 应用命名转换\n const result = {};\n Object.entries(methods).forEach(([key, fn]) => {\n // 优先使用rename映射,然后应用prefix和suffix\n const baseName = rename[key] || key;\n const finalName = `${prefix}${baseName}${suffix}`;\n result[finalName] = fn;\n });\n \n return result;\n}"],"names":[],"mappings":";;AAAO,MAAM,iBAAiB,SAAS,KAAK,CAAC;AAC7C,EAAE,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE;AACtC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;AACnB,IAAI,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;AACpC,IAAI,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;AACrB,IAAI,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;AAC3B,EAAE,CAAC;AACH,CAAC;AACD;AACA;AACO,SAAS,gBAAgB,CAAC,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,OAAO,EAAE;AACvE,EAAE,MAAM,QAAQ,GAAG;AACnB,IAAI,SAAS,EAAE,CAAC,iEAAiE,EAAE,cAAc,CAAC,WAAW,CAAC;AAC9G,IAAI,UAAU,EAAE,CAAC,2BAA2B,EAAE,KAAK,CAAC,sDAAsD,CAAC;AAC3G,IAAI,SAAS,EAAE,CAAC,sBAAsB,EAAE,cAAc,CAAC,4CAA4C,CAAC;AACpG,IAAI,cAAc,EAAE,CAAC,2BAA2B,EAAE,cAAc,CAAC,CAAC,EAAE,KAAK,CAAC,2BAA2B,CAAC;AACtG,IAAI,oBAAoB,EAAE,CAAC,iCAAiC,EAAE,cAAc,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AAI,MAAM,SAAS,GAAG,CAAC,EAAE,MAAM,CAAC,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,CAAC;AACrD,IAAI,MAAM,CAAC,SAAS,CAAC,GAAG,EAAE;AAC1B,EAAE,CAAC,CAAC;AACJ;AACA,EAAE,OAAO,MAAM;AACf;;;;;;;"}
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/utils/v1/errors.js","../src/v1/PromiseLogic.js","../src/v1/factory.js"],"sourcesContent":["export class PromiseLogicError extends Error {\r\n constructor(type, message, results) {\r\n super(message);\r\n this.name = 'PromiseLogicError';\r\n this.type = type; // 'XOR_ERROR', 'NAND_ERROR', etc.\r\n this.results = results; // settlement results of all Promises\r\n }\r\n}\r\n\r\n// Error factory function\r\nexport function createLogicError(type, fulfilledCount, total, results) {\r\n const messages = {\r\n XOR_ERROR: `XOR condition failed: expected exactly 1 promise to fulfill, but ${fulfilledCount} fulfilled.`,\r\n NAND_ERROR: `NAND condition failed: all ${total} promises fulfilled (expected at least one rejection).`,\r\n NOT_ERROR: `NOT condition failed: promise resolved (expected rejection).`,\r\n NOR_ERROR: `NOR condition failed: ${fulfilledCount} promises fulfilled (expected all rejected).`,\r\n MAJORITY_ERROR: `Majority condition failed: ${fulfilledCount}/${total} fulfilled (need majority).`,\r\n ALL_SUCCESSFUL_ERROR: `All successful condition failed: ${fulfilledCount}/${total} promises fulfilled (expected all to succeed).`,\r\n ALL_FAILED_ERROR: `All failed condition failed: ${total - fulfilledCount}/${total} promises rejected (expected all to fail).`\r\n };\r\n \r\n return new PromiseLogicError(type, messages[type] || 'Logic condition failed', results);\r\n}","import { createLogicError } from '../utils/v1/errors.js';\r\n\r\nexport class PromiseLogic {\r\n static and(iterable) {\r\n return Promise.all(iterable);\r\n }\r\n\r\n static or(iterable) {\r\n return Promise.any(iterable);\r\n }\r\n\r\n \r\nstatic not(promise) {\r\n return Promise.resolve(promise).then(\r\n (value) => Promise.reject(value),\r\n (reason) => Promise.resolve(reason)\r\n )\r\n .catch((error) => Promise.resolve(error));\r\n}\r\n\r\n static race(iterable) {\r\n return Promise.race(iterable);\r\n }\r\n\r\n static allSettled(iterable) {\r\n return Promise.allSettled(iterable);\r\n }\r\n\r\n static xor(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const fulfilled = results.filter(result => result.status === 'fulfilled');\r\n const fulfilledCount = fulfilled.length;\r\n const total = results.length;\r\n \r\n if (fulfilledCount === 1) {\r\n // 恰好一个成功,返回成功的值\r\n return fulfilled[0].value;\r\n } else {\r\n // 0个或多个(>1)成功,抛出XOR_ERROR\r\n throw createLogicError('XOR_ERROR', fulfilledCount, total, results);\r\n }\r\n });\r\n }\r\n\r\n static nand(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const fulfilled = results.filter(result => result.status === 'fulfilled');\r\n const fulfilledCount = fulfilled.length;\r\n const total = results.length;\r\n \r\n if (fulfilledCount === total) {\r\n // 全部成功,抛出NAND_ERROR\r\n throw createLogicError('NAND_ERROR', fulfilledCount, total, results);\r\n } else {\r\n // 不是所有都成功,返回成功的值数组\r\n return fulfilled.map(result => result.value);\r\n }\r\n });\r\n }\r\n\r\n static nor(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const fulfilled = results.filter(result => result.status === 'fulfilled');\r\n const fulfilledCount = fulfilled.length;\r\n const total = results.length;\r\n \r\n if (fulfilledCount === 0) {\r\n // 全部失败,返回空数组表示成功\r\n return [];\r\n } else {\r\n // 任意成功,抛出NOR_ERROR\r\n throw createLogicError('NOR_ERROR', fulfilledCount, total, results);\r\n }\r\n });\r\n }\r\n\r\n static xnor(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const fulfilled = results.filter(result => result.status === 'fulfilled');\r\n const fulfilledCount = fulfilled.length;\r\n const total = results.length;\r\n \r\n if (fulfilledCount === 0 || fulfilledCount === total) {\r\n // 全部成功或全部失败,返回成功的值数组\r\n return fulfilled.map(result => result.value);\r\n } else {\r\n // 部分成功部分失败,抛出XNOR_ERROR\r\n throw createLogicError('XNOR_ERROR', fulfilledCount, total, results);\r\n }\r\n });\r\n }\r\n\r\n static majority(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const fulfilled = results.filter(result => result.status === 'fulfilled');\r\n const fulfilledCount = fulfilled.length;\r\n const total = results.length;\r\n \r\n // 多数逻辑:成功数 > 失败数\r\n if (fulfilledCount > total - fulfilledCount) {\r\n // 超过半数成功,返回成功的值数组\r\n return fulfilled.map(result => result.value);\r\n } else {\r\n // 未达到多数,抛出MAJORITY_ERROR\r\n throw createLogicError('MAJORITY_ERROR', fulfilledCount, total, results);\r\n }\r\n });\r\n }\r\n\r\n\r\n // 返回所有成功的Promise结果\r\n static allFulfilled(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const fulfilled = results.filter(result => result.status === 'fulfilled');\r\n return fulfilled.map(result => result.value);\r\n });\r\n }\r\n\r\n // 返回所有失败的Promise结果\r\n static allRejected(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const rejected = results.filter(result => result.status === 'rejected');\r\n return rejected.map(result => result.reason);\r\n });\r\n }\r\n static createFlipFlop(initialState = false) {\r\n let state = initialState;\r\n let resolveCurrent = null;\r\n let currentPromise = Promise.resolve(state);\r\n \r\n return {\r\n // 获取当前状态\r\n getState() {\r\n return state;\r\n },\r\n \r\n // 异步设置状态\r\n set(newState) {\r\n state = newState;\r\n if (resolveCurrent) {\r\n resolveCurrent(state);\r\n resolveCurrent = null;\r\n }\r\n currentPromise = Promise.resolve(state);\r\n return this;\r\n },\r\n \r\n // 切换状态\r\n toggle() {\r\n return this.set(!state);\r\n },\r\n \r\n // 等待状态变化\r\n waitForChange() {\r\n if (!resolveCurrent) {\r\n currentPromise = new Promise((resolve) => {\r\n resolveCurrent = resolve;\r\n });\r\n }\r\n return currentPromise;\r\n },\r\n \r\n // 等待特定状态\r\n waitFor(targetState) {\r\n if (state === targetState) {\r\n return Promise.resolve(state);\r\n }\r\n return new Promise((resolve) => {\r\n const checkState = () => {\r\n if (state === targetState) {\r\n resolve(state);\r\n } else {\r\n this.waitForChange().then(checkState);\r\n }\r\n };\r\n checkState();\r\n });\r\n }\r\n };\r\n }\r\n}","import { PromiseLogic } from './PromiseLogic.js';\n\nexport function createPromiseLogic(options = {}) {\n const { prefix = '', suffix = '', rename = {} } = options;\n \n // 基础方法映射\n const methods = {\n and: PromiseLogic.and,\n or: PromiseLogic.or,\n race: PromiseLogic.race,\n allSettled: PromiseLogic.allSettled,\n xor: PromiseLogic.xor,\n not: PromiseLogic.not,\n nand: PromiseLogic.nand,\n nor: PromiseLogic.nor,\n xnor: PromiseLogic.xnor,\n majority: PromiseLogic.majority,\n allFulfilled: PromiseLogic.allFulfilled,\n allRejected: PromiseLogic.allRejected\n };\n \n // 应用命名转换\n const result = {};\n Object.entries(methods).forEach(([key, fn]) => {\n // 优先使用rename映射,然后应用prefix和suffix\n const baseName = rename[key] || key;\n const finalName = `${prefix}${baseName}${suffix}`;\n result[finalName] = fn;\n });\n \n return result;\n}"],"names":[],"mappings":";;AAAO,MAAM,iBAAiB,SAAS,KAAK,CAAC;AAC7C,EAAE,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE;AACtC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;AACnB,IAAI,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;AACpC,IAAI,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;AACrB,IAAI,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;AAC3B,EAAE,CAAC;AACH,CAAC;AACD;AACA;AACO,SAAS,gBAAgB,CAAC,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,OAAO,EAAE;AACvE,EAAE,MAAM,QAAQ,GAAG;AACnB,IAAI,SAAS,EAAE,CAAC,iEAAiE,EAAE,cAAc,CAAC,WAAW,CAAC;AAC9G,IAAI,UAAU,EAAE,CAAC,2BAA2B,EAAE,KAAK,CAAC,sDAAsD,CAAC;AAC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;AAClB,IAAI,GAAG,EAAE,YAAY,CAAC,GAAG;AACzB,IAAI,EAAE,EAAE,YAAY,CAAC,EAAE;AACvB,IAAI,IAAI,EAAE,YAAY,CAAC,IAAI;AAC3B,IAAI,UAAU,EAAE,YAAY,CAAC,UAAU;AACvC,IAAI,GAAG,EAAE,YAAY,CAAC,GAAG;AACzB,IAAI,GAAG,EAAE,YAAY,CAAC,GAAG;AACzB,IAAI,IAAI,EAAE,YAAY,CAAC,IAAI;AAC3B,IAAI,GAAG,EAAE,YAAY,CAAC,GAAG;AACzB,IAAI,IAAI,EAAE,YAAY,CAAC,IAAI;AAC3B,IAAI,QAAQ,EAAE,YAAY,CAAC,QAAQ;AACnC,IAAI,YAAY,EAAE,YAAY,CAAC,YAAY;AAC3C,IAAI,WAAW,EAAE,YAAY,CAAC;AAC9B,GAAG;AACH;AACA;AACA,EAAE,MAAM,MAAM,GAAG,EAAE;AACnB,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK;AACjD;AACA,IAAI,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,GAAG;AACvC,IAAI,MAAM,SAAS,GAAG,CAAC,EAAE,MAAM,CAAC,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,CAAC;AACrD,IAAI,MAAM,CAAC,SAAS,CAAC,GAAG,EAAE;AAC1B,EAAE,CAAC,CAAC;AACJ;AACA,EAAE,OAAO,MAAM;AACf;;;;;;;"}
package/dist/index.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
  // 应用命名转换
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.js","sources":["../src/utils/errors.js","../src/PromiseLogic.js","../src/factory.js"],"sourcesContent":["export class PromiseLogicError extends Error {\r\n constructor(type, message, results) {\r\n super(message);\r\n this.name = 'PromiseLogicError';\r\n this.type = type; // 'XOR_ERROR', 'NAND_ERROR', etc.\r\n this.results = results; // settlement results of all Promises\r\n }\r\n}\r\n\r\n// Error factory function\r\nexport function createLogicError(type, fulfilledCount, total, results) {\r\n const messages = {\r\n XOR_ERROR: `XOR condition failed: expected exactly 1 promise to fulfill, but ${fulfilledCount} fulfilled.`,\r\n NAND_ERROR: `NAND condition failed: all ${total} promises fulfilled (expected at least one rejection).`,\r\n NOR_ERROR: `NOR condition failed: ${fulfilledCount} promises fulfilled (expected all rejected).`,\r\n MAJORITY_ERROR: `Majority condition failed: ${fulfilledCount}/${total} fulfilled (need majority).`,\r\n ALL_SUCCESSFUL_ERROR: `All successful condition failed: ${fulfilledCount}/${total} promises fulfilled (expected all to succeed).`,\r\n ALL_FAILED_ERROR: `All failed condition failed: ${total - fulfilledCount}/${total} promises rejected (expected all to fail).`\r\n };\r\n \r\n return new PromiseLogicError(type, messages[type] || 'Logic condition failed', results);\r\n}","import { createLogicError } from './utils/errors.js';\r\n\r\nexport class PromiseLogic {\r\n static and(iterable) {\r\n return Promise.all(iterable);\r\n }\r\n\r\n static or(iterable) {\r\n return Promise.any(iterable);\r\n }\r\n\r\n static race(iterable) {\r\n return Promise.race(iterable);\r\n }\r\n\r\n static allSettled(iterable) {\r\n return Promise.allSettled(iterable);\r\n }\r\n\r\n static xor(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const fulfilled = results.filter(result => result.status === 'fulfilled');\r\n const fulfilledCount = fulfilled.length;\r\n const total = results.length;\r\n \r\n if (fulfilledCount === 1) {\r\n // 恰好一个成功,返回成功的值\r\n return fulfilled[0].value;\r\n } else {\r\n // 0个或多个(>1)成功,抛出XOR_ERROR\r\n throw createLogicError('XOR_ERROR', fulfilledCount, total, results);\r\n }\r\n });\r\n }\r\n\r\n static nand(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const fulfilled = results.filter(result => result.status === 'fulfilled');\r\n const fulfilledCount = fulfilled.length;\r\n const total = results.length;\r\n \r\n if (fulfilledCount === total) {\r\n // 全部成功,抛出NAND_ERROR\r\n throw createLogicError('NAND_ERROR', fulfilledCount, total, results);\r\n } else {\r\n // 不是所有都成功,返回成功的值数组\r\n return fulfilled.map(result => result.value);\r\n }\r\n });\r\n }\r\n\r\n static nor(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const fulfilled = results.filter(result => result.status === 'fulfilled');\r\n const fulfilledCount = fulfilled.length;\r\n const total = results.length;\r\n \r\n if (fulfilledCount === 0) {\r\n // 全部失败,返回空数组表示成功\r\n return [];\r\n } else {\r\n // 任意成功,抛出NOR_ERROR\r\n throw createLogicError('NOR_ERROR', fulfilledCount, total, results);\r\n }\r\n });\r\n }\r\n\r\n static xnor(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const fulfilled = results.filter(result => result.status === 'fulfilled');\r\n const fulfilledCount = fulfilled.length;\r\n const total = results.length;\r\n \r\n if (fulfilledCount === 0 || fulfilledCount === total) {\r\n // 全部成功或全部失败,返回成功的值数组\r\n return fulfilled.map(result => result.value);\r\n } else {\r\n // 部分成功部分失败,抛出XNOR_ERROR\r\n throw createLogicError('XNOR_ERROR', fulfilledCount, total, results);\r\n }\r\n });\r\n }\r\n\r\n static majority(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const fulfilled = results.filter(result => result.status === 'fulfilled');\r\n const fulfilledCount = fulfilled.length;\r\n const total = results.length;\r\n \r\n // 多数逻辑:成功数 > 失败数\r\n if (fulfilledCount > total - fulfilledCount) {\r\n // 超过半数成功,返回成功的值数组\r\n return fulfilled.map(result => result.value);\r\n } else {\r\n // 未达到多数,抛出MAJORITY_ERROR\r\n throw createLogicError('MAJORITY_ERROR', fulfilledCount, total, results);\r\n }\r\n });\r\n }\r\n\r\n // 返回所有成功的Promise结果\r\n static allFulfilled(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const fulfilled = results.filter(result => result.status === 'fulfilled');\r\n return fulfilled.map(result => result.value);\r\n });\r\n }\r\n\r\n // 返回所有失败的Promise结果\r\n static allRejected(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const rejected = results.filter(result => result.status === 'rejected');\r\n return rejected.map(result => result.reason);\r\n });\r\n }\r\n static createFlipFlop(initialState = false) {\r\n let state = initialState;\r\n let resolveCurrent = null;\r\n let currentPromise = Promise.resolve(state);\r\n \r\n return {\r\n // 获取当前状态\r\n getState() {\r\n return state;\r\n },\r\n \r\n // 异步设置状态\r\n set(newState) {\r\n state = newState;\r\n if (resolveCurrent) {\r\n resolveCurrent(state);\r\n resolveCurrent = null;\r\n }\r\n currentPromise = Promise.resolve(state);\r\n return this;\r\n },\r\n \r\n // 切换状态\r\n toggle() {\r\n return this.set(!state);\r\n },\r\n \r\n // 等待状态变化\r\n waitForChange() {\r\n if (!resolveCurrent) {\r\n currentPromise = new Promise((resolve) => {\r\n resolveCurrent = resolve;\r\n });\r\n }\r\n return currentPromise;\r\n },\r\n \r\n // 等待特定状态\r\n waitFor(targetState) {\r\n if (state === targetState) {\r\n return Promise.resolve(state);\r\n }\r\n return new Promise((resolve) => {\r\n const checkState = () => {\r\n if (state === targetState) {\r\n resolve(state);\r\n } else {\r\n this.waitForChange().then(checkState);\r\n }\r\n };\r\n checkState();\r\n });\r\n }\r\n };\r\n }\r\n}","import { PromiseLogic } from './PromiseLogic.js';\n\nexport function createPromiseLogic(options = {}) {\n const { prefix = '', suffix = '', rename = {} } = options;\n \n // 基础方法映射\n const methods = {\n and: PromiseLogic.and,\n or: PromiseLogic.or,\n race: PromiseLogic.race,\n allSettled: PromiseLogic.allSettled,\n xor: PromiseLogic.xor,\n nand: PromiseLogic.nand,\n nor: PromiseLogic.nor,\n xnor: PromiseLogic.xnor,\n majority: PromiseLogic.majority\n };\n \n // 应用命名转换\n const result = {};\n Object.entries(methods).forEach(([key, fn]) => {\n // 优先使用rename映射,然后应用prefix和suffix\n const baseName = rename[key] || key;\n const finalName = `${prefix}${baseName}${suffix}`;\n result[finalName] = fn;\n });\n \n return result;\n}"],"names":[],"mappings":"AAAO,MAAM,iBAAiB,SAAS,KAAK,CAAC;AAC7C,EAAE,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE;AACtC,IAAI,KAAK,C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AAG,OAAO;AAC3D;AACA;AACA,EAAE,MAAM,OAAO,GAAG;AAClB,IAAI,GAAG,EAAE,YAAY,CAAC,GAAG;AACzB,IAAI,EAAE,EAAE,YAAY,CAAC,EAAE;AACvB,IAAI,IAAI,EAAE,YAAY,CAAC,IAAI;AAC3B,IAAI,UAAU,EAAE,YAAY,CAAC,UAAU;AACvC,IAAI,GAAG,EAAE,YAAY,CAAC,GAAG;AACzB,IAAI,IAAI,EAAE,YAAY,CAAC,IAAI;AAC3B,IAAI,GAAG,EAAE,YAAY,CAAC,GAAG;AACzB,IAAI,IAAI,EAAE,YAAY,CAAC,IAAI;AAC3B,IAAI,QAAQ,EAAE,YAAY,CAAC;AAC3B,GAAG;AACH;AACA;AACA,EAAE,MAAM,MAAM,GAAG,EAAE;AACnB,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK;AACjD;AACA,IAAI,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,GAAG;AACvC,IAAI,MAAM,SAAS,GAAG,CAAC,EAAE,MAAM,CAAC,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,CAAC;AACrD,IAAI,MAAM,CAAC,SAAS,CAAC,GAAG,EAAE;AAC1B,EAAE,CAAC,CAAC;AACJ;AACA,EAAE,OAAO,MAAM;AACf;;;;"}
1
+ {"version":3,"file":"index.esm.js","sources":["../src/utils/v1/errors.js","../src/v1/PromiseLogic.js","../src/v1/factory.js"],"sourcesContent":["export class PromiseLogicError extends Error {\r\n constructor(type, message, results) {\r\n super(message);\r\n this.name = 'PromiseLogicError';\r\n this.type = type; // 'XOR_ERROR', 'NAND_ERROR', etc.\r\n this.results = results; // settlement results of all Promises\r\n }\r\n}\r\n\r\n// Error factory function\r\nexport function createLogicError(type, fulfilledCount, total, results) {\r\n const messages = {\r\n XOR_ERROR: `XOR condition failed: expected exactly 1 promise to fulfill, but ${fulfilledCount} fulfilled.`,\r\n NAND_ERROR: `NAND condition failed: all ${total} promises fulfilled (expected at least one rejection).`,\r\n NOT_ERROR: `NOT condition failed: promise resolved (expected rejection).`,\r\n NOR_ERROR: `NOR condition failed: ${fulfilledCount} promises fulfilled (expected all rejected).`,\r\n MAJORITY_ERROR: `Majority condition failed: ${fulfilledCount}/${total} fulfilled (need majority).`,\r\n ALL_SUCCESSFUL_ERROR: `All successful condition failed: ${fulfilledCount}/${total} promises fulfilled (expected all to succeed).`,\r\n ALL_FAILED_ERROR: `All failed condition failed: ${total - fulfilledCount}/${total} promises rejected (expected all to fail).`\r\n };\r\n \r\n return new PromiseLogicError(type, messages[type] || 'Logic condition failed', results);\r\n}","import { createLogicError } from '../utils/v1/errors.js';\r\n\r\nexport class PromiseLogic {\r\n static and(iterable) {\r\n return Promise.all(iterable);\r\n }\r\n\r\n static or(iterable) {\r\n return Promise.any(iterable);\r\n }\r\n\r\n \r\nstatic not(promise) {\r\n return Promise.resolve(promise).then(\r\n (value) => Promise.reject(value),\r\n (reason) => Promise.resolve(reason)\r\n )\r\n .catch((error) => Promise.resolve(error));\r\n}\r\n\r\n static race(iterable) {\r\n return Promise.race(iterable);\r\n }\r\n\r\n static allSettled(iterable) {\r\n return Promise.allSettled(iterable);\r\n }\r\n\r\n static xor(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const fulfilled = results.filter(result => result.status === 'fulfilled');\r\n const fulfilledCount = fulfilled.length;\r\n const total = results.length;\r\n \r\n if (fulfilledCount === 1) {\r\n // 恰好一个成功,返回成功的值\r\n return fulfilled[0].value;\r\n } else {\r\n // 0个或多个(>1)成功,抛出XOR_ERROR\r\n throw createLogicError('XOR_ERROR', fulfilledCount, total, results);\r\n }\r\n });\r\n }\r\n\r\n static nand(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const fulfilled = results.filter(result => result.status === 'fulfilled');\r\n const fulfilledCount = fulfilled.length;\r\n const total = results.length;\r\n \r\n if (fulfilledCount === total) {\r\n // 全部成功,抛出NAND_ERROR\r\n throw createLogicError('NAND_ERROR', fulfilledCount, total, results);\r\n } else {\r\n // 不是所有都成功,返回成功的值数组\r\n return fulfilled.map(result => result.value);\r\n }\r\n });\r\n }\r\n\r\n static nor(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const fulfilled = results.filter(result => result.status === 'fulfilled');\r\n const fulfilledCount = fulfilled.length;\r\n const total = results.length;\r\n \r\n if (fulfilledCount === 0) {\r\n // 全部失败,返回空数组表示成功\r\n return [];\r\n } else {\r\n // 任意成功,抛出NOR_ERROR\r\n throw createLogicError('NOR_ERROR', fulfilledCount, total, results);\r\n }\r\n });\r\n }\r\n\r\n static xnor(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const fulfilled = results.filter(result => result.status === 'fulfilled');\r\n const fulfilledCount = fulfilled.length;\r\n const total = results.length;\r\n \r\n if (fulfilledCount === 0 || fulfilledCount === total) {\r\n // 全部成功或全部失败,返回成功的值数组\r\n return fulfilled.map(result => result.value);\r\n } else {\r\n // 部分成功部分失败,抛出XNOR_ERROR\r\n throw createLogicError('XNOR_ERROR', fulfilledCount, total, results);\r\n }\r\n });\r\n }\r\n\r\n static majority(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const fulfilled = results.filter(result => result.status === 'fulfilled');\r\n const fulfilledCount = fulfilled.length;\r\n const total = results.length;\r\n \r\n // 多数逻辑:成功数 > 失败数\r\n if (fulfilledCount > total - fulfilledCount) {\r\n // 超过半数成功,返回成功的值数组\r\n return fulfilled.map(result => result.value);\r\n } else {\r\n // 未达到多数,抛出MAJORITY_ERROR\r\n throw createLogicError('MAJORITY_ERROR', fulfilledCount, total, results);\r\n }\r\n });\r\n }\r\n\r\n\r\n // 返回所有成功的Promise结果\r\n static allFulfilled(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const fulfilled = results.filter(result => result.status === 'fulfilled');\r\n return fulfilled.map(result => result.value);\r\n });\r\n }\r\n\r\n // 返回所有失败的Promise结果\r\n static allRejected(iterable) {\r\n return Promise.allSettled(iterable).then((results) => {\r\n const rejected = results.filter(result => result.status === 'rejected');\r\n return rejected.map(result => result.reason);\r\n });\r\n }\r\n static createFlipFlop(initialState = false) {\r\n let state = initialState;\r\n let resolveCurrent = null;\r\n let currentPromise = Promise.resolve(state);\r\n \r\n return {\r\n // 获取当前状态\r\n getState() {\r\n return state;\r\n },\r\n \r\n // 异步设置状态\r\n set(newState) {\r\n state = newState;\r\n if (resolveCurrent) {\r\n resolveCurrent(state);\r\n resolveCurrent = null;\r\n }\r\n currentPromise = Promise.resolve(state);\r\n return this;\r\n },\r\n \r\n // 切换状态\r\n toggle() {\r\n return this.set(!state);\r\n },\r\n \r\n // 等待状态变化\r\n waitForChange() {\r\n if (!resolveCurrent) {\r\n currentPromise = new Promise((resolve) => {\r\n resolveCurrent = resolve;\r\n });\r\n }\r\n return currentPromise;\r\n },\r\n \r\n // 等待特定状态\r\n waitFor(targetState) {\r\n if (state === targetState) {\r\n return Promise.resolve(state);\r\n }\r\n return new Promise((resolve) => {\r\n const checkState = () => {\r\n if (state === targetState) {\r\n resolve(state);\r\n } else {\r\n this.waitForChange().then(checkState);\r\n }\r\n };\r\n checkState();\r\n });\r\n }\r\n };\r\n }\r\n}","import { PromiseLogic } from './PromiseLogic.js';\n\nexport function createPromiseLogic(options = {}) {\n const { prefix = '', suffix = '', rename = {} } = options;\n \n // 基础方法映射\n const methods = {\n and: PromiseLogic.and,\n or: PromiseLogic.or,\n race: PromiseLogic.race,\n allSettled: PromiseLogic.allSettled,\n xor: PromiseLogic.xor,\n not: PromiseLogic.not,\n nand: PromiseLogic.nand,\n nor: PromiseLogic.nor,\n xnor: PromiseLogic.xnor,\n majority: PromiseLogic.majority,\n allFulfilled: PromiseLogic.allFulfilled,\n allRejected: PromiseLogic.allRejected\n };\n \n // 应用命名转换\n const result = {};\n Object.entries(methods).forEach(([key, fn]) => {\n // 优先使用rename映射,然后应用prefix和suffix\n const baseName = rename[key] || key;\n const finalName = `${prefix}${baseName}${suffix}`;\n result[finalName] = fn;\n });\n \n return result;\n}"],"names":[],"mappings":"AAAO,MAAM,iBAAiB,SAAS,KAAK,CAAC;AAC7C,EAAE,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE;AACtC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;AACnB,IAAI,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;AACpC,IAAI,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;AACrB,IAAI,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;AAC3B,EAAE,CAAC;AACH,CAAC;AACD;AACA;AACO,SAAS,gBAAgB,CAAC,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,OAAO,EAAE;AACvE,EAAE,MAAM,QAAQ,GAAG;AACnB,IAAI,SAAS,EAAE,CAAC,iEAAiE,EAAE,cAAc,CAAC,WAAW,CAAC;AAC9G,IAAI,UAAU,EAAE,CAAC,2BAA2B,EAAE,KAAK,CAAC,sDAAsD,CAAC;AAC3G,IAAI,SAAS,EAAE,CAAC,4DAA4D,CAAC;AAC7E,IAAI,SAAS,EAAE,CAAC,sBAAsB,EAAE,cAAc,CAAC,4CAA4C,CAAC;AACpG,IAAI,cAAc,EAAE,CAAC,2BAA2B,EAAE,cAAc,CAAC,CAAC,EAAE,KAAK,CAAC,2BAA2B,CAAC;AACtG,IAAI,oBAAoB,EAAE,CAAC,iCAAiC,EAAE,cAAc,CAAC,CAAC,EAAE,KAAK,CAAC,8CAA8C,CAAC;AACrI,IAAI,gBAAgB,EAAE,CAAC,6BAA6B,EAAE,KAAK,GAAG,cAAc,CAAC,CAAC,EAAE,KAAK,CAAC,0CAA0C,CAAC;AACjI,GAAG,CAAC;AACJ;AACA,EAAE,OAAO,IAAI,iBAAiB,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,IAAI,wBAAwB,EAAE,OAAO,CAAC,CAAC;AAC1F;;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E;AACnB,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK;AACjD;AACA,IAAI,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,GAAG;AACvC,IAAI,MAAM,SAAS,GAAG,CAAC,EAAE,MAAM,CAAC,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,CAAC;AACrD,IAAI,MAAM,CAAC,SAAS,CAAC,GAAG,EAAE;AAC1B,EAAE,CAAC,CAAC;AACJ;AACA,EAAE,OAAO,MAAM;AACf;;;;"}
@@ -0,0 +1,287 @@
1
+ 'use strict';
2
+
3
+ class BaseGate {
4
+ filterResults(results, status) {
5
+ if (status === 'fulfilled') {
6
+ return results
7
+ .filter((result) => result.status === 'fulfilled')
8
+ .map(result => result.value);
9
+ }
10
+ else {
11
+ return results
12
+ .filter((result) => result.status === 'rejected')
13
+ .map(result => result.reason);
14
+ }
15
+ }
16
+ countFulfilled(results) {
17
+ return results.filter(result => result.status === 'fulfilled').length;
18
+ }
19
+ }
20
+
21
+ class OrGate extends BaseGate {
22
+ async execute(iterable) {
23
+ return Promise.any(iterable);
24
+ }
25
+ }
26
+
27
+ class AndGate extends BaseGate {
28
+ async execute(iterable) {
29
+ try {
30
+ return Promise.all(iterable);
31
+ }
32
+ catch (error) {
33
+ throw new PromiseLogicError('AND_ERROR', 'AND gate failed', [error]);
34
+ }
35
+ }
36
+ }
37
+
38
+ let PromiseLogicError$1 = class PromiseLogicError extends Error {
39
+ constructor(type, message, results) {
40
+ super(message);
41
+ this.type = type;
42
+ this.results = results;
43
+ this.name = 'PromiseLogicError';
44
+ }
45
+ };
46
+ // Error factory function
47
+ function createLogicError(type, fulfilledCount, total, results) {
48
+ const messages = {
49
+ XOR_ERROR: `XOR condition failed: expected exactly 1 promise to fulfill, but ${fulfilledCount} fulfilled.`,
50
+ NAND_ERROR: `NAND condition failed: all ${total} promises fulfilled (expected at least one rejection).`,
51
+ NOR_ERROR: `NOR condition failed: ${fulfilledCount} promises fulfilled (expected all rejected).`,
52
+ XNOR_ERROR: `XNOR condition failed: ${fulfilledCount}/${total} promises fulfilled (expected all or none).`,
53
+ MAJORITY_ERROR: `Majority condition failed: ${fulfilledCount}/${total} fulfilled (need majority).`,
54
+ ALL_SUCCESSFUL_ERROR: `All successful condition failed: ${fulfilledCount}/${total} promises fulfilled (expected all to succeed).`,
55
+ ALL_FAILED_ERROR: `All failed condition failed: ${total - fulfilledCount}/${total} promises rejected (expected all to fail).`
56
+ };
57
+ return new PromiseLogicError$1(type, messages[type] || 'Logic condition failed', results);
58
+ }
59
+
60
+ class MajorityGate extends BaseGate {
61
+ async execute(iterable) {
62
+ const results = await Promise.allSettled(iterable);
63
+ const fulfilled = this.filterResults(results, 'fulfilled');
64
+ const fulfilledCount = fulfilled.length;
65
+ const total = results.length;
66
+ // Majority logic: success count > failure count
67
+ if (fulfilledCount > total - fulfilledCount) {
68
+ return fulfilled;
69
+ }
70
+ else {
71
+ throw createLogicError('MAJORITY_ERROR', fulfilledCount, total, results);
72
+ }
73
+ }
74
+ }
75
+
76
+ class NandGate extends BaseGate {
77
+ async execute(iterable) {
78
+ const results = await Promise.allSettled(iterable);
79
+ const fulfilled = this.filterResults(results, 'fulfilled');
80
+ const fulfilledCount = fulfilled.length;
81
+ const total = results.length;
82
+ if (fulfilledCount === total) {
83
+ // 全部成功,抛出NAND_ERROR
84
+ throw createLogicError('NAND_ERROR', fulfilledCount, total, results);
85
+ }
86
+ else {
87
+ // 不是所有都成功,返回成功的值数组
88
+ return fulfilled;
89
+ }
90
+ }
91
+ }
92
+
93
+ class NorGate extends BaseGate {
94
+ async execute(iterable) {
95
+ const results = await Promise.allSettled(iterable);
96
+ const fulfilled = this.filterResults(results, 'fulfilled');
97
+ const fulfilledCount = fulfilled.length;
98
+ const total = results.length;
99
+ if (fulfilledCount === 0) {
100
+ // 全部失败,返回空数组表示成功
101
+ return [];
102
+ }
103
+ else {
104
+ // 任意成功,抛出NOR_ERROR
105
+ throw createLogicError('NOR_ERROR', fulfilledCount, total, results);
106
+ }
107
+ }
108
+ }
109
+
110
+ class XnorGate extends BaseGate {
111
+ async execute(iterable) {
112
+ const results = await Promise.allSettled(iterable);
113
+ const fulfilled = this.filterResults(results, 'fulfilled');
114
+ const fulfilledCount = fulfilled.length;
115
+ const total = results.length;
116
+ if (fulfilledCount === 0 || fulfilledCount === total) {
117
+ // 全部成功或全部失败,返回成功的值数组
118
+ return fulfilled;
119
+ }
120
+ else {
121
+ // 部分成功部分失败,抛出XNOR_ERROR
122
+ throw createLogicError('XNOR_ERROR', fulfilledCount, total, results);
123
+ }
124
+ }
125
+ }
126
+
127
+ class XorGate extends BaseGate {
128
+ async execute(iterable) {
129
+ const results = await Promise.allSettled(iterable);
130
+ const fulfilled = results.filter(result => result.status === 'fulfilled');
131
+ const fulfilledCount = fulfilled.length;
132
+ const total = results.length;
133
+ if (fulfilledCount === 1) {
134
+ return fulfilled[0].value;
135
+ }
136
+ else {
137
+ throw createLogicError('XOR_ERROR', fulfilledCount, total, results);
138
+ }
139
+ }
140
+ }
141
+
142
+ class PromiseLogicError extends Error {
143
+ constructor(type, message, results) {
144
+ super(message);
145
+ this.type = type;
146
+ this.results = results;
147
+ this.name = 'PromiseLogicError';
148
+ }
149
+ }
150
+ class PromiseLogic {
151
+ static get gates() {
152
+ return {
153
+ and: new AndGate(),
154
+ or: new OrGate(),
155
+ xor: new XorGate(),
156
+ nand: new NandGate(),
157
+ nor: new NorGate(),
158
+ xnor: new XnorGate(),
159
+ majority: new MajorityGate()
160
+ };
161
+ }
162
+ // Core Logic Gates
163
+ static and(iterable) {
164
+ return this.gates.and.execute(iterable);
165
+ }
166
+ static or(iterable) {
167
+ return this.gates.or.execute(iterable);
168
+ }
169
+ static xor(iterable) {
170
+ return this.gates.xor.execute(iterable);
171
+ }
172
+ static nand(iterable) {
173
+ return this.gates.nand.execute(iterable);
174
+ }
175
+ static nor(iterable) {
176
+ return this.gates.nor.execute(iterable);
177
+ }
178
+ static xnor(iterable) {
179
+ return this.gates.xnor.execute(iterable);
180
+ }
181
+ static majority(iterable) {
182
+ return this.gates.majority.execute(iterable);
183
+ }
184
+ // Extended Operations
185
+ static allFulfilled(iterable) {
186
+ return Promise.allSettled(iterable).then((results) => {
187
+ const fulfilled = results.filter(result => result.status === 'fulfilled');
188
+ return fulfilled.map(result => result.value);
189
+ });
190
+ }
191
+ static allRejected(iterable) {
192
+ return Promise.allSettled(iterable).then((results) => {
193
+ return results
194
+ .filter((result) => result.status === 'rejected')
195
+ .map(result => result.reason);
196
+ });
197
+ }
198
+ // NOT logic - Inverts promise resolution
199
+ static not(promise) {
200
+ return Promise.resolve(promise).then((value) => Promise.reject(value), (reason) => Promise.resolve(reason));
201
+ }
202
+ // Utility Methods
203
+ static race(iterable) {
204
+ return Promise.race(iterable);
205
+ }
206
+ static allSettled(iterable) {
207
+ return Promise.allSettled(iterable);
208
+ }
209
+ static createFlipFlop(initialState = false) {
210
+ let state = initialState;
211
+ let resolveCurrent = null;
212
+ let currentPromise = Promise.resolve(state);
213
+ const waitForChange = () => {
214
+ if (!resolveCurrent) {
215
+ currentPromise = new Promise((resolve) => {
216
+ resolveCurrent = resolve;
217
+ });
218
+ }
219
+ return currentPromise;
220
+ };
221
+ return {
222
+ getState() {
223
+ return state;
224
+ },
225
+ async set(newState) {
226
+ state = newState;
227
+ if (resolveCurrent) {
228
+ resolveCurrent(state);
229
+ resolveCurrent = null;
230
+ }
231
+ currentPromise = Promise.resolve(state);
232
+ return state;
233
+ },
234
+ async toggle() {
235
+ return this.set(!state);
236
+ },
237
+ waitForChange,
238
+ waitFor(targetState) {
239
+ if (state === targetState) {
240
+ return Promise.resolve(state);
241
+ }
242
+ return new Promise((resolve) => {
243
+ const checkState = () => {
244
+ if (state === targetState) {
245
+ resolve(state);
246
+ }
247
+ else {
248
+ waitForChange().then(checkState);
249
+ }
250
+ };
251
+ checkState();
252
+ });
253
+ }
254
+ };
255
+ }
256
+ }
257
+
258
+ function createPromiseLogic(options = {}) {
259
+ const { prefix = '', suffix = '', rename = {} } = options;
260
+ // 基础方法映射
261
+ const methods = {
262
+ and: PromiseLogic.and,
263
+ or: PromiseLogic.or,
264
+ not: PromiseLogic.not,
265
+ race: PromiseLogic.race,
266
+ allSettled: PromiseLogic.allSettled,
267
+ xor: PromiseLogic.xor,
268
+ nand: PromiseLogic.nand,
269
+ nor: PromiseLogic.nor,
270
+ xnor: PromiseLogic.xnor,
271
+ majority: PromiseLogic.majority,
272
+ allFulfilled: PromiseLogic.allFulfilled,
273
+ allRejected: PromiseLogic.allRejected
274
+ };
275
+ // 应用命名转换
276
+ const result = {};
277
+ Object.entries(methods).forEach(([key, fn]) => {
278
+ // 优先使用rename映射,然后应用prefix和suffix
279
+ const baseName = rename[key] || key;
280
+ const finalName = `${prefix}${baseName}${suffix}`;
281
+ result[finalName] = fn;
282
+ });
283
+ return result;
284
+ }
285
+
286
+ exports.createPromiseLogic = createPromiseLogic;
287
+ //# sourceMappingURL=factory.cjs.js.map