88
99/**
1010 * Kuzzle handles documents either as realtime messages or as stored documents.
11- * KuzzleDocument is the object representation of one of these documents.
11+ * Document is the object representation of one of these documents.
1212 *
1313 * Notes:
1414 * - this constructor may be called either with a documentId, a content, neither or both.
1515 * - providing a documentID to the constructor will automatically call refresh, unless a content is also provided
1616 *
1717 *
18- * @param {object } kuzzleDataCollection - an instanciated KuzzleDataCollection object
18+ * @param {object } kuzzleDataCollection - an instanciated Collection object
1919 * @param {string } [documentId] - ID of an existing document
2020 * @param {object } [content] - Initializes this document with the provided content
2121 * @constructor
2222 */
23- function KuzzleDocument ( kuzzleDataCollection , documentId , content ) {
23+ function Document ( kuzzleDataCollection , documentId , content ) {
2424 Object . defineProperties ( this , {
2525 // read-only properties
2626 collection : {
@@ -99,7 +99,7 @@ function KuzzleDocument(kuzzleDataCollection, documentId, content) {
9999 *
100100 * @return {object } JSON object representing this document
101101 */
102- KuzzleDocument . prototype . serialize = function ( ) {
102+ Document . prototype . serialize = function ( ) {
103103 var
104104 data = { } ;
105105
@@ -119,7 +119,7 @@ KuzzleDocument.prototype.serialize = function () {
119119 *
120120 * @return {string } serialized version of this object
121121 */
122- KuzzleDocument . prototype . toString = function ( ) {
122+ Document . prototype . toString = function ( ) {
123123 return JSON . stringify ( this . serialize ( ) ) ;
124124} ;
125125
@@ -134,7 +134,7 @@ KuzzleDocument.prototype.toString = function () {
134134 * @param {responseCallback } [cb] - Handles the query response
135135 * @returns {* } this
136136 */
137- KuzzleDocument . prototype . delete = function ( options , cb ) {
137+ Document . prototype . delete = function ( options , cb ) {
138138 var self = this ;
139139
140140 if ( ! cb && typeof options === 'function' ) {
@@ -143,7 +143,7 @@ KuzzleDocument.prototype.delete = function (options, cb) {
143143 }
144144
145145 if ( ! self . id ) {
146- throw new Error ( 'KuzzleDocument .delete: cannot delete a document without a document ID' ) ;
146+ throw new Error ( 'Document .delete: cannot delete a document without a document ID' ) ;
147147 }
148148
149149 this . kuzzle . query ( this . dataCollection . buildQueryArgs ( 'document' , 'delete' ) , this . serialize ( ) , options , cb && function ( err ) {
@@ -158,7 +158,7 @@ KuzzleDocument.prototype.delete = function (options, cb) {
158158 * @param {responseCallback } [cb] - Handles the query response
159159 * @returns {* } this
160160 */
161- KuzzleDocument . prototype . refresh = function ( options , cb ) {
161+ Document . prototype . refresh = function ( options , cb ) {
162162 var self = this ;
163163
164164 if ( ! cb && typeof options === 'function' ) {
@@ -167,10 +167,10 @@ KuzzleDocument.prototype.refresh = function (options, cb) {
167167 }
168168
169169 if ( ! self . id ) {
170- throw new Error ( 'KuzzleDocument .refresh: cannot retrieve a document if no ID has been provided' ) ;
170+ throw new Error ( 'Document .refresh: cannot retrieve a document if no ID has been provided' ) ;
171171 }
172172
173- this . kuzzle . callbackRequired ( 'KuzzleDocument .refresh' , cb ) ;
173+ this . kuzzle . callbackRequired ( 'Document .refresh' , cb ) ;
174174
175175 self . kuzzle . query ( self . dataCollection . buildQueryArgs ( 'document' , 'get' ) , { _id : self . id } , options , function ( error , res ) {
176176 var newDocument ;
@@ -179,7 +179,7 @@ KuzzleDocument.prototype.refresh = function (options, cb) {
179179 return cb ( error ) ;
180180 }
181181
182- newDocument = new KuzzleDocument ( self . dataCollection , self . id , res . result . _source ) ;
182+ newDocument = new Document ( self . dataCollection , self . id , res . result . _source ) ;
183183 newDocument . version = res . result . _version ;
184184
185185 cb ( null , newDocument ) ;
@@ -201,7 +201,7 @@ KuzzleDocument.prototype.refresh = function (options, cb) {
201201 * @param {responseCallback } [cb] - Handles the query response
202202 * @returns {* } this
203203 */
204- KuzzleDocument . prototype . save = function ( options , cb ) {
204+ Document . prototype . save = function ( options , cb ) {
205205 var
206206 data = this . serialize ( ) ,
207207 self = this ;
@@ -237,7 +237,7 @@ KuzzleDocument.prototype.save = function (options, cb) {
237237 * @param {object } [options] - Optional parameters
238238 * @returns {* } this
239239 */
240- KuzzleDocument . prototype . publish = function ( options ) {
240+ Document . prototype . publish = function ( options ) {
241241 var data = this . serialize ( ) ;
242242
243243 this . kuzzle . query ( this . dataCollection . buildQueryArgs ( 'realtime' , 'publish' ) , data , options ) ;
@@ -252,7 +252,7 @@ KuzzleDocument.prototype.publish = function (options) {
252252 * @param {object } data - New content
253253 * @param {boolean } replace - if true: replace this document content with the provided data
254254 */
255- KuzzleDocument . prototype . setContent = function ( data , replace ) {
255+ Document . prototype . setContent = function ( data , replace ) {
256256 var self = this ;
257257
258258 if ( replace ) {
@@ -274,18 +274,18 @@ KuzzleDocument.prototype.setContent = function (data, replace) {
274274 * @param {object } [options] - subscription options
275275 * @param {responseCallback } cb - callback that will be called each time a change has been detected on this document
276276 */
277- KuzzleDocument . prototype . subscribe = function ( options , cb ) {
277+ Document . prototype . subscribe = function ( options , cb ) {
278278 var filters ;
279279
280280 if ( options && ! cb && typeof options === 'function' ) {
281281 cb = options ;
282282 options = null ;
283283 }
284284
285- this . kuzzle . callbackRequired ( 'KuzzleDocument .subscribe' , cb ) ;
285+ this . kuzzle . callbackRequired ( 'Document .subscribe' , cb ) ;
286286
287287 if ( ! this . id ) {
288- throw new Error ( 'KuzzleDocument .subscribe: cannot subscribe to a document if no ID has been provided' ) ;
288+ throw new Error ( 'Document .subscribe: cannot subscribe to a document if no ID has been provided' ) ;
289289 }
290290
291291 filters = { ids : { values : [ this . id ] } } ;
@@ -302,10 +302,10 @@ KuzzleDocument.prototype.subscribe = function (options, cb) {
302302 * @param content - new headers content
303303 * @param [replace] - default: false = append the content. If true: replace the current headers with tj
304304 */
305- KuzzleDocument . prototype . setHeaders = function ( content , replace ) {
305+ Document . prototype . setHeaders = function ( content , replace ) {
306306 this . kuzzle . setHeaders . call ( this , content , replace ) ;
307307 return this ;
308308} ;
309309
310310
311- module . exports = KuzzleDocument ;
311+ module . exports = Document ;
0 commit comments