Feature/object model refactor (#26)
* Move foreach to async iterator * Mock out new APIs * remove legacy tests * remove old ntvs stuff for samples * Add shimmed implemention + bug fixes * Update (some) samples to use new OM * refactor interfaces into their own files * refactor om into new directory structure * small tweak to lib in gitignore * renamed document to item * update tests * Move Item/Permission/User tests * Remove Attachment from OM * Update item, container, database, and database account tests * Permission tests * User tests * Aggregate query tests moved to new OM * collectionNaming tests obsolete due to attachment/media * Update crosspartition test * Add encoding test * Update incremental feed tests * update proxy test * Update query test * update ruPerMind test * Update session tests * Update session container tests (moved to unit test) * Update SSL tests * Update UriFactory tests (moved to unit) * Update document client tests * Update authorization tests * Fix lint * Refactor of UDF test * Refactor trigger test * Refactor functional TTL test * Remove UriFactory * Type assertion due to intermediate implementation details * Query needs to support string * Support any overload * Query e2e tests * Spatial e2e test updated * Refactor functional sproc test * Add await to fix TS errors * Type assertion on container def for now * Remove offer tests for now * authorization tests updated * bug in test * Comment out and skip HashPartitionResolver test * Use UriFactory for urls * rids make me sad * types are fun * bugs in permission test * Symbol Shim for forEach * Fix user test * stringify the funciton bodys to avoid TypeScript weirdness * Support string body for UDF * Small bug in TTL test * Fix Authorization tests * remove bad options object * One more sproc fix * Need a blank object for parition key (if none specified) * One tests is broken still for now * Expose ErrorResponse * Handle undefined in forEach * Better error handling * Better error handling for crossParititon tests * Update tslint to catch dangling promises * Port over existing docs to TS files * Fix Mock toArray to promise based * Include tests in lint and fix errors * No assignment to Symbol.asyncIterator in node 10 * tslint fix * Remove unnecessary test (forEach is an iterable now) * no more generic database names in test * Index kind mistake * Missing promise * Shorten timeout (flakey test) * rename \w+s\.read to \w+s\.readAll * Move all #.get\w+ to #.get * Remove rid test. Pick up global timeout in auth test * Fix tslint * Fix test timeouts against production, except for TTL. Run TS tests directly * Add files * remove some collection/document mentions * fix sproc mistake from rename * Add CosmosClientOptions to export
This commit is contained in:
Родитель
7d31a2a95b
Коммит
0d38b3873b
|
@ -14,9 +14,9 @@
|
|||
"-u",
|
||||
"tdd",
|
||||
"--colors",
|
||||
"${workspaceFolder}/lib/test/**.spec.js",
|
||||
"${workspaceFolder}/lib/test/**/*.js",
|
||||
"-g",
|
||||
".*"
|
||||
".*for non master resource$"
|
||||
],
|
||||
"internalConsoleOptions": "openOnSessionStart",
|
||||
"sourceMaps": true,
|
||||
|
|
|
@ -450,15 +450,6 @@
|
|||
"integrity": "sha1-9zIHu4EgfXX9bIPxJa8m7qN4yjA=",
|
||||
"dev": true
|
||||
},
|
||||
"ansi-green": {
|
||||
"version": "0.1.1",
|
||||
"resolved": "https://registry.npmjs.org/ansi-green/-/ansi-green-0.1.1.tgz",
|
||||
"integrity": "sha1-il2al55FjVfEDjNYCzc5C44Q0Pc=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"ansi-wrap": "0.1.0"
|
||||
}
|
||||
},
|
||||
"ansi-regex": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz",
|
||||
|
@ -471,12 +462,6 @@
|
|||
"integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=",
|
||||
"dev": true
|
||||
},
|
||||
"ansi-wrap": {
|
||||
"version": "0.1.0",
|
||||
"resolved": "https://registry.npmjs.org/ansi-wrap/-/ansi-wrap-0.1.0.tgz",
|
||||
"integrity": "sha1-qCJQ3bABXponyoLoLqYDu/pF768=",
|
||||
"dev": true
|
||||
},
|
||||
"any-observable": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/any-observable/-/any-observable-0.3.0.tgz",
|
||||
|
@ -502,7 +487,7 @@
|
|||
"argparse": {
|
||||
"version": "1.0.10",
|
||||
"resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz",
|
||||
"integrity": "sha1-vNZ5HqWuCXJeF+WtmIE0zUCz2RE=",
|
||||
"integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"sprintf-js": "~1.0.2"
|
||||
|
@ -2611,28 +2596,6 @@
|
|||
"integrity": "sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s=",
|
||||
"dev": true
|
||||
},
|
||||
"copy": {
|
||||
"version": "0.3.2",
|
||||
"resolved": "https://registry.npmjs.org/copy/-/copy-0.3.2.tgz",
|
||||
"integrity": "sha512-drDFuUZctIuvSuvL9dOF/v5GxrwB1Q8eMIRlYONC0lSMEq+L2xabXP3jme8cQFdDO8cgP8JsuYhQg7JtTwezmg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"async-each": "^1.0.0",
|
||||
"bluebird": "^3.4.1",
|
||||
"extend-shallow": "^2.0.1",
|
||||
"file-contents": "^0.3.1",
|
||||
"glob-parent": "^2.0.0",
|
||||
"graceful-fs": "^4.1.4",
|
||||
"has-glob": "^0.1.1",
|
||||
"is-absolute": "^0.2.5",
|
||||
"lazy-cache": "^2.0.1",
|
||||
"log-ok": "^0.1.1",
|
||||
"matched": "^0.4.1",
|
||||
"mkdirp": "^0.5.1",
|
||||
"resolve-dir": "^0.1.0",
|
||||
"to-file": "^0.2.0"
|
||||
}
|
||||
},
|
||||
"copy-concurrently": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/copy-concurrently/-/copy-concurrently-1.0.5.tgz",
|
||||
|
@ -3462,15 +3425,6 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"expand-tilde": {
|
||||
"version": "1.2.2",
|
||||
"resolved": "https://registry.npmjs.org/expand-tilde/-/expand-tilde-1.2.2.tgz",
|
||||
"integrity": "sha1-C4HrqJflo9MdHD0QL48BRB5VlEk=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"os-homedir": "^1.0.1"
|
||||
}
|
||||
},
|
||||
"extend": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/extend/-/extend-3.0.1.tgz",
|
||||
|
@ -3646,38 +3600,6 @@
|
|||
"escape-string-regexp": "^1.0.5"
|
||||
}
|
||||
},
|
||||
"file-contents": {
|
||||
"version": "0.3.2",
|
||||
"resolved": "https://registry.npmjs.org/file-contents/-/file-contents-0.3.2.tgz",
|
||||
"integrity": "sha1-oJOf7RuM2hWAJm/Gt1OiMvtG3lM=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"define-property": "^0.2.5",
|
||||
"extend-shallow": "^2.0.1",
|
||||
"file-stat": "^0.2.3",
|
||||
"fs-exists-sync": "^0.1.0",
|
||||
"graceful-fs": "^4.1.4",
|
||||
"is-buffer": "^1.1.3",
|
||||
"isobject": "^2.1.0",
|
||||
"lazy-cache": "^2.0.1",
|
||||
"strip-bom-buffer": "^0.1.1",
|
||||
"strip-bom-string": "^0.1.2",
|
||||
"through2": "^2.0.1",
|
||||
"vinyl": "^1.1.1"
|
||||
}
|
||||
},
|
||||
"file-stat": {
|
||||
"version": "0.2.3",
|
||||
"resolved": "https://registry.npmjs.org/file-stat/-/file-stat-0.2.3.tgz",
|
||||
"integrity": "sha1-Rpp+kn1pMAeWJM2zgQlAVFbLBqk=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"fs-exists-sync": "^0.1.0",
|
||||
"graceful-fs": "^4.1.4",
|
||||
"lazy-cache": "^2.0.1",
|
||||
"through2": "^2.0.1"
|
||||
}
|
||||
},
|
||||
"file-uri-to-path": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz",
|
||||
|
@ -3848,12 +3770,6 @@
|
|||
"null-check": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"fs-exists-sync": {
|
||||
"version": "0.1.0",
|
||||
"resolved": "https://registry.npmjs.org/fs-exists-sync/-/fs-exists-sync-0.1.0.tgz",
|
||||
"integrity": "sha1-mC1ok6+RjnLQjeyehnP/K1qNat0=",
|
||||
"dev": true
|
||||
},
|
||||
"fs-extra": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-5.0.0.tgz",
|
||||
|
@ -4669,28 +4585,6 @@
|
|||
"integrity": "sha1-jFoUlNIGbFcMw7/kSWF1rMTVAqs=",
|
||||
"dev": true
|
||||
},
|
||||
"global-modules": {
|
||||
"version": "0.2.3",
|
||||
"resolved": "https://registry.npmjs.org/global-modules/-/global-modules-0.2.3.tgz",
|
||||
"integrity": "sha1-6lo77ULG1s6ZWk+KEmm12uIjgo0=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"global-prefix": "^0.1.4",
|
||||
"is-windows": "^0.2.0"
|
||||
}
|
||||
},
|
||||
"global-prefix": {
|
||||
"version": "0.1.5",
|
||||
"resolved": "https://registry.npmjs.org/global-prefix/-/global-prefix-0.1.5.tgz",
|
||||
"integrity": "sha1-jTvGuNo8qBEqFg2NSW/wRiv+948=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"homedir-polyfill": "^1.0.0",
|
||||
"ini": "^1.3.4",
|
||||
"is-windows": "^0.2.0",
|
||||
"which": "^1.2.12"
|
||||
}
|
||||
},
|
||||
"got": {
|
||||
"version": "8.3.1",
|
||||
"resolved": "https://registry.npmjs.org/got/-/got-8.3.1.tgz",
|
||||
|
@ -4836,15 +4730,6 @@
|
|||
"integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=",
|
||||
"dev": true
|
||||
},
|
||||
"has-glob": {
|
||||
"version": "0.1.1",
|
||||
"resolved": "https://registry.npmjs.org/has-glob/-/has-glob-0.1.1.tgz",
|
||||
"integrity": "sha1-omHEwqbGZ+DHe3AKfyl8Oe86pYk=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"is-glob": "^2.0.1"
|
||||
}
|
||||
},
|
||||
"has-symbol-support-x": {
|
||||
"version": "1.4.2",
|
||||
"resolved": "https://registry.npmjs.org/has-symbol-support-x/-/has-symbol-support-x-1.4.2.tgz",
|
||||
|
@ -5223,16 +5108,6 @@
|
|||
"integrity": "sha1-vd7XARQpCCjAoDnnLvJfWq7ENUo=",
|
||||
"dev": true
|
||||
},
|
||||
"is-absolute": {
|
||||
"version": "0.2.6",
|
||||
"resolved": "https://registry.npmjs.org/is-absolute/-/is-absolute-0.2.6.tgz",
|
||||
"integrity": "sha1-IN5p89uULvLYe5wto28XIjWxtes=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"is-relative": "^0.2.1",
|
||||
"is-windows": "^0.2.0"
|
||||
}
|
||||
},
|
||||
"is-accessor-descriptor": {
|
||||
"version": "0.1.6",
|
||||
"resolved": "https://registry.npmjs.org/is-accessor-descriptor/-/is-accessor-descriptor-0.1.6.tgz",
|
||||
|
@ -5494,15 +5369,6 @@
|
|||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"is-relative": {
|
||||
"version": "0.2.1",
|
||||
"resolved": "https://registry.npmjs.org/is-relative/-/is-relative-0.2.1.tgz",
|
||||
"integrity": "sha1-0n9MfVFtF1+2ENuEu+7yPDvJeqU=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"is-unc-path": "^0.1.1"
|
||||
}
|
||||
},
|
||||
"is-retry-allowed": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/is-retry-allowed/-/is-retry-allowed-1.1.0.tgz",
|
||||
|
@ -5531,33 +5397,12 @@
|
|||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"is-unc-path": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/is-unc-path/-/is-unc-path-0.1.2.tgz",
|
||||
"integrity": "sha1-arBTpyVzwQJQ/0FqOBTDUXivObk=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"unc-path-regex": "^0.1.0"
|
||||
}
|
||||
},
|
||||
"is-utf8": {
|
||||
"version": "0.2.1",
|
||||
"resolved": "https://registry.npmjs.org/is-utf8/-/is-utf8-0.2.1.tgz",
|
||||
"integrity": "sha1-Sw2hRCEE0bM2NA6AeX6GXPOffXI=",
|
||||
"dev": true
|
||||
},
|
||||
"is-valid-glob": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/is-valid-glob/-/is-valid-glob-0.3.0.tgz",
|
||||
"integrity": "sha1-1LVcafUYhvm2XHDWwmItN+KfSP4=",
|
||||
"dev": true
|
||||
},
|
||||
"is-windows": {
|
||||
"version": "0.2.0",
|
||||
"resolved": "https://registry.npmjs.org/is-windows/-/is-windows-0.2.0.tgz",
|
||||
"integrity": "sha1-3hqm1j6indJIc3tp8f+LgALSEIw=",
|
||||
"dev": true
|
||||
},
|
||||
"isarray": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
|
||||
|
@ -6107,15 +5952,6 @@
|
|||
"integrity": "sha512-NGEErnH6F2vUuXDh+OlbcKW7/wOcfdRHaZ7VWtqCztfHri/++YKmP51OdWeGPuqCOba6kk2OTe5d02VmTB80Pw==",
|
||||
"dev": true
|
||||
},
|
||||
"lazy-cache": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/lazy-cache/-/lazy-cache-2.0.2.tgz",
|
||||
"integrity": "sha1-uRkKT5EzVGlIQIWfio9whNiCImQ=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"set-getter": "^0.1.0"
|
||||
}
|
||||
},
|
||||
"lcid": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/lcid/-/lcid-1.0.0.tgz",
|
||||
|
@ -6437,16 +6273,6 @@
|
|||
"integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=",
|
||||
"dev": true
|
||||
},
|
||||
"log-ok": {
|
||||
"version": "0.1.1",
|
||||
"resolved": "https://registry.npmjs.org/log-ok/-/log-ok-0.1.1.tgz",
|
||||
"integrity": "sha1-vqPdNqzQuKckDXhza1uXxlREozQ=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"ansi-green": "^0.1.1",
|
||||
"success-symbol": "^0.1.0"
|
||||
}
|
||||
},
|
||||
"log-symbols": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-2.2.0.tgz",
|
||||
|
@ -6500,9 +6326,9 @@
|
|||
}
|
||||
},
|
||||
"log4js": {
|
||||
"version": "2.8.0",
|
||||
"resolved": "https://registry.npmjs.org/log4js/-/log4js-2.8.0.tgz",
|
||||
"integrity": "sha512-PjsaE4ElS0e2jWOY14Ef2PrC1Y+fny4AWPPT3xD6+2k2Aa5golhqJ4DSzP+5kXRL5bSw/5j1ocU5A9ceaxZeGA==",
|
||||
"version": "2.7.0",
|
||||
"resolved": "https://registry.npmjs.org/log4js/-/log4js-2.7.0.tgz",
|
||||
"integrity": "sha512-FyTwaPJfbfiK2AHc9ct/oFHNN4bJj0IQeqdO/LaDHhfjeBi8fnZU5rPcHOZhkYV0Aes31Ow+St1YTCluPtzs5g==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"amqplib": "^0.5.2",
|
||||
|
@ -6747,6 +6573,25 @@
|
|||
"promisify-call": "^2.0.2",
|
||||
"proxy-agent": "~3.0.0",
|
||||
"tsscmp": "~1.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"async": {
|
||||
"version": "2.6.1",
|
||||
"resolved": "https://registry.npmjs.org/async/-/async-2.6.1.tgz",
|
||||
"integrity": "sha512-fNEiL2+AZt6AlAw/29Cr0UDe4sRAHCpEHh54WMz+Bb7QfNcFw4h3loofyJpLeQs4Yx7yuqu/2dLgM5hKOs6HlQ==",
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"lodash": "^4.17.10"
|
||||
}
|
||||
},
|
||||
"lodash": {
|
||||
"version": "4.17.10",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz",
|
||||
"integrity": "sha512-UejweD1pDoXu+AD825lWwp4ZGtSwgnpZxb3JDViD7StjQz+Nb/6l093lx4OQ0foGWNRoc19mWy7BzL+UAK2iVg==",
|
||||
"dev": true,
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"make-dir": {
|
||||
|
@ -6793,23 +6638,6 @@
|
|||
"integrity": "sha1-XUf3CcTJ/Dwha21GEnKA9As515A=",
|
||||
"dev": true
|
||||
},
|
||||
"matched": {
|
||||
"version": "0.4.4",
|
||||
"resolved": "https://registry.npmjs.org/matched/-/matched-0.4.4.tgz",
|
||||
"integrity": "sha1-Vte36xgDPwz5vFLrIJD6x9weifo=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"arr-union": "^3.1.0",
|
||||
"async-array-reduce": "^0.2.0",
|
||||
"extend-shallow": "^2.0.1",
|
||||
"fs-exists-sync": "^0.1.0",
|
||||
"glob": "^7.0.5",
|
||||
"has-glob": "^0.1.1",
|
||||
"is-valid-glob": "^0.3.0",
|
||||
"lazy-cache": "^2.0.1",
|
||||
"resolve-dir": "^0.1.0"
|
||||
}
|
||||
},
|
||||
"math-random": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/math-random/-/math-random-1.0.1.tgz",
|
||||
|
@ -8852,16 +8680,6 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"resolve-dir": {
|
||||
"version": "0.1.1",
|
||||
"resolved": "https://registry.npmjs.org/resolve-dir/-/resolve-dir-0.1.1.tgz",
|
||||
"integrity": "sha1-shklmlYC+sXFxJatiUpujMQwJh4=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"expand-tilde": "^1.2.2",
|
||||
"global-modules": "^0.2.3"
|
||||
}
|
||||
},
|
||||
"resolve-url": {
|
||||
"version": "0.2.1",
|
||||
"resolved": "https://registry.npmjs.org/resolve-url/-/resolve-url-0.2.1.tgz",
|
||||
|
@ -9040,15 +8858,6 @@
|
|||
"integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=",
|
||||
"dev": true
|
||||
},
|
||||
"set-getter": {
|
||||
"version": "0.1.0",
|
||||
"resolved": "https://registry.npmjs.org/set-getter/-/set-getter-0.1.0.tgz",
|
||||
"integrity": "sha1-12nBgsnVpR9AkUXy+6guXoboA3Y=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"to-object-path": "^0.3.0"
|
||||
}
|
||||
},
|
||||
"set-immediate-shim": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/set-immediate-shim/-/set-immediate-shim-1.0.1.tgz",
|
||||
|
@ -9448,9 +9257,9 @@
|
|||
}
|
||||
},
|
||||
"source-map-support": {
|
||||
"version": "0.5.5",
|
||||
"resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.5.tgz",
|
||||
"integrity": "sha512-mR7/Nd5l1z6g99010shcXJiNEaf3fEtmLhRB/sBcQVJGodcHCULPp2y4Sfa43Kv2zq7T+Izmfp/WHCR6dYkQCA==",
|
||||
"version": "0.5.6",
|
||||
"resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.6.tgz",
|
||||
"integrity": "sha512-N4KXEz7jcKqPf2b2vZF11lQIz9W5ZMuUcIOGj243lduidkf2fjkVKJS9vNxVWn3u/uxX38AcE8U9nnH9FPcq+g==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"buffer-from": "^1.0.0",
|
||||
|
@ -9545,7 +9354,6 @@
|
|||
"ecc-jsbn": "~0.1.1",
|
||||
"getpass": "^0.1.1",
|
||||
"jsbn": "~0.1.0",
|
||||
"safer-buffer": "^2.0.2",
|
||||
"tweetnacl": "~0.14.0"
|
||||
}
|
||||
},
|
||||
|
@ -9696,16 +9504,6 @@
|
|||
"is-utf8": "^0.2.0"
|
||||
}
|
||||
},
|
||||
"strip-bom-buffer": {
|
||||
"version": "0.1.1",
|
||||
"resolved": "https://registry.npmjs.org/strip-bom-buffer/-/strip-bom-buffer-0.1.1.tgz",
|
||||
"integrity": "sha1-yj3cSRnBP5/d8wsd/xAKmDUki00=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"is-buffer": "^1.1.0",
|
||||
"is-utf8": "^0.2.0"
|
||||
}
|
||||
},
|
||||
"strip-bom-stream": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/strip-bom-stream/-/strip-bom-stream-2.0.0.tgz",
|
||||
|
@ -9716,24 +9514,12 @@
|
|||
"strip-bom": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"strip-bom-string": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/strip-bom-string/-/strip-bom-string-0.1.2.tgz",
|
||||
"integrity": "sha1-nG5yCjE7qYNliVGEBcz7iKX0G5w=",
|
||||
"dev": true
|
||||
},
|
||||
"strip-eof": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz",
|
||||
"integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=",
|
||||
"dev": true
|
||||
},
|
||||
"success-symbol": {
|
||||
"version": "0.1.0",
|
||||
"resolved": "https://registry.npmjs.org/success-symbol/-/success-symbol-0.1.0.tgz",
|
||||
"integrity": "sha1-JAIuSG878c3KCUKDt2nEctO3KJc=",
|
||||
"dev": true
|
||||
},
|
||||
"supports-color": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz",
|
||||
|
@ -9859,66 +9645,6 @@
|
|||
"integrity": "sha1-uDVx+k2MJbguIxsG46MFXeTKGkc=",
|
||||
"dev": true
|
||||
},
|
||||
"to-file": {
|
||||
"version": "0.2.0",
|
||||
"resolved": "https://registry.npmjs.org/to-file/-/to-file-0.2.0.tgz",
|
||||
"integrity": "sha1-I2xsCIBl5XDe+9Fc9LTlZb5G6pM=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"define-property": "^0.2.5",
|
||||
"extend-shallow": "^2.0.1",
|
||||
"file-contents": "^0.2.4",
|
||||
"glob-parent": "^2.0.0",
|
||||
"is-valid-glob": "^0.3.0",
|
||||
"isobject": "^2.1.0",
|
||||
"lazy-cache": "^2.0.1",
|
||||
"vinyl": "^1.1.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"file-contents": {
|
||||
"version": "0.2.4",
|
||||
"resolved": "https://registry.npmjs.org/file-contents/-/file-contents-0.2.4.tgz",
|
||||
"integrity": "sha1-BQb3uO/2KvpFrkXaTfnp1H30U8s=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"extend-shallow": "^2.0.0",
|
||||
"file-stat": "^0.1.0",
|
||||
"graceful-fs": "^4.1.2",
|
||||
"is-buffer": "^1.1.0",
|
||||
"is-utf8": "^0.2.0",
|
||||
"lazy-cache": "^0.2.3",
|
||||
"through2": "^2.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"lazy-cache": {
|
||||
"version": "0.2.7",
|
||||
"resolved": "https://registry.npmjs.org/lazy-cache/-/lazy-cache-0.2.7.tgz",
|
||||
"integrity": "sha1-f+3fLctu23fRHvHRF6tf/fCrG2U=",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"file-stat": {
|
||||
"version": "0.1.3",
|
||||
"resolved": "https://registry.npmjs.org/file-stat/-/file-stat-0.1.3.tgz",
|
||||
"integrity": "sha1-0PGWHX0QcykoEgpuaVVHHCpbVBE=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"graceful-fs": "^4.1.2",
|
||||
"lazy-cache": "^0.2.3",
|
||||
"through2": "^2.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"lazy-cache": {
|
||||
"version": "0.2.7",
|
||||
"resolved": "https://registry.npmjs.org/lazy-cache/-/lazy-cache-0.2.7.tgz",
|
||||
"integrity": "sha1-f+3fLctu23fRHvHRF6tf/fCrG2U=",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"to-object-path": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/to-object-path/-/to-object-path-0.3.0.tgz",
|
||||
|
@ -10059,21 +9785,27 @@
|
|||
"dev": true
|
||||
},
|
||||
"ts-node": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ts-node/-/ts-node-6.0.0.tgz",
|
||||
"integrity": "sha512-+CQev+4J7BAUNUnW9piRzSfSZZWeFCjgUjMSgGs4+dJ2RZa86NVW9MOlP4e6/kEHTyOqdxHxcIMd7KgmY/ynVw==",
|
||||
"version": "6.2.0",
|
||||
"resolved": "https://registry.npmjs.org/ts-node/-/ts-node-6.2.0.tgz",
|
||||
"integrity": "sha512-ZNT+OEGfUNVMGkpIaDJJ44Zq3Yr0bkU/ugN1PHbU+/01Z7UV1fsELRiTx1KuQNvQ1A3pGh3y25iYF6jXgxV21A==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"arrify": "^1.0.0",
|
||||
"chalk": "^2.3.0",
|
||||
"buffer-from": "^1.1.0",
|
||||
"diff": "^3.1.0",
|
||||
"make-error": "^1.1.1",
|
||||
"minimist": "^1.2.0",
|
||||
"mkdirp": "^0.5.1",
|
||||
"source-map-support": "^0.5.3",
|
||||
"source-map-support": "^0.5.6",
|
||||
"yn": "^2.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"buffer-from": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.0.tgz",
|
||||
"integrity": "sha512-c5mRlguI/Pe2dSZmpER62rSCu0ryKmWddzRYsuXc50U2/g8jMOulc31VZMa4mYx31U5xsmSOpDCgH88Vl9cDGQ==",
|
||||
"dev": true
|
||||
},
|
||||
"minimist": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
|
||||
|
@ -10296,12 +10028,6 @@
|
|||
"integrity": "sha512-UIEXBNeYmKptWH6z8ZnqTeS8fV74zG0/eRU9VGkpzz+LIJNs8W/zM/L+7ctCkRrgbNnnR0xxw4bKOr0cW0N0Og==",
|
||||
"dev": true
|
||||
},
|
||||
"unc-path-regex": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/unc-path-regex/-/unc-path-regex-0.1.2.tgz",
|
||||
"integrity": "sha1-5z3T17DXxe2G+6xrCufYxqadUPo=",
|
||||
"dev": true
|
||||
},
|
||||
"underscore": {
|
||||
"version": "1.8.3",
|
||||
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.8.3.tgz",
|
||||
|
|
11
package.json
11
package.json
|
@ -20,13 +20,13 @@
|
|||
},
|
||||
"scripts": {
|
||||
"clean": "rimraf lib",
|
||||
"lint": "tslint 'src/**/*.ts'",
|
||||
"lint": "tslint --project tsconfig.json",
|
||||
"compile": "echo Using TypeScript && tsc --version && tsc --pretty",
|
||||
"copy-legacy-js": "./node_modules/.bin/copy-cli src/test/legacy/* ./lib/test/legacy/",
|
||||
"docs": "typedoc --mode file --out ./lib/docs ./src",
|
||||
"pack": "webpack",
|
||||
"build": "npm run clean && npm run lint && npm run compile && npm run docs && npm run copy-legacy-js && npm run pack",
|
||||
"test": "mocha ./lib/test/ --recursive --timeout 30000 -i -g .*ignore.js",
|
||||
"build": "npm run clean && npm run lint && npm run compile && npm run docs && npm run pack",
|
||||
"test": "mocha -r ./src/test/common/setup.ts ./lib/test/ --recursive --timeout 30000 -i -g .*ignore.js",
|
||||
"test-ts": "mocha -r ts-node/register -r ./src/test/common/setup.ts ./src/test/**/*.spec.ts --recursive --timeout 30000 -i -g .*ignore.js",
|
||||
"test-browser": "karma start ./karma.config.js --single-run"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -37,7 +37,6 @@
|
|||
"@types/sinon": "^4.3.1",
|
||||
"@types/tunnel": "^0.0.0",
|
||||
"@types/underscore": "^1.8.8",
|
||||
"copy": "^0.3.2",
|
||||
"karma": "^2.0.2",
|
||||
"karma-chrome-launcher": "^2.2.0",
|
||||
"karma-cli": "^1.0.1",
|
||||
|
@ -52,7 +51,7 @@
|
|||
"mocha-multi-reporters": "^1.1.6",
|
||||
"requirejs": "^2.3.5",
|
||||
"sinon": "^5.0.1",
|
||||
"ts-node": "^6.0.0",
|
||||
"ts-node": "^6.2.0",
|
||||
"tslint": "^5.9.1",
|
||||
"typedoc": "^0.11.1",
|
||||
"typescript": "^2.8.3",
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">11.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
<Name>CollectionManagement</Name>
|
||||
<RootNamespace>CollectionManagement</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>5e0f86c7-4c76-4943-ac54-d3e1153009b0</ProjectGuid>
|
||||
<ProjectHome>.</ProjectHome>
|
||||
<StartupFile>app.js</StartupFile>
|
||||
<StartWebBrowser>False</StartWebBrowser>
|
||||
<SearchPath>
|
||||
</SearchPath>
|
||||
<WorkingDirectory>.</WorkingDirectory>
|
||||
<OutputPath>.</OutputPath>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<ProjectTypeGuids>{3AF33F2E-1136-4D97-BBB7-1795711AC8B8};{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}</ProjectTypeGuids>
|
||||
<ProjectView>ShowAllFiles</ProjectView>
|
||||
<StartWebBrowser>false</StartWebBrowser>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="app.js" />
|
||||
<Content Include="package.json" />
|
||||
<Content Include="README.md" />
|
||||
</ItemGroup>
|
||||
<!-- Do not delete the following Import Project. While this appears to do nothing it is a marker for setting TypeScript properties before our import that depends on them. -->
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets" Condition="False" />
|
||||
<Import Project="$(VSToolsPath)\Node.js Tools\Microsoft.NodejsTools.targets" />
|
||||
</Project>
|
|
@ -1,274 +0,0 @@
|
|||
'use strict';
|
||||
console.log();
|
||||
console.log('Azure Cosmos DB Node.js Samples');
|
||||
console.log('================================');
|
||||
console.log();
|
||||
console.log('COLLECTION MANAGEMENT');
|
||||
console.log('=====================');
|
||||
console.log();
|
||||
|
||||
var DocumentDBClient = require('documentdb').DocumentClient
|
||||
, config = require('../Shared/config')
|
||||
, databaseId = config.names.database
|
||||
, collectionId = config.names.collection
|
||||
|
||||
var host = config.connection.endpoint;
|
||||
var masterKey = config.connection.authKey;
|
||||
|
||||
// Establish a new instance of the DocumentDBClient to be used throughout this demo
|
||||
var client = new DocumentDBClient(host, { masterKey: masterKey });
|
||||
var dbLink;
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
// This demo performs a few steps
|
||||
// 1. createCollection - given an id, create a new Collectionwith thedefault indexingPolicy
|
||||
// 2. listCollections - example of using the QueryIterator to get a list of Collections in a Database
|
||||
// 3. readCollection - Read a collection by its _self
|
||||
// 4. readCollection - Read a collection by its id (using new ID Based Routing)
|
||||
// 5. getOfferType - get the Offer.OfferType for a collection. This is what determines if aCollection is S1, S2, or S3
|
||||
// 6. changeOfferType - change the Offer.OfferType for a collection. This is how you scale a Collection up or down
|
||||
// 7. deleteCollection - given just the collection id, delete the collection
|
||||
//---------------------------------------------------------------------------------
|
||||
|
||||
//ensuring a database exists for us to work with
|
||||
init(databaseId, function (db) {
|
||||
if (dbLink) {
|
||||
|
||||
//1.
|
||||
console.log('1. createCollection ith id \'' + collectionId + '\'');
|
||||
createCollection(dbLink, collectionId, function (col) {
|
||||
|
||||
//2.
|
||||
console.log('\n2. listCollections in database');
|
||||
listCollections(dbLink, function (cols) {
|
||||
for (var i = 0; i < cols.length; i++) {
|
||||
console.log(cols[i].id);
|
||||
}
|
||||
|
||||
//3.
|
||||
console.log('\n3. readCollection by its _self');
|
||||
readCollection(col._self, function (result) {
|
||||
if (result) {
|
||||
console.log('Collection with _self \'' + result._self + '\' was found its id is \'' + result.id);
|
||||
}
|
||||
|
||||
//4.
|
||||
console.log('\n4. readCollection by its id');
|
||||
readCollectionById(collectionId, function (result) {
|
||||
if (result) {
|
||||
console.log('Collection with id of \'' + collectionId + '\' was found its _self is \'' + result._self + '\'');
|
||||
}
|
||||
|
||||
//5.
|
||||
console.log('\n5. getOfferType by its id');
|
||||
getOfferType(col, function (offer) {
|
||||
if (offer) {
|
||||
console.log('Collection with id of \'' + collectionId + '\' has an Offer Type of \'' + offer.offerType + '\'');
|
||||
}
|
||||
|
||||
//6.
|
||||
console.log('\n6. changeOfferType to an S2');
|
||||
offer.offerType = 'S2';
|
||||
changeOfferType(offer.id, offer, function (offer) {
|
||||
if (offer) {
|
||||
console.log('Collection now has offerType of \'' + offer.offerType + '\'');
|
||||
}
|
||||
|
||||
//7.
|
||||
console.log('\n7. deleteCollection \'' + collectionId + '\'');
|
||||
deleteCollection(collectionId, function () {
|
||||
|
||||
//cleanup & end
|
||||
console.log('\nCleaning up ...');
|
||||
finish();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function createCollection(databaseLink, collectionId, callback) {
|
||||
//we're creating a Collection here using the default indexingPolicy,
|
||||
//for more information on using other indexingPolicies please consult the IndexManagement sample
|
||||
|
||||
//we're also setting the OfferType for this new collection to be an "S1"
|
||||
//"S1" is the default, so if a OfferType value is not supplied in the 4th parameter then OfferTyoe of "S1" will apply
|
||||
//for more information on OfferTypes please consult the Cosmos DB Documentation on
|
||||
//https://docs.microsoft.com/azure/cosmos-db/
|
||||
|
||||
var collSpec = { id: collectionId };
|
||||
var options = { offerType: "S1" };
|
||||
|
||||
client.createCollection(databaseLink, collSpec, options, function (err, created) {
|
||||
if (err) {
|
||||
handleError(err);
|
||||
|
||||
} else {
|
||||
console.log('Collection \'' + collectionId + '\'created');
|
||||
callback(created);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function listCollections(databaseLink, callback) {
|
||||
var queryIterator = client.readCollections(databaseLink).toArray(function (err, cols) {
|
||||
if (err) {
|
||||
handleError(err);
|
||||
|
||||
} else {
|
||||
console.log(cols.length + ' Collections found');
|
||||
callback(cols);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function readCollection(selfLink, callback) {
|
||||
client.readCollection(selfLink, function (err, coll) {
|
||||
if (err) {
|
||||
handleError(err);
|
||||
|
||||
} else {
|
||||
callback(coll);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function readCollectionById(collectionId, callback) {
|
||||
//when using the new ID Based Routing URIs, the URI must NOT have a trailing / character
|
||||
//i.e. instead of dbs/databaseId/colls/collectionId/ (which is the format of a db._self) the URI must be dbs/databaseId/colls/collectionId
|
||||
|
||||
var collLink = dbLink + '/colls/' + collectionId;
|
||||
client.readCollection(collLink, function (err, coll) {
|
||||
if (err) {
|
||||
handleError(err);
|
||||
|
||||
} else {
|
||||
callback(coll);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getOfferType(collection, callback) {
|
||||
//Collections and OfferTypes are loosely coupled.
|
||||
//Offer.resource == collection._self And Offer.offerResourceId == collection._rid
|
||||
//Therefore, to find the OfferType for a Collection, query for Offers by resourceLink matching collectionSelfLink
|
||||
|
||||
var querySpec = {
|
||||
query: 'SELECT * FROM root r WHERE r.resource = @link',
|
||||
parameters: [
|
||||
{
|
||||
name: '@link',
|
||||
value: collection._self
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
client.queryOffers(querySpec).toArray(function (err, offers) {
|
||||
if (err) {
|
||||
handleError(err);
|
||||
|
||||
} else if (offers.length === 0) {
|
||||
console.log('No offer found for collection');
|
||||
|
||||
} else {
|
||||
console.log('Offer found for collection');
|
||||
var offer = offers[0];
|
||||
callback(offer);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function changeOfferType(offerId, updatedOffer, callback) {
|
||||
var offerLink = 'offers/' + offerId;
|
||||
|
||||
client.replaceOffer(offerLink, updatedOffer, function (err, replacedOffer) {
|
||||
if (err) {
|
||||
handleError(err);
|
||||
|
||||
} else if (replacedOffer.offerType != updatedOffer.offerType) {
|
||||
throw 'OfferType was not updated';
|
||||
|
||||
} else {
|
||||
callback(replacedOffer);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function deleteCollection(collectionId, callback) {
|
||||
var collLink = dbLink + '/colls/' + collectionId;
|
||||
|
||||
client.deleteCollection(collLink, function (err) {
|
||||
if (err) {
|
||||
handleError(err);
|
||||
} else {
|
||||
console.log('Collection \'' + collectionId + '\'deleted');
|
||||
callback();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function init(databaseId, callback){
|
||||
//we're using queryDatabases here and not readDatabase
|
||||
//readDatabase will throw an exception if resource is not found
|
||||
//queryDatabases will not, it will return empty resultset.
|
||||
|
||||
var querySpec = {
|
||||
query: 'SELECT * FROM root r WHERE r.id=@id',
|
||||
parameters: [
|
||||
{
|
||||
name: '@id',
|
||||
value: databaseId
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
client.queryDatabases(querySpec).toArray(function (err, results) {
|
||||
if (err) {
|
||||
handleError(err);
|
||||
|
||||
//database not found, create it
|
||||
} else if (results.length === 0) {
|
||||
var databaseDef = { id: databaseId };
|
||||
|
||||
client.createDatabase(databaseDef, function (err, created) {
|
||||
if (err) {
|
||||
handleError(err);
|
||||
}
|
||||
|
||||
dbLink = 'dbs/' + created.id;
|
||||
callback(created);
|
||||
});
|
||||
|
||||
//database found, return it
|
||||
} else {
|
||||
var db = results[0];
|
||||
dbLink = 'dbs/' + db.id;
|
||||
|
||||
callback(db);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function deleteDatabase(dbLink) {
|
||||
client.deleteDatabase(dbLink, function (err) {
|
||||
if (err) {
|
||||
handleError(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function handleError(error) {
|
||||
console.log('\nAn error with code \'' + error.code + '\' has occurred:');
|
||||
console.log('\t' + JSON.parse(error.body).message);
|
||||
|
||||
finish();
|
||||
}
|
||||
|
||||
function finish() {
|
||||
deleteDatabase(dbLink);
|
||||
console.log('\nEnd of demo.');
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
// @ts-check
|
||||
'use strict';
|
||||
console.log();
|
||||
console.log('Azure Cosmos DB Node.js Samples');
|
||||
console.log('================================');
|
||||
console.log();
|
||||
console.log('container MANAGEMENT');
|
||||
console.log('=====================');
|
||||
console.log();
|
||||
|
||||
const cosmos = require('../../lib/');
|
||||
const CosmosClient = cosmos.CosmosClient;
|
||||
const config = require('../Shared/config')
|
||||
const databaseId = config.names.database
|
||||
const containerId = config.names.container
|
||||
|
||||
var endpoint = config.connection.endpoint;
|
||||
var masterKey = config.connection.authKey;
|
||||
|
||||
// Establish a new instance of the CosmosClient to be used throughout this demo
|
||||
var client = new CosmosClient({ endpoint, auth: { masterKey } });
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
// This demo performs a few steps
|
||||
// 1. create container - given an id, create a new container with thedefault indexingPolicy
|
||||
// 2. read all containers - example of using the QueryIterator to get a list of containers in a Database
|
||||
// 3. read container - Read a container by its _self
|
||||
// 4. delete container - given just the container id, delete the container
|
||||
//---------------------------------------------------------------------------------
|
||||
|
||||
/** @type {cosmos.Database} */
|
||||
let database;
|
||||
|
||||
//ensuring a database exists for us to work with
|
||||
async function run() {
|
||||
await init(databaseId);
|
||||
|
||||
//1.
|
||||
console.log('1. create container ith id \'' + containerId + '\'');
|
||||
await database.containers.create({id: containerId});
|
||||
|
||||
//2.
|
||||
console.log('\n2. read all containers in database');
|
||||
const iterator = database.containers.readAll();
|
||||
for (const {result} of await iterator.forEach()) {
|
||||
console.log(result.id);
|
||||
}
|
||||
|
||||
//3.
|
||||
console.log('\n3. read container definition');
|
||||
const container = database.containers.get(containerId);
|
||||
const {result: containerDef} = await container.read();
|
||||
|
||||
console.log('container with url \'' + container.url + '\' was found its id is \'' + containerDef.id);
|
||||
|
||||
//4.
|
||||
console.log('\n7. deletecontainer \'' + containerId + '\'');
|
||||
container.delete();
|
||||
}
|
||||
|
||||
async function init(databaseId) {
|
||||
//we're using queryDatabases here and not readDatabase
|
||||
//readDatabase will throw an exception if resource is not found
|
||||
//queryDatabases will not, it will return empty resultset.
|
||||
|
||||
var querySpec = {
|
||||
query: 'SELECT * FROM root r WHERE r.id=@id',
|
||||
parameters: [
|
||||
{
|
||||
name: '@id',
|
||||
value: databaseId
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
const { result: results } = await client.databases.query(querySpec).toArray();
|
||||
if (results.length === 0) {
|
||||
var databaseDef = { id: databaseId };
|
||||
|
||||
const { result: newDB } = await client.databases.create(databaseDef);
|
||||
client.databases.get(newDB.id);
|
||||
//database found, return it
|
||||
} else {
|
||||
client.databases.get(results[0].id);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleError(error) {
|
||||
console.log('\nAn error with code \'' + error.code + '\' has occurred:');
|
||||
console.log('\t' + JSON.parse(error.body).message);
|
||||
|
||||
await finish();
|
||||
}
|
||||
|
||||
async function finish() {
|
||||
try {
|
||||
await database.delete();
|
||||
console.log('\nEnd of demo.');
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
run().then(finish).catch(handleError);
|
|
@ -1,40 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">11.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
<Name>DatabaseManagement</Name>
|
||||
<RootNamespace>DatabaseManagement</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{61f8e2a2-42eb-4354-81e0-ff2c91521395}</ProjectGuid>
|
||||
<ProjectHome>.</ProjectHome>
|
||||
<StartupFile>app.js</StartupFile>
|
||||
<StartWebBrowser>False</StartWebBrowser>
|
||||
<SearchPath>
|
||||
</SearchPath>
|
||||
<WorkingDirectory>.</WorkingDirectory>
|
||||
<OutputPath>.</OutputPath>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<ProjectTypeGuids>{3AF33F2E-1136-4D97-BBB7-1795711AC8B8};{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}</ProjectTypeGuids>
|
||||
<ProjectView>ShowAllFiles</ProjectView>
|
||||
<StartWebBrowser>false</StartWebBrowser>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="app.js" />
|
||||
<Content Include="package.json" />
|
||||
<Content Include="README.md" />
|
||||
</ItemGroup>
|
||||
<!-- Do not delete the following Import Project. While this appears to do nothing it is a marker for setting TypeScript properties before our import that depends on them. -->
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets" Condition="False" />
|
||||
<Import Project="$(VSToolsPath)\Node.js Tools\Microsoft.NodejsTools.targets" />
|
||||
</Project>
|
|
@ -1,4 +1,5 @@
|
|||
'use strict';
|
||||
// @ts-check
|
||||
'use strict';
|
||||
console.log();
|
||||
console.log('Azure Cosmos DB Node.js Samples');
|
||||
console.log('================================');
|
||||
|
@ -8,165 +9,68 @@ console.log('===================');
|
|||
console.log();
|
||||
|
||||
|
||||
var DocumentDBClient = require('documentdb').DocumentClient
|
||||
, config = require('../Shared/config')
|
||||
, databaseId = config.names.database
|
||||
const cosmos = require('../../lib/');
|
||||
const CosmosClient = cosmos.CosmosClient;
|
||||
const config = require('../Shared/config')
|
||||
const databaseId = config.names.database
|
||||
|
||||
var host = config.connection.endpoint;
|
||||
var masterKey = config.connection.authKey;
|
||||
const endpoint = config.connection.endpoint;
|
||||
const masterKey = config.connection.authKey;
|
||||
|
||||
// Establish a new instance of the DocumentDBClient to be used throughout this demo
|
||||
var client = new DocumentDBClient(host, { masterKey: masterKey });
|
||||
// Establish a new instance of the CosmosClient to be used throughout this demo
|
||||
const client = new CosmosClient({endpoint, auth: { masterKey }});
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
// This demo performs the following CRUD operations on a Database
|
||||
//
|
||||
// 1. findDatabaseById - Attempt to find a database by Id, if found then just complete the sample
|
||||
// 1. find Database - Attempt to find a database by Id, if found then just complete the sample
|
||||
// 2. create Database - If the database was not found, try create it
|
||||
// 3. listDatabases - Once the database was created, list all the databases on the account
|
||||
// 4. readDatbase - Read a database by its _self
|
||||
// 5. readDatabase - Read a database by its id (using new ID Based Routing)
|
||||
// 6. deleteDatabase - Delete a database given its id
|
||||
// 3. read all Databases - Once the database was created, list all the databases on the account
|
||||
// 4. read Database - Read a database by its id (using new ID Based Routing)
|
||||
// 5. delete Database - Delete a database given its id
|
||||
//
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
|
||||
// 1.
|
||||
console.log('1. findDatabaseById \'' + databaseId + '\'');
|
||||
findDatabaseById(databaseId, function (err, db) {
|
||||
async function run() {
|
||||
|
||||
try {
|
||||
// 1.
|
||||
try {
|
||||
console.log('1. findDatabaseById \'' + databaseId + '\'');
|
||||
const {result: db} = await client.databases.get(databaseId).read();
|
||||
await client.databases.get(databaseId).delete();
|
||||
} catch(err) {
|
||||
if(err.code === 404) {
|
||||
//no database found, let's go ahead with sample
|
||||
if (db == null) {
|
||||
console.log('Database with id ' + databaseId + ' not found.');
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
// 2.
|
||||
console.log('\n2. createDatabase \'' + databaseId + '\'')
|
||||
createDatabase(databaseId, function (db) {
|
||||
if (db != null) {
|
||||
console.log('Database with id ' + db.id + ' created.');
|
||||
await client.databases.create({id: databaseId});
|
||||
console.log('Database with id ' + databaseId + ' created.');
|
||||
|
||||
// 3.
|
||||
console.log('\n3. listDatabases');
|
||||
listDatabases(function (dbs) {
|
||||
for (var i = 0; i < dbs.length; i++) {
|
||||
console.log(dbs[i].id);
|
||||
for (const {db} of await client.databases.readAll().forEach()) {
|
||||
console.log(db.id);
|
||||
}
|
||||
|
||||
// 4.
|
||||
console.log('\n4. readDatabase - with _self \'' + db._self + '\'');
|
||||
readDatabase(db, function (db) {
|
||||
if (db != null) {
|
||||
console.log('Database with _self \'' + db._self + '\' was found its id is \'' + db.id);
|
||||
}
|
||||
console.log('\n5. readDatabase - with id \'' + databaseId + '\'');
|
||||
const {result: db} = await client.databases.get(databaseId).read();
|
||||
console.log('Database with uri of \'dbs/' + db.id + '\' was found');
|
||||
|
||||
// 5.
|
||||
console.log('\n5. readDatabase - with id \'' + db.id + '\'');
|
||||
readDatabaseById(databaseId, function () {
|
||||
if (db != null) {
|
||||
console.log('Database with uri of \'dbs/' + db.id + '\' was found its _self is \'' + db._self + '\'');
|
||||
}
|
||||
|
||||
// 6.
|
||||
console.log('\n6. deleteDatabase with id \'' + databaseId + '\'');
|
||||
deleteDatabase(databaseId, function () {
|
||||
finish();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
await client.databases.get(databaseId).delete();
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
|
||||
//database already present, cleanup for next run
|
||||
} else {
|
||||
console.log('\nNothing more to do here, A database with id ' + databaseId + ' was already found.');
|
||||
deleteDatabase(databaseId, function () {
|
||||
finish();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function readDatabaseById(databaseId, callback) {
|
||||
client.readDatabase('dbs/' + databaseId, function (err, db) {
|
||||
if (err) {
|
||||
handleError(err);
|
||||
}
|
||||
|
||||
callback(db);
|
||||
});
|
||||
}
|
||||
|
||||
function readDatabase(database, callback) {
|
||||
client.readDatabase(database._self, function (err, db) {
|
||||
if (err) {
|
||||
handleError(err);
|
||||
}
|
||||
|
||||
callback(db);
|
||||
});
|
||||
}
|
||||
|
||||
function listDatabases(callback) {
|
||||
var queryIterator = client.readDatabases().toArray(function (err, dbs) {
|
||||
if (err) {
|
||||
handleError(err);
|
||||
}
|
||||
|
||||
callback(dbs);
|
||||
});
|
||||
}
|
||||
|
||||
function createDatabase(databaseId, callback) {
|
||||
var dbdef = {id : databaseId};
|
||||
|
||||
client.createDatabase(dbdef, function (err, createdDatabase) {
|
||||
if (err) {
|
||||
handleError (err);
|
||||
}
|
||||
|
||||
callback(createdDatabase);
|
||||
});
|
||||
}
|
||||
|
||||
function deleteDatabase(databaseId, callback) {
|
||||
var dbLink = 'dbs/' + databaseId;
|
||||
|
||||
client.deleteDatabase(dbLink, function (err) {
|
||||
if (err) {
|
||||
handleError(err);
|
||||
} else {
|
||||
console.log('Database with id \'' + databaseId + '\' deleted.');
|
||||
callback();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function findDatabaseById(databaseId, callback) {
|
||||
var querySpec = {
|
||||
query: 'SELECT * FROM root r WHERE r.id = @id',
|
||||
parameters: [
|
||||
{
|
||||
name: '@id',
|
||||
value: databaseId
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
client.queryDatabases(querySpec).toArray(function (err, results) {
|
||||
if (err) {
|
||||
handleError(err);
|
||||
}
|
||||
|
||||
if (results.length === 0) {
|
||||
// no error occured, but there were no results returned
|
||||
// indicating no database exists matching the query
|
||||
// so, explictly return null
|
||||
callback(null, null);
|
||||
} else {
|
||||
// we found a database, so return it
|
||||
callback(null, results[0]);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
function handleError(error) {
|
||||
console.log();
|
||||
|
@ -181,3 +85,5 @@ function finish() {
|
|||
console.log();
|
||||
console.log('End of demo.');
|
||||
}
|
||||
|
||||
run().catch(handleError).then(finish);
|
||||
|
|
|
@ -1,72 +0,0 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26430.16
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Data", "Data", "{52B0D185-3B67-4804-923E-A0B7948C006D}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
Shared\Data\Families.json = Shared\Data\Families.json
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Shared", "Shared", "{31234210-D784-4E2C-8D32-6379647281B1}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
Shared\config.js = Shared\config.js
|
||||
Shared\utils.js = Shared\utils.js
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}") = "CollectionManagement", "CollectionManagement\CollectionManagement.njsproj", "{5E0F86C7-4C76-4943-AC54-D3E1153009B0}"
|
||||
EndProject
|
||||
Project("{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}") = "DatabaseManagement", "DatabaseManagement\DatabaseManagement.njsproj", "{61F8E2A2-42EB-4354-81E0-FF2C91521395}"
|
||||
EndProject
|
||||
Project("{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}") = "DocumentManagement", "DocumentManagement\DocumentManagement.njsproj", "{59AC41DA-0B9F-4342-8BA0-356D810F56C0}"
|
||||
EndProject
|
||||
Project("{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}") = "IndexManagement", "IndexManagement\IndexManagement.njsproj", "{4764380F-4842-4268-9EDA-3BCE5333BEA3}"
|
||||
EndProject
|
||||
Project("{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}") = "Partitioning", "Partitioning\Partitioning.njsproj", "{C7A99393-DEA4-4BBF-8B96-722BB2DE9D2F}"
|
||||
EndProject
|
||||
Project("{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}") = "ServerSideScripts", "ServerSideScripts\ServerSideScripts.njsproj", "{7420867D-AF24-4824-BAC7-DCE6687BDAEB}"
|
||||
EndProject
|
||||
Project("{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}") = "UserManagement", "UserManagement\UserManagement.njsproj", "{8A03085A-178C-457D-B21C-5173A6CF9BF5}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{5E0F86C7-4C76-4943-AC54-D3E1153009B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5E0F86C7-4C76-4943-AC54-D3E1153009B0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5E0F86C7-4C76-4943-AC54-D3E1153009B0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5E0F86C7-4C76-4943-AC54-D3E1153009B0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{61F8E2A2-42EB-4354-81E0-FF2C91521395}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{61F8E2A2-42EB-4354-81E0-FF2C91521395}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{61F8E2A2-42EB-4354-81E0-FF2C91521395}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{61F8E2A2-42EB-4354-81E0-FF2C91521395}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{59AC41DA-0B9F-4342-8BA0-356D810F56C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{59AC41DA-0B9F-4342-8BA0-356D810F56C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{59AC41DA-0B9F-4342-8BA0-356D810F56C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{59AC41DA-0B9F-4342-8BA0-356D810F56C0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{4764380F-4842-4268-9EDA-3BCE5333BEA3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4764380F-4842-4268-9EDA-3BCE5333BEA3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4764380F-4842-4268-9EDA-3BCE5333BEA3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4764380F-4842-4268-9EDA-3BCE5333BEA3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C7A99393-DEA4-4BBF-8B96-722BB2DE9D2F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C7A99393-DEA4-4BBF-8B96-722BB2DE9D2F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C7A99393-DEA4-4BBF-8B96-722BB2DE9D2F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C7A99393-DEA4-4BBF-8B96-722BB2DE9D2F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{7420867D-AF24-4824-BAC7-DCE6687BDAEB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{7420867D-AF24-4824-BAC7-DCE6687BDAEB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7420867D-AF24-4824-BAC7-DCE6687BDAEB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7420867D-AF24-4824-BAC7-DCE6687BDAEB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{8A03085A-178C-457D-B21C-5173A6CF9BF5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{8A03085A-178C-457D-B21C-5173A6CF9BF5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8A03085A-178C-457D-B21C-5173A6CF9BF5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{8A03085A-178C-457D-B21C-5173A6CF9BF5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{52B0D185-3B67-4804-923E-A0B7948C006D} = {31234210-D784-4E2C-8D32-6379647281B1}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -1,40 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">11.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
<Name>DocumentManagement</Name>
|
||||
<RootNamespace>DocumentManagement</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{59ac41da-0b9f-4342-8ba0-356d810f56c0}</ProjectGuid>
|
||||
<ProjectHome>.</ProjectHome>
|
||||
<StartupFile>app.js</StartupFile>
|
||||
<StartWebBrowser>False</StartWebBrowser>
|
||||
<SearchPath>
|
||||
</SearchPath>
|
||||
<WorkingDirectory>.</WorkingDirectory>
|
||||
<OutputPath>.</OutputPath>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<ProjectTypeGuids>{3AF33F2E-1136-4D97-BBB7-1795711AC8B8};{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}</ProjectTypeGuids>
|
||||
<ProjectView>ProjectFiles</ProjectView>
|
||||
<StartWebBrowser>false</StartWebBrowser>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="app.js" />
|
||||
<Content Include="package.json" />
|
||||
<Content Include="README.md" />
|
||||
</ItemGroup>
|
||||
<!-- Do not delete the following Import Project. While this appears to do nothing it is a marker for setting TypeScript properties before our import that depends on them. -->
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets" Condition="False" />
|
||||
<Import Project="$(VSToolsPath)\Node.js Tools\Microsoft.NodejsTools.targets" />
|
||||
</Project>
|
|
@ -1,40 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">11.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
<Name>IndexManagement</Name>
|
||||
<RootNamespace>IndexManagement</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{4764380f-4842-4268-9eda-3bce5333bea3}</ProjectGuid>
|
||||
<ProjectHome>.</ProjectHome>
|
||||
<StartupFile>app.js</StartupFile>
|
||||
<StartWebBrowser>False</StartWebBrowser>
|
||||
<SearchPath>
|
||||
</SearchPath>
|
||||
<WorkingDirectory>.</WorkingDirectory>
|
||||
<OutputPath>.</OutputPath>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<ProjectTypeGuids>{3AF33F2E-1136-4D97-BBB7-1795711AC8B8};{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}</ProjectTypeGuids>
|
||||
<ProjectView>ShowAllFiles</ProjectView>
|
||||
<StartWebBrowser>false</StartWebBrowser>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="app.js" />
|
||||
<Content Include="package.json" />
|
||||
<Content Include="README.md" />
|
||||
</ItemGroup>
|
||||
<!-- Do not delete the following Import Project. While this appears to do nothing it is a marker for setting TypeScript properties before our import that depends on them. -->
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets" Condition="False" />
|
||||
<Import Project="$(VSToolsPath)\Node.js Tools\Microsoft.NodejsTools.targets" />
|
||||
</Project>
|
|
@ -0,0 +1,224 @@
|
|||
// @ts-check
|
||||
'use strict';
|
||||
console.log();
|
||||
console.log('Azure Cosmos DB Node.js Samples');
|
||||
console.log('================================');
|
||||
console.log();
|
||||
console.log('ITEM MANAGEMENT');
|
||||
console.log('===================');
|
||||
console.log();
|
||||
|
||||
const cosmos = require('../../lib/');
|
||||
const CosmosClient = cosmos.CosmosClient;
|
||||
const config = require('../Shared/config')
|
||||
const fs = require('fs')
|
||||
const async = require('async')
|
||||
const databaseId = config.names.database
|
||||
const containerId = config.names.container
|
||||
let dbLink;
|
||||
let collLink;
|
||||
|
||||
const endpoint = config.connection.endpoint;
|
||||
const masterKey = config.connection.authKey;
|
||||
|
||||
const getItemDefinitions = function () {
|
||||
const data = fs.readFileSync('../Shared/Data/Families.json', 'utf8');
|
||||
return JSON.parse(data).Families;
|
||||
};
|
||||
|
||||
// Establish a new instance of the CosmosClient to be used throughout this demo
|
||||
var client = new CosmosClient( {endpoint, auth: { masterKey }});
|
||||
|
||||
//NOTE:
|
||||
//when using the new IDBased Routing URIs, instead of the _self, as we 're doing in this sample
|
||||
//ensure that the URI does not end with a trailing '/' character
|
||||
//so dbs/databaseId instead of dbs/databaseId/
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------
|
||||
// This demo performs a few steps
|
||||
// 1. create items - Insert some items in to container
|
||||
// 2. list items - Read the item feed for a container
|
||||
// 3. read item
|
||||
// 3.1 - Read a single item by its id
|
||||
// 3.2 - Use ETag and AccessCondition to only return a item if ETag does not match
|
||||
// 4. query items - Query for items by some property
|
||||
// 5. replace item
|
||||
// 5.1 - Update some properties and replace the item
|
||||
// 5.2 - Use ETag and AccessCondition to only replace item if it has not changed
|
||||
// 6. upsert item - Update a item if it exists, else create new item
|
||||
// 7. delete item - Given a item id, delete it
|
||||
//-------------------------------------------------------------------------------------------------------
|
||||
|
||||
async function run() {
|
||||
//ensuring a database & container exists for us to work with
|
||||
await init();
|
||||
|
||||
const database = client.databases.get(databaseId);
|
||||
const container = database.containers.get(containerId);
|
||||
|
||||
//1.
|
||||
console.log('\n1. insert items in to database \'' + databaseId + '\' and container \'' + containerId + '\'');
|
||||
const docDefs = getItemDefinitions();
|
||||
const p = [];
|
||||
for(const docDef of docDefs) {
|
||||
p.push(container.items.create(docDef));
|
||||
}
|
||||
await Promise.all(p);
|
||||
console.log(docDefs.length + ' docs created');
|
||||
|
||||
//2.
|
||||
console.log('\n2. list items in container \'' + collLink + '\'');
|
||||
const {result: docs} = await container.items.readAll().toArray();
|
||||
|
||||
for (const doc of docs) {
|
||||
console.log(doc.id);
|
||||
}
|
||||
|
||||
//3.1
|
||||
const item = container.items.get(docs[0].id);
|
||||
console.log('\n3.1 read item \'' + item.id + '\'');
|
||||
const {result: readDoc} = await item.read();
|
||||
console.log('item with id \'' + item.id + '\' found');
|
||||
|
||||
//3.2
|
||||
console.log('\n3.2 read item with AccessCondition and no change to _etag');
|
||||
const {result: item2, headers} = await item.read({ accessCondition : { type: 'IfNoneMatch', condition: readDoc._etag } });
|
||||
if (!item2 && headers["content-length"] == 0) {
|
||||
console.log('As expected, no item returned. This is because the etag sent matched the etag on the server. i.e. you have the latest version of the doc already');
|
||||
}
|
||||
|
||||
//if we someone else updates this doc, its etag on the server would change.
|
||||
//repeating the above read with the old etag would then get a item in the response
|
||||
readDoc.foo = 'bar';
|
||||
await item.replace(readDoc);
|
||||
const {result: item3} = await item.read({ accessCondition : { type: 'IfNoneMatch', condition: readDoc._etag } });
|
||||
if (!item3 && headers["content-length"] == 0) {
|
||||
throw ('Expected item this time. Something is wrong!');
|
||||
} else {
|
||||
console.log('This time the read request returned the item because the etag values did not match');
|
||||
}
|
||||
|
||||
//4.
|
||||
var querySpec = {
|
||||
query: 'SELECT * FROM Families f WHERE f.lastName = @lastName',
|
||||
parameters: [
|
||||
{
|
||||
name: '@lastName',
|
||||
value: 'Andersen'
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
console.log('\n4. query items in container \'' + collLink + '\'');
|
||||
const {result: results} = await container.items.query(querySpec).toArray();
|
||||
|
||||
if (results.length == 0) {
|
||||
throw ("No items found matching");
|
||||
} else if (results.length > 1) {
|
||||
throw ("More than 1 item found matching");
|
||||
}
|
||||
|
||||
const person = results[0];
|
||||
console.log('The \'' + person.id + '\' family has lastName \'' + person.lastName + '\'');
|
||||
console.log('The \'' + person.id + '\' family has ' + person.children.length + ' children \'');
|
||||
|
||||
//add a new child to this family, and change the family's lastName
|
||||
const childDef = {
|
||||
"firstName": "Newborn",
|
||||
"gender": "unknown",
|
||||
"fingers": 10,
|
||||
"toes": 10
|
||||
};
|
||||
|
||||
person.children.push(childDef);
|
||||
person.lastName = "Updated Family";
|
||||
|
||||
//5.1
|
||||
console.log('\n5.1 replace item with id \'' + item.id + '\'');
|
||||
const {result: updated} = await item.replace(person);
|
||||
|
||||
console.log('The \'' + person.id + '\' family has lastName \'' + person.lastName + '\'');
|
||||
console.log('The \'' + person.id + '\' family has ' + person.children.length + ' children \'');
|
||||
|
||||
// 5.2
|
||||
console.log('\n5.2 trying to replace item when item has changed in the database');
|
||||
// The replace item above will work even if there's a new version of doc on the server from what you originally read
|
||||
// If you want to prevent this from happening you can opt-in to a conditional update
|
||||
// Using accessCondition and etag you can specify that the replace only occurs if the etag you are sending matches the etag on the server
|
||||
// i.e. Only replace if the item hasn't changed
|
||||
|
||||
// let's go update doc
|
||||
person.foo = 'bar';
|
||||
await item.replace(person);
|
||||
|
||||
// now let's try another update to doc with accessCondition and etag set
|
||||
person.foo = 'should never get set';
|
||||
try {
|
||||
await item.replace(person, { accessCondition: { type: 'IfMatch', condition: person._etag } });
|
||||
throw new Error("This should have failed!");
|
||||
} catch (err) {
|
||||
if (err.code == 412) {
|
||||
console.log('As expected, the replace item failed with a pre-condition failure');
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
//6.
|
||||
console.log('\n6. delete item \'' + item.id + '\'');
|
||||
await item.delete();
|
||||
}
|
||||
|
||||
async function init() {
|
||||
await getOrCreateDatabase(databaseId);
|
||||
await getOrCreateContainer(databaseId, containerId);
|
||||
}
|
||||
|
||||
async function getOrCreateContainer(databaseId, id, callback) {
|
||||
const database = client.databases.get(databaseId);
|
||||
try {
|
||||
try {
|
||||
await database.containers.get(id).read();
|
||||
} catch (err) {
|
||||
// if it doesn't exist, create it
|
||||
if(err.code === 404) {
|
||||
await database.containers.create({id});
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
async function getOrCreateDatabase(id, callback) {
|
||||
try {
|
||||
try {
|
||||
await client.databases.get(id).read();
|
||||
} catch (err) {
|
||||
// if it doesn't exist, create it
|
||||
if(err.code === 404) {
|
||||
await client.databases.create({id});
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleError(error) {async
|
||||
console.log('\nAn error with code \'' + error.code + '\' has occurred:');
|
||||
console.log('\t' + JSON.parse(error.body).message);
|
||||
|
||||
await finish();
|
||||
}
|
||||
|
||||
async function finish() {
|
||||
await client.databases.get(dbLink).delete();
|
||||
console.log('\nEnd of demo.');
|
||||
}
|
||||
|
||||
run().then(finish).catch(handleError);
|
|
@ -1,40 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">11.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
<Name>Partitioning</Name>
|
||||
<RootNamespace>Partitioning</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{c7a99393-dea4-4bbf-8b96-722bb2de9d2f}</ProjectGuid>
|
||||
<ProjectHome>.</ProjectHome>
|
||||
<StartupFile>app.js</StartupFile>
|
||||
<StartWebBrowser>False</StartWebBrowser>
|
||||
<SearchPath>
|
||||
</SearchPath>
|
||||
<WorkingDirectory>.</WorkingDirectory>
|
||||
<OutputPath>.</OutputPath>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<ProjectTypeGuids>{3AF33F2E-1136-4D97-BBB7-1795711AC8B8};{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}</ProjectTypeGuids>
|
||||
<ProjectView>ShowAllFiles</ProjectView>
|
||||
<StartWebBrowser>false</StartWebBrowser>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="app.js" />
|
||||
<Content Include="package.json" />
|
||||
<Content Include="README.md" />
|
||||
</ItemGroup>
|
||||
<!-- Do not delete the following Import Project. While this appears to do nothing it is a marker for setting TypeScript properties before our import that depends on them. -->
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets" Condition="False" />
|
||||
<Import Project="$(VSToolsPath)\Node.js Tools\Microsoft.NodejsTools.targets" />
|
||||
</Project>
|
|
@ -1,45 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">11.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
<Name>ServerSideScripts</Name>
|
||||
<RootNamespace>ServerSideScripts</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{7420867d-af24-4824-bac7-dce6687bdaeb}</ProjectGuid>
|
||||
<ProjectHome>.</ProjectHome>
|
||||
<StartupFile>app.js</StartupFile>
|
||||
<StartWebBrowser>False</StartWebBrowser>
|
||||
<SearchPath>
|
||||
</SearchPath>
|
||||
<WorkingDirectory>.</WorkingDirectory>
|
||||
<OutputPath>.</OutputPath>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<ProjectTypeGuids>{3AF33F2E-1136-4D97-BBB7-1795711AC8B8};{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}</ProjectTypeGuids>
|
||||
<ProjectView>ShowAllFiles</ProjectView>
|
||||
<StartWebBrowser>false</StartWebBrowser>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="app.js" />
|
||||
<Compile Include="JS\upsert.js" />
|
||||
<Content Include="JS\README.md" />
|
||||
<Content Include="package.json" />
|
||||
<Content Include="README.md" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="JS\" />
|
||||
</ItemGroup>
|
||||
<!-- Do not delete the following Import Project. While this appears to do nothing it is a marker for setting TypeScript properties before our import that depends on them. -->
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets" Condition="False" />
|
||||
<Import Project="$(VSToolsPath)\Node.js Tools\Microsoft.NodejsTools.targets" />
|
||||
</Project>
|
|
@ -5,5 +5,5 @@
|
|||
|
||||
exports.names = {
|
||||
database: 'NodeSamples',
|
||||
collection: 'Data',
|
||||
container: 'Data',
|
||||
};
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
<Name>UserManagement</Name>
|
||||
<RootNamespace>UserManagement</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>8a03085a-178c-457d-b21c-5173a6cf9bf5</ProjectGuid>
|
||||
<ProjectHome>.</ProjectHome>
|
||||
<StartupFile>app.js</StartupFile>
|
||||
<StartWebBrowser>False</StartWebBrowser>
|
||||
<SearchPath>
|
||||
</SearchPath>
|
||||
<WorkingDirectory>.</WorkingDirectory>
|
||||
<OutputPath>.</OutputPath>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<ProjectTypeGuids>{3AF33F2E-1136-4D97-BBB7-1795711AC8B8};{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}</ProjectTypeGuids>
|
||||
<StartWebBrowser>false</StartWebBrowser>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="app.js" />
|
||||
<Content Include="package.json" />
|
||||
<Content Include="README.md" />
|
||||
</ItemGroup>
|
||||
<!-- Do not delete the following Import Project. While this appears to do nothing it is a marker for setting TypeScript properties before our import that depends on them. -->
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets" Condition="False" />
|
||||
<Import Project="$(VSToolsPath)\Node.js Tools\Microsoft.NodejsTools.targets" />
|
||||
</Project>
|
|
@ -0,0 +1,31 @@
|
|||
import { Databases } from "./client/Database/";
|
||||
import { Offers } from "./client/Offer/";
|
||||
import { CosmosClientOptions } from "./CosmosClientOptions";
|
||||
import { DocumentClient } from "./documentclient";
|
||||
import { DatabaseAccount } from "./documents";
|
||||
import { Response } from "./request";
|
||||
|
||||
/**
|
||||
* Provides a client-side logical representation of the Azure Cosmos DB database account.
|
||||
* This client is used to configure and execute requests in the Azure Cosmos DB database service.
|
||||
*/
|
||||
export class CosmosClient {
|
||||
public readonly databases: Databases;
|
||||
public readonly offers: Offers;
|
||||
public documentClient: DocumentClient; // TODO: This will go away.
|
||||
constructor(private options: CosmosClientOptions) {
|
||||
this.databases = new Databases(this);
|
||||
this.offers = new Offers(this);
|
||||
|
||||
this.documentClient = new DocumentClient(
|
||||
options.endpoint,
|
||||
options.auth,
|
||||
options.connectionPolicy,
|
||||
options.consistencyLevel,
|
||||
);
|
||||
}
|
||||
|
||||
public async getDatabaseAccount(): Promise<Response<DatabaseAccount>> {
|
||||
return this.documentClient.getDatabaseAccount();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
import { ConnectionPolicy, ConsistencyLevel } from "./documents";
|
||||
|
||||
export interface CosmosClientOptions {
|
||||
/** The service endpoint to use to create the client. */
|
||||
endpoint: string;
|
||||
/** An object that is used for authenticating requests and must contains one of the options */
|
||||
auth: {
|
||||
/** The authorization master key to use to create the client. */
|
||||
masterKey?: string;
|
||||
/** An array of {@link Permission} objects. */
|
||||
permissionFeed?: any; // TODO: any
|
||||
/** An object that contains resources tokens.
|
||||
* Keys for the object are resource Ids and values are the resource tokens.
|
||||
*/
|
||||
resourceTokens?: any; // TODO: any
|
||||
tokenProvider?: any; // TODO: any
|
||||
};
|
||||
/** An instance of {@link ConnectionPolicy} class.
|
||||
* This parameter is optional and the default connectionPolicy will be used if omitted.
|
||||
*/
|
||||
connectionPolicy?: ConnectionPolicy;
|
||||
/** An optional parameter that represents the consistency level.
|
||||
* It can take any value from {@link ConsistencyLevel}.
|
||||
*/
|
||||
consistencyLevel?: ConsistencyLevel;
|
||||
}
|
|
@ -4,14 +4,15 @@ import * as tunnel from "tunnel";
|
|||
import * as url from "url";
|
||||
import { Base, ResponseCallback } from "./base";
|
||||
import { Constants, Helper, Platform } from "./common";
|
||||
import { RequestOptions } from "./documentclient";
|
||||
import { ConnectionPolicy, ConsistencyLevel, DatabaseAccount, QueryCompatibilityMode } from "./documents";
|
||||
import { GlobalEndpointManager } from "./globalEndpointManager";
|
||||
import { IHeaders } from "./queryExecutionContext";
|
||||
import { RequestHandler, Response } from "./request";
|
||||
import { RequestHandler, Response } from "./request/request";
|
||||
import { RequestOptions } from "./request/RequestOptions";
|
||||
import { SessionContainer } from "./sessionContainer";
|
||||
|
||||
// Using this to organize public vs internal methods
|
||||
/** @hidden */
|
||||
export abstract class DocumentClientBase {
|
||||
public masterKey: string;
|
||||
public resourceTokens: { [key: string]: string };
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import * as crypto from "crypto";
|
||||
import { DocumentClient } from "./documentclient";
|
||||
import { DocumentClientBase } from "./DocumentClientBase";
|
||||
import { IHeaders } from "./queryExecutionContext";
|
||||
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
import { AuthHandler } from "./auth";
|
||||
import { Constants, Platform } from "./common";
|
||||
import { DocumentClient, FeedOptions, MediaOptions, Options, RequestOptions } from "./documentclient";
|
||||
import { DocumentClientBase } from "./DocumentClientBase";
|
||||
import { IHeaders } from "./queryExecutionContext";
|
||||
import { Response } from "./request";
|
||||
import { FeedOptions } from "./request/FeedOptions";
|
||||
import { MediaOptions } from "./request/MediaOptions";
|
||||
import { Response } from "./request/request";
|
||||
import { RequestOptions } from "./request/RequestOptions";
|
||||
|
||||
export class Base {
|
||||
public static extend(arg0: any, arg1: any): any {
|
||||
|
@ -118,7 +120,7 @@ export class Base {
|
|||
headers[Constants.HttpHeaders.PopulateQuotaInfo] = true;
|
||||
}
|
||||
|
||||
// If the user is not using partition resolver, we add options.partitonKey to the header for elastic collections
|
||||
// If the user is not using partition resolver, we add options.partitonKey to the header for elastic containers
|
||||
if ((documentClient as any).partitionResolver === undefined // TODO: paritionResolver does not exist
|
||||
|| (documentClient as any).partitionResolver === null) {
|
||||
if (opts.partitionKey !== undefined) {
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
import { Constants } from "../../common";
|
||||
import { CosmosClient } from "../../CosmosClient";
|
||||
import { RequestOptions, Response } from "../../request";
|
||||
import { Container } from "../Container";
|
||||
import { ConflictDefinition } from "./ConflictDefinition";
|
||||
|
||||
export class Conflict {
|
||||
public get url() {
|
||||
return `/${this.container.url}/${Constants.Path.ConflictsPathSegment}/${this.id}`;
|
||||
}
|
||||
private client: CosmosClient;
|
||||
constructor(public readonly container: Container, public readonly id: string) {
|
||||
this.client = this.container.database.client;
|
||||
}
|
||||
|
||||
public read(options?: RequestOptions): Promise<Response<ConflictDefinition>> {
|
||||
return this.client.documentClient.readConflict(this.url, options);
|
||||
}
|
||||
|
||||
public delete(options?: RequestOptions): Promise<Response<ConflictDefinition>> {
|
||||
return this.client.documentClient.deleteConflict(this.url, options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
export interface ConflictDefinition {
|
||||
id?: string;
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
import { CosmosClient } from "../../CosmosClient";
|
||||
import { SqlQuerySpec } from "../../queryExecutionContext";
|
||||
import { QueryIterator } from "../../queryIterator";
|
||||
import { FeedOptions } from "../../request";
|
||||
import { Container } from "../Container";
|
||||
import { Conflict } from "./Conflict";
|
||||
import { ConflictDefinition } from "./ConflictDefinition";
|
||||
|
||||
export class Conflicts {
|
||||
private client: CosmosClient;
|
||||
constructor(public readonly container: Container) {
|
||||
this.client = this.container.database.client;
|
||||
}
|
||||
|
||||
public get(id: string) {
|
||||
return new Conflict(this.container, id);
|
||||
}
|
||||
|
||||
public query(query: SqlQuerySpec, options?: FeedOptions): QueryIterator<ConflictDefinition> {
|
||||
return this.client.documentClient.queryConflicts(this.container.url, query, options);
|
||||
}
|
||||
|
||||
public readAll(options?: FeedOptions): QueryIterator<ConflictDefinition> {
|
||||
return this.client.documentClient.readConflicts(this.container.url, options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
export { Conflict } from "./Conflict";
|
||||
export { Conflicts } from "./Conflicts";
|
||||
export { ConflictDefinition } from "./ConflictDefinition";
|
|
@ -0,0 +1,38 @@
|
|||
import { Constants, UriFactory } from "../../common";
|
||||
import { RequestOptions, Response } from "../../request";
|
||||
import { Database } from "../Database";
|
||||
import { Items } from "../Item";
|
||||
import { StoredProcedures } from "../StoredProcedure";
|
||||
import { Triggers } from "../Trigger";
|
||||
import { UserDefinedFunctions } from "../UserDefinedFunction";
|
||||
import { ContainerDefinition } from "./ContainerDefinition";
|
||||
|
||||
export class Container {
|
||||
public readonly items: Items;
|
||||
public readonly storedProcedures: StoredProcedures;
|
||||
public readonly triggers: Triggers;
|
||||
public readonly userDefinedFunctions: UserDefinedFunctions;
|
||||
|
||||
public get url() {
|
||||
return UriFactory.createDocumentCollectionUri(this.database.id, this.id);
|
||||
}
|
||||
|
||||
constructor(public readonly database: Database, public readonly id: string) {
|
||||
this.items = new Items(this);
|
||||
this.storedProcedures = new StoredProcedures(this);
|
||||
this.triggers = new Triggers(this);
|
||||
this.userDefinedFunctions = new UserDefinedFunctions(this);
|
||||
}
|
||||
|
||||
public read(options?: RequestOptions): Promise<Response<ContainerDefinition>> {
|
||||
return this.database.client.documentClient.readCollection(this.url, options);
|
||||
}
|
||||
|
||||
public replace(body: ContainerDefinition, options?: RequestOptions): Promise<Response<ContainerDefinition>> {
|
||||
return this.database.client.documentClient.replaceCollection(this.url, body, options);
|
||||
}
|
||||
|
||||
public delete(options?: RequestOptions): Promise<Response<ContainerDefinition>> {
|
||||
return this.database.client.documentClient.deleteCollection(this.url, options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
import { IndexingPolicy, PartitionKey, PartitionKeyDefinition } from "../../documents";
|
||||
|
||||
export interface ContainerDefinition {
|
||||
/** The id of the container. */
|
||||
id?: string;
|
||||
/** TODO */
|
||||
partitionKey?: PartitionKeyDefinition;
|
||||
/** The indexing policy associated with the container. */
|
||||
indexingPolicy?: IndexingPolicy;
|
||||
/** The default time to live in seconds for items in a container. */
|
||||
defaultTtl?: number;
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
import { SqlQuerySpec } from "../../queryExecutionContext";
|
||||
import { QueryIterator } from "../../queryIterator";
|
||||
import { FeedOptions, RequestOptions, Response } from "../../request";
|
||||
import { Database } from "../Database";
|
||||
import { Container } from "./Container";
|
||||
import { ContainerDefinition } from "./ContainerDefinition";
|
||||
|
||||
export class Containers {
|
||||
constructor(public readonly database: Database) { }
|
||||
|
||||
public get(id: string): Container {
|
||||
return new Container(this.database, id);
|
||||
}
|
||||
|
||||
public query(query: SqlQuerySpec, options?: FeedOptions): QueryIterator<ContainerDefinition> {
|
||||
return this.database.client.documentClient.queryCollections(this.database.url, query, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a container.
|
||||
* <p>
|
||||
* A container is a named logical container for items. <br>
|
||||
* A database may contain zero or more named containers and each container consists of \
|
||||
* zero or more JSON items. <br>
|
||||
* Being schema-free, the items in a container do not need to share the same structure or fields. <br>
|
||||
* Since containers are application resources, they can be authorized using either the \
|
||||
* master key or resource keys. <br>
|
||||
* </p>
|
||||
* @param body - Represents the body of the container.
|
||||
*/
|
||||
public create(body: ContainerDefinition, options?: RequestOptions): Promise<Response<ContainerDefinition>> {
|
||||
return this.database.client.documentClient.createCollection(this.database.url, body, options);
|
||||
}
|
||||
|
||||
public readAll(options?: FeedOptions): QueryIterator<ContainerDefinition> {
|
||||
return this.database.client.documentClient.readCollections(this.database.url, options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
export { Container } from "./Container";
|
||||
export { Containers } from "./Containers";
|
||||
export { ContainerDefinition } from "./ContainerDefinition";
|
|
@ -0,0 +1,28 @@
|
|||
import { Constants, UriFactory } from "../../common";
|
||||
import { CosmosClient } from "../../CosmosClient";
|
||||
import { RequestOptions, Response } from "../../request";
|
||||
import { Containers } from "../Container";
|
||||
import { Users } from "../User";
|
||||
import { DatabaseDefinition } from "./DatabaseDefinition";
|
||||
|
||||
export class Database {
|
||||
public readonly containers: Containers;
|
||||
public readonly users: Users;
|
||||
|
||||
public get url() {
|
||||
return UriFactory.createDatabaseUri(this.id);
|
||||
}
|
||||
|
||||
constructor(public readonly client: CosmosClient, public readonly id: string) {
|
||||
this.containers = new Containers(this);
|
||||
this.users = new Users(this);
|
||||
}
|
||||
|
||||
public read(options?: RequestOptions): Promise<Response<DatabaseDefinition>> {
|
||||
return this.client.documentClient.readDatabase(this.url, options);
|
||||
}
|
||||
|
||||
public delete(options?: RequestOptions): Promise<Response<DatabaseDefinition>> {
|
||||
return this.client.documentClient.deleteDatabase(this.url, options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
export interface DatabaseDefinition {
|
||||
/** The id of the database. */
|
||||
id?: string;
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
import { CosmosClient } from "../../CosmosClient";
|
||||
import { SqlQuerySpec } from "../../queryExecutionContext";
|
||||
import { QueryIterator } from "../../queryIterator";
|
||||
import { FeedOptions, RequestOptions, Response } from "../../request";
|
||||
import { Database } from "./Database";
|
||||
import { DatabaseDefinition } from "./DatabaseDefinition";
|
||||
|
||||
export class Databases {
|
||||
constructor(private readonly client: CosmosClient) {}
|
||||
public get(id: string): Database {
|
||||
return new Database(this.client, id);
|
||||
}
|
||||
|
||||
public query(query: string | SqlQuerySpec, options?: FeedOptions): QueryIterator<DatabaseDefinition> {
|
||||
return this.client.documentClient.queryDatabases(query, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a request for creating a database.
|
||||
* <p>
|
||||
* A database manages users, permissions and a set of containers. <br>
|
||||
* Each Azure Cosmos DB Database Account is able to support multiple independent named databases,\
|
||||
* with the database being the logical container for data. <br>
|
||||
* Each Database consists of one or more containers, each of which in turn contain one or more \
|
||||
* documents. Since databases are an an administrative resource, the Service Master Key will be \
|
||||
* required in order to access and successfully complete any action using the User APIs. <br>
|
||||
* </p>
|
||||
*
|
||||
* @param body - A json object that represents The database to be created.
|
||||
*/
|
||||
public create(body: DatabaseDefinition, options?: RequestOptions): Promise<Response<DatabaseDefinition>> {
|
||||
return this.client.documentClient.createDatabase(body, options);
|
||||
}
|
||||
|
||||
public readAll(options?: FeedOptions): QueryIterator<DatabaseDefinition> {
|
||||
return this.client.documentClient.readDatabases(options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
export { Database } from "./Database";
|
||||
export { Databases } from "./Databases";
|
||||
export { DatabaseDefinition } from "./DatabaseDefinition";
|
|
@ -0,0 +1,49 @@
|
|||
import { Constants, UriFactory } from "../../common";
|
||||
import { CosmosClient } from "../../CosmosClient";
|
||||
import { RequestOptions, Response } from "../../request";
|
||||
import { Container } from "../Container";
|
||||
|
||||
export class Item {
|
||||
|
||||
private client: CosmosClient;
|
||||
public get url() {
|
||||
return UriFactory.createDocumentUri(this.container.database.id, this.container.id, this.id);
|
||||
}
|
||||
|
||||
constructor(
|
||||
public readonly container: Container,
|
||||
public readonly id: string,
|
||||
public readonly primaryKey: string) {
|
||||
this.client = this.container.database.client;
|
||||
}
|
||||
|
||||
public read(options?: RequestOptions): Promise<Response<any>>;
|
||||
public read<T>(options?: RequestOptions): Promise<Response<T>>;
|
||||
public read<T>(options?: RequestOptions): Promise<Response<T>> {
|
||||
options = options || {};
|
||||
if ((!options || !options.partitionKey) && this.primaryKey) {
|
||||
options.partitionKey = this.primaryKey;
|
||||
}
|
||||
return this.client.documentClient.readDocument(this.url, options) as Promise<Response<T>>;
|
||||
}
|
||||
|
||||
public replace(body: any, options?: RequestOptions): Promise<Response<any>>;
|
||||
public replace<T>(body: T, options?: RequestOptions): Promise<Response<T>>;
|
||||
public replace<T>(body: T, options?: RequestOptions): Promise<Response<T>> {
|
||||
options = options || {};
|
||||
if ((!options || !options.partitionKey) && this.primaryKey) {
|
||||
options.partitionKey = this.primaryKey;
|
||||
}
|
||||
return this.client.documentClient.replaceDocument(this.url, body, options) as Promise<Response<T>>;
|
||||
}
|
||||
|
||||
public delete(options?: RequestOptions): Promise<Response<any>>;
|
||||
public delete<T>(options?: RequestOptions): Promise<Response<T>>;
|
||||
public delete<T>(options?: RequestOptions): Promise<Response<T>> {
|
||||
options = options || {};
|
||||
if ((!options || !options.partitionKey) && this.primaryKey) {
|
||||
options.partitionKey = this.primaryKey;
|
||||
}
|
||||
return this.client.documentClient.deleteDocument(this.url, options) as Promise<Response<T>>;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
import { DocumentClient } from "../../documentclient";
|
||||
import { SqlQuerySpec } from "../../queryExecutionContext";
|
||||
import { QueryIterator } from "../../queryIterator";
|
||||
import { FeedOptions, RequestOptions, Response } from "../../request";
|
||||
import { Container } from "../Container";
|
||||
import { Item } from "./Item";
|
||||
|
||||
export class Items {
|
||||
private client: DocumentClient;
|
||||
constructor(public readonly container: Container) {
|
||||
this.client = this.container.database.client.documentClient;
|
||||
}
|
||||
|
||||
public get(id: string, partitionKey?: string): Item {
|
||||
return new Item(this.container, id, partitionKey);
|
||||
}
|
||||
|
||||
public query(query: string | SqlQuerySpec, options?: FeedOptions): QueryIterator<any>;
|
||||
public query<T>(query: SqlQuerySpec, options?: FeedOptions): QueryIterator<T>;
|
||||
public query<T>(query: SqlQuerySpec, options?: FeedOptions): QueryIterator<T> {
|
||||
return this.client.queryDocuments(this.container.url, query, options) as QueryIterator<T>;
|
||||
}
|
||||
|
||||
public readAll(options?: FeedOptions): QueryIterator<any>;
|
||||
public readAll<T>(options?: FeedOptions): QueryIterator<T>;
|
||||
public readAll<T>(options?: FeedOptions): QueryIterator<T> {
|
||||
return this.client.readDocuments(this.container.url, options) as QueryIterator<T>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a item.
|
||||
* <p>
|
||||
* There is no set schema for JSON items. They may contain any number of custom properties as \
|
||||
* well as an optional list of attachments. <br>
|
||||
* A item is an application resource and can be authorized using the master key or resource keys
|
||||
* </p>
|
||||
* @param body - Represents the body of the item. Can contain any number of user defined properties.
|
||||
*/
|
||||
public async create(body: any, options?: RequestOptions): Promise<Response<any>>;
|
||||
public async create<T>(body: T, options?: RequestOptions): Promise<Response<T>>;
|
||||
public async create<T>(body: T, options?: RequestOptions): Promise<Response<T>> {
|
||||
return this.client.createDocument(this.container.url, body, options) as Promise<Response<T>>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Upsert an item.
|
||||
* <p>
|
||||
* There is no set schema for JSON items. They may contain any number of custom properties.<br>
|
||||
* An Item is an application resource and can be authorized using the master key or resource keys
|
||||
* </p>
|
||||
*/
|
||||
public async upsert(body: any, options?: RequestOptions): Promise<Response<any>>;
|
||||
public async upsert<T>(body: T, options?: RequestOptions): Promise<Response<T>>;
|
||||
public async upsert<T>(body: T, options?: RequestOptions): Promise<Response<T>> {
|
||||
return this.client.upsertDocument(this.container.url, body, options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
export { Item } from "./Item";
|
||||
export { Items } from "./Items";
|
|
@ -0,0 +1,20 @@
|
|||
import { Constants, UriFactory } from "../../common";
|
||||
import { CosmosClient } from "../../CosmosClient";
|
||||
import { RequestOptions, Response } from "../../request";
|
||||
import { OfferDefinition } from "./OfferDefinition";
|
||||
|
||||
export class Offer {
|
||||
|
||||
public get url() {
|
||||
return `/${Constants.Path.OffersPathSegment}/${this.id}`;
|
||||
}
|
||||
constructor(public readonly client: CosmosClient, public readonly id: string) {}
|
||||
|
||||
public read(options?: RequestOptions): Promise<Response<OfferDefinition>> {
|
||||
return this.client.documentClient.readOffer(this.url); // TODO: options?
|
||||
}
|
||||
|
||||
public replace(body: OfferDefinition, options?: RequestOptions): Promise<Response<OfferDefinition>> {
|
||||
return this.client.documentClient.replaceOffer(this.url, body); // TODO: options?
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
export interface OfferDefinition {
|
||||
id?: string;
|
||||
offerType?: string; // TODO: enum?
|
||||
offerVersion?: string; // TODO: enum?
|
||||
resource?: string;
|
||||
offerResourceId?: string;
|
||||
content?: {
|
||||
offerThroughput: number;
|
||||
offerIsRUPerMinuteThroughputEnabled: boolean;
|
||||
};
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
import { CosmosClient } from "../../CosmosClient";
|
||||
import { SqlQuerySpec } from "../../queryExecutionContext";
|
||||
import { QueryIterator } from "../../queryIterator";
|
||||
import { FeedOptions } from "../../request";
|
||||
import { Offer } from "./Offer";
|
||||
import { OfferDefinition } from "./OfferDefinition";
|
||||
|
||||
export class Offers {
|
||||
constructor(public readonly client: CosmosClient) {}
|
||||
|
||||
public get(id: string) {
|
||||
return new Offer(this.client, id);
|
||||
}
|
||||
public query(query: SqlQuerySpec, options?: FeedOptions): QueryIterator<OfferDefinition> {
|
||||
return this.client.documentClient.queryOffers(query, options);
|
||||
}
|
||||
|
||||
public readAll(options?: FeedOptions): QueryIterator<OfferDefinition> {
|
||||
return this.client.documentClient.readOffers(options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
export { Offer} from "./Offer";
|
||||
export { Offers } from "./Offers";
|
||||
export { OfferDefinition } from "./OfferDefinition";
|
|
@ -0,0 +1,27 @@
|
|||
import { Constants, UriFactory } from "../../common";
|
||||
import { CosmosClient } from "../../CosmosClient";
|
||||
import { Response } from "../../request";
|
||||
import { RequestOptions } from "../../request/RequestOptions";
|
||||
import { User } from "../User";
|
||||
import { PermissionDefinition } from "./PermissionDefinition";
|
||||
|
||||
export class Permission {
|
||||
public get url() {
|
||||
return UriFactory.createPermissionUri(this.user.database.id, this.user.id, this.id);
|
||||
}
|
||||
private client: CosmosClient;
|
||||
constructor(public readonly user: User, public readonly id: string) {
|
||||
this.client = this.user.database.client;
|
||||
}
|
||||
public read(options?: RequestOptions): Promise<Response<PermissionDefinition>> {
|
||||
return this.client.documentClient.readPermission(this.url, options);
|
||||
}
|
||||
|
||||
public replace(body: PermissionDefinition, options?: RequestOptions): Promise<Response<PermissionDefinition>> {
|
||||
return this.client.documentClient.replacePermission(this.url, body, options);
|
||||
}
|
||||
|
||||
public delete(options?: RequestOptions): Promise<Response<PermissionDefinition>> {
|
||||
return this.client.documentClient.deletePermission(this.url, options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
import { PermissionMode } from "../../documents";
|
||||
|
||||
export interface PermissionDefinition {
|
||||
/** The id of the permission */
|
||||
id?: string;
|
||||
/** The mode of the permission, must be a value of {@link PermissionMode} */
|
||||
permissionMode: PermissionMode;
|
||||
/** The link of the resource that the permission will be applied to. */
|
||||
resource: string;
|
||||
resourcePartitionKey?: string | any[]; // TODO: what's allowed here?
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
import { CosmosClient } from "../../CosmosClient";
|
||||
import { SqlQuerySpec } from "../../queryExecutionContext";
|
||||
import { QueryIterator } from "../../queryIterator";
|
||||
import { FeedOptions, RequestOptions, Response } from "../../request";
|
||||
import { User } from "../User";
|
||||
import { Permission } from "./Permission";
|
||||
import { PermissionDefinition } from "./PermissionDefinition";
|
||||
|
||||
export class Permissions {
|
||||
private client: CosmosClient;
|
||||
constructor(public readonly user: User) {
|
||||
this.client = this.user.database.client;
|
||||
}
|
||||
|
||||
public get(id: string): Permission {
|
||||
return new Permission(this.user, id);
|
||||
}
|
||||
|
||||
public query(query: SqlQuerySpec, options?: FeedOptions): QueryIterator<PermissionDefinition> {
|
||||
return this.client.documentClient
|
||||
.queryPermissions(this.user.url, query, options) as QueryIterator<PermissionDefinition>;
|
||||
}
|
||||
|
||||
public readAll(options?: FeedOptions): QueryIterator<PermissionDefinition> {
|
||||
return this.client.documentClient
|
||||
.readPermissions(this.user.url, options) as QueryIterator<PermissionDefinition>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a permission.
|
||||
* <p> A permission represents a per-User Permission to access a specific resource \
|
||||
* e.g. Item or Container. </p>
|
||||
* @param body - Represents the body of the permission.
|
||||
* @param {string} body.id - The id of the permission
|
||||
* @param {string} body.permissionMode - The mode of the permission, must be a value of {@link PermissionMode}
|
||||
* @param {string} body.resource - The link of the resource that the permission will be applied to.
|
||||
*/
|
||||
public create(
|
||||
body: PermissionDefinition,
|
||||
options?: RequestOptions,
|
||||
): Promise<Response<PermissionDefinition>> {
|
||||
return this.client.documentClient.createPermission(this.user.url, body, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Upsert a permission.
|
||||
* <p> A permission represents a per-User Permission to access a \
|
||||
* specific resource e.g. Item or Cotnainer. </p>
|
||||
*/
|
||||
public upsert(
|
||||
body: PermissionDefinition,
|
||||
options?: RequestOptions,
|
||||
): Promise<Response<PermissionDefinition>> {
|
||||
return this.client.documentClient.upsertPermission(this.user.url, body, options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
export { Permission} from "./Permission";
|
||||
export { Permissions } from "./Permissions";
|
||||
export { PermissionDefinition } from "./PermissionDefinition";
|
|
@ -0,0 +1,35 @@
|
|||
import { Constants, UriFactory } from "../../common";
|
||||
import { DocumentClient } from "../../documentclient";
|
||||
import { RequestOptions, Response } from "../../request";
|
||||
import { Container } from "../Container";
|
||||
import { StoredProcedureDefinition } from "./StoredProcedureDefinition";
|
||||
|
||||
export class StoredProcedure {
|
||||
private client: DocumentClient;
|
||||
public get url() {
|
||||
return UriFactory.createStoredProcedureUri(this.container.database.id, this.container.id, this.id);
|
||||
}
|
||||
constructor(public readonly container: Container, public readonly id: string) {
|
||||
this.client = this.container.database.client.documentClient;
|
||||
}
|
||||
|
||||
public read(options?: RequestOptions): Promise<Response<StoredProcedureDefinition>> {
|
||||
return this.client.readStoredProcedure(this.url, options);
|
||||
}
|
||||
|
||||
public replace(
|
||||
body: StoredProcedureDefinition,
|
||||
options?: RequestOptions,
|
||||
): Promise<Response<StoredProcedureDefinition>> {
|
||||
return this.client.replaceStoredProcedure(this.url, body, options);
|
||||
}
|
||||
|
||||
public delete(options?: RequestOptions): Promise<Response<StoredProcedureDefinition>> {
|
||||
return this.client.deleteStoredProcedure(this.url, options);
|
||||
}
|
||||
|
||||
public execute(params?: any[], options?: RequestOptions): Promise<Response<any>>;
|
||||
public execute<T>(params?: any[], options?: RequestOptions): Promise<Response<T>> {
|
||||
return this.client.executeStoredProcedure(this.url, params, options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
export interface StoredProcedureDefinition {
|
||||
id?: string;
|
||||
body?: string | ((...inputs: any[]) => void);
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
import { CosmosClient } from "../../CosmosClient";
|
||||
import { SqlQuerySpec } from "../../queryExecutionContext";
|
||||
import { QueryIterator } from "../../queryIterator";
|
||||
import { FeedOptions, RequestOptions, Response } from "../../request";
|
||||
import { Container } from "../Container";
|
||||
import { StoredProcedure } from "./StoredProcedure";
|
||||
import { StoredProcedureDefinition } from "./StoredProcedureDefinition";
|
||||
|
||||
export class StoredProcedures {
|
||||
private client: CosmosClient;
|
||||
constructor(public readonly container: Container) {
|
||||
this.client = this.container.database.client;
|
||||
}
|
||||
|
||||
public get(id: string): StoredProcedure {
|
||||
return new StoredProcedure(this.container, id);
|
||||
}
|
||||
public query(query: SqlQuerySpec, options?: FeedOptions): QueryIterator<StoredProcedureDefinition> {
|
||||
return this.client.documentClient.queryStoredProcedures(this.container.url, query, options);
|
||||
}
|
||||
|
||||
public readAll(options?: FeedOptions): QueryIterator<StoredProcedureDefinition> {
|
||||
return this.client.documentClient.readStoredProcedures(this.container.url, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a StoredProcedure.
|
||||
* <p>
|
||||
* Azure Cosmos DB allows stored procedures to be executed in the storage tier, \
|
||||
* directly against an item container. The script <br>
|
||||
* gets executed under ACID transactions on the primary storage partition of the \
|
||||
* specified container. For additional details, <br>
|
||||
* refer to the server-side JavaScript API documentation.
|
||||
* </p>
|
||||
*/
|
||||
public async create(
|
||||
body: StoredProcedureDefinition,
|
||||
options?: RequestOptions,
|
||||
): Promise<Response<StoredProcedureDefinition>> {
|
||||
return this.client.documentClient.createStoredProcedure(this.container.url, body, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Upsert a StoredProcedure.
|
||||
* <p>
|
||||
* Azure Cosmos DB allows stored procedures to be executed in the storage tier,
|
||||
* directly against a document container. The script <br>
|
||||
* gets executed under ACID transactions on the primary storage partition of the
|
||||
* specified container. For additional details, <br>
|
||||
* refer to the server-side JavaScript API documentation.
|
||||
* </p>
|
||||
*/
|
||||
public async upsert(
|
||||
body: StoredProcedureDefinition,
|
||||
options?: RequestOptions,
|
||||
): Promise<Response<StoredProcedureDefinition>> {
|
||||
return this.client.documentClient.upsertStoredProcedure(this.container.url, body, options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
export { StoredProcedure } from "./StoredProcedure";
|
||||
export { StoredProcedures } from "./StoredProcedures";
|
||||
export { StoredProcedureDefinition } from "./StoredProcedureDefinition";
|
|
@ -0,0 +1,29 @@
|
|||
import { Constants, UriFactory } from "../../common";
|
||||
import { CosmosClient } from "../../CosmosClient";
|
||||
import { RequestOptions, Response } from "../../request";
|
||||
import { Container } from "../Container";
|
||||
import { TriggerDefinition } from "./TriggerDefinition";
|
||||
|
||||
export class Trigger {
|
||||
public get url() {
|
||||
return UriFactory.createTriggerUri(this.container.database.id, this.container.id, this.id);
|
||||
}
|
||||
|
||||
private client: CosmosClient;
|
||||
|
||||
constructor(public readonly container: Container, public readonly id: string) {
|
||||
this.client = this.container.database.client;
|
||||
}
|
||||
|
||||
public read(options?: RequestOptions): Promise<Response<TriggerDefinition>> {
|
||||
return this.client.documentClient.readTrigger(this.url, options);
|
||||
}
|
||||
|
||||
public replace(body: TriggerDefinition, options?: RequestOptions): Promise<Response<TriggerDefinition>> {
|
||||
return this.client.documentClient.replaceTrigger(this.url, body, options);
|
||||
}
|
||||
|
||||
public delete(options?: RequestOptions): Promise<Response<TriggerDefinition>> {
|
||||
return this.client.documentClient.deleteTrigger(this.url, options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
import { TriggerOperation, TriggerType } from "../../documents";
|
||||
|
||||
export interface TriggerDefinition {
|
||||
id?: string;
|
||||
/** The body of the trigger, it can also be passed as a stringifed function */
|
||||
body: (() => void) | string;
|
||||
/** The type of the trigger, should be one of the values of {@link TriggerType}. */
|
||||
triggerType: TriggerType;
|
||||
/** The trigger operation, should be one of the values of {@link TriggerOperation}. */
|
||||
triggerOperation: TriggerOperation;
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
import { CosmosClient } from "../../CosmosClient";
|
||||
import { SqlQuerySpec } from "../../queryExecutionContext";
|
||||
import { QueryIterator } from "../../queryIterator";
|
||||
import { FeedOptions, RequestOptions, Response } from "../../request";
|
||||
import { Container } from "../Container";
|
||||
import { Trigger } from "./Trigger";
|
||||
import { TriggerDefinition } from "./TriggerDefinition";
|
||||
|
||||
export class Triggers {
|
||||
private client: CosmosClient;
|
||||
constructor(public readonly container: Container) {
|
||||
this.client = this.container.database.client;
|
||||
}
|
||||
|
||||
public get(id: string): Trigger {
|
||||
return new Trigger(this.container, id);
|
||||
}
|
||||
|
||||
public query(query: SqlQuerySpec, options?: FeedOptions): QueryIterator<TriggerDefinition> {
|
||||
return this.client.documentClient
|
||||
.queryTriggers(this.container.url, query, options) as QueryIterator<TriggerDefinition>;
|
||||
}
|
||||
|
||||
public readAll(options?: FeedOptions): QueryIterator<TriggerDefinition> {
|
||||
return this.client.documentClient.readTriggers(this.container.url, options) as QueryIterator<TriggerDefinition>;
|
||||
}
|
||||
/**
|
||||
* Create a trigger.
|
||||
* <p>
|
||||
* Azure Cosmos DB supports pre and post triggers defined in JavaScript to be executed \
|
||||
* on creates, updates and deletes. <br>
|
||||
* For additional details, refer to the server-side JavaScript API documentation.
|
||||
* </p>
|
||||
*/
|
||||
public create(body: TriggerDefinition, options?: RequestOptions): Promise<Response<TriggerDefinition>> {
|
||||
return this.client.documentClient.createTrigger(this.container.url, body, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Upsert a trigger.
|
||||
* <p>
|
||||
* Azure Cosmos DB supports pre and post triggers defined in JavaScript to be
|
||||
* executed on creates, updates and deletes. <br>
|
||||
* For additional details, refer to the server-side JavaScript API documentation.
|
||||
* </p>
|
||||
*/
|
||||
public upsert(body: TriggerDefinition, options?: RequestOptions): Promise<Response<TriggerDefinition>> {
|
||||
return this.client.documentClient.upsertTrigger(this.container.url, body, options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
export { Trigger} from "./Trigger";
|
||||
export { Triggers } from "./Triggers";
|
||||
export { TriggerDefinition } from "./TriggerDefinition";
|
|
@ -0,0 +1,30 @@
|
|||
import { Constants, UriFactory } from "../../common";
|
||||
import { CosmosClient } from "../../CosmosClient";
|
||||
import { RequestOptions, Response } from "../../request";
|
||||
import { Database } from "../Database";
|
||||
import { Permissions } from "../Permission";
|
||||
import { UserDefinition } from "./UserDefinition";
|
||||
|
||||
export class User {
|
||||
public readonly permissions: Permissions;
|
||||
public get url() {
|
||||
return UriFactory.createUserUri(this.database.id, this.id);
|
||||
}
|
||||
private client: CosmosClient;
|
||||
constructor(public readonly database: Database, public readonly id: string) {
|
||||
this.client = this.database.client;
|
||||
this.permissions = new Permissions(this);
|
||||
}
|
||||
|
||||
public read(options?: RequestOptions): Promise<Response<UserDefinition>> {
|
||||
return this.client.documentClient.readUser(this.url, options);
|
||||
}
|
||||
|
||||
public replace(body: UserDefinition, options?: RequestOptions): Promise<Response<UserDefinition>> {
|
||||
return this.client.documentClient.replaceUser(this.url, body, options);
|
||||
}
|
||||
|
||||
public delete(options?: RequestOptions): Promise<Response<UserDefinition>> {
|
||||
return this.client.documentClient.deleteUser(this.url, options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
export interface UserDefinition {
|
||||
/** The id of the user. */
|
||||
id?: string;
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
import { CosmosClient } from "../../CosmosClient";
|
||||
import { SqlQuerySpec } from "../../queryExecutionContext";
|
||||
import { QueryIterator } from "../../queryIterator";
|
||||
import { FeedOptions, RequestOptions, Response } from "../../request";
|
||||
import { Database } from "../Database";
|
||||
import { User } from "./User";
|
||||
import { UserDefinition } from "./UserDefinition";
|
||||
|
||||
export class Users {
|
||||
private client: CosmosClient;
|
||||
constructor(public readonly database: Database) {
|
||||
this.client = this.database.client;
|
||||
}
|
||||
public get(id: string): User {
|
||||
return new User(this.database, id);
|
||||
}
|
||||
|
||||
public query(query: SqlQuerySpec, options?: FeedOptions): QueryIterator<UserDefinition> {
|
||||
return this.client.documentClient.queryUsers(this.database.url, query, options);
|
||||
}
|
||||
|
||||
public readAll(options?: FeedOptions): QueryIterator<UserDefinition> {
|
||||
return this.client.documentClient.readUsers(this.database.url, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a database user.
|
||||
* @param body - Represents the body of the user.
|
||||
*/
|
||||
public create(
|
||||
body: UserDefinition,
|
||||
options?: RequestOptions,
|
||||
): Promise<Response<UserDefinition>> {
|
||||
return this.client.documentClient.createUser(this.database.url, body, options);
|
||||
}
|
||||
|
||||
public upsert(
|
||||
body: UserDefinition,
|
||||
options?: RequestOptions,
|
||||
): Promise<Response<UserDefinition>> {
|
||||
return this.client.documentClient.upsertUser(this.database.url, body, options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
export { User } from "./User";
|
||||
export { Users } from "./Users";
|
||||
export { UserDefinition } from "./UserDefinition";
|
|
@ -0,0 +1,31 @@
|
|||
import { Constants, UriFactory } from "../../common";
|
||||
import { CosmosClient } from "../../CosmosClient";
|
||||
import { RequestOptions, Response } from "../../request";
|
||||
import { Container } from "../Container";
|
||||
import { UserDefinedFunctionDefinition } from "./UserDefinedFunctionDefinition";
|
||||
|
||||
export class UserDefinedFunction {
|
||||
|
||||
public get url() {
|
||||
return UriFactory.createUserDefinedFunctionUri(this.container.database.id, this.container.id, this.id);
|
||||
}
|
||||
private client: CosmosClient;
|
||||
constructor(public readonly container: Container, public readonly id: string) {
|
||||
this.client = this.container.database.client;
|
||||
}
|
||||
|
||||
public read(options?: RequestOptions): Promise<Response<UserDefinedFunctionDefinition>> {
|
||||
return this.client.documentClient.readUserDefinedFunction(this.url, options);
|
||||
}
|
||||
|
||||
public replace(
|
||||
body: UserDefinedFunctionDefinition,
|
||||
options?: RequestOptions,
|
||||
): Promise<Response<UserDefinedFunctionDefinition>> {
|
||||
return this.client.documentClient.replaceUserDefinedFunction(this.url, body, options);
|
||||
}
|
||||
|
||||
public delete(options?: RequestOptions): Promise<Response<UserDefinedFunctionDefinition>> {
|
||||
return this.client.documentClient.deleteUserDefinedFunction(this.url, options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
export interface UserDefinedFunctionDefinition {
|
||||
id?: string;
|
||||
/** The body of the user defined function, it can also be passed as a stringifed function */
|
||||
body?: string | (() => void);
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
import { CosmosClient } from "../../CosmosClient";
|
||||
import { SqlQuerySpec } from "../../queryExecutionContext";
|
||||
import { QueryIterator } from "../../queryIterator";
|
||||
import { FeedOptions, RequestOptions, Response } from "../../request";
|
||||
import { Container } from "../Container";
|
||||
import { UserDefinedFunction } from "./UserDefinedFunction";
|
||||
import { UserDefinedFunctionDefinition } from "./UserDefinedFunctionDefinition";
|
||||
|
||||
export class UserDefinedFunctions {
|
||||
private client: CosmosClient;
|
||||
constructor(public readonly container: Container) {
|
||||
this.client = this.container.database.client;
|
||||
}
|
||||
|
||||
public get(id: string): UserDefinedFunction {
|
||||
return new UserDefinedFunction(this.container, id);
|
||||
}
|
||||
|
||||
public query(query: SqlQuerySpec, options?: FeedOptions): QueryIterator<UserDefinedFunctionDefinition> {
|
||||
return this.client.documentClient.queryUserDefinedFunctions(this.container.url, query, options);
|
||||
}
|
||||
|
||||
public readAll(options?: FeedOptions): QueryIterator<UserDefinedFunctionDefinition> {
|
||||
return this.client.documentClient.readUserDefinedFunctions(this.container.url, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a UserDefinedFunction.
|
||||
* <p>
|
||||
* Azure Cosmos DB supports JavaScript UDFs which can be used inside queries, stored procedures and triggers. <br>
|
||||
* For additional details, refer to the server-side JavaScript API documentation.
|
||||
* </p>
|
||||
*/
|
||||
public create(
|
||||
body: UserDefinedFunctionDefinition,
|
||||
options?: RequestOptions,
|
||||
): Promise<Response<UserDefinedFunctionDefinition>> {
|
||||
return this.client.documentClient.createUserDefinedFunction(this.container.url, body, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Upsert a UserDefinedFunction.
|
||||
* <p>
|
||||
* Azure Cosmos DB supports JavaScript UDFs which can be used inside queries, stored procedures and triggers. <br>
|
||||
* For additional details, refer to the server-side JavaScript API documentation.
|
||||
* </p>
|
||||
*/
|
||||
public upsert(
|
||||
body: UserDefinedFunctionDefinition,
|
||||
options?: RequestOptions,
|
||||
): Promise<Response<UserDefinedFunctionDefinition>> {
|
||||
return this.client.documentClient.upsertUserDefinedFunction(this.container.url, body, options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
export { UserDefinedFunction } from "./UserDefinedFunction";
|
||||
export { UserDefinedFunctions } from "./UserDefinedFunctions";
|
||||
export { UserDefinedFunctionDefinition } from "./UserDefinedFunctionDefinition";
|
|
@ -0,0 +1,10 @@
|
|||
export * from "./Conflict";
|
||||
export * from "./Container";
|
||||
export * from "./Database";
|
||||
export * from "./Item";
|
||||
export * from "./Offer";
|
||||
export * from "./Permission";
|
||||
export * from "./StoredProcedure";
|
||||
export * from "./Trigger";
|
||||
export * from "./User";
|
||||
export * from "./UserDefinedFunction";
|
|
@ -1,6 +1,4 @@
|
|||
import * as os from "os";
|
||||
import * as semaphore from "semaphore";
|
||||
import * as util from "util";
|
||||
import { Constants } from ".";
|
||||
|
||||
export class Platform {
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,23 @@
|
|||
import { IndexingMode } from ".";
|
||||
import { DataType, IndexKind } from "./documents";
|
||||
|
||||
export interface IndexingPolicy {
|
||||
/** The indexing mode (consistent or lazy) {@link IndexingMode}. */
|
||||
indexingMode?: IndexingMode;
|
||||
automatic?: boolean;
|
||||
/** An array of {@link IncludedPath} represents the paths to be included for indexing. */
|
||||
includedPaths?: IndexedPath[];
|
||||
/** An array of {@link IncludedPath} represents the paths to be excluded for indexing. */
|
||||
excludedPaths?: IndexedPath[];
|
||||
}
|
||||
|
||||
export interface IndexedPath {
|
||||
path: string;
|
||||
indexes?: Index[];
|
||||
}
|
||||
|
||||
export interface Index {
|
||||
kind: IndexKind;
|
||||
dataType: DataType;
|
||||
precision?: number;
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
import { PartitionKind } from "./documents";
|
||||
|
||||
export interface PartitionKeyDefinition {
|
||||
paths: string[];
|
||||
kind: PartitionKind;
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
import { Point, Range } from "../range";
|
||||
import { RetryOptions } from "../retry";
|
||||
import { PartitionKeyDefinition } from "./PartitionKeyDefinition";
|
||||
|
||||
export interface Document {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
export type PartitionKey = Point | Range;
|
||||
export type PartitionKey = PartitionKeyDefinition | Point | Range;
|
||||
|
||||
/**
|
||||
* <p>Represents the consistency levels supported for Azure Cosmos DB client operations.<br>
|
||||
|
@ -42,11 +42,11 @@ export enum ConsistencyLevel {
|
|||
* @enum {string}
|
||||
* @property Consistent <p>Index is updated synchronously with a create or update operation. <br>
|
||||
* With consistent indexing, query behavior is the same as the default consistency \
|
||||
* level for the collection. The index is
|
||||
* level for the container. The index is
|
||||
* always kept up to date with the data. </p>
|
||||
* @property Lazy <p>Index is updated asynchronously with respect to a create or update operation. <br>
|
||||
* With lazy indexing, queries are eventually consistent. The index is updated when the \
|
||||
* collection is idle.</p>
|
||||
* container is idle.</p>
|
||||
*/
|
||||
export enum IndexingMode {
|
||||
Consistent = "consistent",
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
export * from "./documents";
|
||||
export * from "./DatabaseAccount";
|
||||
export * from "./ConnectionPolicy";
|
||||
export * from "./IndexingPolicy";
|
||||
export * from "./PartitionKeyDefinition";
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import * as url from "url";
|
||||
import { Constants } from "./common";
|
||||
import { DocumentClient } from "./documentclient";
|
||||
import { DocumentClientBase } from "./DocumentClientBase";
|
||||
import { DatabaseAccount, LocationsType } from "./documents";
|
||||
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
import * as DocumentBase from "./documents";
|
||||
|
||||
export { DocumentClient, DocumentClient as CosmosClient } from "./documentclient";
|
||||
export { DocumentClient } from "./documentclient";
|
||||
export { DocumentBase, DocumentBase as AzureDocuments };
|
||||
export { Range, RangePartitionResolver } from "./range";
|
||||
export { HashPartitionResolver } from "./hash";
|
||||
export { Constants, UriFactory } from "./common";
|
||||
export { Base } from "./base";
|
||||
export { RetryOptions } from "./retry";
|
||||
export { Response } from "./request";
|
||||
export { Response, RequestOptions, FeedOptions, MediaOptions, ErrorResponse } from "./request/";
|
||||
|
||||
export { IHeaders } from "./queryExecutionContext";
|
||||
export { QueryIterator } from "./queryIterator";
|
||||
|
||||
export {CosmosClient} from "./CosmosClient";
|
||||
export {CosmosClientOptions} from "./CosmosClientOptions";
|
||||
export * from "./client/";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { IHeaders } from "..";
|
||||
import { Response } from "../../request";
|
||||
import { Response } from "../../request/request";
|
||||
import { AverageAggregator, CountAggregator, MaxAggregator, MinAggregator, SumAggregator } from "../Aggregators";
|
||||
import { IExecutionContext } from "../IExecutionContext";
|
||||
import { IEndpointComponent } from "./IEndpointComponent";
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import { IHeaders } from "..";
|
||||
import { Response } from "../../request";
|
||||
import { Response } from "../../request/request";
|
||||
|
||||
export interface IEndpointComponent {
|
||||
nextItem: () => Promise<Response<any>>;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import { IHeaders } from "..";
|
||||
import { Response } from "../../request";
|
||||
import { Response } from "../../request/request";
|
||||
import { IExecutionContext } from "../IExecutionContext";
|
||||
import { IEndpointComponent } from "./IEndpointComponent";
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import { IHeaders } from "..";
|
||||
import { Response } from "../../request";
|
||||
import { Response } from "../../request/request";
|
||||
import { IExecutionContext } from "../IExecutionContext";
|
||||
import { IEndpointComponent } from "./IEndpointComponent";
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import { IHeaders } from ".";
|
||||
import { Response } from "../request";
|
||||
import { Response } from "../request/request";
|
||||
|
||||
export interface IExecutionContext {
|
||||
nextItem: () => Promise<Response<any>>;
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
export interface IHeaders {
|
||||
[key: string]: string | boolean | number;
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
import { IExecutionContext, IHeaders } from ".";
|
||||
import { Base } from "../base";
|
||||
import { IExecutionContext } from ".";
|
||||
import { Constants } from "../common";
|
||||
import { DocumentClient } from "../documentclient";
|
||||
import { ClientSideMetrics, QueryMetrics } from "../queryMetrics";
|
||||
|
|
|
@ -3,7 +3,7 @@ import { FetchFunctionCallback, SqlQuerySpec } from ".";
|
|||
import { Base } from "../base";
|
||||
import { Constants, StatusCodes, SubStatusCodes } from "../common";
|
||||
import { DocumentClient } from "../documentclient";
|
||||
import { Response } from "../request";
|
||||
import { Response } from "../request/request";
|
||||
import { DefaultQueryExecutionContext } from "./defaultQueryExecutionContext";
|
||||
import { FetchResult, FetchResultType } from "./FetchResult";
|
||||
import { HeaderUtils, IHeaders } from "./headerUtils";
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import * as assert from "assert";
|
||||
import {
|
||||
DocumentProducer,
|
||||
IExecutionContext,
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
import * as assert from "assert";
|
||||
import {
|
||||
DocumentProducer,
|
||||
HeaderUtils,
|
||||
IExecutionContext,
|
||||
ParallelQueryExecutionContextBase,
|
||||
PartitionedQueryExecutionContextInfo,
|
||||
} from ".";
|
||||
import { Constants } from "../common";
|
||||
import { DocumentClient } from "../documentclient";
|
||||
import { InMemoryCollectionRoutingMap, PARITIONKEYRANGE } from "../routing";
|
||||
import { PARITIONKEYRANGE } from "../routing";
|
||||
|
||||
export class ParallelQueryExecutionContext extends ParallelQueryExecutionContextBase implements IExecutionContext {
|
||||
/**
|
||||
|
|
|
@ -14,7 +14,7 @@ import {
|
|||
} from ".";
|
||||
import { Constants, StatusCodes, SubStatusCodes } from "../common";
|
||||
import { DocumentClient } from "../documentclient";
|
||||
import { Response } from "../request";
|
||||
import { Response } from "../request/request";
|
||||
import { InMemoryCollectionRoutingMap, PARITIONKEYRANGE, QueryRange, SmartRoutingMapProvider } from "../routing";
|
||||
|
||||
export enum ParallelQueryExecutionContextBaseStates {
|
||||
|
@ -153,7 +153,6 @@ export abstract class ParallelQueryExecutionContextBase implements IExecutionCon
|
|||
} catch (err) {
|
||||
this._mergeWithActiveResponseHeaders(err.headers);
|
||||
this.err = err;
|
||||
throw err;
|
||||
} finally {
|
||||
parallelismSem.leave();
|
||||
this._decrementInitiationLock();
|
||||
|
@ -297,7 +296,7 @@ export abstract class ParallelQueryExecutionContextBase implements IExecutionCon
|
|||
}
|
||||
};
|
||||
// Invoke the recursive function to get the ball rolling
|
||||
checkAndEnqueueDocumentProducers(replacementDocumentProducers);
|
||||
await checkAndEnqueueDocumentProducers(replacementDocumentProducers);
|
||||
} catch (err) {
|
||||
this.err = err;
|
||||
throw err;
|
||||
|
@ -455,7 +454,7 @@ export abstract class ParallelQueryExecutionContextBase implements IExecutionCon
|
|||
// invoke the callback on the item
|
||||
return resolve({result: item, headers: this._getAndResetActiveResponseHeaders()});
|
||||
};
|
||||
this._repairExecutionContextIfNeeded(ifCallback, elseCallback);
|
||||
this._repairExecutionContextIfNeeded(ifCallback, elseCallback).catch(reject);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -494,7 +493,7 @@ export abstract class ParallelQueryExecutionContextBase implements IExecutionCon
|
|||
return resolve(documentProducer.current());
|
||||
};
|
||||
|
||||
this._repairExecutionContextIfNeeded(ifCallback, elseCallback);
|
||||
this._repairExecutionContextIfNeeded(ifCallback, elseCallback).catch(reject);
|
||||
} finally {
|
||||
this.sem.leave();
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import {
|
|||
PartitionedQueryExecutionContextInfoParser,
|
||||
} from ".";
|
||||
import { DocumentClient } from "../documentclient";
|
||||
import { Response } from "../request";
|
||||
import { Response } from "../request/request";
|
||||
import {
|
||||
AggregateEndpointComponent,
|
||||
IEndpointComponent,
|
||||
|
|
|
@ -10,7 +10,7 @@ import {
|
|||
} from ".";
|
||||
import { StatusCodes, SubStatusCodes } from "../common";
|
||||
import { DocumentClient } from "../documentclient";
|
||||
import { Response } from "../request";
|
||||
import { Response } from "../request/request";
|
||||
|
||||
export class ProxyQueryExecutionContext implements IExecutionContext {
|
||||
private queryExecutionContext: IExecutionContext;
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import { Base } from ".";
|
||||
import { Constants } from "./common";
|
||||
import { DocumentClient } from "./documentclient";
|
||||
import {
|
||||
FetchFunctionCallback,
|
||||
|
@ -8,12 +6,11 @@ import {
|
|||
ProxyQueryExecutionContext,
|
||||
SqlQuerySpec,
|
||||
} from "./queryExecutionContext";
|
||||
import { Response } from "./request";
|
||||
import { FeedOptions } from "./request/FeedOptions";
|
||||
import { Response } from "./request/request";
|
||||
|
||||
export type QueryIteratorCallback = (err: any, elements?: any, headers?: IHeaders) => boolean | void;
|
||||
|
||||
export class QueryIterator {
|
||||
private toArrayTempResources: any[];
|
||||
export class QueryIterator<T> {
|
||||
private toArrayTempResources: T[]; // TODO
|
||||
private toArrayLastResHeaders: IHeaders;
|
||||
private queryExecutionContext: IExecutionContext;
|
||||
/**
|
||||
|
@ -32,7 +29,7 @@ export class QueryIterator {
|
|||
constructor(
|
||||
private documentclient: DocumentClient,
|
||||
private query: SqlQuerySpec | string,
|
||||
private options: any, // TODO: any options
|
||||
private options: FeedOptions, // TODO: any options
|
||||
private fetchFunctions: FetchFunctionCallback | FetchFunctionCallback[],
|
||||
private resourceLink?: string | string[]) {
|
||||
|
||||
|
@ -52,9 +49,15 @@ export class QueryIterator {
|
|||
* Note: the last element the callback will be called on will be undefined.
|
||||
* If the callback explicitly returned false, the loop gets stopped.
|
||||
*/
|
||||
public forEach(callback: QueryIteratorCallback) {
|
||||
public async *forEach(): AsyncIterable<Response<T>> {
|
||||
this.reset();
|
||||
this._forEachImplementation(callback);
|
||||
while (this.queryExecutionContext.hasMoreResults()) {
|
||||
const result = await this.queryExecutionContext.nextItem();
|
||||
if (result.result === undefined) {
|
||||
return;
|
||||
}
|
||||
yield result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -64,13 +67,8 @@ export class QueryIterator {
|
|||
* @param {callback} callback - Function to execute for each element. \
|
||||
* the function takes two parameters error, element.
|
||||
*/
|
||||
public async nextItem(callback?: QueryIteratorCallback): Promise<Response<any>> {
|
||||
try {
|
||||
const p = await this.queryExecutionContext.nextItem();
|
||||
return Base.ResponseOrCallback(callback, p);
|
||||
} catch (err) {
|
||||
Base.ThrowOrCallback(callback, err);
|
||||
}
|
||||
public async nextItem(): Promise<Response<T>> {
|
||||
return this.queryExecutionContext.nextItem();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -80,13 +78,8 @@ export class QueryIterator {
|
|||
* @param {callback} callback - Function to execute for the current element. \
|
||||
* the function takes two parameters error, element.
|
||||
*/
|
||||
public async current(callback?: QueryIteratorCallback) {
|
||||
try {
|
||||
const p = await this.queryExecutionContext.current();
|
||||
return Base.ResponseOrCallback(callback, p);
|
||||
} catch (err) {
|
||||
Base.ThrowOrCallback(callback, err);
|
||||
}
|
||||
public async current(): Promise<Response<T>> {
|
||||
return this.queryExecutionContext.current();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -98,7 +91,7 @@ export class QueryIterator {
|
|||
* @instance
|
||||
* @returns {Boolean} true if there is other elements to process in the QueryIterator.
|
||||
*/
|
||||
public hasMoreResults() {
|
||||
public hasMoreResults(): boolean {
|
||||
return this.queryExecutionContext.hasMoreResults();
|
||||
}
|
||||
|
||||
|
@ -108,15 +101,13 @@ export class QueryIterator {
|
|||
* @instance
|
||||
* @param {callback} callback - Function execute on the feed response, takes two parameters error, resourcesList
|
||||
*/
|
||||
public async toArray(callback?: QueryIteratorCallback): Promise<Response<any[]>> {
|
||||
try {
|
||||
public async toArray(): Promise<Response<T[]>> {
|
||||
if (arguments.length !== 0) {
|
||||
throw new Error("toArray takes no arguments");
|
||||
}
|
||||
this.reset();
|
||||
this.toArrayTempResources = [];
|
||||
const p = await this._toArrayImplementation();
|
||||
return Base.ResponseOrCallback(callback, p);
|
||||
} catch (err) {
|
||||
Base.ThrowOrCallback(callback, err);
|
||||
}
|
||||
return this._toArrayImplementation();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -125,13 +116,8 @@ export class QueryIterator {
|
|||
* @instance
|
||||
* @param {callback} callback - Function execute on the feed response, takes two parameters error, resourcesList
|
||||
*/
|
||||
public async executeNext(callback?: QueryIteratorCallback) {
|
||||
try {
|
||||
const p = await this.queryExecutionContext.fetchMore();
|
||||
return Base.ResponseOrCallback(callback, p);
|
||||
} catch (err) {
|
||||
Base.ThrowOrCallback(callback, err);
|
||||
}
|
||||
public async executeNext(): Promise<Response<T>> {
|
||||
return this.queryExecutionContext.fetchMore();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -144,48 +130,20 @@ export class QueryIterator {
|
|||
}
|
||||
|
||||
/** @ignore */
|
||||
private async _toArrayImplementation(): Promise<Response<any>> {
|
||||
try {
|
||||
private async _toArrayImplementation(): Promise<Response<T[]>> {
|
||||
while (this.queryExecutionContext.hasMoreResults()) {
|
||||
const { result, headers } = await this.queryExecutionContext.nextItem();
|
||||
// concatinate the results and fetch more
|
||||
this.toArrayLastResHeaders = headers;
|
||||
|
||||
if (result === undefined) {
|
||||
|
||||
// no more results
|
||||
return { result: this.toArrayTempResources, headers: this.toArrayLastResHeaders };
|
||||
break;
|
||||
}
|
||||
|
||||
this.toArrayTempResources.push(result);
|
||||
|
||||
return this._toArrayImplementation();
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
/** @ignore */
|
||||
private async _forEachImplementation(
|
||||
callback: QueryIteratorCallback) { // TODO: any error
|
||||
try {
|
||||
const { result, headers } = await this.queryExecutionContext.nextItem();
|
||||
if (result === undefined) {
|
||||
// no more results. This is last iteration
|
||||
return callback(undefined, undefined, headers);
|
||||
}
|
||||
|
||||
if (callback(undefined, result, headers) === false) {
|
||||
// callback instructed to stop further iteration
|
||||
return;
|
||||
}
|
||||
|
||||
// recursively call itself to iterate to the remaining elements
|
||||
setImmediate(() => {
|
||||
this._forEachImplementation(callback);
|
||||
});
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
return { result: this.toArrayTempResources, headers: this.toArrayLastResHeaders };
|
||||
}
|
||||
|
||||
/** @ignore */
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { PartitionKey } from "../documents";
|
||||
|
||||
export type CompareFunction = (x: Point , y: Point) => number;
|
||||
|
||||
|
@ -113,7 +114,7 @@ export class Range {
|
|||
// tslint:disable-next-line:variable-name
|
||||
public static _isRange = Range.isRange;
|
||||
|
||||
public static isRange(pointOrRange: Point | Range) {
|
||||
public static isRange(pointOrRange: Point | Range | PartitionKey) {
|
||||
if (pointOrRange === undefined) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
import { IHeaders } from "..";
|
||||
|
||||
export interface ErrorResponse {
|
||||
code?: number;
|
||||
substatus?: number;
|
||||
body?: any;
|
||||
headers?: IHeaders;
|
||||
activityId?: string;
|
||||
retryAfterInMilliseconds?: number;
|
||||
[key: string]: any;
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
import { IHeaders } from "..";
|
||||
|
||||
/**
|
||||
* The feed options
|
||||
* @typedef {Object} FeedOptions - \
|
||||
* The feed options and query methods.
|
||||
* @property {string} [continuation] - Opaque token for continuing the enumeration.
|
||||
* @property {boolean} [disableRUPerMinuteUsage] - \
|
||||
* DisableRUPerMinuteUsage is used to enable/disable Request Units(RUs)/minute capacity to serve the \
|
||||
* request if regular provisioned RUs/second is exhausted.
|
||||
* @property {boolean} [enableCrossPartitionQuery] - \
|
||||
* A value indicating whether users are enabled to send more than one request to execute the query \
|
||||
* in the Azure Cosmos DB database service.
|
||||
* <p>More than one request is necessary if the query is not scoped to single partition key value.</p>
|
||||
* @property {boolean} [enableScanInQuery] - \
|
||||
* Allow scan on the queries which couldn't be served as indexing was opted out on the requested paths.
|
||||
* @property {number} [maxDegreeOfParallelism] - \
|
||||
* The maximum number of concurrent operations that run client side during parallel query execution \
|
||||
* in the Azure Cosmos DB database service. Negative values make the system automatically decides the \
|
||||
* number of concurrent operations to run.
|
||||
* @property {number} [maxItemCount] - \
|
||||
* Max number of items to be returned in the enumeration operation.
|
||||
* @property {string} [partitionKey] - \
|
||||
* Specifies a partition key definition for a particular path in the Azure Cosmos DB database service.
|
||||
* @property {string} [sessionToken] - Token for use with Session consistency.
|
||||
*/
|
||||
export interface FeedOptions {
|
||||
continuation?: string;
|
||||
disableRUPerMinuteUsage?: boolean;
|
||||
enableCrossPartitionQuery?: boolean;
|
||||
enableScanInQuery?: boolean;
|
||||
maxDegreeOfParallelism?: number;
|
||||
maxItemCount?: number;
|
||||
partitionKey?: string;
|
||||
sessionToken?: string;
|
||||
initialHeaders?: IHeaders;
|
||||
a_im?: string;
|
||||
accessCondition?: any; // TODO: any
|
||||
populateQueryMetrics?: boolean;
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
import { IHeaders } from "..";
|
||||
|
||||
/**
|
||||
* The media options
|
||||
* @typedef {Object} MediaOptions - Options associated with upload media.
|
||||
* @property {string} [slug] - HTTP Slug header value.
|
||||
* @property {string} [contentType=application/octet-stream] - HTTP ContentType header value.
|
||||
*
|
||||
*/
|
||||
export interface MediaOptions {
|
||||
initialHeaders?: IHeaders;
|
||||
slug?: string;
|
||||
contentType?: string;
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
import { IHeaders } from "..";
|
||||
import { PartitionKey } from "../documents";
|
||||
|
||||
/**
|
||||
* The request options
|
||||
* @typedef {Object} RequestOptions - \
|
||||
* Options that can be specified for a requested issued to the Azure Cosmos DB servers.
|
||||
* @property {object} [accessCondition] - \
|
||||
* Conditions Associated with the request.
|
||||
* @property {string} accessCondition.type - \
|
||||
* Conditional HTTP method header type (IfMatch or IfNoneMatch).
|
||||
* @property {string} accessCondition.condition - \
|
||||
* Conditional HTTP method header value (the _etag field from the last version you read).
|
||||
* @property {string} [consistencyLevel] - \
|
||||
* Consistency level required by the client.
|
||||
* @property {boolean} [disableRUPerMinuteUsage] - \
|
||||
* DisableRUPerMinuteUsage is used to enable/disable Request Units(RUs)/minute capacity to \
|
||||
* serve the request if regular provisioned RUs/second is exhausted.
|
||||
* @property {boolean} [enableScriptLogging] - \
|
||||
* Enables or disables logging in JavaScript stored procedures.
|
||||
* @property {string} [indexingDirective] - \
|
||||
* Specifies indexing directives (index, do not index .. etc).
|
||||
* @property {boolean} [offerEnableRUPerMinuteThroughput] - \
|
||||
* Represents Request Units(RU)/Minute throughput is enabled/disabled for a container \
|
||||
* in the Azure Cosmos DB database service.
|
||||
* @property {number} [offerThroughput] - \
|
||||
* The offer throughput provisioned for a container in measurement of Requests-per-Unit \
|
||||
* in the Azure Cosmos DB database service.
|
||||
* @property {string} [offerType] - Offer type when creating document containers.
|
||||
* <p>This option is only valid when creating a document container.</p>
|
||||
* @property {string} [partitionKey] - \
|
||||
* Specifies a partition key definition for a particular path in the Azure Cosmos DB database service.
|
||||
* @property {boolean} [populateQuotaInfo] - \
|
||||
* Enables/disables getting document container quota related stats for document container read requests.
|
||||
* @property {string} [postTriggerInclude] - \
|
||||
* Indicates what is the post trigger to be invoked after the operation.
|
||||
* @property {string} [preTriggerInclude] - \
|
||||
* Indicates what is the pre trigger to be invoked before the operation.
|
||||
* @property {number} [resourceTokenExpirySeconds] - \
|
||||
* Expiry time (in seconds) for resource token associated with permission (applicable only for requests on permissions).
|
||||
* @property {string} [sessionToken] - Token for use with Session consistency.
|
||||
*/
|
||||
|
||||
export interface RequestOptions {
|
||||
accessCondition?: {
|
||||
type: string;
|
||||
condition: string;
|
||||
};
|
||||
consistencyLevel?: string;
|
||||
disableRUPerMinuteUsage?: boolean;
|
||||
enableScriptLogging?: boolean;
|
||||
indexingDirective?: string;
|
||||
offerEnableRUPerMinuteThroughput?: boolean;
|
||||
offerThroughput?: number;
|
||||
offerType?: string;
|
||||
partitionKey?: PartitionKey;
|
||||
populateQuotaInfo?: boolean;
|
||||
postTriggerInclude?: string | string[];
|
||||
preTriggerInclude?: string | string[];
|
||||
resourceTokenExpirySeconds?: number;
|
||||
sessionToken?: string;
|
||||
initialHeaders?: IHeaders;
|
||||
urlConnection?: string;
|
||||
skipGetPartitionKeyDefinition?: boolean;
|
||||
disableAutomaticIdGeneration?: boolean;
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
import { IHeaders } from "..";
|
||||
|
||||
export interface Response<T> {
|
||||
headers?: IHeaders;
|
||||
result?: T;
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
export { ErrorResponse } from "./ErrorResponse";
|
||||
export { FeedOptions } from "./FeedOptions";
|
||||
export { MediaOptions } from "./MediaOptions";
|
||||
export { RequestHandler } from "./request";
|
||||
export { RequestOptions } from "./RequestOptions";
|
||||
export { Response } from "./Response";
|
|
@ -4,21 +4,17 @@ import { Socket } from "net";
|
|||
import * as querystring from "querystring";
|
||||
import { Stream } from "stream";
|
||||
import * as url from "url";
|
||||
import { Constants } from "./common";
|
||||
import { ConnectionPolicy, MediaReadMode } from "./documents";
|
||||
import { GlobalEndpointManager } from "./globalEndpointManager";
|
||||
import { IHeaders } from "./queryExecutionContext";
|
||||
import { Body, RetryUtility } from "./retry";
|
||||
import { Constants } from "../common";
|
||||
import { ConnectionPolicy, MediaReadMode } from "../documents";
|
||||
import { GlobalEndpointManager } from "../globalEndpointManager";
|
||||
import { IHeaders } from "../queryExecutionContext";
|
||||
import { Body, RetryUtility } from "../retry";
|
||||
|
||||
export interface ErrorResponse {
|
||||
code?: number;
|
||||
substatus?: number;
|
||||
body?: any;
|
||||
headers?: IHeaders;
|
||||
activityId?: string;
|
||||
retryAfterInMilliseconds?: number;
|
||||
[key: string]: any;
|
||||
}
|
||||
import { ErrorResponse } from "./ErrorResponse";
|
||||
export { ErrorResponse }; // Should refactor this out
|
||||
|
||||
import { Response } from "./Response";
|
||||
export { Response }; // Should refactor this out
|
||||
|
||||
const isBrowser = new Function("try {return this===window;}catch(e){ return false;}");
|
||||
|
||||
|
@ -49,11 +45,6 @@ function bodyFromData(data: Stream | Buffer | string | object) {
|
|||
|
||||
function parse(urlString: string) { return url.parse(urlString); }
|
||||
|
||||
export interface Response<T> {
|
||||
headers?: IHeaders;
|
||||
result?: T;
|
||||
}
|
||||
|
||||
function createRequestObject(
|
||||
connectionPolicy: ConnectionPolicy,
|
||||
requestOptions: RequestOptions,
|
|
@ -1,6 +1,6 @@
|
|||
import { Constants, StatusCodes } from "../common";
|
||||
import { GlobalEndpointManager } from "../globalEndpointManager";
|
||||
import { ErrorResponse } from "../request";
|
||||
import { ErrorResponse } from "../request/request";
|
||||
|
||||
/**
|
||||
* This class implements the retry policy for endpoint discovery.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { StatusCodes } from "../common";
|
||||
import { ErrorResponse } from "../request";
|
||||
import { ErrorResponse } from "../request/request";
|
||||
|
||||
/**
|
||||
* This class implements the resource throttle retry policy for requests.
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
import { Base } from "../base";
|
||||
import { Constants, StatusCodes, SubStatusCodes } from "../common";
|
||||
import { GlobalEndpointManager } from "../globalEndpointManager";
|
||||
import { ErrorResponse } from "../request";
|
||||
import { ErrorResponse } from "../request/request";
|
||||
|
||||
/**
|
||||
* This class implements the retry policy for session consistent reads.
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import * as assert from "assert";
|
||||
import * as bs from "binary-search-bounds"; // TODO: missing types
|
||||
import { Constants } from "../common";
|
||||
import { Range } from "../range";
|
||||
import { QueryRange } from "./QueryRange";
|
||||
|
||||
export class InMemoryCollectionRoutingMap {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import * as semaphore from "semaphore";
|
||||
import { Base } from "../base";
|
||||
import { QueryIterator } from "../queryIterator";
|
||||
import { CollectionRoutingMapFactory, InMemoryCollectionRoutingMap, QueryRange } from "./";
|
||||
|
||||
export class PartitionKeyRangeCache {
|
||||
|
@ -35,14 +36,13 @@ export class PartitionKeyRangeCache {
|
|||
if (collectionRoutingMap === undefined) {
|
||||
// attempt to consturct collection routing map
|
||||
collectionRoutingMap = await new Promise<InMemoryCollectionRoutingMap>((resolve, reject) => {
|
||||
const semaphorizedFuncCollectionMapInstantiator = () => {
|
||||
const semaphorizedFuncCollectionMapInstantiator = async () => {
|
||||
let crm: InMemoryCollectionRoutingMap = this.collectionRoutingMapByCollectionId[collectionId];
|
||||
if (crm === undefined) {
|
||||
const partitionKeyRangesIterator = this.documentclient.readPartitionKeyRanges(collectionLink);
|
||||
partitionKeyRangesIterator.toArray((err: Error, resources: any[]) => { // TODO: Promisification
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
try {
|
||||
const partitionKeyRangesIterator: QueryIterator<any> =
|
||||
this.documentclient.readPartitionKeyRanges(collectionLink);
|
||||
const { result: resources } = await partitionKeyRangesIterator.toArray();
|
||||
|
||||
crm = CollectionRoutingMapFactory.createCompleteRoutingMap(
|
||||
resources.map((r) => [r, true]),
|
||||
|
@ -51,7 +51,10 @@ export class PartitionKeyRangeCache {
|
|||
this.collectionRoutingMapByCollectionId[collectionId] = crm;
|
||||
this.sem.leave();
|
||||
resolve(crm);
|
||||
});
|
||||
} catch (err) {
|
||||
this.sem.leave();
|
||||
reject(err);
|
||||
}
|
||||
|
||||
} else {
|
||||
// sanity gaurd
|
||||
|
|
Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше
Загрузка…
Ссылка в новой задаче