├── .github
├── issue_template.md
└── pull_request_template.md
├── .gitignore
├── .travis.yml
├── CHANGELOG.md
├── LICENSE
├── README.md
├── demo
├── app
│ ├── App_Resources
│ │ ├── Android
│ │ │ ├── app.gradle
│ │ │ └── src
│ │ │ │ └── main
│ │ │ │ ├── AndroidManifest.xml
│ │ │ │ └── res
│ │ │ │ ├── drawable-hdpi
│ │ │ │ ├── background.png
│ │ │ │ ├── icon.png
│ │ │ │ └── logo.png
│ │ │ │ ├── drawable-ldpi
│ │ │ │ ├── background.png
│ │ │ │ ├── icon.png
│ │ │ │ └── logo.png
│ │ │ │ ├── drawable-mdpi
│ │ │ │ ├── background.png
│ │ │ │ ├── icon.png
│ │ │ │ └── logo.png
│ │ │ │ ├── drawable-nodpi
│ │ │ │ └── splash_screen.xml
│ │ │ │ ├── drawable-xhdpi
│ │ │ │ ├── background.png
│ │ │ │ ├── icon.png
│ │ │ │ └── logo.png
│ │ │ │ ├── drawable-xxhdpi
│ │ │ │ ├── background.png
│ │ │ │ ├── icon.png
│ │ │ │ └── logo.png
│ │ │ │ ├── drawable-xxxhdpi
│ │ │ │ ├── background.png
│ │ │ │ ├── icon.png
│ │ │ │ └── logo.png
│ │ │ │ ├── values-v21
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ │ └── values
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ └── iOS
│ │ │ ├── Assets.xcassets
│ │ │ ├── AppIcon.appiconset
│ │ │ │ ├── Contents.json
│ │ │ │ ├── icon-29.png
│ │ │ │ ├── icon-29@2x.png
│ │ │ │ ├── icon-29@3x.png
│ │ │ │ ├── icon-40.png
│ │ │ │ ├── icon-40@2x.png
│ │ │ │ ├── icon-40@3x.png
│ │ │ │ ├── icon-50.png
│ │ │ │ ├── icon-50@2x.png
│ │ │ │ ├── icon-57.png
│ │ │ │ ├── icon-57@2x.png
│ │ │ │ ├── icon-60@2x.png
│ │ │ │ ├── icon-60@3x.png
│ │ │ │ ├── icon-72.png
│ │ │ │ ├── icon-72@2x.png
│ │ │ │ ├── icon-76.png
│ │ │ │ ├── icon-76@2x.png
│ │ │ │ └── icon-83.5@2x.png
│ │ │ ├── Contents.json
│ │ │ ├── LaunchImage.launchimage
│ │ │ │ ├── Contents.json
│ │ │ │ ├── Default-568h@2x.png
│ │ │ │ ├── Default-667h@2x.png
│ │ │ │ ├── Default-736h@3x.png
│ │ │ │ ├── Default-Landscape.png
│ │ │ │ ├── Default-Landscape@2x.png
│ │ │ │ ├── Default-Landscape@3x.png
│ │ │ │ ├── Default-Portrait.png
│ │ │ │ ├── Default-Portrait@2x.png
│ │ │ │ ├── Default.png
│ │ │ │ └── Default@2x.png
│ │ │ ├── LaunchScreen.AspectFill.imageset
│ │ │ │ ├── Contents.json
│ │ │ │ ├── LaunchScreen-AspectFill.png
│ │ │ │ └── LaunchScreen-AspectFill@2x.png
│ │ │ └── LaunchScreen.Center.imageset
│ │ │ │ ├── Contents.json
│ │ │ │ ├── LaunchScreen-Center.png
│ │ │ │ └── LaunchScreen-Center@2x.png
│ │ │ ├── Info.plist
│ │ │ ├── LaunchScreen.storyboard
│ │ │ └── build.xcconfig
│ ├── app.css
│ ├── app.ts
│ ├── main-page.ts
│ ├── main-page.xml
│ ├── main-view-model.ts
│ ├── package.json
│ ├── root-page.xml
│ ├── search
│ │ ├── search-page.ts
│ │ ├── search-page.xml
│ │ └── search-view-model.ts
│ └── tests
│ │ └── tests.js
├── karma.conf.js
├── package.json
├── references.d.ts
├── tsconfig.json
└── tsconfig.tns.json
├── publish
├── CHANGELOG.md
├── pack.sh
├── package.json
└── publish.sh
├── src
├── .npmignore
├── couchbase-plugin.android.ts
├── couchbase-plugin.common.ts
├── couchbase-plugin.ios.ts
├── index.d.ts
├── package.json
├── platforms
│ ├── android
│ │ ├── fancycouchbase-release.aar
│ │ └── include.gradle
│ └── ios
│ │ └── Podfile
├── references.d.ts
├── scripts
│ └── build-native.js
├── tsconfig.json
└── typings
│ ├── android.d.ts
│ └── objc!CouchbaseLite.d.ts
└── tslint.json
/.github/issue_template.md:
--------------------------------------------------------------------------------
1 | ### Make sure to check the demo app(s) for sample usage
2 |
3 | ### Make sure to check the existing issues in this repository
4 |
5 | ### If the demo apps cannot help and there is no issue for your problem, tell us about it
6 | Please, ensure your title is less than 63 characters long and starts with a capital
7 | letter.
8 |
9 | ### Which platform(s) does your issue occur on?
10 | - iOS/Android/Both
11 | - iOS/Android versions
12 | - emulator or device. What type of device?
13 |
14 | ### Please, provide the following version numbers that your issue occurs with:
15 |
16 | - CLI: (run `tns --version` to fetch it)
17 | - Cross-platform modules: (check the 'version' attribute in the
18 | `node_modules/tns-core-modules/package.json` file in your project)
19 | - Runtime(s): (look for the `"tns-android"` and `"tns-ios"` properties in the `package.json` file of your project)
20 | - Plugin(s): (look for the version numbers in the `package.json` file of your
21 | project and paste your dependencies and devDependencies here)
22 |
23 | ### Please, tell us how to recreate the issue in as much detail as possible.
24 | Describe the steps to reproduce it.
25 |
26 | ### Is there any code involved?
27 | - provide a code example to recreate the problem
28 | - (EVEN BETTER) provide a .zip with application or refer to a repository with application where the problem is reproducible.
29 |
--------------------------------------------------------------------------------
/.github/pull_request_template.md:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 | ## PR Checklist
11 |
12 | - [ ] The PR title follows our guidelines: https://github.com/NativeScript/NativeScript/blob/master/CONTRIBUTING.md#commit-messages.
13 | - [ ] There is an issue for the bug/feature this PR is for. To avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it.
14 | - [ ] All existing tests are passing
15 | - [ ] Tests for the changes are included
16 |
17 | ## What is the current behavior?
18 |
19 |
20 | ## What is the new behavior?
21 |
22 |
23 | Fixes/Implements/Closes #[Issue Number].
24 |
25 |
26 |
27 |
36 |
37 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .vscode
2 | .idea
3 | *.DS_Store
4 | *.esm.json
5 | *.js
6 | *.js.map
7 | *.log
8 | src/*.d.ts
9 | !src/index.d.ts
10 | !src/references.d.ts
11 | !src/scripts/*.js
12 | !seed-tests/*.js
13 | seed-tests/seed-copy/**/*.*
14 | seed-tests/seed-copy-new-git-repo/**/*.*
15 | !demo/karma.conf.js
16 | !demo/app/tests/*.js
17 | demo/*.d.ts
18 | !demo/references.d.ts
19 | demo/lib
20 | demo/platforms
21 | node_modules
22 | publish/src
23 | publish/package
24 | demo/report/report.html
25 | demo/report/stats.json
26 | package-lock.json
27 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | matrix:
2 | include:
3 | - stage: "Lint"
4 | language: node_js
5 | os: linux
6 | node_js: "8"
7 | script: cd src && npm run ci.tslint && cd ../demo && npm run ci.tslint
8 | - stage: "WebPack, Build and Test"
9 | os: osx
10 | env:
11 | - WebPack="iOS"
12 | osx_image: xcode9.2
13 | language: node_js
14 | node_js: "8"
15 | jdk: oraclejdk8
16 | script: cd demo && npm run build.plugin && npm i && tns build ios --bundle --env.uglify
17 | - language: android
18 | os: linux
19 | env:
20 | - WebPack="Android"
21 | jdk: oraclejdk8
22 | before_install: nvm install 8
23 | script: cd demo && npm run build.plugin && npm i && tns build android --bundle --env.uglify --env.snapshot
24 | - language: android
25 | env:
26 | - BuildAndroid="26"
27 | os: linux
28 | jdk: oraclejdk8
29 | before_install: nvm install stable
30 | script:
31 | - cd src && npm i && npm run tsc && cd ../demo && tns build android
32 | - os: osx
33 | env:
34 | - BuildiOS="11"
35 | - Xcode="9.2"
36 | osx_image: xcode9.2
37 | language: node_js
38 | node_js: "8"
39 | jdk: oraclejdk8
40 | script:
41 | - cd src && npm i && npm run tsc && cd ../demo && tns build ios
42 | - os: linux
43 | language: android
44 | dist: precise
45 | sudo: required
46 | jdk: oraclejdk8
47 | before_script:
48 | - echo no | android create avd --force -n test -t android-21 -b armeabi-v7a
49 | - emulator -avd test -no-audio -no-window &
50 | - android-wait-for-emulator
51 | before_install:
52 | - nvm install 8
53 | script: cd src && npm run test.android
54 | - os: osx
55 | language: node_js
56 | node_js: "8"
57 | jdk: oraclejdk8
58 | osx_image: xcode9.2
59 | script: cd src && npm run test.ios
60 |
61 | android:
62 | components:
63 | - tools
64 | - platform-tools
65 | - build-tools-26.0.1
66 | - android-26
67 | - android-23
68 | - extra-android-m2repository
69 | - sys-img-armeabi-v7a-android-21
70 |
71 | install:
72 | - echo no | npm install -g nativescript
73 | - tns usage-reporting disable
74 | - tns error-reporting disable
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Change Log
2 |
3 | ## [0.9.1](https://github.com/triniwiz/nativescript-couchbase-plugin/tree/0.9.1) (2019-04-04)
4 | [Full Changelog](https://github.com/triniwiz/nativescript-couchbase-plugin/compare/v0.9.0...0.9.1)
5 |
6 | **Fixed bugs:**
7 |
8 | - Serialize comparison values [\#18](https://github.com/triniwiz/nativescript-couchbase-plugin/issues/18)
9 |
10 | **Merged pull requests:**
11 |
12 | - Update README.md [\#17](https://github.com/triniwiz/nativescript-couchbase-plugin/pull/17) ([cfjedimaster](https://github.com/cfjedimaster))
13 |
14 | ## [v0.9.0](https://github.com/triniwiz/nativescript-couchbase-plugin/tree/v0.9.0) (2019-01-22)
15 | [Full Changelog](https://github.com/triniwiz/nativescript-couchbase-plugin/compare/v0.8.1...v0.9.0)
16 |
17 | ## [v0.8.1](https://github.com/triniwiz/nativescript-couchbase-plugin/tree/v0.8.1) (2019-01-22)
18 | [Full Changelog](https://github.com/triniwiz/nativescript-couchbase-plugin/compare/v0.8.0...v0.8.1)
19 |
20 | **Implemented enhancements:**
21 |
22 | - Add blob/attachment [\#2](https://github.com/triniwiz/nativescript-couchbase-plugin/issues/2)
23 |
24 | ## [v0.8.0](https://github.com/triniwiz/nativescript-couchbase-plugin/tree/v0.8.0) (2019-01-22)
25 | [Full Changelog](https://github.com/triniwiz/nativescript-couchbase-plugin/compare/v0.7.0...v0.8.0)
26 |
27 | **Merged pull requests:**
28 |
29 | - Fix logical type check [\#13](https://github.com/triniwiz/nativescript-couchbase-plugin/pull/13) ([jerbob92](https://github.com/jerbob92))
30 | - Fix bug in operator support for iOS [\#12](https://github.com/triniwiz/nativescript-couchbase-plugin/pull/12) ([jerbob92](https://github.com/jerbob92))
31 | - Add missing float in number support [\#11](https://github.com/triniwiz/nativescript-couchbase-plugin/pull/11) ([jerbob92](https://github.com/jerbob92))
32 |
33 | ## [v0.7.0](https://github.com/triniwiz/nativescript-couchbase-plugin/tree/v0.7.0) (2019-01-22)
34 | [Full Changelog](https://github.com/triniwiz/nativescript-couchbase-plugin/compare/v0.6.0...v0.7.0)
35 |
36 | **Merged pull requests:**
37 |
38 | - Add support for long/float/double [\#10](https://github.com/triniwiz/nativescript-couchbase-plugin/pull/10) ([jerbob92](https://github.com/jerbob92))
39 |
40 | ## [v0.6.0](https://github.com/triniwiz/nativescript-couchbase-plugin/tree/v0.6.0) (2019-01-10)
41 | [Full Changelog](https://github.com/triniwiz/nativescript-couchbase-plugin/compare/v0.5.0...v0.6.0)
42 |
43 | **Closed issues:**
44 |
45 | - Receiving this error when attempting to use this plugin? [\#8](https://github.com/triniwiz/nativescript-couchbase-plugin/issues/8)
46 |
47 | **Merged pull requests:**
48 |
49 | - Add support for inBatch [\#9](https://github.com/triniwiz/nativescript-couchbase-plugin/pull/9) ([jerbob92](https://github.com/jerbob92))
50 |
51 | ## [v0.5.0](https://github.com/triniwiz/nativescript-couchbase-plugin/tree/v0.5.0) (2018-11-30)
52 | [Full Changelog](https://github.com/triniwiz/nativescript-couchbase-plugin/compare/v0.4.1...v0.5.0)
53 |
54 | **Merged pull requests:**
55 |
56 | - Feature/fix null values [\#7](https://github.com/triniwiz/nativescript-couchbase-plugin/pull/7) ([jerbob92](https://github.com/jerbob92))
57 | - Fix limit/offset query [\#6](https://github.com/triniwiz/nativescript-couchbase-plugin/pull/6) ([jerbob92](https://github.com/jerbob92))
58 | - fixed error with not implemented abstract methods [\#5](https://github.com/triniwiz/nativescript-couchbase-plugin/pull/5) ([elcreator](https://github.com/elcreator))
59 |
60 | ## [v0.4.1](https://github.com/triniwiz/nativescript-couchbase-plugin/tree/v0.4.1) (2018-11-29)
61 | [Full Changelog](https://github.com/triniwiz/nativescript-couchbase-plugin/compare/v0.4.0...v0.4.1)
62 |
63 | **Implemented enhancements:**
64 |
65 | - Add Query method [\#1](https://github.com/triniwiz/nativescript-couchbase-plugin/issues/1)
66 |
67 | ## [v0.4.0](https://github.com/triniwiz/nativescript-couchbase-plugin/tree/v0.4.0) (2018-11-29)
68 | [Full Changelog](https://github.com/triniwiz/nativescript-couchbase-plugin/compare/v0.3.2...v0.4.0)
69 |
70 | **Fixed bugs:**
71 |
72 | - Need Basic Authentication [\#4](https://github.com/triniwiz/nativescript-couchbase-plugin/issues/4)
73 | - Typo in source code [\#3](https://github.com/triniwiz/nativescript-couchbase-plugin/issues/3)
74 |
75 | ## [v0.3.2](https://github.com/triniwiz/nativescript-couchbase-plugin/tree/v0.3.2) (2018-10-23)
76 | [Full Changelog](https://github.com/triniwiz/nativescript-couchbase-plugin/compare/v0.0.1...v0.3.2)
77 |
78 | ## [v0.0.1](https://github.com/triniwiz/nativescript-couchbase-plugin/tree/v0.0.1) (2018-10-17)
79 |
80 |
81 | \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright (c) 2015-2018 Telerik EAD
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://www.npmjs.com/package/nativescript-couchbase-plugin)
2 | [](https://www.npmjs.com/package/nativescript-couchbase-plugin)
3 | [](https://travis-ci.org/triniwiz/nativescript-couchbase-plugin)
4 |
5 | # NativeScript-Couchbase
6 |
7 | **The source is now managed at** https://github.com/triniwiz/nativescript-plugins
8 |
9 | ## Installation
10 |
11 | `tns plugin add nativescript-couchbase-plugin`
12 |
13 | ## Usage
14 | **Note Android min-sdk is 19**
15 |
16 |
17 | ```ts
18 | import { Couchbase, ConcurrencyMode } from 'nativescript-couchbase-plugin';
19 | const database = new Couchbase('my-database');
20 |
21 | const documentId = database.createDocument({
22 | "firstname": "O",
23 | "lastname": "Fortune",
24 | "address": {
25 | "country": "Trinidad and Tobago"
26 | },
27 | "twitter": "https://www.twitter.com/triniwiz"
28 | });
29 |
30 | const person = database.getDocument(documentId);
31 |
32 |
33 | database.updateDocument(documentId, {
34 | "firstname": "Osei",
35 | "lastname": "Fortune",
36 | "twitter": "https://www.twitter.com/triniwiz"
37 | });
38 |
39 | // Default concurrency mode is FailOnConflict if you don't pass it
40 | const isDeleted = database.deleteDocument(documentId, ConcurrencyMode.FailOnConflict);
41 | ```
42 |
43 | ### Synchronization with Couchbase Sync Gateway and Couchbase Server
44 |
45 | ```ts
46 | import { Couchbase } from 'nativescript-couchbase-plugin';
47 | const database = new Couchbase('my-database');
48 |
49 | const push = database.createPushReplication(
50 | 'ws://sync-gateway-host:4984/my-database'
51 | );
52 | push.setUserNameAndPassword("user","password");
53 | const pull = database.createPullReplication(
54 | 'ws://sync-gateway-host:4984/my-database'
55 | );
56 | pull.setSessionId("SomeId");
57 | pull.setSessionIdAndCookieName("SomeId","SomeCookieName");
58 |
59 | push.setContinuous(true);
60 | pull.setContinuous(true);
61 | push.start();
62 | pull.start();
63 | ```
64 |
65 | ### Listening for Changes
66 |
67 | ```ts
68 | database.addDatabaseChangeListener(function(changes) {
69 | for (var i = 0; i < changes.length; i++) {
70 | const documentId = changes[i];
71 | console.log(documentId);
72 | }
73 | });
74 | ```
75 |
76 | ### Query
77 |
78 | ```ts
79 | const results = database.query({
80 | select: [], // Leave empty to query for all
81 | from: 'otherDatabaseName', // Omit or set null to use current db
82 | where: [{ property: 'firstName', comparison: 'equalTo', value: 'Osei' }],
83 | order: [{ property: 'firstName', direction: 'desc' }],
84 | limit: 2
85 | });
86 | ```
87 |
88 | ### Transactions
89 | Using the method `inBatch` to run group of database operations in a batch/transaction. Use this when performing bulk write operations like multiple inserts/updates; it saves the overhead of multiple database commits, greatly improving performance.
90 |
91 | ```ts
92 | import { Couchbase } from 'nativescript-couchbase-plugin';
93 | const database = new Couchbase('my-database');
94 |
95 | database.inBatch(() => {
96 | const documentId = database.createDocument({
97 | "firstname": "O",
98 | "lastname": "Fortune",
99 | "address": {
100 | "country": "Trinidad and Tobago"
101 | }
102 | "twitter": "https://www.twitter.com/triniwiz"
103 | });
104 |
105 | const person = database.getDocument(documentId);
106 |
107 |
108 | database.updateDocument(documentId, {
109 | "firstname": "Osei",
110 | "lastname": "Fortune",
111 | "twitter": "https://www.twitter.com/triniwiz"
112 | });
113 |
114 | const isDeleted = database.deleteDocument(documentId);
115 | });
116 | ```
117 |
118 | ## API
119 |
120 | ## License
121 |
122 | Apache License Version 2.0, January 2004
123 |
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/app.gradle:
--------------------------------------------------------------------------------
1 | // Add your native dependencies here:
2 |
3 | // Uncomment to add recyclerview-v7 dependency
4 | //dependencies {
5 | // compile 'com.android.support:recyclerview-v7:+'
6 | //}
7 |
8 | android {
9 | defaultConfig {
10 | generatedDensities = []
11 | }
12 | aaptOptions {
13 | additionalParameters "--no-version-vectors"
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
16 |
17 |
18 |
19 |
20 |
21 |
28 |
29 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/src/main/res/drawable-hdpi/background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/Android/src/main/res/drawable-hdpi/background.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/src/main/res/drawable-hdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/Android/src/main/res/drawable-hdpi/icon.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/src/main/res/drawable-hdpi/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/Android/src/main/res/drawable-hdpi/logo.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/src/main/res/drawable-ldpi/background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/Android/src/main/res/drawable-ldpi/background.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/src/main/res/drawable-ldpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/Android/src/main/res/drawable-ldpi/icon.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/src/main/res/drawable-ldpi/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/Android/src/main/res/drawable-ldpi/logo.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/src/main/res/drawable-mdpi/background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/Android/src/main/res/drawable-mdpi/background.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/src/main/res/drawable-mdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/Android/src/main/res/drawable-mdpi/icon.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/src/main/res/drawable-mdpi/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/Android/src/main/res/drawable-mdpi/logo.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/src/main/res/drawable-nodpi/splash_screen.xml:
--------------------------------------------------------------------------------
1 |
2 | -
3 |
4 |
5 | -
6 |
7 |
8 |
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/src/main/res/drawable-xhdpi/background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/Android/src/main/res/drawable-xhdpi/background.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/src/main/res/drawable-xhdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/Android/src/main/res/drawable-xhdpi/icon.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/src/main/res/drawable-xhdpi/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/Android/src/main/res/drawable-xhdpi/logo.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/src/main/res/drawable-xxhdpi/background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/Android/src/main/res/drawable-xxhdpi/background.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/src/main/res/drawable-xxhdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/Android/src/main/res/drawable-xxhdpi/icon.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/src/main/res/drawable-xxhdpi/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/Android/src/main/res/drawable-xxhdpi/logo.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/src/main/res/drawable-xxxhdpi/background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/Android/src/main/res/drawable-xxxhdpi/background.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/src/main/res/drawable-xxxhdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/Android/src/main/res/drawable-xxxhdpi/icon.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/src/main/res/drawable-xxxhdpi/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/Android/src/main/res/drawable-xxxhdpi/logo.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/src/main/res/values-v21/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3d5afe
4 |
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
9 |
10 |
11 |
14 |
15 |
16 |
19 |
20 |
23 |
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #F5F5F5
4 | #757575
5 | #33B5E5
6 | #272734
7 |
--------------------------------------------------------------------------------
/demo/app/App_Resources/Android/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
18 |
19 |
21 |
22 |
23 |
31 |
32 |
34 |
35 |
36 |
42 |
43 |
45 |
46 |
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "size" : "29x29",
5 | "idiom" : "iphone",
6 | "filename" : "icon-29.png",
7 | "scale" : "1x"
8 | },
9 | {
10 | "size" : "29x29",
11 | "idiom" : "iphone",
12 | "filename" : "icon-29@2x.png",
13 | "scale" : "2x"
14 | },
15 | {
16 | "size" : "29x29",
17 | "idiom" : "iphone",
18 | "filename" : "icon-29@3x.png",
19 | "scale" : "3x"
20 | },
21 | {
22 | "size" : "40x40",
23 | "idiom" : "iphone",
24 | "filename" : "icon-40@2x.png",
25 | "scale" : "2x"
26 | },
27 | {
28 | "size" : "40x40",
29 | "idiom" : "iphone",
30 | "filename" : "icon-40@3x.png",
31 | "scale" : "3x"
32 | },
33 | {
34 | "size" : "57x57",
35 | "idiom" : "iphone",
36 | "filename" : "icon-57.png",
37 | "scale" : "1x"
38 | },
39 | {
40 | "size" : "57x57",
41 | "idiom" : "iphone",
42 | "filename" : "icon-57@2x.png",
43 | "scale" : "2x"
44 | },
45 | {
46 | "size" : "60x60",
47 | "idiom" : "iphone",
48 | "filename" : "icon-60@2x.png",
49 | "scale" : "2x"
50 | },
51 | {
52 | "size" : "60x60",
53 | "idiom" : "iphone",
54 | "filename" : "icon-60@3x.png",
55 | "scale" : "3x"
56 | },
57 | {
58 | "size" : "29x29",
59 | "idiom" : "ipad",
60 | "filename" : "icon-29.png",
61 | "scale" : "1x"
62 | },
63 | {
64 | "size" : "29x29",
65 | "idiom" : "ipad",
66 | "filename" : "icon-29@2x.png",
67 | "scale" : "2x"
68 | },
69 | {
70 | "size" : "40x40",
71 | "idiom" : "ipad",
72 | "filename" : "icon-40.png",
73 | "scale" : "1x"
74 | },
75 | {
76 | "size" : "40x40",
77 | "idiom" : "ipad",
78 | "filename" : "icon-40@2x.png",
79 | "scale" : "2x"
80 | },
81 | {
82 | "size" : "50x50",
83 | "idiom" : "ipad",
84 | "filename" : "icon-50.png",
85 | "scale" : "1x"
86 | },
87 | {
88 | "size" : "50x50",
89 | "idiom" : "ipad",
90 | "filename" : "icon-50@2x.png",
91 | "scale" : "2x"
92 | },
93 | {
94 | "size" : "72x72",
95 | "idiom" : "ipad",
96 | "filename" : "icon-72.png",
97 | "scale" : "1x"
98 | },
99 | {
100 | "size" : "72x72",
101 | "idiom" : "ipad",
102 | "filename" : "icon-72@2x.png",
103 | "scale" : "2x"
104 | },
105 | {
106 | "size" : "76x76",
107 | "idiom" : "ipad",
108 | "filename" : "icon-76.png",
109 | "scale" : "1x"
110 | },
111 | {
112 | "size" : "76x76",
113 | "idiom" : "ipad",
114 | "filename" : "icon-76@2x.png",
115 | "scale" : "2x"
116 | },
117 | {
118 | "size" : "83.5x83.5",
119 | "idiom" : "ipad",
120 | "filename" : "icon-83.5@2x.png",
121 | "scale" : "2x"
122 | }
123 | ],
124 | "info" : {
125 | "version" : 1,
126 | "author" : "xcode"
127 | }
128 | }
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-29.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-29.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-29@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-29@2x.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-29@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-29@3x.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-40.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-40.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-40@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-40@2x.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-40@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-40@3x.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-50.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-50.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-50@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-50@2x.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-57.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-57.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-57@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-57@2x.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-60@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-60@2x.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-60@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-60@3x.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-72.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-72.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-72@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-72@2x.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-76.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-76.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-76@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-76@2x.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-83.5@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-83.5@2x.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "info" : {
3 | "version" : 1,
4 | "author" : "xcode"
5 | }
6 | }
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "extent" : "full-screen",
5 | "idiom" : "iphone",
6 | "subtype" : "736h",
7 | "filename" : "Default-736h@3x.png",
8 | "minimum-system-version" : "8.0",
9 | "orientation" : "portrait",
10 | "scale" : "3x"
11 | },
12 | {
13 | "extent" : "full-screen",
14 | "idiom" : "iphone",
15 | "subtype" : "736h",
16 | "filename" : "Default-Landscape@3x.png",
17 | "minimum-system-version" : "8.0",
18 | "orientation" : "landscape",
19 | "scale" : "3x"
20 | },
21 | {
22 | "extent" : "full-screen",
23 | "idiom" : "iphone",
24 | "subtype" : "667h",
25 | "filename" : "Default-667h@2x.png",
26 | "minimum-system-version" : "8.0",
27 | "orientation" : "portrait",
28 | "scale" : "2x"
29 | },
30 | {
31 | "orientation" : "portrait",
32 | "idiom" : "iphone",
33 | "filename" : "Default@2x.png",
34 | "extent" : "full-screen",
35 | "minimum-system-version" : "7.0",
36 | "scale" : "2x"
37 | },
38 | {
39 | "extent" : "full-screen",
40 | "idiom" : "iphone",
41 | "subtype" : "retina4",
42 | "filename" : "Default-568h@2x.png",
43 | "minimum-system-version" : "7.0",
44 | "orientation" : "portrait",
45 | "scale" : "2x"
46 | },
47 | {
48 | "orientation" : "portrait",
49 | "idiom" : "ipad",
50 | "filename" : "Default-Portrait.png",
51 | "extent" : "full-screen",
52 | "minimum-system-version" : "7.0",
53 | "scale" : "1x"
54 | },
55 | {
56 | "orientation" : "landscape",
57 | "idiom" : "ipad",
58 | "filename" : "Default-Landscape.png",
59 | "extent" : "full-screen",
60 | "minimum-system-version" : "7.0",
61 | "scale" : "1x"
62 | },
63 | {
64 | "orientation" : "portrait",
65 | "idiom" : "ipad",
66 | "filename" : "Default-Portrait@2x.png",
67 | "extent" : "full-screen",
68 | "minimum-system-version" : "7.0",
69 | "scale" : "2x"
70 | },
71 | {
72 | "orientation" : "landscape",
73 | "idiom" : "ipad",
74 | "filename" : "Default-Landscape@2x.png",
75 | "extent" : "full-screen",
76 | "minimum-system-version" : "7.0",
77 | "scale" : "2x"
78 | },
79 | {
80 | "orientation" : "portrait",
81 | "idiom" : "iphone",
82 | "filename" : "Default.png",
83 | "extent" : "full-screen",
84 | "scale" : "1x"
85 | },
86 | {
87 | "orientation" : "portrait",
88 | "idiom" : "iphone",
89 | "filename" : "Default@2x.png",
90 | "extent" : "full-screen",
91 | "scale" : "2x"
92 | },
93 | {
94 | "orientation" : "portrait",
95 | "idiom" : "iphone",
96 | "filename" : "Default-568h@2x.png",
97 | "extent" : "full-screen",
98 | "subtype" : "retina4",
99 | "scale" : "2x"
100 | },
101 | {
102 | "orientation" : "portrait",
103 | "idiom" : "ipad",
104 | "extent" : "to-status-bar",
105 | "scale" : "1x"
106 | },
107 | {
108 | "orientation" : "portrait",
109 | "idiom" : "ipad",
110 | "filename" : "Default-Portrait.png",
111 | "extent" : "full-screen",
112 | "scale" : "1x"
113 | },
114 | {
115 | "orientation" : "landscape",
116 | "idiom" : "ipad",
117 | "extent" : "to-status-bar",
118 | "scale" : "1x"
119 | },
120 | {
121 | "orientation" : "landscape",
122 | "idiom" : "ipad",
123 | "filename" : "Default-Landscape.png",
124 | "extent" : "full-screen",
125 | "scale" : "1x"
126 | },
127 | {
128 | "orientation" : "portrait",
129 | "idiom" : "ipad",
130 | "extent" : "to-status-bar",
131 | "scale" : "2x"
132 | },
133 | {
134 | "orientation" : "portrait",
135 | "idiom" : "ipad",
136 | "filename" : "Default-Portrait@2x.png",
137 | "extent" : "full-screen",
138 | "scale" : "2x"
139 | },
140 | {
141 | "orientation" : "landscape",
142 | "idiom" : "ipad",
143 | "extent" : "to-status-bar",
144 | "scale" : "2x"
145 | },
146 | {
147 | "orientation" : "landscape",
148 | "idiom" : "ipad",
149 | "filename" : "Default-Landscape@2x.png",
150 | "extent" : "full-screen",
151 | "scale" : "2x"
152 | }
153 | ],
154 | "info" : {
155 | "version" : 1,
156 | "author" : "xcode"
157 | }
158 | }
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-568h@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-568h@2x.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-667h@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-667h@2x.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-736h@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-736h@3x.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-Landscape.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-Landscape.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-Landscape@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-Landscape@2x.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-Landscape@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-Landscape@3x.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-Portrait.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-Portrait.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-Portrait@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-Portrait@2x.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default@2x.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/LaunchScreen.AspectFill.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "LaunchScreen-AspectFill.png",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "filename" : "LaunchScreen-AspectFill@2x.png",
11 | "scale" : "2x"
12 | },
13 | {
14 | "idiom" : "universal",
15 | "scale" : "3x"
16 | }
17 | ],
18 | "info" : {
19 | "version" : 1,
20 | "author" : "xcode"
21 | }
22 | }
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/LaunchScreen.AspectFill.imageset/LaunchScreen-AspectFill.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/iOS/Assets.xcassets/LaunchScreen.AspectFill.imageset/LaunchScreen-AspectFill.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/LaunchScreen.AspectFill.imageset/LaunchScreen-AspectFill@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/iOS/Assets.xcassets/LaunchScreen.AspectFill.imageset/LaunchScreen-AspectFill@2x.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/LaunchScreen.Center.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "LaunchScreen-Center.png",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "filename" : "LaunchScreen-Center@2x.png",
11 | "scale" : "2x"
12 | },
13 | {
14 | "idiom" : "universal",
15 | "scale" : "3x"
16 | }
17 | ],
18 | "info" : {
19 | "version" : 1,
20 | "author" : "xcode"
21 | }
22 | }
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/LaunchScreen.Center.imageset/LaunchScreen-Center.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/iOS/Assets.xcassets/LaunchScreen.Center.imageset/LaunchScreen-Center.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Assets.xcassets/LaunchScreen.Center.imageset/LaunchScreen-Center@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/demo/app/App_Resources/iOS/Assets.xcassets/LaunchScreen.Center.imageset/LaunchScreen-Center@2x.png
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleDisplayName
8 | ${PRODUCT_NAME}
9 | CFBundleExecutable
10 | ${EXECUTABLE_NAME}
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | ${PRODUCT_NAME}
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1.0
23 | LSRequiresIPhoneOS
24 |
25 | UILaunchStoryboardName
26 | LaunchScreen
27 | UIRequiresFullScreen
28 |
29 | UIRequiredDeviceCapabilities
30 |
31 | armv7
32 |
33 | UISupportedInterfaceOrientations
34 |
35 | UIInterfaceOrientationPortrait
36 | UIInterfaceOrientationLandscapeLeft
37 | UIInterfaceOrientationLandscapeRight
38 |
39 | UISupportedInterfaceOrientations~ipad
40 |
41 | UIInterfaceOrientationPortrait
42 | UIInterfaceOrientationPortraitUpsideDown
43 | UIInterfaceOrientationLandscapeLeft
44 | UIInterfaceOrientationLandscapeRight
45 |
46 | NSAppTransportSecurity
47 |
48 |
49 | NSAllowsArbitraryLoads
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/demo/app/App_Resources/iOS/build.xcconfig:
--------------------------------------------------------------------------------
1 | // You can add custom settings here
2 | // for example you can uncomment the following line to force distribution code signing
3 | // CODE_SIGN_IDENTITY = iPhone Distribution
4 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
5 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
6 |
--------------------------------------------------------------------------------
/demo/app/app.css:
--------------------------------------------------------------------------------
1 | @import '~nativescript-theme-core/css/core.light.css';
2 |
--------------------------------------------------------------------------------
/demo/app/app.ts:
--------------------------------------------------------------------------------
1 | import * as application from 'tns-core-modules/application';
2 | application.run({ moduleName: 'root-page' });
3 |
--------------------------------------------------------------------------------
/demo/app/main-page.ts:
--------------------------------------------------------------------------------
1 | import * as observable from 'tns-core-modules/data/observable';
2 | import * as pages from 'tns-core-modules/ui/page';
3 | import { HelloWorldModel } from './main-view-model';
4 | import { topmost } from 'tns-core-modules/ui/frame';
5 | let vm;
6 | let page: pages.Page;
7 | // Event handler for Page 'loaded' event attached in main-page.xml
8 | export function pageLoaded(args: observable.EventData) {
9 | vm = new HelloWorldModel();
10 | page = args.object as pages.Page;
11 | page.bindingContext = vm;
12 | page.getViewById('input').on('textChange', (args: any) => {
13 | vm.set('input', args.object.text);
14 | });
15 | }
16 |
17 | export function addNew(args) {
18 | vm.addItem();
19 | const input = page.getViewById('input') as any;
20 | if (input) {
21 | input.text = '';
22 | }
23 | }
24 |
25 | export function goToSearch(args) {
26 | topmost().navigate('search/search-page');
27 | }
28 |
--------------------------------------------------------------------------------
/demo/app/main-page.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/demo/app/main-view-model.ts:
--------------------------------------------------------------------------------
1 | import { Observable } from 'tns-core-modules/data/observable';
2 | import { Couchbase, Replicator } from 'nativescript-couchbase-plugin';
3 | import { ObservableArray } from 'tns-core-modules/data/observable-array/observable-array';
4 | import * as http from 'tns-core-modules/http';
5 |
6 | export class HelloWorldModel extends Observable {
7 | public message: string;
8 | private db: Couchbase;
9 | items: ObservableArray = new ObservableArray([]);
10 | input: string = '';
11 | replicator: Replicator;
12 |
13 | constructor() {
14 | super();
15 | this.db = new Couchbase('tns-couchbase');
16 | this.replicator = this.db.createReplication('ws://192.168.0.10:4984/tns-couchbase', 'both');
17 | this.replicator.setContinuous(true);
18 | this.db.addDatabaseChangeListener(changes => {
19 | for (let change of changes) {
20 | const doc = this.db.getDocument(change);
21 | if (doc) {
22 | const length = this.items.length;
23 | if (length === 0) {
24 | this.items.push(doc);
25 | } else {
26 | for (let i = 0; i < length; i++) {
27 | const item = this.items.getItem(i);
28 | if (item.id === change) {
29 | this.items.setItem(i, doc);
30 | break;
31 | } else if (i === length - 1) {
32 | this.items.push(doc);
33 | }
34 | }
35 | }
36 | } else {
37 | this.items.forEach((item, index) => {
38 | if (item.id === change) {
39 | this.items.splice(index, 1);
40 | }
41 | });
42 | }
43 | }
44 | });
45 | this.replicator.start();
46 | const query = this.db.query();
47 | this.items.push(...query);
48 | }
49 |
50 | addItem() {
51 | const id = this.db.createDocument({
52 | title: this.input,
53 | created_at: new Date().toJSON()
54 | });
55 | http.getJSON('https://randomuser.me/api/').then((json: any) => {
56 | const result = json.results;
57 | return result[0].picture.large;
58 | }).then(url => {
59 | return http.getFile(url).then(file => {
60 | this.db.setBlob(id, 'image', file.path, 'image/png');
61 | });
62 | }).catch(e => {
63 | console.log('error getting ' + e);
64 | });
65 | }
66 |
67 | generateId(): string {
68 | return 'xxxxxxxx-xxxx-xxxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
69 | const r = (Math.random() * 16) | 0,
70 | v = c === 'x' ? r : (r & 0x3) | 0x8;
71 | return v.toString(16);
72 | });
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/demo/app/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "main": "app.js",
3 | "android": {
4 | "v8Flags": "--expose_gc",
5 | "markingMode": "none"
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/demo/app/root-page.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/demo/app/search/search-page.ts:
--------------------------------------------------------------------------------
1 | import { SearchModel } from './search-view-model';
2 | import { EventData } from 'tns-core-modules/ui/core/view';
3 | import { Page } from 'tns-core-modules/ui/page';
4 | let vm;
5 | let page;
6 | export function pageLoaded(args: EventData) {
7 | vm = new SearchModel();
8 | page = args.object as Page;
9 | page.bindingContext = vm;
10 | page.getViewById('search').on('textChange', (args: any) => {
11 | vm.set('input', args.object.text);
12 | });
13 | }
14 |
--------------------------------------------------------------------------------
/demo/app/search/search-page.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/demo/app/search/search-view-model.ts:
--------------------------------------------------------------------------------
1 | import { Observable } from 'tns-core-modules/data/observable';
2 | import { ObservableArray } from 'tns-core-modules/data/observable-array';
3 | import { Couchbase } from 'nativescript-couchbase-plugin';
4 |
5 | export class SearchModel extends Observable {
6 | private db: Couchbase;
7 | items = new ObservableArray([]);
8 | input = '';
9 | constructor() {
10 | super();
11 | this.db = new Couchbase('tns-couchbase');
12 | }
13 |
14 | search(args) {
15 | const query = this.db.query({
16 | select: [],
17 | where: [
18 | {
19 | property: 'title',
20 | comparison: 'equalTo',
21 | value: this.input
22 | }
23 | ]
24 | });
25 | this.set('items', new ObservableArray([...query]));
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/demo/app/tests/tests.js:
--------------------------------------------------------------------------------
1 | var CouchbasePlugin = require("nativescript-couchbase-plugin").CouchbasePlugin;
2 | var couchbasePlugin = new CouchbasePlugin();
3 |
4 | describe("greet function", function() {
5 | it("exists", function() {
6 | expect(couchbasePlugin.greet).toBeDefined();
7 | });
8 |
9 | it("returns a string", function() {
10 | expect(couchbasePlugin.greet()).toEqual("Hello, NS");
11 | });
12 | });
--------------------------------------------------------------------------------
/demo/karma.conf.js:
--------------------------------------------------------------------------------
1 | module.exports = function (config) {
2 | const options = {
3 |
4 | // base path that will be used to resolve all patterns (eg. files, exclude)
5 | basePath: '',
6 |
7 |
8 | // frameworks to use
9 | // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
10 | frameworks: ['jasmine'],
11 |
12 |
13 | // list of files / patterns to load in the browser
14 | files: ['app/tests/**/*.*'],
15 |
16 |
17 | // list of files to exclude
18 | exclude: [
19 | ],
20 |
21 |
22 | // preprocess matching files before serving them to the browser
23 | // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
24 | preprocessors: {
25 | },
26 |
27 |
28 | // test results reporter to use
29 | // possible values: 'dots', 'progress'
30 | // available reporters: https://npmjs.org/browse/keyword/karma-reporter
31 | reporters: ['progress'],
32 |
33 |
34 | // web server port
35 | port: 9876,
36 |
37 |
38 | // enable / disable colors in the output (reporters and logs)
39 | colors: true,
40 |
41 |
42 | // level of logging
43 | // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
44 | logLevel: config.LOG_INFO,
45 |
46 |
47 | // enable / disable watching file and executing tests whenever any file changes
48 | autoWatch: true,
49 |
50 |
51 | // start these browsers
52 | // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
53 | browsers: [],
54 |
55 | customLaunchers: {
56 | android: {
57 | base: 'NS',
58 | platform: 'android'
59 | },
60 | ios: {
61 | base: 'NS',
62 | platform: 'ios'
63 | },
64 | ios_simulator: {
65 | base: 'NS',
66 | platform: 'ios',
67 | arguments: ['--emulator']
68 | }
69 | },
70 |
71 | // Continuous Integration mode
72 | // if true, Karma captures browsers, runs the tests and exits
73 | singleRun: false
74 | };
75 |
76 | setWebpackPreprocessor(config, options);
77 | setWebpack(config, options);
78 |
79 | config.set(options);
80 | }
81 |
82 | function setWebpackPreprocessor(config, options) {
83 | if (config && config.bundle) {
84 | if (!options.preprocessors) {
85 | options.preprocessors = {};
86 | }
87 |
88 | options.files.forEach(file => {
89 | if (!options.preprocessors[file]) {
90 | options.preprocessors[file] = [];
91 | }
92 | options.preprocessors[file].push('webpack');
93 | });
94 | }
95 | }
96 |
97 | function setWebpack(config, options) {
98 | if (config && config.bundle) {
99 | const env = {};
100 | env[config.platform] = true;
101 | env.sourceMap = config.debugBrk;
102 | options.webpack = require('./webpack.config')(env);
103 | delete options.webpack.entry;
104 | delete options.webpack.output.libraryTarget;
105 | const invalidPluginsForUnitTesting = ["GenerateBundleStarterPlugin", "GenerateNativeScriptEntryPointsPlugin"];
106 | options.webpack.plugins = options.webpack.plugins.filter(p => !invalidPluginsForUnitTesting.includes(p.constructor.name));
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/demo/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "nativescript": {
3 | "id": "com.github.triniwiz.couchbase.plugin.demo",
4 | "tns-ios": {
5 | "version": "6.0.1"
6 | },
7 | "tns-android": {
8 | "version": "6.0.0"
9 | }
10 | },
11 | "dependencies": {
12 | "nativescript-couchbase-plugin": "file:../src",
13 | "nativescript-theme-core": "^1.0.4",
14 | "nativescript-unit-test-runner": "0.7.0",
15 | "tns-core-modules": "6.1.1"
16 | },
17 | "devDependencies": {
18 | "jasmine-core": "^2.5.2",
19 | "karma": "4.1.0",
20 | "karma-jasmine": "2.0.1",
21 | "karma-nativescript-launcher": "^0.4.0",
22 | "nativescript-css-loader": "~0.26.1",
23 | "nativescript-dev-webpack": "1.2.0",
24 | "tns-platform-declarations": "6.1.1",
25 | "tslint": "~5.4.3",
26 | "typescript": "3.4.5",
27 | "karma-webpack": "3.0.5"
28 | },
29 | "scripts": {
30 | "build.plugin": "cd ../src && npm run build",
31 | "ci.tslint": "npm i && tslint --config '../tslint.json' 'app/**/*.ts' --exclude '**/node_modules/**'"
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/demo/references.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 | ///
3 |
--------------------------------------------------------------------------------
/demo/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es5",
4 | "module": "commonjs",
5 | "declaration": false,
6 | "removeComments": true,
7 | "noLib": false,
8 | "skipLibCheck": true,
9 | "emitDecoratorMetadata": true,
10 | "experimentalDecorators": true,
11 | "lib": [
12 | "es6",
13 | "dom"
14 | ],
15 | "pretty": true,
16 | "allowUnreachableCode": false,
17 | "allowUnusedLabels": false,
18 | "noEmitHelpers": true,
19 | "noEmitOnError": false,
20 | "noImplicitAny": false,
21 | "noImplicitReturns": true,
22 | "noImplicitUseStrict": false,
23 | "noFallthroughCasesInSwitch": true,
24 | "baseUrl": ".",
25 | "paths": {
26 | "*": [
27 | "./node_modules/*"
28 | ],
29 | "~/*": [
30 | "app/*"
31 | ]
32 | }
33 | },
34 | "include": [
35 | "../src",
36 | "**/*"
37 | ],
38 | "exclude": [
39 | "../src/node_modules",
40 | "node_modules",
41 | "platforms"
42 | ],
43 | "compileOnSave": false
44 | }
--------------------------------------------------------------------------------
/demo/tsconfig.tns.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./tsconfig",
3 | "compilerOptions": {
4 | "module": "esNext",
5 | "moduleResolution": "node"
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/publish/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Change Log
2 |
3 | ## [v0.9.0](https://github.com/triniwiz/nativescript-couchbase-plugin/tree/v0.9.0) (2019-01-22)
4 | [Full Changelog](https://github.com/triniwiz/nativescript-couchbase-plugin/compare/v0.8.1...v0.9.0)
5 |
6 | ## [v0.8.1](https://github.com/triniwiz/nativescript-couchbase-plugin/tree/v0.8.1) (2019-01-22)
7 | [Full Changelog](https://github.com/triniwiz/nativescript-couchbase-plugin/compare/v0.8.0...v0.8.1)
8 |
9 | **Implemented enhancements:**
10 |
11 | - Add blob/attachment [\#2](https://github.com/triniwiz/nativescript-couchbase-plugin/issues/2)
12 |
13 | ## [v0.8.0](https://github.com/triniwiz/nativescript-couchbase-plugin/tree/v0.8.0) (2019-01-22)
14 | [Full Changelog](https://github.com/triniwiz/nativescript-couchbase-plugin/compare/v0.7.0...v0.8.0)
15 |
16 | **Merged pull requests:**
17 |
18 | - Fix logical type check [\#13](https://github.com/triniwiz/nativescript-couchbase-plugin/pull/13) ([jerbob92](https://github.com/jerbob92))
19 | - Fix bug in operator support for iOS [\#12](https://github.com/triniwiz/nativescript-couchbase-plugin/pull/12) ([jerbob92](https://github.com/jerbob92))
20 | - Add missing float in number support [\#11](https://github.com/triniwiz/nativescript-couchbase-plugin/pull/11) ([jerbob92](https://github.com/jerbob92))
21 |
22 | ## [v0.7.0](https://github.com/triniwiz/nativescript-couchbase-plugin/tree/v0.7.0) (2019-01-22)
23 | [Full Changelog](https://github.com/triniwiz/nativescript-couchbase-plugin/compare/v0.6.0...v0.7.0)
24 |
25 | **Merged pull requests:**
26 |
27 | - Add support for long/float/double [\#10](https://github.com/triniwiz/nativescript-couchbase-plugin/pull/10) ([jerbob92](https://github.com/jerbob92))
28 |
29 | ## [v0.6.0](https://github.com/triniwiz/nativescript-couchbase-plugin/tree/v0.6.0) (2019-01-10)
30 | [Full Changelog](https://github.com/triniwiz/nativescript-couchbase-plugin/compare/v0.5.0...v0.6.0)
31 |
32 | **Closed issues:**
33 |
34 | - Receiving this error when attempting to use this plugin? [\#8](https://github.com/triniwiz/nativescript-couchbase-plugin/issues/8)
35 |
36 | **Merged pull requests:**
37 |
38 | - Add support for inBatch [\#9](https://github.com/triniwiz/nativescript-couchbase-plugin/pull/9) ([jerbob92](https://github.com/jerbob92))
39 |
40 | ## [v0.5.0](https://github.com/triniwiz/nativescript-couchbase-plugin/tree/v0.5.0) (2018-11-30)
41 | [Full Changelog](https://github.com/triniwiz/nativescript-couchbase-plugin/compare/v0.4.1...v0.5.0)
42 |
43 | **Merged pull requests:**
44 |
45 | - Feature/fix null values [\#7](https://github.com/triniwiz/nativescript-couchbase-plugin/pull/7) ([jerbob92](https://github.com/jerbob92))
46 | - Fix limit/offset query [\#6](https://github.com/triniwiz/nativescript-couchbase-plugin/pull/6) ([jerbob92](https://github.com/jerbob92))
47 | - fixed error with not implemented abstract methods [\#5](https://github.com/triniwiz/nativescript-couchbase-plugin/pull/5) ([elcreator](https://github.com/elcreator))
48 |
49 | ## [v0.4.1](https://github.com/triniwiz/nativescript-couchbase-plugin/tree/v0.4.1) (2018-11-29)
50 | [Full Changelog](https://github.com/triniwiz/nativescript-couchbase-plugin/compare/v0.4.0...v0.4.1)
51 |
52 | **Implemented enhancements:**
53 |
54 | - Add Query method [\#1](https://github.com/triniwiz/nativescript-couchbase-plugin/issues/1)
55 |
56 | ## [v0.4.0](https://github.com/triniwiz/nativescript-couchbase-plugin/tree/v0.4.0) (2018-11-29)
57 | [Full Changelog](https://github.com/triniwiz/nativescript-couchbase-plugin/compare/v0.3.2...v0.4.0)
58 |
59 | **Fixed bugs:**
60 |
61 | - Need Basic Authentication [\#4](https://github.com/triniwiz/nativescript-couchbase-plugin/issues/4)
62 | - Typo in source code [\#3](https://github.com/triniwiz/nativescript-couchbase-plugin/issues/3)
63 |
64 | ## [v0.3.2](https://github.com/triniwiz/nativescript-couchbase-plugin/tree/v0.3.2) (2018-10-23)
65 | [Full Changelog](https://github.com/triniwiz/nativescript-couchbase-plugin/compare/v0.0.1...v0.3.2)
66 |
67 | ## [v0.0.1](https://github.com/triniwiz/nativescript-couchbase-plugin/tree/v0.0.1) (2018-10-17)
68 |
69 |
70 | \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
--------------------------------------------------------------------------------
/publish/pack.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | SOURCE_DIR=../src;
4 | TO_SOURCE_DIR=src;
5 | PACK_DIR=package;
6 | ROOT_DIR=..;
7 | PUBLISH=--publish
8 |
9 | install(){
10 | npm i
11 | }
12 |
13 | pack() {
14 |
15 | echo 'Clearing /src and /package...'
16 | node_modules/.bin/rimraf "$TO_SOURCE_DIR"
17 | node_modules/.bin/rimraf "$PACK_DIR"
18 |
19 | # copy src
20 | echo 'Copying src...'
21 | node_modules/.bin/ncp "$SOURCE_DIR" "$TO_SOURCE_DIR"
22 |
23 | # copy README & LICENSE to src
24 | echo 'Copying README and LICENSE to /src...'
25 | node_modules/.bin/ncp "$ROOT_DIR"/LICENSE "$TO_SOURCE_DIR"/LICENSE
26 | node_modules/.bin/ncp "$ROOT_DIR"/README.md "$TO_SOURCE_DIR"/README.md
27 |
28 | # compile package and copy files required by npm
29 | echo 'Building /src...'
30 | cd "$TO_SOURCE_DIR"
31 | node_modules/.bin/tsc
32 | cd ..
33 |
34 | echo 'Creating package...'
35 | # create package dir
36 | mkdir "$PACK_DIR"
37 |
38 | # create the package
39 | cd "$PACK_DIR"
40 | npm pack ../"$TO_SOURCE_DIR"
41 |
42 | # delete source directory used to create the package
43 | cd ..
44 | node_modules/.bin/rimraf "$TO_SOURCE_DIR"
45 | }
46 |
47 | install && pack
--------------------------------------------------------------------------------
/publish/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "nativescript-publish",
3 | "version": "1.0.0",
4 | "description": "Publish helper",
5 | "devDependencies": {
6 | "ncp": "^2.0.0",
7 | "rimraf": "^2.5.0"
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/publish/publish.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | PACK_DIR=package;
4 |
5 | publish() {
6 | cd $PACK_DIR
7 | echo 'Publishing to npm...'
8 | npm publish *.tgz
9 | }
10 |
11 | ./pack.sh && publish
--------------------------------------------------------------------------------
/src/.npmignore:
--------------------------------------------------------------------------------
1 | *.map
2 | *.ts
3 | !*.d.ts
4 | .DS_Store
5 | tsconfig.json
6 | scripts/*
7 | platforms/android/*
8 | !platforms/android/include.gradle
9 | !platforms/android/*.aar
10 | !platforms/android/*.jar
11 |
--------------------------------------------------------------------------------
/src/couchbase-plugin.android.ts:
--------------------------------------------------------------------------------
1 | import {
2 | BlobBase,
3 | Common,
4 | ConcurrencyMode,
5 | Query,
6 | QueryComparisonOperator,
7 | QueryLogicalOperator,
8 | QueryMeta,
9 | ReplicatorBase
10 | } from './couchbase-plugin.common';
11 | import * as utils from 'tns-core-modules/utils/utils';
12 | import * as types from 'tns-core-modules/utils/types';
13 | import * as fs from 'tns-core-modules/file-system';
14 |
15 | export {
16 | Query,
17 | QueryMeta,
18 | QueryArrayOperator,
19 | QueryComparisonOperator,
20 | QueryLogicalOperator,
21 | QueryOrderItem,
22 | QueryWhereItem
23 | } from './couchbase-plugin.common';
24 |
25 | declare var com, co;
26 |
27 | export class Couchbase extends Common {
28 | config: any;
29 | android: any;
30 |
31 | constructor(name: string) {
32 | super(name);
33 | this.config = new com.couchbase.lite.DatabaseConfiguration(
34 | utils.ad.getApplicationContext()
35 | );
36 | this.android = new com.couchbase.lite.Database(name, this.config);
37 | }
38 |
39 | inBatch(batch: () => void) {
40 | const runnable = new java.lang.Runnable({
41 | run: () => {
42 | batch();
43 | }
44 | });
45 |
46 | this.android.inBatch(runnable);
47 | }
48 |
49 | createDocument(data: Object, documentId?: string) {
50 | try {
51 | let doc;
52 | if (documentId) {
53 | doc = new com.couchbase.lite.MutableDocument(documentId);
54 | } else {
55 | doc = new com.couchbase.lite.MutableDocument();
56 | }
57 | const keys = Object.keys(data);
58 | for (let key of keys) {
59 | const item = data[key];
60 | this.serialize(item, doc, key);
61 | }
62 | this.android.save(doc);
63 | return doc.getId();
64 | } catch (e) {
65 | console.error(e.message);
66 | return null;
67 | }
68 | }
69 |
70 | setBlob(id: string, name: string, blob: any, mimeType: string = 'application/octet-stream') {
71 | try {
72 | const document = this.android.getDocument(id).toMutable();
73 | if (typeof blob === 'string') {
74 | if (blob.startsWith(`file`)) {
75 | const nativeBlob = new com.couchbase.lite.Blob(mimeType, new java.net.URL(blob));
76 | document.setBlob(name, nativeBlob);
77 | } else if (blob.startsWith(`/`)) {
78 | const nativeBlob = new com.couchbase.lite.Blob(mimeType, new java.net.URL(`file://${blob}`));
79 | document.setBlob(name, nativeBlob);
80 | } else if (blob.startsWith(`~`)) {
81 | const path = fs.path.join(fs.knownFolders.currentApp().path, blob.replace('~', ''));
82 | const nativeBlob = new com.couchbase.lite.Blob(mimeType, new java.net.URL(`file://${path}`));
83 | document.setBlob(name, nativeBlob);
84 | } else if (blob.startsWith(`res`)) {
85 | const ctx = utils.ad.getApplicationContext() as android.content.Context;
86 | const is = ctx.getAssets().open(blob.replace('res://', ''));
87 | const nativeBlob = new com.couchbase.lite.Blob(mimeType, is);
88 | document.setBlob(name, nativeBlob);
89 | } else {
90 | // TODO what else to check?
91 | }
92 | this.android.save(document);
93 | } else {
94 | // TODO what else to check ... maybe native objects ??
95 | }
96 | } catch (e) {
97 | console.debug(e);
98 | }
99 | }
100 |
101 | getBlob(id: string, name: string) {
102 | let document = this.android.getDocument(id) as com.couchbase.lite.Document;
103 | if (!document) return null;
104 | const blob = document.getBlob(name);
105 | if (!blob) return null;
106 | return new Blob(blob);
107 | }
108 |
109 | private deserialize(data: any) {
110 | if (
111 | typeof data === 'string' ||
112 | typeof data === 'number' ||
113 | typeof data === 'boolean' ||
114 | typeof data !== 'object'
115 | )
116 | return data;
117 |
118 | if (types.isNullOrUndefined(data)) {
119 | return data;
120 | }
121 |
122 | switch (data.getClass().getName()) {
123 | case 'java.lang.String':
124 | return String(data);
125 | case 'java.lang.Boolean':
126 | return String(data) === 'true';
127 | case 'java.lang.Integer':
128 | case 'java.lang.Long':
129 | case 'java.lang.Double':
130 | case 'java.lang.Short':
131 | case 'java.lang.Float':
132 | return Number(data);
133 | case 'com.couchbase.lite.Dictionary':
134 | const keys = data.getKeys();
135 | const length = keys.size();
136 | const object = {};
137 | for (let i = 0; i < length; i++) {
138 | const key = keys.get(i);
139 | const nativeItem = data.getValue(key);
140 | object[key] = this.deserialize(nativeItem);
141 | }
142 | return object;
143 | case 'com.couchbase.lite.Array':
144 | const array = [];
145 | const size = data.count();
146 | for (let i = 0; i < size; i++) {
147 | const nativeItem = data.getValue(i);
148 | const item = this.deserialize(nativeItem);
149 | array.push(item);
150 | }
151 | return array;
152 | default:
153 | return data;
154 | }
155 | }
156 |
157 | getDocument(documentId: string): any {
158 | try {
159 | const doc = this.android.getDocument(documentId);
160 | if (!doc) return null;
161 | const keys = doc.getKeys();
162 | const size = keys.size();
163 | let object = {};
164 | object['id'] = doc.getId();
165 | for (let i = 0; i < size; i++) {
166 | const key = keys.get(i);
167 | const nativeItem = doc.getValue(key);
168 | const newItem = {};
169 | newItem[key] = this.deserialize(nativeItem);
170 | object = Object.assign(object, newItem);
171 | }
172 | return object;
173 | } catch (e) {
174 | console.error(e.message);
175 | return null;
176 | }
177 | }
178 |
179 | private fromISO8601UTC(date: string) {
180 | const dateFormat = new java.text.SimpleDateFormat(
181 | 'yyyy-MM-dd\'T\'HH:mm:ss.SSS'
182 | );
183 | const tz = java.util.TimeZone.getTimeZone('UTC');
184 | dateFormat.setTimeZone(tz);
185 | return dateFormat.parse(date);
186 | }
187 |
188 | private toISO8601UTC(date: Date) {
189 | const dateFormat = new java.text.SimpleDateFormat(
190 | 'yyyy-MM-dd\'T\'HH:mm:ss.SSS'
191 | );
192 | const tz = java.util.TimeZone.getTimeZone('UTC');
193 | dateFormat.setTimeZone(tz);
194 |
195 | return dateFormat.format(date);
196 | }
197 |
198 | updateDocument(documentId: string, data: any) {
199 | try {
200 | const origin = this.android.getDocument(
201 | documentId
202 | ) as com.couchbase.lite.Document;
203 | if (origin) {
204 | const doc = origin.toMutable();
205 | const keys = Object.keys(data);
206 | for (let key of keys) {
207 | const item = data[key];
208 | this.serialize(item, doc, key);
209 | }
210 | this.android.save(doc);
211 | }
212 | } catch (e) {
213 | console.error(e.message);
214 | }
215 | }
216 |
217 | private serializeObject(item: any, object: com.couchbase.lite.MutableDictionary, key: string) {
218 | if (item === null) {
219 | object.setValue(key, null);
220 | return;
221 | }
222 |
223 | switch (typeof item) {
224 | case 'object':
225 | if (item instanceof Date) {
226 | object.setDate(key, this.fromISO8601UTC(item.toISOString()));
227 | return;
228 | }
229 |
230 | if (Array.isArray(item)) {
231 | const array = new com.couchbase.lite.MutableArray();
232 | item.forEach(data => {
233 | this.serializeArray(data, array);
234 | });
235 | object.setArray(key, array);
236 | return;
237 | }
238 |
239 | const nativeObject = new com.couchbase.lite.MutableDictionary();
240 | Object.keys(item).forEach(itemKey => {
241 | const obj = item[itemKey];
242 | this.serializeObject(obj, nativeObject, itemKey);
243 | });
244 | object.setDictionary(key, nativeObject);
245 | break;
246 | case 'number':
247 | if (this.numberIs64Bit(item)) {
248 | if (this.numberHasDecimals(item)) {
249 | object.setDouble(key, item);
250 | } else {
251 | object.setLong(key, item);
252 | }
253 | } else {
254 | if (this.numberHasDecimals(item)) {
255 | object.setFloat(key, item);
256 | } else {
257 | object.setInt(key, item);
258 | }
259 | }
260 | break;
261 | case 'boolean':
262 | object.setBoolean(key, item);
263 | break;
264 | default:
265 | object.setValue(key, item);
266 | }
267 | }
268 |
269 | private serializeArray(item: any, array: com.couchbase.lite.MutableArray) {
270 | if (item === null) {
271 | array.addValue(null);
272 | return;
273 | }
274 |
275 | switch (typeof item) {
276 | case 'object':
277 | if (item instanceof Date) {
278 | array.addDate(this.fromISO8601UTC(item.toISOString()));
279 | return;
280 | }
281 |
282 | if (Array.isArray(item)) {
283 | const nativeArray = new com.couchbase.lite.MutableArray();
284 | item.forEach(data => {
285 | this.serializeArray(data, nativeArray);
286 | });
287 | array.addArray(nativeArray);
288 | return;
289 | }
290 |
291 | const object = new com.couchbase.lite.MutableDictionary();
292 | Object.keys(item).forEach(itemKey => {
293 | const obj = item[itemKey];
294 | this.serializeObject(obj, object, itemKey);
295 | });
296 | array.addDictionary(object);
297 | break;
298 | case 'number':
299 | if (this.numberIs64Bit(item)) {
300 | if (this.numberHasDecimals(item)) {
301 | array.addDouble(item);
302 | } else {
303 | array.addLong(item);
304 | }
305 | } else {
306 | if (this.numberHasDecimals(item)) {
307 | array.addFloat(item);
308 | } else {
309 | array.addInt(item);
310 | }
311 | }
312 | break;
313 | case 'boolean':
314 | array.addBoolean(item);
315 | break;
316 | default:
317 | array.addValue(item);
318 | }
319 | }
320 |
321 | private serialize(item: any, doc: com.couchbase.lite.MutableDocument, key: string) {
322 | if (item === null) {
323 | doc.setValue(key, null);
324 | return;
325 | }
326 |
327 | switch (typeof item) {
328 | case 'object':
329 | if (item instanceof Date) {
330 | doc.setDate(key, this.fromISO8601UTC(item.toISOString()));
331 | return;
332 | }
333 |
334 | if (Array.isArray(item)) {
335 | const array = new com.couchbase.lite.MutableArray();
336 | item.forEach(data => {
337 | this.serializeArray(data, array);
338 | });
339 | doc.setArray(key, array);
340 | return;
341 | }
342 |
343 | const object = new com.couchbase.lite.MutableDictionary();
344 | Object.keys(item).forEach(itemKey => {
345 | const obj = item[itemKey];
346 | this.serializeObject(obj, object, itemKey);
347 | });
348 | doc.setDictionary(key, object);
349 | break;
350 | case 'number':
351 | if (this.numberIs64Bit(item)) {
352 | if (this.numberHasDecimals(item)) {
353 | doc.setDouble(key, item);
354 | } else {
355 | doc.setLong(key, item);
356 | }
357 | } else {
358 | if (this.numberHasDecimals(item)) {
359 | doc.setFloat(key, item);
360 | } else {
361 | doc.setInt(key, item);
362 | }
363 | }
364 | break;
365 | case 'boolean':
366 | doc.setBoolean(key, item);
367 | break;
368 | default:
369 | doc.setValue(key, item);
370 | }
371 | }
372 |
373 | numberHasDecimals(item: number) {
374 | return !(item % 1 === 0);
375 | }
376 |
377 | numberIs64Bit(item: number) {
378 | return item < -Math.pow(2, 31) + 1 || item > Math.pow(2, 31) - 1;
379 | }
380 |
381 | deleteDocument(documentId: string, concurrencyMode: ConcurrencyMode = 1) {
382 | try {
383 | const doc = this.android.getDocument(documentId);
384 | return this.android.delete(doc, concurrencyMode === 1 ? com.couchbase.lite.ConcurrencyControl.FAIL_ON_CONFLICT :
385 | com.couchbase.lite.ConcurrencyControl.LAST_WRITE_WINS);
386 | } catch (e) {
387 | console.error(e.message);
388 | return false;
389 | }
390 | }
391 |
392 | destroyDatabase() {
393 | try {
394 | this.android.delete();
395 | } catch (e) {
396 | console.error(e.message);
397 | }
398 | }
399 |
400 | private serializeExpression(item) {
401 | if (item === null) {
402 | return null;
403 | }
404 |
405 | switch (typeof item) {
406 | case 'string':
407 | return com.couchbase.lite.Expression.string(item);
408 | case 'object':
409 | if (item instanceof Date) {
410 | return com.couchbase.lite.Expression.date(this.fromISO8601UTC(item.toISOString()));
411 | }
412 | return com.couchbase.lite.Expression.value(item);
413 |
414 | case 'number':
415 | if (this.numberIs64Bit(item)) {
416 | if (this.numberHasDecimals(item)) {
417 | return com.couchbase.lite.Expression.doubleValue(item);
418 | } else {
419 | return com.couchbase.lite.Expression.longValue(item);
420 | }
421 | } else {
422 | if (this.numberHasDecimals(item)) {
423 | return com.couchbase.lite.Expression.floatValue(item);
424 | } else {
425 | return com.couchbase.lite.Expression.intValue(item);
426 | }
427 | }
428 | case 'boolean':
429 | return com.couchbase.lite.Expression.booleanValue(item);
430 | default:
431 | return com.couchbase.lite.Expression.value(item);
432 | }
433 | }
434 |
435 | private setComparision(item) {
436 | let nativeQuery;
437 | switch (item.comparison as QueryComparisonOperator) {
438 | case 'equalTo':
439 | nativeQuery = com.couchbase.lite.Expression.property(
440 | item.property
441 | ).equalTo(this.serializeExpression(item.value));
442 | break;
443 | case 'add':
444 | nativeQuery = com.couchbase.lite.Expression.property(item.property).add(
445 | this.serializeExpression(item.value)
446 | );
447 | break;
448 | case 'between':
449 | if (Array.isArray(item.value) && item.value.length === 2) {
450 | nativeQuery = com.couchbase.lite.Expression.property(
451 | item.property
452 | ).between(
453 | com.couchbase.lite.Expression.value(this.serializeExpression(item.value[0])),
454 | com.couchbase.lite.Expression.value(this.serializeExpression(item.value[1]))
455 | );
456 | }
457 | break;
458 | case 'collate':
459 | nativeQuery = com.couchbase.lite.Expression.property(
460 | item.property
461 | ).collate(this.serializeExpression(item.value));
462 | break;
463 | case 'divide':
464 | nativeQuery = com.couchbase.lite.Expression.property(
465 | item.property
466 | ).divide(this.serializeExpression(item.value));
467 | break;
468 | case 'greaterThan':
469 | nativeQuery = com.couchbase.lite.Expression.property(
470 | item.property
471 | ).greaterThan(this.serializeExpression(item.value));
472 | break;
473 | case 'greaterThanOrEqualTo':
474 | nativeQuery = com.couchbase.lite.Expression.property(
475 | item.property
476 | ).greaterThanOrEqualTo(this.serializeExpression(item.value));
477 | break;
478 | case 'in':
479 | const inArray = [];
480 | if (Array.isArray(item.value)) {
481 | for (let exp of item.value) {
482 | inArray.push(this.serializeExpression(exp));
483 | }
484 | } else {
485 | inArray.push(this.serializeExpression(item.value));
486 | }
487 | nativeQuery = com.couchbase.lite.Expression.property(item.property).in(
488 | inArray
489 | );
490 | break;
491 | case 'is':
492 | nativeQuery = com.couchbase.lite.Expression.property(item.property).is(
493 | this.serializeExpression(item.value)
494 | );
495 | break;
496 | case 'isNot':
497 | nativeQuery = com.couchbase.lite.Expression.property(
498 | item.property
499 | ).isNot(this.serializeExpression(item.value));
500 | break;
501 | case 'isNullOrMissing':
502 | nativeQuery = com.couchbase.lite.Expression.property(
503 | item.property
504 | ).isNullOrMissing();
505 | break;
506 | case 'lessThan':
507 | nativeQuery = com.couchbase.lite.Expression.property(
508 | item.property
509 | ).lessThan(this.serializeExpression(item.value));
510 | break;
511 | case 'lessThanOrEqualTo':
512 | nativeQuery = com.couchbase.lite.Expression.property(
513 | item.property
514 | ).lessThanOrEqualTo(this.serializeExpression(item.value));
515 | break;
516 | case 'like':
517 | nativeQuery = com.couchbase.lite.Function.lower(
518 | com.couchbase.lite.Expression.property(item.property)
519 | ).like(this.serializeExpression(item.value));
520 | break;
521 | case 'modulo':
522 | nativeQuery = com.couchbase.lite.Expression.property(
523 | item.property
524 | ).modulo(this.serializeExpression(item.value));
525 | break;
526 | case 'multiply':
527 | nativeQuery = com.couchbase.lite.Expression.property(
528 | item.property
529 | ).multiply(this.serializeExpression(item.value));
530 | break;
531 |
532 | case 'notEqualTo':
533 | nativeQuery = com.couchbase.lite.Expression.property(
534 | item.property
535 | ).notEqualTo(this.serializeExpression(item.value));
536 | break;
537 |
538 | case 'notNullOrMissing':
539 | nativeQuery = com.couchbase.lite.Expression.property(
540 | item.property
541 | ).notNullOrMissing();
542 | break;
543 | case 'regex':
544 | nativeQuery = com.couchbase.lite.Function.lower(item.property)
545 | .regex(this.serializeExpression(item.value));
546 | break;
547 | }
548 | return nativeQuery;
549 | }
550 |
551 | query(query: Query = {select: [QueryMeta.ALL, QueryMeta.ID]}) {
552 | const items = [];
553 | let select = [];
554 | let isAll = false;
555 | if (!query.select || query.select.length === 0) {
556 | isAll = true;
557 | select.push(com.couchbase.lite.SelectResult.all());
558 | select.push(
559 | com.couchbase.lite.SelectResult.expression(com.couchbase.lite.Meta.id)
560 | );
561 | } else {
562 | query.select.forEach(item => {
563 | if (item === QueryMeta.ID) {
564 | select.push(
565 | com.couchbase.lite.SelectResult.expression(
566 | com.couchbase.lite.Meta.id
567 | )
568 | );
569 | } else if (item === QueryMeta.ALL) {
570 | isAll = true;
571 | select.push(com.couchbase.lite.SelectResult.all());
572 | } else {
573 | select.push(com.couchbase.lite.SelectResult.property(item));
574 | }
575 | });
576 | }
577 | let queryBuilder: any = com.couchbase.lite.QueryBuilder.select(select);
578 | if (query.from) {
579 | const db = new Couchbase(query.from);
580 | queryBuilder = queryBuilder.from(
581 | com.couchbase.lite.DataSource.database(db.android)
582 | );
583 | } else {
584 | queryBuilder = queryBuilder.from(
585 | com.couchbase.lite.DataSource.database(this.android)
586 | );
587 | }
588 |
589 | let nativeQuery = null;
590 | if (query.where) {
591 | for (let item of query.where) {
592 | if (item.logical === QueryLogicalOperator.AND) {
593 | if (!nativeQuery) break;
594 | nativeQuery = nativeQuery.and(this.setComparision(item));
595 | } else if (item.logical === QueryLogicalOperator.OR) {
596 | if (!nativeQuery) break;
597 | nativeQuery = nativeQuery.or(this.setComparision(item));
598 | } else {
599 | nativeQuery = this.setComparision(item);
600 | }
601 | }
602 | if (nativeQuery) {
603 | queryBuilder = queryBuilder.where(nativeQuery);
604 | }
605 | }
606 | if (query.groupBy) {
607 | const groupBy = [];
608 | for (let prop of query.groupBy) {
609 | groupBy.push(com.couchbase.lite.Expression.property(prop));
610 | }
611 | if (groupBy.length > 0) {
612 | queryBuilder = queryBuilder.groupBy(groupBy);
613 | }
614 | }
615 | if (query.order) {
616 | const orderBy = [];
617 | for (let item of query.order) {
618 | if (item.direction === 'desc') {
619 | orderBy.push(
620 | com.couchbase.lite.Ordering.property(item.property).descending()
621 | );
622 | } else {
623 | orderBy.push(
624 | com.couchbase.lite.Ordering.property(item.property).ascending()
625 | );
626 | }
627 | }
628 | if (orderBy.length > 0) {
629 | queryBuilder = queryBuilder.orderBy(orderBy);
630 | }
631 | }
632 |
633 | if (query.limit && typeof query.limit === 'number') {
634 | if (query.offset && typeof query.offset === 'number') {
635 | queryBuilder = queryBuilder.limit(
636 | com.couchbase.lite.Expression.intValue(query.limit),
637 | com.couchbase.lite.Expression.intValue(query.offset)
638 | );
639 | } else {
640 | queryBuilder = queryBuilder.limit(
641 | com.couchbase.lite.Expression.intValue(query.limit)
642 | );
643 | }
644 | }
645 |
646 | const result = queryBuilder.execute().allResults();
647 | const size = result.size();
648 | for (let i = 0; i < size; i++) {
649 | const item = result.get(i);
650 | const keys = item.getKeys();
651 | const keysSize = keys.size();
652 | const obj = {};
653 | for (let keyId = 0; keyId < keysSize; keyId++) {
654 | const key = keys.get(keyId);
655 | const nativeItem = item.getValue(key);
656 | if (
657 | isAll &&
658 | nativeItem &&
659 | nativeItem.getClass &&
660 | nativeItem.getClass() &&
661 | nativeItem.getClass().getName() === 'com.couchbase.lite.Dictionary'
662 | ) {
663 | const cblKeys = nativeItem.getKeys();
664 | const cblKeysSize = cblKeys.size();
665 | for (let cblKeysId = 0; cblKeysId < cblKeysSize; cblKeysId++) {
666 | const cblKey = cblKeys.get(cblKeysId);
667 | obj[cblKey] = this.deserialize(nativeItem.getValue(cblKey));
668 | }
669 | } else {
670 | obj[key] = this.deserialize(nativeItem);
671 | }
672 | }
673 | items.push(obj);
674 | }
675 |
676 | return items;
677 | }
678 |
679 | createReplication(remoteUrl: string, direction: 'push' | 'pull' | 'both') {
680 |
681 | const uri = new com.couchbase.lite.URLEndpoint(new java.net.URI(remoteUrl));
682 | const repConfig = new com.couchbase.lite.ReplicatorConfiguration(
683 | this.android,
684 | uri
685 | );
686 | if (direction === 'pull') {
687 | repConfig.setReplicatorType(
688 | com.couchbase.lite.ReplicatorConfiguration.ReplicatorType.PULL
689 | );
690 | } else if (direction === 'push') {
691 | repConfig.setReplicatorType(
692 | com.couchbase.lite.ReplicatorConfiguration.ReplicatorType.PUSH
693 | );
694 | } else {
695 | repConfig.setReplicatorType(
696 | com.couchbase.lite.ReplicatorConfiguration.ReplicatorType.PUSH_AND_PULL
697 | );
698 | }
699 |
700 | const replicator = new com.couchbase.lite.Replicator(repConfig);
701 |
702 | return new Replicator(replicator);
703 |
704 | }
705 |
706 | createPullReplication(
707 | remoteUrl: string
708 | ) {
709 | return this.createReplication(remoteUrl, 'pull');
710 | }
711 |
712 | createPushReplication(
713 | remoteUrl: string
714 | ) {
715 | return this.createReplication(remoteUrl, 'push');
716 | }
717 |
718 | private _listenerMap = {};
719 |
720 | addDatabaseChangeListener(callback: any) {
721 | const listener = (co as any).fitcom.fancycouchbase.TNSDatabaseChangeListener.extend({
722 | onChange(changes: any): void {
723 | if (callback && typeof callback === 'function') {
724 | const ids = [];
725 | const documentIds = changes.getDocumentIDs();
726 | const size = documentIds.size();
727 | for (let i = 0; i < size; i++) {
728 | const item = documentIds.get(i);
729 | ids.push(item);
730 | }
731 | callback(ids);
732 | }
733 | }
734 | });
735 | const token = this.android.addChangeListener(new listener());
736 | if (!types.isNullOrUndefined(token)) {
737 | this._listenerMap[callback] = token;
738 | }
739 | }
740 |
741 | removeDatabaseChangeListener(callback: any) {
742 | const token = this._listenerMap[callback];
743 | if (!types.isNullOrUndefined(token)) {
744 | this.android.removeChangeListener(token);
745 | delete this._listenerMap[callback];
746 | }
747 | }
748 |
749 | }
750 |
751 | export class Replicator extends ReplicatorBase {
752 | constructor(replicator: any) {
753 | super(replicator);
754 | }
755 |
756 | start() {
757 | this.replicator.start();
758 | }
759 |
760 | stop() {
761 | this.replicator.stop();
762 | }
763 |
764 | isRunning() {
765 | return (
766 | this.replicator.getStatus().getActivityLevel() ===
767 | com.couchbase.lite.AbstractReplicator.ActivityLevel.BUSY
768 | );
769 | }
770 |
771 | setContinuous(isContinuous: boolean) {
772 | const newConfig = new com.couchbase.lite.ReplicatorConfiguration(this.replicator.getConfig());
773 | newConfig.setContinuous(isContinuous);
774 | this.replicator = new com.couchbase.lite.Replicator(newConfig);
775 | }
776 |
777 | setSessionId(sessionId: string) {
778 | const newConfig = new com.couchbase.lite.ReplicatorConfiguration(this.replicator.getConfig());
779 | newConfig.setAuthenticator(
780 | new com.couchbase.lite.SessionAuthenticator(sessionId)
781 | );
782 | this.replicator = new com.couchbase.lite.Replicator(newConfig);
783 | }
784 |
785 | setSessionIdAndCookieName(sessionId: string, cookieName: string) {
786 | const newConfig = new com.couchbase.lite.ReplicatorConfiguration(this.replicator.getConfig());
787 | newConfig.setAuthenticator(
788 | new com.couchbase.lite.SessionAuthenticator(sessionId, cookieName)
789 | );
790 | this.replicator = new com.couchbase.lite.Replicator(newConfig);
791 | }
792 |
793 | setUserNameAndPassword(username: string, password: string) {
794 | const newConfig = new com.couchbase.lite.ReplicatorConfiguration(this.replicator.getConfig());
795 | newConfig.setAuthenticator(
796 | new com.couchbase.lite.BasicAuthenticator(username, password)
797 | );
798 | this.replicator = new com.couchbase.lite.Replicator(newConfig);
799 | }
800 |
801 | setChannels(channels: string[]) {
802 | const newConfig = new com.couchbase.lite.ReplicatorConfiguration(this.replicator.getConfig());
803 | newConfig.setChannels(java.util.Arrays.asList(channels));
804 | this.replicator = new com.couchbase.lite.Replicator(newConfig);
805 | };
806 | }
807 |
808 | export class Blob extends BlobBase {
809 | constructor(blob: any) {
810 | super(blob);
811 | }
812 |
813 | get android() {
814 | return this.blob;
815 | }
816 |
817 | get content(): any {
818 | if (!this.android) return null;
819 | return this.android.getContent();
820 | }
821 |
822 | get contentStream(): any {
823 | if (!this.android) return null;
824 | this.android.length();
825 | return this.android.getContentStream();
826 | }
827 |
828 | get contentType(): string {
829 | if (!this.android) return null;
830 | return this.android.getContentType();
831 | }
832 |
833 | get length(): number {
834 | if (!this.android) return 0;
835 | return this.android.length();
836 | }
837 |
838 | get digest(): string {
839 | if (!this.android) return null;
840 | return this.android.digest();
841 | }
842 |
843 | get properties(): Map {
844 | const map = new Map();
845 | if (!this.android) return map;
846 | const nativeMap = this.android.getProperties();
847 | const mapKeys = nativeMap.keySet();
848 | const mapKeysArray = mapKeys.toArray();
849 | const length = mapKeysArray.length;
850 | for (let i = 0; i < length; i++) {
851 | const key = mapKeysArray[i];
852 | const value = nativeMap.get(key);
853 | map.set(key, value);
854 | }
855 | return map;
856 | }
857 |
858 | }
859 |
--------------------------------------------------------------------------------
/src/couchbase-plugin.common.ts:
--------------------------------------------------------------------------------
1 | export abstract class Common {
2 | ios: any;
3 | android: any;
4 | config: any;
5 |
6 | constructor(databaseName: string) {
7 | }
8 |
9 | abstract createDocument(data: Object, documentId?: string);
10 |
11 | abstract getDocument(documentId: string);
12 |
13 | abstract updateDocument(documentId: string, data: any);
14 |
15 | abstract deleteDocument(documentId: string);
16 |
17 | abstract destroyDatabase();
18 |
19 | abstract query(query: Query): any[];
20 |
21 | abstract createPullReplication(remoteUrl: string);
22 |
23 | abstract createPushReplication(remoteUrl: string);
24 |
25 | abstract createReplication(remoteUrl: string, direction: 'push' | 'pull' | 'both');
26 |
27 | abstract addDatabaseChangeListener(callback: any);
28 |
29 | abstract inBatch(batch: () => void);
30 |
31 | abstract setBlob(id: string, name: string, blob: any, mimeType: string);
32 |
33 | abstract getBlob(id: string, name: string);
34 | }
35 |
36 | export abstract class ReplicatorBase {
37 | replicator: any;
38 |
39 | constructor(replicator: any) {
40 | this.replicator = replicator;
41 | }
42 |
43 | abstract start();
44 |
45 | abstract stop();
46 |
47 | abstract isRunning();
48 |
49 | abstract setContinuous(isContinuous: boolean);
50 |
51 | abstract setUserNameAndPassword(username: string, password: string);
52 |
53 | abstract setChannels(channels: string[]);
54 |
55 | abstract setSessionIdAndCookieName(sessionId: string, cookieName: string);
56 |
57 | abstract setSessionId(sessionId: string);
58 | }
59 |
60 | export enum QueryMeta {
61 | ALL = 'COUCHBASE_ALL',
62 | ID = 'COUCHBASE_ID'
63 | }
64 |
65 | export type QueryComparisonOperator =
66 | | 'modulo'
67 | | 'is'
68 | | 'between'
69 | | 'isNot'
70 | | 'collate'
71 | | 'in'
72 | | 'add'
73 | | 'isNullOrMissing'
74 | | 'greaterThan'
75 | | 'divide'
76 | | 'notEqualTo'
77 | | 'greaterThanOrEqualTo'
78 | | 'like'
79 | | 'subtract'
80 | | 'lessThanOrEqualTo'
81 | | 'lessThan'
82 | | 'notNullOrMissing'
83 | | 'regex'
84 | | 'equalTo'
85 | | 'multiply';
86 |
87 | export enum QueryLogicalOperator {
88 | AND = 'and',
89 | OR = 'or'
90 | }
91 |
92 | export enum QueryArrayOperator {
93 | CONTAINS = 'contains'
94 | }
95 |
96 | export interface Query {
97 | select: any[];
98 | // join?: any[];
99 | where?: QueryWhereItem[];
100 | groupBy?: any;
101 | // having?: any;
102 | order?: QueryOrderItem[];
103 | limit?: any;
104 | offset?: any;
105 | from?: string;
106 | }
107 |
108 | export interface QueryWhereItem {
109 | logical?: QueryLogicalOperator;
110 | property: string;
111 | comparison: QueryComparisonOperator;
112 | value: any;
113 | }
114 |
115 | export interface QueryOrderItem {
116 | property: string;
117 | direction: 'asc' | 'desc';
118 | }
119 |
120 |
121 | export abstract class BlobBase {
122 | blob: any;
123 |
124 | readonly ios: any;
125 |
126 | readonly android: any;
127 |
128 | readonly content: any;
129 |
130 | readonly contentStream: any;
131 |
132 | readonly contentType: string;
133 |
134 | readonly length: number;
135 |
136 | readonly digest: string;
137 |
138 | readonly properties: Map;
139 |
140 | constructor(blob: any) {
141 | this.blob = blob;
142 | }
143 | }
144 |
145 | export enum ConcurrencyMode {
146 | 'LastWriteWins' = 0,
147 | 'FailOnConflict' = 1
148 | }
149 |
--------------------------------------------------------------------------------
/src/couchbase-plugin.ios.ts:
--------------------------------------------------------------------------------
1 | import {
2 | BlobBase,
3 | Common,
4 | ConcurrencyMode,
5 | Query,
6 | QueryComparisonOperator,
7 | QueryLogicalOperator,
8 | QueryMeta,
9 | ReplicatorBase
10 | } from './couchbase-plugin.common';
11 | import * as types from 'tns-core-modules/utils/types';
12 | import * as fs from 'tns-core-modules/file-system';
13 |
14 | export {
15 | Query, QueryMeta, QueryArrayOperator, QueryComparisonOperator, QueryLogicalOperator, QueryOrderItem, QueryWhereItem
16 | } from './couchbase-plugin.common';
17 |
18 |
19 | declare var CBLDatabase,
20 | CBLMutableDocument,
21 | CBLURLEndpoint,
22 | CBLReplicatorConfiguration,
23 | CBLReplicatorType,
24 | CBLBasicAuthenticator,
25 | CBLReplicator,
26 | CBLQueryExpression,
27 | CBLQueryOrdering,
28 | CBLQueryBuilder,
29 | CBLReplicatorActivityLevel,
30 | CBLQueryDataSource,
31 | CBLQuerySelectResult,
32 | CBLQueryMeta;
33 |
34 | export class Couchbase extends Common {
35 | ios: CBLDatabase;
36 |
37 | constructor(databaseName: string) {
38 | super(databaseName);
39 | this.ios = CBLDatabase.alloc().initWithNameError(databaseName);
40 | }
41 |
42 | inBatch(batch: () => void) {
43 | const errorRef = new interop.Reference() as interop.Reference;
44 | this.ios.inBatchUsingBlock(errorRef, batch);
45 | }
46 |
47 | createDocument(data: Object, documentId?: string) {
48 | let doc: CBLMutableDocument;
49 | if (documentId) {
50 | doc = CBLMutableDocument.alloc().initWithID(documentId);
51 | } else {
52 | doc = CBLMutableDocument.alloc().init();
53 | }
54 |
55 | const keys = Object.keys(data);
56 | for (let key of keys) {
57 | const item = data[key];
58 | this.serialize(item, doc, key);
59 | }
60 | this.ios.saveDocumentError(doc);
61 | return doc.id;
62 | }
63 |
64 | setBlob(id: string, name: string, blob: any, mimeType: string = 'application/octet-stream') {
65 | try {
66 | const document = this.ios.documentWithID(id).toMutable();
67 | if (typeof blob === 'string') {
68 | if (blob.startsWith(`file`)) {
69 | const nativeBlob = CBLBlob.alloc().initWithContentTypeFileURLError(mimeType, NSURL.URLWithString(blob));
70 | document.setBlobForKey(nativeBlob, name);
71 | } else if (blob.startsWith(`/`)) {
72 | const nativeBlob = CBLBlob.alloc().initWithContentTypeFileURLError(mimeType, NSURL.fileURLWithPath(blob));
73 | document.setBlobForKey(nativeBlob, name);
74 | } else if (blob.startsWith(`~`)) {
75 | const path = fs.path.join(fs.knownFolders.currentApp().path, blob.replace('~', ''));
76 | const nativeBlob = CBLBlob.alloc().initWithContentTypeFileURLError(mimeType, NSURL.URLWithString(path));
77 | document.setBlobForKey(nativeBlob, name);
78 | } else if (blob.startsWith(`res`)) {
79 | const bundle = NSBundle.mainBundle;
80 | const path = bundle.pathForResourceOfType(blob.replace('res://', ''), this.getExtension(mimeType));
81 | const nativeBlob = CBLBlob.alloc().initWithContentTypeFileURLError(mimeType, NSURL.URLWithString(path));
82 | document.setBlobForKey(nativeBlob, name);
83 | } else {
84 | // TODO what else to check?
85 | }
86 | this.ios.saveDocumentError(document);
87 | } else {
88 | // TODO what else to check ... maybe native objects ??
89 | }
90 | } catch (e) {
91 | console.debug(e);
92 | }
93 | }
94 |
95 | getBlob(id: string, name: string) {
96 | let document = this.ios.documentWithID(id) as CBLDocument;
97 | if (!document) return null;
98 | const blob = document.blobForKey(name);
99 | if (!blob) return null;
100 | return new Blob(blob);
101 | }
102 |
103 | private fromISO8601UTC(date: string) {
104 | const dateFormatter = NSDateFormatter.new();
105 | dateFormatter.dateFormat = 'yyyy-MM-dd\'T\'HH:mm:ss.SSSZ';
106 | return dateFormatter.dateFromString(date);
107 | }
108 |
109 | private serializeObject(item: any, object: CBLMutableDictionary, key: string) {
110 | if (item === null) {
111 | object.setValueForKey(null, key);
112 | return;
113 | }
114 |
115 | switch (typeof item) {
116 | case 'object':
117 | if (item instanceof Date) {
118 | object.setDateForKey(this.fromISO8601UTC(item.toISOString()), key);
119 | return;
120 | }
121 |
122 | if (Array.isArray(item)) {
123 | const array = CBLMutableArray.new();
124 | item.forEach((data) => {
125 | this.serializeArray(data, array);
126 | });
127 | object.setArrayForKey(array, key);
128 | return;
129 | }
130 |
131 | const nativeObject = CBLMutableDictionary.new();
132 | Object.keys(item).forEach((itemKey) => {
133 | const obj = item[itemKey];
134 | this.serializeObject(obj, nativeObject, itemKey);
135 | });
136 | object.setDictionaryForKey(nativeObject, key);
137 | break;
138 | case 'number':
139 | if (this.numberIs64Bit(item)) {
140 | if (this.numberHasDecimals(item)) {
141 | object.setDoubleForKey(item, key);
142 | } else {
143 | object.setLongLongForKey(item, key);
144 | }
145 | } else {
146 | if (this.numberHasDecimals(item)) {
147 | object.setFloatForKey(item, key);
148 | } else {
149 | object.setIntegerForKey(item, key);
150 | }
151 | }
152 | break;
153 | case 'boolean':
154 | object.setBooleanForKey(item, key);
155 | break;
156 | default:
157 | object.setValueForKey(item, key);
158 | }
159 | }
160 |
161 | private serializeArray(item: any, array: CBLMutableArray) {
162 | if (item === null) {
163 | array.addValue(null);
164 | return;
165 | }
166 |
167 | switch (typeof item) {
168 | case 'object':
169 | if (item instanceof Date) {
170 | array.addDate(this.fromISO8601UTC(item.toISOString()));
171 | return;
172 | }
173 |
174 | if (Array.isArray(item)) {
175 | const nativeArray = CBLMutableArray.new();
176 | item.forEach((data) => {
177 | this.serializeArray(data, nativeArray);
178 | });
179 | array.addArray(nativeArray);
180 | return;
181 | }
182 |
183 | const object = CBLMutableDictionary.new();
184 | Object.keys(item).forEach((itemKey) => {
185 | const obj = item[itemKey];
186 | this.serializeObject(obj, object, itemKey);
187 | });
188 | array.addDictionary(object);
189 | break;
190 | case 'number':
191 | if (this.numberIs64Bit(item)) {
192 | if (this.numberHasDecimals(item)) {
193 | array.addDouble(item);
194 | } else {
195 | array.addLongLong(item);
196 | }
197 | } else {
198 | if (this.numberHasDecimals(item)) {
199 | array.addFloat(item);
200 | } else {
201 | array.addInteger(item);
202 | }
203 | }
204 | break;
205 | case 'boolean':
206 | array.addBoolean(item);
207 | break;
208 | default:
209 | array.addValue(item);
210 | }
211 | }
212 |
213 | private serialize(item: any, doc: CBLMutableDocument, key: string) {
214 | if (item === null) {
215 | doc.setValueForKey(null, key);
216 | return;
217 | }
218 |
219 | switch (typeof item) {
220 | case 'object':
221 | if (item instanceof Date) {
222 | doc.setDateForKey(this.fromISO8601UTC(item.toISOString()), key);
223 | return;
224 | }
225 |
226 | if (Array.isArray(item)) {
227 | const array = CBLMutableArray.new();
228 | item.forEach((data) => {
229 | this.serializeArray(data, array);
230 | });
231 | doc.setArrayForKey(array, key);
232 | return;
233 | }
234 |
235 | const object = CBLMutableDictionary.new();
236 | Object.keys(item).forEach((itemKey) => {
237 | const obj = item[itemKey];
238 | this.serializeObject(obj, object, itemKey);
239 | });
240 | doc.setDictionaryForKey(object, key);
241 | break;
242 | case 'number':
243 | if (this.numberIs64Bit(item)) {
244 | if (this.numberHasDecimals(item)) {
245 | doc.setDoubleForKey(item, key);
246 | } else {
247 | doc.setLongLongForKey(item, key);
248 | }
249 | } else {
250 | if (this.numberHasDecimals(item)) {
251 | doc.setFloatForKey(item, key);
252 | } else {
253 | doc.setIntegerForKey(item, key);
254 | }
255 | }
256 | break;
257 | case 'boolean':
258 | doc.setBooleanForKey(item, key);
259 | break;
260 | default:
261 | doc.setValueForKey(item, key);
262 | }
263 | }
264 |
265 | getDocument(documentId: string): any {
266 | const doc = this.ios.documentWithID(documentId);
267 | if (doc) {
268 | let obj = {};
269 | const keys = doc.keys;
270 | const size = keys.count;
271 | obj['id'] = doc.id;
272 | for (let i = 0; i < size; i++) {
273 | const key = keys.objectAtIndex(i);
274 | const value = doc.valueForKey(key);
275 | const newValue = {};
276 | newValue[key] = this.deserialize(value);
277 | obj = Object.assign(obj, newValue);
278 | }
279 | return obj;
280 | }
281 | return null;
282 | }
283 |
284 | numberHasDecimals(item: number) {
285 | return !(item % 1 === 0);
286 | }
287 |
288 | numberIs64Bit(item: number) {
289 | return item < -Math.pow(2, 31) + 1 || item > Math.pow(2, 31) - 1;
290 | }
291 |
292 | private deserialize(data: any) {
293 | if (typeof data === 'string' || typeof data === 'number' || typeof data === 'boolean' || typeof data !== 'object') return data;
294 |
295 | if (types.isNullOrUndefined(data)) {
296 | return data;
297 | }
298 |
299 | if (data instanceof NSNull) {
300 | return null;
301 | }
302 |
303 | if (data instanceof CBLDictionary) {
304 | const keys = data.keys;
305 | const length = keys.count;
306 | const object = {};
307 | for (let i = 0; i < length; i++) {
308 | const key = keys.objectAtIndex(i);
309 | const nativeItem = data.valueForKey(key);
310 | object[key] = this.deserialize(nativeItem);
311 | }
312 | return object;
313 | }
314 |
315 | if (data instanceof CBLArray) {
316 | const array = [];
317 | const size = data.count;
318 | for (let i = 0; i < size; i++) {
319 | const nativeItem = data.valueAtIndex(i);
320 | const item = this.deserialize(nativeItem);
321 | array.push(item);
322 | }
323 | return array;
324 | }
325 |
326 | return data;
327 | }
328 |
329 | updateDocument(documentId: string, data: any) {
330 | const original = this.ios.documentWithID(documentId);
331 | const newDoc = original.toMutable();
332 | const keys = Object.keys(data);
333 | for (let key of keys) {
334 | const item = data[key];
335 | this.serialize(item, newDoc, key);
336 | }
337 | this.ios.saveDocumentError(newDoc);
338 | }
339 |
340 | deleteDocument(documentId: string, concurrencyMode: ConcurrencyMode = 1) {
341 |
342 | const doc = this.ios.documentWithID(documentId);
343 | return this.ios.deleteDocumentConcurrencyControlError(doc,
344 | concurrencyMode === 1 ? CBLConcurrencyControl.kCBLConcurrencyControlFailOnConflict :
345 | CBLConcurrencyControl.kCBLConcurrencyControlLastWriteWins);
346 | }
347 |
348 | destroyDatabase() {
349 | return this.ios.delete();
350 | }
351 |
352 | createReplication(remoteUrl: string, direction: 'push' | 'pull' | 'both') {
353 | const url = NSURL.alloc().initWithString(remoteUrl);
354 | const targetEndpoint = CBLURLEndpoint.alloc().initWithURL(url);
355 | const replConfig = CBLReplicatorConfiguration.alloc().initWithDatabaseTarget(
356 | this.ios,
357 | targetEndpoint
358 | );
359 | if (direction === 'pull') {
360 | replConfig.replicatorType = CBLReplicatorType.kCBLReplicatorTypePull;
361 | } else if (direction === 'push') {
362 | replConfig.replicatorType = CBLReplicatorType.kCBLReplicatorTypePush;
363 | } else {
364 | replConfig.replicatorType = CBLReplicatorType.kCBLReplicatorTypePushAndPull;
365 | }
366 |
367 | const replicator = CBLReplicator.alloc().initWithConfig(replConfig);
368 |
369 | return new Replicator(replicator);
370 | }
371 |
372 | createPushReplication(
373 | remoteUrl: string
374 | ) {
375 | return this.createReplication(remoteUrl, 'push');
376 | }
377 |
378 | createPullReplication(
379 | remoteUrl: string
380 | ) {
381 | return this.createReplication(remoteUrl, 'pull');
382 | }
383 |
384 | private _listenerMap = {};
385 |
386 | addDatabaseChangeListener(callback: any) {
387 | const token = this.ios.addChangeListener((change: any) => {
388 | if (callback && typeof callback === 'function') {
389 | const ids = [];
390 | const documentIds = change.documentIDs;
391 | const size = documentIds.count;
392 | for (let i = 0; i < size; i++) {
393 | const item = documentIds[i];
394 | ids.push(item);
395 | }
396 | callback(ids);
397 | }
398 | });
399 | if (!types.isNullOrUndefined(token)) {
400 | this._listenerMap[callback] = token;
401 | }
402 | }
403 |
404 | removeDatabaseChangeListener(callback: any) {
405 | const token = this._listenerMap[callback];
406 | if (!types.isNullOrUndefined(token)) {
407 | this.ios.removeChangeListenerWithToken(token);
408 | delete this._listenerMap[callback];
409 | }
410 | }
411 |
412 | private serializeExpression(item) {
413 | if (item === null) {
414 | return null;
415 | }
416 |
417 | switch (typeof item) {
418 | case 'string':
419 | return CBLQueryExpression.string(item);
420 | case 'object':
421 | if (item instanceof Date) {
422 | return CBLQueryExpression.date(this.fromISO8601UTC(item.toISOString()));
423 | }
424 | return CBLQueryExpression.value(item);
425 |
426 | case 'number':
427 | if (this.numberIs64Bit(item)) {
428 | if (this.numberHasDecimals(item)) {
429 | return CBLQueryExpression.double(item);
430 | } else {
431 | return CBLQueryExpression.longLong(item);
432 | }
433 | } else {
434 | if (this.numberHasDecimals(item)) {
435 | return CBLQueryExpression.float(item);
436 | } else {
437 | return CBLQueryExpression.integer(item);
438 | }
439 | }
440 | case 'boolean':
441 | return CBLQueryExpression.boolean(item);
442 | default:
443 | return CBLQueryExpression.value(item);
444 | }
445 | }
446 |
447 | private setComparision(item) {
448 | let nativeQuery;
449 | switch (item.comparison as QueryComparisonOperator) {
450 | case 'equalTo':
451 | nativeQuery = CBLQueryExpression.property(
452 | item.property
453 | ).equalTo(this.serializeExpression(item.value));
454 | break;
455 | case 'add':
456 | nativeQuery = CBLQueryExpression.property(
457 | item.property
458 | ).add(this.serializeExpression(item.value));
459 | break;
460 | case 'between':
461 | if (Array.isArray(item.value) && item.value.length === 2) {
462 | nativeQuery = CBLQueryExpression.property(
463 | item.property
464 | ).between(this.serializeExpression(item.value[0])).andExpression(this.serializeExpression(item.value[1]));
465 | }
466 | break;
467 | case 'collate':
468 | nativeQuery = CBLQueryExpression.property(
469 | item.property
470 | ).collate(this.serializeExpression(item.value));
471 | break;
472 | case 'divide':
473 | nativeQuery = CBLQueryExpression.property(
474 | item.property
475 | ).divide(this.serializeExpression(item.value));
476 | break;
477 | case 'greaterThan':
478 | nativeQuery = CBLQueryExpression.property(
479 | item.property
480 | ).greaterThan(this.serializeExpression(item.value));
481 | break;
482 | case 'greaterThanOrEqualTo':
483 | nativeQuery = CBLQueryExpression.property(
484 | item.property
485 | ).greaterThanOrEqualTo(this.serializeExpression(item.value));
486 | break;
487 | case 'in':
488 | const inArray = [];
489 | if (Array.isArray(item.value)) {
490 | for (let exp of item.value) {
491 | inArray.push(this.serializeExpression(exp));
492 | }
493 | } else {
494 | inArray.push(this.serializeExpression(item.value));
495 | }
496 | nativeQuery = CBLQueryExpression.property(item.property).in(
497 | inArray
498 | );
499 | break;
500 | case 'is':
501 | nativeQuery = CBLQueryExpression.property(item.property).is(
502 | this.serializeExpression(item.value)
503 | );
504 | break;
505 | case 'isNot':
506 | nativeQuery = CBLQueryExpression.property(item.property).isNot(
507 | this.serializeExpression(item.value)
508 | );
509 | break;
510 | case 'isNullOrMissing':
511 | nativeQuery = CBLQueryExpression.property(
512 | item.property
513 | ).isNullOrMissing();
514 | break;
515 | case 'lessThan':
516 | nativeQuery = CBLQueryExpression.property(
517 | item.property
518 | ).lessThan(this.serializeExpression(item.value));
519 | break;
520 | case 'lessThanOrEqualTo':
521 | nativeQuery = CBLQueryExpression.property(
522 | item.property
523 | ).lessThanOrEqualTo(this.serializeExpression(item.value));
524 | break;
525 | case 'like':
526 | nativeQuery = CBLQueryFunction.lower(CBLQueryExpression.property(item.property)).like(
527 | this.serializeExpression(item.value)
528 | );
529 | break;
530 | case 'modulo':
531 | nativeQuery = CBLQueryExpression.property(item.property).modulo(
532 | this.serializeExpression(item.value)
533 | );
534 | break;
535 | case 'multiply':
536 | nativeQuery = CBLQueryExpression.property(
537 | item.property
538 | ).multiply(this.serializeExpression(item.value));
539 | break;
540 |
541 | case 'notEqualTo':
542 | nativeQuery = CBLQueryExpression.property(
543 | item.property
544 | ).notEqualTo(this.serializeExpression(item.value));
545 | break;
546 |
547 | case 'notNullOrMissing':
548 | nativeQuery = CBLQueryExpression.property(
549 | item.property
550 | ).notNullOrMissing();
551 | break;
552 | case 'regex':
553 | nativeQuery = CBLQueryFunction.lower(item.property).regex(
554 | this.serializeExpression(item.value)
555 | );
556 | break;
557 | }
558 | return nativeQuery;
559 | }
560 |
561 | query(query: Query = {select: [QueryMeta.ALL, QueryMeta.ID]}) {
562 | const items = [];
563 | let select = [];
564 | let from;
565 | let join = null;
566 | let where;
567 | let groupBy = null;
568 | let orderBy = null;
569 | let limit = null;
570 | let having = null;
571 | let isAll = false;
572 | if (!query.select || query.select.length === 0) {
573 | isAll = true;
574 | select.push(CBLQuerySelectResult.all());
575 | select.push(CBLQuerySelectResult.expression(CBLQueryMeta.id()));
576 | } else {
577 | query.select.forEach(item => {
578 | if (item === QueryMeta.ID) {
579 | select.push(CBLQuerySelectResult.expression(CBLQueryMeta.id()));
580 | } else if (item === QueryMeta.ALL) {
581 | isAll = true;
582 | select.push(CBLQuerySelectResult.all());
583 | } else {
584 | select.push(CBLQueryExpression.property(item));
585 | }
586 | });
587 | }
588 |
589 | if (query.from) {
590 | const db = new Couchbase(query.from);
591 | from = CBLQueryDataSource.database(db.ios);
592 | } else {
593 | from = CBLQueryDataSource.database(this.ios);
594 | }
595 |
596 | let nativeQuery = null;
597 | if (query.where) {
598 | for (let item of query.where) {
599 | if (item.logical === QueryLogicalOperator.AND) {
600 | if (!nativeQuery) break;
601 | nativeQuery = nativeQuery.andExpression(this.setComparision(item));
602 | } else if (item.logical === QueryLogicalOperator.OR) {
603 | if (!nativeQuery) break;
604 | nativeQuery = nativeQuery.orExpression(this.setComparision(item));
605 | } else {
606 | nativeQuery = this.setComparision(item);
607 | }
608 | }
609 | }
610 |
611 | if (query.groupBy) {
612 | if (query.groupBy.length > 0) {
613 | groupBy = [];
614 | }
615 | for (let prop of query.groupBy) {
616 | groupBy.push(CBLQueryExpression.property(prop));
617 | }
618 | }
619 | if (query.order) {
620 | if (query.order.length > 0) {
621 | orderBy = [];
622 | }
623 | for (let item of query.order) {
624 | switch (item.direction) {
625 | case 'desc':
626 | orderBy.push(CBLQueryOrdering.property(item.property).descending());
627 | break;
628 | default:
629 | orderBy.push(CBLQueryOrdering.property(item.property).ascending());
630 | break;
631 | }
632 | }
633 | }
634 |
635 | if (query.limit && typeof query.limit === 'number') {
636 | if (query.offset && typeof query.offset === 'number') {
637 | limit = CBLQueryLimit.limitOffset(CBLQueryExpression.integer(query.limit), CBLQueryExpression.integer(query.offset));
638 | } else {
639 | limit = CBLQueryLimit.limit(CBLQueryExpression.integer(query.limit));
640 | }
641 | }
642 |
643 | let queryBuilder = CBLQueryBuilder.selectFromJoinWhereGroupByHavingOrderByLimit(
644 | select,
645 | from,
646 | join,
647 | nativeQuery,
648 | groupBy,
649 | having,
650 | orderBy,
651 | limit
652 | );
653 |
654 | const result = queryBuilder.execute().allResults();
655 | const size = result.count;
656 | for (let i = 0; i < size; i++) {
657 | const item = result.objectAtIndex(i);
658 | const keys = item.keys;
659 | const keysSize = keys.count;
660 | const obj = {};
661 | for (let keyId = 0; keyId < keysSize; keyId++) {
662 | const key = keys.objectAtIndex(keyId);
663 | const nativeItem = item.valueForKey(key);
664 | if (isAll && types.getClass(nativeItem) === 'CBLDictionary') {
665 | const cblKeys = nativeItem.keys;
666 | const cblKeysSize = cblKeys.count;
667 | for (let cblKeysId = 0; cblKeysId < cblKeysSize; cblKeysId++) {
668 | const cblKey = cblKeys.objectAtIndex(cblKeysId);
669 | obj[cblKey] = this.deserialize(nativeItem.valueForKey(cblKey));
670 | }
671 | } else {
672 | obj[key] = this.deserialize(nativeItem);
673 | }
674 | }
675 | items.push(obj);
676 | }
677 | return items;
678 | }
679 |
680 | private getExtension(mimeType: string) {
681 | if (!mimeType) return 'bin';
682 | for (let key of Object.keys(mimeTypes)) {
683 | let mime = mimeType[key];
684 | if (typeof mimeType === 'string' && mimeType.indexOf(mime) > -1) {
685 | return key;
686 | }
687 | }
688 | return 'bin';
689 | }
690 | }
691 |
692 | export class Replicator extends ReplicatorBase {
693 | constructor(replicator: any) {
694 | super(replicator);
695 | }
696 |
697 | start() {
698 | this.replicator.start();
699 | }
700 |
701 | stop() {
702 | this.replicator.stop();
703 | }
704 |
705 | isRunning() {
706 | if (this.replicator && this.replicator.status && this.replicator.status.activity) {
707 | return (
708 | this.replicator.status.activity ===
709 | CBLReplicatorActivityLevel.kCBLReplicatorBusy
710 | );
711 | }
712 | return false;
713 | }
714 |
715 | setContinuous(isContinuous: boolean) {
716 | const newConfig = CBLReplicatorConfiguration.alloc().initWithConfig(this.replicator.config);
717 | newConfig.continuous = isContinuous;
718 | this.replicator = CBLReplicator.alloc().initWithConfig(newConfig);
719 | }
720 |
721 | setUserNameAndPassword(username: string, password: string) {
722 | const newConfig = CBLReplicatorConfiguration.alloc().initWithConfig(this.replicator.config);
723 | newConfig.authenticator = CBLBasicAuthenticator.alloc().initWithUsernamePassword(
724 | username,
725 | password
726 | );
727 | this.replicator = CBLReplicator.alloc().initWithConfig(newConfig);
728 | }
729 |
730 | setChannels(channels: string[]) {
731 | const newConfig = CBLReplicatorConfiguration.alloc().initWithConfig(this.replicator.config);
732 | newConfig.channels = NSArray.arrayWithArray(channels);
733 | this.replicator = CBLReplicator.alloc().initWithConfig(newConfig);
734 | }
735 |
736 | setSessionIdAndCookieName(sessionId: string, cookieName: string) {
737 | const newConfig = CBLReplicatorConfiguration.alloc().initWithConfig(this.replicator.config);
738 | newConfig.authenticator = CBLSessionAuthenticator.alloc().initWithSessionIDCookieName(
739 | sessionId,
740 | cookieName
741 | );
742 | this.replicator = CBLReplicator.alloc().initWithConfig(newConfig);
743 | }
744 |
745 | setSessionId(sessionId: string) {
746 | const newConfig = CBLReplicatorConfiguration.alloc().initWithConfig(this.replicator.config);
747 | newConfig.authenticator = CBLSessionAuthenticator.alloc().initWithSessionID(
748 | sessionId
749 | );
750 | this.replicator = CBLReplicator.alloc().initWithConfig(newConfig);
751 | }
752 | }
753 |
754 |
755 | export class Blob extends BlobBase {
756 |
757 | constructor(blob: any) {
758 | super(blob);
759 | }
760 |
761 | get ios() {
762 | return this.blob;
763 | }
764 |
765 | get content(): any {
766 | if (!this.ios) return null;
767 | return this.ios.content;
768 | }
769 |
770 | get contentStream(): any {
771 | if (!this.ios) return null;
772 | return this.ios.contentStream;
773 | }
774 |
775 | get contentType(): string {
776 | if (!this.ios) return null;
777 | return this.ios.contentType;
778 | }
779 |
780 | get length(): number {
781 | if (!this.ios) return 0;
782 | return this.ios.length;
783 | }
784 |
785 |
786 | get digest(): string {
787 | if (!this.ios) return null;
788 | return this.ios.digest;
789 | }
790 |
791 | get properties(): Map {
792 | const map = new Map();
793 | if (!this.ios) return map;
794 | const nativeMap = this.ios.properties;
795 | const mapKeysArray = nativeMap.allKeys;
796 | const length = mapKeysArray.count;
797 | for (let i = 0; i < length; i++) {
798 | const key = mapKeysArray[i];
799 | const value = nativeMap.valueForKey(key);
800 | map.set(key, value);
801 | }
802 | return map;
803 | }
804 |
805 | }
806 |
807 |
808 | let DEFAULT_MIME_TYPE = 'application/octet-stream';
809 |
810 | let mimeTypes = {
811 | 'md': 'text/markdown',
812 | 'html': 'text/html',
813 | 'htm': 'text/html',
814 | 'shtml': 'text/html',
815 | 'css': 'text/css',
816 | 'xml': 'text/xml',
817 | 'gif': 'image/gif',
818 | 'jpeg': 'image/jpeg',
819 | 'jpg': 'image/jpeg',
820 | 'js': 'application/javascript',
821 | 'atom': 'application/atom+xml',
822 | 'rss': 'application/rss+xml',
823 | 'mml': 'text/mathml',
824 | 'txt': 'text/plain',
825 | 'jad': 'text/vnd.sun.j2me.app-descriptor',
826 | 'wml': 'text/vnd.wap.wml',
827 | 'htc': 'text/x-component',
828 | 'png': 'image/png',
829 | 'tif': 'image/tiff',
830 | 'tiff': 'image/tiff',
831 | 'wbmp': 'image/vnd.wap.wbmp',
832 | 'ico': 'image/x-icon',
833 | 'jng': 'image/x-jng',
834 | 'bmp': 'image/x-ms-bmp',
835 | 'svg': 'image/svg+xml',
836 | 'svgz': 'image/svg+xml',
837 | 'webp': 'image/webp',
838 | 'woff': 'application/font-woff',
839 | 'jar': 'application/java-archive',
840 | 'war': 'application/java-archive',
841 | 'ear': 'application/java-archive',
842 | 'json': 'application/json',
843 | 'hqx': 'application/mac-binhex40',
844 | 'doc': 'application/msword',
845 | 'pdf': 'application/pdf',
846 | 'ps': 'application/postscript',
847 | 'eps': 'application/postscript',
848 | 'ai': 'application/postscript',
849 | 'rtf': 'application/rtf',
850 | 'm3u8': 'application/vnd.apple.mpegurl',
851 | 'xls': 'application/vnd.ms-excel',
852 | 'eot': 'application/vnd.ms-fontobject',
853 | 'ppt': 'application/vnd.ms-powerpoint',
854 | 'wmlc': 'application/vnd.wap.wmlc',
855 | 'kml': 'application/vnd.google-earth.kml+xml',
856 | 'kmz': 'application/vnd.google-earth.kmz',
857 | '7z': 'application/x-7z-compressed',
858 | 'cco': 'application/x-cocoa',
859 | 'jardiff': 'application/x-java-archive-diff',
860 | 'jnlp': 'application/x-java-jnlp-file',
861 | 'run': 'application/x-makeself',
862 | 'pl': 'application/x-perl',
863 | 'pm': 'application/x-perl',
864 | 'prc': 'application/x-pilot',
865 | 'pdb': 'application/x-pilot',
866 | 'rar': 'application/x-rar-compressed',
867 | 'rpm': 'application/x-redhat-package-manager',
868 | 'sea': 'application/x-sea',
869 | 'swf': 'application/x-shockwave-flash',
870 | 'sit': 'application/x-stuffit',
871 | 'tcl': 'application/x-tcl',
872 | 'tk': 'application/x-tcl',
873 | 'der': 'application/x-x509-ca-cert',
874 | 'pem': 'application/x-x509-ca-cert',
875 | 'crt': 'application/x-x509-ca-cert',
876 | 'xpi': 'application/x-xpinstall',
877 | 'xhtml': 'application/xhtml+xml',
878 | 'xspf': 'application/xspf+xml',
879 | 'zip': 'application/zip',
880 | 'bin': 'application/octet-stream',
881 | 'exe': 'application/octet-stream',
882 | 'dll': 'application/octet-stream',
883 | 'deb': 'application/octet-stream',
884 | 'dmg': 'application/octet-stream',
885 | 'iso': 'application/octet-stream',
886 | 'img': 'application/octet-stream',
887 | 'msi': 'application/octet-stream',
888 | 'msp': 'application/octet-stream',
889 | 'msm': 'application/octet-stream',
890 | 'docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
891 | 'xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
892 | 'pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
893 | 'mid': 'audio/midi',
894 | 'midi': 'audio/midi',
895 | 'kar': 'audio/midi',
896 | 'mp3': 'audio/mpeg',
897 | 'ogg': 'audio/ogg',
898 | 'm4a': 'audio/x-m4a',
899 | 'ra': 'audio/x-realaudio',
900 | '3gpp': 'video/3gpp',
901 | '3gp': 'video/3gpp',
902 | 'ts': 'video/mp2t',
903 | 'mp4': 'video/mp4',
904 | 'mpeg': 'video/mpeg',
905 | 'mpg': 'video/mpeg',
906 | 'mov': 'video/quicktime',
907 | 'webm': 'video/webm',
908 | 'flv': 'video/x-flv',
909 | 'm4v': 'video/x-m4v',
910 | 'mng': 'video/x-mng',
911 | 'asx': 'video/x-ms-asf',
912 | 'asf': 'video/x-ms-asf',
913 | 'wmv': 'video/x-ms-wmv',
914 | 'avi': 'video/x-msvideo'
915 | };
916 |
--------------------------------------------------------------------------------
/src/index.d.ts:
--------------------------------------------------------------------------------
1 | import { Common, Query, ReplicatorBase } from './couchbase-plugin.common';
2 |
3 | export {
4 | ConcurrencyMode, Query, QueryMeta, QueryArrayOperator, QueryComparisonOperator, QueryLogicalOperator, QueryOrderItem, QueryWhereItem
5 | }from './couchbase-plugin.common';
6 |
7 | export declare class Couchbase extends Common {
8 | config: any;
9 | android: any;
10 | ios: any;
11 |
12 | constructor(name: string);
13 |
14 | createDocument(data: Object, documentId?: string): any;
15 |
16 | setBlob(id: string, name: string, blob: any, mimeType?: string): void;
17 |
18 | getBlob(id: string, name: string): Blob;
19 |
20 | getDocument(documentId: string): any;
21 |
22 | updateDocument(documentId: string, data: any): void;
23 |
24 | deleteDocument(documentId: string): any;
25 |
26 | destroyDatabase(): void;
27 |
28 | query(query?: Query): any[];
29 |
30 | createReplication(remoteUrl: string, direction: 'push' | 'pull' | 'both'): Replicator;
31 |
32 | createPullReplication(remoteUrl: string, username?: string, password?: string): Replicator;
33 |
34 | createPushReplication(remoteUrl: string, username?: string, password?: string): Replicator;
35 |
36 | addDatabaseChangeListener(callback: any): void;
37 |
38 | removeDatabaseChangeListener(callback: any): void;
39 |
40 | inBatch(batch: () => void): void;
41 | }
42 |
43 | export declare class Replicator extends ReplicatorBase {
44 | constructor(replicator: any);
45 |
46 | start(): void;
47 |
48 | stop(): void;
49 |
50 | isRunning(): boolean;
51 |
52 | setContinuous(isContinuous: boolean): void;
53 |
54 | setUserNameAndPassword(username: string, password: string): any;
55 |
56 | setChannels(channels: string[]): any;
57 |
58 | setSessionIdAndCookieName(sessionId: string, cookieName: string): any;
59 |
60 | setSessionId(sessionId: string): any;
61 | }
62 |
63 |
--------------------------------------------------------------------------------
/src/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "nativescript-couchbase-plugin",
3 | "version": "0.9.6",
4 | "description": "NativeScript couchbase",
5 | "main": "couchbase-plugin",
6 | "typings": "index.d.ts",
7 | "nativescript": {
8 | "platforms": {
9 | "android": "6.0.0",
10 | "ios": "6.0.1"
11 | }
12 | },
13 | "scripts": {
14 | "tsc": "tsc --skipLibCheck",
15 | "build": "npm run tsc && npm run build.native",
16 | "build.native": "node scripts/build-native.js",
17 | "postclone": "npm i && node scripts/postclone.js && cd ../demo && npm i && npx rimraf -- package-lock.json && cd ../src",
18 | "test.android": "npm run tsc && npm run tslint && cd ../demo && tns build android && tns test android --justlaunch",
19 | "test.ios": "npm run tsc && npm run tslint && cd ../demo && tns build ios && tns test ios --justlaunch",
20 | "tslint": "cd .. && tslint \"**/*.ts\" --config tslint.json --exclude \"**/node_modules/**\"",
21 | "plugin.tscwatch": "npm run tsc -- -w",
22 | "demo.ios": "npm run tsc && cd ../demo && tns run ios",
23 | "demo.android": "npm run tsc && cd ../demo && tns run android",
24 | "demo.reset": "cd ../demo && npx rimraf -- hooks node_modules platforms package-lock.json",
25 | "plugin.prepare": "npm run build && cd ../demo && tns plugin remove nativescript-couchbase-plugin && tns plugin add ../src",
26 | "clean": "npm run demo.reset && npx rimraf -- node_modules package-lock.json && npm i",
27 | "ci.tslint": "npm i && tslint '**/*.ts' --config '../tslint.json' --exclude '**/node_modules/**'",
28 | "prepack": "npm run build.native"
29 | },
30 | "keywords": [
31 | "NativeScript",
32 | "JavaScript",
33 | "Android",
34 | "iOS"
35 | ],
36 | "author": {
37 | "name": "Osei Fortune",
38 | "email": "fortune.osei@yahoo.com"
39 | },
40 | "contributors": [
41 | {
42 | "name": "Shiva Prasad",
43 | "email": "sp@shiv19.com",
44 | "url": "https://shiv19.com"
45 | }
46 | ],
47 | "bugs": {
48 | "url": "https://github.com/triniwiz/nativescript-couchbase-plugin/issues"
49 | },
50 | "license": "Apache-2.0",
51 | "homepage": "https://github.com/triniwiz/nativescript-couchbase-plugin",
52 | "readmeFilename": "README.md",
53 | "devDependencies": {
54 | "tns-core-modules": "^6.0.0",
55 | "tns-platform-declarations": "^6.0.0",
56 | "typescript": "~2.8.2",
57 | "prompt": "^1.0.0",
58 | "rimraf": "^2.6.2",
59 | "tslint": "^5.11.0",
60 | "semver": "^5.5.0"
61 | },
62 | "dependencies": {},
63 | "bootstrapper": "nativescript-plugin-seed"
64 | }
65 |
--------------------------------------------------------------------------------
/src/platforms/android/fancycouchbase-release.aar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/triniwiz/nativescript-couchbase-plugin/7e12fe59e3fbe09436acef1ca5528bf3a7eba50c/src/platforms/android/fancycouchbase-release.aar
--------------------------------------------------------------------------------
/src/platforms/android/include.gradle:
--------------------------------------------------------------------------------
1 | android {
2 | defaultConfig {
3 | minSdkVersion 19
4 | }
5 | }
6 |
7 | repositories {
8 | google()
9 | jcenter()
10 | maven {
11 | url "http://mobile.maven.couchbase.com/maven2/dev/"
12 | }
13 | }
14 | dependencies {
15 | implementation 'com.couchbase.lite:couchbase-lite-android:2.5.3'
16 | }
17 |
--------------------------------------------------------------------------------
/src/platforms/ios/Podfile:
--------------------------------------------------------------------------------
1 | use_frameworks!
2 | pod 'CouchbaseLite', '~> 2.5.3'
3 |
--------------------------------------------------------------------------------
/src/references.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 | ///
3 |
--------------------------------------------------------------------------------
/src/scripts/build-native.js:
--------------------------------------------------------------------------------
1 | const { exec } = require('child_process');
2 | const semver = require('semver');
3 |
4 | exec('tns --version', (err, stdout, stderr) => {
5 | if (err) {
6 | // node couldn't execute the command
7 | console.log(`tns --version err: ${err}`);
8 | return;
9 | }
10 |
11 | const tnsVersion = semver.major(stdout);
12 |
13 | // execute 'tns plugin build' for {N} version > 4. This command builds .aar in platforms/android folder.
14 | if (tnsVersion >= 4) {
15 | console.log(`executing 'tns plugin build'`);
16 | exec('tns plugin build', (err, stdout, stderr) => {
17 | if (err) {
18 | // node couldn't execute the command
19 | console.log(`${err}`);
20 | return;
21 | }
22 | });
23 | }
24 | });
25 |
--------------------------------------------------------------------------------
/src/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es5",
4 | "module": "commonjs",
5 | "declaration": true,
6 | "removeComments": true,
7 | "noLib": false,
8 | "emitDecoratorMetadata": true,
9 | "experimentalDecorators": true,
10 | "skipLibCheck": true,
11 | "lib": ["es6", "dom"],
12 | "sourceMap": true,
13 | "pretty": true,
14 | "allowUnreachableCode": false,
15 | "allowUnusedLabels": false,
16 | "noEmitHelpers": true,
17 | "noEmitOnError": false,
18 | "noImplicitAny": false,
19 | "noImplicitReturns": true,
20 | "noImplicitUseStrict": false,
21 | "noFallthroughCasesInSwitch": true
22 | },
23 | "exclude": [
24 | "node_modules"
25 | ],
26 | "compileOnSave": false
27 | }
28 |
--------------------------------------------------------------------------------
/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "rules": {
3 | "class-name": true,
4 | "comment-format": [
5 | true,
6 | "check-space"
7 | ],
8 | "indent": [
9 | true,
10 | "spaces"
11 | ],
12 | "no-duplicate-variable": true,
13 | "no-eval": true,
14 | "no-internal-module": true,
15 | "no-trailing-whitespace": true,
16 | "no-var-keyword": true,
17 | "one-line": [
18 | true,
19 | "check-open-brace",
20 | "check-whitespace"
21 | ],
22 | "quotemark": [
23 | false,
24 | "double"
25 | ],
26 | "semicolon": [
27 | true,
28 | "always"
29 | ],
30 | "triple-equals": [
31 | true,
32 | "allow-null-check"
33 | ],
34 | "typedef-whitespace": [
35 | true,
36 | {
37 | "call-signature": "nospace",
38 | "index-signature": "nospace",
39 | "parameter": "nospace",
40 | "property-declaration": "nospace",
41 | "variable-declaration": "nospace"
42 | }
43 | ],
44 | "variable-name": [
45 | true,
46 | "ban-keywords"
47 | ],
48 | "whitespace": [
49 | true,
50 | "check-branch",
51 | "check-decl",
52 | "check-operator",
53 | "check-separator",
54 | "check-type"
55 | ]
56 | }
57 | }
--------------------------------------------------------------------------------