1 | // Copyright (c) Microsoft Corporation.
|
2 | // Licensed under the MIT license.
|
3 | import { Constants } from "./constants";
|
4 | import { trimSlashFromLeftAndRight, validateResourceId, validateItemResourceId } from "./helper";
|
5 | /**
|
6 | * Would be used when creating or deleting a DocumentCollection
|
7 | * or a User in Azure Cosmos DB database service
|
8 | * @hidden
|
9 | * Given a database id, this creates a database link.
|
10 | * @param databaseId - The database id
|
11 | * @returns A database link in the format of `dbs/{0}`
|
12 | * with `{0}` being a Uri escaped version of the databaseId
|
13 | */
|
14 | export function createDatabaseUri(databaseId) {
|
15 | databaseId = trimSlashFromLeftAndRight(databaseId);
|
16 | validateResourceId(databaseId);
|
17 | return Constants.Path.DatabasesPathSegment + "/" + databaseId;
|
18 | }
|
19 | /**
|
20 | * Given a database and collection id, this creates a collection link.
|
21 | * Would be used when updating or deleting a DocumentCollection, creating a
|
22 | * Document, a StoredProcedure, a Trigger, a UserDefinedFunction, or when executing a query
|
23 | * with CreateDocumentQuery in Azure Cosmos DB database service.
|
24 | * @param databaseId - The database id
|
25 | * @param collectionId - The collection id
|
26 | * @returns A collection link in the format of `dbs/{0}/colls/{1}`
|
27 | * with `{0}` being a Uri escaped version of the databaseId and `{1}` being collectionId
|
28 | * @hidden
|
29 | */
|
30 | export function createDocumentCollectionUri(databaseId, collectionId) {
|
31 | collectionId = trimSlashFromLeftAndRight(collectionId);
|
32 | validateResourceId(collectionId);
|
33 | return (createDatabaseUri(databaseId) + "/" + Constants.Path.CollectionsPathSegment + "/" + collectionId);
|
34 | }
|
35 | /**
|
36 | * Given a database and user id, this creates a user link.
|
37 | * Would be used when creating a Permission, or when replacing or deleting
|
38 | * a User in Azure Cosmos DB database service
|
39 | * @param databaseId - The database id
|
40 | * @param userId - The user id
|
41 | * @returns A user link in the format of `dbs/{0}/users/{1}`
|
42 | * with `{0}` being a Uri escaped version of the databaseId and `{1}` being userId
|
43 | * @hidden
|
44 | */
|
45 | export function createUserUri(databaseId, userId) {
|
46 | userId = trimSlashFromLeftAndRight(userId);
|
47 | validateResourceId(userId);
|
48 | return createDatabaseUri(databaseId) + "/" + Constants.Path.UsersPathSegment + "/" + userId;
|
49 | }
|
50 | /**
|
51 | * Given a database and collection id, this creates a collection link.
|
52 | * Would be used when creating an Attachment, or when replacing
|
53 | * or deleting a Document in Azure Cosmos DB database service
|
54 | * @param databaseId - The database id
|
55 | * @param collectionId - The collection id
|
56 | * @param documentId - The document id
|
57 | * @returns A document link in the format of
|
58 | * `dbs/{0}/colls/{1}/docs/{2}` with `{0}` being a Uri escaped version of
|
59 | * the databaseId, `{1}` being collectionId and `{2}` being the documentId
|
60 | * @hidden
|
61 | */
|
62 | export function createDocumentUri(databaseId, collectionId, documentId) {
|
63 | documentId = trimSlashFromLeftAndRight(documentId);
|
64 | validateItemResourceId(documentId);
|
65 | return (createDocumentCollectionUri(databaseId, collectionId) +
|
66 | "/" +
|
67 | Constants.Path.DocumentsPathSegment +
|
68 | "/" +
|
69 | documentId);
|
70 | }
|
71 | /**
|
72 | * Given a database, collection and document id, this creates a document link.
|
73 | * Would be used when replacing or deleting a Permission in Azure Cosmos DB database service.
|
74 | * @param databaseId -The database Id
|
75 | * @param userId -The user Id
|
76 | * @param permissionId - The permissionId
|
77 | * @returns A permission link in the format of `dbs/{0}/users/{1}/permissions/{2}`
|
78 | * with `{0}` being a Uri escaped version of the databaseId, `{1}` being userId and `{2}` being permissionId
|
79 | * @hidden
|
80 | */
|
81 | export function createPermissionUri(databaseId, userId, permissionId) {
|
82 | permissionId = trimSlashFromLeftAndRight(permissionId);
|
83 | validateResourceId(permissionId);
|
84 | return (createUserUri(databaseId, userId) +
|
85 | "/" +
|
86 | Constants.Path.PermissionsPathSegment +
|
87 | "/" +
|
88 | permissionId);
|
89 | }
|
90 | /**
|
91 | * Given a database, collection and stored proc id, this creates a stored proc link.
|
92 | * Would be used when replacing, executing, or deleting a StoredProcedure in
|
93 | * Azure Cosmos DB database service.
|
94 | * @param databaseId -The database Id
|
95 | * @param collectionId -The collection Id
|
96 | * @param storedProcedureId -The stored procedure Id
|
97 | * @returns A stored procedure link in the format of
|
98 | * `dbs/{0}/colls/{1}/sprocs/{2}` with `{0}` being a Uri escaped version of the databaseId,
|
99 | * `{1}` being collectionId and `{2}` being the storedProcedureId
|
100 | * @hidden
|
101 | */
|
102 | export function createStoredProcedureUri(databaseId, collectionId, storedProcedureId) {
|
103 | storedProcedureId = trimSlashFromLeftAndRight(storedProcedureId);
|
104 | validateResourceId(storedProcedureId);
|
105 | return (createDocumentCollectionUri(databaseId, collectionId) +
|
106 | "/" +
|
107 | Constants.Path.StoredProceduresPathSegment +
|
108 | "/" +
|
109 | storedProcedureId);
|
110 | }
|
111 | /**
|
112 | * Given a database, collection and trigger id, this creates a trigger link.
|
113 | * Would be used when replacing, executing, or deleting a Trigger in Azure Cosmos DB database service
|
114 | * @param databaseId -The database Id
|
115 | * @param collectionId -The collection Id
|
116 | * @param triggerId -The trigger Id
|
117 | * @returns A trigger link in the format of
|
118 | * `dbs/{0}/colls/{1}/triggers/{2}` with `{0}` being a Uri escaped version of the databaseId,
|
119 | * `{1}` being collectionId and `{2}` being the triggerId
|
120 | * @hidden
|
121 | */
|
122 | export function createTriggerUri(databaseId, collectionId, triggerId) {
|
123 | triggerId = trimSlashFromLeftAndRight(triggerId);
|
124 | validateResourceId(triggerId);
|
125 | return (createDocumentCollectionUri(databaseId, collectionId) +
|
126 | "/" +
|
127 | Constants.Path.TriggersPathSegment +
|
128 | "/" +
|
129 | triggerId);
|
130 | }
|
131 | /**
|
132 | * Given a database, collection and udf id, this creates a udf link.
|
133 | * Would be used when replacing, executing, or deleting a UserDefinedFunction in
|
134 | * Azure Cosmos DB database service
|
135 | * @param databaseId -The database Id
|
136 | * @param collectionId -The collection Id
|
137 | * @param udfId -The User Defined Function Id
|
138 | * @returns A udf link in the format of `dbs/{0}/colls/{1}/udfs/{2}`
|
139 | * with `{0}` being a Uri escaped version of the databaseId, `{1}` being collectionId and `{2}` being the udfId
|
140 | * @hidden
|
141 | */
|
142 | export function createUserDefinedFunctionUri(databaseId, collectionId, udfId) {
|
143 | udfId = trimSlashFromLeftAndRight(udfId);
|
144 | validateResourceId(udfId);
|
145 | return (createDocumentCollectionUri(databaseId, collectionId) +
|
146 | "/" +
|
147 | Constants.Path.UserDefinedFunctionsPathSegment +
|
148 | "/" +
|
149 | udfId);
|
150 | }
|
151 | /**
|
152 | * Given a database, collection and conflict id, this creates a conflict link.
|
153 | * Would be used when creating a Conflict in Azure Cosmos DB database service.
|
154 | * @param databaseId -The database Id
|
155 | * @param collectionId -The collection Id
|
156 | * @param conflictId -The conflict Id
|
157 | * @returns A conflict link in the format of `dbs/{0}/colls/{1}/conflicts/{2}`
|
158 | * with `{0}` being a Uri escaped version of the databaseId, `{1}` being collectionId and `{2}` being the conflictId
|
159 | * @hidden
|
160 | */
|
161 | export function createConflictUri(databaseId, collectionId, conflictId) {
|
162 | conflictId = trimSlashFromLeftAndRight(conflictId);
|
163 | validateResourceId(conflictId);
|
164 | return (createDocumentCollectionUri(databaseId, collectionId) +
|
165 | "/" +
|
166 | Constants.Path.ConflictsPathSegment +
|
167 | "/" +
|
168 | conflictId);
|
169 | }
|
170 | /**
|
171 | * Given a database, collection and conflict id, this creates a conflict link.
|
172 | * Would be used when creating a Conflict in Azure Cosmos DB database service.
|
173 | * @param databaseId -The database Id
|
174 | * @param collectionId -The collection Id
|
175 | * @param documentId -The document Id
|
176 | * @param attachmentId -The attachment Id
|
177 | * @returns A conflict link in the format of `dbs/{0}/colls/{1}/conflicts/{2}`
|
178 | * with `{0}` being a Uri escaped version of the databaseId, `{1}` being collectionId and `{2}` being the conflictId
|
179 | * @hidden
|
180 | */
|
181 | export function createAttachmentUri(databaseId, collectionId, documentId, attachmentId) {
|
182 | attachmentId = trimSlashFromLeftAndRight(attachmentId);
|
183 | validateResourceId(attachmentId);
|
184 | return (createDocumentUri(databaseId, collectionId, documentId) +
|
185 | "/" +
|
186 | Constants.Path.AttachmentsPathSegment +
|
187 | "/" +
|
188 | attachmentId);
|
189 | }
|
190 | /**
|
191 | * Given a database and collection, this creates a partition key ranges link in
|
192 | * the Azure Cosmos DB database service.
|
193 | * @param databaseId - The database Id
|
194 | * @param collectionId - The collection Id
|
195 | * @returns A partition key ranges link in the format of
|
196 | * `dbs/{0}/colls/{1}/pkranges` with `{0}` being a Uri escaped version of the databaseId and `{1}` being collectionId
|
197 | * @hidden
|
198 | */
|
199 | export function createPartitionKeyRangesUri(databaseId, collectionId) {
|
200 | return (createDocumentCollectionUri(databaseId, collectionId) +
|
201 | "/" +
|
202 | Constants.Path.PartitionKeyRangesPathSegment);
|
203 | }
|
204 | //# sourceMappingURL=uriFactory.js.map |
\ | No newline at end of file |