You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Added error for CYCLE clause in WITH RECURSIVE page in 7.6.2 (#231)
* Added error for 7.6.2
* Added patch release
* [DOC-12129] base64 encoding/decoding functions in Eventing (Server 7.6.2) (#229)
* Added info about base64 functions
* Small update to language construct page
* DOC-11756: JavaScript language restrictions for JS-UDFs [Server 7.6.2] (#237)
* DOC-11756 Language Restrictions
* DOC-10013 Update title of calling JavaScript topic
* DOC-10013 Update JavaScript UDF introduction to describe inline and external functions
* DOC-10013 Add titles to diagram preview doc
* DOC-10013 Improve partial for external libraries and scopes
* DOC-10013 Add partial for SQL++ Managed UDFs
* DOC-10013 Minor wording updates for JavaScript UDF diagrams
* DOC-10013 Minor wording updates for JavaScript UDF reference
* DOC-10013 Update links for JavaScript UDF reference
* DOC-10013 Minor formatting updates for CREATE FUNCTION
* DOC-10013 These lines left blank intentionally
* DOC-10013 Add extra link to Calling SQL++ from JavaScript
* Remove unused nav partial for JavaScript UDFs
* Drive-by fix: link to Query Admin page
* Drive-by fix: replace SVG files with Kroki diagrams
* Updates after review
* DOC-12048: New indexer setting for default value of "defer build" (#239)
* Add section on deferring index builds by default
* Add horizontal style for all index arguments
* Use tables for object parameters
* Remove outdated version notices
* Minor formatting changes: consistent brackets, admonition placement
* Added note that you cannot use WITH NODES if you have enabled file-based index rebalancing
* [DOC-12139] Raise Dimensionality Support for Vector Search (#212)
* [DOC-12038] Added xattrs object to REST API example, create-search-index-payload.sh
Created a new example to show all of the nested JSON objects in a search index definition with nest-json-object-example.jsonc
Added an xattrs example to query-field-name.jsonc
Added xattrs to simple-search-index-payload.jsonc
Added a clarifying sentence to create-child-mapping.adoc
Added context about xattrs mapping to create-search-index-rest-api.adoc
Created create-xattrs-mapping.adoc
Added a link and then info on xattrs mappings to customize-index.adoc
Added info and examples on xattrs objects to search-index-params.adoc
Added examples for searching xattrs to search-request-params.adoc
Added create-xattrs-mapping to nav.adoc
* [DOC-12038] Adding note about xattrs support to search.adoc
Updating metafun and searchfun to explain accessing xattrs from Search Service in SQL++
* [DOC-12038] Adding note about travel sample docs not including xattrs
* [DOC-12139] Update the two mentions of dimensionality in vector-search-field-descriptions partial and create-vector-search-index-ui
* Revert "[DOC-12038] Adding note about travel sample docs not including xattrs"
This reverts commit ad934e8.
* Revert "[DOC-12038] Adding note about xattrs support to search.adoc"
This reverts commit 4c3f14d.
* Revert "[DOC-12038] Added xattrs object to REST API example, create-search-index-payload.sh"
This reverts commit 99e3c0f.
* [DOC-12139] Add version caveat to dimensionality changes.
* [DOC-12077] base64 Vector Embeddings (SERVER VERSION) (#213)
* [DOC-12077] Quick initial pass adding info on base64
Adding new field data type to field-data-types-reference and search-index-params
Updating properties in search-request-params, to include vector_base64
Modifying create-vector-search-index-ui to reflect base64 encoded strings - made additional updates for clarity, based on some feedback received
* [DOC-12077] Added vector-search-base64-document-example.json to show how the navy document looks with base64 encoded strings
Added example query for base64 vectors
Updated run-vector-search-ui.adoc to include example with base64 strings
* [DOC-12077] Add version caveat to all changes.
* [DOC-12077] Adding missing word and space
* [DOC-12077] Comments from writer review
* [DOC-12047] Edit JSON Query Requests in Couchbase Web Console (#209)
* [DOC-12047] Updating run-searches, simple-search-rest-api, simple-search-ui, and geo-search-ui to add more info about getting command line examples and editing query request JSON directly in the UI
* [DOC-12047] Adding caveats about required patch version.
* Change language around version caveat
* Change language around version caveat
* Update simple-search-ui.adoc
* [DOC-12074] Support match_none as the Default `query` object for Vector Searches (#210)
* [DOC-12074] Updating run-vector-search-payload-ui to remove the match_none object, as it's not necessary
Updating search-request-params and run-vector-search-ui to reflect that the match_none object is no longer required
* [DOC-12074] Removing "match_none" from SQL++ query example
* [DOC-12074] Adding version information to default match_none query object behaviour
* Update search-request-params.adoc
* [DOC-12038] Use XATTRS in Search Indexes, Search Queries, and SQL++ Search Functions (SERVER) (#211)
* [DOC-12038] Added xattrs object to REST API example, create-search-index-payload.sh
Created a new example to show all of the nested JSON objects in a search index definition with nest-json-object-example.jsonc
Added an xattrs example to query-field-name.jsonc
Added xattrs to simple-search-index-payload.jsonc
Added a clarifying sentence to create-child-mapping.adoc
Added context about xattrs mapping to create-search-index-rest-api.adoc
Created create-xattrs-mapping.adoc
Added a link and then info on xattrs mappings to customize-index.adoc
Added info and examples on xattrs objects to search-index-params.adoc
Added examples for searching xattrs to search-request-params.adoc
Added create-xattrs-mapping to nav.adoc
* [DOC-12038] Adding note about xattrs support to search.adoc
Updating metafun and searchfun to explain accessing xattrs from Search Service in SQL++
* [DOC-12038] Adding note about travel sample docs not including xattrs
* [DOC-12038] Add version limitation info to all changes.
* Update metafun.adoc
* Update searchfun.adoc
* Update customize-index.adoc
* Update search.adoc
* DOC-12187 File based rebalance now supports placing indexes on nodes (#234)
* Change statements about index placement with file-based rebalance enabled ito indicate it's no longer a restriction.
* Changes based on Varun's feedback.
* [DOC-12049] LOOKUPIN operation in Eventing (Server 7.6.2) (#230)
* Added subdocument LOOKUPIN operation to page
* Added new example page and made small changes to existing pages
* Added new page link to examples page
* Update eventing-advanced-keyspace-accessors.adoc
* Update eventing-handler-advancedLookupInOp.adoc
* Update eventing-advanced-keyspace-accessors.adoc
* Update nav.adoc for Server 7.6.2 (#241)
---------
Co-authored-by: Julia Browne <[email protected]>
Co-authored-by: Simon Dew <[email protected]>
Co-authored-by: Sarah Welton <[email protected]>
Co-authored-by: sarahlwelton <[email protected]>
Co-authored-by: Gary Gray <[email protected]>
You can use the optional fourth parameter `{ "self_recursion": true }` to prevent the suppression of recursive source bucket mutations and to process the mutations that you have just created.
708
712
709
713
If you do not add `{ "self_recursion": true }` to your operation, all source bucket mutations are suppressed.
This reference includes details of external functions using JavaScript.
15
18
16
-
If you want to learn how to create JavaScript function libraries using the administration console and/or the REST-API then take a look at the xref:guides:javascript-udfs.adoc[JavaScript UDF Guides].
19
+
include::partial$libraries-and-scopes.adoc[]
20
+
21
+
include::partial$sqlpp-managed-udfs.adoc[]
17
22
18
23
== Added Constructs
19
24
20
-
JavaScript functions in Couchbase support most of the language constructs available in https://en.wikipedia.org/wiki/ECMAScript[ECMAScript], though there are a number of restrictions related to the Couchbase environment.
25
+
JavaScript functions in {sqlpp} for Query support most of the language constructs available in https://en.wikipedia.org/wiki/ECMAScript[ECMAScript], though there are a number of restrictions related to the Couchbase environment.
21
26
There are also additions that have been made to the language for working specifically with Couchbase.
22
27
23
28
=== {sqlpp} Embedded Statements
24
29
25
30
Top level {sqlpp} keywords, such as SELECT, UPDATE, INSERT and DELETE, are available as inline keywords in functions.
26
-
Operations that return values such as SELECT are accessible through a returned iterable handle.
31
+
Operations that return values such as SELECT are accessible through a returned iterable handle.
27
32
{sqlpp} Query results, via a SELECT, are streamed in batches to the iterable handle as the iteration progresses through the result set.
28
33
34
+
.JavaScript code with embedded {sqlpp} statements
35
+
====
29
36
[source, javascript]
30
37
----
31
38
include::example$select-airline-inline.js[]
32
39
----
40
+
33
41
<1> The {sqlpp} is written directly into the JavaScript code without having to be used as part of a function call.
34
42
You can even provide parameters that can be used in the {sqlpp} statement.
35
43
<2> A standard JavaScript iterator is used to access the values returned from the {sqlpp} statement.
For more details, see xref:calling-n1ql-from-javascript.adoc[].
38
47
39
48
== Unsupported Features
40
49
50
+
The following features are not supported in JavaScript functions for Query.
51
+
41
52
=== Browser Extensions
42
53
43
-
Because JavaScript UDF functions do not execute in the context of a browser, the extensions that browsers add to the core language, such as window methods, DOM events etc. are not available.
54
+
Because JavaScript functions in {sqlpp} for Query do not execute in the context of a browser, the extensions that browsers add to the core language, such as window methods, DOM events, and so on, are not available.
44
55
45
56
=== Global State
46
-
All variables must be local to the function; global state is not permitted.
47
57
58
+
All variables must be local to the function; global state is not permitted.
59
+
60
+
.JavaScript code with global variable
61
+
====
48
62
[source, javascript]
49
63
----
50
64
include::example$illegal-global-variable.js[]
51
65
----
66
+
====
52
67
53
68
Along with global state, global https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions[arrow functions] are not supported.
54
69
Arrow functions local to individual JavaScript functions are supported.
@@ -57,11 +72,107 @@ Arrow functions local to individual JavaScript functions are supported.
57
72
58
73
Logging using the `console.log(..)` function is not supported.
59
74
60
-
In the rest of this section, you're going to look at the concepts behind JavaScript User-Defined Functions:
75
+
== Restricted Features
61
76
62
-
* xref:calling-javascript-from-n1ql.adoc[]
63
-
* xref:calling-n1ql-from-javascript.adoc[]
64
-
* xref:handling-errors-javascript-udf.adoc[]
77
+
[.status]#Couchbase Server 7.6.2#
78
+
79
+
The following features are restricted in JavaScript functions for Query in Couchbase Server 7.6.2 and later.
80
+
81
+
=== Code Injection
82
+
83
+
JavaScript constructs that may allow for code injection have been removed:
84
+
85
+
* The `eval` symbol has been removed.
86
+
* The `Function` construct has been removed.
87
+
88
+
.JavaScript code with the `eval` symbol
89
+
====
90
+
The following example does not compile as it uses the `eval` symbol.
91
+
92
+
[source,javascript]
93
+
----
94
+
function evaluate() {
95
+
var q = select jscode from <bucket> where meta().id = <docid>;
96
+
let iter = q[Symbol.iterator]();
97
+
let code = iter.next();
98
+
let result = eval(code);
99
+
}
100
+
----
101
+
====
102
+
103
+
.JavaScript code with the `Function` construct
104
+
====
105
+
The following example does not compile as it uses the `Function` construct.
106
+
107
+
[source,javascript]
108
+
----
109
+
function dynamicfunction() {
110
+
var q = select jscode from <bucket> where meta().id = <docid>;
111
+
let iter = q[Symbol.iterator]();
112
+
let code = iter.next();
113
+
return new Function("inject", code);
114
+
}
115
+
116
+
function evaluate() {
117
+
dynamicfunction();
118
+
}
119
+
----
120
+
====
121
+
122
+
=== Date Granularity
65
123
124
+
The granularity of the `Date` object has been reduced to 1 second.
125
+
This is to prevent a potential attacker from easily measuring the difference between a CPU cache miss and cache hit, hence taking advantage of side-channel attacks or speculative execution attacks.
66
126
127
+
.JavaScript code with timestamp
128
+
====
129
+
The following example executes a {sqlpp} query to insert a document with a field containing the current timestamp.
130
+
The timestamp is returned to the last second, rather than the most recent millisecond.
67
131
132
+
[source,javascript]
133
+
----
134
+
function addOrder() {
135
+
let curr = Date.now();
136
+
N1QL('INSERT INTO orders VALUES (uuid(),{"time":'+ curr +'})')
137
+
}
138
+
----
139
+
====
140
+
141
+
.JavaScript code with date comparison
142
+
====
143
+
The following example simulates sleep by blocking execution by the number of milliseconds passed as a function parameter.
144
+
Since the `Date.Now()` function does not return the current time with millisecond granularity, the function may not work as expected.
0 commit comments