1 | /// <reference types="node" />
|
2 | import * as Promise from "bluebird";
|
3 | import ReadableStream = NodeJS.ReadableStream;
|
4 | export interface IDeferred {
|
5 | resolve: (result: any) => void;
|
6 | reject: (error: Error) => void;
|
7 | promise: Promise<any> & {
|
8 | metadata?: any;
|
9 | };
|
10 | }
|
11 | export declare type CommunibaseEntityType = "Person" | "Membership" | "Event" | "Invoice" | "Contact" | "Debtor" | "File" | string;
|
12 | export interface ICommunibaseDocument {
|
13 | _id?: string;
|
14 | [prop: string]: any;
|
15 | }
|
16 | export interface ICommunibaseDocumentReference {
|
17 | rootDocumentEntityType: CommunibaseEntityType;
|
18 | rootDocumentId: string;
|
19 | path: Array<{
|
20 | field: string;
|
21 | objectId: string;
|
22 | }>;
|
23 | }
|
24 | export interface ICommunibaseVersionInformation {
|
25 | _id: string;
|
26 | updatedAt: string;
|
27 | updatedBy: string;
|
28 | }
|
29 | export interface ICommunibaseParams {
|
30 | fields?: string;
|
31 | limit?: number;
|
32 | page?: number;
|
33 | sort?: string;
|
34 | includeMetadata?: boolean;
|
35 | dir?: "ASC" | "DESC";
|
36 | deleted?: boolean;
|
37 | }
|
38 | /**
|
39 | * Constructor for connector.
|
40 | *
|
41 | * @param key - The communibase api key
|
42 | * @constructor
|
43 | */
|
44 | export declare class Connector {
|
45 | private getByIdQueue;
|
46 | private getByIdPrimed;
|
47 | private key?;
|
48 | private token;
|
49 | private serviceUrl;
|
50 | private serviceUrlIsHttps;
|
51 | private queue;
|
52 | private cache?;
|
53 | constructor(key?: string);
|
54 | setServiceUrl(newServiceUrl: string): void;
|
55 | /**
|
56 | * Get a single object by its id
|
57 | *
|
58 | * @param {string} objectType - E.g. Person
|
59 | * string}objectId - E.g. 52259f95dafd757b06002221
{ |
60 | * for extra arguments like fields, limit, page and/or sort
{object} [params={}] - key/value store |
61 | * string|null} [versionId=null] - optional versionId to retrieve
{ |
62 | * Promise} - for object: a key/value object with object data
{ |
63 | */
|
64 | getById<T extends ICommunibaseDocument = ICommunibaseDocument>(objectType: CommunibaseEntityType, objectId: string, params?: ICommunibaseParams, versionId?: string): Promise<T>;
|
65 | /**
|
66 | * Get an array of objects by their ids
|
67 | * If one or more entries are found, they are returned as an array of values
|
68 | *
|
69 | * @param {string} objectType - E.g. Person
|
70 | * @param {Array} objectIds - objectIds - E.g. ['52259f95dafd757b06002221']
|
71 | * @param {object} [params={}] - key/value store for extra arguments like fields, limit, page and/or sort
|
72 | * @returns {Promise} - for array of key/value objects
|
73 | */
|
74 | getByIds<T extends ICommunibaseDocument = ICommunibaseDocument>(objectType: CommunibaseEntityType, objectIds: string[], params?: ICommunibaseParams): Promise<T[]>;
|
75 | /**
|
76 | * Get all objects of a certain type
|
77 | *
|
78 | * @param {string} objectType - E.g. Person
|
79 | * @param {object} [params={}] - key/value store for extra arguments like fields, limit, page and/or sort
|
80 | * @returns {Promise} - for array of key/value objects
|
81 | */
|
82 | getAll<T extends ICommunibaseDocument = ICommunibaseDocument>(objectType: CommunibaseEntityType, params?: ICommunibaseParams): Promise<T[]>;
|
83 | /**
|
84 | * Get result objectIds of a certain search
|
85 | *
|
86 | * @param {string} objectType - E.g. Person
|
87 | * @param {object} selector - { firstName: "Henk" }
|
88 | * @param {object} [params={}] - key/value store for extra arguments like fields, limit, page and/or sort
|
89 | * @returns {Promise} - for array of key/value objects
|
90 | */
|
91 | getIds(objectType: CommunibaseEntityType, selector?: {}, params?: ICommunibaseParams): Promise<string[]>;
|
92 | /**
|
93 | * Get the id of an object based on a search
|
94 | *
|
95 | * @param {string} objectType - E.g. Person
|
96 | * @param {object} selector - { firstName: "Henk" }
|
97 | * @returns {Promise} - for a string OR undefined if not found
|
98 | */
|
99 | getId(objectType: CommunibaseEntityType, selector?: {}): Promise<string | null>;
|
100 | /**
|
101 | *
|
102 | * @param objectType
|
103 | * @param selector - mongodb style
|
104 | * @param params
|
105 | * @returns {Promise} for objects
|
106 | */
|
107 | search<T extends ICommunibaseDocument = ICommunibaseDocument>(objectType: CommunibaseEntityType, selector: {}, params?: ICommunibaseParams): Promise<T[]>;
|
108 | /**
|
109 | * This will save a document in Communibase. When a _id-field is found, this document will be updated
|
110 | *
|
111 | * @param objectType
|
112 | * @param object - the to-be-saved object data
|
113 | * @returns promise for object (the created or updated object)
|
114 | */
|
115 | update<T extends ICommunibaseDocument = ICommunibaseDocument>(objectType: CommunibaseEntityType, object: T): Promise<T>;
|
116 | /**
|
117 | * Delete something from Communibase
|
118 | *
|
119 | * @param objectType
|
120 | * @param objectId
|
121 | * @returns promise (for null)
|
122 | */
|
123 | destroy(objectType: CommunibaseEntityType, objectId: string): Promise<null>;
|
124 | /**
|
125 | * Undelete something from Communibase
|
126 | *
|
127 | * @param objectType
|
128 | * @param objectId
|
129 | * @returns promise (for null)
|
130 | */
|
131 | undelete(objectType: CommunibaseEntityType, objectId: string): Promise<ICommunibaseDocument>;
|
132 | /**
|
133 | * Get a Promise for a Read stream for a File stored in Communibase
|
134 | *
|
135 | * @param fileId
|
136 | * @returns {Stream} see http://nodejs.org/api/stream.html#stream_stream
|
137 | */
|
138 | createReadStream(fileId: string): ReadableStream;
|
139 | /**
|
140 | * Uploads the contents of the resource to Communibase (updates or creates a new File)
|
141 | *
|
142 | * Note `File` is not versioned
|
143 | *
|
144 | * @param {Stream|Buffer|String} resource a stream, buffer or a content-string
|
145 | * @param {String} name The binary name (i.e. a filename)
|
146 | * @param {String} destinationPath The "directory location"
|
147 | * @param {String} id The `File` id to replace the contents of (optional; if not set then creates a new File)
|
148 | *
|
149 | * @returns {Promise}
|
150 | */
|
151 | updateBinary(resource: ReadableStream | Buffer | string, name: string, destinationPath: string, id?: string): Promise<ICommunibaseDocument>;
|
152 | /**
|
153 | * Get a new Communibase Connector, may be with a different API key
|
154 | *
|
155 | * @param apiKey
|
156 | * @returns {Connector}
|
157 | */
|
158 | clone(apiKey: string): Connector;
|
159 | /**
|
160 | * Get the history information for a certain type of object
|
161 | *
|
162 | * VersionInformation: {
|
163 | * "_id": "ObjectId",
|
164 | * "updatedAt": "Date",
|
165 | * "updatedBy": "string"
|
166 | * }
|
167 | *
|
168 | * @param {string} objectType
|
169 | * @param {string} objectId
|
170 | * @returns promise for VersionInformation[]
|
171 | */
|
172 | getHistory(objectType: CommunibaseEntityType, objectId: string): Promise<ICommunibaseVersionInformation[]>;
|
173 | /**
|
174 | *
|
175 | * @param {string} objectType
|
176 | * @param {Object} selector
|
177 | * @returns promise for VersionInformation[]
|
178 | */
|
179 | historySearch(objectType: CommunibaseEntityType, selector: {}): Promise<ICommunibaseVersionInformation[]>;
|
180 | /**
|
181 | * Get a single object by a DocumentReference-object. A DocumentReference object looks like
|
182 | * {
|
183 | * rootDocumentId: '524aca8947bd91000600000c',
|
184 | * rootDocumentEntityType: 'Person',
|
185 | * path: [
|
186 | * {
|
187 | * field: 'addresses',
|
188 | * objectId: '53440792463cda7161000003'
|
189 | * }, ...
|
190 | * ]
|
191 | * }
|
192 | *
|
193 | * @param {object} ref - DocumentReference style, see above
|
194 | * @param {object} parentDocument
|
195 | * @return {Promise} for referred object
|
196 | */
|
197 | getByRef(ref: ICommunibaseDocumentReference, parentDocument: ICommunibaseDocument): Promise<ICommunibaseDocument>;
|
198 | /**
|
199 | *
|
200 | * @param {string} objectType - E.g. Event
|
201 | * @param {array} aggregationPipeline - E.g. A MongoDB-specific Aggregation Pipeline
|
202 | * @see http://docs.mongodb.org/manual/core/aggregation-pipeline/
|
203 | *
|
204 | * E.g. [
|
205 | * { "$match": { "_id": {"$ObjectId": "52f8fb85fae15e6d0806e7c7"} } },
|
206 | * { "$unwind": "$participants" },
|
207 | * { "$group": { "_id": "$_id", "participantCount": { "$sum": 1 } } }
|
208 | * ]
|
209 | */
|
210 | aggregate(objectType: CommunibaseEntityType, aggregationPipeline: Array<{}>): Promise<Array<{}>>;
|
211 | /**
|
212 | * Finalize an invoice by its ID
|
213 | *
|
214 | * @param invoiceId
|
215 | * @returns {*}
|
216 | */
|
217 | finalizeInvoice(invoiceId: string): Promise<ICommunibaseDocument>;
|
218 | /**
|
219 | * @param communibaseAdministrationId
|
220 | * @param socketServiceUrl
|
221 | */
|
222 | enableCache(communibaseAdministrationId: string, socketServiceUrl: string): void;
|
223 | private queueSearch;
|
224 | /**
|
225 | * Bare boned retrieval by objectIds
|
226 | * @returns {Promise}
|
227 | */
|
228 | private privateGetByIds;
|
229 | /**
|
230 | * Default object retrieval: should provide cachable objects
|
231 | */
|
232 | private spoolQueue;
|
233 | }
|
234 | declare const _default: Connector;
|
235 | export default _default;
|