-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
60 lines (56 loc) · 1.74 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { Platform, Linking, NativeModules } from 'react-native'
import CloudKitJS from './local_versions/1.0/cloudkit'
import helper from './helper'
export default class CloudKit {
static init(options) {
const configured = CloudKitJS.configure({
containers: options.containers
})
return CloudKitJS
}
static async query(options = {
query: { // query must be included and at least have a recordType
recordType:"",
filterBy:[],
sortBy:[]
},
zoneID:undefined, // default zone
resultsLimit:undefined, // currently default is 200
desiredKeys:undefined, // currently default gets all keys/values from record
zoneWide:undefined, // if options.zone is undefined, and options.zoneWide is true, searches all zones, otherwise searches JUST the default zone
container:"default",
database:"public"
}) {
return new Promise((resolve, reject)=>{
const CD = helper.getContainerAndDatabase(options)
const modifiedOptions = {
zoneID:options.zoneID,
resultsLimit:options.resultsLimit,
desiredKeys:options.desiredKeys,
zoneWide:options.zoneWide,
}
CD.database.performQuery(options.query).then(response=>{
if (response.hasErrors) {
reject(response.errors)
} else {
resolve(response)
}
})
})
}
static fetchRecordsByName(recordName, options = {
container:"default",
database:"public"
}) {
return new Promise((resolve, reject)=>{
const CD = helper.getContainerAndDatabase(options)
CD.database.fetchRecords(recordName).then(response=>{
if (response.hasErrors) {
reject(response.errors)
} else {
resolve(response.records)
}
})
})
}
}