@@ -1007,8 +1007,28 @@ WOQLClient.prototype.prepareRevisionControlArgs = function (rc_args) {
1007
1007
* "name" : "xsd:string",
1008
1008
* "perimeter" : { "@type " : "List",
1009
1009
* "@class" : "Coordinate" } }]
1010
- * client.addDocument(json,{"graph_type":"schema"},"mydb","add new schema")
1010
+ * client.addDocument(json,{"graph_type":"schema"},"mydb","add new schema documents ")
1011
1011
*
1012
+ * //if we would like to override the intire schema
1013
+ * const json = [
1014
+ * {"@base ": "terminusdb:///data/",
1015
+ * "@schema": "terminusdb:///schema#",
1016
+ * "@type": "@context"
1017
+ * },
1018
+ * {
1019
+ * "@id ": "Person",
1020
+ * "@key": {
1021
+ * "@type ": "Random"
1022
+ * },
1023
+ * "@type": "Class",
1024
+ * "name": {
1025
+ * "@class ": "xsd:string",
1026
+ * "@type": "Optional"
1027
+ * }
1028
+ * }]
1029
+ *
1030
+ * // client.addDocument(json,{"graph_type":"schema","full_replace:tue"},
1031
+ "mydb","update the all schema");
1012
1032
*
1013
1033
* // Here we will pass true to show how to get dataVersion
1014
1034
*
@@ -1559,7 +1579,7 @@ WOQLClient.prototype.userOrganizations = function (orgList) {
1559
1579
/**
1560
1580
* Apply a patch object to another object
1561
1581
* @param {object } before - The current state of JSON document
1562
- * @param {object } after - The patch object
1582
+ * @param {object } patch - The patch object
1563
1583
* @returns {Promise } A promise that returns the call response object, or an Error if rejected.
1564
1584
* @example
1565
1585
* client.patch(
@@ -1571,15 +1591,76 @@ WOQLClient.prototype.userOrganizations = function (orgList) {
1571
1591
* //result example
1572
1592
* //{ "@id" : "Person/Jane", "@type" : "Person", "name" : "Jannet" }
1573
1593
*/
1574
- WOQLClient . prototype . patch = function ( before , after ) {
1594
+ WOQLClient . prototype . patch = function ( before , patch ) {
1575
1595
if ( typeof before !== 'object' || typeof after !== 'object' ) {
1576
1596
const errmsg = '"before" or "after" parameter error - you must specify a valid before and after json document' ;
1577
1597
1578
1598
return Promise . reject (
1579
1599
new Error ( ErrorMessage . getInvalidParameterMessage ( CONST . PATCH , errmsg ) ) ,
1580
1600
) ;
1581
1601
}
1582
- const payload = { before, after } ;
1602
+ const payload = { before, patch } ;
1603
+
1604
+ return this . dispatch (
1605
+ CONST . POST ,
1606
+ `${ this . connectionConfig . apiURL ( ) } patch` ,
1607
+ payload ,
1608
+ ) . then ( ( response ) => response ) ;
1609
+ } ;
1610
+
1611
+ /**
1612
+ * Apply a patch object to the current resource
1613
+ * @param {array } patch - The patch object
1614
+ * @param {string } message - The commit message
1615
+ * @returns {Promise } A promise that returns the call response object, or an Error if rejected.
1616
+ * @example
1617
+ * const patch = [
1618
+ * {
1619
+ * "@id ": "Obj/id1",
1620
+ * "name": {
1621
+ * "@op ": "SwapValue",
1622
+ * "@before": "foo",
1623
+ * "@after": "bar"
1624
+ * }
1625
+ * },
1626
+ * {
1627
+ * "@id ": "Obj/id2",
1628
+ * "name": {
1629
+ * "@op ": "SwapValue",
1630
+ * "@before": "foo",
1631
+ * "@after": "bar"
1632
+ * }
1633
+ * }
1634
+ * ]
1635
+ * client.db("mydb")
1636
+ * client.checkout("mybranch")
1637
+ * client.patchResource(patch,"apply patch to mybranch").then(patchResult=>{
1638
+ * console.log(patchResult)
1639
+ * })
1640
+ * // result example
1641
+ * // ["Obj/id1",
1642
+ * // "Obj/id2"]
1643
+ * // or conflict error 409
1644
+ * // {
1645
+ * // "@type ": "api:PatchError",
1646
+ * // "api:status": "api:conflict",
1647
+ * // "api:witnesses": [
1648
+ * // {
1649
+ * // "@op ": "InsertConflict",
1650
+ * // "@id_already_exists": "Person/Jane"
1651
+ * // }
1652
+ * //]
1653
+ * //}
1654
+ */
1655
+ WOQLClient . prototype . patchResource = function ( patch , message ) {
1656
+ if ( ! Array . isArray ( patch ) ) {
1657
+ const errmsg = '"patch" parameter error - you must specify a valid patch document' ;
1658
+
1659
+ return Promise . reject (
1660
+ new Error ( ErrorMessage . getInvalidParameterMessage ( CONST . PATCH , errmsg ) ) ,
1661
+ ) ;
1662
+ }
1663
+ const payload = { patch, author : this . author ( ) , message } ;
1583
1664
1584
1665
return this . dispatch (
1585
1666
CONST . POST ,
0 commit comments