You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ko...@apache.org on 2014/10/20 09:39:14 UTC
[1/5] git commit: [OLINGO-440] Remove odatajs.js file (not needed)
Repository: olingo-odata4-js
Updated Branches:
refs/heads/master d37c4df92 -> 87e35975d
[OLINGO-440] Remove odatajs.js file (not needed)
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/commit/5e973c8d
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/tree/5e973c8d
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/diff/5e973c8d
Branch: refs/heads/master
Commit: 5e973c8df5404bbe58edbdaa380bda8c75a53b36
Parents: d37c4df
Author: Sven Kobler <sv...@sap.com>
Authored: Thu Sep 25 12:35:47 2014 +0200
Committer: Sven Kobler <sv...@sap.com>
Committed: Mon Oct 20 09:34:59 2014 +0200
----------------------------------------------------------------------
odatajs/Gruntfile.js | 18 +++++++++++++++++-
odatajs/src/index.js | 12 +++++++++++-
odatajs/src/lib/cache.js | 8 ++++----
odatajs/src/lib/cache/source.js | 2 +-
odatajs/src/lib/odata/batch.js | 2 +-
odatajs/src/lib/odata/handler.js | 2 +-
odatajs/src/lib/odata/json.js | 2 +-
odatajs/src/lib/odata/metadata.js | 4 ++--
odatajs/src/lib/odata/net.js | 2 +-
odatajs/src/lib/odata/utils.js | 2 +-
odatajs/src/lib/odatajs.js | 32 --------------------------------
odatajs/src/lib/store/dom.js | 2 +-
odatajs/src/lib/store/indexeddb.js | 2 +-
odatajs/src/lib/store/memory.js | 2 +-
14 files changed, 43 insertions(+), 49 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5e973c8d/odatajs/Gruntfile.js
----------------------------------------------------------------------
diff --git a/odatajs/Gruntfile.js b/odatajs/Gruntfile.js
index b3c9cee..5b66d60 100644
--- a/odatajs/Gruntfile.js
+++ b/odatajs/Gruntfile.js
@@ -62,6 +62,11 @@ module.exports = function(grunt) {
src: 'build/lib/<%= artifactname %>.min.js',
dest: 'build/lib/<%= artifactname %>.min.js',
},
+ src: {
+ src: ['src/**/*.js'],
+ dest: 'build/lib/<%= artifactname %>.js',
+ },
+
},
"jsdoc" : { // generate documentation
src : {
@@ -79,6 +84,16 @@ module.exports = function(grunt) {
dest: 'build/'
}
},
+ 'copy' : {
+ 'to-latest' : {
+ files: [
+ {
+ src :'build/lib/<%= artifactname %>.js',
+ dest: 'build/lib/odatajs-latest.js' },
+ ]
+ }
+
+ },
"npm-clean": {
options: {force: true},
"build": {
@@ -155,7 +170,8 @@ module.exports = function(grunt) {
grunt.registerTask('doc-test', ['clearEnv', 'jsdoc:test']);
// Build the odatajs library
- grunt.registerTask('build', ['clean:lib','browserify:src', 'uglify:build', 'concat', 'nugetpack']);
+ grunt.registerTask('build', ['clean:lib','browserify:src', 'uglify:build', 'concat:licence','concat:licence_min','copy:to-latest','nugetpack']);
+ grunt.registerTask('build2', ['clean:lib','concat:src', 'uglify:build', 'concat:licence','concat:licence_min','nugetpack']);
grunt.registerTask('test-browser', ['configureProxies:test-browser', 'connect:test-browser']);
grunt.registerTask('test-node', ['node-qunit:default-tests']);
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5e973c8d/odatajs/src/index.js
----------------------------------------------------------------------
diff --git a/odatajs/src/index.js b/odatajs/src/index.js
index a2b71be..42615d3 100644
--- a/odatajs/src/index.js
+++ b/odatajs/src/index.js
@@ -17,7 +17,17 @@
* under the License.
*/
-var odatajs = require('./lib/odatajs.js');
+var odatajs = {};
+
+odatajs.version = {
+ major: 1,
+ minor: 1,
+ build: 1
+};
+
+odatajs.deferred = require('./lib/odatajs/deferred.js');
+odatajs.utils = require('./lib/odatajs/utils.js');
+odatajs.xml = require('./lib/odatajs/xml.js');
odatajs.oData = require('./lib/odata.js');
odatajs.store = require('./lib/store.js');
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5e973c8d/odatajs/src/lib/cache.js
----------------------------------------------------------------------
diff --git a/odatajs/src/lib/cache.js b/odatajs/src/lib/cache.js
index cc047f0..92a740d 100644
--- a/odatajs/src/lib/cache.js
+++ b/odatajs/src/lib/cache.js
@@ -19,10 +19,10 @@
/** @module cache */
-var odatajs = require('./odatajs.js');
-var utils = odatajs.utils;
-var deferred = odatajs.deferred;
-var storeReq = odatajs.store;
+//var odatajs = require('./odatajs/utils.js');
+var utils = require('./odatajs/utils.js');
+var deferred = require('./odatajs/deferred.js');
+var storeReq = require('./store.js');
var cacheSource = require('./cache/source');
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5e973c8d/odatajs/src/lib/cache/source.js
----------------------------------------------------------------------
diff --git a/odatajs/src/lib/cache/source.js b/odatajs/src/lib/cache/source.js
index e459157..eccf5d9 100644
--- a/odatajs/src/lib/cache/source.js
+++ b/odatajs/src/lib/cache/source.js
@@ -19,7 +19,7 @@
/** @module cache/source */
-var utils = require("./../odatajs.js").utils;
+var utils = require("./../odatajs/utils.js");
var odataRequest = require("./../odata.js");
var parseInt10 = utils.parseInt10;
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5e973c8d/odatajs/src/lib/odata/batch.js
----------------------------------------------------------------------
diff --git a/odatajs/src/lib/odata/batch.js b/odatajs/src/lib/odata/batch.js
index 517e3a8..59fb1f8 100644
--- a/odatajs/src/lib/odata/batch.js
+++ b/odatajs/src/lib/odata/batch.js
@@ -19,7 +19,7 @@
/** @module odata/batch */
-var utils = require('./../odatajs.js').utils;
+var utils = require('./../odatajs/utils.js');
var odataUtils = require('./utils.js');
var odataHandler = require('./handler.js');
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5e973c8d/odatajs/src/lib/odata/handler.js
----------------------------------------------------------------------
diff --git a/odatajs/src/lib/odata/handler.js b/odatajs/src/lib/odata/handler.js
index 876dc37..d2b62d4 100644
--- a/odatajs/src/lib/odata/handler.js
+++ b/odatajs/src/lib/odata/handler.js
@@ -20,7 +20,7 @@
/** @module odata/handler */
-var utils = require('./../odatajs.js').utils;
+var utils = require('./../odatajs/utils.js');
var oDataUtils = require('./utils.js');
// Imports.
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5e973c8d/odatajs/src/lib/odata/json.js
----------------------------------------------------------------------
diff --git a/odatajs/src/lib/odata/json.js b/odatajs/src/lib/odata/json.js
index 864ead4..d003e2b 100644
--- a/odatajs/src/lib/odata/json.js
+++ b/odatajs/src/lib/odata/json.js
@@ -21,7 +21,7 @@
-var utils = require('./../odatajs.js').utils;
+var utils = require('./../odatajs/utils.js');
var oDataUtils = require('./utils.js');
var oDataHandler = require('./handler.js');
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5e973c8d/odatajs/src/lib/odata/metadata.js
----------------------------------------------------------------------
diff --git a/odatajs/src/lib/odata/metadata.js b/odatajs/src/lib/odata/metadata.js
index 5a106e7..fb34286 100644
--- a/odatajs/src/lib/odata/metadata.js
+++ b/odatajs/src/lib/odata/metadata.js
@@ -19,8 +19,8 @@
/** @module odata/metadata */
-var utils = require('./../odatajs.js').utils;
-var oDSxml = require('./../odatajs.js').xml;
+var utils = require('./../odatajs/utils.js');
+var oDSxml = require('./../odatajs/xml.js');
var odataHandler = require('./handler.js');
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5e973c8d/odatajs/src/lib/odata/net.js
----------------------------------------------------------------------
diff --git a/odatajs/src/lib/odata/net.js b/odatajs/src/lib/odata/net.js
index 5c7fa41..0dbbce0 100644
--- a/odatajs/src/lib/odata/net.js
+++ b/odatajs/src/lib/odata/net.js
@@ -21,7 +21,7 @@
-var utils = require('./../odatajs.js').utils;
+var utils = require('./../odatajs/utils.js');
// Imports.
var defined = utils.defined;
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5e973c8d/odatajs/src/lib/odata/utils.js
----------------------------------------------------------------------
diff --git a/odatajs/src/lib/odata/utils.js b/odatajs/src/lib/odata/utils.js
index 0f84f2a..b728f14 100644
--- a/odatajs/src/lib/odata/utils.js
+++ b/odatajs/src/lib/odata/utils.js
@@ -18,7 +18,7 @@
*/
/** @module odata/utils */
-var utils = require('./../odatajs.js').utils;
+var utils = require('./../odatajs/utils.js');
// Imports
var assigned = utils.assigned;
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5e973c8d/odatajs/src/lib/odatajs.js
----------------------------------------------------------------------
diff --git a/odatajs/src/lib/odatajs.js b/odatajs/src/lib/odatajs.js
deleted file mode 100644
index fcd2dc7..0000000
--- a/odatajs/src/lib/odatajs.js
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/** @module datajs */
-
-//expose all external usable functions via self.apiFunc = function
-exports.version = {
- major: 1,
- minor: 1,
- build: 1
-};
-
-exports.deferred = require('./odatajs/deferred.js');
-exports.utils = require('./odatajs/utils.js');
-exports.xml = require('./odatajs/xml.js');
-
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5e973c8d/odatajs/src/lib/store/dom.js
----------------------------------------------------------------------
diff --git a/odatajs/src/lib/store/dom.js b/odatajs/src/lib/store/dom.js
index a56e5cc..ca9d27c 100644
--- a/odatajs/src/lib/store/dom.js
+++ b/odatajs/src/lib/store/dom.js
@@ -21,7 +21,7 @@
-var utils = require('./../odatajs.js').utils;
+var utils = require('./../odatajs/utils.js');
// Imports.
var throwErrorCallback = utils.throwErrorCallback;
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5e973c8d/odatajs/src/lib/store/indexeddb.js
----------------------------------------------------------------------
diff --git a/odatajs/src/lib/store/indexeddb.js b/odatajs/src/lib/store/indexeddb.js
index 5e82eb2..5c17816 100644
--- a/odatajs/src/lib/store/indexeddb.js
+++ b/odatajs/src/lib/store/indexeddb.js
@@ -18,7 +18,7 @@
*/
/** @module store/indexeddb */
-var utils = require('./../odatajs.js').utils;
+var utils = require('./../odatajs/utils.js');
// Imports.
var throwErrorCallback = utils.throwErrorCallback;
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5e973c8d/odatajs/src/lib/store/memory.js
----------------------------------------------------------------------
diff --git a/odatajs/src/lib/store/memory.js b/odatajs/src/lib/store/memory.js
index 00280d0..08ddafe 100644
--- a/odatajs/src/lib/store/memory.js
+++ b/odatajs/src/lib/store/memory.js
@@ -20,7 +20,7 @@
/** @module store/memory */
-var utils = require('./../odatajs.js').utils;
+var utils = require('./../odatajs/utils.js');
// Imports.
var throwErrorCallback = utils.throwErrorCallback;
[2/5] [OLINGO-442] Create packaging tool and remove browserify
Posted by ko...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/87e35975/olingojs-4.0.0-beta-01.exports.json
----------------------------------------------------------------------
diff --git a/olingojs-4.0.0-beta-01.exports.json b/olingojs-4.0.0-beta-01.exports.json
new file mode 100644
index 0000000..0f9471a
--- /dev/null
+++ b/olingojs-4.0.0-beta-01.exports.json
@@ -0,0 +1,917 @@
+{
+ "version": {
+ "major": 1,
+ "minor": 1,
+ "build": 1
+ },
+ "deferred": {},
+ "utils": {},
+ "xml": {
+ "http": "http://",
+ "w3org": "http://www.w3.org/",
+ "xmlNS": "http://www.w3.org/XML/1998/namespace",
+ "xmlnsNS": "http://www.w3.org/2000/xmlns/"
+ },
+ "oData": {
+ "utils": {
+ "EDM_BINARY": "Edm.Binary",
+ "EDM_BOOLEAN": "Edm.Boolean",
+ "EDM_BYTE": "Edm.Byte",
+ "EDM_DATE": "Edm.Date",
+ "EDM_DATETIMEOFFSET": "Edm.DateTimeOffset",
+ "EDM_DURATION": "Edm.Duration",
+ "EDM_DECIMAL": "Edm.Decimal",
+ "EDM_DOUBLE": "Edm.Double",
+ "EDM_GEOGRAPHY": "Edm.Geography",
+ "EDM_GEOGRAPHY_POINT": "Edm.GeographyPoint",
+ "EDM_GEOGRAPHY_LINESTRING": "Edm.GeographyLineString",
+ "EDM_GEOGRAPHY_POLYGON": "Edm.GeographyPolygon",
+ "EDM_GEOGRAPHY_COLLECTION": "Edm.GeographyCollection",
+ "EDM_GEOGRAPHY_MULTIPOLYGON": "Edm.GeographyMultiPolygon",
+ "EDM_GEOGRAPHY_MULTILINESTRING": "Edm.GeographyMultiLineString",
+ "EDM_GEOGRAPHY_MULTIPOINT": "Edm.GeographyMultiPoint",
+ "EDM_GEOMETRY": "Edm.Geometry",
+ "EDM_GEOMETRY_POINT": "Edm.GeometryPoint",
+ "EDM_GEOMETRY_LINESTRING": "Edm.GeometryLineString",
+ "EDM_GEOMETRY_POLYGON": "Edm.GeometryPolygon",
+ "EDM_GEOMETRY_COLLECTION": "Edm.GeometryCollection",
+ "EDM_GEOMETRY_MULTIPOLYGON": "Edm.GeometryMultiPolygon",
+ "EDM_GEOMETRY_MULTILINESTRING": "Edm.GeometryMultiLineString",
+ "EDM_GEOMETRY_MULTIPOINT": "Edm.GeometryMultiPoint",
+ "EDM_GUID": "Edm.Guid",
+ "EDM_INT16": "Edm.Int16",
+ "EDM_INT32": "Edm.Int32",
+ "EDM_INT64": "Edm.Int64",
+ "EDM_SBYTE": "Edm.SByte",
+ "EDM_SINGLE": "Edm.Single",
+ "EDM_STRING": "Edm.String",
+ "EDM_TIMEOFDAY": "Edm.Time",
+ "GEOJSON_POINT": "Point",
+ "GEOJSON_LINESTRING": "LineString",
+ "GEOJSON_POLYGON": "Polygon",
+ "GEOJSON_MULTIPOINT": "MultiPoint",
+ "GEOJSON_MULTILINESTRING": "MultiLineString",
+ "GEOJSON_MULTIPOLYGON": "MultiPolygon",
+ "GEOJSON_GEOMETRYCOLLECTION": "GeometryCollection"
+ },
+ "handler": {
+ "textHandler": {
+ "accept": "text/plain",
+ "maxDataServiceVersion": "4.0"
+ },
+ "MAX_DATA_SERVICE_VERSION": "4.0"
+ },
+ "metadata": {
+ "metadataHandler": {
+ "accept": "application/xml",
+ "maxDataServiceVersion": "4.0"
+ },
+ "schema": {
+ "elements": {
+ "Action": {
+ "attributes": [
+ "Name",
+ "IsBound",
+ "EntitySetPath"
+ ],
+ "elements": [
+ "ReturnType",
+ "Parameter*",
+ "Annotation*"
+ ],
+ "text": false
+ },
+ "ActionImport": {
+ "attributes": [
+ "Name",
+ "Action",
+ "EntitySet",
+ "Annotation*"
+ ],
+ "text": false
+ },
+ "Annotation": {
+ "attributes": [
+ "Term",
+ "Qualifier",
+ "Binary",
+ "Bool",
+ "Date",
+ "DateTimeOffset",
+ "Decimal",
+ "Duration",
+ "EnumMember",
+ "Float",
+ "Guid",
+ "Int",
+ "String",
+ "TimeOfDay",
+ "AnnotationPath",
+ "NavigationPropertyPath",
+ "Path",
+ "PropertyPath",
+ "UrlRef"
+ ],
+ "elements": [
+ "Binary*",
+ "Bool*",
+ "Date*",
+ "DateTimeOffset*",
+ "Decimal*",
+ "Duration*",
+ "EnumMember*",
+ "Float*",
+ "Guid*",
+ "Int*",
+ "String*",
+ "TimeOfDay*",
+ "And*",
+ "Or*",
+ "Not*",
+ "Eq*",
+ "Ne*",
+ "Gt*",
+ "Ge*",
+ "Lt*",
+ "Le*",
+ "AnnotationPath*",
+ "Apply*",
+ "Cast*",
+ "Collection*",
+ "If*",
+ "IsOf*",
+ "LabeledElement*",
+ "LabeledElementReference*",
+ "Null*",
+ "NavigationPropertyPath*",
+ "Path*",
+ "PropertyPath*",
+ "Record*",
+ "UrlRef*",
+ "Annotation*"
+ ],
+ "text": false
+ },
+ "AnnotationPath": {
+ "attributes": null,
+ "elements": null,
+ "text": true
+ },
+ "Annotations": {
+ "attributes": [
+ "Target",
+ "Qualifier"
+ ],
+ "elements": [
+ "Annotation*"
+ ],
+ "text": false
+ },
+ "Apply": {
+ "attributes": [
+ "Function"
+ ],
+ "elements": [
+ "String*",
+ "Path*",
+ "LabeledElement*",
+ "Annotation*"
+ ],
+ "text": false
+ },
+ "And": {
+ "attributes": null,
+ "elements": null,
+ "text": true
+ },
+ "Or": {
+ "attributes": null,
+ "elements": null,
+ "text": true
+ },
+ "Not": {
+ "attributes": null,
+ "elements": null,
+ "text": true
+ },
+ "Eq": {
+ "attributes": null,
+ "elements": null,
+ "text": true
+ },
+ "Ne": {
+ "attributes": null,
+ "elements": null,
+ "text": true
+ },
+ "Gt": {
+ "attributes": null,
+ "elements": null,
+ "text": true
+ },
+ "Ge": {
+ "attributes": null,
+ "elements": null,
+ "text": true
+ },
+ "Lt": {
+ "attributes": null,
+ "elements": null,
+ "text": true
+ },
+ "Le": {
+ "attributes": null,
+ "elements": null,
+ "text": true
+ },
+ "Binary": {
+ "attributes": null,
+ "elements": null,
+ "text": true
+ },
+ "Bool": {
+ "attributes": null,
+ "elements": null,
+ "text": true
+ },
+ "Cast": {
+ "attributes": [
+ "Type"
+ ],
+ "elements": [
+ "Path*",
+ "Annotation*"
+ ],
+ "text": false
+ },
+ "Collection": {
+ "attributes": null,
+ "elements": [
+ "Binary*",
+ "Bool*",
+ "Date*",
+ "DateTimeOffset*",
+ "Decimal*",
+ "Duration*",
+ "EnumMember*",
+ "Float*",
+ "Guid*",
+ "Int*",
+ "String*",
+ "TimeOfDay*",
+ "And*",
+ "Or*",
+ "Not*",
+ "Eq*",
+ "Ne*",
+ "Gt*",
+ "Ge*",
+ "Lt*",
+ "Le*",
+ "AnnotationPath*",
+ "Apply*",
+ "Cast*",
+ "Collection*",
+ "If*",
+ "IsOf*",
+ "LabeledElement*",
+ "LabeledElementReference*",
+ "Null*",
+ "NavigationPropertyPath*",
+ "Path*",
+ "PropertyPath*",
+ "Record*",
+ "UrlRef*"
+ ],
+ "text": false
+ },
+ "ComplexType": {
+ "attributes": [
+ "Name",
+ "BaseType",
+ "Abstract",
+ "OpenType"
+ ],
+ "elements": [
+ "Property*",
+ "NavigationProperty*",
+ "Annotation*"
+ ],
+ "text": false
+ },
+ "Date": {
+ "attributes": null,
+ "elements": null,
+ "text": true
+ },
+ "DateTimeOffset": {
+ "attributes": null,
+ "elements": null,
+ "text": true
+ },
+ "Decimal": {
+ "attributes": null,
+ "elements": null,
+ "text": true
+ },
+ "Duration": {
+ "attributes": null,
+ "elements": null,
+ "text": true
+ },
+ "EntityContainer": {
+ "attributes": [
+ "Name",
+ "Extends"
+ ],
+ "elements": [
+ "EntitySet*",
+ "Singleton*",
+ "ActionImport*",
+ "FunctionImport*",
+ "Annotation*"
+ ],
+ "text": false
+ },
+ "EntitySet": {
+ "attributes": [
+ "Name",
+ "EntityType",
+ "IncludeInServiceDocument"
+ ],
+ "elements": [
+ "NavigationPropertyBinding*",
+ "Annotation*"
+ ],
+ "text": false
+ },
+ "EntityType": {
+ "attributes": [
+ "Name",
+ "BaseType",
+ "Abstract",
+ "OpenType",
+ "HasStream"
+ ],
+ "elements": [
+ "Key*",
+ "Property*",
+ "NavigationProperty*",
+ "Annotation*"
+ ],
+ "text": false
+ },
+ "EnumMember": {
+ "attributes": null,
+ "elements": null,
+ "text": true
+ },
+ "EnumType": {
+ "attributes": [
+ "Name",
+ "UnderlyingType",
+ "IsFlags"
+ ],
+ "elements": [
+ "Member*"
+ ],
+ "text": false
+ },
+ "Float": {
+ "attributes": null,
+ "elements": null,
+ "text": true
+ },
+ "Function": {
+ "attributes": [
+ "Name",
+ "IsBound",
+ "IsComposable",
+ "EntitySetPath"
+ ],
+ "elements": [
+ "ReturnType",
+ "Parameter*",
+ "Annotation*"
+ ],
+ "text": false
+ },
+ "FunctionImport": {
+ "attributes": [
+ "Name",
+ "Function",
+ "EntitySet",
+ "IncludeInServiceDocument",
+ "Annotation*"
+ ],
+ "text": false
+ },
+ "Guid": {
+ "attributes": null,
+ "elements": null,
+ "text": true
+ },
+ "If": {
+ "attributes": null,
+ "elements": [
+ "Path*",
+ "String*",
+ "Annotation*"
+ ],
+ "text": false
+ },
+ "Int": {
+ "attributes": null,
+ "elements": null,
+ "text": true
+ },
+ "IsOf": {
+ "attributes": [
+ "Type",
+ "MaxLength",
+ "Precision",
+ "Scale",
+ "Unicode",
+ "SRID",
+ "DefaultValue",
+ "Annotation*"
+ ],
+ "elements": [
+ "Path*"
+ ],
+ "text": false
+ },
+ "Key": {
+ "attributes": null,
+ "elements": [
+ "PropertyRef*"
+ ],
+ "text": false
+ },
+ "LabeledElement": {
+ "attributes": [
+ "Name"
+ ],
+ "elements": [
+ "Binary*",
+ "Bool*",
+ "Date*",
+ "DateTimeOffset*",
+ "Decimal*",
+ "Duration*",
+ "EnumMember*",
+ "Float*",
+ "Guid*",
+ "Int*",
+ "String*",
+ "TimeOfDay*",
+ "And*",
+ "Or*",
+ "Not*",
+ "Eq*",
+ "Ne*",
+ "Gt*",
+ "Ge*",
+ "Lt*",
+ "Le*",
+ "AnnotationPath*",
+ "Apply*",
+ "Cast*",
+ "Collection*",
+ "If*",
+ "IsOf*",
+ "LabeledElement*",
+ "LabeledElementReference*",
+ "Null*",
+ "NavigationPropertyPath*",
+ "Path*",
+ "PropertyPath*",
+ "Record*",
+ "UrlRef*",
+ "Annotation*"
+ ],
+ "text": false
+ },
+ "LabeledElementReference": {
+ "attributes": [
+ "Term"
+ ],
+ "elements": [
+ "Binary*",
+ "Bool*",
+ "Date*",
+ "DateTimeOffset*",
+ "Decimal*",
+ "Duration*",
+ "EnumMember*",
+ "Float*",
+ "Guid*",
+ "Int*",
+ "String*",
+ "TimeOfDay*",
+ "And*",
+ "Or*",
+ "Not*",
+ "Eq*",
+ "Ne*",
+ "Gt*",
+ "Ge*",
+ "Lt*",
+ "Le*",
+ "AnnotationPath*",
+ "Apply*",
+ "Cast*",
+ "Collection*",
+ "If*",
+ "IsOf*",
+ "LabeledElement*",
+ "LabeledElementReference*",
+ "Null*",
+ "NavigationPropertyPath*",
+ "Path*",
+ "PropertyPath*",
+ "Record*",
+ "UrlRef*"
+ ],
+ "text": false
+ },
+ "Member": {
+ "attributes": [
+ "Name",
+ "Value"
+ ],
+ "elements": [
+ "Annotation*"
+ ],
+ "text": false
+ },
+ "NavigationProperty": {
+ "attributes": [
+ "Name",
+ "Type",
+ "Nullable",
+ "Partner",
+ "ContainsTarget"
+ ],
+ "elements": [
+ "ReferentialConstraint*",
+ "OnDelete*",
+ "Annotation*"
+ ],
+ "text": false
+ },
+ "NavigationPropertyBinding": {
+ "attributes": [
+ "Path",
+ "Target"
+ ],
+ "text": false
+ },
+ "NavigationPropertyPath": {
+ "attributes": null,
+ "elements": null,
+ "text": true
+ },
+ "Null": {
+ "attributes": null,
+ "elements": [
+ "Annotation*"
+ ],
+ "text": false
+ },
+ "OnDelete": {
+ "attributes": [
+ "Action"
+ ],
+ "elements": [
+ "Annotation*"
+ ],
+ "text": false
+ },
+ "Path": {
+ "attributes": null,
+ "elements": null,
+ "text": true
+ },
+ "Parameter": {
+ "attributes": [
+ "Name",
+ "Type",
+ "Nullable",
+ "MaxLength",
+ "Precision",
+ "Scale",
+ "SRID"
+ ],
+ "elements": [
+ "Annotation*"
+ ],
+ "text": false
+ },
+ "Property": {
+ "attributes": [
+ "Name",
+ "Type",
+ "Nullable",
+ "MaxLength",
+ "Precision",
+ "Scale",
+ "Unicode",
+ "SRID",
+ "DefaultValue"
+ ],
+ "elements": [
+ "Annotation*"
+ ],
+ "text": false
+ },
+ "PropertyPath": {
+ "attributes": null,
+ "elements": null,
+ "text": true
+ },
+ "PropertyRef": {
+ "attributes": [
+ "Name",
+ "Alias"
+ ],
+ "text": false
+ },
+ "PropertyValue": {
+ "attributes": [
+ "Property",
+ "Path"
+ ],
+ "elements": [
+ "Binary*",
+ "Bool*",
+ "Date*",
+ "DateTimeOffset*",
+ "Decimal*",
+ "Duration*",
+ "EnumMember*",
+ "Float*",
+ "Guid*",
+ "Int*",
+ "String*",
+ "TimeOfDay*",
+ "And*",
+ "Or*",
+ "Not*",
+ "Eq*",
+ "Ne*",
+ "Gt*",
+ "Ge*",
+ "Lt*",
+ "Le*",
+ "AnnotationPath*",
+ "Apply*",
+ "Cast*",
+ "Collection*",
+ "If*",
+ "IsOf*",
+ "LabeledElement*",
+ "LabeledElementReference*",
+ "Null*",
+ "NavigationPropertyPath*",
+ "Path*",
+ "PropertyPath*",
+ "Record*",
+ "UrlRef*",
+ "Annotation*"
+ ],
+ "text": false
+ },
+ "Record": {
+ "attributes": null,
+ "elements": [
+ "PropertyValue*",
+ "Property*",
+ "Annotation*"
+ ],
+ "text": false
+ },
+ "ReferentialConstraint": {
+ "attributes": [
+ "Property",
+ "ReferencedProperty",
+ "Annotation*"
+ ],
+ "text": false
+ },
+ "ReturnType": {
+ "attributes": [
+ "Type",
+ "Nullable",
+ "MaxLength",
+ "Precision",
+ "Scale",
+ "SRID"
+ ],
+ "text": false
+ },
+ "String": {
+ "attributes": null,
+ "elements": null,
+ "text": true
+ },
+ "Schema": {
+ "attributes": [
+ "Namespace",
+ "Alias"
+ ],
+ "elements": [
+ "Action*",
+ "Annotations*",
+ "Annotation*",
+ "ComplexType*",
+ "EntityContainer",
+ "EntityType*",
+ "EnumType*",
+ "Function*",
+ "Term*",
+ "TypeDefinition*",
+ "Annotation*"
+ ],
+ "text": false
+ },
+ "Singleton": {
+ "attributes": [
+ "Name",
+ "Type"
+ ],
+ "elements": [
+ "NavigationPropertyBinding*",
+ "Annotation*"
+ ],
+ "text": false
+ },
+ "Term": {
+ "attributes": [
+ "Name",
+ "Type",
+ "BaseTerm",
+ "DefaultValue ",
+ "AppliesTo",
+ "Nullable",
+ "MaxLength",
+ "Precision",
+ "Scale",
+ "SRID"
+ ],
+ "elements": [
+ "Annotation*"
+ ],
+ "text": false
+ },
+ "TimeOfDay": {
+ "attributes": null,
+ "elements": null,
+ "text": true
+ },
+ "TypeDefinition": {
+ "attributes": [
+ "Name",
+ "UnderlyingType",
+ "MaxLength",
+ "Unicode",
+ "Precision",
+ "Scale",
+ "SRID"
+ ],
+ "elements": [
+ "Annotation*"
+ ],
+ "text": false
+ },
+ "UrlRef": {
+ "attributes": null,
+ "elements": [
+ "Binary*",
+ "Bool*",
+ "Date*",
+ "DateTimeOffset*",
+ "Decimal*",
+ "Duration*",
+ "EnumMember*",
+ "Float*",
+ "Guid*",
+ "Int*",
+ "String*",
+ "TimeOfDay*",
+ "And*",
+ "Or*",
+ "Not*",
+ "Eq*",
+ "Ne*",
+ "Gt*",
+ "Ge*",
+ "Lt*",
+ "Le*",
+ "AnnotationPath*",
+ "Apply*",
+ "Cast*",
+ "Collection*",
+ "If*",
+ "IsOf*",
+ "LabeledElement*",
+ "LabeledElementReference*",
+ "Null*",
+ "NavigationPropertyPath*",
+ "Path*",
+ "PropertyPath*",
+ "Record*",
+ "UrlRef*",
+ "Annotation*"
+ ],
+ "text": false
+ },
+ "Edmx": {
+ "attributes": [
+ "Version"
+ ],
+ "elements": [
+ "DataServices",
+ "Reference*"
+ ],
+ "text": false,
+ "ns": "http://docs.oasis-open.org/odata/ns/edmx"
+ },
+ "DataServices": {
+ "attributes": [
+ "m:MaxDataServiceVersion",
+ "m:DataServiceVersion"
+ ],
+ "elements": [
+ "Schema*"
+ ],
+ "text": false,
+ "ns": "http://docs.oasis-open.org/odata/ns/edmx"
+ },
+ "Reference": {
+ "attributes": [
+ "Uri"
+ ],
+ "elements": [
+ "Include*",
+ "IncludeAnnotations*",
+ "Annotation*"
+ ],
+ "text": false
+ },
+ "Include": {
+ "attributes": [
+ "Namespace",
+ "Alias"
+ ],
+ "text": false
+ },
+ "IncludeAnnotations": {
+ "attributes": [
+ "TermNamespace",
+ "Qualifier",
+ "TargetNamespace"
+ ],
+ "text": false
+ }
+ }
+ }
+ },
+ "net": {
+ "defaultHttpClient": {
+ "callbackParameterName": "$callback",
+ "formatQueryString": "$format=json",
+ "enableJsonpCallback": false
+ }
+ },
+ "json": {
+ "jsonHandler": {
+ "accept": "application/json",
+ "recognizeDates": false
+ }
+ },
+ "batch": {
+ "batchHandler": {
+ "accept": "multipart/mixed",
+ "maxDataServiceVersion": "4.0",
+ "partHandler": {
+ "maxDataServiceVersion": "4.0",
+ "accept": "application/json;q=0.9, */*;q=0.1"
+ }
+ }
+ },
+ "defaultHandler": {
+ "maxDataServiceVersion": "4.0",
+ "accept": "application/json;q=0.9, */*;q=0.1"
+ },
+ "defaultMetadata": [],
+ "metadataHandler": {
+ "accept": "application/xml",
+ "maxDataServiceVersion": "4.0"
+ }
+ },
+ "store": {
+ "defaultStoreMechanism": "best"
+ },
+ "cache": {}
+}
\ No newline at end of file
[3/5] [OLINGO-442] Create packaging tool and remove browserify
Posted by ko...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/87e35975/odatajs/src/lib/odatajs/xml.js
----------------------------------------------------------------------
diff --git a/odatajs/src/lib/odatajs/xml.js b/odatajs/src/lib/odatajs/xml.js
deleted file mode 100644
index b8af4fe..0000000
--- a/odatajs/src/lib/odatajs/xml.js
+++ /dev/null
@@ -1,816 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-
-/** @module datajs/xml */
-
-var utils = require('./utils.js');
-
-var activeXObject = utils.activeXObject;
-var djsassert = utils.djsassert;
-var extend = utils.extend;
-var isArray = utils.isArray;
-var normalizeURI = utils.normalizeURI;
-
-// URI prefixes to generate smaller code.
-var http = "http://";
-var w3org = http + "www.w3.org/"; // http://www.w3.org/
-
-var xhtmlNS = w3org + "1999/xhtml"; // http://www.w3.org/1999/xhtml
-var xmlnsNS = w3org + "2000/xmlns/"; // http://www.w3.org/2000/xmlns/
-var xmlNS = w3org + "XML/1998/namespace"; // http://www.w3.org/XML/1998/namespace
-
-var mozillaParserErroNS = http + "www.mozilla.org/newlayout/xml/parsererror.xml";
-
-/** Checks whether the specified string has leading or trailing spaces.
- * @param {String} text - String to check.
- * @returns {Boolean} true if text has any leading or trailing whitespace; false otherwise.
- */
-function hasLeadingOrTrailingWhitespace(text) {
- var re = /(^\s)|(\s$)/;
- return re.test(text);
-}
-
-/** Determines whether the specified text is empty or whitespace.
- * @param {String} text - Value to inspect.
- * @returns {Boolean} true if the text value is empty or all whitespace; false otherwise.
- */
-function isWhitespace(text) {
-
-
- var ws = /^\s*$/;
- return text === null || ws.test(text);
-}
-
-/** Determines whether the specified element has xml:space='preserve' applied.
- * @param domElement - Element to inspect.
- * @returns {Boolean} Whether xml:space='preserve' is in effect.
- */
-function isWhitespacePreserveContext(domElement) {
-
-
- while (domElement !== null && domElement.nodeType === 1) {
- var val = xmlAttributeValue(domElement, "space", xmlNS);
- if (val === "preserve") {
- return true;
- } else if (val === "default") {
- break;
- } else {
- domElement = domElement.parentNode;
- }
- }
-
- return false;
-}
-
-/** Determines whether the attribute is a XML namespace declaration.
- * @param domAttribute - Element to inspect.
- * @return {Boolean} True if the attribute is a namespace declaration (its name is 'xmlns' or starts with 'xmlns:'; false otherwise.
- */
-function isXmlNSDeclaration(domAttribute) {
- var nodeName = domAttribute.nodeName;
- return nodeName == "xmlns" || nodeName.indexOf("xmlns:") === 0;
-}
-
-/** Safely set as property in an object by invoking obj.setProperty.
- * @param obj - Object that exposes a setProperty method.
- * @param {String} name - Property name
- * @param value - Property value.
- */
-function safeSetProperty(obj, name, value) {
-
-
- try {
- obj.setProperty(name, value);
- } catch (_) { }
-}
-
-/** Creates an configures new MSXML 3.0 ActiveX object.
- * @returns {Object} New MSXML 3.0 ActiveX object.
- * This function throws any exception that occurs during the creation
- * of the MSXML 3.0 ActiveX object.
- */
-function msXmlDom3() {
- var msxml3 = activeXObject("Msxml2.DOMDocument.3.0");
- if (msxml3) {
- safeSetProperty(msxml3, "ProhibitDTD", true);
- safeSetProperty(msxml3, "MaxElementDepth", 256);
- safeSetProperty(msxml3, "AllowDocumentFunction", false);
- safeSetProperty(msxml3, "AllowXsltScript", false);
- }
- return msxml3;
-}
-
-/** Creates an configures new MSXML 6.0 or MSXML 3.0 ActiveX object.
- * @returns {Object} New MSXML 3.0 ActiveX object.
- * This function will try to create a new MSXML 6.0 ActiveX object. If it fails then
- * it will fallback to create a new MSXML 3.0 ActiveX object. Any exception that
- * happens during the creation of the MSXML 6.0 will be handled by the function while
- * the ones that happend during the creation of the MSXML 3.0 will be thrown.
- */
-function msXmlDom() {
- try {
- var msxml = activeXObject("Msxml2.DOMDocument.6.0");
- if (msxml) {
- msxml.async = true;
- }
- return msxml;
- } catch (_) {
- return msXmlDom3();
- }
-}
-
-/** Parses an XML string using the MSXML DOM.
- * @returns {Object} New MSXML DOMDocument node representing the parsed XML string.
- * This function throws any exception that occurs during the creation
- * of the MSXML ActiveX object. It also will throw an exception
- * in case of a parsing error.
- */
-function msXmlParse(text) {
- var dom = msXmlDom();
- if (!dom) {
- return null;
- }
-
- dom.loadXML(text);
- var parseError = dom.parseError;
- if (parseError.errorCode !== 0) {
- xmlThrowParserError(parseError.reason, parseError.srcText, text);
- }
- return dom;
-}
-
-/** Throws a new exception containing XML parsing error information.
- * @param exceptionOrReason - String indicating the reason of the parsing failure or Object detailing the parsing error.
- * @param {String} srcText - String indicating the part of the XML string that caused the parsing error.
- * @param {String} errorXmlText - XML string for wich the parsing failed.
- */
-function xmlThrowParserError(exceptionOrReason, srcText, errorXmlText) {
-
- if (typeof exceptionOrReason === "string") {
- exceptionOrReason = { message: exceptionOrReason };
- }
- throw extend(exceptionOrReason, { srcText: srcText || "", errorXmlText: errorXmlText || "" });
-}
-
-/** Returns an XML DOM document from the specified text.
- * @param {String} text - Document text.
- * @returns XML DOM document.
- * This function will throw an exception in case of a parse error
- */
-function xmlParse(text) {
- var domParser = window.DOMParser && new window.DOMParser();
- var dom;
-
- if (!domParser) {
- dom = msXmlParse(text);
- if (!dom) {
- xmlThrowParserError("XML DOM parser not supported");
- }
- return dom;
- }
-
- try {
- dom = domParser.parseFromString(text, "text/xml");
- } catch (e) {
- xmlThrowParserError(e, "", text);
- }
-
- var element = dom.documentElement;
- var nsURI = element.namespaceURI;
- var localName = xmlLocalName(element);
-
- // Firefox reports errors by returing the DOM for an xml document describing the problem.
- if (localName === "parsererror" && nsURI === mozillaParserErroNS) {
- var srcTextElement = xmlFirstChildElement(element, mozillaParserErroNS, "sourcetext");
- var srcText = srcTextElement ? xmlNodeValue(srcTextElement) : "";
- xmlThrowParserError(xmlInnerText(element) || "", srcText, text);
- }
-
- // Chrome (and maybe other webkit based browsers) report errors by injecting a header with an error message.
- // The error may be localized, so instead we simply check for a header as the
- // top element or descendant child of the document.
- if (localName === "h3" && nsURI === xhtmlNS || xmlFirstDescendantElement(element, xhtmlNS, "h3")) {
- var reason = "";
- var siblings = [];
- var cursor = element.firstChild;
- while (cursor) {
- if (cursor.nodeType === 1) {
- reason += xmlInnerText(cursor) || "";
- }
- siblings.push(cursor.nextSibling);
- cursor = cursor.firstChild || siblings.shift();
- }
- reason += xmlInnerText(element) || "";
- xmlThrowParserError(reason, "", text);
- }
-
- return dom;
-}
-
-/** Builds a XML qualified name string in the form of "prefix:name".
- * @param {String} prefix - Prefix string (may be null)
- * @param {String} name - Name string to qualify with the prefix.
- * @returns {String} Qualified name.
- */
-function xmlQualifiedName(prefix, name) {
- return prefix ? prefix + ":" + name : name;
-}
-
-/** Appends a text node into the specified DOM element node.
- * @param domNode - DOM node for the element.
- * @param {String} text - Text to append as a child of element.
-*/
-function xmlAppendText(domNode, textNode) {
- if (hasLeadingOrTrailingWhitespace(textNode.data)) {
- var attr = xmlAttributeNode(domNode, xmlNS, "space");
- if (!attr) {
- attr = xmlNewAttribute(domNode.ownerDocument, xmlNS, xmlQualifiedName("xml", "space"));
- xmlAppendChild(domNode, attr);
- }
- attr.value = "preserve";
- }
- domNode.appendChild(textNode);
- return domNode;
-}
-
-/** Iterates through the XML element's attributes and invokes the callback function for each one.
- * @param element - Wrapped element to iterate over.
- * @param {Function} onAttributeCallback - Callback function to invoke with wrapped attribute nodes.
-*/
-function xmlAttributes(element, onAttributeCallback) {
- var attributes = element.attributes;
- var i, len;
- for (i = 0, len = attributes.length; i < len; i++) {
- onAttributeCallback(attributes.item(i));
- }
-}
-
-/** Returns the value of a DOM element's attribute.
- * @param domNode - DOM node for the owning element.
- * @param {String} localName - Local name of the attribute.
- * @param {String} nsURI - Namespace URI of the attribute.
- * @returns {String} - The attribute value, null if not found (may be null)
- */
-function xmlAttributeValue(domNode, localName, nsURI) {
-
- var attribute = xmlAttributeNode(domNode, localName, nsURI);
- return attribute ? xmlNodeValue(attribute) : null;
-}
-
-/** Gets an attribute node from a DOM element.
- * @param domNode - DOM node for the owning element.
- * @param {String} localName - Local name of the attribute.
- * @param {String} nsURI - Namespace URI of the attribute.
- * @returns The attribute node, null if not found.
- */
-function xmlAttributeNode(domNode, localName, nsURI) {
-
- var attributes = domNode.attributes;
- if (attributes.getNamedItemNS) {
- return attributes.getNamedItemNS(nsURI || null, localName);
- }
-
- return attributes.getQualifiedItem(localName, nsURI) || null;
-}
-
-/** Gets the value of the xml:base attribute on the specified element.
- * @param domNode - Element to get xml:base attribute value from.
- * @param [baseURI] - Base URI used to normalize the value of the xml:base attribute ( may be null)
- * @returns {String} Value of the xml:base attribute if found; the baseURI or null otherwise.
- */
-function xmlBaseURI(domNode, baseURI) {
-
- var base = xmlAttributeNode(domNode, "base", xmlNS);
- return (base ? normalizeURI(base.value, baseURI) : baseURI) || null;
-}
-
-
-/** Iterates through the XML element's child DOM elements and invokes the callback function for each one.
- * @param element - DOM Node containing the DOM elements to iterate over.
- * @param {Function} onElementCallback - Callback function to invoke for each child DOM element.
-*/
-function xmlChildElements(domNode, onElementCallback) {
-
- xmlTraverse(domNode, /*recursive*/false, function (child) {
- if (child.nodeType === 1) {
- onElementCallback(child);
- }
- // continue traversing.
- return true;
- });
-}
-
-/** Gets the descendant element under root that corresponds to the specified path and namespace URI.
- * @param root - DOM element node from which to get the descendant element.
- * @param {String} namespaceURI - The namespace URI of the element to match.
- * @param {String} path - Path to the desired descendant element.
- * @return The element specified by path and namespace URI.
- * All the elements in the path are matched against namespaceURI.
- * The function will stop searching on the first element that doesn't match the namespace and the path.
- */
-function xmlFindElementByPath(root, namespaceURI, path) {
- var parts = path.split("/");
- var i, len;
- for (i = 0, len = parts.length; i < len; i++) {
- root = root && xmlFirstChildElement(root, namespaceURI, parts[i]);
- }
- return root || null;
-}
-
-/** Gets the DOM element or DOM attribute node under root that corresponds to the specified path and namespace URI.
- * @param root - DOM element node from which to get the descendant node.
- * @param {String} namespaceURI - The namespace URI of the node to match.
- * @param {String} path - Path to the desired descendant node.
- * @return The node specified by path and namespace URI.</returns>
-
-* This function will traverse the path and match each node associated to a path segement against the namespace URI.
-* The traversal stops when the whole path has been exahusted or a node that doesn't belogong the specified namespace is encountered.
-* The last segment of the path may be decorated with a starting @ character to indicate that the desired node is a DOM attribute.
-*/
-function xmlFindNodeByPath(root, namespaceURI, path) {
-
-
- var lastSegmentStart = path.lastIndexOf("/");
- var nodePath = path.substring(lastSegmentStart + 1);
- var parentPath = path.substring(0, lastSegmentStart);
-
- var node = parentPath ? xmlFindElementByPath(root, namespaceURI, parentPath) : root;
- if (node) {
- if (nodePath.charAt(0) === "@") {
- return xmlAttributeNode(node, nodePath.substring(1), namespaceURI);
- }
- return xmlFirstChildElement(node, namespaceURI, nodePath);
- }
- return null;
-}
-
-/** Returns the first child DOM element under the specified DOM node that matches the specified namespace URI and local name.
- * @param domNode - DOM node from which the child DOM element is going to be retrieved.
- * @param {String} [namespaceURI] -
- * @param {String} [localName] -
- * @return The node's first child DOM element that matches the specified namespace URI and local name; null otherwise.</returns>
- */
-function xmlFirstChildElement(domNode, namespaceURI, localName) {
-
- return xmlFirstElementMaybeRecursive(domNode, namespaceURI, localName, /*recursive*/false);
-}
-
-/** Returns the first descendant DOM element under the specified DOM node that matches the specified namespace URI and local name.
- * @param domNode - DOM node from which the descendant DOM element is going to be retrieved.
- * @param {String} [namespaceURI] -
- * @param {String} [localName] -
- * @return The node's first descendant DOM element that matches the specified namespace URI and local name; null otherwise.
-*/
-function xmlFirstDescendantElement(domNode, namespaceURI, localName) {
- if (domNode.getElementsByTagNameNS) {
- var result = domNode.getElementsByTagNameNS(namespaceURI, localName);
- return result.length > 0 ? result[0] : null;
- }
- return xmlFirstElementMaybeRecursive(domNode, namespaceURI, localName, /*recursive*/true);
-}
-
-/** Returns the first descendant DOM element under the specified DOM node that matches the specified namespace URI and local name.
- * @param domNode - DOM node from which the descendant DOM element is going to be retrieved.
- * @param {String} [namespaceURI] -
- * @param {String} [localName] -
- * @param {Boolean} recursive
- * - True if the search should include all the descendants of the DOM node.
- * - False if the search should be scoped only to the direct children of the DOM node.
- * @return The node's first descendant DOM element that matches the specified namespace URI and local name; null otherwise.
- */
-function xmlFirstElementMaybeRecursive(domNode, namespaceURI, localName, recursive) {
-
- var firstElement = null;
- xmlTraverse(domNode, recursive, function (child) {
- if (child.nodeType === 1) {
- var isExpectedNamespace = !namespaceURI || xmlNamespaceURI(child) === namespaceURI;
- var isExpectedNodeName = !localName || xmlLocalName(child) === localName;
-
- if (isExpectedNamespace && isExpectedNodeName) {
- firstElement = child;
- }
- }
- return firstElement === null;
- });
- return firstElement;
-}
-
-/** Gets the concatenated value of all immediate child text and CDATA nodes for the specified element.
- * @param domElement - Element to get values for.
- * @returns {String} Text for all direct children.
- */
-function xmlInnerText(xmlElement) {
-
- var result = null;
- var root = (xmlElement.nodeType === 9 && xmlElement.documentElement) ? xmlElement.documentElement : xmlElement;
- var whitespaceAlreadyRemoved = root.ownerDocument.preserveWhiteSpace === false;
- var whitespacePreserveContext;
-
- xmlTraverse(root, false, function (child) {
- if (child.nodeType === 3 || child.nodeType === 4) {
- // isElementContentWhitespace indicates that this is 'ignorable whitespace',
- // but it's not defined by all browsers, and does not honor xml:space='preserve'
- // in some implementations.
- //
- // If we can't tell either way, we walk up the tree to figure out whether
- // xml:space is set to preserve; otherwise we discard pure-whitespace.
- //
- // For example <a> <b>1</b></a>. The space between <a> and <b> is usually 'ignorable'.
- var text = xmlNodeValue(child);
- var shouldInclude = whitespaceAlreadyRemoved || !isWhitespace(text);
- if (!shouldInclude) {
- // Walk up the tree to figure out whether we are in xml:space='preserve' context
- // for the cursor (needs to happen only once).
- if (whitespacePreserveContext === undefined) {
- whitespacePreserveContext = isWhitespacePreserveContext(root);
- }
-
- shouldInclude = whitespacePreserveContext;
- }
-
- if (shouldInclude) {
- if (!result) {
- result = text;
- } else {
- result += text;
- }
- }
- }
- // Continue traversing?
- return true;
- });
- return result;
-}
-
-/** Returns the localName of a XML node.
- * @param domNode - DOM node to get the value from.
- * @returns {String} localName of domNode.
- */
-function xmlLocalName(domNode) {
-
- return domNode.localName || domNode.baseName;
-}
-
-/** Returns the namespace URI of a XML node.
- * @param node - DOM node to get the value from.
- * @returns {String} Namespace URI of domNode.
- */
-function xmlNamespaceURI(domNode) {
-
- return domNode.namespaceURI || null;
-}
-
-/** Returns the value or the inner text of a XML node.
- * @param node - DOM node to get the value from.
- * @return Value of the domNode or the inner text if domNode represents a DOM element node.
- */
-function xmlNodeValue(domNode) {
-
- if (domNode.nodeType === 1) {
- return xmlInnerText(domNode);
- }
- return domNode.nodeValue;
-}
-
-/** Walks through the descendants of the domNode and invokes a callback for each node.
- * @param domNode - DOM node whose descendants are going to be traversed.
- * @param {Boolean} recursive
- * - True if the traversal should include all the descenants of the DOM node.
- * - False if the traversal should be scoped only to the direct children of the DOM node.
- * @returns {String} Namespace URI of node.
- */
-function xmlTraverse(domNode, recursive, onChildCallback) {
-
- var subtrees = [];
- var child = domNode.firstChild;
- var proceed = true;
- while (child && proceed) {
- proceed = onChildCallback(child);
- if (proceed) {
- if (recursive && child.firstChild) {
- subtrees.push(child.firstChild);
- }
- child = child.nextSibling || subtrees.shift();
- }
- }
-}
-
-/** Returns the next sibling DOM element of the specified DOM node.
- * @param domNode - DOM node from which the next sibling is going to be retrieved.
- * @param {String} [namespaceURI] -
- * @param {String} [localName] -
- * @return The node's next sibling DOM element, null if there is none.</returns>
- */
-function xmlSiblingElement(domNode, namespaceURI, localName) {
-
- var sibling = domNode.nextSibling;
- while (sibling) {
- if (sibling.nodeType === 1) {
- var isExpectedNamespace = !namespaceURI || xmlNamespaceURI(sibling) === namespaceURI;
- var isExpectedNodeName = !localName || xmlLocalName(sibling) === localName;
-
- if (isExpectedNamespace && isExpectedNodeName) {
- return sibling;
- }
- }
- sibling = sibling.nextSibling;
- }
- return null;
-}
-
-/** Creates a new empty DOM document node.
- * @return New DOM document node.</returns>
- *
- * This function will first try to create a native DOM document using
- * the browsers createDocument function. If the browser doesn't
- * support this but supports ActiveXObject, then an attempt to create
- * an MSXML 6.0 DOM will be made. If this attempt fails too, then an attempt
- * for creating an MXSML 3.0 DOM will be made. If this last attemp fails or
- * the browser doesn't support ActiveXObject then an exception will be thrown.
- */
-function xmlDom() {
- var implementation = window.document.implementation;
- return (implementation && implementation.createDocument) ?
- implementation.createDocument(null, null, null) :
- msXmlDom();
-}
-
-/** Appends a collection of child nodes or string values to a parent DOM node.
- * @param parent - DOM node to which the children will be appended.
- * @param {Array} children - Array containing DOM nodes or string values that will be appended to the parent.
- * @return The parent with the appended children or string values.</returns>
- * If a value in the children collection is a string, then a new DOM text node is going to be created
- * for it and then appended to the parent.
- */
-function xmlAppendChildren(parent, children) {
- if (!isArray(children)) {
- return xmlAppendChild(parent, children);
- }
-
- var i, len;
- for (i = 0, len = children.length; i < len; i++) {
- children[i] && xmlAppendChild(parent, children[i]);
- }
- return parent;
-}
-
-/** Appends a child node or a string value to a parent DOM node.
- * @param parent - DOM node to which the child will be appended.
- * @param child - Child DOM node or string value to append to the parent.
- * @return The parent with the appended child or string value.</returns>
- * If child is a string value, then a new DOM text node is going to be created
- * for it and then appended to the parent.
- */
-function xmlAppendChild(parent, child) {
-
- djsassert(parent !== child, "xmlAppendChild() - parent and child are one and the same!");
- if (child) {
- if (typeof child === "string") {
- return xmlAppendText(parent, xmlNewText(parent.ownerDocument, child));
- }
- if (child.nodeType === 2) {
- parent.setAttributeNodeNS ? parent.setAttributeNodeNS(child) : parent.setAttributeNode(child);
- } else {
- parent.appendChild(child);
- }
- }
- return parent;
-}
-
-/** Creates a new DOM attribute node.
- * @param dom - DOM document used to create the attribute.
- * @param {String} prefix - Namespace prefix.
- * @param {String} namespaceURI - Namespace URI.
- * @return DOM attribute node for the namespace declaration.
- */
-function xmlNewAttribute(dom, namespaceURI, qualifiedName, value) {
-
- var attribute =
- dom.createAttributeNS && dom.createAttributeNS(namespaceURI, qualifiedName) ||
- dom.createNode(2, qualifiedName, namespaceURI || undefined);
-
- attribute.value = value || "";
- return attribute;
-}
-
-/** Creates a new DOM element node.
- * @param dom - DOM document used to create the DOM element.
- * @param {String} namespaceURI - Namespace URI of the new DOM element.
- * @param {String} qualifiedName - Qualified name in the form of "prefix:name" of the new DOM element.
- * @param {Array} [children] Collection of child DOM nodes or string values that are going to be appended to the new DOM element.
- * @return New DOM element.</returns>
- * If a value in the children collection is a string, then a new DOM text node is going to be created
- * for it and then appended to the new DOM element.
- */
-function xmlNewElement(dom, nampespaceURI, qualifiedName, children) {
- var element =
- dom.createElementNS && dom.createElementNS(nampespaceURI, qualifiedName) ||
- dom.createNode(1, qualifiedName, nampespaceURI || undefined);
-
- return xmlAppendChildren(element, children || []);
-}
-
-/** Creates a namespace declaration attribute.
- * @param dom - DOM document used to create the attribute.
- * @param {String} namespaceURI - Namespace URI.
- * @param {String} prefix - Namespace prefix.
- * @return DOM attribute node for the namespace declaration.</returns>
- */
-function xmlNewNSDeclaration(dom, namespaceURI, prefix) {
- return xmlNewAttribute(dom, xmlnsNS, xmlQualifiedName("xmlns", prefix), namespaceURI);
-}
-
-/** Creates a new DOM document fragment node for the specified xml text.
- * @param dom - DOM document from which the fragment node is going to be created.
- * @param {String} text XML text to be represented by the XmlFragment.
- * @return New DOM document fragment object.
- */
-function xmlNewFragment(dom, text) {
-
- var value = "<c>" + text + "</c>";
- var tempDom = xmlParse(value);
- var tempRoot = tempDom.documentElement;
- var imported = ("importNode" in dom) ? dom.importNode(tempRoot, true) : tempRoot;
- var fragment = dom.createDocumentFragment();
-
- var importedChild = imported.firstChild;
- while (importedChild) {
- fragment.appendChild(importedChild);
- importedChild = importedChild.nextSibling;
- }
- return fragment;
-}
-
-/** Creates new DOM text node.
- * @param dom - DOM document used to create the text node.
- * @param {String} text - Text value for the DOM text node.
- * @return DOM text node.</returns>
- */
-function xmlNewText(dom, text) {
- return dom.createTextNode(text);
-}
-
-/** Creates a new DOM element or DOM attribute node as specified by path and appends it to the DOM tree pointed by root.
- * @param dom - DOM document used to create the new node.
- * @param root - DOM element node used as root of the subtree on which the new nodes are going to be created.
- * @param {String} namespaceURI - Namespace URI of the new DOM element or attribute.
- * @param {String} namespacePrefix - Prefix used to qualify the name of the new DOM element or attribute.
- * @param {String} Path - Path string describing the location of the new DOM element or attribute from the root element.
- * @return DOM element or attribute node for the last segment of the path.</returns>
-
- * This function will traverse the path and will create a new DOM element with the specified namespace URI and prefix
- * for each segment that doesn't have a matching element under root.
- * The last segment of the path may be decorated with a starting @ character. In this case a new DOM attribute node
- * will be created.
- */
-function xmlNewNodeByPath(dom, root, namespaceURI, prefix, path) {
- var name = "";
- var parts = path.split("/");
- var xmlFindNode = xmlFirstChildElement;
- var xmlNewNode = xmlNewElement;
- var xmlNode = root;
-
- var i, len;
- for (i = 0, len = parts.length; i < len; i++) {
- name = parts[i];
- if (name.charAt(0) === "@") {
- name = name.substring(1);
- xmlFindNode = xmlAttributeNode;
- xmlNewNode = xmlNewAttribute;
- }
-
- var childNode = xmlFindNode(xmlNode, namespaceURI, name);
- if (!childNode) {
- childNode = xmlNewNode(dom, namespaceURI, xmlQualifiedName(prefix, name));
- xmlAppendChild(xmlNode, childNode);
- }
- xmlNode = childNode;
- }
- return xmlNode;
-}
-
-/** Returns the text representation of the document to which the specified node belongs.
- * @param root - Wrapped element in the document to serialize.
- * @returns {String} Serialized document.
-*/
-function xmlSerialize(domNode) {
- var xmlSerializer = window.XMLSerializer;
- if (xmlSerializer) {
- var serializer = new xmlSerializer();
- return serializer.serializeToString(domNode);
- }
-
- if (domNode.xml) {
- return domNode.xml;
- }
-
- throw { message: "XML serialization unsupported" };
-}
-
-/** Returns the XML representation of the all the descendants of the node.
- * @param domNode - Node to serialize.</param>
- * @returns {String} The XML representation of all the descendants of the node.
- */
-function xmlSerializeDescendants(domNode) {
- var children = domNode.childNodes;
- var i, len = children.length;
- if (len === 0) {
- return "";
- }
-
- // Some implementations of the XMLSerializer don't deal very well with fragments that
- // don't have a DOMElement as their first child. The work around is to wrap all the
- // nodes in a dummy root node named "c", serialize it and then just extract the text between
- // the <c> and the </c> substrings.
-
- var dom = domNode.ownerDocument;
- var fragment = dom.createDocumentFragment();
- var fragmentRoot = dom.createElement("c");
-
- fragment.appendChild(fragmentRoot);
- // Move the children to the fragment tree.
- for (i = 0; i < len; i++) {
- fragmentRoot.appendChild(children[i]);
- }
-
- var xml = xmlSerialize(fragment);
- xml = xml.substr(3, xml.length - 7);
-
- // Move the children back to the original dom tree.
- for (i = 0; i < len; i++) {
- domNode.appendChild(fragmentRoot.childNodes[i]);
- }
-
- return xml;
-}
-
-/** Returns the XML representation of the node and all its descendants.
- * @param domNode - Node to serialize
- * @returns {String} The XML representation of the node and all its descendants.
- */
-function xmlSerializeNode(domNode) {
-
- var xml = domNode.xml;
- if (xml !== undefined) {
- return xml;
- }
-
- if (window.XMLSerializer) {
- var serializer = new window.XMLSerializer();
- return serializer.serializeToString(domNode);
- }
-
- throw { message: "XML serialization unsupported" };
-}
-
-exports.http = http;
-exports.w3org = w3org;
-exports.xmlNS = xmlNS;
-exports.xmlnsNS = xmlnsNS;
-
-exports.hasLeadingOrTrailingWhitespace = hasLeadingOrTrailingWhitespace;
-exports.isXmlNSDeclaration = isXmlNSDeclaration;
-exports.xmlAppendChild = xmlAppendChild;
-exports.xmlAppendChildren = xmlAppendChildren;
-exports.xmlAttributeNode = xmlAttributeNode;
-exports.xmlAttributes = xmlAttributes;
-exports.xmlAttributeValue = xmlAttributeValue;
-exports.xmlBaseURI = xmlBaseURI;
-exports.xmlChildElements = xmlChildElements;
-exports.xmlFindElementByPath = xmlFindElementByPath;
-exports.xmlFindNodeByPath = xmlFindNodeByPath;
-exports.xmlFirstChildElement = xmlFirstChildElement;
-exports.xmlFirstDescendantElement = xmlFirstDescendantElement;
-exports.xmlInnerText = xmlInnerText;
-exports.xmlLocalName = xmlLocalName;
-exports.xmlNamespaceURI = xmlNamespaceURI;
-exports.xmlNodeValue = xmlNodeValue;
-exports.xmlDom = xmlDom;
-exports.xmlNewAttribute = xmlNewAttribute;
-exports.xmlNewElement = xmlNewElement;
-exports.xmlNewFragment = xmlNewFragment;
-exports.xmlNewNodeByPath = xmlNewNodeByPath;
-exports.xmlNewNSDeclaration = xmlNewNSDeclaration;
-exports.xmlNewText = xmlNewText;
-exports.xmlParse = xmlParse;
-exports.xmlQualifiedName = xmlQualifiedName;
-exports.xmlSerialize = xmlSerialize;
-exports.xmlSerializeDescendants = xmlSerializeDescendants;
-exports.xmlSiblingElement = xmlSiblingElement;
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/87e35975/odatajs/src/lib/store/dom.js
----------------------------------------------------------------------
diff --git a/odatajs/src/lib/store/dom.js b/odatajs/src/lib/store/dom.js
index ca9d27c..355b70e 100644
--- a/odatajs/src/lib/store/dom.js
+++ b/odatajs/src/lib/store/dom.js
@@ -21,7 +21,7 @@
-var utils = require('./../odatajs/utils.js');
+var utils = require('./../utils.js');
// Imports.
var throwErrorCallback = utils.throwErrorCallback;
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/87e35975/odatajs/src/lib/store/indexeddb.js
----------------------------------------------------------------------
diff --git a/odatajs/src/lib/store/indexeddb.js b/odatajs/src/lib/store/indexeddb.js
index 5c17816..0150e3f 100644
--- a/odatajs/src/lib/store/indexeddb.js
+++ b/odatajs/src/lib/store/indexeddb.js
@@ -18,7 +18,7 @@
*/
/** @module store/indexeddb */
-var utils = require('./../odatajs/utils.js');
+var utils = require('./../utils.js');
// Imports.
var throwErrorCallback = utils.throwErrorCallback;
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/87e35975/odatajs/src/lib/store/memory.js
----------------------------------------------------------------------
diff --git a/odatajs/src/lib/store/memory.js b/odatajs/src/lib/store/memory.js
index 08ddafe..fa49e01 100644
--- a/odatajs/src/lib/store/memory.js
+++ b/odatajs/src/lib/store/memory.js
@@ -20,7 +20,7 @@
/** @module store/memory */
-var utils = require('./../odatajs/utils.js');
+var utils = require('./../utils.js');
// Imports.
var throwErrorCallback = utils.throwErrorCallback;
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/87e35975/odatajs/src/lib/utils.js
----------------------------------------------------------------------
diff --git a/odatajs/src/lib/utils.js b/odatajs/src/lib/utils.js
new file mode 100644
index 0000000..27af705
--- /dev/null
+++ b/odatajs/src/lib/utils.js
@@ -0,0 +1,582 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/** @module datajs/utils */
+
+
+function inBrowser() {
+ return typeof window !== 'undefined';
+}
+
+/** Creates a new ActiveXObject from the given progId.
+ * @param {String} progId - ProgId string of the desired ActiveXObject.
+ * @returns {Object} The ActiveXObject instance. Null if ActiveX is not supported by the browser.
+ * This function throws whatever exception might occur during the creation
+ * of the ActiveXObject.
+*/
+var activeXObject = function (progId) {
+
+ if (window.ActiveXObject) {
+ return new window.ActiveXObject(progId);
+ }
+ return null;
+};
+
+/** Checks whether the specified value is different from null and undefined.
+ * @param [value] Value to check ( may be null)
+ * @returns {Boolean} true if the value is assigned; false otherwise.
+*/
+function assigned(value) {
+ return value !== null && value !== undefined;
+}
+
+/** Checks whether the specified item is in the array.
+ * @param {Array} [arr] Array to check in.
+ * @param item - Item to look for.
+ * @returns {Boolean} true if the item is contained, false otherwise.
+*/
+function contains(arr, item) {
+ var i, len;
+ for (i = 0, len = arr.length; i < len; i++) {
+ if (arr[i] === item) {
+ return true;
+ }
+ }
+ return false;
+}
+
+/** Given two values, picks the first one that is not undefined.
+ * @param a - First value.
+ * @param b - Second value.
+ * @returns a if it's a defined value; else b.</returns>
+ */
+function defined(a, b) {
+ return (a !== undefined) ? a : b;
+}
+
+/** Delays the invocation of the specified function until execution unwinds.
+ * @param {Function} callback - Callback function.
+ */
+function delay(callback) {
+
+ if (arguments.length === 1) {
+ window.setTimeout(callback, 0);
+ return;
+ }
+
+ var args = Array.prototype.slice.call(arguments, 1);
+ window.setTimeout(function () {
+ callback.apply(this, args);
+ }, 0);
+}
+
+/** Throws an exception in case that a condition evaluates to false.
+ * @param {Boolean} condition - Condition to evaluate.
+ * @param {String} message - Message explaining the assertion.
+ * @param {Object} data - Additional data to be included in the exception.
+ */
+// DATAJS INTERNAL START
+function djsassert(condition, message, data) {
+
+
+ if (!condition) {
+ throw { message: "Assert fired: " + message, data: data };
+ }
+}
+// DATAJS INTERNAL END
+
+/** Extends the target with the specified values.
+ * @param {Object} target - Object to add properties to.
+ * @param {Object} values - Object with properties to add into target.
+ * @returns {Object} The target object.
+*/
+function extend(target, values) {
+ for (var name in values) {
+ target[name] = values[name];
+ }
+
+ return target;
+}
+
+function find(arr, callback) {
+ /** Returns the first item in the array that makes the callback function true.
+ * @param {Array} [arr] Array to check in. ( may be null)
+ * @param {Function} callback - Callback function to invoke once per item in the array.
+ * @returns The first item that makes the callback return true; null otherwise or if the array is null.
+ */
+
+ if (arr) {
+ var i, len;
+ for (i = 0, len = arr.length; i < len; i++) {
+ if (callback(arr[i])) {
+ return arr[i];
+ }
+ }
+ }
+ return null;
+}
+
+function isArray(value) {
+ /** Checks whether the specified value is an array object.
+ * @param value - Value to check.
+ * @returns {Boolean} true if the value is an array object; false otherwise.
+ */
+
+ return Object.prototype.toString.call(value) === "[object Array]";
+}
+
+/** Checks whether the specified value is a Date object.
+ * @param value - Value to check.
+ * @returns {Boolean} true if the value is a Date object; false otherwise.
+ */
+function isDate(value) {
+ return Object.prototype.toString.call(value) === "[object Date]";
+}
+
+/** Tests whether a value is an object.
+ * @param value - Value to test.
+ * @returns {Boolean} True is the value is an object; false otherwise.
+ * Per javascript rules, null and array values are objects and will cause this function to return true.
+ */
+function isObject(value) {
+ return typeof value === "object";
+}
+
+/** Parses a value in base 10.
+ * @param {String} value - String value to parse.
+ * @returns {Number} The parsed value, NaN if not a valid value.
+*/
+function parseInt10(value) {
+ return parseInt(value, 10);
+}
+
+/** Renames a property in an object.
+ * @param {Object} obj - Object in which the property will be renamed.
+ * @param {String} oldName - Name of the property that will be renamed.
+ * @param {String} newName - New name of the property.
+ * This function will not do anything if the object doesn't own a property with the specified old name.
+ */
+function renameProperty(obj, oldName, newName) {
+ if (obj.hasOwnProperty(oldName)) {
+ obj[newName] = obj[oldName];
+ delete obj[oldName];
+ }
+}
+
+/** Default error handler.
+ * @param {Object} error - Error to handle.
+ */
+function throwErrorCallback(error) {
+ throw error;
+}
+
+/** Removes leading and trailing whitespaces from a string.
+ * @param {String str String to trim
+ * @returns {String} The string with no leading or trailing whitespace.
+ */
+function trimString(str) {
+ if (str.trim) {
+ return str.trim();
+ }
+
+ return str.replace(/^\s+|\s+$/g, '');
+}
+
+/** Returns a default value in place of undefined.
+ * @param [value] Value to check (may be null)
+ * @param defaultValue - Value to return if value is undefined.
+ * @returns value if it's defined; defaultValue otherwise.
+ * This should only be used for cases where falsy values are valid;
+ * otherwise the pattern should be 'x = (value) ? value : defaultValue;'.
+ */
+function undefinedDefault(value, defaultValue) {
+ return (value !== undefined) ? value : defaultValue;
+}
+
+// Regular expression that splits a uri into its components:
+// 0 - is the matched string.
+// 1 - is the scheme.
+// 2 - is the authority.
+// 3 - is the path.
+// 4 - is the query.
+// 5 - is the fragment.
+var uriRegEx = /^([^:\/?#]+:)?(\/\/[^\/?#]*)?([^?#:]+)?(\?[^#]*)?(#.*)?/;
+var uriPartNames = ["scheme", "authority", "path", "query", "fragment"];
+
+/** Gets information about the components of the specified URI.
+ * @param {String} uri - URI to get information from.
+ * @return {Object} An object with an isAbsolute flag and part names (scheme, authority, etc.) if available.
+ */
+function getURIInfo(uri) {
+ var result = { isAbsolute: false };
+
+ if (uri) {
+ var matches = uriRegEx.exec(uri);
+ if (matches) {
+ var i, len;
+ for (i = 0, len = uriPartNames.length; i < len; i++) {
+ if (matches[i + 1]) {
+ result[uriPartNames[i]] = matches[i + 1];
+ }
+ }
+ }
+ if (result.scheme) {
+ result.isAbsolute = true;
+ }
+ }
+
+ return result;
+}
+
+/** Builds a URI string from its components.
+ * @param {Object} uriInfo - An object with uri parts (scheme, authority, etc.).
+ * @returns {String} URI string.
+ */
+function getURIFromInfo(uriInfo) {
+ return "".concat(
+ uriInfo.scheme || "",
+ uriInfo.authority || "",
+ uriInfo.path || "",
+ uriInfo.query || "",
+ uriInfo.fragment || "");
+}
+
+// Regular expression that splits a uri authority into its subcomponents:
+// 0 - is the matched string.
+// 1 - is the userinfo subcomponent.
+// 2 - is the host subcomponent.
+// 3 - is the port component.
+var uriAuthorityRegEx = /^\/{0,2}(?:([^@]*)@)?([^:]+)(?::{1}(\d+))?/;
+
+// Regular expression that matches percentage enconded octects (i.e %20 or %3A);
+var pctEncodingRegEx = /%[0-9A-F]{2}/ig;
+
+/** Normalizes the casing of a URI.
+ * @param {String} uri - URI to normalize, absolute or relative.
+ * @returns {String} The URI normalized to lower case.
+*/
+function normalizeURICase(uri) {
+ var uriInfo = getURIInfo(uri);
+ var scheme = uriInfo.scheme;
+ var authority = uriInfo.authority;
+
+ if (scheme) {
+ uriInfo.scheme = scheme.toLowerCase();
+ if (authority) {
+ var matches = uriAuthorityRegEx.exec(authority);
+ if (matches) {
+ uriInfo.authority = "//" +
+ (matches[1] ? matches[1] + "@" : "") +
+ (matches[2].toLowerCase()) +
+ (matches[3] ? ":" + matches[3] : "");
+ }
+ }
+ }
+
+ uri = getURIFromInfo(uriInfo);
+
+ return uri.replace(pctEncodingRegEx, function (str) {
+ return str.toLowerCase();
+ });
+}
+
+/** Normalizes a possibly relative URI with a base URI.
+ * @param {String} uri - URI to normalize, absolute or relative
+ * @param {String} base - Base URI to compose with (may be null)
+ * @returns {String} The composed URI if relative; the original one if absolute.
+ */
+function normalizeURI(uri, base) {
+ if (!base) {
+ return uri;
+ }
+
+ var uriInfo = getURIInfo(uri);
+ if (uriInfo.isAbsolute) {
+ return uri;
+ }
+
+ var baseInfo = getURIInfo(base);
+ var normInfo = {};
+ var path;
+
+ if (uriInfo.authority) {
+ normInfo.authority = uriInfo.authority;
+ path = uriInfo.path;
+ normInfo.query = uriInfo.query;
+ } else {
+ if (!uriInfo.path) {
+ path = baseInfo.path;
+ normInfo.query = uriInfo.query || baseInfo.query;
+ } else {
+ if (uriInfo.path.charAt(0) === '/') {
+ path = uriInfo.path;
+ } else {
+ path = mergeUriPathWithBase(uriInfo.path, baseInfo.path);
+ }
+ normInfo.query = uriInfo.query;
+ }
+ normInfo.authority = baseInfo.authority;
+ }
+
+ normInfo.path = removeDotsFromPath(path);
+
+ normInfo.scheme = baseInfo.scheme;
+ normInfo.fragment = uriInfo.fragment;
+
+ return getURIFromInfo(normInfo);
+}
+
+/** Merges the path of a relative URI and a base URI.
+ * @param {String} uriPath - Relative URI path.</param>
+ * @param {String} basePath - Base URI path.
+ * @returns {String} A string with the merged path.
+ */
+function mergeUriPathWithBase(uriPath, basePath) {
+ var path = "/";
+ var end;
+
+ if (basePath) {
+ end = basePath.lastIndexOf("/");
+ path = basePath.substring(0, end);
+
+ if (path.charAt(path.length - 1) !== "/") {
+ path = path + "/";
+ }
+ }
+
+ return path + uriPath;
+}
+
+/** Removes the special folders . and .. from a URI's path.
+ * @param {string} path - URI path component.
+ * @returns {String} Path without any . and .. folders.
+ */
+function removeDotsFromPath(path) {
+ var result = "";
+ var segment = "";
+ var end;
+
+ while (path) {
+ if (path.indexOf("..") === 0 || path.indexOf(".") === 0) {
+ path = path.replace(/^\.\.?\/?/g, "");
+ } else if (path.indexOf("/..") === 0) {
+ path = path.replace(/^\/\..\/?/g, "/");
+ end = result.lastIndexOf("/");
+ if (end === -1) {
+ result = "";
+ } else {
+ result = result.substring(0, end);
+ }
+ } else if (path.indexOf("/.") === 0) {
+ path = path.replace(/^\/\.\/?/g, "/");
+ } else {
+ segment = path;
+ end = path.indexOf("/", 1);
+ if (end !== -1) {
+ segment = path.substring(0, end);
+ }
+ result = result + segment;
+ path = path.replace(segment, "");
+ }
+ }
+ return result;
+}
+
+function convertByteArrayToHexString(str) {
+ var arr = [];
+ if (window.atob === undefined) {
+ arr = decodeBase64(str);
+ } else {
+ var binaryStr = window.atob(str);
+ for (var i = 0; i < binaryStr.length; i++) {
+ arr.push(binaryStr.charCodeAt(i));
+ }
+ }
+ var hexValue = "";
+ var hexValues = "0123456789ABCDEF";
+ for (var j = 0; j < arr.length; j++) {
+ var t = arr[j];
+ hexValue += hexValues[t >> 4];
+ hexValue += hexValues[t & 0x0F];
+ }
+ return hexValue;
+}
+
+function decodeBase64(str) {
+ var binaryString = "";
+ for (var i = 0; i < str.length; i++) {
+ var base65IndexValue = getBase64IndexValue(str[i]);
+ var binaryValue = "";
+ if (base65IndexValue !== null) {
+ binaryValue = base65IndexValue.toString(2);
+ binaryString += addBase64Padding(binaryValue);
+ }
+ }
+ var byteArray = [];
+ var numberOfBytes = parseInt(binaryString.length / 8, 10);
+ for (i = 0; i < numberOfBytes; i++) {
+ var intValue = parseInt(binaryString.substring(i * 8, (i + 1) * 8), 2);
+ byteArray.push(intValue);
+ }
+ return byteArray;
+}
+
+function getBase64IndexValue(character) {
+ var asciiCode = character.charCodeAt(0);
+ var asciiOfA = 65;
+ var differenceBetweenZanda = 6;
+ if (asciiCode >= 65 && asciiCode <= 90) { // between "A" and "Z" inclusive
+ return asciiCode - asciiOfA;
+ } else if (asciiCode >= 97 && asciiCode <= 122) { // between 'a' and 'z' inclusive
+ return asciiCode - asciiOfA - differenceBetweenZanda;
+ } else if (asciiCode >= 48 && asciiCode <= 57) { // between '0' and '9' inclusive
+ return asciiCode + 4;
+ } else if (character == "+") {
+ return 62;
+ } else if (character == "/") {
+ return 63;
+ } else {
+ return null;
+ }
+}
+
+function addBase64Padding(binaryString) {
+ while (binaryString.length < 6) {
+ binaryString = "0" + binaryString;
+ }
+ return binaryString;
+
+}
+
+function getJsonValueArraryLength(data) {
+ if (data && data.value) {
+ return data.value.length;
+ }
+
+ return 0;
+}
+
+function sliceJsonValueArray(data, start, end) {
+ if (data === undefined || data.value === undefined) {
+ return data;
+ }
+
+ if (start < 0) {
+ start = 0;
+ }
+
+ var length = getJsonValueArraryLength(data);
+ if (length < end) {
+ end = length;
+ }
+
+ var newdata = {};
+ for (var property in data) {
+ if (property == "value") {
+ newdata[property] = data[property].slice(start, end);
+ } else {
+ newdata[property] = data[property];
+ }
+ }
+
+ return newdata;
+}
+
+function concatJsonValueArray(data, concatData) {
+ if (concatData === undefined || concatData.value === undefined) {
+ return data;
+ }
+
+ if (data === undefined || Object.keys(data).length === 0) {
+ return concatData;
+ }
+
+ if (data.value === undefined) {
+ data.value = concatData.value;
+ return data;
+ }
+
+ data.value = data.value.concat(concatData.value);
+
+ return data;
+}
+
+function endsWith(input, search) {
+ return input.indexOf(search, input.length - search.length) !== -1;
+}
+
+function startsWith (input, search) {
+ return input.indexOf(search) === 0;
+}
+
+function getFormatKind(format, defaultFormatKind) {
+ var formatKind = defaultFormatKind;
+ if (!assigned(format)) {
+ return formatKind;
+ }
+
+ var normalizedFormat = format.toLowerCase();
+ switch (normalizedFormat) {
+ case "none":
+ formatKind = 0;
+ break;
+ case "minimal":
+ formatKind = 1;
+ break;
+ case "full":
+ formatKind = 2;
+ break;
+ default:
+ break;
+ }
+
+ return formatKind;
+}
+
+
+
+
+exports.inBrowser = inBrowser;
+exports.activeXObject = activeXObject;
+exports.assigned = assigned;
+exports.contains = contains;
+exports.defined = defined;
+exports.delay = delay;
+exports.djsassert = djsassert;
+exports.extend = extend;
+exports.find = find;
+exports.getURIInfo = getURIInfo;
+exports.isArray = isArray;
+exports.isDate = isDate;
+exports.isObject = isObject;
+exports.normalizeURI = normalizeURI;
+exports.normalizeURICase = normalizeURICase;
+exports.parseInt10 = parseInt10;
+exports.renameProperty = renameProperty;
+exports.throwErrorCallback = throwErrorCallback;
+exports.trimString = trimString;
+exports.undefinedDefault = undefinedDefault;
+exports.decodeBase64 = decodeBase64;
+exports.convertByteArrayToHexString = convertByteArrayToHexString;
+exports.getJsonValueArraryLength = getJsonValueArraryLength;
+exports.sliceJsonValueArray = sliceJsonValueArray;
+exports.concatJsonValueArray = concatJsonValueArray;
+exports.startsWith = startsWith;
+exports.endsWith = endsWith;
+exports.getFormatKind = getFormatKind;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/87e35975/odatajs/src/lib/xml.js
----------------------------------------------------------------------
diff --git a/odatajs/src/lib/xml.js b/odatajs/src/lib/xml.js
new file mode 100644
index 0000000..e519c60
--- /dev/null
+++ b/odatajs/src/lib/xml.js
@@ -0,0 +1,816 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+/** @module datajs/xml */
+
+var utils = require('./../utils.js');
+
+var activeXObject = utils.activeXObject;
+var djsassert = utils.djsassert;
+var extend = utils.extend;
+var isArray = utils.isArray;
+var normalizeURI = utils.normalizeURI;
+
+// URI prefixes to generate smaller code.
+var http = "http://";
+var w3org = http + "www.w3.org/"; // http://www.w3.org/
+
+var xhtmlNS = w3org + "1999/xhtml"; // http://www.w3.org/1999/xhtml
+var xmlnsNS = w3org + "2000/xmlns/"; // http://www.w3.org/2000/xmlns/
+var xmlNS = w3org + "XML/1998/namespace"; // http://www.w3.org/XML/1998/namespace
+
+var mozillaParserErroNS = http + "www.mozilla.org/newlayout/xml/parsererror.xml";
+
+/** Checks whether the specified string has leading or trailing spaces.
+ * @param {String} text - String to check.
+ * @returns {Boolean} true if text has any leading or trailing whitespace; false otherwise.
+ */
+function hasLeadingOrTrailingWhitespace(text) {
+ var re = /(^\s)|(\s$)/;
+ return re.test(text);
+}
+
+/** Determines whether the specified text is empty or whitespace.
+ * @param {String} text - Value to inspect.
+ * @returns {Boolean} true if the text value is empty or all whitespace; false otherwise.
+ */
+function isWhitespace(text) {
+
+
+ var ws = /^\s*$/;
+ return text === null || ws.test(text);
+}
+
+/** Determines whether the specified element has xml:space='preserve' applied.
+ * @param domElement - Element to inspect.
+ * @returns {Boolean} Whether xml:space='preserve' is in effect.
+ */
+function isWhitespacePreserveContext(domElement) {
+
+
+ while (domElement !== null && domElement.nodeType === 1) {
+ var val = xmlAttributeValue(domElement, "space", xmlNS);
+ if (val === "preserve") {
+ return true;
+ } else if (val === "default") {
+ break;
+ } else {
+ domElement = domElement.parentNode;
+ }
+ }
+
+ return false;
+}
+
+/** Determines whether the attribute is a XML namespace declaration.
+ * @param domAttribute - Element to inspect.
+ * @return {Boolean} True if the attribute is a namespace declaration (its name is 'xmlns' or starts with 'xmlns:'; false otherwise.
+ */
+function isXmlNSDeclaration(domAttribute) {
+ var nodeName = domAttribute.nodeName;
+ return nodeName == "xmlns" || nodeName.indexOf("xmlns:") === 0;
+}
+
+/** Safely set as property in an object by invoking obj.setProperty.
+ * @param obj - Object that exposes a setProperty method.
+ * @param {String} name - Property name
+ * @param value - Property value.
+ */
+function safeSetProperty(obj, name, value) {
+
+
+ try {
+ obj.setProperty(name, value);
+ } catch (_) { }
+}
+
+/** Creates an configures new MSXML 3.0 ActiveX object.
+ * @returns {Object} New MSXML 3.0 ActiveX object.
+ * This function throws any exception that occurs during the creation
+ * of the MSXML 3.0 ActiveX object.
+ */
+function msXmlDom3() {
+ var msxml3 = activeXObject("Msxml2.DOMDocument.3.0");
+ if (msxml3) {
+ safeSetProperty(msxml3, "ProhibitDTD", true);
+ safeSetProperty(msxml3, "MaxElementDepth", 256);
+ safeSetProperty(msxml3, "AllowDocumentFunction", false);
+ safeSetProperty(msxml3, "AllowXsltScript", false);
+ }
+ return msxml3;
+}
+
+/** Creates an configures new MSXML 6.0 or MSXML 3.0 ActiveX object.
+ * @returns {Object} New MSXML 3.0 ActiveX object.
+ * This function will try to create a new MSXML 6.0 ActiveX object. If it fails then
+ * it will fallback to create a new MSXML 3.0 ActiveX object. Any exception that
+ * happens during the creation of the MSXML 6.0 will be handled by the function while
+ * the ones that happend during the creation of the MSXML 3.0 will be thrown.
+ */
+function msXmlDom() {
+ try {
+ var msxml = activeXObject("Msxml2.DOMDocument.6.0");
+ if (msxml) {
+ msxml.async = true;
+ }
+ return msxml;
+ } catch (_) {
+ return msXmlDom3();
+ }
+}
+
+/** Parses an XML string using the MSXML DOM.
+ * @returns {Object} New MSXML DOMDocument node representing the parsed XML string.
+ * This function throws any exception that occurs during the creation
+ * of the MSXML ActiveX object. It also will throw an exception
+ * in case of a parsing error.
+ */
+function msXmlParse(text) {
+ var dom = msXmlDom();
+ if (!dom) {
+ return null;
+ }
+
+ dom.loadXML(text);
+ var parseError = dom.parseError;
+ if (parseError.errorCode !== 0) {
+ xmlThrowParserError(parseError.reason, parseError.srcText, text);
+ }
+ return dom;
+}
+
+/** Throws a new exception containing XML parsing error information.
+ * @param exceptionOrReason - String indicating the reason of the parsing failure or Object detailing the parsing error.
+ * @param {String} srcText - String indicating the part of the XML string that caused the parsing error.
+ * @param {String} errorXmlText - XML string for wich the parsing failed.
+ */
+function xmlThrowParserError(exceptionOrReason, srcText, errorXmlText) {
+
+ if (typeof exceptionOrReason === "string") {
+ exceptionOrReason = { message: exceptionOrReason };
+ }
+ throw extend(exceptionOrReason, { srcText: srcText || "", errorXmlText: errorXmlText || "" });
+}
+
+/** Returns an XML DOM document from the specified text.
+ * @param {String} text - Document text.
+ * @returns XML DOM document.
+ * This function will throw an exception in case of a parse error
+ */
+function xmlParse(text) {
+ var domParser = window.DOMParser && new window.DOMParser();
+ var dom;
+
+ if (!domParser) {
+ dom = msXmlParse(text);
+ if (!dom) {
+ xmlThrowParserError("XML DOM parser not supported");
+ }
+ return dom;
+ }
+
+ try {
+ dom = domParser.parseFromString(text, "text/xml");
+ } catch (e) {
+ xmlThrowParserError(e, "", text);
+ }
+
+ var element = dom.documentElement;
+ var nsURI = element.namespaceURI;
+ var localName = xmlLocalName(element);
+
+ // Firefox reports errors by returing the DOM for an xml document describing the problem.
+ if (localName === "parsererror" && nsURI === mozillaParserErroNS) {
+ var srcTextElement = xmlFirstChildElement(element, mozillaParserErroNS, "sourcetext");
+ var srcText = srcTextElement ? xmlNodeValue(srcTextElement) : "";
+ xmlThrowParserError(xmlInnerText(element) || "", srcText, text);
+ }
+
+ // Chrome (and maybe other webkit based browsers) report errors by injecting a header with an error message.
+ // The error may be localized, so instead we simply check for a header as the
+ // top element or descendant child of the document.
+ if (localName === "h3" && nsURI === xhtmlNS || xmlFirstDescendantElement(element, xhtmlNS, "h3")) {
+ var reason = "";
+ var siblings = [];
+ var cursor = element.firstChild;
+ while (cursor) {
+ if (cursor.nodeType === 1) {
+ reason += xmlInnerText(cursor) || "";
+ }
+ siblings.push(cursor.nextSibling);
+ cursor = cursor.firstChild || siblings.shift();
+ }
+ reason += xmlInnerText(element) || "";
+ xmlThrowParserError(reason, "", text);
+ }
+
+ return dom;
+}
+
+/** Builds a XML qualified name string in the form of "prefix:name".
+ * @param {String} prefix - Prefix string (may be null)
+ * @param {String} name - Name string to qualify with the prefix.
+ * @returns {String} Qualified name.
+ */
+function xmlQualifiedName(prefix, name) {
+ return prefix ? prefix + ":" + name : name;
+}
+
+/** Appends a text node into the specified DOM element node.
+ * @param domNode - DOM node for the element.
+ * @param {String} text - Text to append as a child of element.
+*/
+function xmlAppendText(domNode, textNode) {
+ if (hasLeadingOrTrailingWhitespace(textNode.data)) {
+ var attr = xmlAttributeNode(domNode, xmlNS, "space");
+ if (!attr) {
+ attr = xmlNewAttribute(domNode.ownerDocument, xmlNS, xmlQualifiedName("xml", "space"));
+ xmlAppendChild(domNode, attr);
+ }
+ attr.value = "preserve";
+ }
+ domNode.appendChild(textNode);
+ return domNode;
+}
+
+/** Iterates through the XML element's attributes and invokes the callback function for each one.
+ * @param element - Wrapped element to iterate over.
+ * @param {Function} onAttributeCallback - Callback function to invoke with wrapped attribute nodes.
+*/
+function xmlAttributes(element, onAttributeCallback) {
+ var attributes = element.attributes;
+ var i, len;
+ for (i = 0, len = attributes.length; i < len; i++) {
+ onAttributeCallback(attributes.item(i));
+ }
+}
+
+/** Returns the value of a DOM element's attribute.
+ * @param domNode - DOM node for the owning element.
+ * @param {String} localName - Local name of the attribute.
+ * @param {String} nsURI - Namespace URI of the attribute.
+ * @returns {String} - The attribute value, null if not found (may be null)
+ */
+function xmlAttributeValue(domNode, localName, nsURI) {
+
+ var attribute = xmlAttributeNode(domNode, localName, nsURI);
+ return attribute ? xmlNodeValue(attribute) : null;
+}
+
+/** Gets an attribute node from a DOM element.
+ * @param domNode - DOM node for the owning element.
+ * @param {String} localName - Local name of the attribute.
+ * @param {String} nsURI - Namespace URI of the attribute.
+ * @returns The attribute node, null if not found.
+ */
+function xmlAttributeNode(domNode, localName, nsURI) {
+
+ var attributes = domNode.attributes;
+ if (attributes.getNamedItemNS) {
+ return attributes.getNamedItemNS(nsURI || null, localName);
+ }
+
+ return attributes.getQualifiedItem(localName, nsURI) || null;
+}
+
+/** Gets the value of the xml:base attribute on the specified element.
+ * @param domNode - Element to get xml:base attribute value from.
+ * @param [baseURI] - Base URI used to normalize the value of the xml:base attribute ( may be null)
+ * @returns {String} Value of the xml:base attribute if found; the baseURI or null otherwise.
+ */
+function xmlBaseURI(domNode, baseURI) {
+
+ var base = xmlAttributeNode(domNode, "base", xmlNS);
+ return (base ? normalizeURI(base.value, baseURI) : baseURI) || null;
+}
+
+
+/** Iterates through the XML element's child DOM elements and invokes the callback function for each one.
+ * @param element - DOM Node containing the DOM elements to iterate over.
+ * @param {Function} onElementCallback - Callback function to invoke for each child DOM element.
+*/
+function xmlChildElements(domNode, onElementCallback) {
+
+ xmlTraverse(domNode, /*recursive*/false, function (child) {
+ if (child.nodeType === 1) {
+ onElementCallback(child);
+ }
+ // continue traversing.
+ return true;
+ });
+}
+
+/** Gets the descendant element under root that corresponds to the specified path and namespace URI.
+ * @param root - DOM element node from which to get the descendant element.
+ * @param {String} namespaceURI - The namespace URI of the element to match.
+ * @param {String} path - Path to the desired descendant element.
+ * @return The element specified by path and namespace URI.
+ * All the elements in the path are matched against namespaceURI.
+ * The function will stop searching on the first element that doesn't match the namespace and the path.
+ */
+function xmlFindElementByPath(root, namespaceURI, path) {
+ var parts = path.split("/");
+ var i, len;
+ for (i = 0, len = parts.length; i < len; i++) {
+ root = root && xmlFirstChildElement(root, namespaceURI, parts[i]);
+ }
+ return root || null;
+}
+
+/** Gets the DOM element or DOM attribute node under root that corresponds to the specified path and namespace URI.
+ * @param root - DOM element node from which to get the descendant node.
+ * @param {String} namespaceURI - The namespace URI of the node to match.
+ * @param {String} path - Path to the desired descendant node.
+ * @return The node specified by path and namespace URI.</returns>
+
+* This function will traverse the path and match each node associated to a path segement against the namespace URI.
+* The traversal stops when the whole path has been exahusted or a node that doesn't belogong the specified namespace is encountered.
+* The last segment of the path may be decorated with a starting @ character to indicate that the desired node is a DOM attribute.
+*/
+function xmlFindNodeByPath(root, namespaceURI, path) {
+
+
+ var lastSegmentStart = path.lastIndexOf("/");
+ var nodePath = path.substring(lastSegmentStart + 1);
+ var parentPath = path.substring(0, lastSegmentStart);
+
+ var node = parentPath ? xmlFindElementByPath(root, namespaceURI, parentPath) : root;
+ if (node) {
+ if (nodePath.charAt(0) === "@") {
+ return xmlAttributeNode(node, nodePath.substring(1), namespaceURI);
+ }
+ return xmlFirstChildElement(node, namespaceURI, nodePath);
+ }
+ return null;
+}
+
+/** Returns the first child DOM element under the specified DOM node that matches the specified namespace URI and local name.
+ * @param domNode - DOM node from which the child DOM element is going to be retrieved.
+ * @param {String} [namespaceURI] -
+ * @param {String} [localName] -
+ * @return The node's first child DOM element that matches the specified namespace URI and local name; null otherwise.</returns>
+ */
+function xmlFirstChildElement(domNode, namespaceURI, localName) {
+
+ return xmlFirstElementMaybeRecursive(domNode, namespaceURI, localName, /*recursive*/false);
+}
+
+/** Returns the first descendant DOM element under the specified DOM node that matches the specified namespace URI and local name.
+ * @param domNode - DOM node from which the descendant DOM element is going to be retrieved.
+ * @param {String} [namespaceURI] -
+ * @param {String} [localName] -
+ * @return The node's first descendant DOM element that matches the specified namespace URI and local name; null otherwise.
+*/
+function xmlFirstDescendantElement(domNode, namespaceURI, localName) {
+ if (domNode.getElementsByTagNameNS) {
+ var result = domNode.getElementsByTagNameNS(namespaceURI, localName);
+ return result.length > 0 ? result[0] : null;
+ }
+ return xmlFirstElementMaybeRecursive(domNode, namespaceURI, localName, /*recursive*/true);
+}
+
+/** Returns the first descendant DOM element under the specified DOM node that matches the specified namespace URI and local name.
+ * @param domNode - DOM node from which the descendant DOM element is going to be retrieved.
+ * @param {String} [namespaceURI] -
+ * @param {String} [localName] -
+ * @param {Boolean} recursive
+ * - True if the search should include all the descendants of the DOM node.
+ * - False if the search should be scoped only to the direct children of the DOM node.
+ * @return The node's first descendant DOM element that matches the specified namespace URI and local name; null otherwise.
+ */
+function xmlFirstElementMaybeRecursive(domNode, namespaceURI, localName, recursive) {
+
+ var firstElement = null;
+ xmlTraverse(domNode, recursive, function (child) {
+ if (child.nodeType === 1) {
+ var isExpectedNamespace = !namespaceURI || xmlNamespaceURI(child) === namespaceURI;
+ var isExpectedNodeName = !localName || xmlLocalName(child) === localName;
+
+ if (isExpectedNamespace && isExpectedNodeName) {
+ firstElement = child;
+ }
+ }
+ return firstElement === null;
+ });
+ return firstElement;
+}
+
+/** Gets the concatenated value of all immediate child text and CDATA nodes for the specified element.
+ * @param domElement - Element to get values for.
+ * @returns {String} Text for all direct children.
+ */
+function xmlInnerText(xmlElement) {
+
+ var result = null;
+ var root = (xmlElement.nodeType === 9 && xmlElement.documentElement) ? xmlElement.documentElement : xmlElement;
+ var whitespaceAlreadyRemoved = root.ownerDocument.preserveWhiteSpace === false;
+ var whitespacePreserveContext;
+
+ xmlTraverse(root, false, function (child) {
+ if (child.nodeType === 3 || child.nodeType === 4) {
+ // isElementContentWhitespace indicates that this is 'ignorable whitespace',
+ // but it's not defined by all browsers, and does not honor xml:space='preserve'
+ // in some implementations.
+ //
+ // If we can't tell either way, we walk up the tree to figure out whether
+ // xml:space is set to preserve; otherwise we discard pure-whitespace.
+ //
+ // For example <a> <b>1</b></a>. The space between <a> and <b> is usually 'ignorable'.
+ var text = xmlNodeValue(child);
+ var shouldInclude = whitespaceAlreadyRemoved || !isWhitespace(text);
+ if (!shouldInclude) {
+ // Walk up the tree to figure out whether we are in xml:space='preserve' context
+ // for the cursor (needs to happen only once).
+ if (whitespacePreserveContext === undefined) {
+ whitespacePreserveContext = isWhitespacePreserveContext(root);
+ }
+
+ shouldInclude = whitespacePreserveContext;
+ }
+
+ if (shouldInclude) {
+ if (!result) {
+ result = text;
+ } else {
+ result += text;
+ }
+ }
+ }
+ // Continue traversing?
+ return true;
+ });
+ return result;
+}
+
+/** Returns the localName of a XML node.
+ * @param domNode - DOM node to get the value from.
+ * @returns {String} localName of domNode.
+ */
+function xmlLocalName(domNode) {
+
+ return domNode.localName || domNode.baseName;
+}
+
+/** Returns the namespace URI of a XML node.
+ * @param node - DOM node to get the value from.
+ * @returns {String} Namespace URI of domNode.
+ */
+function xmlNamespaceURI(domNode) {
+
+ return domNode.namespaceURI || null;
+}
+
+/** Returns the value or the inner text of a XML node.
+ * @param node - DOM node to get the value from.
+ * @return Value of the domNode or the inner text if domNode represents a DOM element node.
+ */
+function xmlNodeValue(domNode) {
+
+ if (domNode.nodeType === 1) {
+ return xmlInnerText(domNode);
+ }
+ return domNode.nodeValue;
+}
+
+/** Walks through the descendants of the domNode and invokes a callback for each node.
+ * @param domNode - DOM node whose descendants are going to be traversed.
+ * @param {Boolean} recursive
+ * - True if the traversal should include all the descenants of the DOM node.
+ * - False if the traversal should be scoped only to the direct children of the DOM node.
+ * @returns {String} Namespace URI of node.
+ */
+function xmlTraverse(domNode, recursive, onChildCallback) {
+
+ var subtrees = [];
+ var child = domNode.firstChild;
+ var proceed = true;
+ while (child && proceed) {
+ proceed = onChildCallback(child);
+ if (proceed) {
+ if (recursive && child.firstChild) {
+ subtrees.push(child.firstChild);
+ }
+ child = child.nextSibling || subtrees.shift();
+ }
+ }
+}
+
+/** Returns the next sibling DOM element of the specified DOM node.
+ * @param domNode - DOM node from which the next sibling is going to be retrieved.
+ * @param {String} [namespaceURI] -
+ * @param {String} [localName] -
+ * @return The node's next sibling DOM element, null if there is none.</returns>
+ */
+function xmlSiblingElement(domNode, namespaceURI, localName) {
+
+ var sibling = domNode.nextSibling;
+ while (sibling) {
+ if (sibling.nodeType === 1) {
+ var isExpectedNamespace = !namespaceURI || xmlNamespaceURI(sibling) === namespaceURI;
+ var isExpectedNodeName = !localName || xmlLocalName(sibling) === localName;
+
+ if (isExpectedNamespace && isExpectedNodeName) {
+ return sibling;
+ }
+ }
+ sibling = sibling.nextSibling;
+ }
+ return null;
+}
+
+/** Creates a new empty DOM document node.
+ * @return New DOM document node.</returns>
+ *
+ * This function will first try to create a native DOM document using
+ * the browsers createDocument function. If the browser doesn't
+ * support this but supports ActiveXObject, then an attempt to create
+ * an MSXML 6.0 DOM will be made. If this attempt fails too, then an attempt
+ * for creating an MXSML 3.0 DOM will be made. If this last attemp fails or
+ * the browser doesn't support ActiveXObject then an exception will be thrown.
+ */
+function xmlDom() {
+ var implementation = window.document.implementation;
+ return (implementation && implementation.createDocument) ?
+ implementation.createDocument(null, null, null) :
+ msXmlDom();
+}
+
+/** Appends a collection of child nodes or string values to a parent DOM node.
+ * @param parent - DOM node to which the children will be appended.
+ * @param {Array} children - Array containing DOM nodes or string values that will be appended to the parent.
+ * @return The parent with the appended children or string values.</returns>
+ * If a value in the children collection is a string, then a new DOM text node is going to be created
+ * for it and then appended to the parent.
+ */
+function xmlAppendChildren(parent, children) {
+ if (!isArray(children)) {
+ return xmlAppendChild(parent, children);
+ }
+
+ var i, len;
+ for (i = 0, len = children.length; i < len; i++) {
+ children[i] && xmlAppendChild(parent, children[i]);
+ }
+ return parent;
+}
+
+/** Appends a child node or a string value to a parent DOM node.
+ * @param parent - DOM node to which the child will be appended.
+ * @param child - Child DOM node or string value to append to the parent.
+ * @return The parent with the appended child or string value.</returns>
+ * If child is a string value, then a new DOM text node is going to be created
+ * for it and then appended to the parent.
+ */
+function xmlAppendChild(parent, child) {
+
+ djsassert(parent !== child, "xmlAppendChild() - parent and child are one and the same!");
+ if (child) {
+ if (typeof child === "string") {
+ return xmlAppendText(parent, xmlNewText(parent.ownerDocument, child));
+ }
+ if (child.nodeType === 2) {
+ parent.setAttributeNodeNS ? parent.setAttributeNodeNS(child) : parent.setAttributeNode(child);
+ } else {
+ parent.appendChild(child);
+ }
+ }
+ return parent;
+}
+
+/** Creates a new DOM attribute node.
+ * @param dom - DOM document used to create the attribute.
+ * @param {String} prefix - Namespace prefix.
+ * @param {String} namespaceURI - Namespace URI.
+ * @return DOM attribute node for the namespace declaration.
+ */
+function xmlNewAttribute(dom, namespaceURI, qualifiedName, value) {
+
+ var attribute =
+ dom.createAttributeNS && dom.createAttributeNS(namespaceURI, qualifiedName) ||
+ dom.createNode(2, qualifiedName, namespaceURI || undefined);
+
+ attribute.value = value || "";
+ return attribute;
+}
+
+/** Creates a new DOM element node.
+ * @param dom - DOM document used to create the DOM element.
+ * @param {String} namespaceURI - Namespace URI of the new DOM element.
+ * @param {String} qualifiedName - Qualified name in the form of "prefix:name" of the new DOM element.
+ * @param {Array} [children] Collection of child DOM nodes or string values that are going to be appended to the new DOM element.
+ * @return New DOM element.</returns>
+ * If a value in the children collection is a string, then a new DOM text node is going to be created
+ * for it and then appended to the new DOM element.
+ */
+function xmlNewElement(dom, nampespaceURI, qualifiedName, children) {
+ var element =
+ dom.createElementNS && dom.createElementNS(nampespaceURI, qualifiedName) ||
+ dom.createNode(1, qualifiedName, nampespaceURI || undefined);
+
+ return xmlAppendChildren(element, children || []);
+}
+
+/** Creates a namespace declaration attribute.
+ * @param dom - DOM document used to create the attribute.
+ * @param {String} namespaceURI - Namespace URI.
+ * @param {String} prefix - Namespace prefix.
+ * @return DOM attribute node for the namespace declaration.</returns>
+ */
+function xmlNewNSDeclaration(dom, namespaceURI, prefix) {
+ return xmlNewAttribute(dom, xmlnsNS, xmlQualifiedName("xmlns", prefix), namespaceURI);
+}
+
+/** Creates a new DOM document fragment node for the specified xml text.
+ * @param dom - DOM document from which the fragment node is going to be created.
+ * @param {String} text XML text to be represented by the XmlFragment.
+ * @return New DOM document fragment object.
+ */
+function xmlNewFragment(dom, text) {
+
+ var value = "<c>" + text + "</c>";
+ var tempDom = xmlParse(value);
+ var tempRoot = tempDom.documentElement;
+ var imported = ("importNode" in dom) ? dom.importNode(tempRoot, true) : tempRoot;
+ var fragment = dom.createDocumentFragment();
+
+ var importedChild = imported.firstChild;
+ while (importedChild) {
+ fragment.appendChild(importedChild);
+ importedChild = importedChild.nextSibling;
+ }
+ return fragment;
+}
+
+/** Creates new DOM text node.
+ * @param dom - DOM document used to create the text node.
+ * @param {String} text - Text value for the DOM text node.
+ * @return DOM text node.</returns>
+ */
+function xmlNewText(dom, text) {
+ return dom.createTextNode(text);
+}
+
+/** Creates a new DOM element or DOM attribute node as specified by path and appends it to the DOM tree pointed by root.
+ * @param dom - DOM document used to create the new node.
+ * @param root - DOM element node used as root of the subtree on which the new nodes are going to be created.
+ * @param {String} namespaceURI - Namespace URI of the new DOM element or attribute.
+ * @param {String} namespacePrefix - Prefix used to qualify the name of the new DOM element or attribute.
+ * @param {String} Path - Path string describing the location of the new DOM element or attribute from the root element.
+ * @return DOM element or attribute node for the last segment of the path.</returns>
+
+ * This function will traverse the path and will create a new DOM element with the specified namespace URI and prefix
+ * for each segment that doesn't have a matching element under root.
+ * The last segment of the path may be decorated with a starting @ character. In this case a new DOM attribute node
+ * will be created.
+ */
+function xmlNewNodeByPath(dom, root, namespaceURI, prefix, path) {
+ var name = "";
+ var parts = path.split("/");
+ var xmlFindNode = xmlFirstChildElement;
+ var xmlNewNode = xmlNewElement;
+ var xmlNode = root;
+
+ var i, len;
+ for (i = 0, len = parts.length; i < len; i++) {
+ name = parts[i];
+ if (name.charAt(0) === "@") {
+ name = name.substring(1);
+ xmlFindNode = xmlAttributeNode;
+ xmlNewNode = xmlNewAttribute;
+ }
+
+ var childNode = xmlFindNode(xmlNode, namespaceURI, name);
+ if (!childNode) {
+ childNode = xmlNewNode(dom, namespaceURI, xmlQualifiedName(prefix, name));
+ xmlAppendChild(xmlNode, childNode);
+ }
+ xmlNode = childNode;
+ }
+ return xmlNode;
+}
+
+/** Returns the text representation of the document to which the specified node belongs.
+ * @param root - Wrapped element in the document to serialize.
+ * @returns {String} Serialized document.
+*/
+function xmlSerialize(domNode) {
+ var xmlSerializer = window.XMLSerializer;
+ if (xmlSerializer) {
+ var serializer = new xmlSerializer();
+ return serializer.serializeToString(domNode);
+ }
+
+ if (domNode.xml) {
+ return domNode.xml;
+ }
+
+ throw { message: "XML serialization unsupported" };
+}
+
+/** Returns the XML representation of the all the descendants of the node.
+ * @param domNode - Node to serialize.</param>
+ * @returns {String} The XML representation of all the descendants of the node.
+ */
+function xmlSerializeDescendants(domNode) {
+ var children = domNode.childNodes;
+ var i, len = children.length;
+ if (len === 0) {
+ return "";
+ }
+
+ // Some implementations of the XMLSerializer don't deal very well with fragments that
+ // don't have a DOMElement as their first child. The work around is to wrap all the
+ // nodes in a dummy root node named "c", serialize it and then just extract the text between
+ // the <c> and the </c> substrings.
+
+ var dom = domNode.ownerDocument;
+ var fragment = dom.createDocumentFragment();
+ var fragmentRoot = dom.createElement("c");
+
+ fragment.appendChild(fragmentRoot);
+ // Move the children to the fragment tree.
+ for (i = 0; i < len; i++) {
+ fragmentRoot.appendChild(children[i]);
+ }
+
+ var xml = xmlSerialize(fragment);
+ xml = xml.substr(3, xml.length - 7);
+
+ // Move the children back to the original dom tree.
+ for (i = 0; i < len; i++) {
+ domNode.appendChild(fragmentRoot.childNodes[i]);
+ }
+
+ return xml;
+}
+
+/** Returns the XML representation of the node and all its descendants.
+ * @param domNode - Node to serialize
+ * @returns {String} The XML representation of the node and all its descendants.
+ */
+function xmlSerializeNode(domNode) {
+
+ var xml = domNode.xml;
+ if (xml !== undefined) {
+ return xml;
+ }
+
+ if (window.XMLSerializer) {
+ var serializer = new window.XMLSerializer();
+ return serializer.serializeToString(domNode);
+ }
+
+ throw { message: "XML serialization unsupported" };
+}
+
+exports.http = http;
+exports.w3org = w3org;
+exports.xmlNS = xmlNS;
+exports.xmlnsNS = xmlnsNS;
+
+exports.hasLeadingOrTrailingWhitespace = hasLeadingOrTrailingWhitespace;
+exports.isXmlNSDeclaration = isXmlNSDeclaration;
+exports.xmlAppendChild = xmlAppendChild;
+exports.xmlAppendChildren = xmlAppendChildren;
+exports.xmlAttributeNode = xmlAttributeNode;
+exports.xmlAttributes = xmlAttributes;
+exports.xmlAttributeValue = xmlAttributeValue;
+exports.xmlBaseURI = xmlBaseURI;
+exports.xmlChildElements = xmlChildElements;
+exports.xmlFindElementByPath = xmlFindElementByPath;
+exports.xmlFindNodeByPath = xmlFindNodeByPath;
+exports.xmlFirstChildElement = xmlFirstChildElement;
+exports.xmlFirstDescendantElement = xmlFirstDescendantElement;
+exports.xmlInnerText = xmlInnerText;
+exports.xmlLocalName = xmlLocalName;
+exports.xmlNamespaceURI = xmlNamespaceURI;
+exports.xmlNodeValue = xmlNodeValue;
+exports.xmlDom = xmlDom;
+exports.xmlNewAttribute = xmlNewAttribute;
+exports.xmlNewElement = xmlNewElement;
+exports.xmlNewFragment = xmlNewFragment;
+exports.xmlNewNodeByPath = xmlNewNodeByPath;
+exports.xmlNewNSDeclaration = xmlNewNSDeclaration;
+exports.xmlNewText = xmlNewText;
+exports.xmlParse = xmlParse;
+exports.xmlQualifiedName = xmlQualifiedName;
+exports.xmlSerialize = xmlSerialize;
+exports.xmlSerializeDescendants = xmlSerializeDescendants;
+exports.xmlSiblingElement = xmlSiblingElement;
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/87e35975/odatajs/test-node/test.html
----------------------------------------------------------------------
diff --git a/odatajs/test-node/test.html b/odatajs/test-node/test.html
new file mode 100644
index 0000000..12e75dd
--- /dev/null
+++ b/odatajs/test-node/test.html
@@ -0,0 +1,29 @@
+<!--/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */-->
+<html>
+ <head>
+ <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
+ <title>datajs startup perf test</title>
+ <script type="text/javascript" src="./../src/index2.js" ></script>
+ <script type="text/javascript" src="./../src/include.js" ></script>
+ </head>
+ <body>
+ XXX
+ </body>
+</html>
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/87e35975/odatajs/test-node/test.js
----------------------------------------------------------------------
diff --git a/odatajs/test-node/test.js b/odatajs/test-node/test.js
new file mode 100644
index 0000000..263366b
--- /dev/null
+++ b/odatajs/test-node/test.js
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+var x = require('./../src/index-no-browserify.js');
+//x.show();
+//x.included.show();
+console.log(x);
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/87e35975/odatajs/tests/odata-qunit-tests.htm
----------------------------------------------------------------------
diff --git a/odatajs/tests/odata-qunit-tests.htm b/odatajs/tests/odata-qunit-tests.htm
index e16eca0..064699d 100644
--- a/odatajs/tests/odata-qunit-tests.htm
+++ b/odatajs/tests/odata-qunit-tests.htm
@@ -42,7 +42,7 @@
<script type="text/javascript">
window.TestSynchronizer.init(QUnit);
</script>
- <script type="text/javascript" src="../build/lib/odatajs-4.0.0-beta-01-RC02.js"></script>
+ <script type="text/javascript" src="../build/lib/odatajs-latest.js"></script>
<script type="text/javascript" src="common/common.js"></script>
<script type="text/javascript" src="./common/mockHttpClient.js"></script>
[4/5] [OLINGO-442] Create packaging tool and remove browserify
Posted by ko...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/87e35975/odatajs/src/lib/odata/utils.js
----------------------------------------------------------------------
diff --git a/odatajs/src/lib/odata/utils.js b/odatajs/src/lib/odata/utils.js
deleted file mode 100644
index b728f14..0000000
--- a/odatajs/src/lib/odata/utils.js
+++ /dev/null
@@ -1,1265 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
- /** @module odata/utils */
-
-var utils = require('./../odatajs/utils.js');
-
-// Imports
-var assigned = utils.assigned;
-var contains = utils.contains;
-var find = utils.find;
-var isArray = utils.isArray;
-var isDate = utils.isDate;
-var isObject = utils.isObject;
-var parseInt10 = utils.parseInt10;
-
-
-/** Gets the type name of a data item value that belongs to a feed, an entry, a complex type property, or a collection property
- * @param {string} value - Value of the data item from which the type name is going to be retrieved.
- * @param {object} [metadata] - Object containing metadata about the data tiem.
- * @returns {string} Data item type name; null if the type name cannot be found within the value or the metadata
- * This function will first try to get the type name from the data item's value itself if it is an object with a __metadata property; otherwise
- * it will try to recover it from the metadata. If both attempts fail, it will return null.
- */
-var dataItemTypeName = function (value, metadata) {
- var valueTypeName = ((value && value.__metadata) || {}).type;
- return valueTypeName || (metadata ? metadata.type : null);
-};
-
-var EDM = "Edm.";
-var EDM_BOOLEAN = EDM + "Boolean";
-var EDM_BYTE = EDM + "Byte";
-var EDM_SBYTE = EDM + "SByte";
-var EDM_INT16 = EDM + "Int16";
-var EDM_INT32 = EDM + "Int32";
-var EDM_INT64 = EDM + "Int64";
-var EDM_SINGLE = EDM + "Single";
-var EDM_DOUBLE = EDM + "Double";
-var EDM_DECIMAL = EDM + "Decimal";
-var EDM_STRING = EDM + "String";
-
-var EDM_BINARY = EDM + "Binary";
-var EDM_DATE = EDM + "Date";
-var EDM_DATETIMEOFFSET = EDM + "DateTimeOffset";
-var EDM_DURATION = EDM + "Duration";
-var EDM_GUID = EDM + "Guid";
-var EDM_TIMEOFDAY = EDM + "Time";
-
-var GEOGRAPHY = "Geography";
-var EDM_GEOGRAPHY = EDM + GEOGRAPHY;
-var EDM_GEOGRAPHY_POINT = EDM_GEOGRAPHY + "Point";
-var EDM_GEOGRAPHY_LINESTRING = EDM_GEOGRAPHY + "LineString";
-var EDM_GEOGRAPHY_POLYGON = EDM_GEOGRAPHY + "Polygon";
-var EDM_GEOGRAPHY_COLLECTION = EDM_GEOGRAPHY + "Collection";
-var EDM_GEOGRAPHY_MULTIPOLYGON = EDM_GEOGRAPHY + "MultiPolygon";
-var EDM_GEOGRAPHY_MULTILINESTRING = EDM_GEOGRAPHY + "MultiLineString";
-var EDM_GEOGRAPHY_MULTIPOINT = EDM_GEOGRAPHY + "MultiPoint";
-
-var GEOGRAPHY_POINT = GEOGRAPHY + "Point";
-var GEOGRAPHY_LINESTRING = GEOGRAPHY + "LineString";
-var GEOGRAPHY_POLYGON = GEOGRAPHY + "Polygon";
-var GEOGRAPHY_COLLECTION = GEOGRAPHY + "Collection";
-var GEOGRAPHY_MULTIPOLYGON = GEOGRAPHY + "MultiPolygon";
-var GEOGRAPHY_MULTILINESTRING = GEOGRAPHY + "MultiLineString";
-var GEOGRAPHY_MULTIPOINT = GEOGRAPHY + "MultiPoint";
-
-var GEOMETRY = "Geometry";
-var EDM_GEOMETRY = EDM + GEOMETRY;
-var EDM_GEOMETRY_POINT = EDM_GEOMETRY + "Point";
-var EDM_GEOMETRY_LINESTRING = EDM_GEOMETRY + "LineString";
-var EDM_GEOMETRY_POLYGON = EDM_GEOMETRY + "Polygon";
-var EDM_GEOMETRY_COLLECTION = EDM_GEOMETRY + "Collection";
-var EDM_GEOMETRY_MULTIPOLYGON = EDM_GEOMETRY + "MultiPolygon";
-var EDM_GEOMETRY_MULTILINESTRING = EDM_GEOMETRY + "MultiLineString";
-var EDM_GEOMETRY_MULTIPOINT = EDM_GEOMETRY + "MultiPoint";
-
-var GEOMETRY_POINT = GEOMETRY + "Point";
-var GEOMETRY_LINESTRING = GEOMETRY + "LineString";
-var GEOMETRY_POLYGON = GEOMETRY + "Polygon";
-var GEOMETRY_COLLECTION = GEOMETRY + "Collection";
-var GEOMETRY_MULTIPOLYGON = GEOMETRY + "MultiPolygon";
-var GEOMETRY_MULTILINESTRING = GEOMETRY + "MultiLineString";
-var GEOMETRY_MULTIPOINT = GEOMETRY + "MultiPoint";
-
-var GEOJSON_POINT = "Point";
-var GEOJSON_LINESTRING = "LineString";
-var GEOJSON_POLYGON = "Polygon";
-var GEOJSON_MULTIPOINT = "MultiPoint";
-var GEOJSON_MULTILINESTRING = "MultiLineString";
-var GEOJSON_MULTIPOLYGON = "MultiPolygon";
-var GEOJSON_GEOMETRYCOLLECTION = "GeometryCollection";
-
-var primitiveEdmTypes = [
- EDM_STRING,
- EDM_INT32,
- EDM_INT64,
- EDM_BOOLEAN,
- EDM_DOUBLE,
- EDM_SINGLE,
- EDM_DATE,
- EDM_DATETIMEOFFSET,
- EDM_DURATION,
- EDM_TIMEOFDAY,
- EDM_DECIMAL,
- EDM_GUID,
- EDM_BYTE,
- EDM_INT16,
- EDM_SBYTE,
- EDM_BINARY
-];
-
-var geometryEdmTypes = [
- EDM_GEOMETRY,
- EDM_GEOMETRY_POINT,
- EDM_GEOMETRY_LINESTRING,
- EDM_GEOMETRY_POLYGON,
- EDM_GEOMETRY_COLLECTION,
- EDM_GEOMETRY_MULTIPOLYGON,
- EDM_GEOMETRY_MULTILINESTRING,
- EDM_GEOMETRY_MULTIPOINT
-];
-
-var geometryTypes = [
- GEOMETRY,
- GEOMETRY_POINT,
- GEOMETRY_LINESTRING,
- GEOMETRY_POLYGON,
- GEOMETRY_COLLECTION,
- GEOMETRY_MULTIPOLYGON,
- GEOMETRY_MULTILINESTRING,
- GEOMETRY_MULTIPOINT
-];
-
-var geographyEdmTypes = [
- EDM_GEOGRAPHY,
- EDM_GEOGRAPHY_POINT,
- EDM_GEOGRAPHY_LINESTRING,
- EDM_GEOGRAPHY_POLYGON,
- EDM_GEOGRAPHY_COLLECTION,
- EDM_GEOGRAPHY_MULTIPOLYGON,
- EDM_GEOGRAPHY_MULTILINESTRING,
- EDM_GEOGRAPHY_MULTIPOINT
-];
-
-var geographyTypes = [
- GEOGRAPHY,
- GEOGRAPHY_POINT,
- GEOGRAPHY_LINESTRING,
- GEOGRAPHY_POLYGON,
- GEOGRAPHY_COLLECTION,
- GEOGRAPHY_MULTIPOLYGON,
- GEOGRAPHY_MULTILINESTRING,
- GEOGRAPHY_MULTIPOINT
-];
-
-/** Invokes a function once per schema in metadata.
- * @param metadata - Metadata store; one of edmx, schema, or an array of any of them.
- * @param {Function} callback - Callback function to invoke once per schema.
- * @returns The first truthy value to be returned from the callback; null or the last falsy value otherwise.
- */
-function forEachSchema(metadata, callback) {
-
-
- if (!metadata) {
- return null;
- }
-
- if (isArray(metadata)) {
- var i, len, result;
- for (i = 0, len = metadata.length; i < len; i++) {
- result = forEachSchema(metadata[i], callback);
- if (result) {
- return result;
- }
- }
-
- return null;
- } else {
- if (metadata.dataServices) {
- return forEachSchema(metadata.dataServices.schema, callback);
- }
-
- return callback(metadata);
- }
-}
-
-/** Formats a millisecond and a nanosecond value into a single string.
- * @param {Numaber} ms - Number of milliseconds to format.</param>
- * @param {Numaber} ns - Number of nanoseconds to format.</param>
- * @returns {String} Formatted text.
- * If the value is already as string it's returned as-is.</remarks>
- */
-function formatMilliseconds(ms, ns) {
-
- // Avoid generating milliseconds if not necessary.
- if (ms === 0) {
- ms = "";
- } else {
- ms = "." + formatNumberWidth(ms.toString(), 3);
- }
- if (ns > 0) {
- if (ms === "") {
- ms = ".000";
- }
- ms += formatNumberWidth(ns.toString(), 4);
- }
- return ms;
-}
-
-function formatDateTimeOffsetJSON(value) {
- return "\/Date(" + value.getTime() + ")\/";
-}
-
-/** Formats a DateTime or DateTimeOffset value a string.
- * @param {Date} value - Value to format
- * @returns {String} Formatted text.
- * If the value is already as string it's returned as-is
-´*/
-function formatDateTimeOffset(value) {
-
- if (typeof value === "string") {
- return value;
- }
-
- var hasOffset = isDateTimeOffset(value);
- var offset = getCanonicalTimezone(value.__offset);
- if (hasOffset && offset !== "Z") {
- // We're about to change the value, so make a copy.
- value = new Date(value.valueOf());
-
- var timezone = parseTimezone(offset);
- var hours = value.getUTCHours() + (timezone.d * timezone.h);
- var minutes = value.getUTCMinutes() + (timezone.d * timezone.m);
-
- value.setUTCHours(hours, minutes);
- } else if (!hasOffset) {
- // Don't suffix a 'Z' for Edm.DateTime values.
- offset = "";
- }
-
- var year = value.getUTCFullYear();
- var month = value.getUTCMonth() + 1;
- var sign = "";
- if (year <= 0) {
- year = -(year - 1);
- sign = "-";
- }
-
- var ms = formatMilliseconds(value.getUTCMilliseconds(), value.__ns);
-
- return sign +
- formatNumberWidth(year, 4) + "-" +
- formatNumberWidth(month, 2) + "-" +
- formatNumberWidth(value.getUTCDate(), 2) + "T" +
- formatNumberWidth(value.getUTCHours(), 2) + ":" +
- formatNumberWidth(value.getUTCMinutes(), 2) + ":" +
- formatNumberWidth(value.getUTCSeconds(), 2) +
- ms + offset;
-}
-
-/** Converts a duration to a string in xsd:duration format.
- * @param {Object} value - Object with ms and __edmType properties.
- * @returns {String} String representation of the time object in xsd:duration format.
- */
-function formatDuration(value) {
-
- var ms = value.ms;
-
- var sign = "";
- if (ms < 0) {
- sign = "-";
- ms = -ms;
- }
-
- var days = Math.floor(ms / 86400000);
- ms -= 86400000 * days;
- var hours = Math.floor(ms / 3600000);
- ms -= 3600000 * hours;
- var minutes = Math.floor(ms / 60000);
- ms -= 60000 * minutes;
- var seconds = Math.floor(ms / 1000);
- ms -= seconds * 1000;
-
- return sign + "P" +
- formatNumberWidth(days, 2) + "DT" +
- formatNumberWidth(hours, 2) + "H" +
- formatNumberWidth(minutes, 2) + "M" +
- formatNumberWidth(seconds, 2) +
- formatMilliseconds(ms, value.ns) + "S";
-}
-
-/** Formats the specified value to the given width.
- * @param {Number} value - Number to format (non-negative).
- * @param {Number} width - Minimum width for number.
- * @param {Boolean} append - Flag indicating if the value is padded at the beginning (false) or at the end (true).
- * @returns {String} Text representation.
- */
-function formatNumberWidth(value, width, append) {
- var result = value.toString(10);
- while (result.length < width) {
- if (append) {
- result += "0";
- } else {
- result = "0" + result;
- }
- }
-
- return result;
-}
-
-/** Gets the canonical timezone representation.
- * @param {String} timezone - Timezone representation.
- * @returns {String} An 'Z' string if the timezone is absent or 0; the timezone otherwise.
- */
-function getCanonicalTimezone(timezone) {
-
- return (!timezone || timezone === "Z" || timezone === "+00:00" || timezone === "-00:00") ? "Z" : timezone;
-}
-
-/** Gets the type of a collection type name.
- * @param {String} typeName - Type name of the collection.
- * @returns {String} Type of the collection; null if the type name is not a collection type.
- */
-function getCollectionType(typeName) {
-
- if (typeof typeName === "string") {
- var end = typeName.indexOf(")", 10);
- if (typeName.indexOf("Collection(") === 0 && end > 0) {
- return typeName.substring(11, end);
- }
- }
- return null;
-}
-
-/** Sends a request containing OData payload to a server.
-* @param request - Object that represents the request to be sent..
-* @param success - Callback for a successful read operation.
-* @param error - Callback for handling errors.
-* @param handler - Handler for data serialization.
-* @param httpClient - HTTP client layer.
-* @param context - Context used for processing the request
-*/
-function invokeRequest(request, success, error, handler, httpClient, context) {
-
- return httpClient.request(request, function (response) {
- try {
- if (response.headers) {
- normalizeHeaders(response.headers);
- }
-
- if (response.data === undefined && response.statusCode !== 204) {
- handler.read(response, context);
- }
- } catch (err) {
- if (err.request === undefined) {
- err.request = request;
- }
- if (err.response === undefined) {
- err.response = response;
- }
- error(err);
- return;
- }
- // errors in success handler for sync requests result in error handler calls. So here we fix this.
- try {
- success(response.data, response);
- } catch (err) {
- err.bIsSuccessHandlerError = true;
- throw err;
- }
- }, error);
-}
-
-/** Tests whether a value is a batch object in the library's internal representation.
- * @param value - Value to test.
- * @returns {Boolean} True is the value is a batch object; false otherwise.
- */
-function isBatch(value) {
-
- return isComplex(value) && isArray(value.__batchRequests);
-}
-
-// Regular expression used for testing and parsing for a collection type.
-var collectionTypeRE = /Collection\((.*)\)/;
-
-/** Tests whether a value is a collection value in the library's internal representation.
- * @param value - Value to test.
- * @param {Sting} typeName - Type name of the value. This is used to disambiguate from a collection property value.
- * @returns {Boolean} True is the value is a feed value; false otherwise.
- */
-function isCollection(value, typeName) {
-
- var colData = value && value.results || value;
- return !!colData &&
- (isCollectionType(typeName)) ||
- (!typeName && isArray(colData) && !isComplex(colData[0]));
-}
-
-/** Checks whether the specified type name is a collection type.
- * @param {String} typeName - Name of type to check.
- * @returns {Boolean} True if the type is the name of a collection type; false otherwise.
- */
-function isCollectionType(typeName) {
- return collectionTypeRE.test(typeName);
-}
-
-/** Tests whether a value is a complex type value in the library's internal representation.
- * @param value - Value to test.
- * @returns {Boolean} True is the value is a complex type value; false otherwise.
- */
-function isComplex(value) {
-
- return !!value &&
- isObject(value) &&
- !isArray(value) &&
- !isDate(value);
-}
-
-/** Checks whether a Date object is DateTimeOffset value
- * @param {Date} value - Value to check
- * @returns {Boolean} true if the value is a DateTimeOffset, false otherwise.
- */
-function isDateTimeOffset(value) {
- return (value.__edmType === "Edm.DateTimeOffset" || (!value.__edmType && value.__offset));
-}
-
-/** Tests whether a value is a deferred navigation property in the library's internal representation.
- * @param value - Value to test.
- * @returns {Boolean} True is the value is a deferred navigation property; false otherwise.
- */
-function isDeferred(value) {
-
- if (!value && !isComplex(value)) {
- return false;
- }
- var metadata = value.__metadata || {};
- var deferred = value.__deferred || {};
- return !metadata.type && !!deferred.uri;
-}
-
-/** Tests whether a value is an entry object in the library's internal representation.
- * @param value - Value to test.
- * @returns {Boolean} True is the value is an entry object; false otherwise.
- */
-function isEntry(value) {
-
- return isComplex(value) && value.__metadata && "uri" in value.__metadata;
-}
-
-/** Tests whether a value is a feed value in the library's internal representation.
- * @param value - Value to test.
- * @param {Sting} typeName - Type name of the value. This is used to disambiguate from a collection property value.
- * @returns {Boolean} True is the value is a feed value; false otherwise.
- */
-function isFeed(value, typeName) {
-
- var feedData = value && value.results || value;
- return isArray(feedData) && (
- (!isCollectionType(typeName)) &&
- (isComplex(feedData[0]))
- );
-}
-
-/** Checks whether the specified type name is a geography EDM type.
- * @param {String} typeName - Name of type to check.
- * @returns {Boolean} True if the type is a geography EDM type; false otherwise.
- */
-function isGeographyEdmType(typeName) {
-
- //check with edm
- var ret = contains(geographyEdmTypes, typeName) ||
- (typeName.indexOf('.') === -1 && contains(geographyTypes, typeName));
- return ret;
-
-}
-
-/** Checks whether the specified type name is a geometry EDM type.
- * @param {String} typeName - Name of type to check.
- * @returns {Boolean} True if the type is a geometry EDM type; false otherwise.
- */
-function isGeometryEdmType(typeName) {
-
- var ret = contains(geometryEdmTypes, typeName) ||
- (typeName.indexOf('.') === -1 && contains(geometryTypes, typeName));
- return ret;
-}
-
-/** Tests whether a value is a named stream value in the library's internal representation.
- * @param value - Value to test.
- * @returns {Boolean} True is the value is a named stream; false otherwise.
- */
-function isNamedStream(value) {
-
- if (!value && !isComplex(value)) {
- return false;
- }
- var metadata = value.__metadata;
- var mediaResource = value.__mediaresource;
- return !metadata && !!mediaResource && !!mediaResource.media_src;
-}
-
-/** Tests whether a value is a primitive type value in the library's internal representation.
- * @param value - Value to test.
- * @returns {Boolean} True is the value is a primitive type value.
- * Date objects are considered primitive types by the library.
- */
-function isPrimitive(value) {
-
- return isDate(value) ||
- typeof value === "string" ||
- typeof value === "number" ||
- typeof value === "boolean";
-}
-
-/** Checks whether the specified type name is a primitive EDM type.
- * @param {String} typeName - Name of type to check.
- * @returns {Boolean} True if the type is a primitive EDM type; false otherwise.
- */
-function isPrimitiveEdmType(typeName) {
-
- return contains(primitiveEdmTypes, typeName);
-}
-
-/** Gets the kind of a navigation property value.
- * @param value - Value of the navigation property.
- * @param {Object} [propertyModel] - Object that describes the navigation property in an OData conceptual schema.
- * @returns {String} String value describing the kind of the navigation property; null if the kind cannot be determined.
- */
-function navigationPropertyKind(value, propertyModel) {
-
- if (isDeferred(value)) {
- return "deferred";
- }
- if (isEntry(value)) {
- return "entry";
- }
- if (isFeed(value)) {
- return "feed";
- }
- if (propertyModel && propertyModel.relationship) {
- if (value === null || value === undefined || !isFeed(value)) {
- return "entry";
- }
- return "feed";
- }
- return null;
-}
-
-/** Looks up a property by name.
- * @param {Array} properties - Array of property objects as per EDM metadata (may be null)
- * @param {String} name - Name to look for.
- * @returns {Object} The property object; null if not found.
- */
-function lookupProperty(properties, name) {
-
- return find(properties, function (property) {
- return property.name === name;
- });
-}
-
-/** Looks up a type object by name.
- * @param {String} name - Name, possibly null or empty.
- * @param metadata - Metadata store; one of edmx, schema, or an array of any of them.
- * @param {String} kind - Kind of object to look for as per EDM metadata.
- * @returns An type description if the name is found; null otherwise
- */
-function lookupInMetadata(name, metadata, kind) {
-
- return (name) ? forEachSchema(metadata, function (schema) {
- return lookupInSchema(name, schema, kind);
- }) : null;
-}
-
-/** Looks up a entity set by name.
- * @param {Array} properties - Array of entity set objects as per EDM metadata( may be null)
- * @param {String} name - Name to look for.
- * @returns {Object} The entity set object; null if not found.
- */
-function lookupEntitySet(entitySets, name) {
-
- return find(entitySets, function (entitySet) {
- return entitySet.name === name;
- });
-}
-
-/** Looks up a entity set by name.
- * @param {Array} properties - Array of entity set objects as per EDM metadata (may be null)
- * @param {String} name - Name to look for.
- * @returns {Object} The entity set object; null if not found.
- */
-function lookupSingleton(singletons, name) {
-
- return find(singletons, function (singleton) {
- return singleton.name === name;
- });
-}
-
-/** Looks up a complex type object by name.
- * @param {String} name - Name, possibly null or empty.
- * @param metadata - Metadata store; one of edmx, schema, or an array of any of them.
- * @returns A complex type description if the name is found; null otherwise.</returns>
- */
-function lookupComplexType(name, metadata) {
-
- return lookupInMetadata(name, metadata, "complexType");
-}
-
-/** Looks up an entity type object by name.
- * @param {String} name - Name, possibly null or empty.
- * @param metadata - Metadata store; one of edmx, schema, or an array of any of them.
- * @returns An entity type description if the name is found; null otherwise.</returns>
- */
-function lookupEntityType(name, metadata) {
-
- return lookupInMetadata(name, metadata, "entityType");
-}
-
-
-/** Looks up an
- * @param {String} name - Name, possibly null or empty.
- * @param metadata - Metadata store; one of edmx, schema, or an array of any of them.
- * @returns An entity container description if the name is found; null otherwise.</returns>
- */
-function lookupDefaultEntityContainer(metadata) {
-
- return forEachSchema(metadata, function (schema) {
- if (isObject(schema.entityContainer)) {
- return schema.entityContainer;
- }
- });
-}
-
-/** Looks up an entity container object by name.
- * @param {String} name - Name, possibly null or empty.
- * @param metadata - Metadata store; one of edmx, schema, or an array of any of them.
- * @returns An entity container description if the name is found; null otherwise.</returns>
- */
-function lookupEntityContainer(name, metadata) {
-
- return lookupInMetadata(name, metadata, "entityContainer");
-}
-
-/** Looks up a function import by name.
- * @param {Array} properties - Array of function import objects as per EDM metadata (May be null)
- * @param {String} name - Name to look for.
- * @returns {Object} The entity set object; null if not found.
- */
-function lookupFunctionImport(functionImports, name) {
- return find(functionImports, function (functionImport) {
- return functionImport.name === name;
- });
-}
-
-/** Looks up the target entity type for a navigation property.
- * @param {Object} navigationProperty -
- * @param {Object} metadata -
- * @returns {String} The entity type name for the specified property, null if not found.
- */
-function lookupNavigationPropertyType(navigationProperty, metadata) {
-
- var result = null;
- if (navigationProperty) {
- var rel = navigationProperty.relationship;
- var association = forEachSchema(metadata, function (schema) {
- // The name should be the namespace qualified name in 'ns'.'type' format.
- var nameOnly = removeNamespace(schema.namespace, rel);
- var associations = schema.association;
- if (nameOnly && associations) {
- var i, len;
- for (i = 0, len = associations.length; i < len; i++) {
- if (associations[i].name === nameOnly) {
- return associations[i];
- }
- }
- }
- return null;
- });
-
- if (association) {
- var end = association.end[0];
- if (end.role !== navigationProperty.toRole) {
- end = association.end[1];
- // For metadata to be valid, end.role === navigationProperty.toRole now.
- }
- result = end.type;
- }
- }
- return result;
-}
-
-/** Looks up the target entityset name for a navigation property.
- * @param {Object} navigationProperty -
- * @param {Object} metadata -
- * @returns {String} The entityset name for the specified property, null if not found.
- */
-function lookupNavigationPropertyEntitySet(navigationProperty, sourceEntitySetName, metadata) {
-
- if (navigationProperty) {
- var rel = navigationProperty.relationship;
- var associationSet = forEachSchema(metadata, function (schema) {
- var containers = schema.entityContainer;
- for (var i = 0; i < containers.length; i++) {
- var associationSets = containers[i].associationSet;
- if (associationSets) {
- for (var j = 0; j < associationSets.length; j++) {
- if (associationSets[j].association == rel) {
- return associationSets[j];
- }
- }
- }
- }
- return null;
- });
- if (associationSet && associationSet.end[0] && associationSet.end[1]) {
- return (associationSet.end[0].entitySet == sourceEntitySetName) ? associationSet.end[1].entitySet : associationSet.end[0].entitySet;
- }
- }
- return null;
-}
-
-/** Gets the entitySet info, container name and functionImports for an entitySet
- * @param {Object} navigationProperty -
- * @param {Object} metadata -
- * @returns {Object} The info about the entitySet.
- */
-function getEntitySetInfo(entitySetName, metadata) {
-
- var info = forEachSchema(metadata, function (schema) {
- var container = schema.entityContainer;
- var entitySets = container.entitySet;
- if (entitySets) {
- for (var j = 0; j < entitySets.length; j++) {
- if (entitySets[j].name == entitySetName) {
- return { entitySet: entitySets[j], containerName: container.name, functionImport: container.functionImport };
- }
- }
- }
- return null;
- });
-
- return info;
-}
-
-/** Given an expected namespace prefix, removes it from a full name.
- * @param {String} ns - Expected namespace.
- * @param {String} fullName - Full name in 'ns'.'name' form.
- * @returns {String} The local name, null if it isn't found in the expected namespace.
- */
-function removeNamespace(ns, fullName) {
-
- if (fullName.indexOf(ns) === 0 && fullName.charAt(ns.length) === ".") {
- return fullName.substr(ns.length + 1);
- }
-
- return null;
-}
-
-/** Looks up a schema object by name.
- * @param {String} name - Name (assigned).
- * @param schema - Schema object as per EDM metadata.
- * @param {String} kind - Kind of object to look for as per EDM metadata.
- * @returns An entity type description if the name is found; null otherwise.</returns>
- */
-function lookupInSchema(name, schema, kind) {
-
- if (name && schema) {
- // The name should be the namespace qualified name in 'ns'.'type' format.
- var nameOnly = removeNamespace(schema.namespace, name);
- if (nameOnly) {
- return find(schema[kind], function (item) {
- return item.name === nameOnly;
- });
- }
- }
- return null;
-}
-
-/** Compares to version strings and returns the higher one.
- * @param {String} left - Version string in the form "major.minor.rev"
- * @param {String} right - Version string in the form "major.minor.rev"
- * @returns {String} The higher version string.
- */
-function maxVersion(left, right) {
-
- if (left === right) {
- return left;
- }
-
- var leftParts = left.split(".");
- var rightParts = right.split(".");
-
- var len = (leftParts.length >= rightParts.length) ?
- leftParts.length :
- rightParts.length;
-
- for (var i = 0; i < len; i++) {
- var leftVersion = leftParts[i] && parseInt10(leftParts[i]);
- var rightVersion = rightParts[i] && parseInt10(rightParts[i]);
- if (leftVersion > rightVersion) {
- return left;
- }
- if (leftVersion < rightVersion) {
- return right;
- }
- }
-}
-
-var normalHeaders = {
- // Headers shared by request and response
- "content-type": "Content-Type",
- "content-encoding": "Content-Encoding",
- "content-length": "Content-Length",
- "odata-version": "OData-Version",
-
- // Headers used by request
- "accept": "Accept",
- "accept-charset": "Accept-Charset",
- "if-match": "If-Match",
- "if-none-match": "If-None-Match",
- "odata-isolation": "OData-Isolation",
- "odata-maxversion": "OData-MaxVersion",
- "prefer": "Prefer",
- "content-id": "Content-ID",
- "content-transfer-encoding": "Content-Transfer-Encoding",
-
- // Headers used by response
- "etag": "ETag",
- "location": "Location",
- "odata-entityid": "OData-EntityId",
- "preference-applied": "Preference-Applied",
- "retry-after": "Retry-After"
-};
-
-/** Normalizes headers so they can be found with consistent casing.
- * @param {Object} headers - Dictionary of name/value pairs.
- */
-function normalizeHeaders(headers) {
-
- for (var name in headers) {
- var lowerName = name.toLowerCase();
- var normalName = normalHeaders[lowerName];
- if (normalName && name !== normalName) {
- var val = headers[name];
- delete headers[name];
- headers[normalName] = val;
- }
- }
-}
-
-/** Parses a string into a boolean value.
- * @param propertyValue - Value to parse.
- * @returns {Boolean} true if the property value is 'true'; false otherwise.
- */
-function parseBool(propertyValue) {
-
- if (typeof propertyValue === "boolean") {
- return propertyValue;
- }
-
- return typeof propertyValue === "string" && propertyValue.toLowerCase() === "true";
-}
-
-
-// The captured indices for this expression are:
-// 0 - complete input
-// 1,2,3 - year with optional minus sign, month, day
-// 4,5,6 - hours, minutes, seconds
-// 7 - optional milliseconds
-// 8 - everything else (presumably offset information)
-var parseDateTimeRE = /^(-?\d{4,})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2}))?(?:\.(\d+))?(.*)$/;
-
-/** Parses a string into a DateTime value.
- * @param {String} value - Value to parse.
- * @param {Boolean} withOffset - Whether offset is expected.
- * @returns {Date} The parsed value.
- */
-function parseDateTimeMaybeOffset(value, withOffset, nullOnError) {
-
- // We cannot parse this in cases of failure to match or if offset information is specified.
- var parts = parseDateTimeRE.exec(value);
- var offset = (parts) ? getCanonicalTimezone(parts[8]) : null;
-
- if (!parts || (!withOffset && offset !== "Z")) {
- if (nullOnError) {
- return null;
- }
- throw { message: "Invalid date/time value" };
- }
-
- // Pre-parse years, account for year '0' being invalid in dateTime.
- var year = parseInt10(parts[1]);
- if (year <= 0) {
- year++;
- }
-
- // Pre-parse optional milliseconds, fill in default. Fail if value is too precise.
- var ms = parts[7];
- var ns = 0;
- if (!ms) {
- ms = 0;
- } else {
- if (ms.length > 7) {
- if (nullOnError) {
- return null;
- }
- throw { message: "Cannot parse date/time value to given precision." };
- }
-
- ns = formatNumberWidth(ms.substring(3), 4, true);
- ms = formatNumberWidth(ms.substring(0, 3), 3, true);
-
- ms = parseInt10(ms);
- ns = parseInt10(ns);
- }
-
- // Pre-parse other time components and offset them if necessary.
- var hours = parseInt10(parts[4]);
- var minutes = parseInt10(parts[5]);
- var seconds = parseInt10(parts[6]) || 0;
- if (offset !== "Z") {
- // The offset is reversed to get back the UTC date, which is
- // what the API will eventually have.
- var timezone = parseTimezone(offset);
- var direction = -(timezone.d);
- hours += timezone.h * direction;
- minutes += timezone.m * direction;
- }
-
- // Set the date and time separately with setFullYear, so years 0-99 aren't biased like in Date.UTC.
- var result = new Date();
- result.setUTCFullYear(
- year, // Year.
- parseInt10(parts[2]) - 1, // Month (zero-based for Date.UTC and setFullYear).
- parseInt10(parts[3]) // Date.
- );
- result.setUTCHours(hours, minutes, seconds, ms);
-
- if (isNaN(result.valueOf())) {
- if (nullOnError) {
- return null;
- }
- throw { message: "Invalid date/time value" };
- }
-
- if (withOffset) {
- result.__edmType = "Edm.DateTimeOffset";
- result.__offset = offset;
- }
-
- if (ns) {
- result.__ns = ns;
- }
-
- return result;
-}
-
-/** Parses a string into a Date object.
- * @param {String} propertyValue - Value to parse.
- * @returns {Date} The parsed with year, month, day set, time values are set to 0
- */
-function parseDate(propertyValue, nullOnError) {
- var parts = propertyValue.split('-');
-
- if (parts.length != 3 && nullOnError) {
- return null;
- }
- return new Date(
- parseInt10(parts[0]), // Year.
- parseInt10(parts[1]) - 1, // Month (zero-based for Date.UTC and setFullYear).
- parseInt10(parts[2],
- 0,0,0,0) // Date.
- );
-
-}
-
-var parseTimeOfDayRE = /^(\d+):(\d+)(:(\d+)(.(\d+))?)?$/;
-
-function parseTimeOfDay(propertyValue, nullOnError) {
- var parts = parseTimeOfDayRE.exec(propertyValue);
-
-
- return {
- 'h' :parseInt10(parts[1]),
- 'm' :parseInt10(parts[2]),
- 's' :parseInt10(parts[4]),
- 'ms' :parseInt10(parts[6]),
- };
-}
-
-/** Parses a string into a DateTimeOffset value.
- * @param {String} propertyValue - Value to parse.
- * @returns {Date} The parsed value.
-
-
- * The resulting object is annotated with an __edmType property and
- * an __offset property reflecting the original intended offset of
- * the value. The time is adjusted for UTC time, as the current
- * timezone-aware Date APIs will only work with the local timezone.
- */
-function parseDateTimeOffset(propertyValue, nullOnError) {
-
-
- return parseDateTimeMaybeOffset(propertyValue, true, nullOnError);
-}
-
-// The captured indices for this expression are:
-// 0 - complete input
-// 1 - direction
-// 2,3,4 - years, months, days
-// 5,6,7,8 - hours, minutes, seconds, miliseconds
-
-var parseTimeRE = /^([+-])?P(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)(?:\.(\d+))?S)?)?/;
-
-function isEdmDurationValue(value) {
- parseTimeRE.test(value);
-}
-
-/** Parses a string in xsd:duration format.
- * @param {String} duration - Duration value.
-
- * This method will throw an exception if the input string has a year or a month component.
-
- * @returns {Object} Object representing the time
- */
-function parseDuration(duration) {
-
- var parts = parseTimeRE.exec(duration);
-
- if (parts === null) {
- throw { message: "Invalid duration value." };
- }
-
- var years = parts[2] || "0";
- var months = parts[3] || "0";
- var days = parseInt10(parts[4] || 0);
- var hours = parseInt10(parts[5] || 0);
- var minutes = parseInt10(parts[6] || 0);
- var seconds = parseFloat(parts[7] || 0);
-
- if (years !== "0" || months !== "0") {
- throw { message: "Unsupported duration value." };
- }
-
- var ms = parts[8];
- var ns = 0;
- if (!ms) {
- ms = 0;
- } else {
- if (ms.length > 7) {
- throw { message: "Cannot parse duration value to given precision." };
- }
-
- ns = formatNumberWidth(ms.substring(3), 4, true);
- ms = formatNumberWidth(ms.substring(0, 3), 3, true);
-
- ms = parseInt10(ms);
- ns = parseInt10(ns);
- }
-
- ms += seconds * 1000 + minutes * 60000 + hours * 3600000 + days * 86400000;
-
- if (parts[1] === "-") {
- ms = -ms;
- }
-
- var result = { ms: ms, __edmType: "Edm.Time" };
-
- if (ns) {
- result.ns = ns;
- }
- return result;
-}
-
-/** Parses a timezone description in (+|-)nn:nn format.
- * @param {String} timezone - Timezone offset.
- * @returns {Object} An object with a (d)irection property of 1 for + and -1 for -, offset (h)ours and offset (m)inutes.
- */
-function parseTimezone(timezone) {
-
- var direction = timezone.substring(0, 1);
- direction = (direction === "+") ? 1 : -1;
-
- var offsetHours = parseInt10(timezone.substring(1));
- var offsetMinutes = parseInt10(timezone.substring(timezone.indexOf(":") + 1));
- return { d: direction, h: offsetHours, m: offsetMinutes };
-}
-
-/** Prepares a request object so that it can be sent through the network.
-* @param request - Object that represents the request to be sent.
-* @param handler - Handler for data serialization
-* @param context - Context used for preparing the request
-*/
-function prepareRequest(request, handler, context) {
-
- // Default to GET if no method has been specified.
- if (!request.method) {
- request.method = "GET";
- }
-
- if (!request.headers) {
- request.headers = {};
- } else {
- normalizeHeaders(request.headers);
- }
-
- if (request.headers.Accept === undefined) {
- request.headers.Accept = handler.accept;
- }
-
- if (assigned(request.data) && request.body === undefined) {
- handler.write(request, context);
- }
-
- if (!assigned(request.headers["OData-MaxVersion"])) {
- request.headers["OData-MaxVersion"] = handler.maxDataServiceVersion || "4.0";
- }
-
- if (request.async === undefined) {
- request.async = true;
- }
-
-}
-
-/** Traverses a tree of objects invoking callback for every value.
- * @param {Object} item - Object or array to traverse.
- * @param {Function} callback - Callback function with key and value, similar to JSON.parse reviver.
- * @returns {Object} The object with traversed properties.
- Unlike the JSON reviver, this won't delete null members.</remarks>
-*/
-function traverseInternal(item, owner, callback) {
-
- if (item && typeof item === "object") {
- for (var name in item) {
- var value = item[name];
- var result = traverseInternal(value, name, callback);
- result = callback(name, result, owner);
- if (result !== value) {
- if (value === undefined) {
- delete item[name];
- } else {
- item[name] = result;
- }
- }
- }
- }
-
- return item;
-}
-
-/** Traverses a tree of objects invoking callback for every value.
- * @param {Object} item - Object or array to traverse.
- * @param {Function} callback - Callback function with key and value, similar to JSON.parse reviver.
- * @returns {Object} The traversed object.
- * Unlike the JSON reviver, this won't delete null members.</remarks>
-*/
-function traverse(item, callback) {
-
- return callback("", traverseInternal(item, "", callback));
-}
-
-exports.dataItemTypeName = dataItemTypeName;
-exports.EDM_BINARY = EDM_BINARY;
-exports.EDM_BOOLEAN = EDM_BOOLEAN;
-exports.EDM_BYTE = EDM_BYTE;
-exports.EDM_DATE = EDM_DATE;
-exports.EDM_DATETIMEOFFSET = EDM_DATETIMEOFFSET;
-exports.EDM_DURATION = EDM_DURATION;
-exports.EDM_DECIMAL = EDM_DECIMAL;
-exports.EDM_DOUBLE = EDM_DOUBLE;
-exports.EDM_GEOGRAPHY = EDM_GEOGRAPHY;
-exports.EDM_GEOGRAPHY_POINT = EDM_GEOGRAPHY_POINT;
-exports.EDM_GEOGRAPHY_LINESTRING = EDM_GEOGRAPHY_LINESTRING;
-exports.EDM_GEOGRAPHY_POLYGON = EDM_GEOGRAPHY_POLYGON;
-exports.EDM_GEOGRAPHY_COLLECTION = EDM_GEOGRAPHY_COLLECTION;
-exports.EDM_GEOGRAPHY_MULTIPOLYGON = EDM_GEOGRAPHY_MULTIPOLYGON;
-exports.EDM_GEOGRAPHY_MULTILINESTRING = EDM_GEOGRAPHY_MULTILINESTRING;
-exports.EDM_GEOGRAPHY_MULTIPOINT = EDM_GEOGRAPHY_MULTIPOINT;
-exports.EDM_GEOMETRY = EDM_GEOMETRY;
-exports.EDM_GEOMETRY_POINT = EDM_GEOMETRY_POINT;
-exports.EDM_GEOMETRY_LINESTRING = EDM_GEOMETRY_LINESTRING;
-exports.EDM_GEOMETRY_POLYGON = EDM_GEOMETRY_POLYGON;
-exports.EDM_GEOMETRY_COLLECTION = EDM_GEOMETRY_COLLECTION;
-exports.EDM_GEOMETRY_MULTIPOLYGON = EDM_GEOMETRY_MULTIPOLYGON;
-exports.EDM_GEOMETRY_MULTILINESTRING = EDM_GEOMETRY_MULTILINESTRING;
-exports.EDM_GEOMETRY_MULTIPOINT = EDM_GEOMETRY_MULTIPOINT;
-exports.EDM_GUID = EDM_GUID;
-exports.EDM_INT16 = EDM_INT16;
-exports.EDM_INT32 = EDM_INT32;
-exports.EDM_INT64 = EDM_INT64;
-exports.EDM_SBYTE = EDM_SBYTE;
-exports.EDM_SINGLE = EDM_SINGLE;
-exports.EDM_STRING = EDM_STRING;
-exports.EDM_TIMEOFDAY = EDM_TIMEOFDAY;
-exports.GEOJSON_POINT = GEOJSON_POINT;
-exports.GEOJSON_LINESTRING = GEOJSON_LINESTRING;
-exports.GEOJSON_POLYGON = GEOJSON_POLYGON;
-exports.GEOJSON_MULTIPOINT = GEOJSON_MULTIPOINT;
-exports.GEOJSON_MULTILINESTRING = GEOJSON_MULTILINESTRING;
-exports.GEOJSON_MULTIPOLYGON = GEOJSON_MULTIPOLYGON;
-exports.GEOJSON_GEOMETRYCOLLECTION = GEOJSON_GEOMETRYCOLLECTION;
-exports.forEachSchema = forEachSchema;
-exports.formatDateTimeOffset = formatDateTimeOffset;
-exports.formatDateTimeOffsetJSON = formatDateTimeOffsetJSON;
-exports.formatDuration = formatDuration;
-exports.formatNumberWidth = formatNumberWidth;
-exports.getCanonicalTimezone = getCanonicalTimezone;
-exports.getCollectionType = getCollectionType;
-exports.invokeRequest = invokeRequest;
-exports.isBatch = isBatch;
-exports.isCollection = isCollection;
-exports.isCollectionType = isCollectionType;
-exports.isComplex = isComplex;
-exports.isDateTimeOffset = isDateTimeOffset;
-exports.isDeferred = isDeferred;
-exports.isEntry = isEntry;
-exports.isFeed = isFeed;
-exports.isGeographyEdmType = isGeographyEdmType;
-exports.isGeometryEdmType = isGeometryEdmType;
-exports.isNamedStream = isNamedStream;
-exports.isPrimitive = isPrimitive;
-exports.isPrimitiveEdmType = isPrimitiveEdmType;
-exports.lookupComplexType = lookupComplexType;
-exports.lookupDefaultEntityContainer = lookupDefaultEntityContainer;
-exports.lookupEntityContainer = lookupEntityContainer;
-exports.lookupEntitySet = lookupEntitySet;
-exports.lookupSingleton = lookupSingleton;
-exports.lookupEntityType = lookupEntityType;
-exports.lookupFunctionImport = lookupFunctionImport;
-exports.lookupNavigationPropertyType = lookupNavigationPropertyType;
-exports.lookupNavigationPropertyEntitySet = lookupNavigationPropertyEntitySet;
-exports.lookupInSchema = lookupInSchema;
-exports.lookupProperty = lookupProperty;
-exports.lookupInMetadata = lookupInMetadata;
-exports.getEntitySetInfo = getEntitySetInfo;
-exports.maxVersion = maxVersion;
-exports.navigationPropertyKind = navigationPropertyKind;
-exports.normalizeHeaders = normalizeHeaders;
-exports.parseBool = parseBool;
-
-
-exports.parseDate = parseDate;
-exports.parseDateTimeOffset = parseDateTimeOffset;
-exports.parseDuration = parseDuration;
-exports.parseTimeOfDay = parseTimeOfDay;
-
-exports.parseInt10 = parseInt10;
-exports.prepareRequest = prepareRequest;
-exports.removeNamespace = removeNamespace;
-exports.traverse = traverse;
-
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/87e35975/odatajs/src/lib/odatajs/deferred.js
----------------------------------------------------------------------
diff --git a/odatajs/src/lib/odatajs/deferred.js b/odatajs/src/lib/odatajs/deferred.js
deleted file mode 100644
index 7d5fd68..0000000
--- a/odatajs/src/lib/odatajs/deferred.js
+++ /dev/null
@@ -1,189 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/** @module datajs/deferred */
-
-
-
-/** Creates a new function to forward a call.
- * @param {Object} thisValue - Value to use as the 'this' object.
- * @param {String} name - Name of function to forward to.
- * @param {Object} returnValue - Return value for the forward call (helps keep identity when chaining calls).
- * @returns {Function} A new function that will forward a call.
- */
-function forwardCall(thisValue, name, returnValue) {
- return function () {
- thisValue[name].apply(thisValue, arguments);
- return returnValue;
- };
-}
-
-/** Initializes a new DjsDeferred object.
- * <ul>
- * <li> Compability Note A - Ordering of callbacks through chained 'then' invocations <br>
- *
- * The Wiki entry at http://wiki.commonjs.org/wiki/Promises/A
- * implies that .then() returns a distinct object.
- *
- * For compatibility with http://api.jquery.com/category/deferred-object/
- * we return this same object. This affects ordering, as
- * the jQuery version will fire callbacks in registration
- * order regardless of whether they occur on the result
- * or the original object.
- * </li>
- * <li>Compability Note B - Fulfillment value <br>
- *
- * The Wiki entry at http://wiki.commonjs.org/wiki/Promises/A
- * implies that the result of a success callback is the
- * fulfillment value of the object and is received by
- * other success callbacks that are chained.
- *
- * For compatibility with http://api.jquery.com/category/deferred-object/
- * we disregard this value instead.
- * </li></ul>
- * @class DjsDeferred
- */
- function DjsDeferred() {
- this._arguments = undefined;
- this._done = undefined;
- this._fail = undefined;
- this._resolved = false;
- this._rejected = false;
-}
-
-
-DjsDeferred.prototype = {
-
- /** Adds success and error callbacks for this deferred object.
- * See Compatibility Note A.
- * @method DjsDeferred#then
- * @param {function} [fulfilledHandler] - Success callback ( may be null)
- * @param {function} [errorHandler] - Error callback ( may be null)
- */
- then: function (fulfilledHandler, errorHandler) {
-
- if (fulfilledHandler) {
- if (!this._done) {
- this._done = [fulfilledHandler];
- } else {
- this._done.push(fulfilledHandler);
- }
- }
-
- if (errorHandler) {
- if (!this._fail) {
- this._fail = [errorHandler];
- } else {
- this._fail.push(errorHandler);
- }
- }
-
- //// See Compatibility Note A in the DjsDeferred constructor.
- //// if (!this._next) {
- //// this._next = createDeferred();
- //// }
- //// return this._next.promise();
-
- if (this._resolved) {
- this.resolve.apply(this, this._arguments);
- } else if (this._rejected) {
- this.reject.apply(this, this._arguments);
- }
-
- return this;
- },
-
- /** Invokes success callbacks for this deferred object.
- * All arguments are forwarded to success callbacks.
- * @method DjsDeferred#resolve
- */
- resolve: function (/* args */) {
- if (this._done) {
- var i, len;
- for (i = 0, len = this._done.length; i < len; i++) {
- //// See Compability Note B - Fulfillment value.
- //// var nextValue =
- this._done[i].apply(null, arguments);
- }
-
- //// See Compatibility Note A in the DjsDeferred constructor.
- //// this._next.resolve(nextValue);
- //// delete this._next;
-
- this._done = undefined;
- this._resolved = false;
- this._arguments = undefined;
- } else {
- this._resolved = true;
- this._arguments = arguments;
- }
- },
-
- /** Invokes error callbacks for this deferred object.
- * All arguments are forwarded to error callbacks.
- * @method DjsDeferred#reject
- */
- reject: function (/* args */) {
-
- if (this._fail) {
- var i, len;
- for (i = 0, len = this._fail.length; i < len; i++) {
- this._fail[i].apply(null, arguments);
- }
-
- this._fail = undefined;
- this._rejected = false;
- this._arguments = undefined;
- } else {
- this._rejected = true;
- this._arguments = arguments;
- }
- },
-
- /** Returns a version of this object that has only the read-only methods available.
- * @method DjsDeferred#promise
- * @returns An object with only the promise object.
- */
-
- promise: function () {
- var result = {};
- result.then = forwardCall(this, "then", result);
- return result;
- }
-};
-
-/** Creates a deferred object.
- * @returns {DjsDeferred} A new deferred object. If jQuery is installed, then a jQueryDeferred object is returned, which provides a superset of features.
-*/
-function createDeferred() {
- if (window.jQuery && window.jQuery.Deferred) {
- return new window.jQuery.Deferred();
- } else {
- return new DjsDeferred();
- }
-};
-
-
-
-
-/** createDeferred (see {@link module:datajs/deferred~createDeferred}) */
-exports.createDeferred = createDeferred;
-
-/** DjsDeferred (see {@link DjsDeferred}) */
-exports.DjsDeferred = DjsDeferred;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/87e35975/odatajs/src/lib/odatajs/utils.js
----------------------------------------------------------------------
diff --git a/odatajs/src/lib/odatajs/utils.js b/odatajs/src/lib/odatajs/utils.js
deleted file mode 100644
index 27af705..0000000
--- a/odatajs/src/lib/odatajs/utils.js
+++ /dev/null
@@ -1,582 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/** @module datajs/utils */
-
-
-function inBrowser() {
- return typeof window !== 'undefined';
-}
-
-/** Creates a new ActiveXObject from the given progId.
- * @param {String} progId - ProgId string of the desired ActiveXObject.
- * @returns {Object} The ActiveXObject instance. Null if ActiveX is not supported by the browser.
- * This function throws whatever exception might occur during the creation
- * of the ActiveXObject.
-*/
-var activeXObject = function (progId) {
-
- if (window.ActiveXObject) {
- return new window.ActiveXObject(progId);
- }
- return null;
-};
-
-/** Checks whether the specified value is different from null and undefined.
- * @param [value] Value to check ( may be null)
- * @returns {Boolean} true if the value is assigned; false otherwise.
-*/
-function assigned(value) {
- return value !== null && value !== undefined;
-}
-
-/** Checks whether the specified item is in the array.
- * @param {Array} [arr] Array to check in.
- * @param item - Item to look for.
- * @returns {Boolean} true if the item is contained, false otherwise.
-*/
-function contains(arr, item) {
- var i, len;
- for (i = 0, len = arr.length; i < len; i++) {
- if (arr[i] === item) {
- return true;
- }
- }
- return false;
-}
-
-/** Given two values, picks the first one that is not undefined.
- * @param a - First value.
- * @param b - Second value.
- * @returns a if it's a defined value; else b.</returns>
- */
-function defined(a, b) {
- return (a !== undefined) ? a : b;
-}
-
-/** Delays the invocation of the specified function until execution unwinds.
- * @param {Function} callback - Callback function.
- */
-function delay(callback) {
-
- if (arguments.length === 1) {
- window.setTimeout(callback, 0);
- return;
- }
-
- var args = Array.prototype.slice.call(arguments, 1);
- window.setTimeout(function () {
- callback.apply(this, args);
- }, 0);
-}
-
-/** Throws an exception in case that a condition evaluates to false.
- * @param {Boolean} condition - Condition to evaluate.
- * @param {String} message - Message explaining the assertion.
- * @param {Object} data - Additional data to be included in the exception.
- */
-// DATAJS INTERNAL START
-function djsassert(condition, message, data) {
-
-
- if (!condition) {
- throw { message: "Assert fired: " + message, data: data };
- }
-}
-// DATAJS INTERNAL END
-
-/** Extends the target with the specified values.
- * @param {Object} target - Object to add properties to.
- * @param {Object} values - Object with properties to add into target.
- * @returns {Object} The target object.
-*/
-function extend(target, values) {
- for (var name in values) {
- target[name] = values[name];
- }
-
- return target;
-}
-
-function find(arr, callback) {
- /** Returns the first item in the array that makes the callback function true.
- * @param {Array} [arr] Array to check in. ( may be null)
- * @param {Function} callback - Callback function to invoke once per item in the array.
- * @returns The first item that makes the callback return true; null otherwise or if the array is null.
- */
-
- if (arr) {
- var i, len;
- for (i = 0, len = arr.length; i < len; i++) {
- if (callback(arr[i])) {
- return arr[i];
- }
- }
- }
- return null;
-}
-
-function isArray(value) {
- /** Checks whether the specified value is an array object.
- * @param value - Value to check.
- * @returns {Boolean} true if the value is an array object; false otherwise.
- */
-
- return Object.prototype.toString.call(value) === "[object Array]";
-}
-
-/** Checks whether the specified value is a Date object.
- * @param value - Value to check.
- * @returns {Boolean} true if the value is a Date object; false otherwise.
- */
-function isDate(value) {
- return Object.prototype.toString.call(value) === "[object Date]";
-}
-
-/** Tests whether a value is an object.
- * @param value - Value to test.
- * @returns {Boolean} True is the value is an object; false otherwise.
- * Per javascript rules, null and array values are objects and will cause this function to return true.
- */
-function isObject(value) {
- return typeof value === "object";
-}
-
-/** Parses a value in base 10.
- * @param {String} value - String value to parse.
- * @returns {Number} The parsed value, NaN if not a valid value.
-*/
-function parseInt10(value) {
- return parseInt(value, 10);
-}
-
-/** Renames a property in an object.
- * @param {Object} obj - Object in which the property will be renamed.
- * @param {String} oldName - Name of the property that will be renamed.
- * @param {String} newName - New name of the property.
- * This function will not do anything if the object doesn't own a property with the specified old name.
- */
-function renameProperty(obj, oldName, newName) {
- if (obj.hasOwnProperty(oldName)) {
- obj[newName] = obj[oldName];
- delete obj[oldName];
- }
-}
-
-/** Default error handler.
- * @param {Object} error - Error to handle.
- */
-function throwErrorCallback(error) {
- throw error;
-}
-
-/** Removes leading and trailing whitespaces from a string.
- * @param {String str String to trim
- * @returns {String} The string with no leading or trailing whitespace.
- */
-function trimString(str) {
- if (str.trim) {
- return str.trim();
- }
-
- return str.replace(/^\s+|\s+$/g, '');
-}
-
-/** Returns a default value in place of undefined.
- * @param [value] Value to check (may be null)
- * @param defaultValue - Value to return if value is undefined.
- * @returns value if it's defined; defaultValue otherwise.
- * This should only be used for cases where falsy values are valid;
- * otherwise the pattern should be 'x = (value) ? value : defaultValue;'.
- */
-function undefinedDefault(value, defaultValue) {
- return (value !== undefined) ? value : defaultValue;
-}
-
-// Regular expression that splits a uri into its components:
-// 0 - is the matched string.
-// 1 - is the scheme.
-// 2 - is the authority.
-// 3 - is the path.
-// 4 - is the query.
-// 5 - is the fragment.
-var uriRegEx = /^([^:\/?#]+:)?(\/\/[^\/?#]*)?([^?#:]+)?(\?[^#]*)?(#.*)?/;
-var uriPartNames = ["scheme", "authority", "path", "query", "fragment"];
-
-/** Gets information about the components of the specified URI.
- * @param {String} uri - URI to get information from.
- * @return {Object} An object with an isAbsolute flag and part names (scheme, authority, etc.) if available.
- */
-function getURIInfo(uri) {
- var result = { isAbsolute: false };
-
- if (uri) {
- var matches = uriRegEx.exec(uri);
- if (matches) {
- var i, len;
- for (i = 0, len = uriPartNames.length; i < len; i++) {
- if (matches[i + 1]) {
- result[uriPartNames[i]] = matches[i + 1];
- }
- }
- }
- if (result.scheme) {
- result.isAbsolute = true;
- }
- }
-
- return result;
-}
-
-/** Builds a URI string from its components.
- * @param {Object} uriInfo - An object with uri parts (scheme, authority, etc.).
- * @returns {String} URI string.
- */
-function getURIFromInfo(uriInfo) {
- return "".concat(
- uriInfo.scheme || "",
- uriInfo.authority || "",
- uriInfo.path || "",
- uriInfo.query || "",
- uriInfo.fragment || "");
-}
-
-// Regular expression that splits a uri authority into its subcomponents:
-// 0 - is the matched string.
-// 1 - is the userinfo subcomponent.
-// 2 - is the host subcomponent.
-// 3 - is the port component.
-var uriAuthorityRegEx = /^\/{0,2}(?:([^@]*)@)?([^:]+)(?::{1}(\d+))?/;
-
-// Regular expression that matches percentage enconded octects (i.e %20 or %3A);
-var pctEncodingRegEx = /%[0-9A-F]{2}/ig;
-
-/** Normalizes the casing of a URI.
- * @param {String} uri - URI to normalize, absolute or relative.
- * @returns {String} The URI normalized to lower case.
-*/
-function normalizeURICase(uri) {
- var uriInfo = getURIInfo(uri);
- var scheme = uriInfo.scheme;
- var authority = uriInfo.authority;
-
- if (scheme) {
- uriInfo.scheme = scheme.toLowerCase();
- if (authority) {
- var matches = uriAuthorityRegEx.exec(authority);
- if (matches) {
- uriInfo.authority = "//" +
- (matches[1] ? matches[1] + "@" : "") +
- (matches[2].toLowerCase()) +
- (matches[3] ? ":" + matches[3] : "");
- }
- }
- }
-
- uri = getURIFromInfo(uriInfo);
-
- return uri.replace(pctEncodingRegEx, function (str) {
- return str.toLowerCase();
- });
-}
-
-/** Normalizes a possibly relative URI with a base URI.
- * @param {String} uri - URI to normalize, absolute or relative
- * @param {String} base - Base URI to compose with (may be null)
- * @returns {String} The composed URI if relative; the original one if absolute.
- */
-function normalizeURI(uri, base) {
- if (!base) {
- return uri;
- }
-
- var uriInfo = getURIInfo(uri);
- if (uriInfo.isAbsolute) {
- return uri;
- }
-
- var baseInfo = getURIInfo(base);
- var normInfo = {};
- var path;
-
- if (uriInfo.authority) {
- normInfo.authority = uriInfo.authority;
- path = uriInfo.path;
- normInfo.query = uriInfo.query;
- } else {
- if (!uriInfo.path) {
- path = baseInfo.path;
- normInfo.query = uriInfo.query || baseInfo.query;
- } else {
- if (uriInfo.path.charAt(0) === '/') {
- path = uriInfo.path;
- } else {
- path = mergeUriPathWithBase(uriInfo.path, baseInfo.path);
- }
- normInfo.query = uriInfo.query;
- }
- normInfo.authority = baseInfo.authority;
- }
-
- normInfo.path = removeDotsFromPath(path);
-
- normInfo.scheme = baseInfo.scheme;
- normInfo.fragment = uriInfo.fragment;
-
- return getURIFromInfo(normInfo);
-}
-
-/** Merges the path of a relative URI and a base URI.
- * @param {String} uriPath - Relative URI path.</param>
- * @param {String} basePath - Base URI path.
- * @returns {String} A string with the merged path.
- */
-function mergeUriPathWithBase(uriPath, basePath) {
- var path = "/";
- var end;
-
- if (basePath) {
- end = basePath.lastIndexOf("/");
- path = basePath.substring(0, end);
-
- if (path.charAt(path.length - 1) !== "/") {
- path = path + "/";
- }
- }
-
- return path + uriPath;
-}
-
-/** Removes the special folders . and .. from a URI's path.
- * @param {string} path - URI path component.
- * @returns {String} Path without any . and .. folders.
- */
-function removeDotsFromPath(path) {
- var result = "";
- var segment = "";
- var end;
-
- while (path) {
- if (path.indexOf("..") === 0 || path.indexOf(".") === 0) {
- path = path.replace(/^\.\.?\/?/g, "");
- } else if (path.indexOf("/..") === 0) {
- path = path.replace(/^\/\..\/?/g, "/");
- end = result.lastIndexOf("/");
- if (end === -1) {
- result = "";
- } else {
- result = result.substring(0, end);
- }
- } else if (path.indexOf("/.") === 0) {
- path = path.replace(/^\/\.\/?/g, "/");
- } else {
- segment = path;
- end = path.indexOf("/", 1);
- if (end !== -1) {
- segment = path.substring(0, end);
- }
- result = result + segment;
- path = path.replace(segment, "");
- }
- }
- return result;
-}
-
-function convertByteArrayToHexString(str) {
- var arr = [];
- if (window.atob === undefined) {
- arr = decodeBase64(str);
- } else {
- var binaryStr = window.atob(str);
- for (var i = 0; i < binaryStr.length; i++) {
- arr.push(binaryStr.charCodeAt(i));
- }
- }
- var hexValue = "";
- var hexValues = "0123456789ABCDEF";
- for (var j = 0; j < arr.length; j++) {
- var t = arr[j];
- hexValue += hexValues[t >> 4];
- hexValue += hexValues[t & 0x0F];
- }
- return hexValue;
-}
-
-function decodeBase64(str) {
- var binaryString = "";
- for (var i = 0; i < str.length; i++) {
- var base65IndexValue = getBase64IndexValue(str[i]);
- var binaryValue = "";
- if (base65IndexValue !== null) {
- binaryValue = base65IndexValue.toString(2);
- binaryString += addBase64Padding(binaryValue);
- }
- }
- var byteArray = [];
- var numberOfBytes = parseInt(binaryString.length / 8, 10);
- for (i = 0; i < numberOfBytes; i++) {
- var intValue = parseInt(binaryString.substring(i * 8, (i + 1) * 8), 2);
- byteArray.push(intValue);
- }
- return byteArray;
-}
-
-function getBase64IndexValue(character) {
- var asciiCode = character.charCodeAt(0);
- var asciiOfA = 65;
- var differenceBetweenZanda = 6;
- if (asciiCode >= 65 && asciiCode <= 90) { // between "A" and "Z" inclusive
- return asciiCode - asciiOfA;
- } else if (asciiCode >= 97 && asciiCode <= 122) { // between 'a' and 'z' inclusive
- return asciiCode - asciiOfA - differenceBetweenZanda;
- } else if (asciiCode >= 48 && asciiCode <= 57) { // between '0' and '9' inclusive
- return asciiCode + 4;
- } else if (character == "+") {
- return 62;
- } else if (character == "/") {
- return 63;
- } else {
- return null;
- }
-}
-
-function addBase64Padding(binaryString) {
- while (binaryString.length < 6) {
- binaryString = "0" + binaryString;
- }
- return binaryString;
-
-}
-
-function getJsonValueArraryLength(data) {
- if (data && data.value) {
- return data.value.length;
- }
-
- return 0;
-}
-
-function sliceJsonValueArray(data, start, end) {
- if (data === undefined || data.value === undefined) {
- return data;
- }
-
- if (start < 0) {
- start = 0;
- }
-
- var length = getJsonValueArraryLength(data);
- if (length < end) {
- end = length;
- }
-
- var newdata = {};
- for (var property in data) {
- if (property == "value") {
- newdata[property] = data[property].slice(start, end);
- } else {
- newdata[property] = data[property];
- }
- }
-
- return newdata;
-}
-
-function concatJsonValueArray(data, concatData) {
- if (concatData === undefined || concatData.value === undefined) {
- return data;
- }
-
- if (data === undefined || Object.keys(data).length === 0) {
- return concatData;
- }
-
- if (data.value === undefined) {
- data.value = concatData.value;
- return data;
- }
-
- data.value = data.value.concat(concatData.value);
-
- return data;
-}
-
-function endsWith(input, search) {
- return input.indexOf(search, input.length - search.length) !== -1;
-}
-
-function startsWith (input, search) {
- return input.indexOf(search) === 0;
-}
-
-function getFormatKind(format, defaultFormatKind) {
- var formatKind = defaultFormatKind;
- if (!assigned(format)) {
- return formatKind;
- }
-
- var normalizedFormat = format.toLowerCase();
- switch (normalizedFormat) {
- case "none":
- formatKind = 0;
- break;
- case "minimal":
- formatKind = 1;
- break;
- case "full":
- formatKind = 2;
- break;
- default:
- break;
- }
-
- return formatKind;
-}
-
-
-
-
-exports.inBrowser = inBrowser;
-exports.activeXObject = activeXObject;
-exports.assigned = assigned;
-exports.contains = contains;
-exports.defined = defined;
-exports.delay = delay;
-exports.djsassert = djsassert;
-exports.extend = extend;
-exports.find = find;
-exports.getURIInfo = getURIInfo;
-exports.isArray = isArray;
-exports.isDate = isDate;
-exports.isObject = isObject;
-exports.normalizeURI = normalizeURI;
-exports.normalizeURICase = normalizeURICase;
-exports.parseInt10 = parseInt10;
-exports.renameProperty = renameProperty;
-exports.throwErrorCallback = throwErrorCallback;
-exports.trimString = trimString;
-exports.undefinedDefault = undefinedDefault;
-exports.decodeBase64 = decodeBase64;
-exports.convertByteArrayToHexString = convertByteArrayToHexString;
-exports.getJsonValueArraryLength = getJsonValueArraryLength;
-exports.sliceJsonValueArray = sliceJsonValueArray;
-exports.concatJsonValueArray = concatJsonValueArray;
-exports.startsWith = startsWith;
-exports.endsWith = endsWith;
-exports.getFormatKind = getFormatKind;
\ No newline at end of file
[5/5] git commit: [OLINGO-442] Create packaging tool and remove
browserify
Posted by ko...@apache.org.
[OLINGO-442] Create packaging tool and remove browserify
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/commit/87e35975
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/tree/87e35975
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/diff/87e35975
Branch: refs/heads/master
Commit: 87e35975d7c71819e69d591daba23f5c8c07b1f3
Parents: 5e973c8
Author: Sven Kobler <sv...@sap.com>
Authored: Mon Oct 20 09:26:58 2014 +0200
Committer: Sven Kobler <sv...@sap.com>
Committed: Mon Oct 20 09:38:52 2014 +0200
----------------------------------------------------------------------
odatajs/Gruntfile.js | 121 +-
.../stripheader/package.json | 42 -
.../stripheader/stripheader.js | 42 -
.../custom-tasks/rat/extern-tools/info.md | 4 +-
.../grunt-config/custom-tasks/rat/package.json | 18 -
odatajs/grunt-config/custom-tasks/toBrowser.js | 23 +
.../custom-tasks/toBrowser/toBrowser.js | 78 ++
.../custom-tasks/toBrowser/wrapper-tpl.js | 43 +
odatajs/grunt-config/release.js | 28 +-
odatajs/grunt-config/sign.js | 1 -
odatajs/package.json | 4 +-
odatajs/src/browser-lib-tpl.js | 43 +
odatajs/src/index-browser.js | 36 +
odatajs/src/index-node.js | 47 +
odatajs/src/index.js | 21 +-
odatajs/src/lib/cache.js | 11 +-
odatajs/src/lib/cache/source.js | 2 +-
odatajs/src/lib/deferred.js | 189 +++
odatajs/src/lib/odata.js | 4 +-
odatajs/src/lib/odata/batch.js | 4 +-
odatajs/src/lib/odata/handler.js | 4 +-
odatajs/src/lib/odata/json.js | 4 +-
odatajs/src/lib/odata/metadata.js | 4 +-
odatajs/src/lib/odata/net.js | 2 +-
odatajs/src/lib/odata/odatautils.js | 1265 ++++++++++++++++++
odatajs/src/lib/odata/utils.js | 1265 ------------------
odatajs/src/lib/odatajs/deferred.js | 189 ---
odatajs/src/lib/odatajs/utils.js | 582 --------
odatajs/src/lib/odatajs/xml.js | 816 -----------
odatajs/src/lib/store/dom.js | 2 +-
odatajs/src/lib/store/indexeddb.js | 2 +-
odatajs/src/lib/store/memory.js | 2 +-
odatajs/src/lib/utils.js | 582 ++++++++
odatajs/src/lib/xml.js | 816 +++++++++++
odatajs/test-node/test.html | 29 +
odatajs/test-node/test.js | 22 +
odatajs/tests/odata-qunit-tests.htm | 2 +-
olingojs-4.0.0-beta-01.exports.json | 917 +++++++++++++
38 files changed, 4194 insertions(+), 3072 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/87e35975/odatajs/Gruntfile.js
----------------------------------------------------------------------
diff --git a/odatajs/Gruntfile.js b/odatajs/Gruntfile.js
index 5b66d60..435584d 100644
--- a/odatajs/Gruntfile.js
+++ b/odatajs/Gruntfile.js
@@ -26,56 +26,53 @@ module.exports = function(grunt) {
(pkg.postfix.length > 0 ? "-" : "") + pkg.postfix +
(pkg.releaseCandidate.length > 0 ? "-" : "") + pkg.releaseCandidate;
+ //options
var init = {
pkg: pkg,
banner: grunt.file.read('src/banner.txt'),
artifactname : artifactname,
- "browserify": { // convert code from nodejs style to browser style
- src: {
- files: { 'build/lib/<%= artifactname %>.js': ['src/index.js'] },
- options: { // remove apache license headers before contatenating
- transform: ['./grunt-config/browserify_transforms/stripheader/stripheader.js'],
- }
+ "toBrowser" : {
+ "release" : {
+ options: { index : "src/index-browser.js" },
+ files: [{
+ src: ["src/lib/**/*.js"],
+ dest: "build/lib/<%= artifactname %>.js",
+ }]
}
},
"uglify": { // uglify and minify the lib
options: {
sourceMap : true,
- sourceMapName : 'build/lib/<%= artifactname %>.map',
+ sourceMapName : "build/lib/<%= artifactname %>.map",
sourceMapIncludeSources : true,
},
build: {
- src: 'build/lib/<%= artifactname %>.js',
- dest: 'build/lib/<%= artifactname %>.min.js'
+ src: "build/lib/<%= artifactname %>.js",
+ dest: "build/lib/<%= artifactname %>.min.js"
}
},
"concat" : { // add the apache license headers
options : {
- banner : '<%= banner %>'
+ banner : "<%= banner %>"
},
licence: {
- src: 'build/lib/<%= artifactname %>.js',
- dest: 'build/lib/<%= artifactname %>.js',
+ src: "build/lib/<%= artifactname %>.js",
+ dest: "build/lib/<%= artifactname %>.js",
},
licence_min: {
- src: 'build/lib/<%= artifactname %>.min.js',
- dest: 'build/lib/<%= artifactname %>.min.js',
- },
- src: {
- src: ['src/**/*.js'],
- dest: 'build/lib/<%= artifactname %>.js',
+ src: "build/lib/<%= artifactname %>.min.js",
+ dest: "build/lib/<%= artifactname %>.min.js",
},
-
},
- "jsdoc" : { // generate documentation
+ "jsdoc" : {
src : {
- src: ['src/**/*.js'],
- options: { destination: 'build/doc-src', verbose : false }
+ src: ["src/**/*.js"],
+ options: { destination: "build/doc-src", verbose : false }
},
test : {
- src: ['tests/**/*.js'],
- options: { destination: 'build/doc-test', verbose : false }
+ src: ["tests/**/*.js"],
+ options: { destination: "build/doc-test", verbose : false }
}
},
"nugetpack" : { // create nuget pagckage
@@ -84,57 +81,43 @@ module.exports = function(grunt) {
dest: 'build/'
}
},
- 'copy' : {
- 'to-latest' : {
+ "copy" : {
+ "to-latest" : {
files: [
{
- src :'build/lib/<%= artifactname %>.js',
- dest: 'build/lib/odatajs-latest.js' },
- ]
- }
-
+ src :"build/lib/<%= artifactname %>.js",
+ dest: "build/lib/odatajs-latest.js" },
+ ]
+ }
},
"npm-clean": {
options: {force: true},
"build": {
- src: [ "build"],
- },
- "lib": {
- src: [ "build/lib"]
- },
- "tmp": {
- src: [ "build/tmp"]
- },
- "doc": {
- src: ["build/doc"],
- },
- "doc-test": {
- src: ["build/doc-test"],
+ src: [ "build"]
},
},
"curl": {
- 'license': {
+ "license": {
src: {
- url: 'http://apache.org/licenses/LICENSE-2.0.txt',
- proxy: 'http://proxy:8080'
+ url: "http://apache.org/licenses/LICENSE-2.0.txt",
+ proxy: "http://proxy:8080"
},
- dest: 'LICENSE'
+ dest: "LICENSE"
}
- }
+ }
};
- /*** Join local configuration for proxies and local test servers ***/
+ // Join local configuration for proxies and local test servers
if (grunt.file.exists('localgrunt.config')) {
console.log("merge localgrunt.config");
var localGrundConfig = grunt.file.read('localgrunt.config');
init.connect['test-browser'].proxies = init.connect['test-browser'].proxies.concat(JSON.parse(localGrundConfig).proxies);
}
- /*** Init ***/
+ // Init config
grunt.initConfig(init);
- /*** Load tasks from npm modules ***/
- grunt.loadNpmTasks('grunt-browserify');
+ // Load tasks from npm modules ***/
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks("grunt-contrib-copy");
grunt.loadNpmTasks("grunt-contrib-concat");
@@ -143,10 +126,8 @@ module.exports = function(grunt) {
grunt.loadNpmTasks("grunt-jsdoc");
grunt.loadNpmTasks("grunt-nuget");
- // Start Qunit tests direcly in node js, internally qunit (npm qunit)
- // is used, no phantomjs instance required
- //grunt.loadNpmTasks('grunt-node-qunit');
- //grunt.loadNpmTasks('grunt-contrib-clean');
+ // Load the custom-* tasks from the grunt-config directory
+ grunt.loadTasks('grunt-config/custom-tasks');
// Load the custom-* tasks from the grunt-config directory
grunt.loadTasks('grunt-config');
@@ -158,9 +139,9 @@ module.exports = function(grunt) {
process.env['JAVA_TOOL_OPTIONS'] = '';
});
- /*** E N D U S E R T A S K S ***/
+ // E N D U S E R T A S K S
- grunt.registerTask('clean', ['npm-clean']);
+ grunt.registerTask('clean', ['npm-clean:build']);
// Runs the license header check to verify the any source file contains a license header
grunt.registerTask('license-check', ['rat:manual']);
@@ -170,14 +151,32 @@ module.exports = function(grunt) {
grunt.registerTask('doc-test', ['clearEnv', 'jsdoc:test']);
// Build the odatajs library
- grunt.registerTask('build', ['clean:lib','browserify:src', 'uglify:build', 'concat:licence','concat:licence_min','copy:to-latest','nugetpack']);
- grunt.registerTask('build2', ['clean:lib','concat:src', 'uglify:build', 'concat:licence','concat:licence_min','nugetpack']);
+
grunt.registerTask('test-browser', ['configureProxies:test-browser', 'connect:test-browser']);
grunt.registerTask('test-node', ['node-qunit:default-tests']);
//grunt.registerTask('release', ['build','doc','compress']);
//grunt.registerTask('update-legal', ['curl:license']);
+
+ grunt.registerTask('build', ['clean:lib','toBrowser:release', 'uglify:build', 'concat:licence_min','copy:to-latest','nugetpack']);
+
+ grunt.registerTask('get-licence', ['curl:license']);
+
+ // R E L E A S E T A S K S
+ grunt.registerTask('release',[
+ 'npm-clean:release-dist',
+ 'build',
+ 'doc',
+ 'copy:release-lib','copy:release-doc','copy:release-sources',
+ 'rat:dist', // check the license headers
+ 'compress:release-lib','compress:release-doc','compress:release-sources',
+ ]);
+
+ grunt.registerTask('release:sign',[
+ 'sign:release','sign:asc','sign:asc-verify'
+ ]);
+
};
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/87e35975/odatajs/grunt-config/browserify_transforms/stripheader/package.json
----------------------------------------------------------------------
diff --git a/odatajs/grunt-config/browserify_transforms/stripheader/package.json b/odatajs/grunt-config/browserify_transforms/stripheader/package.json
deleted file mode 100644
index a86cfca..0000000
--- a/odatajs/grunt-config/browserify_transforms/stripheader/package.json
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-{
- "name": "grunt-rat",
- "version": "0.0.1",
- "description": "Transform vor removing license headers",
- "license": "Apache",
- "author": {
- "name": "Sven Kobler-Morris",
- "email": "koblers@apache.org"
- },
- "files": [
- "tasks"
- ],
- "dependencies": {
- "through": "^2.3.4"
- },
- "devDependencies": {
- },
- "peerDependencies": {
- "grunt": "~0.4.0"
- },
- "engines": {
- "node": ">=0.8.0"
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/87e35975/odatajs/grunt-config/browserify_transforms/stripheader/stripheader.js
----------------------------------------------------------------------
diff --git a/odatajs/grunt-config/browserify_transforms/stripheader/stripheader.js b/odatajs/grunt-config/browserify_transforms/stripheader/stripheader.js
deleted file mode 100644
index b4f6f35..0000000
--- a/odatajs/grunt-config/browserify_transforms/stripheader/stripheader.js
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-var through = require('through');
-
-module.exports = function (file) {
- //if (/\.json$/.test(file)) return through();
- //console.log('strip header from ' + file);
- var data = "";
-
-
- return through(
- function (buf) { data += buf; },
- function () {
- try {
- //console.log('\nin--------------\na'+data.substring(0,1000));
- var out = data.replace(/(\/\*(.|\n|\r)*?\*\/)/i,"");
- //console.log('\nout--------------\n'+out.substring(0,300));
- this.queue(out);
- } catch (er) {
- this.emit("error", new Error(er.toString().replace("Error: ", "") + " (" + file + ")"));
- }
- this.queue(null);
- }
- );
-};
-
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/87e35975/odatajs/grunt-config/custom-tasks/rat/extern-tools/info.md
----------------------------------------------------------------------
diff --git a/odatajs/grunt-config/custom-tasks/rat/extern-tools/info.md b/odatajs/grunt-config/custom-tasks/rat/extern-tools/info.md
index f925cb2..f48049e 100644
--- a/odatajs/grunt-config/custom-tasks/rat/extern-tools/info.md
+++ b/odatajs/grunt-config/custom-tasks/rat/extern-tools/info.md
@@ -16,5 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-Place apache-rat-0.11.jar in ./apache-rat-0.11/apache-rat-0.11.jar.
+Place apache-rat-0.11.jar from http://creadur.apache.org/rat/download_rat.cgi
+in ./apache-rat-0.11/apache-rat-0.11.jar.
+
See ./../readme.md for details
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/87e35975/odatajs/grunt-config/custom-tasks/rat/package.json
----------------------------------------------------------------------
diff --git a/odatajs/grunt-config/custom-tasks/rat/package.json b/odatajs/grunt-config/custom-tasks/rat/package.json
index f5fa8bb..0c374c7 100644
--- a/odatajs/grunt-config/custom-tasks/rat/package.json
+++ b/odatajs/grunt-config/custom-tasks/rat/package.json
@@ -1,21 +1,3 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
{
"name": "grunt-rat",
"version": "0.0.1",
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/87e35975/odatajs/grunt-config/custom-tasks/toBrowser.js
----------------------------------------------------------------------
diff --git a/odatajs/grunt-config/custom-tasks/toBrowser.js b/odatajs/grunt-config/custom-tasks/toBrowser.js
new file mode 100644
index 0000000..4712a87
--- /dev/null
+++ b/odatajs/grunt-config/custom-tasks/toBrowser.js
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+module.exports = function(grunt) {
+ require('./toBrowser/toBrowser.js')(grunt);
+};
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/87e35975/odatajs/grunt-config/custom-tasks/toBrowser/toBrowser.js
----------------------------------------------------------------------
diff --git a/odatajs/grunt-config/custom-tasks/toBrowser/toBrowser.js b/odatajs/grunt-config/custom-tasks/toBrowser/toBrowser.js
new file mode 100644
index 0000000..eccaf35
--- /dev/null
+++ b/odatajs/grunt-config/custom-tasks/toBrowser/toBrowser.js
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+module.exports = function(grunt) {
+
+ var stripHeader = function(input) {
+ return input.replace(/(\/\*(.|\n|\r)*?\*\/)/i,"");
+ };
+
+ grunt.registerMultiTask('toBrowser', function() {
+ var self = this;
+
+ var path = require('path');
+ var fs = require( 'fs' );
+
+ var globalDone = this.async();
+
+ var options = this.options({ });
+
+ var workLoad = [];
+ var writeToLogOk = function(data) { grunt.log.ok(data.toString()); };
+
+
+ // fill workLoad
+ for(var i = 0; i < this.files.length; i++) {
+ for(var ii = 0; ii < this.files[i].src.length; ii++) {
+ var srcFile = this.files[i].src[ii];
+ workLoad.push({
+ srcFile : srcFile,
+ name : srcFile.substring(srcFile.lastIndexOf('/')+1,srcFile.length-3)
+ });
+ }
+
+ var concat = '{';
+ for(var x = 0; x < workLoad.length; x++) {
+ var src = grunt.file.read(workLoad[x].srcFile);
+ // remove the first comment
+ src = stripHeader(src);
+
+ if (x > 0) {
+ concat+= ', ';
+ }
+
+ concat+= '"' + workLoad[x].name + '" : ';
+ concat+= 'function(exports, module, require) {';
+ concat+= src +'}';
+ }
+ concat+= '}';
+
+ var tpl = grunt.file.read('./grunt-config/custom-tasks/toBrowser/wrapper-tpl.js');
+ var init = stripHeader(grunt.file.read(options.index));
+
+ tpl = tpl.replace('\'<% initFunction %>\'',init);
+ tpl = tpl.replace('\'<% filesAsFunctionList %>\'',concat);
+
+ grunt.file.write(this.files[i].dest, tpl);
+ }
+
+ globalDone();
+ });
+};
+
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/87e35975/odatajs/grunt-config/custom-tasks/toBrowser/wrapper-tpl.js
----------------------------------------------------------------------
diff --git a/odatajs/grunt-config/custom-tasks/toBrowser/wrapper-tpl.js b/odatajs/grunt-config/custom-tasks/toBrowser/wrapper-tpl.js
new file mode 100644
index 0000000..9c335db
--- /dev/null
+++ b/odatajs/grunt-config/custom-tasks/toBrowser/wrapper-tpl.js
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+var init = function(exports, module, require) {
+ '<% initFunction %>'
+};
+
+var datas = '<% filesAsFunctionList %>';
+
+var modules = {};
+
+var require = function(path) {
+ var name = path.substring(path.lastIndexOf('/')+1,path.length-3);
+ if (modules[name]) { return modules[name].exports; }
+
+ modules[name] = { exports : {}};
+ console.log(name);
+ if (name === 'sou') {
+ var i = 0;
+ }
+ datas[name].call(this,modules[name].exports,modules[name],require);
+ return modules[name].exports;
+ };
+
+window.odatajs = {};
+init.call(this,window.odatajs,window.odatajs,require);
+
+
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/87e35975/odatajs/grunt-config/release.js
----------------------------------------------------------------------
diff --git a/odatajs/grunt-config/release.js b/odatajs/grunt-config/release.js
index 99edb19..f163ca0 100644
--- a/odatajs/grunt-config/release.js
+++ b/odatajs/grunt-config/release.js
@@ -166,34 +166,8 @@ module.exports = function(grunt) {
},
});
-
-
- /*
- //sign
- grunt.config.merge( {
- sign : {
- 'release-lib': { // just the lib
- options: {archive: './../dist/<%= artifactname %>/<%= artifactname %>-lib.zip'},
- files: [{expand: true, cwd: './../dist/<%= artifactname %>/lib', src: ['**'], dest: '/'}]
- },
- }
- });
-*/
grunt.loadNpmTasks('grunt-contrib-compress');
-
- //tasks
- grunt.registerTask('release',[
- 'npm-clean:release-dist',
- 'build',
- 'doc',
- 'copy:release-lib','copy:release-doc','copy:release-sources',
- 'rat:dist', // check the license headers
- 'compress:release-lib','compress:release-doc','compress:release-sources',
- ]);
- grunt.registerTask('release:sign',[
- 'sign:release','sign:asc','sign:asc-verify'
- ]);
-
+
};
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/87e35975/odatajs/grunt-config/sign.js
----------------------------------------------------------------------
diff --git a/odatajs/grunt-config/sign.js b/odatajs/grunt-config/sign.js
index 188d019..5a676ab 100644
--- a/odatajs/grunt-config/sign.js
+++ b/odatajs/grunt-config/sign.js
@@ -19,7 +19,6 @@
module.exports = function(grunt) {
-
//sign
grunt.config.merge( {
'sign' : {
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/87e35975/odatajs/package.json
----------------------------------------------------------------------
diff --git a/odatajs/package.json b/odatajs/package.json
index 8f1e577..ea387d9 100644
--- a/odatajs/package.json
+++ b/odatajs/package.json
@@ -7,7 +7,8 @@
"title": "Olingo OData Client for JavaScript",
"description": "the Olingo OData Client for JavaScript library is a new cross-browser JavaScript library that enables data-centric web applications by leveraging modern protocols such as JSON and OData and HTML5-enabled browser features. It's designed to be small, fast and easy to use.",
"homepage": "http://olingo.apache.org",
- "main": "index.js",
+ "main": "index-node.js",
+ "main-browser": "index.js",
"repository": {
"type": "git",
"url": "http://git-wip-us.apache.org/repos/asf/olingo-odata4-js.git"
@@ -31,7 +32,6 @@
],
"scripts": {},
"devDependencies": {
- "browserify": "^4.1.5",
"grunt": "^0.4.5",
"grunt-browserify": "^2.1.0",
"grunt-connect-proxy": "^0.1.10",
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/87e35975/odatajs/src/browser-lib-tpl.js
----------------------------------------------------------------------
diff --git a/odatajs/src/browser-lib-tpl.js b/odatajs/src/browser-lib-tpl.js
new file mode 100644
index 0000000..9c335db
--- /dev/null
+++ b/odatajs/src/browser-lib-tpl.js
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+var init = function(exports, module, require) {
+ '<% initFunction %>'
+};
+
+var datas = '<% filesAsFunctionList %>';
+
+var modules = {};
+
+var require = function(path) {
+ var name = path.substring(path.lastIndexOf('/')+1,path.length-3);
+ if (modules[name]) { return modules[name].exports; }
+
+ modules[name] = { exports : {}};
+ console.log(name);
+ if (name === 'sou') {
+ var i = 0;
+ }
+ datas[name].call(this,modules[name].exports,modules[name],require);
+ return modules[name].exports;
+ };
+
+window.odatajs = {};
+init.call(this,window.odatajs,window.odatajs,require);
+
+
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/87e35975/odatajs/src/index-browser.js
----------------------------------------------------------------------
diff --git a/odatajs/src/index-browser.js b/odatajs/src/index-browser.js
new file mode 100644
index 0000000..1f52e6b
--- /dev/null
+++ b/odatajs/src/index-browser.js
@@ -0,0 +1,36 @@
+/*1
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+// version information
+exports.version = { major: 4, minor: 0, build: 0 };
+
+// core stuff, always needed
+exports.deferred = require('./lib/deferred.js');
+exports.utils = require('./lib/utils.js');
+
+// only needed for xml metadata
+exports.xml = require('./lib/ext/xml.js');
+
+// only need in browser case
+exports.oData = require('./lib/odata.js');
+exports.store = require('./lib/store.js');
+exports.cache = require('./lib/cache.js');
+
+
+
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/87e35975/odatajs/src/index-node.js
----------------------------------------------------------------------
diff --git a/odatajs/src/index-node.js b/odatajs/src/index-node.js
new file mode 100644
index 0000000..28bf066
--- /dev/null
+++ b/odatajs/src/index-node.js
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+var odatajs = {};
+
+odatajs.version = {
+ major: 4,
+ minor: 0,
+ build: 0
+};
+
+// core stuff, alway needed
+odatajs.deferred = require('./lib/deferred.js');
+odatajs.utils = require('./lib/utils.js');
+
+// only neede for xml metadata
+odatajs.xml = require('./lib/ext/xml.js');
+
+// only need in browser case
+odatajs.oData = require('./lib/odata.js');
+odatajs.store = require('./lib/store.js');
+odatajs.cache = require('./lib/cache.js');
+
+if (typeof window !== 'undefined') {
+ //expose to browsers window object
+ window.odatajs = odatajs;
+} else {
+ //expose in commonjs style
+ odatajs.node = "node";
+ module.exports = odatajs;
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/87e35975/odatajs/src/index.js
----------------------------------------------------------------------
diff --git a/odatajs/src/index.js b/odatajs/src/index.js
index 42615d3..d939da2 100644
--- a/odatajs/src/index.js
+++ b/odatajs/src/index.js
@@ -17,18 +17,27 @@
* under the License.
*/
+//console.log('main starting');
+//var a = require('./a.js');
+//var b = require('./b.js');
+//console.log('in main, a.done=%j, b.done=%j', a.done, b.done);
+
var odatajs = {};
odatajs.version = {
- major: 1,
- minor: 1,
- build: 1
+ major: 4,
+ minor: 0,
+ build: 0
};
-odatajs.deferred = require('./lib/odatajs/deferred.js');
-odatajs.utils = require('./lib/odatajs/utils.js');
-odatajs.xml = require('./lib/odatajs/xml.js');
+// core stuff, alway needed
+odatajs.deferred = require('./lib/deferred.js');
+odatajs.utils = require('./lib/utils.js');
+
+// only neede for xml metadata
+odatajs.xml = require('./lib/ext/xml.js');
+// only need in browser case
odatajs.oData = require('./lib/odata.js');
odatajs.store = require('./lib/store.js');
odatajs.cache = require('./lib/cache.js');
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/87e35975/odatajs/src/lib/cache.js
----------------------------------------------------------------------
diff --git a/odatajs/src/lib/cache.js b/odatajs/src/lib/cache.js
index 92a740d..9912865 100644
--- a/odatajs/src/lib/cache.js
+++ b/odatajs/src/lib/cache.js
@@ -20,10 +20,10 @@
/** @module cache */
//var odatajs = require('./odatajs/utils.js');
-var utils = require('./odatajs/utils.js');
-var deferred = require('./odatajs/deferred.js');
+var utils = require('./utils.js');
+var deferred = require('./deferred.js');
var storeReq = require('./store.js');
-var cacheSource = require('./cache/source');
+var cacheSource = require('./cache/source.js');
var assigned = utils.assigned;
@@ -1447,4 +1447,7 @@ function createDataCache (options) {
exports.estimateSize = estimateSize;
/** createDataCache */
-exports.createDataCache = createDataCache;
\ No newline at end of file
+exports.createDataCache = createDataCache;
+
+
+
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/87e35975/odatajs/src/lib/cache/source.js
----------------------------------------------------------------------
diff --git a/odatajs/src/lib/cache/source.js b/odatajs/src/lib/cache/source.js
index eccf5d9..af878c6 100644
--- a/odatajs/src/lib/cache/source.js
+++ b/odatajs/src/lib/cache/source.js
@@ -19,7 +19,7 @@
/** @module cache/source */
-var utils = require("./../odatajs/utils.js");
+var utils = require("./../utils.js");
var odataRequest = require("./../odata.js");
var parseInt10 = utils.parseInt10;
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/87e35975/odatajs/src/lib/deferred.js
----------------------------------------------------------------------
diff --git a/odatajs/src/lib/deferred.js b/odatajs/src/lib/deferred.js
new file mode 100644
index 0000000..7d5fd68
--- /dev/null
+++ b/odatajs/src/lib/deferred.js
@@ -0,0 +1,189 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/** @module datajs/deferred */
+
+
+
+/** Creates a new function to forward a call.
+ * @param {Object} thisValue - Value to use as the 'this' object.
+ * @param {String} name - Name of function to forward to.
+ * @param {Object} returnValue - Return value for the forward call (helps keep identity when chaining calls).
+ * @returns {Function} A new function that will forward a call.
+ */
+function forwardCall(thisValue, name, returnValue) {
+ return function () {
+ thisValue[name].apply(thisValue, arguments);
+ return returnValue;
+ };
+}
+
+/** Initializes a new DjsDeferred object.
+ * <ul>
+ * <li> Compability Note A - Ordering of callbacks through chained 'then' invocations <br>
+ *
+ * The Wiki entry at http://wiki.commonjs.org/wiki/Promises/A
+ * implies that .then() returns a distinct object.
+ *
+ * For compatibility with http://api.jquery.com/category/deferred-object/
+ * we return this same object. This affects ordering, as
+ * the jQuery version will fire callbacks in registration
+ * order regardless of whether they occur on the result
+ * or the original object.
+ * </li>
+ * <li>Compability Note B - Fulfillment value <br>
+ *
+ * The Wiki entry at http://wiki.commonjs.org/wiki/Promises/A
+ * implies that the result of a success callback is the
+ * fulfillment value of the object and is received by
+ * other success callbacks that are chained.
+ *
+ * For compatibility with http://api.jquery.com/category/deferred-object/
+ * we disregard this value instead.
+ * </li></ul>
+ * @class DjsDeferred
+ */
+ function DjsDeferred() {
+ this._arguments = undefined;
+ this._done = undefined;
+ this._fail = undefined;
+ this._resolved = false;
+ this._rejected = false;
+}
+
+
+DjsDeferred.prototype = {
+
+ /** Adds success and error callbacks for this deferred object.
+ * See Compatibility Note A.
+ * @method DjsDeferred#then
+ * @param {function} [fulfilledHandler] - Success callback ( may be null)
+ * @param {function} [errorHandler] - Error callback ( may be null)
+ */
+ then: function (fulfilledHandler, errorHandler) {
+
+ if (fulfilledHandler) {
+ if (!this._done) {
+ this._done = [fulfilledHandler];
+ } else {
+ this._done.push(fulfilledHandler);
+ }
+ }
+
+ if (errorHandler) {
+ if (!this._fail) {
+ this._fail = [errorHandler];
+ } else {
+ this._fail.push(errorHandler);
+ }
+ }
+
+ //// See Compatibility Note A in the DjsDeferred constructor.
+ //// if (!this._next) {
+ //// this._next = createDeferred();
+ //// }
+ //// return this._next.promise();
+
+ if (this._resolved) {
+ this.resolve.apply(this, this._arguments);
+ } else if (this._rejected) {
+ this.reject.apply(this, this._arguments);
+ }
+
+ return this;
+ },
+
+ /** Invokes success callbacks for this deferred object.
+ * All arguments are forwarded to success callbacks.
+ * @method DjsDeferred#resolve
+ */
+ resolve: function (/* args */) {
+ if (this._done) {
+ var i, len;
+ for (i = 0, len = this._done.length; i < len; i++) {
+ //// See Compability Note B - Fulfillment value.
+ //// var nextValue =
+ this._done[i].apply(null, arguments);
+ }
+
+ //// See Compatibility Note A in the DjsDeferred constructor.
+ //// this._next.resolve(nextValue);
+ //// delete this._next;
+
+ this._done = undefined;
+ this._resolved = false;
+ this._arguments = undefined;
+ } else {
+ this._resolved = true;
+ this._arguments = arguments;
+ }
+ },
+
+ /** Invokes error callbacks for this deferred object.
+ * All arguments are forwarded to error callbacks.
+ * @method DjsDeferred#reject
+ */
+ reject: function (/* args */) {
+
+ if (this._fail) {
+ var i, len;
+ for (i = 0, len = this._fail.length; i < len; i++) {
+ this._fail[i].apply(null, arguments);
+ }
+
+ this._fail = undefined;
+ this._rejected = false;
+ this._arguments = undefined;
+ } else {
+ this._rejected = true;
+ this._arguments = arguments;
+ }
+ },
+
+ /** Returns a version of this object that has only the read-only methods available.
+ * @method DjsDeferred#promise
+ * @returns An object with only the promise object.
+ */
+
+ promise: function () {
+ var result = {};
+ result.then = forwardCall(this, "then", result);
+ return result;
+ }
+};
+
+/** Creates a deferred object.
+ * @returns {DjsDeferred} A new deferred object. If jQuery is installed, then a jQueryDeferred object is returned, which provides a superset of features.
+*/
+function createDeferred() {
+ if (window.jQuery && window.jQuery.Deferred) {
+ return new window.jQuery.Deferred();
+ } else {
+ return new DjsDeferred();
+ }
+};
+
+
+
+
+/** createDeferred (see {@link module:datajs/deferred~createDeferred}) */
+exports.createDeferred = createDeferred;
+
+/** DjsDeferred (see {@link DjsDeferred}) */
+exports.DjsDeferred = DjsDeferred;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/87e35975/odatajs/src/lib/odata.js
----------------------------------------------------------------------
diff --git a/odatajs/src/lib/odata.js b/odatajs/src/lib/odata.js
index 8999bb2..7ea728b 100644
--- a/odatajs/src/lib/odata.js
+++ b/odatajs/src/lib/odata.js
@@ -20,7 +20,7 @@
/** @module odata */
// Imports
-var odataUtils = exports.utils = require('./odata/utils.js');
+var odataUtils = exports.utils = require('./odata/odatautils.js');
var odataHandler = exports.handler = require('./odata/handler.js');
var odataMetadata = exports.metadata = require('./odata/metadata.js');
var odataNet = exports.net = require('./odata/net.js');
@@ -29,7 +29,7 @@ var odataJson = exports.json = require('./odata/json.js');
-var utils = require('./odatajs/utils.js');
+var utils = require('./utils.js');
var assigned = utils.assigned;
var defined = utils.defined;
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/87e35975/odatajs/src/lib/odata/batch.js
----------------------------------------------------------------------
diff --git a/odatajs/src/lib/odata/batch.js b/odatajs/src/lib/odata/batch.js
index 59fb1f8..c71fc31 100644
--- a/odatajs/src/lib/odata/batch.js
+++ b/odatajs/src/lib/odata/batch.js
@@ -19,8 +19,8 @@
/** @module odata/batch */
-var utils = require('./../odatajs/utils.js');
-var odataUtils = require('./utils.js');
+var utils = require('./../utils.js');
+var odataUtils = require('./odatautils.js');
var odataHandler = require('./handler.js');
var extend = utils.extend;
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/87e35975/odatajs/src/lib/odata/handler.js
----------------------------------------------------------------------
diff --git a/odatajs/src/lib/odata/handler.js b/odatajs/src/lib/odata/handler.js
index d2b62d4..cbd09c6 100644
--- a/odatajs/src/lib/odata/handler.js
+++ b/odatajs/src/lib/odata/handler.js
@@ -20,8 +20,8 @@
/** @module odata/handler */
-var utils = require('./../odatajs/utils.js');
-var oDataUtils = require('./utils.js');
+var utils = require('./../utils.js');
+var oDataUtils = require('./odatautils.js');
// Imports.
var assigned = utils.assigned;
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/87e35975/odatajs/src/lib/odata/json.js
----------------------------------------------------------------------
diff --git a/odatajs/src/lib/odata/json.js b/odatajs/src/lib/odata/json.js
index d003e2b..6955cbe 100644
--- a/odatajs/src/lib/odata/json.js
+++ b/odatajs/src/lib/odata/json.js
@@ -21,8 +21,8 @@
-var utils = require('./../odatajs/utils.js');
-var oDataUtils = require('./utils.js');
+var utils = require('./../utils.js');
+var oDataUtils = require('./odatautils.js');
var oDataHandler = require('./handler.js');
var odataNs = "odata";
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/87e35975/odatajs/src/lib/odata/metadata.js
----------------------------------------------------------------------
diff --git a/odatajs/src/lib/odata/metadata.js b/odatajs/src/lib/odata/metadata.js
index fb34286..e37161f 100644
--- a/odatajs/src/lib/odata/metadata.js
+++ b/odatajs/src/lib/odata/metadata.js
@@ -19,8 +19,8 @@
/** @module odata/metadata */
-var utils = require('./../odatajs/utils.js');
-var oDSxml = require('./../odatajs/xml.js');
+var utils = require('./../utils.js');
+var oDSxml = require('./../xml.js');
var odataHandler = require('./handler.js');
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/87e35975/odatajs/src/lib/odata/net.js
----------------------------------------------------------------------
diff --git a/odatajs/src/lib/odata/net.js b/odatajs/src/lib/odata/net.js
index 0dbbce0..6e0f6c8 100644
--- a/odatajs/src/lib/odata/net.js
+++ b/odatajs/src/lib/odata/net.js
@@ -21,7 +21,7 @@
-var utils = require('./../odatajs/utils.js');
+var utils = require('./../utils.js');
// Imports.
var defined = utils.defined;
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/87e35975/odatajs/src/lib/odata/odatautils.js
----------------------------------------------------------------------
diff --git a/odatajs/src/lib/odata/odatautils.js b/odatajs/src/lib/odata/odatautils.js
new file mode 100644
index 0000000..a44fa05
--- /dev/null
+++ b/odatajs/src/lib/odata/odatautils.js
@@ -0,0 +1,1265 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+ /** @module odata/utils */
+
+var utils = require('./../utils.js');
+
+// Imports
+var assigned = utils.assigned;
+var contains = utils.contains;
+var find = utils.find;
+var isArray = utils.isArray;
+var isDate = utils.isDate;
+var isObject = utils.isObject;
+var parseInt10 = utils.parseInt10;
+
+
+/** Gets the type name of a data item value that belongs to a feed, an entry, a complex type property, or a collection property
+ * @param {string} value - Value of the data item from which the type name is going to be retrieved.
+ * @param {object} [metadata] - Object containing metadata about the data tiem.
+ * @returns {string} Data item type name; null if the type name cannot be found within the value or the metadata
+ * This function will first try to get the type name from the data item's value itself if it is an object with a __metadata property; otherwise
+ * it will try to recover it from the metadata. If both attempts fail, it will return null.
+ */
+var dataItemTypeName = function (value, metadata) {
+ var valueTypeName = ((value && value.__metadata) || {}).type;
+ return valueTypeName || (metadata ? metadata.type : null);
+};
+
+var EDM = "Edm.";
+var EDM_BOOLEAN = EDM + "Boolean";
+var EDM_BYTE = EDM + "Byte";
+var EDM_SBYTE = EDM + "SByte";
+var EDM_INT16 = EDM + "Int16";
+var EDM_INT32 = EDM + "Int32";
+var EDM_INT64 = EDM + "Int64";
+var EDM_SINGLE = EDM + "Single";
+var EDM_DOUBLE = EDM + "Double";
+var EDM_DECIMAL = EDM + "Decimal";
+var EDM_STRING = EDM + "String";
+
+var EDM_BINARY = EDM + "Binary";
+var EDM_DATE = EDM + "Date";
+var EDM_DATETIMEOFFSET = EDM + "DateTimeOffset";
+var EDM_DURATION = EDM + "Duration";
+var EDM_GUID = EDM + "Guid";
+var EDM_TIMEOFDAY = EDM + "Time";
+
+var GEOGRAPHY = "Geography";
+var EDM_GEOGRAPHY = EDM + GEOGRAPHY;
+var EDM_GEOGRAPHY_POINT = EDM_GEOGRAPHY + "Point";
+var EDM_GEOGRAPHY_LINESTRING = EDM_GEOGRAPHY + "LineString";
+var EDM_GEOGRAPHY_POLYGON = EDM_GEOGRAPHY + "Polygon";
+var EDM_GEOGRAPHY_COLLECTION = EDM_GEOGRAPHY + "Collection";
+var EDM_GEOGRAPHY_MULTIPOLYGON = EDM_GEOGRAPHY + "MultiPolygon";
+var EDM_GEOGRAPHY_MULTILINESTRING = EDM_GEOGRAPHY + "MultiLineString";
+var EDM_GEOGRAPHY_MULTIPOINT = EDM_GEOGRAPHY + "MultiPoint";
+
+var GEOGRAPHY_POINT = GEOGRAPHY + "Point";
+var GEOGRAPHY_LINESTRING = GEOGRAPHY + "LineString";
+var GEOGRAPHY_POLYGON = GEOGRAPHY + "Polygon";
+var GEOGRAPHY_COLLECTION = GEOGRAPHY + "Collection";
+var GEOGRAPHY_MULTIPOLYGON = GEOGRAPHY + "MultiPolygon";
+var GEOGRAPHY_MULTILINESTRING = GEOGRAPHY + "MultiLineString";
+var GEOGRAPHY_MULTIPOINT = GEOGRAPHY + "MultiPoint";
+
+var GEOMETRY = "Geometry";
+var EDM_GEOMETRY = EDM + GEOMETRY;
+var EDM_GEOMETRY_POINT = EDM_GEOMETRY + "Point";
+var EDM_GEOMETRY_LINESTRING = EDM_GEOMETRY + "LineString";
+var EDM_GEOMETRY_POLYGON = EDM_GEOMETRY + "Polygon";
+var EDM_GEOMETRY_COLLECTION = EDM_GEOMETRY + "Collection";
+var EDM_GEOMETRY_MULTIPOLYGON = EDM_GEOMETRY + "MultiPolygon";
+var EDM_GEOMETRY_MULTILINESTRING = EDM_GEOMETRY + "MultiLineString";
+var EDM_GEOMETRY_MULTIPOINT = EDM_GEOMETRY + "MultiPoint";
+
+var GEOMETRY_POINT = GEOMETRY + "Point";
+var GEOMETRY_LINESTRING = GEOMETRY + "LineString";
+var GEOMETRY_POLYGON = GEOMETRY + "Polygon";
+var GEOMETRY_COLLECTION = GEOMETRY + "Collection";
+var GEOMETRY_MULTIPOLYGON = GEOMETRY + "MultiPolygon";
+var GEOMETRY_MULTILINESTRING = GEOMETRY + "MultiLineString";
+var GEOMETRY_MULTIPOINT = GEOMETRY + "MultiPoint";
+
+var GEOJSON_POINT = "Point";
+var GEOJSON_LINESTRING = "LineString";
+var GEOJSON_POLYGON = "Polygon";
+var GEOJSON_MULTIPOINT = "MultiPoint";
+var GEOJSON_MULTILINESTRING = "MultiLineString";
+var GEOJSON_MULTIPOLYGON = "MultiPolygon";
+var GEOJSON_GEOMETRYCOLLECTION = "GeometryCollection";
+
+var primitiveEdmTypes = [
+ EDM_STRING,
+ EDM_INT32,
+ EDM_INT64,
+ EDM_BOOLEAN,
+ EDM_DOUBLE,
+ EDM_SINGLE,
+ EDM_DATE,
+ EDM_DATETIMEOFFSET,
+ EDM_DURATION,
+ EDM_TIMEOFDAY,
+ EDM_DECIMAL,
+ EDM_GUID,
+ EDM_BYTE,
+ EDM_INT16,
+ EDM_SBYTE,
+ EDM_BINARY
+];
+
+var geometryEdmTypes = [
+ EDM_GEOMETRY,
+ EDM_GEOMETRY_POINT,
+ EDM_GEOMETRY_LINESTRING,
+ EDM_GEOMETRY_POLYGON,
+ EDM_GEOMETRY_COLLECTION,
+ EDM_GEOMETRY_MULTIPOLYGON,
+ EDM_GEOMETRY_MULTILINESTRING,
+ EDM_GEOMETRY_MULTIPOINT
+];
+
+var geometryTypes = [
+ GEOMETRY,
+ GEOMETRY_POINT,
+ GEOMETRY_LINESTRING,
+ GEOMETRY_POLYGON,
+ GEOMETRY_COLLECTION,
+ GEOMETRY_MULTIPOLYGON,
+ GEOMETRY_MULTILINESTRING,
+ GEOMETRY_MULTIPOINT
+];
+
+var geographyEdmTypes = [
+ EDM_GEOGRAPHY,
+ EDM_GEOGRAPHY_POINT,
+ EDM_GEOGRAPHY_LINESTRING,
+ EDM_GEOGRAPHY_POLYGON,
+ EDM_GEOGRAPHY_COLLECTION,
+ EDM_GEOGRAPHY_MULTIPOLYGON,
+ EDM_GEOGRAPHY_MULTILINESTRING,
+ EDM_GEOGRAPHY_MULTIPOINT
+];
+
+var geographyTypes = [
+ GEOGRAPHY,
+ GEOGRAPHY_POINT,
+ GEOGRAPHY_LINESTRING,
+ GEOGRAPHY_POLYGON,
+ GEOGRAPHY_COLLECTION,
+ GEOGRAPHY_MULTIPOLYGON,
+ GEOGRAPHY_MULTILINESTRING,
+ GEOGRAPHY_MULTIPOINT
+];
+
+/** Invokes a function once per schema in metadata.
+ * @param metadata - Metadata store; one of edmx, schema, or an array of any of them.
+ * @param {Function} callback - Callback function to invoke once per schema.
+ * @returns The first truthy value to be returned from the callback; null or the last falsy value otherwise.
+ */
+function forEachSchema(metadata, callback) {
+
+
+ if (!metadata) {
+ return null;
+ }
+
+ if (isArray(metadata)) {
+ var i, len, result;
+ for (i = 0, len = metadata.length; i < len; i++) {
+ result = forEachSchema(metadata[i], callback);
+ if (result) {
+ return result;
+ }
+ }
+
+ return null;
+ } else {
+ if (metadata.dataServices) {
+ return forEachSchema(metadata.dataServices.schema, callback);
+ }
+
+ return callback(metadata);
+ }
+}
+
+/** Formats a millisecond and a nanosecond value into a single string.
+ * @param {Numaber} ms - Number of milliseconds to format.</param>
+ * @param {Numaber} ns - Number of nanoseconds to format.</param>
+ * @returns {String} Formatted text.
+ * If the value is already as string it's returned as-is.</remarks>
+ */
+function formatMilliseconds(ms, ns) {
+
+ // Avoid generating milliseconds if not necessary.
+ if (ms === 0) {
+ ms = "";
+ } else {
+ ms = "." + formatNumberWidth(ms.toString(), 3);
+ }
+ if (ns > 0) {
+ if (ms === "") {
+ ms = ".000";
+ }
+ ms += formatNumberWidth(ns.toString(), 4);
+ }
+ return ms;
+}
+
+function formatDateTimeOffsetJSON(value) {
+ return "\/Date(" + value.getTime() + ")\/";
+}
+
+/** Formats a DateTime or DateTimeOffset value a string.
+ * @param {Date} value - Value to format
+ * @returns {String} Formatted text.
+ * If the value is already as string it's returned as-is
+´*/
+function formatDateTimeOffset(value) {
+
+ if (typeof value === "string") {
+ return value;
+ }
+
+ var hasOffset = isDateTimeOffset(value);
+ var offset = getCanonicalTimezone(value.__offset);
+ if (hasOffset && offset !== "Z") {
+ // We're about to change the value, so make a copy.
+ value = new Date(value.valueOf());
+
+ var timezone = parseTimezone(offset);
+ var hours = value.getUTCHours() + (timezone.d * timezone.h);
+ var minutes = value.getUTCMinutes() + (timezone.d * timezone.m);
+
+ value.setUTCHours(hours, minutes);
+ } else if (!hasOffset) {
+ // Don't suffix a 'Z' for Edm.DateTime values.
+ offset = "";
+ }
+
+ var year = value.getUTCFullYear();
+ var month = value.getUTCMonth() + 1;
+ var sign = "";
+ if (year <= 0) {
+ year = -(year - 1);
+ sign = "-";
+ }
+
+ var ms = formatMilliseconds(value.getUTCMilliseconds(), value.__ns);
+
+ return sign +
+ formatNumberWidth(year, 4) + "-" +
+ formatNumberWidth(month, 2) + "-" +
+ formatNumberWidth(value.getUTCDate(), 2) + "T" +
+ formatNumberWidth(value.getUTCHours(), 2) + ":" +
+ formatNumberWidth(value.getUTCMinutes(), 2) + ":" +
+ formatNumberWidth(value.getUTCSeconds(), 2) +
+ ms + offset;
+}
+
+/** Converts a duration to a string in xsd:duration format.
+ * @param {Object} value - Object with ms and __edmType properties.
+ * @returns {String} String representation of the time object in xsd:duration format.
+ */
+function formatDuration(value) {
+
+ var ms = value.ms;
+
+ var sign = "";
+ if (ms < 0) {
+ sign = "-";
+ ms = -ms;
+ }
+
+ var days = Math.floor(ms / 86400000);
+ ms -= 86400000 * days;
+ var hours = Math.floor(ms / 3600000);
+ ms -= 3600000 * hours;
+ var minutes = Math.floor(ms / 60000);
+ ms -= 60000 * minutes;
+ var seconds = Math.floor(ms / 1000);
+ ms -= seconds * 1000;
+
+ return sign + "P" +
+ formatNumberWidth(days, 2) + "DT" +
+ formatNumberWidth(hours, 2) + "H" +
+ formatNumberWidth(minutes, 2) + "M" +
+ formatNumberWidth(seconds, 2) +
+ formatMilliseconds(ms, value.ns) + "S";
+}
+
+/** Formats the specified value to the given width.
+ * @param {Number} value - Number to format (non-negative).
+ * @param {Number} width - Minimum width for number.
+ * @param {Boolean} append - Flag indicating if the value is padded at the beginning (false) or at the end (true).
+ * @returns {String} Text representation.
+ */
+function formatNumberWidth(value, width, append) {
+ var result = value.toString(10);
+ while (result.length < width) {
+ if (append) {
+ result += "0";
+ } else {
+ result = "0" + result;
+ }
+ }
+
+ return result;
+}
+
+/** Gets the canonical timezone representation.
+ * @param {String} timezone - Timezone representation.
+ * @returns {String} An 'Z' string if the timezone is absent or 0; the timezone otherwise.
+ */
+function getCanonicalTimezone(timezone) {
+
+ return (!timezone || timezone === "Z" || timezone === "+00:00" || timezone === "-00:00") ? "Z" : timezone;
+}
+
+/** Gets the type of a collection type name.
+ * @param {String} typeName - Type name of the collection.
+ * @returns {String} Type of the collection; null if the type name is not a collection type.
+ */
+function getCollectionType(typeName) {
+
+ if (typeof typeName === "string") {
+ var end = typeName.indexOf(")", 10);
+ if (typeName.indexOf("Collection(") === 0 && end > 0) {
+ return typeName.substring(11, end);
+ }
+ }
+ return null;
+}
+
+/** Sends a request containing OData payload to a server.
+* @param request - Object that represents the request to be sent..
+* @param success - Callback for a successful read operation.
+* @param error - Callback for handling errors.
+* @param handler - Handler for data serialization.
+* @param httpClient - HTTP client layer.
+* @param context - Context used for processing the request
+*/
+function invokeRequest(request, success, error, handler, httpClient, context) {
+
+ return httpClient.request(request, function (response) {
+ try {
+ if (response.headers) {
+ normalizeHeaders(response.headers);
+ }
+
+ if (response.data === undefined && response.statusCode !== 204) {
+ handler.read(response, context);
+ }
+ } catch (err) {
+ if (err.request === undefined) {
+ err.request = request;
+ }
+ if (err.response === undefined) {
+ err.response = response;
+ }
+ error(err);
+ return;
+ }
+ // errors in success handler for sync requests result in error handler calls. So here we fix this.
+ try {
+ success(response.data, response);
+ } catch (err) {
+ err.bIsSuccessHandlerError = true;
+ throw err;
+ }
+ }, error);
+}
+
+/** Tests whether a value is a batch object in the library's internal representation.
+ * @param value - Value to test.
+ * @returns {Boolean} True is the value is a batch object; false otherwise.
+ */
+function isBatch(value) {
+
+ return isComplex(value) && isArray(value.__batchRequests);
+}
+
+// Regular expression used for testing and parsing for a collection type.
+var collectionTypeRE = /Collection\((.*)\)/;
+
+/** Tests whether a value is a collection value in the library's internal representation.
+ * @param value - Value to test.
+ * @param {Sting} typeName - Type name of the value. This is used to disambiguate from a collection property value.
+ * @returns {Boolean} True is the value is a feed value; false otherwise.
+ */
+function isCollection(value, typeName) {
+
+ var colData = value && value.results || value;
+ return !!colData &&
+ (isCollectionType(typeName)) ||
+ (!typeName && isArray(colData) && !isComplex(colData[0]));
+}
+
+/** Checks whether the specified type name is a collection type.
+ * @param {String} typeName - Name of type to check.
+ * @returns {Boolean} True if the type is the name of a collection type; false otherwise.
+ */
+function isCollectionType(typeName) {
+ return collectionTypeRE.test(typeName);
+}
+
+/** Tests whether a value is a complex type value in the library's internal representation.
+ * @param value - Value to test.
+ * @returns {Boolean} True is the value is a complex type value; false otherwise.
+ */
+function isComplex(value) {
+
+ return !!value &&
+ isObject(value) &&
+ !isArray(value) &&
+ !isDate(value);
+}
+
+/** Checks whether a Date object is DateTimeOffset value
+ * @param {Date} value - Value to check
+ * @returns {Boolean} true if the value is a DateTimeOffset, false otherwise.
+ */
+function isDateTimeOffset(value) {
+ return (value.__edmType === "Edm.DateTimeOffset" || (!value.__edmType && value.__offset));
+}
+
+/** Tests whether a value is a deferred navigation property in the library's internal representation.
+ * @param value - Value to test.
+ * @returns {Boolean} True is the value is a deferred navigation property; false otherwise.
+ */
+function isDeferred(value) {
+
+ if (!value && !isComplex(value)) {
+ return false;
+ }
+ var metadata = value.__metadata || {};
+ var deferred = value.__deferred || {};
+ return !metadata.type && !!deferred.uri;
+}
+
+/** Tests whether a value is an entry object in the library's internal representation.
+ * @param value - Value to test.
+ * @returns {Boolean} True is the value is an entry object; false otherwise.
+ */
+function isEntry(value) {
+
+ return isComplex(value) && value.__metadata && "uri" in value.__metadata;
+}
+
+/** Tests whether a value is a feed value in the library's internal representation.
+ * @param value - Value to test.
+ * @param {Sting} typeName - Type name of the value. This is used to disambiguate from a collection property value.
+ * @returns {Boolean} True is the value is a feed value; false otherwise.
+ */
+function isFeed(value, typeName) {
+
+ var feedData = value && value.results || value;
+ return isArray(feedData) && (
+ (!isCollectionType(typeName)) &&
+ (isComplex(feedData[0]))
+ );
+}
+
+/** Checks whether the specified type name is a geography EDM type.
+ * @param {String} typeName - Name of type to check.
+ * @returns {Boolean} True if the type is a geography EDM type; false otherwise.
+ */
+function isGeographyEdmType(typeName) {
+
+ //check with edm
+ var ret = contains(geographyEdmTypes, typeName) ||
+ (typeName.indexOf('.') === -1 && contains(geographyTypes, typeName));
+ return ret;
+
+}
+
+/** Checks whether the specified type name is a geometry EDM type.
+ * @param {String} typeName - Name of type to check.
+ * @returns {Boolean} True if the type is a geometry EDM type; false otherwise.
+ */
+function isGeometryEdmType(typeName) {
+
+ var ret = contains(geometryEdmTypes, typeName) ||
+ (typeName.indexOf('.') === -1 && contains(geometryTypes, typeName));
+ return ret;
+}
+
+/** Tests whether a value is a named stream value in the library's internal representation.
+ * @param value - Value to test.
+ * @returns {Boolean} True is the value is a named stream; false otherwise.
+ */
+function isNamedStream(value) {
+
+ if (!value && !isComplex(value)) {
+ return false;
+ }
+ var metadata = value.__metadata;
+ var mediaResource = value.__mediaresource;
+ return !metadata && !!mediaResource && !!mediaResource.media_src;
+}
+
+/** Tests whether a value is a primitive type value in the library's internal representation.
+ * @param value - Value to test.
+ * @returns {Boolean} True is the value is a primitive type value.
+ * Date objects are considered primitive types by the library.
+ */
+function isPrimitive(value) {
+
+ return isDate(value) ||
+ typeof value === "string" ||
+ typeof value === "number" ||
+ typeof value === "boolean";
+}
+
+/** Checks whether the specified type name is a primitive EDM type.
+ * @param {String} typeName - Name of type to check.
+ * @returns {Boolean} True if the type is a primitive EDM type; false otherwise.
+ */
+function isPrimitiveEdmType(typeName) {
+
+ return contains(primitiveEdmTypes, typeName);
+}
+
+/** Gets the kind of a navigation property value.
+ * @param value - Value of the navigation property.
+ * @param {Object} [propertyModel] - Object that describes the navigation property in an OData conceptual schema.
+ * @returns {String} String value describing the kind of the navigation property; null if the kind cannot be determined.
+ */
+function navigationPropertyKind(value, propertyModel) {
+
+ if (isDeferred(value)) {
+ return "deferred";
+ }
+ if (isEntry(value)) {
+ return "entry";
+ }
+ if (isFeed(value)) {
+ return "feed";
+ }
+ if (propertyModel && propertyModel.relationship) {
+ if (value === null || value === undefined || !isFeed(value)) {
+ return "entry";
+ }
+ return "feed";
+ }
+ return null;
+}
+
+/** Looks up a property by name.
+ * @param {Array} properties - Array of property objects as per EDM metadata (may be null)
+ * @param {String} name - Name to look for.
+ * @returns {Object} The property object; null if not found.
+ */
+function lookupProperty(properties, name) {
+
+ return find(properties, function (property) {
+ return property.name === name;
+ });
+}
+
+/** Looks up a type object by name.
+ * @param {String} name - Name, possibly null or empty.
+ * @param metadata - Metadata store; one of edmx, schema, or an array of any of them.
+ * @param {String} kind - Kind of object to look for as per EDM metadata.
+ * @returns An type description if the name is found; null otherwise
+ */
+function lookupInMetadata(name, metadata, kind) {
+
+ return (name) ? forEachSchema(metadata, function (schema) {
+ return lookupInSchema(name, schema, kind);
+ }) : null;
+}
+
+/** Looks up a entity set by name.
+ * @param {Array} properties - Array of entity set objects as per EDM metadata( may be null)
+ * @param {String} name - Name to look for.
+ * @returns {Object} The entity set object; null if not found.
+ */
+function lookupEntitySet(entitySets, name) {
+
+ return find(entitySets, function (entitySet) {
+ return entitySet.name === name;
+ });
+}
+
+/** Looks up a entity set by name.
+ * @param {Array} properties - Array of entity set objects as per EDM metadata (may be null)
+ * @param {String} name - Name to look for.
+ * @returns {Object} The entity set object; null if not found.
+ */
+function lookupSingleton(singletons, name) {
+
+ return find(singletons, function (singleton) {
+ return singleton.name === name;
+ });
+}
+
+/** Looks up a complex type object by name.
+ * @param {String} name - Name, possibly null or empty.
+ * @param metadata - Metadata store; one of edmx, schema, or an array of any of them.
+ * @returns A complex type description if the name is found; null otherwise.</returns>
+ */
+function lookupComplexType(name, metadata) {
+
+ return lookupInMetadata(name, metadata, "complexType");
+}
+
+/** Looks up an entity type object by name.
+ * @param {String} name - Name, possibly null or empty.
+ * @param metadata - Metadata store; one of edmx, schema, or an array of any of them.
+ * @returns An entity type description if the name is found; null otherwise.</returns>
+ */
+function lookupEntityType(name, metadata) {
+
+ return lookupInMetadata(name, metadata, "entityType");
+}
+
+
+/** Looks up an
+ * @param {String} name - Name, possibly null or empty.
+ * @param metadata - Metadata store; one of edmx, schema, or an array of any of them.
+ * @returns An entity container description if the name is found; null otherwise.</returns>
+ */
+function lookupDefaultEntityContainer(metadata) {
+
+ return forEachSchema(metadata, function (schema) {
+ if (isObject(schema.entityContainer)) {
+ return schema.entityContainer;
+ }
+ });
+}
+
+/** Looks up an entity container object by name.
+ * @param {String} name - Name, possibly null or empty.
+ * @param metadata - Metadata store; one of edmx, schema, or an array of any of them.
+ * @returns An entity container description if the name is found; null otherwise.</returns>
+ */
+function lookupEntityContainer(name, metadata) {
+
+ return lookupInMetadata(name, metadata, "entityContainer");
+}
+
+/** Looks up a function import by name.
+ * @param {Array} properties - Array of function import objects as per EDM metadata (May be null)
+ * @param {String} name - Name to look for.
+ * @returns {Object} The entity set object; null if not found.
+ */
+function lookupFunctionImport(functionImports, name) {
+ return find(functionImports, function (functionImport) {
+ return functionImport.name === name;
+ });
+}
+
+/** Looks up the target entity type for a navigation property.
+ * @param {Object} navigationProperty -
+ * @param {Object} metadata -
+ * @returns {String} The entity type name for the specified property, null if not found.
+ */
+function lookupNavigationPropertyType(navigationProperty, metadata) {
+
+ var result = null;
+ if (navigationProperty) {
+ var rel = navigationProperty.relationship;
+ var association = forEachSchema(metadata, function (schema) {
+ // The name should be the namespace qualified name in 'ns'.'type' format.
+ var nameOnly = removeNamespace(schema.namespace, rel);
+ var associations = schema.association;
+ if (nameOnly && associations) {
+ var i, len;
+ for (i = 0, len = associations.length; i < len; i++) {
+ if (associations[i].name === nameOnly) {
+ return associations[i];
+ }
+ }
+ }
+ return null;
+ });
+
+ if (association) {
+ var end = association.end[0];
+ if (end.role !== navigationProperty.toRole) {
+ end = association.end[1];
+ // For metadata to be valid, end.role === navigationProperty.toRole now.
+ }
+ result = end.type;
+ }
+ }
+ return result;
+}
+
+/** Looks up the target entityset name for a navigation property.
+ * @param {Object} navigationProperty -
+ * @param {Object} metadata -
+ * @returns {String} The entityset name for the specified property, null if not found.
+ */
+function lookupNavigationPropertyEntitySet(navigationProperty, sourceEntitySetName, metadata) {
+
+ if (navigationProperty) {
+ var rel = navigationProperty.relationship;
+ var associationSet = forEachSchema(metadata, function (schema) {
+ var containers = schema.entityContainer;
+ for (var i = 0; i < containers.length; i++) {
+ var associationSets = containers[i].associationSet;
+ if (associationSets) {
+ for (var j = 0; j < associationSets.length; j++) {
+ if (associationSets[j].association == rel) {
+ return associationSets[j];
+ }
+ }
+ }
+ }
+ return null;
+ });
+ if (associationSet && associationSet.end[0] && associationSet.end[1]) {
+ return (associationSet.end[0].entitySet == sourceEntitySetName) ? associationSet.end[1].entitySet : associationSet.end[0].entitySet;
+ }
+ }
+ return null;
+}
+
+/** Gets the entitySet info, container name and functionImports for an entitySet
+ * @param {Object} navigationProperty -
+ * @param {Object} metadata -
+ * @returns {Object} The info about the entitySet.
+ */
+function getEntitySetInfo(entitySetName, metadata) {
+
+ var info = forEachSchema(metadata, function (schema) {
+ var container = schema.entityContainer;
+ var entitySets = container.entitySet;
+ if (entitySets) {
+ for (var j = 0; j < entitySets.length; j++) {
+ if (entitySets[j].name == entitySetName) {
+ return { entitySet: entitySets[j], containerName: container.name, functionImport: container.functionImport };
+ }
+ }
+ }
+ return null;
+ });
+
+ return info;
+}
+
+/** Given an expected namespace prefix, removes it from a full name.
+ * @param {String} ns - Expected namespace.
+ * @param {String} fullName - Full name in 'ns'.'name' form.
+ * @returns {String} The local name, null if it isn't found in the expected namespace.
+ */
+function removeNamespace(ns, fullName) {
+
+ if (fullName.indexOf(ns) === 0 && fullName.charAt(ns.length) === ".") {
+ return fullName.substr(ns.length + 1);
+ }
+
+ return null;
+}
+
+/** Looks up a schema object by name.
+ * @param {String} name - Name (assigned).
+ * @param schema - Schema object as per EDM metadata.
+ * @param {String} kind - Kind of object to look for as per EDM metadata.
+ * @returns An entity type description if the name is found; null otherwise.</returns>
+ */
+function lookupInSchema(name, schema, kind) {
+
+ if (name && schema) {
+ // The name should be the namespace qualified name in 'ns'.'type' format.
+ var nameOnly = removeNamespace(schema.namespace, name);
+ if (nameOnly) {
+ return find(schema[kind], function (item) {
+ return item.name === nameOnly;
+ });
+ }
+ }
+ return null;
+}
+
+/** Compares to version strings and returns the higher one.
+ * @param {String} left - Version string in the form "major.minor.rev"
+ * @param {String} right - Version string in the form "major.minor.rev"
+ * @returns {String} The higher version string.
+ */
+function maxVersion(left, right) {
+
+ if (left === right) {
+ return left;
+ }
+
+ var leftParts = left.split(".");
+ var rightParts = right.split(".");
+
+ var len = (leftParts.length >= rightParts.length) ?
+ leftParts.length :
+ rightParts.length;
+
+ for (var i = 0; i < len; i++) {
+ var leftVersion = leftParts[i] && parseInt10(leftParts[i]);
+ var rightVersion = rightParts[i] && parseInt10(rightParts[i]);
+ if (leftVersion > rightVersion) {
+ return left;
+ }
+ if (leftVersion < rightVersion) {
+ return right;
+ }
+ }
+}
+
+var normalHeaders = {
+ // Headers shared by request and response
+ "content-type": "Content-Type",
+ "content-encoding": "Content-Encoding",
+ "content-length": "Content-Length",
+ "odata-version": "OData-Version",
+
+ // Headers used by request
+ "accept": "Accept",
+ "accept-charset": "Accept-Charset",
+ "if-match": "If-Match",
+ "if-none-match": "If-None-Match",
+ "odata-isolation": "OData-Isolation",
+ "odata-maxversion": "OData-MaxVersion",
+ "prefer": "Prefer",
+ "content-id": "Content-ID",
+ "content-transfer-encoding": "Content-Transfer-Encoding",
+
+ // Headers used by response
+ "etag": "ETag",
+ "location": "Location",
+ "odata-entityid": "OData-EntityId",
+ "preference-applied": "Preference-Applied",
+ "retry-after": "Retry-After"
+};
+
+/** Normalizes headers so they can be found with consistent casing.
+ * @param {Object} headers - Dictionary of name/value pairs.
+ */
+function normalizeHeaders(headers) {
+
+ for (var name in headers) {
+ var lowerName = name.toLowerCase();
+ var normalName = normalHeaders[lowerName];
+ if (normalName && name !== normalName) {
+ var val = headers[name];
+ delete headers[name];
+ headers[normalName] = val;
+ }
+ }
+}
+
+/** Parses a string into a boolean value.
+ * @param propertyValue - Value to parse.
+ * @returns {Boolean} true if the property value is 'true'; false otherwise.
+ */
+function parseBool(propertyValue) {
+
+ if (typeof propertyValue === "boolean") {
+ return propertyValue;
+ }
+
+ return typeof propertyValue === "string" && propertyValue.toLowerCase() === "true";
+}
+
+
+// The captured indices for this expression are:
+// 0 - complete input
+// 1,2,3 - year with optional minus sign, month, day
+// 4,5,6 - hours, minutes, seconds
+// 7 - optional milliseconds
+// 8 - everything else (presumably offset information)
+var parseDateTimeRE = /^(-?\d{4,})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2}))?(?:\.(\d+))?(.*)$/;
+
+/** Parses a string into a DateTime value.
+ * @param {String} value - Value to parse.
+ * @param {Boolean} withOffset - Whether offset is expected.
+ * @returns {Date} The parsed value.
+ */
+function parseDateTimeMaybeOffset(value, withOffset, nullOnError) {
+
+ // We cannot parse this in cases of failure to match or if offset information is specified.
+ var parts = parseDateTimeRE.exec(value);
+ var offset = (parts) ? getCanonicalTimezone(parts[8]) : null;
+
+ if (!parts || (!withOffset && offset !== "Z")) {
+ if (nullOnError) {
+ return null;
+ }
+ throw { message: "Invalid date/time value" };
+ }
+
+ // Pre-parse years, account for year '0' being invalid in dateTime.
+ var year = parseInt10(parts[1]);
+ if (year <= 0) {
+ year++;
+ }
+
+ // Pre-parse optional milliseconds, fill in default. Fail if value is too precise.
+ var ms = parts[7];
+ var ns = 0;
+ if (!ms) {
+ ms = 0;
+ } else {
+ if (ms.length > 7) {
+ if (nullOnError) {
+ return null;
+ }
+ throw { message: "Cannot parse date/time value to given precision." };
+ }
+
+ ns = formatNumberWidth(ms.substring(3), 4, true);
+ ms = formatNumberWidth(ms.substring(0, 3), 3, true);
+
+ ms = parseInt10(ms);
+ ns = parseInt10(ns);
+ }
+
+ // Pre-parse other time components and offset them if necessary.
+ var hours = parseInt10(parts[4]);
+ var minutes = parseInt10(parts[5]);
+ var seconds = parseInt10(parts[6]) || 0;
+ if (offset !== "Z") {
+ // The offset is reversed to get back the UTC date, which is
+ // what the API will eventually have.
+ var timezone = parseTimezone(offset);
+ var direction = -(timezone.d);
+ hours += timezone.h * direction;
+ minutes += timezone.m * direction;
+ }
+
+ // Set the date and time separately with setFullYear, so years 0-99 aren't biased like in Date.UTC.
+ var result = new Date();
+ result.setUTCFullYear(
+ year, // Year.
+ parseInt10(parts[2]) - 1, // Month (zero-based for Date.UTC and setFullYear).
+ parseInt10(parts[3]) // Date.
+ );
+ result.setUTCHours(hours, minutes, seconds, ms);
+
+ if (isNaN(result.valueOf())) {
+ if (nullOnError) {
+ return null;
+ }
+ throw { message: "Invalid date/time value" };
+ }
+
+ if (withOffset) {
+ result.__edmType = "Edm.DateTimeOffset";
+ result.__offset = offset;
+ }
+
+ if (ns) {
+ result.__ns = ns;
+ }
+
+ return result;
+}
+
+/** Parses a string into a Date object.
+ * @param {String} propertyValue - Value to parse.
+ * @returns {Date} The parsed with year, month, day set, time values are set to 0
+ */
+function parseDate(propertyValue, nullOnError) {
+ var parts = propertyValue.split('-');
+
+ if (parts.length != 3 && nullOnError) {
+ return null;
+ }
+ return new Date(
+ parseInt10(parts[0]), // Year.
+ parseInt10(parts[1]) - 1, // Month (zero-based for Date.UTC and setFullYear).
+ parseInt10(parts[2],
+ 0,0,0,0) // Date.
+ );
+
+}
+
+var parseTimeOfDayRE = /^(\d+):(\d+)(:(\d+)(.(\d+))?)?$/;
+
+function parseTimeOfDay(propertyValue, nullOnError) {
+ var parts = parseTimeOfDayRE.exec(propertyValue);
+
+
+ return {
+ 'h' :parseInt10(parts[1]),
+ 'm' :parseInt10(parts[2]),
+ 's' :parseInt10(parts[4]),
+ 'ms' :parseInt10(parts[6]),
+ };
+}
+
+/** Parses a string into a DateTimeOffset value.
+ * @param {String} propertyValue - Value to parse.
+ * @returns {Date} The parsed value.
+
+
+ * The resulting object is annotated with an __edmType property and
+ * an __offset property reflecting the original intended offset of
+ * the value. The time is adjusted for UTC time, as the current
+ * timezone-aware Date APIs will only work with the local timezone.
+ */
+function parseDateTimeOffset(propertyValue, nullOnError) {
+
+
+ return parseDateTimeMaybeOffset(propertyValue, true, nullOnError);
+}
+
+// The captured indices for this expression are:
+// 0 - complete input
+// 1 - direction
+// 2,3,4 - years, months, days
+// 5,6,7,8 - hours, minutes, seconds, miliseconds
+
+var parseTimeRE = /^([+-])?P(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)(?:\.(\d+))?S)?)?/;
+
+function isEdmDurationValue(value) {
+ parseTimeRE.test(value);
+}
+
+/** Parses a string in xsd:duration format.
+ * @param {String} duration - Duration value.
+
+ * This method will throw an exception if the input string has a year or a month component.
+
+ * @returns {Object} Object representing the time
+ */
+function parseDuration(duration) {
+
+ var parts = parseTimeRE.exec(duration);
+
+ if (parts === null) {
+ throw { message: "Invalid duration value." };
+ }
+
+ var years = parts[2] || "0";
+ var months = parts[3] || "0";
+ var days = parseInt10(parts[4] || 0);
+ var hours = parseInt10(parts[5] || 0);
+ var minutes = parseInt10(parts[6] || 0);
+ var seconds = parseFloat(parts[7] || 0);
+
+ if (years !== "0" || months !== "0") {
+ throw { message: "Unsupported duration value." };
+ }
+
+ var ms = parts[8];
+ var ns = 0;
+ if (!ms) {
+ ms = 0;
+ } else {
+ if (ms.length > 7) {
+ throw { message: "Cannot parse duration value to given precision." };
+ }
+
+ ns = formatNumberWidth(ms.substring(3), 4, true);
+ ms = formatNumberWidth(ms.substring(0, 3), 3, true);
+
+ ms = parseInt10(ms);
+ ns = parseInt10(ns);
+ }
+
+ ms += seconds * 1000 + minutes * 60000 + hours * 3600000 + days * 86400000;
+
+ if (parts[1] === "-") {
+ ms = -ms;
+ }
+
+ var result = { ms: ms, __edmType: "Edm.Time" };
+
+ if (ns) {
+ result.ns = ns;
+ }
+ return result;
+}
+
+/** Parses a timezone description in (+|-)nn:nn format.
+ * @param {String} timezone - Timezone offset.
+ * @returns {Object} An object with a (d)irection property of 1 for + and -1 for -, offset (h)ours and offset (m)inutes.
+ */
+function parseTimezone(timezone) {
+
+ var direction = timezone.substring(0, 1);
+ direction = (direction === "+") ? 1 : -1;
+
+ var offsetHours = parseInt10(timezone.substring(1));
+ var offsetMinutes = parseInt10(timezone.substring(timezone.indexOf(":") + 1));
+ return { d: direction, h: offsetHours, m: offsetMinutes };
+}
+
+/** Prepares a request object so that it can be sent through the network.
+* @param request - Object that represents the request to be sent.
+* @param handler - Handler for data serialization
+* @param context - Context used for preparing the request
+*/
+function prepareRequest(request, handler, context) {
+
+ // Default to GET if no method has been specified.
+ if (!request.method) {
+ request.method = "GET";
+ }
+
+ if (!request.headers) {
+ request.headers = {};
+ } else {
+ normalizeHeaders(request.headers);
+ }
+
+ if (request.headers.Accept === undefined) {
+ request.headers.Accept = handler.accept;
+ }
+
+ if (assigned(request.data) && request.body === undefined) {
+ handler.write(request, context);
+ }
+
+ if (!assigned(request.headers["OData-MaxVersion"])) {
+ request.headers["OData-MaxVersion"] = handler.maxDataServiceVersion || "4.0";
+ }
+
+ if (request.async === undefined) {
+ request.async = true;
+ }
+
+}
+
+/** Traverses a tree of objects invoking callback for every value.
+ * @param {Object} item - Object or array to traverse.
+ * @param {Function} callback - Callback function with key and value, similar to JSON.parse reviver.
+ * @returns {Object} The object with traversed properties.
+ Unlike the JSON reviver, this won't delete null members.</remarks>
+*/
+function traverseInternal(item, owner, callback) {
+
+ if (item && typeof item === "object") {
+ for (var name in item) {
+ var value = item[name];
+ var result = traverseInternal(value, name, callback);
+ result = callback(name, result, owner);
+ if (result !== value) {
+ if (value === undefined) {
+ delete item[name];
+ } else {
+ item[name] = result;
+ }
+ }
+ }
+ }
+
+ return item;
+}
+
+/** Traverses a tree of objects invoking callback for every value.
+ * @param {Object} item - Object or array to traverse.
+ * @param {Function} callback - Callback function with key and value, similar to JSON.parse reviver.
+ * @returns {Object} The traversed object.
+ * Unlike the JSON reviver, this won't delete null members.</remarks>
+*/
+function traverse(item, callback) {
+
+ return callback("", traverseInternal(item, "", callback));
+}
+
+exports.dataItemTypeName = dataItemTypeName;
+exports.EDM_BINARY = EDM_BINARY;
+exports.EDM_BOOLEAN = EDM_BOOLEAN;
+exports.EDM_BYTE = EDM_BYTE;
+exports.EDM_DATE = EDM_DATE;
+exports.EDM_DATETIMEOFFSET = EDM_DATETIMEOFFSET;
+exports.EDM_DURATION = EDM_DURATION;
+exports.EDM_DECIMAL = EDM_DECIMAL;
+exports.EDM_DOUBLE = EDM_DOUBLE;
+exports.EDM_GEOGRAPHY = EDM_GEOGRAPHY;
+exports.EDM_GEOGRAPHY_POINT = EDM_GEOGRAPHY_POINT;
+exports.EDM_GEOGRAPHY_LINESTRING = EDM_GEOGRAPHY_LINESTRING;
+exports.EDM_GEOGRAPHY_POLYGON = EDM_GEOGRAPHY_POLYGON;
+exports.EDM_GEOGRAPHY_COLLECTION = EDM_GEOGRAPHY_COLLECTION;
+exports.EDM_GEOGRAPHY_MULTIPOLYGON = EDM_GEOGRAPHY_MULTIPOLYGON;
+exports.EDM_GEOGRAPHY_MULTILINESTRING = EDM_GEOGRAPHY_MULTILINESTRING;
+exports.EDM_GEOGRAPHY_MULTIPOINT = EDM_GEOGRAPHY_MULTIPOINT;
+exports.EDM_GEOMETRY = EDM_GEOMETRY;
+exports.EDM_GEOMETRY_POINT = EDM_GEOMETRY_POINT;
+exports.EDM_GEOMETRY_LINESTRING = EDM_GEOMETRY_LINESTRING;
+exports.EDM_GEOMETRY_POLYGON = EDM_GEOMETRY_POLYGON;
+exports.EDM_GEOMETRY_COLLECTION = EDM_GEOMETRY_COLLECTION;
+exports.EDM_GEOMETRY_MULTIPOLYGON = EDM_GEOMETRY_MULTIPOLYGON;
+exports.EDM_GEOMETRY_MULTILINESTRING = EDM_GEOMETRY_MULTILINESTRING;
+exports.EDM_GEOMETRY_MULTIPOINT = EDM_GEOMETRY_MULTIPOINT;
+exports.EDM_GUID = EDM_GUID;
+exports.EDM_INT16 = EDM_INT16;
+exports.EDM_INT32 = EDM_INT32;
+exports.EDM_INT64 = EDM_INT64;
+exports.EDM_SBYTE = EDM_SBYTE;
+exports.EDM_SINGLE = EDM_SINGLE;
+exports.EDM_STRING = EDM_STRING;
+exports.EDM_TIMEOFDAY = EDM_TIMEOFDAY;
+exports.GEOJSON_POINT = GEOJSON_POINT;
+exports.GEOJSON_LINESTRING = GEOJSON_LINESTRING;
+exports.GEOJSON_POLYGON = GEOJSON_POLYGON;
+exports.GEOJSON_MULTIPOINT = GEOJSON_MULTIPOINT;
+exports.GEOJSON_MULTILINESTRING = GEOJSON_MULTILINESTRING;
+exports.GEOJSON_MULTIPOLYGON = GEOJSON_MULTIPOLYGON;
+exports.GEOJSON_GEOMETRYCOLLECTION = GEOJSON_GEOMETRYCOLLECTION;
+exports.forEachSchema = forEachSchema;
+exports.formatDateTimeOffset = formatDateTimeOffset;
+exports.formatDateTimeOffsetJSON = formatDateTimeOffsetJSON;
+exports.formatDuration = formatDuration;
+exports.formatNumberWidth = formatNumberWidth;
+exports.getCanonicalTimezone = getCanonicalTimezone;
+exports.getCollectionType = getCollectionType;
+exports.invokeRequest = invokeRequest;
+exports.isBatch = isBatch;
+exports.isCollection = isCollection;
+exports.isCollectionType = isCollectionType;
+exports.isComplex = isComplex;
+exports.isDateTimeOffset = isDateTimeOffset;
+exports.isDeferred = isDeferred;
+exports.isEntry = isEntry;
+exports.isFeed = isFeed;
+exports.isGeographyEdmType = isGeographyEdmType;
+exports.isGeometryEdmType = isGeometryEdmType;
+exports.isNamedStream = isNamedStream;
+exports.isPrimitive = isPrimitive;
+exports.isPrimitiveEdmType = isPrimitiveEdmType;
+exports.lookupComplexType = lookupComplexType;
+exports.lookupDefaultEntityContainer = lookupDefaultEntityContainer;
+exports.lookupEntityContainer = lookupEntityContainer;
+exports.lookupEntitySet = lookupEntitySet;
+exports.lookupSingleton = lookupSingleton;
+exports.lookupEntityType = lookupEntityType;
+exports.lookupFunctionImport = lookupFunctionImport;
+exports.lookupNavigationPropertyType = lookupNavigationPropertyType;
+exports.lookupNavigationPropertyEntitySet = lookupNavigationPropertyEntitySet;
+exports.lookupInSchema = lookupInSchema;
+exports.lookupProperty = lookupProperty;
+exports.lookupInMetadata = lookupInMetadata;
+exports.getEntitySetInfo = getEntitySetInfo;
+exports.maxVersion = maxVersion;
+exports.navigationPropertyKind = navigationPropertyKind;
+exports.normalizeHeaders = normalizeHeaders;
+exports.parseBool = parseBool;
+
+
+exports.parseDate = parseDate;
+exports.parseDateTimeOffset = parseDateTimeOffset;
+exports.parseDuration = parseDuration;
+exports.parseTimeOfDay = parseTimeOfDay;
+
+exports.parseInt10 = parseInt10;
+exports.prepareRequest = prepareRequest;
+exports.removeNamespace = removeNamespace;
+exports.traverse = traverse;
+