@fedify/postgres 0.1.0 → 0.2.1
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 +19 -0
- package/esm/src/kv.js +7 -3
- package/esm/src/mq.js +16 -13
- package/package.json +2 -2
- package/script/src/kv.js +7 -3
- package/script/src/mq.js +16 -13
- package/types/src/kv.d.ts +3 -2
- package/types/src/kv.d.ts.map +1 -1
- package/types/src/mq.d.ts +2 -2
- package/types/src/mq.d.ts.map +1 -1
package/README.md
CHANGED
|
@@ -64,6 +64,25 @@ bun add @fedify/postgres
|
|
|
64
64
|
Changelog
|
|
65
65
|
---------
|
|
66
66
|
|
|
67
|
+
### Version 0.2.1
|
|
68
|
+
|
|
69
|
+
Released on November 3, 2024.
|
|
70
|
+
|
|
71
|
+
- Fixed a bug where some scalar values have failed to be stored in the
|
|
72
|
+
database.
|
|
73
|
+
|
|
74
|
+
### Version 0.2.0
|
|
75
|
+
|
|
76
|
+
Released on November 3, 2024.
|
|
77
|
+
|
|
78
|
+
- Fixed a bug where JSON values are double-quoted in the database. Since it's
|
|
79
|
+
a breaking change data-wise, the default values of the following options
|
|
80
|
+
are also changed:
|
|
81
|
+
|
|
82
|
+
- `PostgresKvStoreOptions.tableName` defaults to `"fedify_kv_v2"`.
|
|
83
|
+
- `PostgresMessageQueueOptions.tableName` defaults to
|
|
84
|
+
`"fedify_message_v2"`.
|
|
85
|
+
|
|
67
86
|
### Version 0.1.0
|
|
68
87
|
|
|
69
88
|
Initial release. Released on September 26, 2024.
|
package/esm/src/kv.js
CHANGED
|
@@ -40,7 +40,7 @@ export class PostgresKvStore {
|
|
|
40
40
|
_PostgresKvStore_tableName.set(this, void 0);
|
|
41
41
|
_PostgresKvStore_initialized.set(this, void 0);
|
|
42
42
|
__classPrivateFieldSet(this, _PostgresKvStore_sql, sql, "f");
|
|
43
|
-
__classPrivateFieldSet(this, _PostgresKvStore_tableName, options.tableName ?? "
|
|
43
|
+
__classPrivateFieldSet(this, _PostgresKvStore_tableName, options.tableName ?? "fedify_kv_v2", "f");
|
|
44
44
|
__classPrivateFieldSet(this, _PostgresKvStore_initialized, options.initialized ?? false, "f");
|
|
45
45
|
}
|
|
46
46
|
async get(key) {
|
|
@@ -52,14 +52,18 @@ export class PostgresKvStore {
|
|
|
52
52
|
`;
|
|
53
53
|
if (result.length < 1)
|
|
54
54
|
return undefined;
|
|
55
|
-
return
|
|
55
|
+
return result[0].value;
|
|
56
56
|
}
|
|
57
57
|
async set(key, value, options) {
|
|
58
58
|
await this.initialize();
|
|
59
59
|
const ttl = options?.ttl == null ? null : options.ttl.toString();
|
|
60
60
|
await __classPrivateFieldGet(this, _PostgresKvStore_sql, "f").bind(this) `
|
|
61
61
|
INSERT INTO ${__classPrivateFieldGet(this, _PostgresKvStore_sql, "f").call(this, __classPrivateFieldGet(this, _PostgresKvStore_tableName, "f"))} (key, value, ttl)
|
|
62
|
-
VALUES (
|
|
62
|
+
VALUES (
|
|
63
|
+
${key},
|
|
64
|
+
(${{ value }}::jsonb) -> 'value',
|
|
65
|
+
${ttl}
|
|
66
|
+
)
|
|
63
67
|
ON CONFLICT (key)
|
|
64
68
|
DO UPDATE SET value = EXCLUDED.value, ttl = EXCLUDED.ttl;
|
|
65
69
|
`;
|
package/esm/src/mq.js
CHANGED
|
@@ -40,7 +40,7 @@ export class PostgresMessageQueue {
|
|
|
40
40
|
_PostgresMessageQueue_pollIntervalMs.set(this, void 0);
|
|
41
41
|
_PostgresMessageQueue_initialized.set(this, void 0);
|
|
42
42
|
__classPrivateFieldSet(this, _PostgresMessageQueue_sql, sql, "f");
|
|
43
|
-
__classPrivateFieldSet(this, _PostgresMessageQueue_tableName, options?.tableName ?? "
|
|
43
|
+
__classPrivateFieldSet(this, _PostgresMessageQueue_tableName, options?.tableName ?? "fedify_message_v2", "f");
|
|
44
44
|
__classPrivateFieldSet(this, _PostgresMessageQueue_channelName, options?.channelName ?? "fedify_channel", "f");
|
|
45
45
|
__classPrivateFieldSet(this, _PostgresMessageQueue_pollIntervalMs, dntShim.Temporal.Duration.from(options?.pollInterval ?? { seconds: 5 }).total("millisecond"), "f");
|
|
46
46
|
__classPrivateFieldSet(this, _PostgresMessageQueue_initialized, options?.initialized ?? false, "f");
|
|
@@ -52,7 +52,10 @@ export class PostgresMessageQueue {
|
|
|
52
52
|
const delay = options?.delay ?? dntShim.Temporal.Duration.from({ seconds: 0 });
|
|
53
53
|
await __classPrivateFieldGet(this, _PostgresMessageQueue_sql, "f").bind(this) `
|
|
54
54
|
INSERT INTO ${__classPrivateFieldGet(this, _PostgresMessageQueue_sql, "f").call(this, __classPrivateFieldGet(this, _PostgresMessageQueue_tableName, "f"))} (message, delay)
|
|
55
|
-
VALUES (
|
|
55
|
+
VALUES (
|
|
56
|
+
(${{ message }}::jsonb) -> 'message',
|
|
57
|
+
${delay.toString()}
|
|
58
|
+
);
|
|
56
59
|
`;
|
|
57
60
|
await __classPrivateFieldGet(this, _PostgresMessageQueue_sql, "f").notify(__classPrivateFieldGet(this, _PostgresMessageQueue_channelName, "f"), delay.toString());
|
|
58
61
|
}
|
|
@@ -64,23 +67,23 @@ export class PostgresMessageQueue {
|
|
|
64
67
|
const poll = async () => {
|
|
65
68
|
while (!signal?.aborted) {
|
|
66
69
|
const query = __classPrivateFieldGet(this, _PostgresMessageQueue_sql, "f").bind(this) `
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
70
|
+
DELETE FROM ${__classPrivateFieldGet(this, _PostgresMessageQueue_sql, "f").call(this, __classPrivateFieldGet(this, _PostgresMessageQueue_tableName, "f"))}
|
|
71
|
+
WHERE id = (
|
|
72
|
+
SELECT id
|
|
73
|
+
FROM ${__classPrivateFieldGet(this, _PostgresMessageQueue_sql, "f").call(this, __classPrivateFieldGet(this, _PostgresMessageQueue_tableName, "f"))}
|
|
74
|
+
WHERE created + delay < CURRENT_TIMESTAMP
|
|
75
|
+
ORDER BY created
|
|
76
|
+
LIMIT 1
|
|
77
|
+
)
|
|
78
|
+
RETURNING message;
|
|
79
|
+
`.execute();
|
|
77
80
|
const cancel = query.cancel.bind(query);
|
|
78
81
|
signal?.addEventListener("abort", cancel);
|
|
79
82
|
let i = 0;
|
|
80
83
|
for (const message of await query) {
|
|
81
84
|
if (signal?.aborted)
|
|
82
85
|
return;
|
|
83
|
-
await handler(
|
|
86
|
+
await handler(message.message);
|
|
84
87
|
i++;
|
|
85
88
|
}
|
|
86
89
|
signal?.removeEventListener("abort", cancel);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fedify/postgres",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "PostgreSQL drivers for Fedify",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fedify",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
],
|
|
62
62
|
"dependencies": {
|
|
63
63
|
"@fedify/fedify": "^1.0.0",
|
|
64
|
-
"postgres": "^3.4.
|
|
64
|
+
"postgres": "^3.4.5",
|
|
65
65
|
"@deno/shim-deno": "~0.18.0",
|
|
66
66
|
"@js-temporal/polyfill": "^0.4.4"
|
|
67
67
|
},
|
package/script/src/kv.js
CHANGED
|
@@ -43,7 +43,7 @@ class PostgresKvStore {
|
|
|
43
43
|
_PostgresKvStore_tableName.set(this, void 0);
|
|
44
44
|
_PostgresKvStore_initialized.set(this, void 0);
|
|
45
45
|
__classPrivateFieldSet(this, _PostgresKvStore_sql, sql, "f");
|
|
46
|
-
__classPrivateFieldSet(this, _PostgresKvStore_tableName, options.tableName ?? "
|
|
46
|
+
__classPrivateFieldSet(this, _PostgresKvStore_tableName, options.tableName ?? "fedify_kv_v2", "f");
|
|
47
47
|
__classPrivateFieldSet(this, _PostgresKvStore_initialized, options.initialized ?? false, "f");
|
|
48
48
|
}
|
|
49
49
|
async get(key) {
|
|
@@ -55,14 +55,18 @@ class PostgresKvStore {
|
|
|
55
55
|
`;
|
|
56
56
|
if (result.length < 1)
|
|
57
57
|
return undefined;
|
|
58
|
-
return
|
|
58
|
+
return result[0].value;
|
|
59
59
|
}
|
|
60
60
|
async set(key, value, options) {
|
|
61
61
|
await this.initialize();
|
|
62
62
|
const ttl = options?.ttl == null ? null : options.ttl.toString();
|
|
63
63
|
await __classPrivateFieldGet(this, _PostgresKvStore_sql, "f").bind(this) `
|
|
64
64
|
INSERT INTO ${__classPrivateFieldGet(this, _PostgresKvStore_sql, "f").call(this, __classPrivateFieldGet(this, _PostgresKvStore_tableName, "f"))} (key, value, ttl)
|
|
65
|
-
VALUES (
|
|
65
|
+
VALUES (
|
|
66
|
+
${key},
|
|
67
|
+
(${{ value }}::jsonb) -> 'value',
|
|
68
|
+
${ttl}
|
|
69
|
+
)
|
|
66
70
|
ON CONFLICT (key)
|
|
67
71
|
DO UPDATE SET value = EXCLUDED.value, ttl = EXCLUDED.ttl;
|
|
68
72
|
`;
|
package/script/src/mq.js
CHANGED
|
@@ -69,7 +69,7 @@ class PostgresMessageQueue {
|
|
|
69
69
|
_PostgresMessageQueue_pollIntervalMs.set(this, void 0);
|
|
70
70
|
_PostgresMessageQueue_initialized.set(this, void 0);
|
|
71
71
|
__classPrivateFieldSet(this, _PostgresMessageQueue_sql, sql, "f");
|
|
72
|
-
__classPrivateFieldSet(this, _PostgresMessageQueue_tableName, options?.tableName ?? "
|
|
72
|
+
__classPrivateFieldSet(this, _PostgresMessageQueue_tableName, options?.tableName ?? "fedify_message_v2", "f");
|
|
73
73
|
__classPrivateFieldSet(this, _PostgresMessageQueue_channelName, options?.channelName ?? "fedify_channel", "f");
|
|
74
74
|
__classPrivateFieldSet(this, _PostgresMessageQueue_pollIntervalMs, dntShim.Temporal.Duration.from(options?.pollInterval ?? { seconds: 5 }).total("millisecond"), "f");
|
|
75
75
|
__classPrivateFieldSet(this, _PostgresMessageQueue_initialized, options?.initialized ?? false, "f");
|
|
@@ -81,7 +81,10 @@ class PostgresMessageQueue {
|
|
|
81
81
|
const delay = options?.delay ?? dntShim.Temporal.Duration.from({ seconds: 0 });
|
|
82
82
|
await __classPrivateFieldGet(this, _PostgresMessageQueue_sql, "f").bind(this) `
|
|
83
83
|
INSERT INTO ${__classPrivateFieldGet(this, _PostgresMessageQueue_sql, "f").call(this, __classPrivateFieldGet(this, _PostgresMessageQueue_tableName, "f"))} (message, delay)
|
|
84
|
-
VALUES (
|
|
84
|
+
VALUES (
|
|
85
|
+
(${{ message }}::jsonb) -> 'message',
|
|
86
|
+
${delay.toString()}
|
|
87
|
+
);
|
|
85
88
|
`;
|
|
86
89
|
await __classPrivateFieldGet(this, _PostgresMessageQueue_sql, "f").notify(__classPrivateFieldGet(this, _PostgresMessageQueue_channelName, "f"), delay.toString());
|
|
87
90
|
}
|
|
@@ -93,23 +96,23 @@ class PostgresMessageQueue {
|
|
|
93
96
|
const poll = async () => {
|
|
94
97
|
while (!signal?.aborted) {
|
|
95
98
|
const query = __classPrivateFieldGet(this, _PostgresMessageQueue_sql, "f").bind(this) `
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
99
|
+
DELETE FROM ${__classPrivateFieldGet(this, _PostgresMessageQueue_sql, "f").call(this, __classPrivateFieldGet(this, _PostgresMessageQueue_tableName, "f"))}
|
|
100
|
+
WHERE id = (
|
|
101
|
+
SELECT id
|
|
102
|
+
FROM ${__classPrivateFieldGet(this, _PostgresMessageQueue_sql, "f").call(this, __classPrivateFieldGet(this, _PostgresMessageQueue_tableName, "f"))}
|
|
103
|
+
WHERE created + delay < CURRENT_TIMESTAMP
|
|
104
|
+
ORDER BY created
|
|
105
|
+
LIMIT 1
|
|
106
|
+
)
|
|
107
|
+
RETURNING message;
|
|
108
|
+
`.execute();
|
|
106
109
|
const cancel = query.cancel.bind(query);
|
|
107
110
|
signal?.addEventListener("abort", cancel);
|
|
108
111
|
let i = 0;
|
|
109
112
|
for (const message of await query) {
|
|
110
113
|
if (signal?.aborted)
|
|
111
114
|
return;
|
|
112
|
-
await handler(
|
|
115
|
+
await handler(message.message);
|
|
113
116
|
i++;
|
|
114
117
|
}
|
|
115
118
|
signal?.removeEventListener("abort", cancel);
|
package/types/src/kv.d.ts
CHANGED
|
@@ -5,8 +5,9 @@ import type { Sql } from "postgres";
|
|
|
5
5
|
*/
|
|
6
6
|
export interface PostgresKvStoreOptions {
|
|
7
7
|
/**
|
|
8
|
-
* The table name to use for the key-value store.
|
|
9
|
-
*
|
|
8
|
+
* The table name to use for the key-value store.
|
|
9
|
+
* `"fedify_kv_v2"` by default.
|
|
10
|
+
* @default `"fedify_kv_v2"`
|
|
10
11
|
*/
|
|
11
12
|
tableName?: string;
|
|
12
13
|
/**
|
package/types/src/kv.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kv.d.ts","sourceRoot":"","sources":["../../src/src/kv.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAEpC;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC
|
|
1
|
+
{"version":3,"file":"kv.d.ts","sourceRoot":"","sources":["../../src/src/kv.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAEpC;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;;;;;;;;;;;;;;GAcG;AACH,qBAAa,eAAgB,YAAW,OAAO;;IAM7C;;;;OAIG;gBAGD,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC,EACZ,OAAO,GAAE,sBAA2B;IAchC,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,KAAK,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAWpD,GAAG,CACP,GAAG,EAAE,KAAK,EACV,KAAK,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,iBAAiB,GAAG,SAAS,GACtC,OAAO,CAAC,IAAI,CAAC;IAgBV,MAAM,CAAC,GAAG,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;IASvC;;;OAGG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAajC;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAG5B"}
|
package/types/src/mq.d.ts
CHANGED
|
@@ -7,8 +7,8 @@ import type { Sql } from "postgres";
|
|
|
7
7
|
export interface PostgresMessageQueueOptions {
|
|
8
8
|
/**
|
|
9
9
|
* The table name to use for the message queue.
|
|
10
|
-
* `"
|
|
11
|
-
* @default `"
|
|
10
|
+
* `"fedify_message_v2"` by default.
|
|
11
|
+
* @default `"fedify_message_v2"`
|
|
12
12
|
*/
|
|
13
13
|
tableName?: string;
|
|
14
14
|
/**
|
package/types/src/mq.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mq.d.ts","sourceRoot":"","sources":["../../src/src/mq.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAC;AAC5C,OAAO,KAAK,EACV,YAAY,EACZ,0BAA0B,EAC1B,yBAAyB,EAC1B,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAGpC;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1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