@@ -60,6 +60,48 @@ class CblReactnative: NSObject {
6060 }
6161 }
6262
63+ @objc ( collection_CreateIndex: withIndexData: fromCollectionWithName: fromScopeWithName: fromDatabaseWithName: withResolver: withRejecter: )
64+ func collection_CreateIndex(
65+ indexName: NSString ,
66+ index: NSDictionary ,
67+ collectionName: NSString ,
68+ scopeName: NSString ,
69+ name: NSString ,
70+ resolve: @escaping RCTPromiseResolveBlock ,
71+ reject: @escaping RCTPromiseRejectBlock
72+ ) -> Void {
73+ backgroundQueue. async {
74+ do {
75+ let ( isError, args) = DataAdapter . shared. adaptCollectionArgs ( name: name, collectionName: collectionName, scopeName: scopeName, reject: reject)
76+ let ( isIndexNameError, idxName) = DataAdapter . shared. adaptNonEmptyString ( value: indexName, propertyName: " indexName " , reject: reject)
77+
78+ let ( isIndexDataError, indexData) = DataAdapter . shared. adaptIndexToArrayAny ( dict: index, reject: reject)
79+ if isError || isIndexNameError || isIndexDataError {
80+ return
81+ }
82+
83+ try CollectionManager . shared. createIndex (
84+ idxName,
85+ indexType: indexData. indexType,
86+ items: indexData. indexes,
87+ collectionName: args. collectionName,
88+ scopeName: args. scopeName,
89+ databaseName: args. databaseName)
90+ DispatchQueue . main. async {
91+ resolve ( nil )
92+ }
93+ } catch let error as NSError {
94+ DispatchQueue . main. async {
95+ reject ( " DATABASE_ERROR " , error. localizedDescription, nil )
96+ }
97+ } catch {
98+ DispatchQueue . main. async {
99+ reject ( " DATABASE_ERROR " , error. localizedDescription, nil )
100+ }
101+ }
102+ }
103+ }
104+
63105 @objc ( collection_DeleteCollection: fromDatabaseWithName: fromScopeWithName: withResolver: withRejecter: )
64106 func collection_DeleteCollection(
65107 collectionName: NSString ,
@@ -127,6 +169,44 @@ class CblReactnative: NSObject {
127169 }
128170 }
129171
172+ @objc ( collection_DeleteCollection: fromCollectionWithName: fromScopeWithName: fromDatabaseWithName: withResolver: withRejecter: )
173+ func collection_DeleteCollection(
174+ indexName: NSString ,
175+ collectionName: NSString ,
176+ scopeName: NSString ,
177+ name: NSString ,
178+ resolve: @escaping RCTPromiseResolveBlock ,
179+ reject: @escaping RCTPromiseRejectBlock
180+ ) -> Void {
181+ backgroundQueue. async {
182+ do {
183+ let ( isError, args) = DataAdapter . shared. adaptCollectionArgs ( name: name, collectionName: collectionName, scopeName: scopeName, reject: reject)
184+ let ( isIndexNameError, idxName) = DataAdapter . shared. adaptNonEmptyString ( value: indexName, propertyName: " indexName " , reject: reject)
185+
186+ if isError || isIndexNameError {
187+ return
188+ }
189+
190+ try CollectionManager . shared. deleteIndex (
191+ idxName,
192+ collectionName: args. collectionName,
193+ scopeName: args. scopeName,
194+ databaseName: args. databaseName)
195+ DispatchQueue . main. async {
196+ resolve ( nil )
197+ }
198+ } catch let error as NSError {
199+ DispatchQueue . main. async {
200+ reject ( " DATABASE_ERROR " , error. localizedDescription, nil )
201+ }
202+ } catch {
203+ DispatchQueue . main. async {
204+ reject ( " DATABASE_ERROR " , error. localizedDescription, nil )
205+ }
206+ }
207+ }
208+ }
209+
130210 @objc ( collection_GetBlobContent: fromDocumentWithId: fromDatabaseWithName: fromScopeWithName: fromCollectionWithName: withResolver: withRejecter: )
131211 func collection_GetBlobContent(
132212 key: NSString ,
@@ -279,6 +359,7 @@ class CblReactnative: NSObject {
279359 }
280360 }
281361
362+
282363 @objc ( collection_GetDefault: withResolver: withRejecter: )
283364 func collection_GetDefault(
284365 name: NSString ,
@@ -407,6 +488,43 @@ class CblReactnative: NSObject {
407488 }
408489 }
409490
491+ @objc ( collection_GetIndexes: fromScopeWithName: fromDatabaseWithName: withResolver: withRejecter: )
492+ func collection_DeleteCollection(
493+ collectionName: NSString ,
494+ scopeName: NSString ,
495+ name: NSString ,
496+ resolve: @escaping RCTPromiseResolveBlock ,
497+ reject: @escaping RCTPromiseRejectBlock
498+ ) -> Void {
499+ backgroundQueue. async {
500+ do {
501+ let ( isError, args) = DataAdapter . shared. adaptCollectionArgs ( name: name, collectionName: collectionName, scopeName: scopeName, reject: reject)
502+
503+ if isError {
504+ return
505+ }
506+
507+ let indexes = try CollectionManager . shared. indexes (
508+ args. collectionName,
509+ scopeName: args. scopeName,
510+ databaseName: args. databaseName)
511+ let dict : NSDictionary = [
512+ " indexes " : indexes]
513+ DispatchQueue . main. async {
514+ resolve ( dict)
515+ }
516+ } catch let error as NSError {
517+ DispatchQueue . main. async {
518+ reject ( " DATABASE_ERROR " , error. localizedDescription, nil )
519+ }
520+ } catch {
521+ DispatchQueue . main. async {
522+ reject ( " DATABASE_ERROR " , error. localizedDescription, nil )
523+ }
524+ }
525+ }
526+ }
527+
410528 @objc ( collection_PurgeDocument: fromDatabaseWithName: fromScopeWithName: fromCollectionWithName: withResolver: withRejecter: )
411529 func collection_PurgeDocument(
412530 docId: NSString ,
0 commit comments