@fedify/postgres 2.0.0-dev.1875 → 2.0.0-dev.196

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright 2024–2025 Hong Minhee
3
+ Copyright 2024–2026 Hong Minhee
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
package/README.md CHANGED
@@ -25,10 +25,10 @@ const federation = createFederation({
25
25
  });
26
26
  ~~~~
27
27
 
28
- [JSR]: https://jsr.io/@fedify/postgres
29
28
  [JSR badge]: https://jsr.io/badges/@fedify/postgres
30
- [npm]: https://www.npmjs.com/package/@fedify/postgres
29
+ [JSR]: https://jsr.io/@fedify/postgres
31
30
  [npm badge]: https://img.shields.io/npm/v/@fedify/postgres?logo=npm
31
+ [npm]: https://www.npmjs.com/package/@fedify/postgres
32
32
  [Fedify]: https://fedify.dev/
33
33
  [`KvStore`]: https://jsr.io/@fedify/fedify/doc/federation/~/KvStore
34
34
  [`MessageQueue`]: https://jsr.io/@fedify/fedify/doc/federation/~/MessageQueue
package/dist/kv.cjs CHANGED
@@ -81,6 +81,35 @@ var PostgresKvStore = class {
81
81
  await this.#expire();
82
82
  }
83
83
  /**
84
+ * {@inheritDoc KvStore.list}
85
+ * @since 1.10.0
86
+ */
87
+ async *list(prefix) {
88
+ await this.initialize();
89
+ let results;
90
+ if (prefix == null || prefix.length === 0) results = await this.#sql`
91
+ SELECT key, value
92
+ FROM ${this.#sql(this.#tableName)}
93
+ WHERE ttl IS NULL OR created + ttl > CURRENT_TIMESTAMP
94
+ ORDER BY key
95
+ `;
96
+ else {
97
+ const prefixLength = prefix.length;
98
+ results = await this.#sql`
99
+ SELECT key, value
100
+ FROM ${this.#sql(this.#tableName)}
101
+ WHERE array_length(key, 1) >= ${prefixLength}
102
+ AND key[1:${prefixLength}] = ${prefix}::text[]
103
+ AND (ttl IS NULL OR created + ttl > CURRENT_TIMESTAMP)
104
+ ORDER BY key
105
+ `;
106
+ }
107
+ for (const row of results) yield {
108
+ key: row.key,
109
+ value: row.value
110
+ };
111
+ }
112
+ /**
84
113
  * Creates the table used by the key–value store if it does not already exist.
85
114
  * Does nothing if the table already exists.
86
115
  */
package/dist/kv.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { KvKey, KvStore, KvStoreSetOptions } from "@fedify/fedify";
1
+ import { KvKey, KvStore, KvStoreListEntry, KvStoreSetOptions } from "@fedify/fedify";
2
2
  import { Sql } from "postgres";
3
3
 
4
4
  //#region src/kv.d.ts
@@ -11,12 +11,12 @@ interface PostgresKvStoreOptions {
11
11
  * `"fedify_kv_v2"` by default.
12
12
  * @default `"fedify_kv_v2"`
13
13
  */
14
- tableName?: string;
14
+ readonly tableName?: string;
15
15
  /**
16
16
  * Whether the table has been initialized. `false` by default.
17
17
  * @default `false`
18
18
  */
19
- initialized?: boolean;
19
+ readonly initialized?: boolean;
20
20
  }
21
21
  /**
22
22
  * A key–value store that uses PostgreSQL as the underlying storage.
@@ -44,6 +44,11 @@ declare class PostgresKvStore implements KvStore {
44
44
  get<T = unknown>(key: KvKey): Promise<T | undefined>;
45
45
  set(key: KvKey, value: unknown, options?: KvStoreSetOptions | undefined): Promise<void>;
46
46
  delete(key: KvKey): Promise<void>;
47
+ /**
48
+ * {@inheritDoc KvStore.list}
49
+ * @since 1.10.0
50
+ */
51
+ list(prefix?: KvKey): AsyncIterable<KvStoreListEntry>;
47
52
  /**
48
53
  * Creates the table used by the key–value store if it does not already exist.
49
54
  * Does nothing if the table already exists.
package/dist/kv.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
2
  import { Sql } from "postgres";
3
- import { KvKey, KvStore, KvStoreSetOptions } from "@fedify/fedify";
3
+ import { KvKey, KvStore, KvStoreListEntry, KvStoreSetOptions } from "@fedify/fedify";
4
4
 
5
5
  //#region src/kv.d.ts
6
6
  /**
@@ -12,12 +12,12 @@ interface PostgresKvStoreOptions {
12
12
  * `"fedify_kv_v2"` by default.
13
13
  * @default `"fedify_kv_v2"`
14
14
  */
15
- tableName?: string;
15
+ readonly tableName?: string;
16
16
  /**
17
17
  * Whether the table has been initialized. `false` by default.
18
18
  * @default `false`
19
19
  */
20
- initialized?: boolean;
20
+ readonly initialized?: boolean;
21
21
  }
22
22
  /**
23
23
  * A key–value store that uses PostgreSQL as the underlying storage.
@@ -45,6 +45,11 @@ declare class PostgresKvStore implements KvStore {
45
45
  get<T = unknown>(key: KvKey): Promise<T | undefined>;
46
46
  set(key: KvKey, value: unknown, options?: KvStoreSetOptions | undefined): Promise<void>;
47
47
  delete(key: KvKey): Promise<void>;
48
+ /**
49
+ * {@inheritDoc KvStore.list}
50
+ * @since 1.10.0
51
+ */
52
+ list(prefix?: KvKey): AsyncIterable<KvStoreListEntry>;
48
53
  /**
49
54
  * Creates the table used by the key–value store if it does not already exist.
50
55
  * Does nothing if the table already exists.
package/dist/kv.js CHANGED
@@ -80,6 +80,35 @@ var PostgresKvStore = class {
80
80
  await this.#expire();
81
81
  }
82
82
  /**
83
+ * {@inheritDoc KvStore.list}
84
+ * @since 1.10.0
85
+ */
86
+ async *list(prefix) {
87
+ await this.initialize();
88
+ let results;
89
+ if (prefix == null || prefix.length === 0) results = await this.#sql`
90
+ SELECT key, value
91
+ FROM ${this.#sql(this.#tableName)}
92
+ WHERE ttl IS NULL OR created + ttl > CURRENT_TIMESTAMP
93
+ ORDER BY key
94
+ `;
95
+ else {
96
+ const prefixLength = prefix.length;
97
+ results = await this.#sql`
98
+ SELECT key, value
99
+ FROM ${this.#sql(this.#tableName)}
100
+ WHERE array_length(key, 1) >= ${prefixLength}
101
+ AND key[1:${prefixLength}] = ${prefix}::text[]
102
+ AND (ttl IS NULL OR created + ttl > CURRENT_TIMESTAMP)
103
+ ORDER BY key
104
+ `;
105
+ }
106
+ for (const row of results) yield {
107
+ key: row.key,
108
+ value: row.value
109
+ };
110
+ }
111
+ /**
83
112
  * Creates the table used by the key–value store if it does not already exist.
84
113
  * Does nothing if the table already exists.
85
114
  */
package/dist/mq.d.cts CHANGED
@@ -11,23 +11,23 @@ interface PostgresMessageQueueOptions {
11
11
  * `"fedify_message_v2"` by default.
12
12
  * @default `"fedify_message_v2"`
13
13
  */
14
- tableName?: string;
14
+ readonly tableName?: string;
15
15
  /**
16
16
  * The channel name to use for the message queue.
17
17
  * `"fedify_channel"` by default.
18
18
  * @default `"fedify_channel"`
19
19
  */
20
- channelName?: string;
20
+ readonly channelName?: string;
21
21
  /**
22
22
  * Whether the table has been initialized. `false` by default.
23
23
  * @default `false`
24
24
  */
25
- initialized?: boolean;
25
+ readonly initialized?: boolean;
26
26
  /**
27
27
  * The poll interval for the message queue. 5 seconds by default.
28
28
  * @default `{ seconds: 5 }`
29
29
  */
30
- pollInterval?: Temporal.Duration | Temporal.DurationLike;
30
+ readonly pollInterval?: Temporal.Duration | Temporal.DurationLike;
31
31
  }
32
32
  /**
33
33
  * A message queue that uses PostgreSQL as the underlying storage.
@@ -50,7 +50,7 @@ declare class PostgresMessageQueue implements MessageQueue {
50
50
  #private;
51
51
  constructor(sql: Sql<{}>, options?: PostgresMessageQueueOptions);
52
52
  enqueue(message: any, options?: MessageQueueEnqueueOptions): Promise<void>;
53
- enqueueMany(messages: any[], options?: MessageQueueEnqueueOptions): Promise<void>;
53
+ enqueueMany(messages: readonly any[], options?: MessageQueueEnqueueOptions): Promise<void>;
54
54
  listen(handler: (message: any) => void | Promise<void>, options?: MessageQueueListenOptions): Promise<void>;
55
55
  /**
56
56
  * Initializes the message queue table if it does not already exist.
package/dist/mq.d.ts CHANGED
@@ -12,23 +12,23 @@ interface PostgresMessageQueueOptions {
12
12
  * `"fedify_message_v2"` by default.
13
13
  * @default `"fedify_message_v2"`
14
14
  */
15
- tableName?: string;
15
+ readonly tableName?: string;
16
16
  /**
17
17
  * The channel name to use for the message queue.
18
18
  * `"fedify_channel"` by default.
19
19
  * @default `"fedify_channel"`
20
20
  */
21
- channelName?: string;
21
+ readonly channelName?: string;
22
22
  /**
23
23
  * Whether the table has been initialized. `false` by default.
24
24
  * @default `false`
25
25
  */
26
- initialized?: boolean;
26
+ readonly initialized?: boolean;
27
27
  /**
28
28
  * The poll interval for the message queue. 5 seconds by default.
29
29
  * @default `{ seconds: 5 }`
30
30
  */
31
- pollInterval?: Temporal.Duration | Temporal.DurationLike;
31
+ readonly pollInterval?: Temporal.Duration | Temporal.DurationLike;
32
32
  }
33
33
  /**
34
34
  * A message queue that uses PostgreSQL as the underlying storage.
@@ -51,7 +51,7 @@ declare class PostgresMessageQueue implements MessageQueue {
51
51
  #private;
52
52
  constructor(sql: Sql<{}>, options?: PostgresMessageQueueOptions);
53
53
  enqueue(message: any, options?: MessageQueueEnqueueOptions): Promise<void>;
54
- enqueueMany(messages: any[], options?: MessageQueueEnqueueOptions): Promise<void>;
54
+ enqueueMany(messages: readonly any[], options?: MessageQueueEnqueueOptions): Promise<void>;
55
55
  listen(handler: (message: any) => void | Promise<void>, options?: MessageQueueListenOptions): Promise<void>;
56
56
  /**
57
57
  * Initializes the message queue table if it does not already exist.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/postgres",
3
- "version": "2.0.0-dev.1875+d712d60c",
3
+ "version": "2.0.0-dev.196+c3cfc0a9",
4
4
  "description": "PostgreSQL drivers for Fedify",
5
5
  "keywords": [
6
6
  "fedify",
@@ -70,11 +70,11 @@
70
70
  ],
71
71
  "dependencies": {
72
72
  "@js-temporal/polyfill": "^0.5.1",
73
- "@logtape/logtape": "^1.1.1"
73
+ "@logtape/logtape": "^2.0.0"
74
74
  },
75
75
  "peerDependencies": {
76
76
  "postgres": "^3.4.7",
77
- "@fedify/fedify": "^2.0.0-dev.1875+d712d60c"
77
+ "@fedify/fedify": "^2.0.0-dev.196+c3cfc0a9"
78
78
  },
79
79
  "devDependencies": {
80
80
  "@std/async": "npm:@jsr/std__async@^1.0.13",