mqtt-plus 1.4.22 → 1.4.24

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 (39) hide show
  1. package/.ase/service.log +10402 -0
  2. package/.ase/task/TASK-P18.md +47 -0
  3. package/.ase/task/TASK-P2.md +76 -0
  4. package/.ase/task/TASK-P21.md +75 -0
  5. package/.claude/settings.local.json +7 -0
  6. package/CHANGELOG.md +21 -1
  7. package/README.md +4 -4
  8. package/dst-stage1/mqtt-plus-api.d.ts +6 -6
  9. package/dst-stage1/mqtt-plus-base.js +34 -4
  10. package/dst-stage1/mqtt-plus-codec.js +15 -6
  11. package/dst-stage1/mqtt-plus-error.js +47 -14
  12. package/dst-stage1/mqtt-plus-event.js +1 -1
  13. package/dst-stage1/mqtt-plus-options.js +1 -3
  14. package/dst-stage1/mqtt-plus-service.js +1 -1
  15. package/dst-stage1/mqtt-plus-sink.js +10 -2
  16. package/dst-stage1/mqtt-plus-source.d.ts +1 -0
  17. package/dst-stage1/mqtt-plus-source.js +11 -3
  18. package/dst-stage1/mqtt-plus-subscription.js +7 -2
  19. package/dst-stage1/mqtt-plus-timer.js +4 -2
  20. package/dst-stage2/mqtt-plus.cjs.cjs +94 -36
  21. package/dst-stage2/mqtt-plus.esm.js +94 -36
  22. package/dst-stage2/mqtt-plus.umd.js +11 -11
  23. package/package.json +1 -1
  24. package/src/mqtt-plus-api.ts +5 -5
  25. package/src/mqtt-plus-base.ts +35 -4
  26. package/src/mqtt-plus-codec.ts +15 -8
  27. package/src/mqtt-plus-error.ts +52 -14
  28. package/src/mqtt-plus-event.ts +1 -1
  29. package/src/mqtt-plus-options.ts +1 -4
  30. package/src/mqtt-plus-service.ts +1 -1
  31. package/src/mqtt-plus-sink.ts +12 -2
  32. package/src/mqtt-plus-source.ts +13 -3
  33. package/src/mqtt-plus-subscription.ts +7 -2
  34. package/src/mqtt-plus-timer.ts +4 -2
  35. package/tst/mqtt-plus-4-sink.spec.ts +43 -0
  36. package/tst/mqtt-plus-5-source.spec.ts +35 -0
  37. package/tst/mqtt-plus-6-misc.spec.ts +82 -5
  38. package/tst/mqtt-plus-8-run.spec.ts +107 -0
  39. package/.ase/service.yaml +0 -1
@@ -81,6 +81,23 @@ describe("MQTT+ Run", function () {
81
81
  }
82
82
  })
83
83
 
84
+ /* test case: MQTT+ Run: async oncatch recovers but onfinally fails invokes onfinally once */
85
+ it("MQTT+ Run: async oncatch recovers but onfinally fails invokes onfinally once", async function () {
86
+ let finallyCount = 0
87
+ try {
88
+ await run(
89
+ () => Promise.reject(new Error("async-fail")),
90
+ (_err: Error) => Promise.resolve("async-recovered"),
91
+ async () => { finallyCount++; throw new Error("onfinally-fail") }
92
+ )
93
+ expect.fail("should have thrown")
94
+ }
95
+ catch (err: any) {
96
+ expect(err.message).to.match(/onfinally-fail/)
97
+ }
98
+ expect(finallyCount).to.equal(1)
99
+ })
100
+
84
101
  /* test case: MQTT+ Run: sync success with spool and oncleanup */
85
102
  it("MQTT+ Run: sync success with spool and oncleanup", function () {
86
103
  const spool = new Spool()
@@ -96,6 +113,36 @@ describe("MQTT+ Run", function () {
96
113
  expect(cleanups).to.deep.equal([ "resource-val" ])
97
114
  })
98
115
 
116
+ /* test case: MQTT+ Run: sync oncatch recovery with spool and oncleanup */
117
+ it("MQTT+ Run: sync oncatch recovery with spool and oncleanup", function () {
118
+ const spool = new Spool()
119
+ const cleanups: string[] = []
120
+ run<string, string>(
121
+ spool,
122
+ () => { throw new Error("fail") },
123
+ (_err: Error) => "recovered-val",
124
+ undefined,
125
+ (val: string) => { cleanups.push(val) }
126
+ )
127
+ spool.unroll()
128
+ expect(cleanups).to.deep.equal([ "recovered-val" ])
129
+ })
130
+
131
+ /* test case: MQTT+ Run: async oncatch recovery with spool and oncleanup */
132
+ it("MQTT+ Run: async oncatch recovery with spool and oncleanup", async function () {
133
+ const spool = new Spool()
134
+ const cleanups: string[] = []
135
+ await run<string, Promise<string>>(
136
+ spool,
137
+ () => Promise.reject(new Error("async-fail")),
138
+ (_err: Error) => Promise.resolve("async-recovered-val"),
139
+ undefined,
140
+ async (val: string) => { cleanups.push(val) }
141
+ )
142
+ await spool.unroll()
143
+ expect(cleanups).to.deep.equal([ "async-recovered-val" ])
144
+ })
145
+
99
146
  /* test case: MQTT+ Run: oncleanup without spool throws */
100
147
  it("MQTT+ Run: oncleanup without spool throws", function () {
101
148
  try {
@@ -111,5 +158,65 @@ describe("MQTT+ Run", function () {
111
158
  expect(err.message).to.equal("oncleanup requires a spool")
112
159
  }
113
160
  })
161
+
162
+ /* test case: MQTT+ Run: sync error with throwing onfinally still unrolls and preserves error */
163
+ it("MQTT+ Run: sync error with throwing onfinally still unrolls and preserves error", function () {
164
+ const spool = new Spool()
165
+ const cleanups: string[] = []
166
+ spool.roll("res", (val: unknown) => { cleanups.push(val as string) })
167
+ try {
168
+ run<string, string>(
169
+ spool,
170
+ () => { throw new Error("action-fail") },
171
+ undefined,
172
+ () => { throw new Error("finally-fail") }
173
+ )
174
+ expect.fail("should have thrown")
175
+ }
176
+ catch (err: any) {
177
+ expect(err.message).to.match(/action-fail/)
178
+ }
179
+ expect(cleanups).to.deep.equal([ "res" ])
180
+ })
181
+
182
+ /* test case: MQTT+ Run: async error with rejecting onfinally still unrolls and preserves error */
183
+ it("MQTT+ Run: async error with rejecting onfinally still unrolls and preserves error", async function () {
184
+ const spool = new Spool()
185
+ const cleanups: string[] = []
186
+ spool.roll("res", (val: unknown) => { cleanups.push(val as string) })
187
+ try {
188
+ await run<string, Promise<string>>(
189
+ spool,
190
+ () => Promise.reject(new Error("async-action-fail")),
191
+ undefined,
192
+ () => Promise.reject(new Error("async-finally-fail"))
193
+ )
194
+ expect.fail("should have thrown")
195
+ }
196
+ catch (err: any) {
197
+ expect(err.message).to.match(/async-action-fail/)
198
+ }
199
+ expect(cleanups).to.deep.equal([ "res" ])
200
+ })
201
+
202
+ /* test case: MQTT+ Run: async success with rejecting onfinally surfaces onfinally error but still cleans up */
203
+ it("MQTT+ Run: async success with rejecting onfinally surfaces onfinally error but still cleans up", async function () {
204
+ const spool = new Spool()
205
+ const cleanups: string[] = []
206
+ try {
207
+ await run<string, Promise<string>>(
208
+ spool,
209
+ () => Promise.resolve("resource-val"),
210
+ undefined,
211
+ () => Promise.reject(new Error("finally-fail")),
212
+ async (val: string) => { cleanups.push(val) }
213
+ )
214
+ expect.fail("should have thrown")
215
+ }
216
+ catch (err: any) {
217
+ expect(err.message).to.match(/finally-fail/)
218
+ }
219
+ expect(cleanups).to.deep.equal([ "resource-val" ])
220
+ })
114
221
  })
115
222
 
package/.ase/service.yaml DELETED
@@ -1 +0,0 @@
1
- port: 42082