couchdb-web-node-plugin 1.0.518 → 1.0.521

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/type.d.ts ADDED
@@ -0,0 +1,394 @@
1
+ /// <reference types="pouchdb-core" />
2
+ /// <reference types="pouchdb-find" />
3
+ /// <reference types="pouchdb-mapreduce" />
4
+ /// <reference types="pouchdb-replication" />
5
+ /// <reference types="pouchdb-adapter-cordova-sqlite" />
6
+ /// <reference types="pouchdb-adapter-fruitdown" />
7
+ /// <reference types="pouchdb-adapter-http" />
8
+ /// <reference types="pouchdb-adapter-idb" />
9
+ /// <reference types="pouchdb-adapter-leveldb" />
10
+ /// <reference types="pouchdb-adapter-localstorage" />
11
+ /// <reference types="pouchdb-adapter-memory" />
12
+ /// <reference types="pouchdb-adapter-websql" />
13
+ /// <reference types="node" />
14
+ import { ChildProcess } from 'child_process';
15
+ import Tools from 'clientnode';
16
+ import { AnyFunction, Mapping, PlainObject, Primitive, ProcessCloseReason } from 'clientnode/type';
17
+ import { PluginAPI } from 'web-node';
18
+ import { Configuration as BaseConfiguration, Plugin, PluginHandler as BasePluginHandler, Service as BaseService, ServicePromises as BaseServicePromises, Services as BaseServices } from 'web-node/type';
19
+ import DatabaseHelper from './databaseHelper';
20
+ export declare type Attachments = PouchDB.Core.Attachments;
21
+ export declare type FullAttachment = PouchDB.Core.FullAttachment;
22
+ export declare type StubAttachment = PouchDB.Core.StubAttachment;
23
+ export declare type ChangesMeta = PouchDB.Core.ChangesMeta;
24
+ export declare type ChangesResponseChange<Type = unknown> = PouchDB.Core.ChangesResponseChange<Type>;
25
+ export declare type ChangesStream<Type = unknown> = PouchDB.Core.Changes<Type>;
26
+ export declare type ChangesStreamOptions = PouchDB.Core.ChangesOptions;
27
+ export declare type Connection = PouchDB.Database;
28
+ export declare type Connector = PouchDB.Static;
29
+ export declare type DatabaseConnectorConfiguration = PouchDB.Configuration.RemoteDatabaseConfiguration;
30
+ export declare type DatabaseError = PouchDB.Core.Error;
31
+ export declare type DatabaseFetch = PouchDB.Core.Options['fetch'];
32
+ export declare type DatabaseResponse = PouchDB.Core.Response;
33
+ export declare type DeleteIndexOptions = PouchDB.Find.DeleteIndexOptions;
34
+ export declare type Document<Type = PlainObject> = PouchDB.Core.Document<Type>;
35
+ export declare type ExistingDocument<Type = PlainObject> = PouchDB.Core.ExistingDocument<Type>;
36
+ export declare type DocumentGetMeta = PouchDB.Core.GetMeta;
37
+ export declare type DocumentIDMeta = PouchDB.Core.IdMeta;
38
+ export declare type DocumentRevisionIDMeta = PouchDB.Core.RevisionIdMeta;
39
+ export declare type Index = PouchDB.Find.Index;
40
+ export declare type DatabasePlugin = AnyFunction;
41
+ export declare type AllowedRoles = (Array<string> | string | {
42
+ read?: Array<string> | string;
43
+ write?: Array<string> | string;
44
+ });
45
+ export interface NormalizedAllowedRoles {
46
+ read: Array<string>;
47
+ write: Array<string>;
48
+ }
49
+ export interface NormalizedAllowedModelRoles extends NormalizedAllowedRoles {
50
+ properties: Mapping<NormalizedAllowedRoles>;
51
+ }
52
+ export declare type AllowedModelRolesMapping = Mapping<NormalizedAllowedModelRoles>;
53
+ export interface Constraint {
54
+ description?: null | string;
55
+ evaluation: string;
56
+ }
57
+ export declare type Type = string | 'any' | 'boolean' | 'integer' | 'number' | 'string' | 'DateTime';
58
+ export declare type TypeSpecification = Array<Type> | Type;
59
+ export declare type ConstraintKey = 'arrayConstraintExecution' | 'arrayConstraintExpression' | 'conflictingConstraintExecution' | 'conflictingConstraintExpression' | 'constraintExecution' | 'constraintExpression';
60
+ export interface SelectionMapping {
61
+ label: string;
62
+ value: unknown;
63
+ }
64
+ export interface PropertySpecification {
65
+ allowedRoles?: AllowedRoles | null;
66
+ arrayConstraintExecution?: Constraint | null;
67
+ arrayConstraintExpression?: Constraint | null;
68
+ conflictingConstraintExecution?: Constraint | null;
69
+ conflictingConstraintExpression?: Constraint | null;
70
+ constraintExecution?: Constraint | null;
71
+ constraintExpression?: Constraint | null;
72
+ contentTypeRegularExpressionPattern?: null | string;
73
+ default?: unknown;
74
+ emptyEqualsToNull?: boolean | null;
75
+ index?: boolean | null;
76
+ invertedContentTypeRegularExpressionPattern?: null | string;
77
+ invertedRegularExpressionPattern?: null | string;
78
+ maximum?: null | number;
79
+ maximumAggregatedSize?: null | number;
80
+ maximumLength?: null | number;
81
+ maximumNumber?: null | number;
82
+ maximumSize?: null | number;
83
+ minimum?: null | number;
84
+ minimumAggregatedSize?: null | number;
85
+ minimumLength?: null | number;
86
+ minimumNumber?: null | number;
87
+ minimumSize?: null | number;
88
+ mutable?: boolean | null;
89
+ nullable?: boolean | null;
90
+ onCreateExecution?: null | string;
91
+ onCreateExpression?: null | string;
92
+ oldName?: Array<string> | null | string;
93
+ onUpdateExecution?: null | string;
94
+ onUpdateExpression?: null | string;
95
+ regularExpressionPattern?: null | string;
96
+ selection?: Array<unknown> | Array<SelectionMapping> | Mapping<unknown> | null;
97
+ trim?: boolean | null;
98
+ type?: TypeSpecification | null;
99
+ value?: unknown;
100
+ writable?: boolean | null;
101
+ }
102
+ export interface FileSpecification extends PropertySpecification {
103
+ fileName?: PropertySpecification;
104
+ }
105
+ export interface BaseModel {
106
+ _allowedRoles?: AllowedRoles | null;
107
+ _attachments?: Mapping<FileSpecification> | null;
108
+ _constraintExecutions?: Array<Constraint> | Constraint | null;
109
+ _constraintExpressions?: Array<Constraint> | Constraint | null;
110
+ _createExecution?: null | string;
111
+ _createExpression?: null | string;
112
+ _extends?: Array<string> | null | string;
113
+ _maximumAggregatedSize?: null | number;
114
+ _minimumAggregatedSize?: null | number;
115
+ _oldType?: Array<string> | null | string;
116
+ _onUpdateExecution?: null | string;
117
+ _onUpdateExpression?: null | string;
118
+ }
119
+ export declare type Model = BaseModel & Mapping<PropertySpecification>;
120
+ export declare type Models = Mapping<Model>;
121
+ export declare const PrimitiveTypes: readonly ["boolean", "DateTime", "integer", "number", "string"];
122
+ export declare type UpdateStrategy = '' | 'fillUp' | 'incremental' | 'migrate';
123
+ export declare type DocumentContent = Array<DocumentContent> | PlainObject<Primitive> | Primitive;
124
+ export declare type DocumentStrategyMeta = {
125
+ _updateStrategy?: UpdateStrategy;
126
+ };
127
+ export declare type DocumentTypeMeta = {
128
+ '-type': string;
129
+ };
130
+ export declare type BaseDocument = ChangesMeta & DocumentGetMeta & DocumentIDMeta & DocumentRevisionIDMeta & DocumentStrategyMeta & DocumentTypeMeta;
131
+ export declare type FullDocument = BaseDocument & PlainObject;
132
+ export declare type PartialFullDocument = Partial<BaseDocument> & PlainObject;
133
+ export interface SpecialPropertyNames {
134
+ additional: '_additional';
135
+ allowedRoles: '_allowedRoles';
136
+ attachment: '_attachments';
137
+ conflict: '_conflicts';
138
+ deleted: '_deleted';
139
+ deletedConflict: '_deleted_conflict';
140
+ extend: '_extends';
141
+ id: '_id';
142
+ revision: '_rev';
143
+ revisions: '_revisions';
144
+ revisionsInformation: '_revs_info';
145
+ strategy: '_updateStrategy';
146
+ type: keyof DocumentTypeMeta;
147
+ constraint: {
148
+ execution: string;
149
+ expression: string;
150
+ };
151
+ create: {
152
+ execution: string;
153
+ expression: string;
154
+ };
155
+ designDocumentNamePrefix: string;
156
+ localSequence: string;
157
+ maximumAggregatedSize: string;
158
+ minimumAggregatedSize: string;
159
+ oldType: string;
160
+ update: {
161
+ execution: string;
162
+ expression: string;
163
+ };
164
+ }
165
+ export interface PropertyNameConfiguration {
166
+ reserved: Array<string>;
167
+ special: SpecialPropertyNames;
168
+ typeRegularExpressionPattern: {
169
+ private: string;
170
+ public: string;
171
+ };
172
+ validatedDocumentsCache: string;
173
+ }
174
+ export interface BaseModelConfiguration {
175
+ dateTimeFormat: 'iso' | 'iso8601' | 'number';
176
+ property: {
177
+ defaultSpecification: PropertySpecification;
178
+ name: PropertyNameConfiguration;
179
+ };
180
+ updateStrategy: UpdateStrategy;
181
+ }
182
+ export interface ModelConfiguration extends BaseModelConfiguration {
183
+ autoMigrationPath: string;
184
+ entities: Models;
185
+ triggerInitialCompaction: boolean;
186
+ updateConfiguration: boolean;
187
+ updateValidation: boolean;
188
+ }
189
+ export interface UserContext {
190
+ db: string;
191
+ name?: string;
192
+ roles: Array<string>;
193
+ }
194
+ export interface DatabaseUserConfiguration {
195
+ names: Array<string>;
196
+ roles: Array<string>;
197
+ }
198
+ export interface Runner {
199
+ adminUserConfigurationPath: string;
200
+ arguments?: Array<string> | null | string;
201
+ binaryFilePath?: null | string;
202
+ configurationFile?: null | {
203
+ content: string;
204
+ path: string;
205
+ };
206
+ environment?: null | Mapping;
207
+ location: Array<string> | string;
208
+ name: Array<string> | string;
209
+ }
210
+ export interface SecuritySettings {
211
+ admins: DatabaseUserConfiguration;
212
+ members: DatabaseUserConfiguration;
213
+ _validatedDocuments?: Set<string>;
214
+ }
215
+ export declare type ConnectorConfiguration = DatabaseConnectorConfiguration & {
216
+ fetch?: (RequestInit & {
217
+ timeout: number;
218
+ }) | null;
219
+ };
220
+ export declare type Configuration<ConfigurationType = Mapping<unknown>> = BaseConfiguration<{
221
+ couchdb: {
222
+ attachAutoRestarter: boolean;
223
+ backend: {
224
+ configuration: PlainObject;
225
+ prefixes: Array<string>;
226
+ };
227
+ binary: {
228
+ memoryInMegaByte: string;
229
+ nodePath: string;
230
+ runner: Array<Runner>;
231
+ };
232
+ changesStream: ChangesStreamOptions;
233
+ connector: ConnectorConfiguration;
234
+ createGenericFlatIndex: boolean;
235
+ databaseName: string;
236
+ debug: boolean;
237
+ ensureAdminPresence: boolean;
238
+ ensureSecuritySettingsPresence: boolean;
239
+ ensureUserPresence: boolean;
240
+ ignoreNoChangeError: boolean;
241
+ local: boolean;
242
+ maximumRepresentationLength: number;
243
+ maximumRepresentationTryLength: number;
244
+ model: ModelConfiguration;
245
+ path: string;
246
+ security: SecuritySettings;
247
+ url: string;
248
+ user: {
249
+ name: string;
250
+ password: string;
251
+ };
252
+ };
253
+ }> & ConfigurationType;
254
+ export interface Service extends BaseService {
255
+ name: 'couchdb';
256
+ promise: null | Promise<ProcessCloseReason>;
257
+ }
258
+ export declare type ServicePromises<ServicePromiseType = Mapping<unknown>> = BaseServicePromises<{
259
+ couchdb: Promise<ProcessCloseReason>;
260
+ }> & ServicePromiseType;
261
+ export declare type Services<ServiceType = Mapping<unknown>> = BaseServices<{
262
+ couchdb: {
263
+ connection: Connection;
264
+ connector: Connector;
265
+ server: {
266
+ process: ChildProcess;
267
+ reject: (_value: ProcessCloseReason) => void;
268
+ resolve: (_reason: ProcessCloseReason) => void;
269
+ restart: (_services: Services, _configuration: Configuration, _plugins: Array<Plugin>, _pluginAPI: typeof PluginAPI) => Promise<void>;
270
+ runner: Runner;
271
+ start: (_services: Services, _configuration: Configuration) => Promise<void>;
272
+ stop: (_services: Services, _configuration: Configuration) => Promise<void>;
273
+ };
274
+ };
275
+ }> & ServiceType;
276
+ export interface PluginHandler extends BasePluginHandler {
277
+ /**
278
+ * Hook after each data change.
279
+ * @param _changesStream - Stream of database changes.
280
+ * @param _services - List of other web-node plugin services.
281
+ * @param _configuration - Configuration object extended by each plugin
282
+ * specific configuration.
283
+ * @param _plugins - Topological sorted list of plugins.
284
+ * @param _pluginAPI - Plugin api reference.
285
+ *
286
+ * @returns Given entry files.
287
+ */
288
+ couchdbInitializeChangesStream?(_changesStream: ChangesStream, _services: Services, _configuration: Configuration, _plugins: Array<Plugin>, _pluginAPI: typeof PluginAPI): ChangesStream;
289
+ /**
290
+ * Hook after each data base restart.
291
+ * @param _services - List of other web-node plugin services.
292
+ * @param _configuration - Configuration object extended by each plugin
293
+ * specific configuration.
294
+ * @param _plugins - Topological sorted list of plugins.
295
+ * @param _pluginAPI - Plugin api reference.
296
+ *
297
+ * @returns Given entry files.
298
+ */
299
+ restartCouchdb?(_services: Services, _configuration: Configuration, _plugins: Array<Plugin>, _pluginAPI: typeof PluginAPI): Services;
300
+ }
301
+ export interface EmptyEvaluationExceptionData {
302
+ empty: string;
303
+ }
304
+ export declare type EmptyEvaluationException = Exception<EmptyEvaluationExceptionData>;
305
+ export interface EvaluationExceptionData<S = Mapping<unknown>> {
306
+ code: string;
307
+ error: Error;
308
+ scope: S;
309
+ }
310
+ export interface CompilationExceptionData<S = Mapping<unknown>> extends EvaluationExceptionData<S> {
311
+ compilation: string;
312
+ }
313
+ export interface RuntimeExceptionData<S = Mapping<unknown>> extends EvaluationExceptionData<S> {
314
+ runtime: string;
315
+ }
316
+ export declare type EvaluationException<S = Mapping<unknown>> = Exception<EvaluationExceptionData<S>>;
317
+ export interface BasicScope {
318
+ attachmentWithPrefixExists: (_namePrefix: string) => boolean;
319
+ checkDocument: (_newDocument: PartialFullDocument, _oldDocument: PartialFullDocument | null, _parentNames: Array<string>) => CheckedDocumentResult;
320
+ getFileNameByPrefix: (_prefix?: string, _attachments?: Attachments) => null | string;
321
+ serialize: (_value: unknown) => string;
322
+ id: string;
323
+ revision: string;
324
+ idName: string;
325
+ revisionName: string;
326
+ specialNames: SpecialPropertyNames;
327
+ typeName: string;
328
+ modelConfiguration: BaseModelConfiguration;
329
+ models: Models;
330
+ now: Date;
331
+ nowUTCTimestamp: number;
332
+ securitySettings: Partial<SecuritySettings>;
333
+ userContext: Partial<UserContext>;
334
+ }
335
+ export interface CommonScope {
336
+ checkPropertyContent: (_newValue: unknown, _name: string, _propertySpecification: PropertySpecification, _oldValue: unknown) => CheckedPropertyResult;
337
+ model: Model;
338
+ modelName: string;
339
+ type: string;
340
+ newDocument: Attachments | PartialFullDocument;
341
+ oldDocument: Attachments | null | PartialFullDocument;
342
+ parentNames: Array<string>;
343
+ pathDescription: string;
344
+ }
345
+ export interface PropertyScope extends CommonScope {
346
+ name: string;
347
+ newValue: unknown;
348
+ oldValue: unknown;
349
+ propertySpecification: PropertySpecification;
350
+ }
351
+ export interface EvaluationResult<T = unknown, S = BasicScope & CommonScope> {
352
+ code: string;
353
+ result: T;
354
+ scope: S;
355
+ }
356
+ export declare type Evaluate<R = unknown, P = unknown> = (..._parameters: Array<P>) => R;
357
+ export interface CheckedResult {
358
+ changedPath: Array<string>;
359
+ }
360
+ export interface CheckedPropertyResult extends CheckedResult {
361
+ newValue: unknown;
362
+ }
363
+ export interface CheckedDocumentResult extends CheckedResult {
364
+ newDocument: PartialFullDocument;
365
+ }
366
+ export declare type Exception<DataType = Mapping<unknown>> = {
367
+ message: string;
368
+ name: string;
369
+ } & DataType;
370
+ export declare type Migrator = (document: Document, scope: {
371
+ configuration: Configuration;
372
+ databaseHelper: DatabaseHelper;
373
+ tools: typeof Tools;
374
+ idName: string;
375
+ typeName: string;
376
+ migrater: Mapping<Migrator>;
377
+ models: Models;
378
+ modelConfiguration: ModelConfiguration;
379
+ selfFilePath: string;
380
+ services: Services;
381
+ }) => Document | null;
382
+ export declare type DateRepresentationType = Date | null | number | string;
383
+ export declare type User = BaseDocument & {
384
+ password: string;
385
+ roles: Array<string>;
386
+ };
387
+ export interface Interval {
388
+ end: number;
389
+ start: number;
390
+ }
391
+ export interface Location {
392
+ latitude: number;
393
+ longitude: number;
394
+ }