@decaf-ts/for-nano 0.8.0 → 0.10.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/lib/cjs/NanoDispatch.cjs +1 -0
- package/lib/cjs/NanoDispatch.cjs.map +1 -0
- package/lib/cjs/NanoRepository.cjs +1 -0
- package/lib/cjs/NanoRepository.cjs.map +1 -0
- package/lib/cjs/adapter.cjs +10 -9
- package/lib/cjs/adapter.cjs.map +1 -0
- package/lib/cjs/constants.cjs +1 -0
- package/lib/cjs/constants.cjs.map +1 -0
- package/lib/cjs/index.cjs +4 -3
- package/lib/cjs/index.cjs.map +1 -0
- package/lib/cjs/types.cjs +1 -0
- package/lib/cjs/types.cjs.map +1 -0
- package/lib/esm/index.js +1 -1
- package/lib/types/NanoDispatch.d.cts +119 -0
- package/lib/types/NanoDispatch.d.mts +119 -0
- package/lib/types/NanoRepository.d.cts +17 -0
- package/lib/types/NanoRepository.d.mts +17 -0
- package/lib/types/adapter.d.cts +449 -0
- package/lib/types/adapter.d.mts +449 -0
- package/lib/types/constants.d.cts +7 -0
- package/lib/types/constants.d.mts +7 -0
- package/lib/types/index.d.cts +23 -0
- package/lib/types/index.d.mts +23 -0
- package/lib/types/index.d.ts +1 -1
- package/lib/types/types.d.cts +39 -0
- package/lib/types/types.d.mts +39 -0
- package/package.json +4 -4
- package/lib/cjs/NanoDispatch.js.map +0 -1
- package/lib/cjs/NanoRepository.js.map +0 -1
- package/lib/cjs/adapter.js.map +0 -1
- package/lib/cjs/constants.js.map +0 -1
- package/lib/cjs/index.js.map +0 -1
- package/lib/cjs/types.js.map +0 -1
|
@@ -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.cjs";
|
|
6
|
+
import { Adapter, Context, ContextOf, ContextualArgs, MaybeContextualArg, RelationsMetadata, Repository } from "@decaf-ts/core";
|
|
7
|
+
import { NanoRepository } from "./NanoRepository.cjs";
|
|
8
|
+
import { NanoDispatch } from "./NanoDispatch.cjs";
|
|
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
|
+
}
|