Skip to content

Commit bebabda

Browse files
osfameronjulia-cbsimon-dewsarahlweltonggray-cb
committed
Devex server 7.6.2 GA PR (#243)
* 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]>
1 parent 10c1492 commit bebabda

33 files changed

+475
-226
lines changed

modules/eventing/pages/eventing-advanced-keyspace-accessors.adoc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,7 @@ function OnUpdate(doc, meta) {
407407
[#advanced-touch-op]
408408
== Advanced TOUCH Operation
409409

410-
ifeval::['{page-component-version}' == '7.6']
411-
_(Introduced in Couchbase Server 7.6)_
412-
endif::[]
410+
[.status]#Couchbase Server 7.6#
413411

414412
`result = couchbase.touch(binding, meta)`
415413

@@ -465,6 +463,8 @@ function OnUpdate(doc, meta) {
465463
[#advanced-subdoc-array-op-mutatein]
466464
== Sub-Document MUTATEIN Operation
467465

466+
[.status]#Couchbase Server 7.6#
467+
468468
`result = couchbase.mutateIn(binding, meta, subdoc_operation_array, options)`
469469

470470
Sub-Document MUTATEIN operations let you modify only parts of a document instead of the entire document.
@@ -558,6 +558,8 @@ function OnUpdate(doc, meta, xattrs) {
558558
[#advanced-subdoc-array-op-lookupin]
559559
== Sub-Document LOOKUPIN Operation
560560

561+
[.status]#Couchbase Server 7.6.2#
562+
561563
`result = couchbase.lookupIn(binding, meta, subdoc_array, options)`
562564

563565
Sub-Document LOOKUPIN operations let you search for a specific field in a document without having to search and retrieve the entire document.
@@ -704,6 +706,8 @@ function OnUpdate(doc, meta) {
704706
[#optional-params-recursion]
705707
=== Optional `{ "self_recursion": true }` Parameter
706708

709+
[.status]#Couchbase Server 7.6#
710+
707711
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.
708712

709713
If you do not add `{ "self_recursion": true }` to your operation, all source bucket mutations are suppressed.

modules/guides/pages/.javascript-udfs.adoc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,14 @@ include::ROOT:partial$component-signpost.adoc[]
1616

1717
== Introduction
1818

19-
include::javascript-udfs:partial$javascript-udf-introduction.adoc[]
19+
{sqlpp} includes a large number of built-in operations and functions that cover every aspect of data manipulation.
20+
User-defined functions enable you to create your own extensions to the language.
21+
22+
Using user-defined functions, you can:
23+
24+
* Create reuseable, domain-specific functions for use in your applications.
25+
* Execute complex logic that may be difficult to do in {sqlpp}.
26+
* Migrate from RDBMS stored procedures.
2027

2128
== User-Defined Functions with JavaScript
2229

modules/guides/partials/javascript-udfs/diagrams.adoc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ left to right direction
2929
3030
actor "developer" as user
3131
32+
frame "Create library and add first function" as cAndA {
33+
[(1) Create library] as createLibrary
34+
[(2) Add the JavaScript function to the library] as addFunction
35+
createLibrary --> addFunction
36+
}
37+
3238
note top of cAndA #Ivory
3339
The library and the first function
3440
are usually added in the same step.
@@ -41,12 +47,6 @@ note right of cAndA #Ivory
4147
by users with access to a scope within a bucket.
4248
end note
4349
44-
frame "Create library and add first function" as cAndA {
45-
[(1) Create library] as createLibrary
46-
[(2) Add the JavaScript function to the library] as addFunction
47-
createLibrary --> addFunction
48-
}
49-
5050
user --> createLibrary
5151
[(3) Create {sqlpp} User-Defined Function] as createN1QL
5252

modules/javascript-udfs/pages/.calling-javascript-from-n1ql.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
= Calling JavaScript from {sqlpp} User-Defined Functions
1+
= Calling JavaScript from {sqlpp}
22
:description: Using a {sqlpp} User-Defined Function to call JavaScript functions.
33
ifndef::flag-devex-javascript-udfs[]
44
:page-embargo: EMBARGOED
Lines changed: 123 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
= JavaScript Functions with Couchbase
2-
:description: Writing Couchbase extension functions in the JavaScript Language.
1+
= JavaScript Functions for Query Reference
2+
:description: This reference guide describes how to write extension functions for {sqlpp} for Query using the JavaScript language.
33
ifndef::flag-devex-javascript-udfs[]
44
:page-embargo: EMBARGOED
55
endif::flag-devex-javascript-udfs[]
6+
:page-topic-type: reference
67
:page-toclevels: 2
8+
:keywords: library namespacing
79

810
[abstract]
911
{description}
@@ -12,43 +14,56 @@ endif::flag-devex-javascript-udfs[]
1214

1315
include::partial$javascript-udf-introduction.adoc[]
1416

17+
This reference includes details of external functions using JavaScript.
1518

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[]
1722

1823
== Added Constructs
1924

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.
2126
There are also additions that have been made to the language for working specifically with Couchbase.
2227

2328
=== {sqlpp} Embedded Statements
2429

2530
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.
2732
{sqlpp} Query results, via a SELECT, are streamed in batches to the iterable handle as the iteration progresses through the result set.
2833

34+
.JavaScript code with embedded {sqlpp} statements
35+
====
2936
[source, javascript]
3037
----
3138
include::example$select-airline-inline.js[]
3239
----
40+
3341
<1> The {sqlpp} is written directly into the JavaScript code without having to be used as part of a function call.
3442
You can even provide parameters that can be used in the {sqlpp} statement.
3543
<2> A standard JavaScript iterator is used to access the values returned from the {sqlpp} statement.
44+
====
3645

37-
include::partial$libraries-and-scopes.adoc[leveloffset=+2]
46+
For more details, see xref:calling-n1ql-from-javascript.adoc[].
3847

3948
== Unsupported Features
4049

50+
The following features are not supported in JavaScript functions for Query.
51+
4152
=== Browser Extensions
4253

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.
4455

4556
=== Global State
46-
All variables must be local to the function; global state is not permitted.
4757

58+
All variables must be local to the function; global state is not permitted.
59+
60+
.JavaScript code with global variable
61+
====
4862
[source, javascript]
4963
----
5064
include::example$illegal-global-variable.js[]
5165
----
66+
====
5267

5368
Along with global state, global https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions[arrow functions] are not supported.
5469
Arrow functions local to individual JavaScript functions are supported.
@@ -57,11 +72,107 @@ Arrow functions local to individual JavaScript functions are supported.
5772

5873
Logging using the `console.log(..)` function is not supported.
5974

60-
In the rest of this section, you're going to look at the concepts behind JavaScript User-Defined Functions:
75+
== Restricted Features
6176

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
65123

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.
66126

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.
67131
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.
145+
146+
[source,javascript]
147+
----
148+
function sleep(milliseconds) {
149+
let init = Date.now();
150+
let curr = null;
151+
do {
152+
curr = Date.now();
153+
} while (curr - init < milliseconds);
154+
}
155+
----
156+
====
157+
158+
== See Also
159+
160+
.User-Defined Function Guides
161+
* xref:guides:javascript-udfs.adoc[]
162+
* xref:n1ql:n1ql-intro/sysinfo.adoc#sys-functions[Monitor Functions]
163+
164+
.{sqlpp} User-Defined Function Commands
165+
* xref:n1ql:n1ql-language-reference/createfunction.adoc[]
166+
* xref:n1ql:n1ql-language-reference/explainfunction.adoc[]
167+
* xref:n1ql:n1ql-language-reference/execfunction.adoc[]
168+
* xref:n1ql:n1ql-language-reference/dropfunction.adoc[]
169+
* xref:n1ql:n1ql-language-reference/userfun.adoc[]
170+
171+
.External Libraries
172+
* xref:tools:udfs-ui.adoc[]
173+
* xref:n1ql:n1ql-rest-api/functions.adoc[]
174+
175+
.JavaScript Functions
176+
* xref:calling-javascript-from-n1ql.adoc[]
177+
* xref:calling-n1ql-from-javascript.adoc[]
178+
* xref:handling-errors-javascript-udf.adoc[]

modules/javascript-udfs/partials/diagrams.adoc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,37 @@
22
Previews the diagrams used in the JavaScript UDF section
33
////
44

5+
.Inline call sequence
56
[plantuml, subs=attributes]
67
....
78
include::diagrams/inline-call-sequence.puml[]
89
....
910

11+
.Transactions and iterators
1012
[plantuml, subs=attributes]
1113
....
1214
include::diagrams/transactions-and-iterators.puml[]
1315
....
1416

15-
17+
.Data transformation
1618
[plantuml, subs=attributes]
1719
....
1820
include::diagrams/data-transformation.puml[]
1921
....
2022

21-
.Scopes for JavaScript Libraries
23+
.UDF scopes
2224
[plantuml, subs=attributes]
2325
....
2426
include::diagrams/udf-scopes-diagram.puml[]
2527
....
2628

27-
.Using Multiple Scopes
29+
.Banking scope scenario
2830
[plantuml, subs=attributes]
2931
....
3032
include::diagrams/banking-scope-scenario.puml[]
3133
....
3234

33-
.JavaScript UDFs Structure
35+
.JavaScript scopes
3436
[plantuml]
3537
....
3638
include::diagrams/javascript-scopes.puml[]

modules/javascript-udfs/partials/diagrams/javascript-scopes.puml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@startuml
22

3-
frame Cluster {
3+
frame Namespace {
44

55
frame "global library" as globalLibrary #white {
66

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,8 @@
1-
////
2-
This is a reusable abstract the covers the main selling points of UDFs for the JavaScript section.
3-
Shouldn't be too JavaScript specific.
4-
////
5-
{sqlpp} includes a large number of
6-
ifdef::flag-devex-query[]
7-
xref:n1ql:n1ql-language-reference/index.adoc[operations and generic functions]
8-
endif::flag-devex-query[]
9-
ifndef::flag-devex-query[]
10-
operations and generic functions
11-
endif::flag-devex-query[]
12-
that cover every aspect of data manipulation.
13-
In addition to the built-in functions, Couchbase also allows you to create your own extensions to the language.
1+
There are two types of user-defined function in {sqlpp} for Query:
142

15-
Using user-defined functions, you can:
3+
* [.term]#Inline functions# are defined using {sqlpp} expressions.
4+
They enable you to name and reuse complex or repetitive expressions, including subqueries, in order to simplify your queries.
165
17-
* Create reuseable, domain-specific functions for use in your applications.
18-
* Execute complex logic that may be difficult to do in {sqlpp}.
19-
* Migrate from RDBMS stored procedures.
6+
* [.term]#External functions# are defined using an external language.
7+
They enable you to create functions that may be difficult or impossible to define using built-in {sqlpp} expressions.
8+
The only supported language is JavaScript.

0 commit comments

Comments
 (0)