Skip to content

Commit d841ad1

Browse files
committed
feat: add documents::incomingGlobalDocumentReferenceCount() and
documents::get()
1 parent 5fd3c5d commit d841ad1

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

spec/14-extensions.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,72 @@ geo_distance_validate(args):
198198

199199
- If the length of {args} is not 2:
200200
- Report an error.
201+
202+
## Documents Extension
203+
204+
Functions available in Documents extension are grouped under the `documents` namespace.
205+
206+
### Global Document Reference type
207+
208+
A Global Document Reference (GDR) type represents a reference to a document. The referenced document can be in a dataset separate from the dataset of the query context in the current scope.
209+
210+
A GDR consists of a string formatted to uniquely identify a dataset and a document within that dataset.
211+
212+
MatchesGDR({gdr}, {datasetID}, {documentID}):
213+
214+
- If {gdr} is not a string:
215+
- Return {false}.
216+
- If {gdr} is not in a valid Global Document Reference format:
217+
- Return {false}.
218+
- Let {gdrDatasetID} be the unique identifier for the dataset identified by {gdr}.
219+
- Let {gdrDocumentID} be the unique identifier for the document identified by {gdr}.
220+
- If {Equal(gdrDatasetID, datasetID)} is {true} and {Equal(gdrDatasetID, datasetID)} is {true}:
221+
- Return {true}.
222+
- Otherwise:
223+
- Return {false}.
224+
225+
### documents::get()
226+
227+
This function takes a Global Document Reference referencing a document and returns the document.
228+
229+
documents_get(args, scope):
230+
231+
- Let {gdrNode} be the first element of {args}.
232+
- Let {gdr} be the result of {Evaluate(gdrNode, scope)}.
233+
- If {gdr} is not a string:
234+
- Return {null}.
235+
- If {gdr} is not in a valid Global Document Reference format:
236+
- Return {null}.
237+
- Let {sources} be a list of other data sources in the query context of {scope}.
238+
- For each {source} in {sources}:
239+
- If {source} is a dataset:
240+
- Let {datasetID} be a unique identifier for the {source} dataset.
241+
- For each {document} in the {source} dataset:
242+
- If {document} is an object and has an attribute `_id`:
243+
- Let {documentID} be the value of the attribute `_id` in {document}.
244+
- If {MatchesGDR(gdr, datasetID, documentID)} is {true}:
245+
- return {document}.
246+
- Return {null}.
247+
248+
documents_get_validate(args, scope):
249+
250+
- If the length of {args} is not 1:
251+
- Report an error.
252+
253+
### documents::incomingGlobalDocumentReferenceCount()
254+
255+
This function returns the number of Global Document References referencing a document.
256+
257+
documents_incomingGlobalDocumentReferenceCount(args, scope):
258+
259+
- Let {document} be this value in {scope}.
260+
- Let {\_incomingGDRCount} be a property of {document} which represents the number of Global Document References referencing {document}. This property is updated whenever a Global Document Reference to {document} is created or deleted.
261+
- If {\_incomingGDRCount} is {null}:
262+
- Return {null}.
263+
- Otherwise:
264+
- Return {\_incomingGDRCount}.
265+
266+
documents_incomingGlobalDocumentReferenceCount_validate(args, scope):
267+
268+
- If the length of {args} is not 0:
269+
- Report an error.

0 commit comments

Comments
 (0)