@@ -84,8 +84,8 @@
Loading
84 84
    return new SetOp(this._value);
85 85
  }
86 86
87 -
  toJSON() {
88 -
    return encode(this._value, false, true);
87 +
  toJSON(offline?: boolean) {
88 +
    return encode(this._value, false, true, undefined, offline);
89 89
  }
90 90
}
91 91

@@ -273,8 +273,8 @@
Loading
273 273
    return dirty;
274 274
  }
275 275
276 -
  _toFullJSON(seen?: Array<any>): AttributeMap {
277 -
    const json: { [key: string]: mixed } = this.toJSON(seen);
276 +
  _toFullJSON(seen?: Array<any>, offline?: boolean): AttributeMap {
277 +
    const json: { [key: string]: mixed } = this.toJSON(seen, offline);
278 278
    json.__type = 'Object';
279 279
    json.className = this.className;
280 280
    return json;
@@ -434,7 +434,7 @@
Loading
434 434
   * Returns a JSON version of the object suitable for saving to Parse.
435 435
   * @return {Object}
436 436
   */
437 -
  toJSON(seen: Array<any> | void): AttributeMap {
437 +
  toJSON(seen: Array<any> | void, offline?: boolean): AttributeMap {
438 438
    const seenEntry = this.id ? this.className + ':' + this.id : this;
439 439
    seen = seen || [seenEntry];
440 440
    const json = {};
@@ -443,12 +443,12 @@
Loading
443 443
      if ((attr === 'createdAt' || attr === 'updatedAt') && attrs[attr].toJSON) {
444 444
        json[attr] = attrs[attr].toJSON();
445 445
      } else {
446 -
        json[attr] = encode(attrs[attr], false, false, seen);
446 +
        json[attr] = encode(attrs[attr], false, false, seen, offline);
447 447
      }
448 448
    }
449 449
    const pending = this._getPendingOps();
450 450
    for (const attr in pending[0]) {
451 -
      json[attr] = pending[0][attr].toJSON();
451 +
      json[attr] = pending[0][attr].toJSON(offline);
452 452
    }
453 453
454 454
    if (this.id) {
@@ -550,6 +550,21 @@
Loading
550 550
    };
551 551
  }
552 552
553 +
  /**
554 +
   * Gets a Pointer referencing this Object.
555 +
   * @return {Pointer}
556 +
   */
557 +
  toOfflinePointer(): Pointer {
558 +
    if (!this._localId) {
559 +
      throw new Error('Cannot create a offline pointer to a saved ParseObject');
560 +
    }
561 +
    return {
562 +
      __type: 'Object',
563 +
      className: this.className,
564 +
      _localId: this._localId
565 +
    };
566 +
  }
567 +
553 568
  /**
554 569
   * Gets the value of an attribute.
555 570
   * @param {String} attr The string name of an attribute.

@@ -79,7 +79,7 @@
Loading
79 79
    for (const parent of objects) {
80 80
      const children = this._getChildren(parent);
81 81
      const parentKey = this.getKeyForObject(parent);
82 -
      const json = parent._toFullJSON();
82 +
      const json = parent._toFullJSON(undefined, true);
83 83
      if (parent._localId) {
84 84
        json._localId = parent._localId;
85 85
      }
@@ -139,7 +139,7 @@
Loading
139 139
  // Retrieve all pointer fields from object recursively
140 140
  _getChildren(object: ParseObject) {
141 141
    const encountered = {};
142 -
    const json = object._toFullJSON();
142 +
    const json = object._toFullJSON(undefined, true);
143 143
    for (const key in json) {
144 144
      if (json[key] && json[key].__type && json[key].__type === 'Object') {
145 145
        this._traverse(json[key], encountered);

@@ -19,7 +19,7 @@
Loading
19 19
20 20
const toString = Object.prototype.toString;
21 21
22 -
function encode(value: mixed, disallowObjects: boolean, forcePointers: boolean, seen: Array<mixed>): any {
22 +
function encode(value: mixed, disallowObjects: boolean, forcePointers: boolean, seen: Array<mixed>, offline: boolean): any {
23 23
  if (value instanceof ParseObject) {
24 24
    if (disallowObjects) {
25 25
      throw new Error('Parse Objects not allowed here');
@@ -31,10 +31,13 @@
Loading
31 31
      value.dirty() ||
32 32
      Object.keys(value._getServerData()).length < 1
33 33
    ) {
34 +
      if (offline && value._getId().startsWith('local')) {
35 +
        return value.toOfflinePointer();
36 +
      }
34 37
      return value.toPointer();
35 38
    }
36 39
    seen = seen.concat(seenEntry);
37 -
    return value._toFullJSON(seen);
40 +
    return value._toFullJSON(seen, offline);
38 41
  }
39 42
  if (value instanceof Op ||
40 43
      value instanceof ParseACL ||
@@ -62,14 +65,14 @@
Loading
62 65
63 66
  if (Array.isArray(value)) {
64 67
    return value.map((v) => {
65 -
      return encode(v, disallowObjects, forcePointers, seen);
68 +
      return encode(v, disallowObjects, forcePointers, seen, offline);
66 69
    });
67 70
  }
68 71
69 72
  if (value && typeof value === 'object') {
70 73
    const output = {};
71 74
    for (const k in value) {
72 -
      output[k] = encode(value[k], disallowObjects, forcePointers, seen);
75 +
      output[k] = encode(value[k], disallowObjects, forcePointers, seen, offline);
73 76
    }
74 77
    return output;
75 78
  }
@@ -77,6 +80,6 @@
Loading
77 80
  return value;
78 81
}
79 82
80 -
export default function(value: mixed, disallowObjects?: boolean, forcePointers?: boolean, seen?: Array<mixed>): any {
81 -
  return encode(value, !!disallowObjects, !!forcePointers, seen || []);
83 +
export default function(value: mixed, disallowObjects?: boolean, forcePointers?: boolean, seen?: Array<mixed>, offline?: boolean): any {
84 +
  return encode(value, !!disallowObjects, !!forcePointers, seen || [], offline);
82 85
}

@@ -1299,6 +1299,7 @@
Loading
1299 1299
   * This may be slow for large datasets.
1300 1300
   * @param {String} key The key that the string to match is stored in.
1301 1301
   * @param {RegExp} regex The regular expression pattern to match.
1302 +
   * @param {String} modifiers The regular expression mode.
1302 1303
   * @return {Parse.Query} Returns the query, so you can chain this call.
1303 1304
   */
1304 1305
  matches(key: string, regex: RegExp, modifiers: string): ParseQuery {
Files Coverage
src 92.38%
Project Totals (54 files) 92.38%

No yaml found.

Create your codecov.yml to customize your Codecov experience

Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading