aurelia-json
Advanced tools
Comparing version 0.4.1 to 0.5.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var metadataKeys = require("./metadata-keys"); | ||
@@ -3,0 +4,0 @@ function jsonIgnore() { |
@@ -7,5 +7,6 @@ import { FrameworkConfiguration } from "aurelia-framework"; | ||
import { JsonDecoder } from "./json-decoder"; | ||
import { JsonMessageContentInterceptor } from "./json-message-content-interceptor"; | ||
import { JsonMultipartRelatedInterceptor } from "./json-multipart-related-interceptor"; | ||
export declare function configure(frameworkConfiguration: FrameworkConfiguration, pluginConfiguration: Function): void; | ||
export { JsonSchema, JsonPatch, JsonPointer, JsonEncoder, JsonDecoder, JsonMultipartRelatedInterceptor }; | ||
export { JsonSchema, JsonPatch, JsonPointer, JsonEncoder, JsonDecoder, JsonMessageContentInterceptor, JsonMultipartRelatedInterceptor }; | ||
export * from "./decorators"; |
@@ -5,2 +5,3 @@ "use strict"; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var aurelia_http_client_1 = require("aurelia-http-client"); | ||
@@ -17,2 +18,4 @@ var json_schema_1 = require("./json-schema"); | ||
exports.JsonDecoder = json_decoder_1.JsonDecoder; | ||
var json_message_content_interceptor_1 = require("./json-message-content-interceptor"); | ||
exports.JsonMessageContentInterceptor = json_message_content_interceptor_1.JsonMessageContentInterceptor; | ||
var json_multipart_related_interceptor_1 = require("./json-multipart-related-interceptor"); | ||
@@ -23,8 +26,3 @@ exports.JsonMultipartRelatedInterceptor = json_multipart_related_interceptor_1.JsonMultipartRelatedInterceptor; | ||
var httpClient = container.get(aurelia_http_client_1.HttpClient); | ||
var jsonDecoder = new json_decoder_1.JsonDecoder(); | ||
container.registerTransient(json_encoder_1.JsonEncoder); | ||
container.registerInstance(json_decoder_1.JsonDecoder, jsonDecoder); | ||
if (pluginConfiguration) { | ||
pluginConfiguration(jsonDecoder); | ||
} | ||
httpClient.configure(function (x) { return x.withInterceptor(new json_message_content_interceptor_1.JsonMessageContentInterceptor()); }); | ||
} | ||
@@ -31,0 +29,0 @@ exports.configure = configure; |
@@ -11,2 +11,3 @@ "use strict"; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var aurelia_dependency_injection_1 = require("aurelia-dependency-injection"); | ||
@@ -25,3 +26,3 @@ var type_binder_1 = require("type-binder"); | ||
var object = JSON.parse(json); | ||
return typeof type["fromJSON"] === "function" | ||
return type && typeof type["fromJSON"] === "function" | ||
? type["fromJSON"](object, this, this.typeBinder) | ||
@@ -28,0 +29,0 @@ : (_a = this.typeBinder).bind.apply(_a, [object, type].concat(generics)); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var metadataKeys = require("./metadata-keys"); | ||
@@ -21,3 +22,3 @@ var JsonEncoder = (function () { | ||
else if (typeof value === "string") { | ||
return JsonEncoder.START_STRING + value + JsonEncoder.END_STRING; | ||
return JSON.stringify(value); | ||
} | ||
@@ -24,0 +25,0 @@ else if (typeof value["toJSON"] === "function") { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var aurelia_http_utils_1 = require("aurelia-http-utils"); | ||
@@ -3,0 +4,0 @@ var json_encoder_1 = require("./json-encoder"); |
@@ -14,3 +14,3 @@ export declare class JsonPatch { | ||
toJSON(): any; | ||
static diff<T>(target: T, properties?: string[], patch?: JsonPatch, prefix?: string, separator?: string, wildcard?: string): JsonPatch; | ||
static diff<T>(target: T, properties?: string[], patch?: JsonPatch, prefix?: string, separator?: string, wildcard?: string, seen?: Set<Object>): JsonPatch; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var type_binder_1 = require("type-binder"); | ||
@@ -75,3 +76,3 @@ var metadataKeys = require("./metadata-keys"); | ||
}; | ||
JsonPatch.diff = function (target, properties, patch, prefix, separator, wildcard) { | ||
JsonPatch.diff = function (target, properties, patch, prefix, separator, wildcard, seen) { | ||
if (properties === void 0) { properties = Object.keys(target); } | ||
@@ -81,2 +82,4 @@ if (patch === void 0) { patch = new JsonPatch(); } | ||
if (wildcard === void 0) { wildcard = "-"; } | ||
if (seen === void 0) { seen = new Set(); } | ||
seen.add(target); | ||
var _loop_1 = function (key) { | ||
@@ -92,4 +95,4 @@ var currentValue = target[key]; | ||
} | ||
else if (currentValue !== null && typeof currentValue === "object") { | ||
JsonPatch.diff(currentValue, Object.keys(currentValue), patch, [prefix, key].join(separator), separator, wildcard); | ||
else if (currentValue !== null && typeof currentValue === "object" && !seen.has(currentValue)) { | ||
JsonPatch.diff(currentValue, Object.keys(currentValue), patch, [prefix, key].join(separator), separator, wildcard, seen); | ||
} | ||
@@ -112,4 +115,4 @@ } | ||
} | ||
else if (value !== null && typeof value === "object") { | ||
JsonPatch.diff(value, Object.keys(value), patch, pointer, separator, wildcard); | ||
else if (value !== null && typeof value === "object" && !seen.has(value)) { | ||
JsonPatch.diff(value, Object.keys(value), patch, pointer, separator, wildcard, seen); | ||
} | ||
@@ -116,0 +119,0 @@ }); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var JsonPointer = (function () { | ||
@@ -3,0 +4,0 @@ function JsonPointer() { |
"use strict"; | ||
var __extends = (this && this.__extends) || function (d, b) { | ||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var JsonSchema = (function (_super) { | ||
@@ -8,0 +14,0 @@ __extends(JsonSchema, _super); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.jsonIgnore = "json:ignore"; | ||
@@ -3,0 +4,0 @@ exports.serializer = "json:serializer"; |
@@ -11,2 +11,3 @@ "use strict"; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var json_encoder_1 = require("../../main/json-encoder"); | ||
@@ -13,0 +14,0 @@ var decorators_1 = require("../../main/decorators"); |
@@ -11,2 +11,3 @@ "use strict"; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var type_binder_1 = require("type-binder"); | ||
@@ -26,3 +27,3 @@ var json_patch_1 = require("../../main/json-patch"); | ||
__decorate([ | ||
type_binder_1.bind(Bar), type_binder_1.track(), | ||
type_binder_1.bind(function () { return Bar; }), type_binder_1.track(), | ||
__metadata("design:type", Bar) | ||
@@ -70,3 +71,3 @@ ], Foo.prototype, "bar", void 0); | ||
__decorate([ | ||
type_binder_1.bind(Array), | ||
type_binder_1.bind(function () { return Array; }), | ||
type_binder_1.trackIterable(), | ||
@@ -76,4 +77,4 @@ __metadata("design:type", Array) | ||
__decorate([ | ||
type_binder_1.bind(Set), | ||
type_binder_1.generics(Bar), | ||
type_binder_1.bind(function () { return Set; }), | ||
type_binder_1.generics(function () { return Bar; }), | ||
type_binder_1.trackIterable(), | ||
@@ -83,4 +84,4 @@ __metadata("design:type", Set) | ||
__decorate([ | ||
type_binder_1.bind(Map), | ||
type_binder_1.generics(Foo, Bar), | ||
type_binder_1.bind(function () { return Map; }), | ||
type_binder_1.generics(function () { return Foo; }, function () { return Bar; }), | ||
type_binder_1.trackIterable(function (i) { return Array.from(i); }, function (v1, v2) { return v1.every(function (v, i) { return v === v2[i]; }); }), | ||
@@ -87,0 +88,0 @@ __metadata("design:type", Map) |
{ | ||
"name": "aurelia-json", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"description": "A JSON plugin for Aurelia based projects.", | ||
@@ -26,25 +26,25 @@ "keywords": [ | ||
"dependencies": { | ||
"aurelia-dependency-injection": "^1.2.1", | ||
"aurelia-framework": "^1.0.8", | ||
"aurelia-http-client": "^1.0.3", | ||
"aurelia-http-utils": "^0.3.1", | ||
"type-binder": "^0.3.1" | ||
"aurelia-dependency-injection": "^1.3.1", | ||
"aurelia-framework": "^1.1.2", | ||
"aurelia-http-client": "^1.1.1", | ||
"aurelia-http-utils": "^0.4.0", | ||
"type-binder": "^0.4.0" | ||
}, | ||
"devDependencies": { | ||
"@types/jasmine": "^2.5.40", | ||
"babel-preset-es2015": "^6.18.0", | ||
"babel-register": "^6.18.0", | ||
"@types/jasmine": "^2.5.47", | ||
"babel-preset-es2015": "^6.24.1", | ||
"babel-register": "^6.24.1", | ||
"del": "^2.2.2", | ||
"gulp": "^3.9.1", | ||
"gulp-jasmine": "^2.4.2", | ||
"gulp-sass": "^3.0.0", | ||
"gulp-sourcemaps": "^1.9.1", | ||
"gulp-typescript": "^3.1.3", | ||
"jasmine": "^2.5.2", | ||
"jasmine-reporters": "^2.2.0", | ||
"gulp-sass": "^3.1.0", | ||
"gulp-sourcemaps": "^2.6.0", | ||
"gulp-typescript": "^3.1.6", | ||
"jasmine": "^2.5.3", | ||
"jasmine-reporters": "^2.2.1", | ||
"merge2": "^1.0.3", | ||
"run-sequence": "^1.2.2", | ||
"typescript": "^2.1.4", | ||
"typescript": "^2.2.2", | ||
"vinyl-paths": "^2.1.0" | ||
} | ||
} |
@@ -9,2 +9,3 @@ import { FrameworkConfiguration } from "aurelia-framework"; | ||
import { JsonDecoder } from "./json-decoder"; | ||
import { JsonMessageContentInterceptor } from "./json-message-content-interceptor"; | ||
import { JsonMultipartRelatedInterceptor } from "./json-multipart-related-interceptor"; | ||
@@ -15,11 +16,6 @@ | ||
let httpClient: HttpClient = container.get(HttpClient); | ||
let jsonDecoder = new JsonDecoder(); | ||
container.registerTransient(JsonEncoder); | ||
container.registerInstance(JsonDecoder, jsonDecoder); | ||
if (pluginConfiguration) { | ||
pluginConfiguration(jsonDecoder); | ||
} | ||
httpClient.configure(x => x.withInterceptor(new JsonMessageContentInterceptor())); | ||
} | ||
export { JsonSchema, JsonPatch, JsonPointer, JsonEncoder, JsonDecoder, JsonMultipartRelatedInterceptor }; | ||
export { JsonSchema, JsonPatch, JsonPointer, JsonEncoder, JsonDecoder, JsonMessageContentInterceptor, JsonMultipartRelatedInterceptor }; | ||
export * from "./decorators"; |
@@ -16,3 +16,3 @@ | ||
let object = JSON.parse(json); | ||
return typeof type["fromJSON"] === "function" | ||
return type && typeof type["fromJSON"] === "function" | ||
? type["fromJSON"](object, this, this.typeBinder) | ||
@@ -19,0 +19,0 @@ : this.typeBinder.bind(object, type, ...generics); |
@@ -39,3 +39,3 @@ import * as metadataKeys from "./metadata-keys"; | ||
} else if (typeof value === "string") { | ||
return JsonEncoder.START_STRING + value + JsonEncoder.END_STRING; | ||
return JSON.stringify(value); | ||
} else if (typeof value["toJSON"] === "function") { | ||
@@ -42,0 +42,0 @@ return this.encode(value.toJSON(), ignore); |
@@ -84,3 +84,4 @@ import { binderPropertyTrackValue, binderPropertyEntriesValue, binderPropertyTrackCompare, binderPropertyEntries, binderPropertyEntriesCompare } from "type-binder"; | ||
public static diff<T>(target: T, properties: string[] = Object.keys(target), patch: JsonPatch = new JsonPatch(), prefix?: string, separator: string = "/", wildcard: string = "-"): JsonPatch { | ||
public static diff<T>(target: T, properties: string[] = Object.keys(target), patch: JsonPatch = new JsonPatch(), prefix?: string, separator: string = "/", wildcard: string = "-", seen: Set<Object> = new Set()): JsonPatch { | ||
seen.add(target); | ||
for (let key of properties) { | ||
@@ -95,4 +96,4 @@ let currentValue = target[key]; | ||
patch.replace([prefix, key].join(separator), currentValue); | ||
} else if (currentValue !== null && typeof currentValue === "object") { | ||
JsonPatch.diff(currentValue, Object.keys(currentValue), patch, [prefix, key].join(separator), separator, wildcard); | ||
} else if (currentValue !== null && typeof currentValue === "object" && !seen.has(currentValue)) { | ||
JsonPatch.diff(currentValue, Object.keys(currentValue), patch, [prefix, key].join(separator), separator, wildcard, seen); | ||
} | ||
@@ -112,4 +113,4 @@ } else if (currentValue !== null && Reflect.hasMetadata(binderPropertyEntriesValue, target, key)) { | ||
patch.replace(pointer, currentEntries[index], Reflect.getMetadata(metadataKeys.serializer, target, key)); | ||
} else if (value !== null && typeof value === "object") { | ||
JsonPatch.diff(value, Object.keys(value), patch, pointer, separator, wildcard); | ||
} else if (value !== null && typeof value === "object" && !seen.has(value)) { | ||
JsonPatch.diff(value, Object.keys(value), patch, pointer, separator, wildcard, seen); | ||
} | ||
@@ -116,0 +117,0 @@ }); |
@@ -10,3 +10,3 @@ import { TypeBinder, bind, generics, track, trackIterable } from "type-binder"; | ||
b: number; | ||
@bind(Bar) @track() bar: Bar; | ||
@bind(() => Bar) @track() bar: Bar; | ||
} | ||
@@ -45,13 +45,13 @@ | ||
class Bag { | ||
@bind(Array) | ||
@bind(() => Array) | ||
@trackIterable() | ||
numbers: number[]; | ||
@bind(Set) | ||
@generics(Bar) | ||
@bind(() => Set) | ||
@generics(() => Bar) | ||
@trackIterable() | ||
bars: Set<Bar>; | ||
@bind(Map) | ||
@generics(Foo, Bar) | ||
@bind(() => Map) | ||
@generics(() => Foo, () => Bar) | ||
@trackIterable<[Foo, Bar], Map<Foo, Bar>>(i => Array.from(i), (v1, v2) => v1.every((v, i) => v === v2[i])) | ||
@@ -58,0 +58,0 @@ foobars: Map<Foo, Bar>; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
87682
56
1023
+ Addedaurelia-http-utils@0.4.0(transitive)
+ Addedtype-binder@0.4.0(transitive)
- Removedaurelia-http-utils@0.3.1(transitive)
- Removedtype-binder@0.3.1(transitive)
Updatedaurelia-framework@^1.1.2
Updatedaurelia-http-client@^1.1.1
Updatedaurelia-http-utils@^0.4.0
Updatedtype-binder@^0.4.0