@fedify/postgres 2.4.0-pr.936.41 → 2.4.0
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 +9 -0
- package/dist/kv.cjs +107 -18
- package/dist/kv.d.cts +16 -0
- package/dist/kv.d.ts +16 -0
- package/dist/kv.js +103 -16
- package/dist/mq.cjs +27 -16
- package/dist/mq.d.cts +5 -0
- package/dist/mq.d.ts +5 -0
- package/dist/mq.js +26 -15
- package/dist/node_modules/.pnpm/temporal-polyfill@1.0.1/node_modules/temporal-polyfill/chunks/apiHelpers.cjs +3 -3
- package/dist/node_modules/.pnpm/temporal-polyfill@1.0.1/node_modules/temporal-polyfill/chunks/classApi-basic.cjs +23 -23
- package/dist/node_modules/.pnpm/temporal-polyfill@1.0.1/node_modules/temporal-polyfill/chunks/internal.cjs +154 -84
- package/dist/node_modules/.pnpm/temporal-utils@1.0.1/node_modules/temporal-utils/dist/utils.cjs +1 -0
- package/package.json +3 -3
package/dist/mq.js
CHANGED
|
@@ -52,12 +52,14 @@ function getCreatedIndexName(tableName) {
|
|
|
52
52
|
* ```
|
|
53
53
|
*/
|
|
54
54
|
var PostgresMessageQueue = class {
|
|
55
|
+
atomicEnqueueMany = false;
|
|
55
56
|
#sql;
|
|
56
57
|
#tableName;
|
|
57
58
|
#channelName;
|
|
58
59
|
#pollIntervalMs;
|
|
59
60
|
#handlerTimeoutMs;
|
|
60
|
-
#
|
|
61
|
+
#skipDdl;
|
|
62
|
+
#initialized = false;
|
|
61
63
|
#initPromise;
|
|
62
64
|
#driverSerializesJson = false;
|
|
63
65
|
constructor(sql, options = {}) {
|
|
@@ -66,7 +68,7 @@ var PostgresMessageQueue = class {
|
|
|
66
68
|
this.#channelName = options?.channelName ?? "fedify_channel";
|
|
67
69
|
this.#pollIntervalMs = Temporal.Duration.from(options?.pollInterval ?? { seconds: 5 }).total("millisecond");
|
|
68
70
|
this.#handlerTimeoutMs = Temporal.Duration.from(options?.handlerTimeout ?? { seconds: 60 }).total("millisecond");
|
|
69
|
-
this.#
|
|
71
|
+
this.#skipDdl = options?.initialized ?? false;
|
|
70
72
|
}
|
|
71
73
|
async enqueue(message, options) {
|
|
72
74
|
await this.initialize();
|
|
@@ -154,6 +156,7 @@ var PostgresMessageQueue = class {
|
|
|
154
156
|
async listen(handler, options = {}) {
|
|
155
157
|
await this.initialize();
|
|
156
158
|
const { signal } = options;
|
|
159
|
+
if (signal?.aborted) return;
|
|
157
160
|
const poll = async () => {
|
|
158
161
|
while (!signal?.aborted) {
|
|
159
162
|
let processed = false;
|
|
@@ -247,6 +250,7 @@ var PostgresMessageQueue = class {
|
|
|
247
250
|
};
|
|
248
251
|
const timeouts = /* @__PURE__ */ new Set();
|
|
249
252
|
const listen = await this.#sql.listen(this.#channelName, async (delay) => {
|
|
253
|
+
if (signal?.aborted) return;
|
|
250
254
|
try {
|
|
251
255
|
const durationMs = Temporal.Duration.from(delay).total("millisecond");
|
|
252
256
|
if (durationMs < 1) await safeSerializedPoll("notify-immediate");
|
|
@@ -270,31 +274,35 @@ var PostgresMessageQueue = class {
|
|
|
270
274
|
timeouts.clear();
|
|
271
275
|
};
|
|
272
276
|
signal?.addEventListener("abort", clearTimeouts, { once: true });
|
|
273
|
-
let unlistenError;
|
|
274
277
|
try {
|
|
275
278
|
while (!signal?.aborted) {
|
|
276
|
-
let timeout;
|
|
277
279
|
await new Promise((resolve) => {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
signal?.removeEventListener("abort",
|
|
281
|
-
resolve(
|
|
280
|
+
const onAbort = () => {
|
|
281
|
+
clearTimeout(timeout);
|
|
282
|
+
signal?.removeEventListener("abort", onAbort);
|
|
283
|
+
resolve();
|
|
284
|
+
};
|
|
285
|
+
const timeout = setTimeout(() => {
|
|
286
|
+
signal?.removeEventListener("abort", onAbort);
|
|
287
|
+
resolve();
|
|
282
288
|
}, this.#pollIntervalMs);
|
|
283
|
-
|
|
289
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
284
290
|
});
|
|
285
|
-
if (timeout != null) timeouts.delete(timeout);
|
|
286
291
|
await safeSerializedPoll("interval");
|
|
287
292
|
}
|
|
288
293
|
} finally {
|
|
289
294
|
signal?.removeEventListener("abort", clearTimeouts);
|
|
290
295
|
clearTimeouts();
|
|
296
|
+
await pollLock;
|
|
291
297
|
try {
|
|
292
298
|
await listen.unlisten();
|
|
293
299
|
} catch (error) {
|
|
294
|
-
if (!isConnectionDestroyedError(error))
|
|
300
|
+
if (!isConnectionDestroyedError(error)) logger.error("Error while unlistening from channel {channelName}: {error}", {
|
|
301
|
+
channelName: this.#channelName,
|
|
302
|
+
error
|
|
303
|
+
});
|
|
295
304
|
}
|
|
296
305
|
}
|
|
297
|
-
if (unlistenError != null) throw unlistenError;
|
|
298
306
|
}
|
|
299
307
|
/**
|
|
300
308
|
* Initializes the message queue table if it does not already exist.
|
|
@@ -305,6 +313,12 @@ var PostgresMessageQueue = class {
|
|
|
305
313
|
}
|
|
306
314
|
async #doInitialize() {
|
|
307
315
|
logger.debug("Initializing the message queue table {tableName}...", { tableName: this.#tableName });
|
|
316
|
+
if (!this.#skipDdl) await this.#initializeTable();
|
|
317
|
+
this.#driverSerializesJson = await driverSerializesJson(this.#sql);
|
|
318
|
+
this.#initialized = true;
|
|
319
|
+
logger.debug("Initialized the message queue table {tableName}.", { tableName: this.#tableName });
|
|
320
|
+
}
|
|
321
|
+
async #initializeTable() {
|
|
308
322
|
for (let attempt = 1; attempt <= INITIALIZE_MAX_ATTEMPTS; attempt++) try {
|
|
309
323
|
await this.#sql`
|
|
310
324
|
CREATE TABLE IF NOT EXISTS ${this.#sql(this.#tableName)} (
|
|
@@ -339,9 +353,6 @@ var PostgresMessageQueue = class {
|
|
|
339
353
|
});
|
|
340
354
|
await sleep(backoffMs);
|
|
341
355
|
}
|
|
342
|
-
this.#driverSerializesJson = await driverSerializesJson(this.#sql);
|
|
343
|
-
this.#initialized = true;
|
|
344
|
-
logger.debug("Initialized the message queue table {tableName}.", { tableName: this.#tableName });
|
|
345
356
|
}
|
|
346
357
|
/**
|
|
347
358
|
* Drops the message queue table if it exists.
|
|
@@ -134,10 +134,10 @@ exports.PlainYearMonthBranding = PlainYearMonthBranding;
|
|
|
134
134
|
exports.ZonedDateTimeBranding = ZonedDateTimeBranding;
|
|
135
135
|
exports.attachDebugString = attachDebugString;
|
|
136
136
|
exports.dateDerivedGetters = dateDerivedGetters;
|
|
137
|
-
exports.dateFieldGetters
|
|
137
|
+
exports.dateFieldGetters = dateFieldGetters$1;
|
|
138
138
|
exports.defineTemporalClass = defineTemporalClass;
|
|
139
139
|
exports.forbiddenValueOf = forbiddenValueOf;
|
|
140
140
|
exports.invalidRecordType = invalidRecordType;
|
|
141
|
-
exports.monthDayFieldGetters
|
|
141
|
+
exports.monthDayFieldGetters = monthDayFieldGetters$1;
|
|
142
142
|
exports.yearMonthDerivedGetters = yearMonthDerivedGetters;
|
|
143
|
-
exports.yearMonthFieldGetters
|
|
143
|
+
exports.yearMonthFieldGetters = yearMonthFieldGetters$1;
|
|
@@ -10,8 +10,8 @@ function resolveBasicCalendarId(rawCalendarId) {
|
|
|
10
10
|
function resolveBasicCalendarArg(rawCalendarId = require_internal.isoCalendarId) {
|
|
11
11
|
return resolveBasicCalendarId(rawCalendarId);
|
|
12
12
|
}
|
|
13
|
-
const zonedDateTimeSlotsMap =
|
|
14
|
-
const ZonedDateTime =
|
|
13
|
+
const zonedDateTimeSlotsMap = /*@__PURE__*/ new WeakMap();
|
|
14
|
+
const ZonedDateTime = /*@__PURE__*/ require_apiHelpers.defineTemporalClass(require_apiHelpers.ZonedDateTimeBranding, class {
|
|
15
15
|
constructor(epochNanoseconds, timeZoneId, calendar = void 0) {
|
|
16
16
|
const epochNano = require_internal.checkEpochNanoInBounds(require_internal.toBigInt(epochNanoseconds));
|
|
17
17
|
const timeZone = require_internal.queryTimeZone(require_internal.refineTimeZoneId(timeZoneId));
|
|
@@ -124,7 +124,7 @@ const ZonedDateTime = /* @__PURE__ */ require_apiHelpers.defineTemporalClass(req
|
|
|
124
124
|
valueOf() {
|
|
125
125
|
return require_apiHelpers.forbiddenValueOf();
|
|
126
126
|
}
|
|
127
|
-
}, getZonedDateTimeIsoSlots, require_apiHelpers.dateFieldGetters
|
|
127
|
+
}, getZonedDateTimeIsoSlots, require_apiHelpers.dateFieldGetters, require_apiHelpers.dateDerivedGetters, require_internal.timeGetters);
|
|
128
128
|
function createZonedDateTime(slots) {
|
|
129
129
|
return initZonedDateTime(Object.create(ZonedDateTime.prototype), slots);
|
|
130
130
|
}
|
|
@@ -159,8 +159,8 @@ function refineTimeZoneArg(arg) {
|
|
|
159
159
|
}
|
|
160
160
|
return ((arg) => require_internal.resolveTimeZoneId(require_internal.parseTimeZoneId(require_internal.requireString(arg))))(arg);
|
|
161
161
|
}
|
|
162
|
-
const instantSlotsMap =
|
|
163
|
-
const Instant =
|
|
162
|
+
const instantSlotsMap = /*@__PURE__*/ new WeakMap();
|
|
163
|
+
const Instant = /*@__PURE__*/ require_apiHelpers.defineTemporalClass(require_apiHelpers.InstantBranding, class {
|
|
164
164
|
constructor(epochNanoseconds) {
|
|
165
165
|
const epochNano = require_internal.checkEpochNanoInBounds(require_internal.toBigInt(epochNanoseconds));
|
|
166
166
|
initInstant(this, require_internal.createEpochNanoSlots(epochNano));
|
|
@@ -245,8 +245,8 @@ const { toTemporalInstant } = { toTemporalInstant() {
|
|
|
245
245
|
function initInstant(instance, slots) {
|
|
246
246
|
return instantSlotsMap.set(instance, slots), require_apiHelpers.attachDebugString(instance), instance;
|
|
247
247
|
}
|
|
248
|
-
const plainMonthDaySlotsMap =
|
|
249
|
-
const PlainMonthDay =
|
|
248
|
+
const plainMonthDaySlotsMap = /*@__PURE__*/ new WeakMap();
|
|
249
|
+
const PlainMonthDay = /*@__PURE__*/ require_apiHelpers.defineTemporalClass(require_apiHelpers.PlainMonthDayBranding, class {
|
|
250
250
|
constructor(isoMonth, isoDay, calendar = void 0, referenceIsoYear) {
|
|
251
251
|
const isoMonthInt = require_utils.toIntegerWithTrunc(isoMonth);
|
|
252
252
|
const isoDayInt = require_utils.toIntegerWithTrunc(isoDay);
|
|
@@ -287,7 +287,7 @@ const PlainMonthDay = /* @__PURE__ */ require_apiHelpers.defineTemporalClass(req
|
|
|
287
287
|
valueOf() {
|
|
288
288
|
return require_apiHelpers.forbiddenValueOf();
|
|
289
289
|
}
|
|
290
|
-
}, getPlainMonthDaySlots, require_apiHelpers.monthDayFieldGetters
|
|
290
|
+
}, getPlainMonthDaySlots, require_apiHelpers.monthDayFieldGetters);
|
|
291
291
|
function createPlainMonthDay(slots) {
|
|
292
292
|
return initPlainMonthDay(Object.create(PlainMonthDay.prototype), slots);
|
|
293
293
|
}
|
|
@@ -310,8 +310,8 @@ function toPlainMonthDaySlots(arg, options) {
|
|
|
310
310
|
function initPlainMonthDay(instance, slots) {
|
|
311
311
|
return plainMonthDaySlotsMap.set(instance, slots), require_apiHelpers.attachDebugString(instance), instance;
|
|
312
312
|
}
|
|
313
|
-
const plainYearMonthSlotsMap =
|
|
314
|
-
const PlainYearMonth =
|
|
313
|
+
const plainYearMonthSlotsMap = /*@__PURE__*/ new WeakMap();
|
|
314
|
+
const PlainYearMonth = /*@__PURE__*/ require_apiHelpers.defineTemporalClass(require_apiHelpers.PlainYearMonthBranding, class {
|
|
315
315
|
constructor(isoYear, isoMonth, calendar = void 0, referenceIsoDay) {
|
|
316
316
|
const isoYearInt = require_utils.toIntegerWithTrunc(isoYear);
|
|
317
317
|
const isoMonthInt = require_utils.toIntegerWithTrunc(isoMonth);
|
|
@@ -373,7 +373,7 @@ const PlainYearMonth = /* @__PURE__ */ require_apiHelpers.defineTemporalClass(re
|
|
|
373
373
|
valueOf() {
|
|
374
374
|
return require_apiHelpers.forbiddenValueOf();
|
|
375
375
|
}
|
|
376
|
-
}, getPlainYearMonthSlots, require_apiHelpers.yearMonthFieldGetters
|
|
376
|
+
}, getPlainYearMonthSlots, require_apiHelpers.yearMonthFieldGetters, require_apiHelpers.yearMonthDerivedGetters);
|
|
377
377
|
function createPlainYearMonth(slots) {
|
|
378
378
|
return initPlainYearMonth(Object.create(PlainYearMonth.prototype), slots);
|
|
379
379
|
}
|
|
@@ -403,8 +403,8 @@ function getTemporalBrandingAndSlots(obj) {
|
|
|
403
403
|
function validateBag(bag) {
|
|
404
404
|
return (getTemporalBrandingAndSlots(bag) || void 0 !== bag.calendar || void 0 !== bag.timeZone) && require_internal.throwTypeError("Invalid bag"), bag;
|
|
405
405
|
}
|
|
406
|
-
const plainTimeSlotsMap =
|
|
407
|
-
const PlainTime =
|
|
406
|
+
const plainTimeSlotsMap = /*@__PURE__*/ new WeakMap();
|
|
407
|
+
const PlainTime = /*@__PURE__*/ require_apiHelpers.defineTemporalClass(require_apiHelpers.PlainTimeBranding, class {
|
|
408
408
|
constructor(hour = 0, minute = 0, second = 0, millisecond = 0, microsecond = 0, nanosecond = 0) {
|
|
409
409
|
const fields = require_internal.validateTimeFields(require_internal.mapProps(require_utils.toIntegerWithTrunc, {
|
|
410
410
|
hour,
|
|
@@ -486,8 +486,8 @@ function optionalToPlainTimeFields(timeArg) {
|
|
|
486
486
|
function initPlainTime(instance, slots) {
|
|
487
487
|
return plainTimeSlotsMap.set(instance, slots), require_apiHelpers.attachDebugString(instance), instance;
|
|
488
488
|
}
|
|
489
|
-
const plainDateTimeSlotsMap =
|
|
490
|
-
const PlainDateTime =
|
|
489
|
+
const plainDateTimeSlotsMap = /*@__PURE__*/ new WeakMap();
|
|
490
|
+
const PlainDateTime = /*@__PURE__*/ require_apiHelpers.defineTemporalClass(require_apiHelpers.PlainDateTimeBranding, class {
|
|
491
491
|
constructor(isoYear, isoMonth, isoDay, hour = 0, minute = 0, second = 0, millisecond = 0, microsecond = 0, nanosecond = 0, calendar = void 0) {
|
|
492
492
|
const fields = require_internal.checkIsoDateTimeInBounds(require_internal.validateIsoDateTimeFields(require_internal.mapProps(require_utils.toIntegerWithTrunc, {
|
|
493
493
|
year: isoYear,
|
|
@@ -572,7 +572,7 @@ const PlainDateTime = /* @__PURE__ */ require_apiHelpers.defineTemporalClass(req
|
|
|
572
572
|
valueOf() {
|
|
573
573
|
return require_apiHelpers.forbiddenValueOf();
|
|
574
574
|
}
|
|
575
|
-
}, getPlainDateTimeSlots, require_apiHelpers.dateFieldGetters
|
|
575
|
+
}, getPlainDateTimeSlots, require_apiHelpers.dateFieldGetters, require_apiHelpers.dateDerivedGetters, require_internal.timeGetters);
|
|
576
576
|
function createPlainDateTime(slots) {
|
|
577
577
|
return initPlainDateTime(Object.create(PlainDateTime.prototype), slots);
|
|
578
578
|
}
|
|
@@ -598,8 +598,8 @@ function toPlainDateTimeSlots(arg, options) {
|
|
|
598
598
|
function initPlainDateTime(instance, slots) {
|
|
599
599
|
return plainDateTimeSlotsMap.set(instance, slots), require_apiHelpers.attachDebugString(instance), instance;
|
|
600
600
|
}
|
|
601
|
-
const plainDateSlotsMap =
|
|
602
|
-
const PlainDate =
|
|
601
|
+
const plainDateSlotsMap = /*@__PURE__*/ new WeakMap();
|
|
602
|
+
const PlainDate = /*@__PURE__*/ require_apiHelpers.defineTemporalClass(require_apiHelpers.PlainDateBranding, class {
|
|
603
603
|
constructor(isoYear, isoMonth, isoDay, calendar = void 0) {
|
|
604
604
|
const fields = require_internal.checkIsoDateInBounds(require_internal.validateIsoDateFields(require_internal.mapProps(require_utils.toIntegerWithTrunc, {
|
|
605
605
|
year: isoYear,
|
|
@@ -676,7 +676,7 @@ const PlainDate = /* @__PURE__ */ require_apiHelpers.defineTemporalClass(require
|
|
|
676
676
|
valueOf() {
|
|
677
677
|
return require_apiHelpers.forbiddenValueOf();
|
|
678
678
|
}
|
|
679
|
-
}, getPlainDateSlots, require_apiHelpers.dateFieldGetters
|
|
679
|
+
}, getPlainDateSlots, require_apiHelpers.dateFieldGetters, require_apiHelpers.dateDerivedGetters);
|
|
680
680
|
function createPlainDate(slots) {
|
|
681
681
|
return initPlainDate(Object.create(PlainDate.prototype), slots);
|
|
682
682
|
}
|
|
@@ -717,8 +717,8 @@ function refineCalendarArg(arg) {
|
|
|
717
717
|
}
|
|
718
718
|
return ((arg) => resolveBasicCalendarId(require_internal.parseCalendarId(require_internal.requireString(arg))))(arg);
|
|
719
719
|
}
|
|
720
|
-
const durationSlotsMap =
|
|
721
|
-
const Duration =
|
|
720
|
+
const durationSlotsMap = /*@__PURE__*/ new WeakMap();
|
|
721
|
+
const Duration = /*@__PURE__*/ require_apiHelpers.defineTemporalClass(require_apiHelpers.DurationBranding, class {
|
|
722
722
|
constructor(years = 0, months = 0, weeks = 0, days = 0, hours = 0, minutes = 0, seconds = 0, milliseconds = 0, microseconds = 0, nanoseconds = 0) {
|
|
723
723
|
const fields = require_internal.validateDurationFields(require_internal.mapProps(require_internal.toStrictInteger, {
|
|
724
724
|
years,
|
|
@@ -811,7 +811,7 @@ function refinePublicRelativeTo(relativeTo) {
|
|
|
811
811
|
function initDuration(instance, slots) {
|
|
812
812
|
return durationSlotsMap.set(instance, slots), require_apiHelpers.attachDebugString(instance), instance;
|
|
813
813
|
}
|
|
814
|
-
const Now =
|
|
814
|
+
const Now = /*@__PURE__*/ Object.defineProperties({}, {
|
|
815
815
|
...require_internal.createStringTagDescriptors("Temporal.Now"),
|
|
816
816
|
...require_internal.createPropDescriptors({
|
|
817
817
|
timeZoneId() {
|
|
@@ -835,7 +835,7 @@ const Now = /* @__PURE__ */ Object.defineProperties({}, {
|
|
|
835
835
|
}
|
|
836
836
|
})
|
|
837
837
|
});
|
|
838
|
-
const Temporal =
|
|
838
|
+
const Temporal = /*@__PURE__*/ Object.defineProperties({}, {
|
|
839
839
|
...require_internal.createStringTagDescriptors("Temporal"),
|
|
840
840
|
...require_internal.createPropDescriptors({
|
|
841
841
|
PlainYearMonth,
|