@decaf-ts/for-nano 0.7.6 → 0.9.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.
@@ -0,0 +1,449 @@
1
+ import { OperationKeys, PrimaryKeyType } from "@decaf-ts/db-decorators";
2
+ import { CouchDBAdapter, MangoQuery, ViewResponse } from "@decaf-ts/for-couchdb";
3
+ import { DocumentScope, ServerScope } from "nano";
4
+ import { Model } from "@decaf-ts/decorator-validation";
5
+ import { NanoConfig, NanoFlags } from "./types.js";
6
+ import { Adapter, Context, ContextOf, ContextualArgs, MaybeContextualArg, RelationsMetadata, Repository } from "@decaf-ts/core";
7
+ import { NanoRepository } from "./NanoRepository.js";
8
+ import { NanoDispatch } from "./NanoDispatch.js";
9
+ import { Constructor } from "@decaf-ts/decoration";
10
+ /**
11
+ * @description Sets the creator or updater field in a model based on the user in the context
12
+ * @summary Callback function used in decorators to automatically set the created_by or updated_by fields
13
+ * with the username from the context when a document is created or updated
14
+ * @template M - Type extending Model
15
+ * @template R - Type extending NanoRepository<M>
16
+ * @template V - Type extending RelationsMetadata
17
+ * @param {R} this - The repository instance
18
+ * @param {Context<NanoFlags>} context - The operation context containing user information
19
+ * @param {V} data - The relation metadata
20
+ * @param key - The property key to set with the username
21
+ * @param {M} model - The model instance being created or updated
22
+ * @return {Promise<void>} A promise that resolves when the operation is complete
23
+ * @function createdByOnNanoCreateUpdate
24
+ * @memberOf module:for-nano
25
+ * @mermaid
26
+ * sequenceDiagram
27
+ * participant F as createdByOnNanoCreateUpdate
28
+ * participant C as Context
29
+ * participant M as Model
30
+ * F->>C: get("user")
31
+ * C-->>F: user object
32
+ * F->>M: set key to user.name
33
+ * Note over F: If no user in context
34
+ * F-->>F: throw UnsupportedError
35
+ */
36
+ export declare function createdByOnNanoCreateUpdate<M extends Model, R extends NanoRepository<M>, V extends RelationsMetadata>(this: R, context: ContextOf<R>, data: V, key: keyof M, model: M): Promise<void>;
37
+ /**
38
+ * @description Adapter for interacting with Nano databases
39
+ * @summary Provides a standardized interface for performing CRUD operations on Nano databases,
40
+ * extending the CouchDB adapter with Nano-specific functionality. This adapter handles document
41
+ * creation, reading, updating, and deletion, as well as bulk operations and index management.
42
+ * @template DocumentScope - The Nano document scope type
43
+ * @template NanoFlags - Configuration flags for Nano operations
44
+ * @template Context - Context type for operations
45
+ * @param {DocumentScope<any>} scope - The Nano document scope to use for database operations
46
+ * @param {string} [alias] - Optional alias for the adapter
47
+ * @class NanoAdapter
48
+ * @example
49
+ * ```typescript
50
+ * // Connect to a Nano database
51
+ * const server = NanoAdapter.connect('admin', 'password', 'localhost:5984');
52
+ * const db = server.db.use('my_database');
53
+ *
54
+ * // Create an adapter instance
55
+ * const adapter = new NanoAdapter(db);
56
+ *
57
+ * // Use the adapter for database operations
58
+ * const document = await adapter.read('users', '123');
59
+ * ```
60
+ * @mermaid
61
+ * classDiagram
62
+ * class CouchDBAdapter {
63
+ * +flags()
64
+ * +Dispatch()
65
+ * +index()
66
+ * +create()
67
+ * +read()
68
+ * +update()
69
+ * +delete()
70
+ * }
71
+ * class NanoAdapter {
72
+ * +flags()
73
+ * +Dispatch()
74
+ * +index()
75
+ * +create()
76
+ * +createAll()
77
+ * +read()
78
+ * +readAll()
79
+ * +update()
80
+ * +updateAll()
81
+ * +delete()
82
+ * +deleteAll()
83
+ * +raw()
84
+ * +static connect()
85
+ * +static createDatabase()
86
+ * +static deleteDatabase()
87
+ * +static createUser()
88
+ * +static deleteUser()
89
+ * +static decoration()
90
+ * }
91
+ * CouchDBAdapter <|-- NanoAdapter
92
+ */
93
+ export declare class NanoAdapter extends CouchDBAdapter<NanoConfig, DocumentScope<any>, Context<NanoFlags>> {
94
+ constructor(scope: NanoConfig, alias?: string);
95
+ /**
96
+ * @description Shuts down the adapter instance
97
+ * @summary Cleans up internal resources and clears the cached Nano client instance
98
+ * @return {Promise<void>} A promise that resolves when shutdown completes
99
+ */
100
+ shutdown(...args: MaybeContextualArg<Context<NanoFlags>>): Promise<void>;
101
+ /**
102
+ * @description Lazily creates and returns the Nano DocumentScope client
103
+ * @summary Uses the adapter configuration to establish a connection and wrap a database scope with credentials
104
+ * @return {DocumentScope<any>} The ready-to-use Nano DocumentScope for the configured database
105
+ */
106
+ protected getClient(): any;
107
+ /**
108
+ * @description Generates flags for database operations
109
+ * @summary Creates a set of flags for a specific operation, including user information
110
+ * @template M - Type extending Model
111
+ * @param {OperationKeys} operation - The operation being performed (create, read, update, delete)
112
+ * @param {Constructor<M>} model - The model constructor
113
+ * @param {Partial<NanoFlags>} flags - Partial flags to be merged
114
+ * @return {Promise<NanoFlags>} Complete flags for the operation
115
+ */
116
+ protected flags<M extends Model>(operation: OperationKeys, model: Constructor<M>, flags: Partial<NanoFlags>, ...args: any[]): Promise<NanoFlags>;
117
+ /**
118
+ * @description Creates a new NanoDispatch instance
119
+ * @summary Returns a dispatcher for handling Nano-specific operations
120
+ * @return {NanoDispatch} A new NanoDispatch instance
121
+ */
122
+ protected Dispatch(): NanoDispatch;
123
+ repository<R extends Repository<any, Adapter<NanoConfig, DocumentScope<any>, MangoQuery, Context<NanoFlags>>>>(): Constructor<R>;
124
+ /**
125
+ * @description Creates database indexes for models
126
+ * @summary Generates and creates indexes in the Nano database based on the provided models
127
+ * @template M - Type extending Model
128
+ * @param models - Model constructors to create indexes for
129
+ * @return {Promise<void>} A promise that resolves when all indexes are created
130
+ * @mermaid
131
+ * sequenceDiagram
132
+ * participant A as NanoAdapter
133
+ * participant G as generateIndexes
134
+ * participant DB as Nano Database
135
+ * A->>G: generateIndexes(models)
136
+ * G-->>A: indexes
137
+ * loop For each index
138
+ * A->>DB: createIndex(index)
139
+ * DB-->>A: response
140
+ * Note over A: Check if index already exists
141
+ * alt Index exists
142
+ * A-->>A: throw ConflictError
143
+ * end
144
+ * end
145
+ */
146
+ protected index<M extends Model>(...models: Constructor<M>[]): Promise<void>;
147
+ /**
148
+ * @description Creates a new document in the database
149
+ * @summary Inserts a new document into the Nano database with the provided data
150
+ * @param {string} tableName - The name of the table/collection
151
+ * @param {string | number} id - The document identifier
152
+ * @param {Record<string, any>} model - The document data to insert
153
+ * @return {Promise<Record<string, any>>} A promise that resolves to the created document with metadata
154
+ * @mermaid
155
+ * sequenceDiagram
156
+ * participant A as NanoAdapter
157
+ * participant DB as Nano Database
158
+ * A->>DB: insert(model)
159
+ * alt Success
160
+ * DB-->>A: response with ok=true
161
+ * A->>A: assignMetadata(model, response.rev)
162
+ * A-->>A: return document with metadata
163
+ * else Error
164
+ * DB-->>A: error
165
+ * A-->>A: throw parseError(e)
166
+ * else Not OK
167
+ * DB-->>A: response with ok=false
168
+ * A-->>A: throw InternalError
169
+ * end
170
+ */
171
+ create<M extends Model>(tableName: Constructor<M>, id: PrimaryKeyType, model: Record<string, any>, ...args: ContextualArgs<Context<NanoFlags>>): Promise<Record<string, any>>;
172
+ /**
173
+ * @description Creates multiple documents in the database
174
+ * @summary Inserts multiple documents into the Nano database in a single bulk operation
175
+ * @param {string} tableName - The name of the table/collection
176
+ * @param {string[] | number[]} ids - Array of document identifiers
177
+ * @param models - Array of document data to insert
178
+ * @return A promise that resolves to an array of created documents with metadata
179
+ * @mermaid
180
+ * sequenceDiagram
181
+ * participant A as NanoAdapter
182
+ * participant DB as Nano Database
183
+ * A->>DB: bulk({docs: models})
184
+ * alt Success
185
+ * DB-->>A: response array
186
+ * A->>A: Check if all responses have no errors
187
+ * alt All OK
188
+ * A->>A: assignMultipleMetadata(models, revs)
189
+ * A-->>A: return documents with metadata
190
+ * else Some errors
191
+ * A->>A: Collect error messages
192
+ * A-->>A: throw InternalError with collected messages
193
+ * end
194
+ * else Error
195
+ * DB-->>A: error
196
+ * A-->>A: throw parseError(e)
197
+ * end
198
+ */
199
+ createAll<M extends Model>(tableName: Constructor<M>, ids: PrimaryKeyType[], models: Record<string, any>[], ...args: ContextualArgs<Context<NanoFlags>>): Promise<Record<string, any>[]>;
200
+ /**
201
+ * @description Retrieves a document from the database
202
+ * @summary Fetches a single document from the Nano database by its ID
203
+ * @param {string} tableName - The name of the table/collection
204
+ * @param {string | number} id - The document identifier
205
+ * @return {Promise<Record<string, any>>} A promise that resolves to the retrieved document with metadata
206
+ * @mermaid
207
+ * sequenceDiagram
208
+ * participant A as NanoAdapter
209
+ * participant DB as Nano Database
210
+ * A->>A: generateId(tableName, id)
211
+ * A->>DB: get(_id)
212
+ * alt Success
213
+ * DB-->>A: record
214
+ * A->>A: assignMetadata(record, record._rev)
215
+ * A-->>A: return document with metadata
216
+ * else Error
217
+ * DB-->>A: error
218
+ * A-->>A: throw parseError(e)
219
+ * end
220
+ */
221
+ read<M extends Model>(tableName: Constructor<M>, id: PrimaryKeyType, ...args: ContextualArgs<Context<NanoFlags>>): Promise<Record<string, any>>;
222
+ /**
223
+ * @description Retrieves multiple documents from the database
224
+ * @summary Fetches multiple documents from the Nano database by their IDs in a single operation
225
+ * @param {string} tableName - The name of the table/collection
226
+ * @param {Array<string | number | bigint>} ids - Array of document identifiers
227
+ * @return A promise that resolves to an array of retrieved documents with metadata
228
+ * @mermaid
229
+ * sequenceDiagram
230
+ * participant A as NanoAdapter
231
+ * participant DB as Nano Database
232
+ * A->>A: Map ids to generateId(tableName, id)
233
+ * A->>DB: fetch({keys: mappedIds}, {})
234
+ * DB-->>A: results
235
+ * A->>A: Process each result row
236
+ * loop For each row
237
+ * alt Row has error
238
+ * A-->>A: throw InternalError
239
+ * else Row has document
240
+ * A->>A: assignMetadata(doc, doc._rev)
241
+ * else No document
242
+ * A-->>A: throw InternalError
243
+ * end
244
+ * end
245
+ * A-->>A: return documents with metadata
246
+ */
247
+ readAll<M extends Model>(tableName: Constructor<M>, ids: (string | number | bigint)[], ...args: ContextualArgs<Context<NanoFlags>>): Promise<Record<string, any>[]>;
248
+ /**
249
+ * @description Updates a document in the database
250
+ * @summary Updates an existing document in the Nano database with the provided data
251
+ * @param {string} tableName - The name of the table/collection
252
+ * @param {string | number} id - The document identifier
253
+ * @param {Record<string, any>} model - The updated document data
254
+ * @return {Promise<Record<string, any>>} A promise that resolves to the updated document with metadata
255
+ * @mermaid
256
+ * sequenceDiagram
257
+ * participant A as NanoAdapter
258
+ * participant DB as Nano Database
259
+ * A->>DB: insert(model)
260
+ * alt Success
261
+ * DB-->>A: response with ok=true
262
+ * A->>A: assignMetadata(model, response.rev)
263
+ * A-->>A: return document with metadata
264
+ * else Error
265
+ * DB-->>A: error
266
+ * A-->>A: throw parseError(e)
267
+ * else Not OK
268
+ * DB-->>A: response with ok=false
269
+ * A-->>A: throw InternalError
270
+ * end
271
+ */
272
+ update<M extends Model>(tableName: Constructor<M>, id: PrimaryKeyType, model: Record<string, any>, ...args: ContextualArgs<Context<NanoFlags>>): Promise<Record<string, any>>;
273
+ /**
274
+ * @description Updates multiple documents in the database
275
+ * @summary Performs a bulk update operation on the Nano database for the provided documents
276
+ * @param {string} tableName - The name of the table/collection
277
+ * @param {Array<string|number>} ids - Array of document identifiers
278
+ * @param {Promise<Array<Record<string, any>>>} models - Array of updated document data
279
+ * @return {Promise<Promise<Array<Record<string, any>>>>} A promise that resolves to the updated documents with metadata
280
+ */
281
+ updateAll<M extends Model>(tableName: Constructor<M>, ids: PrimaryKeyType[], models: Record<string, any>[], ...args: ContextualArgs<Context<NanoFlags>>): Promise<Record<string, any>[]>;
282
+ /**
283
+ * @description Deletes a document from the database
284
+ * @summary Removes a single document from the Nano database by its ID and returns the deleted document metadata
285
+ * @param {string} tableName - The name of the table/collection
286
+ * @param {string|number} id - The document identifier
287
+ * @return {Promise<Record<string, any>>} A promise that resolves to the deleted document with metadata
288
+ */
289
+ delete<M extends Model>(tableName: Constructor<M>, id: PrimaryKeyType, ...args: ContextualArgs<Context<NanoFlags>>): Promise<Record<string, any>>;
290
+ /**
291
+ * @description Deletes multiple documents from the database
292
+ * @summary Performs a bulk delete operation for the provided IDs and returns the deleted documents metadata
293
+ * @param {string} tableName - The name of the table/collection
294
+ * @param {Array<string|number|bigint>} ids - Array of document identifiers to delete
295
+ * @return {Promise<Array<Record<string, any>>>} A promise resolving to the deleted documents with metadata
296
+ */
297
+ deleteAll<M extends Model>(tableName: Constructor<M>, ids: PrimaryKeyType[], ...args: ContextualArgs<Context<NanoFlags>>): Promise<Record<string, any>[]>;
298
+ /**
299
+ * @description Executes a raw Mango query against the database
300
+ * @summary Runs a Mango query using Nano's find API and optionally returns only the documents array
301
+ * @template R - The expected response or document array type
302
+ * @param {MangoQuery} rawInput - The Mango query to execute
303
+ * @param {boolean} [docsOnly=true] - Whether to return only the docs array or the full response
304
+ * @return {Promise<R>} A promise that resolves to the query result, shaped according to docsOnly
305
+ */
306
+ raw<R>(rawInput: MangoQuery, docsOnly?: boolean, ...args: ContextualArgs<Context<NanoFlags>>): Promise<R>;
307
+ view<R>(ddoc: string, viewName: string, options: Record<string, any>, ..._args: ContextualArgs<Context<NanoFlags>>): Promise<ViewResponse<R>>;
308
+ /**
309
+ * @description Establishes a connection to a Nano (CouchDB) server
310
+ * @summary Creates and returns a Nano ServerScope using the given credentials, host, and protocol
311
+ * @param {string} user - Username used for authentication
312
+ * @param {string} pass - Password used for authentication
313
+ * @param {string} [host="localhost:5984"] - Host and port of the CouchDB server
314
+ * @param {("http"|"https")} [protocol="http"] - Protocol to use for the connection
315
+ * @return {ServerScope} The Nano ServerScope connection
316
+ */
317
+ static connect(user: string, pass: string, host?: string, protocol?: "http" | "https", agent?: any): ServerScope;
318
+ /**
319
+ * @description Creates a new database on the Nano server
320
+ * @summary Creates a new database with the specified name on the connected Nano server
321
+ * @param {ServerScope} con - The Nano server connection
322
+ * @param {string} name - The name of the database to create
323
+ * @return {Promise<void>} A promise that resolves when the database is created
324
+ * @mermaid
325
+ * sequenceDiagram
326
+ * participant A as NanoAdapter
327
+ * participant DB as Nano Server
328
+ * A->>DB: db.create(name)
329
+ * alt Success
330
+ * DB-->>A: result with ok=true
331
+ * else Error
332
+ * DB-->>A: error
333
+ * A-->>A: throw parseError(e)
334
+ * else Not OK
335
+ * DB-->>A: result with ok=false
336
+ * A-->>A: throw parseError(error, reason)
337
+ * end
338
+ */
339
+ static createDatabase(con: ServerScope, name: string): Promise<void>;
340
+ /**
341
+ * @description Deletes a database from the Nano server
342
+ * @summary Removes an existing database with the specified name from the connected Nano server
343
+ * @param {ServerScope} con - The Nano server connection
344
+ * @param {string} name - The name of the database to delete
345
+ * @return {Promise<void>} A promise that resolves when the database is deleted
346
+ * @mermaid
347
+ * sequenceDiagram
348
+ * participant A as NanoAdapter
349
+ * participant DB as Nano Server
350
+ * A->>DB: db.destroy(name)
351
+ * alt Success
352
+ * DB-->>A: result with ok=true
353
+ * else Error
354
+ * DB-->>A: error
355
+ * A-->>A: throw parseError(e)
356
+ * else Not OK
357
+ * DB-->>A: result with ok=false
358
+ * A-->>A: throw InternalError
359
+ * end
360
+ */
361
+ static deleteDatabase(con: ServerScope, name: string): Promise<void>;
362
+ /**
363
+ * @description Closes the keep-alive agent associated with a Nano connection
364
+ * @summary Destroys the custom HTTP/HTTPS agent that was created during connection setup
365
+ * @param {ServerScope} con - The Nano server connection whose agent should be destroyed
366
+ */
367
+ static closeConnection(con?: ServerScope | null): void;
368
+ /**
369
+ * @description Creates a new user and grants access to a database
370
+ * @summary Creates a new user in the Nano server and configures security to grant the user access to a specific database
371
+ * @param {ServerScope} con - The Nano server connection
372
+ * @param {string} dbName - The name of the database to grant access to
373
+ * @param {string} user - The username to create
374
+ * @param {string} pass - The password for the new user
375
+ * @param {string[]} [roles=["reader", "writer"]] - The roles to assign to the user
376
+ * @return {Promise<void>} A promise that resolves when the user is created and granted access
377
+ * @mermaid
378
+ * sequenceDiagram
379
+ * participant A as NanoAdapter
380
+ * participant U as _users Database
381
+ * participant S as Security API
382
+ * A->>A: Create user object
383
+ * A->>U: insert(user)
384
+ * alt Success
385
+ * U-->>A: response with ok=true
386
+ * A->>S: PUT _security with user permissions
387
+ * alt Security Success
388
+ * S-->>A: security response with ok=true
389
+ * else Security Failure
390
+ * S-->>A: security response with ok=false
391
+ * A-->>A: throw InternalError
392
+ * end
393
+ * else Error
394
+ * U-->>A: error
395
+ * A-->>A: throw parseError(e)
396
+ * else Not OK
397
+ * U-->>A: response with ok=false
398
+ * A-->>A: throw InternalError
399
+ * end
400
+ */
401
+ static createUser(con: ServerScope, dbName: string, user: string, pass: string, roles?: string[]): Promise<void>;
402
+ /**
403
+ * @description Deletes a user from the Nano server
404
+ * @summary Removes an existing user from the Nano server
405
+ * @param {ServerScope} con - The Nano server connection
406
+ * @param {string} dbName - The name of the database (used for logging purposes)
407
+ * @param {string} user - The username to delete
408
+ * @return {Promise<void>} A promise that resolves when the user is deleted
409
+ * @mermaid
410
+ * sequenceDiagram
411
+ * participant A as NanoAdapter
412
+ * participant U as _users Database
413
+ * A->>A: Generate user ID
414
+ * A->>U: get(id)
415
+ * U-->>A: user document
416
+ * A->>U: destroy(id, user._rev)
417
+ * alt Success
418
+ * U-->>A: success response
419
+ * else Error
420
+ * U-->>A: error
421
+ * A-->>A: throw parseError(e)
422
+ * end
423
+ */
424
+ static deleteUser(con: ServerScope, dbName: string, user: string): Promise<void>;
425
+ /**
426
+ * @description Sets up decorations for Nano-specific model properties
427
+ * @summary Configures decorators for created_by and updated_by fields in models to be automatically
428
+ * populated with the user from the context when documents are created or updated
429
+ * @return {void}
430
+ * @mermaid
431
+ * sequenceDiagram
432
+ * participant A as NanoAdapter
433
+ * participant D as Decoration
434
+ * participant R as Repository
435
+ * A->>R: key(PersistenceKeys.CREATED_BY)
436
+ * R-->>A: createdByKey
437
+ * A->>D: flavouredAs("nano")
438
+ * A->>D: for(createdByKey)
439
+ * A->>D: define(onCreate(createdByOnNanoCreateUpdate), propMetadata)
440
+ * A->>D: apply()
441
+ * A->>R: key(PersistenceKeys.UPDATED_BY)
442
+ * R-->>A: updatedByKey
443
+ * A->>D: flavouredAs("nano")
444
+ * A->>D: for(updatedByKey)
445
+ * A->>D: define(onCreate(createdByOnNanoCreateUpdate), propMetadata)
446
+ * A->>D: apply()
447
+ */
448
+ static decoration(): void;
449
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @description Identifier for the Nano database flavor
3
+ * @summary Constant string that identifies the database type as "nano" for use in adapter selection and configuration
4
+ * @const NanoFlavour
5
+ * @memberOf module:for-nano
6
+ */
7
+ export declare const NanoFlavour = "nano";
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @description Identifier for the Nano database flavor
3
+ * @summary Constant string that identifies the database type as "nano" for use in adapter selection and configuration
4
+ * @const NanoFlavour
5
+ * @memberOf module:for-nano
6
+ */
7
+ export declare const NanoFlavour = "nano";
@@ -0,0 +1,23 @@
1
+ export * from "./constants.cjs";
2
+ export * from "./NanoRepository.cjs";
3
+ export * from "./types.cjs";
4
+ export * from "./adapter.cjs";
5
+ /**
6
+ * @description A TypeScript module for interacting with Nano databases
7
+ * @summary This module provides a set of utilities, classes, and types for working with Nano databases. It includes repository patterns, adapters, and type definitions to simplify database operations. Key exports include {@link NanoAdapter}, {@link NanoRepository}, {@link NanoFlags}, and {@link NanoFlavour}.
8
+ * @module for-nano
9
+ */
10
+ /**
11
+ * @description Package version identifier
12
+ * @summary Stores the current package version string for the for-nano module
13
+ * @const VERSION
14
+ * @memberOf module:for-nano
15
+ */
16
+ export declare const VERSION = "0.8.0";
17
+ /**
18
+ * @description Package version identifier
19
+ * @summary Stores the current package version string for the for-nano module
20
+ * @const PACKAGE_NAME
21
+ * @memberOf module:for-nano
22
+ */
23
+ export declare const PACKAGE_NAME = "@decaf-ts/for-nano";
@@ -0,0 +1,23 @@
1
+ export * from "./constants.js";
2
+ export * from "./NanoRepository.js";
3
+ export * from "./types.js";
4
+ export * from "./adapter.js";
5
+ /**
6
+ * @description A TypeScript module for interacting with Nano databases
7
+ * @summary This module provides a set of utilities, classes, and types for working with Nano databases. It includes repository patterns, adapters, and type definitions to simplify database operations. Key exports include {@link NanoAdapter}, {@link NanoRepository}, {@link NanoFlags}, and {@link NanoFlavour}.
8
+ * @module for-nano
9
+ */
10
+ /**
11
+ * @description Package version identifier
12
+ * @summary Stores the current package version string for the for-nano module
13
+ * @const VERSION
14
+ * @memberOf module:for-nano
15
+ */
16
+ export declare const VERSION = "0.8.0";
17
+ /**
18
+ * @description Package version identifier
19
+ * @summary Stores the current package version string for the for-nano module
20
+ * @const PACKAGE_NAME
21
+ * @memberOf module:for-nano
22
+ */
23
+ export declare const PACKAGE_NAME = "@decaf-ts/for-nano";
@@ -13,7 +13,7 @@ export * from "./adapter";
13
13
  * @const VERSION
14
14
  * @memberOf module:for-nano
15
15
  */
16
- export declare const VERSION = "0.7.5";
16
+ export declare const VERSION = "0.8.0";
17
17
  /**
18
18
  * @description Package version identifier
19
19
  * @summary Stores the current package version string for the for-nano module
@@ -0,0 +1,39 @@
1
+ import { AdapterFlags } from "@decaf-ts/core";
2
+ /**
3
+ * @description Configuration flags for Nano database operations
4
+ * @summary Extended repository flags that include user authentication information for Nano database connections
5
+ * @interface NanoFlags
6
+ * @memberOf module:for-nano
7
+ */
8
+ export interface NanoFlags extends AdapterFlags {
9
+ /**
10
+ * @description User authentication information for Nano database connections
11
+ */
12
+ user: {
13
+ /**
14
+ * @description Username for authentication with the Nano database
15
+ */
16
+ name: string;
17
+ /**
18
+ * @description Optional array of roles assigned to the user
19
+ */
20
+ roles?: string[];
21
+ };
22
+ }
23
+ /**
24
+ * @description Connection configuration for Nano
25
+ * @summary Defines the necessary parameters to establish a connection to a Nano (CouchDB) server and select a database
26
+ * @property {string} user - Username to authenticate against the server
27
+ * @property {string} password - Password to authenticate the user
28
+ * @property {string} host - Host and port of the server (e.g., "localhost:5984") or full URL host without protocol
29
+ * @property {string} dbName - The database name to use on the server
30
+ * @typeDef NanoConfig
31
+ * @memberOf module:for-nano
32
+ */
33
+ export type NanoConfig = {
34
+ user: string;
35
+ password: string;
36
+ host: string;
37
+ dbName: string;
38
+ protocol: "http" | "https";
39
+ };
@@ -0,0 +1,39 @@
1
+ import { AdapterFlags } from "@decaf-ts/core";
2
+ /**
3
+ * @description Configuration flags for Nano database operations
4
+ * @summary Extended repository flags that include user authentication information for Nano database connections
5
+ * @interface NanoFlags
6
+ * @memberOf module:for-nano
7
+ */
8
+ export interface NanoFlags extends AdapterFlags {
9
+ /**
10
+ * @description User authentication information for Nano database connections
11
+ */
12
+ user: {
13
+ /**
14
+ * @description Username for authentication with the Nano database
15
+ */
16
+ name: string;
17
+ /**
18
+ * @description Optional array of roles assigned to the user
19
+ */
20
+ roles?: string[];
21
+ };
22
+ }
23
+ /**
24
+ * @description Connection configuration for Nano
25
+ * @summary Defines the necessary parameters to establish a connection to a Nano (CouchDB) server and select a database
26
+ * @property {string} user - Username to authenticate against the server
27
+ * @property {string} password - Password to authenticate the user
28
+ * @property {string} host - Host and port of the server (e.g., "localhost:5984") or full URL host without protocol
29
+ * @property {string} dbName - The database name to use on the server
30
+ * @typeDef NanoConfig
31
+ * @memberOf module:for-nano
32
+ */
33
+ export type NanoConfig = {
34
+ user: string;
35
+ password: string;
36
+ host: string;
37
+ dbName: string;
38
+ protocol: "http" | "https";
39
+ };
package/package.json CHANGED
@@ -1,17 +1,22 @@
1
1
  {
2
2
  "name": "@decaf-ts/for-nano",
3
- "version": "0.7.6",
3
+ "version": "0.9.0",
4
4
  "description": "decaf-ts persistence adapter for CouchDB via nano",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {
8
- "types": "./lib/types/index.d.ts",
9
- "import": "./lib/esm/index.js",
10
- "require": "./lib/cjs/index.cjs",
8
+ "import": {
9
+ "types": "./lib/types/index.d.mts",
10
+ "default": "./lib/esm/index.js"
11
+ },
12
+ "require": {
13
+ "types": "./lib/types/index.d.cts",
14
+ "default": "./lib/cjs/index.cjs"
15
+ },
11
16
  "default": "./lib/esm/index.js"
12
17
  }
13
18
  },
14
- "types": "./lib/types/index.d.ts",
19
+ "types": "./lib/types/index.d.mts",
15
20
  "main": "./lib/cjs/index.cjs",
16
21
  "module": "./lib/esm/index.js",
17
22
  "sideEffects": false,
@@ -23,8 +28,8 @@
23
28
  "set-git-auth": "git config url.\"https://api:$(cat .token)@github.com/\".insteadOf \"https://github.com/\" && git config url.\"https://ssh:$(cat .token)@github.com/\".insteadOf \"ssh://git@github.com/\" && git config url.\"https://git:$(cat .token)@github.com/\".insteadOf \"git@github.com:\"",
24
29
  "flash-forward": "npx npm-check-updates -u && npm run do-install",
25
30
  "reset": "rm -rf * && git checkout . && git pull && npm run do-install",
26
- "build": "npx build-scripts --dev",
27
- "build:prod": "npx build-scripts --prod",
31
+ "build": "build-scripts --dev",
32
+ "build:prod": "build-scripts --prod",
28
33
  "test": "jest --runInBand --coverage --detectOpenHandles",
29
34
  "test:unit": "jest --testPathPatterns=\"/tests/unit\" --passWithNoTests --detectOpenHandles",
30
35
  "test:integration": "jest --testPathPatterns=\"/tests/(integration)\" --passWithNoTests --detectOpenHandles",
@@ -39,7 +44,7 @@
39
44
  "clean-publish": "npx clean-publish",
40
45
  "drawings": "for FILE in workdocs/drawings/*.drawio; do echo \"converting $FILE to image...\" && docker run --rm -v $(pwd):/data rlespinasse/drawio-export --format png $FILE; done && cp -rf workdocs/drawings/export/* workdocs/resources/",
41
46
  "uml": "cd workdocs/uml && for FILE in ./*.puml; do docker run --rm -v $(pwd):/work -w /work miy4/plantuml -DPLANTUML_LIMIT_SIZE=8192 -tpng $FILE; done && cd ../.. && cp -fr workdocs/uml/*.png workdocs/resources/",
42
- "docs": "npx rimraf ./docs && mkdir docs && npx build-scripts --docs",
47
+ "docs": "npx rimraf ./docs && mkdir docs && build-scripts --docs",
43
48
  "publish-docs": "docker run -it --rm --user $(id -u):$(id -g) -v \"$(pwd)/workdocs/confluence:/content\" -e ATLASSIAN_API_TOKEN=$(cat .confluence-token) ghcr.io/markdown-confluence/publish:latest",
44
49
  "repo:init": "codex exec \"$(cat ./.codex/prompts/repo-setup.md)\nbase_path is `./`, initialize the repository\"",
45
50
  "repo:setup": "codex exec \"$(cat ./.codex/prompts/repo-setup.md)\nbase_path is ./\"",
@@ -1 +0,0 @@
1
- {"version":3,"file":"NanoDispatch.js","sourceRoot":"","sources":["../../src/NanoDispatch.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