@fedify/mysql 2.5.0-dev.2766 → 2.5.0-dev.2816

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/dist/kv.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  /// <reference lib="esnext.temporal" />
2
- import { KvKey, KvStore, KvStoreListEntry, KvStoreSetOptions } from "@fedify/fedify";
2
+ import { AtomicKvStore, KvKey, KvStoreCasEntry, KvStoreListEntry, KvStoreSetEntry, KvStoreSetOptions } from "@fedify/fedify";
3
3
 
4
4
  //#region src/kv.d.ts
5
5
  interface MysqlQueryable {
@@ -10,6 +10,7 @@ interface MysqlPoolConnection extends MysqlQueryable {
10
10
  commit(): Promise<void>;
11
11
  rollback(): Promise<void>;
12
12
  release(): void;
13
+ destroy(): void;
13
14
  }
14
15
  interface MysqlPool extends MysqlQueryable {
15
16
  getConnection(): Promise<MysqlPoolConnection>;
@@ -28,7 +29,8 @@ interface MysqlKvStoreOptions {
28
29
  */
29
30
  readonly tableName?: string;
30
31
  /**
31
- * Whether the table has been initialized. `false` by default.
32
+ * Whether the table has been created. `false` by default. With `true`,
33
+ * initialization skips DDL but still validates the InnoDB schema.
32
34
  * @default `false`
33
35
  * @since 2.1.0
34
36
  */
@@ -43,7 +45,27 @@ interface MysqlKvStoreOptions {
43
45
  readonly expireCleanupRate?: number;
44
46
  }
45
47
  /**
46
- * A key-value store that uses MySQL (or MariaDB) as the underlying storage.
48
+ * An atomic key-value store backed by an InnoDB table on MySQL or MariaDB.
49
+ *
50
+ * All keys in one primary database/table share an atomic scope. Batches have
51
+ * at most 1,000 entries and serialized keys at most 768 Unicode code points;
52
+ * server packet and resource limits also apply. Values use JSON serialization
53
+ * and decoded structural equality (`isEqual`); object member order is ignored.
54
+ * Do not mutate expected values while a CAS is pending.
55
+ *
56
+ * TTLs are truncated to safe integer microseconds (approximately ±285 years),
57
+ * evaluated using one server cutoff per attempt. Calendar units use the local
58
+ * current date for conversion. Omitted TTL clears the previous expiry.
59
+ *
60
+ * Use a normal mysql2 pool with autocommit enabled, object rows, default type
61
+ * casting, and the same fixed-offset or UTC session time zone on every client.
62
+ * Caller-owned transactions, replica routing, concurrent schema changes,
63
+ * `NO_BACKSLASH_ESCAPES`, and disabled InnoDB gap locking are unsupported.
64
+ * Initialization checks the schema even with `initialized: true`.
65
+ *
66
+ * Deadlocks and MariaDB snapshot conflicts retry up to five total attempts.
67
+ * Other failures reject; a failed commit response can leave its outcome
68
+ * unknown. Atomicity does not promise crash durability or external effects.
47
69
  *
48
70
  * @example
49
71
  * ```ts
@@ -61,7 +83,7 @@ interface MysqlKvStoreOptions {
61
83
  *
62
84
  * @since 2.1.0
63
85
  */
64
- declare class MysqlKvStore implements KvStore {
86
+ declare class MysqlKvStore implements AtomicKvStore {
65
87
  #private;
66
88
  /**
67
89
  * Creates a new MySQL key-value store.
@@ -71,33 +93,55 @@ declare class MysqlKvStore implements KvStore {
71
93
  */
72
94
  constructor(pool: MysqlPool, options?: MysqlKvStoreOptions);
73
95
  /**
74
- * {@inheritDoc KvStore.get}
96
+ * {@inheritDoc AtomicKvStore.get}
75
97
  * @since 2.1.0
76
98
  */
77
99
  get<T = unknown>(key: KvKey): Promise<T | undefined>;
78
100
  /**
79
- * {@inheritDoc KvStore.set}
101
+ * {@inheritDoc AtomicKvStore.set}
80
102
  * @since 2.1.0
81
103
  */
82
- set(key: KvKey, value: unknown, options?: KvStoreSetOptions | undefined): Promise<void>;
104
+ set(key: KvKey, value: unknown, options?: KvStoreSetOptions): Promise<void>;
83
105
  /**
84
- * {@inheritDoc KvStore.delete}
106
+ * {@inheritDoc AtomicKvStore.delete}
85
107
  * @since 2.1.0
86
108
  */
87
109
  delete(key: KvKey): Promise<void>;
88
110
  /**
89
- * {@inheritDoc KvStore.cas}
111
+ * {@inheritDoc AtomicKvStore.cas}
90
112
  * @since 2.1.0
91
113
  */
92
114
  cas(key: KvKey, expectedValue: unknown, newValue: unknown, options?: KvStoreSetOptions): Promise<boolean>;
93
115
  /**
94
- * {@inheritDoc KvStore.list}
116
+ * {@inheritDoc AtomicKvStore.getMany}
117
+ * @since 2.5.0
118
+ */
119
+ getMany<T = unknown>(keys: readonly KvKey[]): Promise<(T | undefined)[]>;
120
+ /**
121
+ * {@inheritDoc AtomicKvStore.setMany}
122
+ * @since 2.5.0
123
+ */
124
+ setMany(entries: readonly KvStoreSetEntry[]): Promise<void>;
125
+ /**
126
+ * {@inheritDoc AtomicKvStore.deleteMany}
127
+ * @since 2.5.0
128
+ */
129
+ deleteMany(keys: readonly KvKey[]): Promise<void>;
130
+ /**
131
+ * {@inheritDoc AtomicKvStore.casMany}
132
+ * @since 2.5.0
133
+ */
134
+ casMany(entries: readonly KvStoreCasEntry[]): Promise<boolean>;
135
+ /**
136
+ * {@inheritDoc AtomicKvStore.list}
95
137
  * @since 2.1.0
96
138
  */
97
139
  list(prefix?: KvKey): AsyncIterable<KvStoreListEntry>;
98
140
  /**
99
141
  * Creates the table used by the key-value store if it does not already exist.
100
- * Does nothing if the table already exists.
142
+ * Validates the existing schema, including when `initialized: true` was
143
+ * supplied. Successful initialization is cached until {@link MysqlKvStore.drop}.
144
+ * Initialization and dropping must not overlap store operations.
101
145
  *
102
146
  * @since 2.1.0
103
147
  */
package/dist/kv.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /// <reference lib="esnext.temporal" />
2
- import { KvKey, KvStore, KvStoreListEntry, KvStoreSetOptions } from "@fedify/fedify";
2
+ import { AtomicKvStore, KvKey, KvStoreCasEntry, KvStoreListEntry, KvStoreSetEntry, KvStoreSetOptions } from "@fedify/fedify";
3
3
 
4
4
  //#region src/kv.d.ts
5
5
  interface MysqlQueryable {
@@ -10,6 +10,7 @@ interface MysqlPoolConnection extends MysqlQueryable {
10
10
  commit(): Promise<void>;
11
11
  rollback(): Promise<void>;
12
12
  release(): void;
13
+ destroy(): void;
13
14
  }
14
15
  interface MysqlPool extends MysqlQueryable {
15
16
  getConnection(): Promise<MysqlPoolConnection>;
@@ -28,7 +29,8 @@ interface MysqlKvStoreOptions {
28
29
  */
29
30
  readonly tableName?: string;
30
31
  /**
31
- * Whether the table has been initialized. `false` by default.
32
+ * Whether the table has been created. `false` by default. With `true`,
33
+ * initialization skips DDL but still validates the InnoDB schema.
32
34
  * @default `false`
33
35
  * @since 2.1.0
34
36
  */
@@ -43,7 +45,27 @@ interface MysqlKvStoreOptions {
43
45
  readonly expireCleanupRate?: number;
44
46
  }
45
47
  /**
46
- * A key-value store that uses MySQL (or MariaDB) as the underlying storage.
48
+ * An atomic key-value store backed by an InnoDB table on MySQL or MariaDB.
49
+ *
50
+ * All keys in one primary database/table share an atomic scope. Batches have
51
+ * at most 1,000 entries and serialized keys at most 768 Unicode code points;
52
+ * server packet and resource limits also apply. Values use JSON serialization
53
+ * and decoded structural equality (`isEqual`); object member order is ignored.
54
+ * Do not mutate expected values while a CAS is pending.
55
+ *
56
+ * TTLs are truncated to safe integer microseconds (approximately ±285 years),
57
+ * evaluated using one server cutoff per attempt. Calendar units use the local
58
+ * current date for conversion. Omitted TTL clears the previous expiry.
59
+ *
60
+ * Use a normal mysql2 pool with autocommit enabled, object rows, default type
61
+ * casting, and the same fixed-offset or UTC session time zone on every client.
62
+ * Caller-owned transactions, replica routing, concurrent schema changes,
63
+ * `NO_BACKSLASH_ESCAPES`, and disabled InnoDB gap locking are unsupported.
64
+ * Initialization checks the schema even with `initialized: true`.
65
+ *
66
+ * Deadlocks and MariaDB snapshot conflicts retry up to five total attempts.
67
+ * Other failures reject; a failed commit response can leave its outcome
68
+ * unknown. Atomicity does not promise crash durability or external effects.
47
69
  *
48
70
  * @example
49
71
  * ```ts
@@ -61,7 +83,7 @@ interface MysqlKvStoreOptions {
61
83
  *
62
84
  * @since 2.1.0
63
85
  */
64
- declare class MysqlKvStore implements KvStore {
86
+ declare class MysqlKvStore implements AtomicKvStore {
65
87
  #private;
66
88
  /**
67
89
  * Creates a new MySQL key-value store.
@@ -71,33 +93,55 @@ declare class MysqlKvStore implements KvStore {
71
93
  */
72
94
  constructor(pool: MysqlPool, options?: MysqlKvStoreOptions);
73
95
  /**
74
- * {@inheritDoc KvStore.get}
96
+ * {@inheritDoc AtomicKvStore.get}
75
97
  * @since 2.1.0
76
98
  */
77
99
  get<T = unknown>(key: KvKey): Promise<T | undefined>;
78
100
  /**
79
- * {@inheritDoc KvStore.set}
101
+ * {@inheritDoc AtomicKvStore.set}
80
102
  * @since 2.1.0
81
103
  */
82
- set(key: KvKey, value: unknown, options?: KvStoreSetOptions | undefined): Promise<void>;
104
+ set(key: KvKey, value: unknown, options?: KvStoreSetOptions): Promise<void>;
83
105
  /**
84
- * {@inheritDoc KvStore.delete}
106
+ * {@inheritDoc AtomicKvStore.delete}
85
107
  * @since 2.1.0
86
108
  */
87
109
  delete(key: KvKey): Promise<void>;
88
110
  /**
89
- * {@inheritDoc KvStore.cas}
111
+ * {@inheritDoc AtomicKvStore.cas}
90
112
  * @since 2.1.0
91
113
  */
92
114
  cas(key: KvKey, expectedValue: unknown, newValue: unknown, options?: KvStoreSetOptions): Promise<boolean>;
93
115
  /**
94
- * {@inheritDoc KvStore.list}
116
+ * {@inheritDoc AtomicKvStore.getMany}
117
+ * @since 2.5.0
118
+ */
119
+ getMany<T = unknown>(keys: readonly KvKey[]): Promise<(T | undefined)[]>;
120
+ /**
121
+ * {@inheritDoc AtomicKvStore.setMany}
122
+ * @since 2.5.0
123
+ */
124
+ setMany(entries: readonly KvStoreSetEntry[]): Promise<void>;
125
+ /**
126
+ * {@inheritDoc AtomicKvStore.deleteMany}
127
+ * @since 2.5.0
128
+ */
129
+ deleteMany(keys: readonly KvKey[]): Promise<void>;
130
+ /**
131
+ * {@inheritDoc AtomicKvStore.casMany}
132
+ * @since 2.5.0
133
+ */
134
+ casMany(entries: readonly KvStoreCasEntry[]): Promise<boolean>;
135
+ /**
136
+ * {@inheritDoc AtomicKvStore.list}
95
137
  * @since 2.1.0
96
138
  */
97
139
  list(prefix?: KvKey): AsyncIterable<KvStoreListEntry>;
98
140
  /**
99
141
  * Creates the table used by the key-value store if it does not already exist.
100
- * Does nothing if the table already exists.
142
+ * Validates the existing schema, including when `initialized: true` was
143
+ * supplied. Successful initialization is cached until {@link MysqlKvStore.drop}.
144
+ * Initialization and dropping must not overlap store operations.
101
145
  *
102
146
  * @since 2.1.0
103
147
  */