mppx 0.5.12 → 0.5.14
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/CHANGELOG.md +16 -0
- package/dist/server/internal/html/config.d.ts.map +1 -1
- package/dist/server/internal/html/config.js +8 -1
- package/dist/server/internal/html/config.js.map +1 -1
- package/dist/tempo/Methods.d.ts +8 -0
- package/dist/tempo/Methods.d.ts.map +1 -1
- package/dist/tempo/Methods.js +6 -2
- package/dist/tempo/Methods.js.map +1 -1
- package/dist/tempo/client/Charge.d.ts +11 -1
- package/dist/tempo/client/Charge.d.ts.map +1 -1
- package/dist/tempo/client/Charge.js +14 -2
- package/dist/tempo/client/Charge.js.map +1 -1
- package/dist/tempo/client/Methods.d.ts +6 -0
- package/dist/tempo/client/Methods.d.ts.map +1 -1
- package/dist/tempo/internal/fee-payer.d.ts +8 -0
- package/dist/tempo/internal/fee-payer.d.ts.map +1 -1
- package/dist/tempo/internal/fee-payer.js +31 -4
- package/dist/tempo/internal/fee-payer.js.map +1 -1
- package/dist/tempo/server/Charge.d.ts +17 -0
- package/dist/tempo/server/Charge.d.ts.map +1 -1
- package/dist/tempo/server/Charge.js +13 -1
- package/dist/tempo/server/Charge.js.map +1 -1
- package/dist/tempo/server/Methods.d.ts +6 -0
- package/dist/tempo/server/Methods.d.ts.map +1 -1
- package/dist/tempo/server/Session.d.ts +4 -0
- package/dist/tempo/server/Session.d.ts.map +1 -1
- package/dist/tempo/server/Session.js +36 -28
- package/dist/tempo/server/Session.js.map +1 -1
- package/dist/tempo/server/internal/html.gen.d.ts +1 -1
- package/dist/tempo/server/internal/html.gen.d.ts.map +1 -1
- package/dist/tempo/server/internal/html.gen.js +1 -1
- package/dist/tempo/server/internal/html.gen.js.map +1 -1
- package/dist/tempo/session/Chain.d.ts +5 -0
- package/dist/tempo/session/Chain.d.ts.map +1 -1
- package/dist/tempo/session/Chain.js +202 -63
- package/dist/tempo/session/Chain.js.map +1 -1
- package/dist/tempo/session/ChannelStore.d.ts +1 -0
- package/dist/tempo/session/ChannelStore.d.ts.map +1 -1
- package/dist/tempo/session/ChannelStore.js +38 -15
- package/dist/tempo/session/ChannelStore.js.map +1 -1
- package/package.json +2 -2
- package/src/server/Transport.test.ts +20 -0
- package/src/server/internal/html/config.ts +9 -1
- package/src/tempo/Methods.test.ts +25 -0
- package/src/tempo/Methods.ts +30 -22
- package/src/tempo/client/Charge.ts +20 -6
- package/src/tempo/internal/fee-payer.test.ts +122 -12
- package/src/tempo/internal/fee-payer.ts +49 -4
- package/src/tempo/server/Charge.test.ts +259 -1
- package/src/tempo/server/Charge.ts +31 -0
- package/src/tempo/server/Session.test.ts +130 -1
- package/src/tempo/server/Session.ts +41 -35
- package/src/tempo/server/internal/html/main.ts +2 -2
- package/src/tempo/server/internal/html.gen.ts +1 -1
- package/src/tempo/session/Chain.test.ts +225 -2
- package/src/tempo/session/Chain.ts +250 -65
- package/src/tempo/session/ChannelStore.test.ts +23 -0
- package/src/tempo/session/ChannelStore.ts +46 -13
|
@@ -109,6 +109,18 @@ export type ChannelStore = {
|
|
|
109
109
|
|
|
110
110
|
export type DeductResult = { ok: true; channel: State } | { ok: false; channel: State }
|
|
111
111
|
|
|
112
|
+
export function normalizeChannelId(channelId: Hex): Hex {
|
|
113
|
+
return channelId.toLowerCase() as Hex
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function normalizeState(channelId: Hex, state: State): State {
|
|
117
|
+
return state.channelId === channelId ? state : { ...state, channelId }
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function normalizeMaybeState(channelId: Hex, state: State | null): State | null {
|
|
121
|
+
return state ? normalizeState(channelId, state) : null
|
|
122
|
+
}
|
|
123
|
+
|
|
112
124
|
/**
|
|
113
125
|
* Atomically deduct `amount` from a channel's available balance.
|
|
114
126
|
*
|
|
@@ -208,54 +220,75 @@ export function fromStore(store: Store.Store | Store.AtomicStore): ChannelStore
|
|
|
208
220
|
channelId: Hex,
|
|
209
221
|
fn: (current: State | null) => Store.Change<State, result>,
|
|
210
222
|
): Promise<result> {
|
|
223
|
+
const normalizedChannelId = normalizeChannelId(channelId)
|
|
211
224
|
let change: Store.Change<State, result> | undefined
|
|
212
225
|
|
|
213
226
|
if (atomicUpdate) {
|
|
214
|
-
const result = await atomicUpdate(
|
|
215
|
-
change = fn((current as State | null) ?? null)
|
|
227
|
+
const result = await atomicUpdate(normalizedChannelId, (current) => {
|
|
228
|
+
change = fn(normalizeMaybeState(normalizedChannelId, (current as State | null) ?? null))
|
|
229
|
+
if (change.op === 'set') {
|
|
230
|
+
change = {
|
|
231
|
+
...change,
|
|
232
|
+
value: normalizeState(normalizedChannelId, change.value),
|
|
233
|
+
}
|
|
234
|
+
}
|
|
216
235
|
if (change.op !== 'set') return change
|
|
217
236
|
return { ...change, value: change.value as never }
|
|
218
237
|
})
|
|
219
|
-
if (change?.op !== 'noop') notify(
|
|
238
|
+
if (change?.op !== 'noop') notify(normalizedChannelId)
|
|
220
239
|
return result
|
|
221
240
|
}
|
|
222
241
|
|
|
223
|
-
while (locks.has(
|
|
242
|
+
while (locks.has(normalizedChannelId)) await locks.get(normalizedChannelId)
|
|
224
243
|
|
|
225
244
|
let release!: () => void
|
|
226
245
|
locks.set(
|
|
227
|
-
|
|
246
|
+
normalizedChannelId,
|
|
228
247
|
new Promise<void>((r) => {
|
|
229
248
|
release = r
|
|
230
249
|
}),
|
|
231
250
|
)
|
|
232
251
|
|
|
233
252
|
try {
|
|
234
|
-
const current = (
|
|
253
|
+
const current = normalizeMaybeState(
|
|
254
|
+
normalizedChannelId,
|
|
255
|
+
(await store.get(normalizedChannelId)) as State | null,
|
|
256
|
+
)
|
|
235
257
|
change = fn(current)
|
|
236
|
-
if (change.op === 'set')
|
|
237
|
-
|
|
238
|
-
|
|
258
|
+
if (change.op === 'set') {
|
|
259
|
+
change = {
|
|
260
|
+
...change,
|
|
261
|
+
value: normalizeState(normalizedChannelId, change.value),
|
|
262
|
+
}
|
|
263
|
+
await store.put(normalizedChannelId, change.value as never)
|
|
264
|
+
}
|
|
265
|
+
if (change.op === 'delete') await store.delete(normalizedChannelId)
|
|
266
|
+
if (change.op !== 'noop') notify(normalizedChannelId)
|
|
239
267
|
return change.result
|
|
240
268
|
} finally {
|
|
241
|
-
locks.delete(
|
|
269
|
+
locks.delete(normalizedChannelId)
|
|
242
270
|
release()
|
|
243
271
|
}
|
|
244
272
|
}
|
|
245
273
|
|
|
246
274
|
const cs: ChannelStore = {
|
|
247
275
|
async getChannel(channelId) {
|
|
248
|
-
|
|
276
|
+
const normalizedChannelId = normalizeChannelId(channelId)
|
|
277
|
+
return normalizeMaybeState(
|
|
278
|
+
normalizedChannelId,
|
|
279
|
+
(await store.get(normalizedChannelId)) as State | null,
|
|
280
|
+
)
|
|
249
281
|
},
|
|
250
282
|
async updateChannel(channelId, fn) {
|
|
251
283
|
return update(channelId, fn)
|
|
252
284
|
},
|
|
253
285
|
waitForUpdate(channelId) {
|
|
254
286
|
return new Promise<void>((resolve) => {
|
|
255
|
-
|
|
287
|
+
const normalizedChannelId = normalizeChannelId(channelId)
|
|
288
|
+
let set = waiters.get(normalizedChannelId)
|
|
256
289
|
if (!set) {
|
|
257
290
|
set = new Set()
|
|
258
|
-
waiters.set(
|
|
291
|
+
waiters.set(normalizedChannelId, set)
|
|
259
292
|
}
|
|
260
293
|
set.add(resolve)
|
|
261
294
|
})
|