@ensnode/ensdb-sdk 1.10.0 → 1.11.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/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { EnsIndexerPublicConfig, EnsDbPublicConfig, CrossChainIndexingStatusSnapshot, Unvalidated } from '@ensnode/ensnode-sdk';
1
+ import { EnsDbPublicConfig, IndexingMetadataContext, IndexingMetadataContextInitialized, Unvalidated } from '@ensnode/ensnode-sdk';
2
+ export { IndexingMetadataContext, IndexingMetadataContextInitialized, IndexingMetadataContextStatusCodes, IndexingMetadataContextUninitialized } from '@ensnode/ensnode-sdk';
2
3
  import { NodePgDatabase } from 'drizzle-orm/node-postgres';
3
- import { a as abstractEnsIndexerSchema } from './index-DN0SGSyd.js';
4
+ import { a as abstractEnsIndexerSchema } from './index-C0lByZGy.js';
4
5
  import { e as ensNodeSchema } from './index-BHoa233Z.js';
5
6
  import 'drizzle-orm/pg-core';
6
7
  import 'drizzle-orm';
@@ -8,42 +9,20 @@ import 'ponder';
8
9
  import 'enssdk';
9
10
 
10
11
  /**
11
- * ENSDb Config
12
+ * Utilities for Drizzle ORM integration with ENSDb.
12
13
  */
13
- interface EnsDbConfig {
14
- /**
15
- * PostgreSQL connection string for ENSDb.
16
- *
17
- * Guaranteed to be a valid PostgreSQL connection string with the format:
18
- * `postgresql://username:password@host:port/database` or
19
- * `postgres://username:password@host:port/database`
20
- */
21
- ensDbUrl: string;
22
- /**
23
- * The name of the ENSIndexer Schema in the ENSDb instance.
24
- *
25
- * Guaranteed to be a non-empty string that is
26
- * a valid Postgres database schema identifier
27
- */
28
- ensIndexerSchemaName: string;
29
- }
14
+
30
15
  /**
31
- * ENSDb Schema Checksum
16
+ * PostgreSQL startup `options` string for ENSDb connections.
32
17
  *
33
- * Checksum representing the ENSDb Schema definition, which is a combination of
34
- * - the ENSIndexer Schema definition, and
35
- * - the ENSNode Schema definition.
18
+ * Sets `search_path` so unqualified references (notably the `gin_trgm_ops`
19
+ * opclass from the pg_trgm extension, installed in the `ensnode` schema by
20
+ * migration 0001) resolve correctly at query and index-creation time.
36
21
  *
37
- * This checksum can be used to verify compatibility between
38
- * the ENSDb Schema definition expected by any client app connecting to ENSDb
39
- * instance and the actual ENSDb Schema definition present in ENSDb SDK.
22
+ * Pass via node-postgres `PoolConfig.options` (e.g. Ponder's
23
+ * `database.poolConfig.options`) or Drizzle's connection config.
40
24
  */
41
- declare const ENSDB_SCHEMA_CHECKSUM: string;
42
-
43
- /**
44
- * Utilities for Drizzle ORM integration with ENSDb.
45
- */
46
-
25
+ declare const ENSDB_CONNECTION_OPTIONS = "-c search_path=ensnode,public";
47
26
  /**
48
27
  * Abstract ENSIndexer Schema
49
28
  *
@@ -73,6 +52,39 @@ type EnsDbSchema<ConcreteEnsIndexerSchema extends AbstractEnsIndexerSchema> = Co
73
52
  */
74
53
  type EnsDbDrizzleClient<ConcreteEnsIndexerSchema extends AbstractEnsIndexerSchema> = NodePgDatabase<EnsDbSchema<ConcreteEnsIndexerSchema>>;
75
54
 
55
+ /**
56
+ * ENSDb Config
57
+ */
58
+ interface EnsDbConfig {
59
+ /**
60
+ * PostgreSQL connection string for ENSDb.
61
+ *
62
+ * Guaranteed to be a valid PostgreSQL connection string with the format:
63
+ * `postgresql://username:password@host:port/database` or
64
+ * `postgres://username:password@host:port/database`
65
+ */
66
+ ensDbUrl: string;
67
+ /**
68
+ * The name of the ENSIndexer Schema in the ENSDb instance.
69
+ *
70
+ * Guaranteed to be a non-empty string that is
71
+ * a valid Postgres database schema identifier
72
+ */
73
+ ensIndexerSchemaName: string;
74
+ }
75
+ /**
76
+ * ENSDb Schema Checksum
77
+ *
78
+ * Checksum representing the ENSDb Schema definition, which is a combination of
79
+ * - the ENSIndexer Schema definition, and
80
+ * - the ENSNode Schema definition.
81
+ *
82
+ * This checksum can be used to verify compatibility between
83
+ * the ENSDb Schema definition expected by any client app connecting to ENSDb
84
+ * instance and the actual ENSDb Schema definition present in ENSDb SDK.
85
+ */
86
+ declare const ENSDB_SCHEMA_CHECKSUM: string;
87
+
76
88
  /**
77
89
  * ENSDb Reader
78
90
  *
@@ -141,27 +153,26 @@ declare class EnsDbReader<ConcreteEnsIndexerSchema extends AbstractEnsIndexerSch
141
153
  */
142
154
  get ensNodeSchema(): EnsNodeSchema;
143
155
  /**
144
- * Get ENSDb Version
145
- *
146
- * @returns the existing record, or `undefined`.
156
+ * Check if the ENSDb instance is healthy by running a simple query
157
+ * against it.
147
158
  */
148
- getEnsDbVersion(): Promise<string | undefined>;
159
+ isHealthy(): Promise<boolean>;
149
160
  /**
150
- * Get ENSIndexer Public Config
151
- *
152
- * @returns the existing record, or `undefined`.
161
+ * Check if the ENSDb instance is ready by verifying that
162
+ * the {@link IndexingMetadataContext} has been initialized for
163
+ * the ENSIndexer Schema used by this ENSDbReader instance.
153
164
  */
154
- getEnsIndexerPublicConfig(): Promise<EnsIndexerPublicConfig | undefined>;
165
+ isReady(): Promise<boolean>;
155
166
  /**
156
167
  * Build ENSDb Public Config
157
168
  */
158
169
  buildEnsDbPublicConfig(): Promise<EnsDbPublicConfig>;
159
170
  /**
160
- * Get Indexing Status Snapshot
171
+ * Get Indexing Metadata Context
161
172
  *
162
- * @returns the existing record, or `undefined`.
173
+ * @returns the initialized record, or a default uninitialized one if no record exists in ENSDb.
163
174
  */
164
- getIndexingStatusSnapshot(): Promise<CrossChainIndexingStatusSnapshot | undefined>;
175
+ getIndexingMetadataContext(): Promise<IndexingMetadataContext>;
165
176
  /**
166
177
  * Get ENSNode Metadata record
167
178
  *
@@ -194,32 +205,31 @@ declare class EnsDbReader<ConcreteEnsIndexerSchema extends AbstractEnsIndexerSch
194
205
  * - updating ENSNode Metadata records in ENSDb for the given ENSIndexer instance.
195
206
  */
196
207
  declare class EnsDbWriter extends EnsDbReader {
208
+ /**
209
+ * Stable arbitrary lock ID for ENSNode Schema migrations to
210
+ * prevent concurrent migration execution across multiple ENSIndexer instances.
211
+ */
212
+ private static readonly MIGRATION_LOCK_ID;
197
213
  /**
198
214
  * Execute pending database migrations for ENSNode Schema in ENSDb.
199
215
  *
216
+ * This function is:
217
+ * - idempotent and can be safely executed multiple times,
218
+ * - safe to execute concurrently across multiple ENSIndexer instances,
219
+ * as it uses a stable arbitrary advisory lock to prevent concurrent
220
+ * execution of migrations.
221
+ *
200
222
  * @param migrationsDirPath - The file path to the directory containing
201
223
  * database migration files for ENSNode Schema.
202
224
  * @throws error when migration execution fails.
203
225
  */
204
226
  migrateEnsNodeSchema(migrationsDirPath: string): Promise<void>;
205
227
  /**
206
- * Upsert ENSDb Version
228
+ * Upsert Indexing Metadata Context Initialized
207
229
  *
208
230
  * @throws when upsert operation failed.
209
231
  */
210
- upsertEnsDbVersion(ensDbVersion: string): Promise<void>;
211
- /**
212
- * Upsert ENSIndexer Public Config
213
- *
214
- * @throws when upsert operation failed.
215
- */
216
- upsertEnsIndexerPublicConfig(ensIndexerPublicConfig: EnsIndexerPublicConfig): Promise<void>;
217
- /**
218
- * Upsert Indexing Status Snapshot
219
- *
220
- * @throws when upsert operation failed.
221
- */
222
- upsertIndexingStatusSnapshot(indexingStatus: CrossChainIndexingStatusSnapshot): Promise<void>;
232
+ upsertIndexingMetadataContext(indexingMetadataContext: IndexingMetadataContextInitialized): Promise<void>;
223
233
  /**
224
234
  * Upsert ENSNode metadata
225
235
  *
@@ -232,29 +242,28 @@ declare class EnsDbWriter extends EnsDbReader {
232
242
  * Keys used to distinguish records in `ensnode_metadata` table in the ENSDb.
233
243
  */
234
244
  declare const EnsNodeMetadataKeys: {
235
- readonly EnsDbVersion: "ensdb_version";
236
- readonly EnsIndexerPublicConfig: "ensindexer_public_config";
237
- readonly EnsIndexerIndexingStatus: "ensindexer_indexing_status";
245
+ readonly IndexingMetadataContext: "indexing_metadata_context";
238
246
  };
239
247
  type EnsNodeMetadataKey = (typeof EnsNodeMetadataKeys)[keyof typeof EnsNodeMetadataKeys];
240
- interface EnsNodeMetadataEnsDbVersion {
241
- key: typeof EnsNodeMetadataKeys.EnsDbVersion;
242
- value: string;
243
- }
244
- interface EnsNodeMetadataEnsIndexerPublicConfig {
245
- key: typeof EnsNodeMetadataKeys.EnsIndexerPublicConfig;
246
- value: EnsIndexerPublicConfig;
247
- }
248
- interface EnsNodeMetadataEnsIndexerIndexingStatus {
249
- key: typeof EnsNodeMetadataKeys.EnsIndexerIndexingStatus;
250
- value: CrossChainIndexingStatusSnapshot;
248
+ /**
249
+ * ENSNode Metadata record for Indexing Metadata Context
250
+ *
251
+ * This record is used to store the Indexing Metadata Context in
252
+ * ENSNode Metadata table for each ENSIndexer instance.
253
+ */
254
+ interface EnsNodeMetadataIndexingMetadataContext {
255
+ key: typeof EnsNodeMetadataKeys.IndexingMetadataContext;
256
+ value: IndexingMetadataContextInitialized;
251
257
  }
252
258
  /**
253
259
  * ENSNode Metadata
254
260
  *
255
- * Union type gathering all variants of ENSNode Metadata.
261
+ * Type alias for ENSNode Metadata records,
262
+ * currently only includes the record for Indexing Metadata Context,
263
+ * but can be extended in the future to include more types of
264
+ * ENSNode Metadata records as needed.
256
265
  */
257
- type EnsNodeMetadata = EnsNodeMetadataEnsDbVersion | EnsNodeMetadataEnsIndexerPublicConfig | EnsNodeMetadataEnsIndexerIndexingStatus;
266
+ type EnsNodeMetadata = EnsNodeMetadataIndexingMetadataContext;
258
267
 
259
268
  /**
260
269
  * Validate ENSDb config
@@ -265,4 +274,4 @@ type EnsNodeMetadata = EnsNodeMetadataEnsDbVersion | EnsNodeMetadataEnsIndexerPu
265
274
  */
266
275
  declare function validateEnsDbConfig(unvalidatedConfig: Unvalidated<EnsDbConfig>): EnsDbConfig;
267
276
 
268
- export { ENSDB_SCHEMA_CHECKSUM, type EnsDbConfig, type EnsDbDrizzleClient, EnsDbReader, EnsDbWriter, type EnsNodeMetadata, type EnsNodeMetadataEnsDbVersion, type EnsNodeMetadataEnsIndexerIndexingStatus, type EnsNodeMetadataEnsIndexerPublicConfig, type EnsNodeMetadataKey, EnsNodeMetadataKeys, validateEnsDbConfig };
277
+ export { ENSDB_CONNECTION_OPTIONS, ENSDB_SCHEMA_CHECKSUM, type EnsDbConfig, type EnsDbDrizzleClient, EnsDbReader, EnsDbWriter, type EnsNodeMetadata, type EnsNodeMetadataIndexingMetadataContext, type EnsNodeMetadataKey, EnsNodeMetadataKeys, validateEnsDbConfig };