ar_sync 1.0.5 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5ce8f54d9f17ebdd9341d3ba5e1087bde5875d5a4f88b5eeddded0602aece480
4
- data.tar.gz: 209d8c04edf0d06b42c853eea568e298ccd626438fb64b416a8cc8e82293f0b8
3
+ metadata.gz: ab145d5094c25600e95e01ab625c0128782b2a0592be95d8c9333539a5128bd1
4
+ data.tar.gz: 062fcf8cb8996e145dfa35eb25b31f2ecc2b4a486183bc70678d055db2bf2bc8
5
5
  SHA512:
6
- metadata.gz: bb0b79346ca7062f69f77254ac4463aba3261ae8419937c64b0a0cb17715b5e97dc4035c76c863bdc87739fb1070ee21c27b034d908839309b83f26462038663
7
- data.tar.gz: 2b633cdcff19283fd2626e41751de5e969888e905452f2a86621c39be9eed6a6c467e5abe98d194b120aa7096e370f95a5fdb80439829a47cf60047f9ed0d608
6
+ metadata.gz: 556a1c954088cea90d44bb61cec1fc250804f1fc5ec4e1c4101ff642343af49bc4ce8870be152de4627802931409d3c5f25707fa34b59ba8e53e9873a99e9b54
7
+ data.tar.gz: 28846608f3314be4a117d1ffbf265702f2170755f027696300f991b01a9228302d7e218fce757826c7528c8643d98f66e1073741305c1d851f1fe6602c9f185b
@@ -0,0 +1,27 @@
1
+ name: Test
2
+ on: [push, pull_request]
3
+ jobs:
4
+ test:
5
+ strategy:
6
+ fail-fast: false
7
+ matrix:
8
+ ruby: [ '2.7', '3.0', '3.1' ]
9
+ gemfiles:
10
+ - gemfiles/Gemfile-rails-6
11
+ - gemfiles/Gemfile-rails-7
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - uses: actions/checkout@v2
15
+ - uses: ruby/setup-ruby@v1
16
+ with:
17
+ ruby-version: ${{ matrix.ruby }}
18
+ - uses: actions/setup-node@v1
19
+ with:
20
+ node-version: '14.x'
21
+ - run: |
22
+ sudo apt-get update
23
+ sudo apt-get install -y libsqlite3-dev
24
+ - run: bundle install --gemfile ${{ matrix.gemfiles }} --jobs 4 --retry 3
25
+ - run: npm install
26
+ - run: npm run build
27
+ - run: bundle exec --gemfile ${{ matrix.gemfiles }} rake
data/Gemfile CHANGED
@@ -4,3 +4,4 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in ar_sync.gemspec
6
6
  gemspec
7
+ gem 'ar_serializer'
data/Gemfile.lock CHANGED
@@ -1,52 +1,50 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ar_sync (1.0.5)
4
+ ar_sync (1.1.0)
5
5
  activerecord
6
6
  ar_serializer
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activemodel (6.0.2.1)
12
- activesupport (= 6.0.2.1)
13
- activerecord (6.0.2.1)
14
- activemodel (= 6.0.2.1)
15
- activesupport (= 6.0.2.1)
16
- activerecord-import (1.0.2)
17
- activerecord (>= 3.2)
18
- activesupport (6.0.2.1)
11
+ activemodel (7.0.2.3)
12
+ activesupport (= 7.0.2.3)
13
+ activerecord (7.0.2.3)
14
+ activemodel (= 7.0.2.3)
15
+ activesupport (= 7.0.2.3)
16
+ activerecord-import (1.4.0)
17
+ activerecord (>= 4.2)
18
+ activesupport (7.0.2.3)
19
19
  concurrent-ruby (~> 1.0, >= 1.0.2)
20
- i18n (>= 0.7, < 2)
21
- minitest (~> 5.1)
22
- tzinfo (~> 1.1)
23
- zeitwerk (~> 2.2)
24
- ar_serializer (1.1.0)
20
+ i18n (>= 1.6, < 2)
21
+ minitest (>= 5.1)
22
+ tzinfo (~> 2.0)
23
+ ar_serializer (1.2.0)
25
24
  activerecord
26
25
  top_n_loader
27
- coderay (1.1.2)
28
- concurrent-ruby (1.1.5)
29
- i18n (1.7.0)
26
+ coderay (1.1.3)
27
+ concurrent-ruby (1.1.10)
28
+ i18n (1.10.0)
30
29
  concurrent-ruby (~> 1.0)
31
- method_source (0.9.2)
32
- minitest (5.13.0)
33
- pry (0.12.2)
34
- coderay (~> 1.1.0)
35
- method_source (~> 0.9.0)
36
- rake (12.3.2)
30
+ method_source (1.0.0)
31
+ minitest (5.15.0)
32
+ pry (0.14.1)
33
+ coderay (~> 1.1)
34
+ method_source (~> 1.0)
35
+ rake (13.0.6)
37
36
  sqlite3 (1.4.2)
38
- thread_safe (0.3.6)
39
- top_n_loader (1.0.1)
37
+ top_n_loader (1.0.2)
40
38
  activerecord
41
- tzinfo (1.2.6)
42
- thread_safe (~> 0.1)
43
- zeitwerk (2.2.2)
39
+ tzinfo (2.0.4)
40
+ concurrent-ruby (~> 1.0)
44
41
 
45
42
  PLATFORMS
46
43
  ruby
47
44
 
48
45
  DEPENDENCIES
49
46
  activerecord-import
47
+ ar_serializer
50
48
  ar_sync!
51
49
  pry
52
50
  rake
data/core/ArSyncApi.d.ts CHANGED
@@ -1,8 +1,14 @@
1
1
  declare function apiBatchFetch(endpoint: string, requests: object[]): Promise<any>;
2
+ declare type Request = {
3
+ api: string;
4
+ params?: any;
5
+ query: any;
6
+ id?: number;
7
+ };
2
8
  declare const ArSyncApi: {
3
9
  domain: string | null;
4
10
  _batchFetch: typeof apiBatchFetch;
5
- fetch: (request: object) => Promise<unknown>;
6
- syncFetch: (request: object) => Promise<unknown>;
11
+ fetch: (request: Request) => Promise<unknown>;
12
+ syncFetch: (request: Request) => Promise<unknown>;
7
13
  };
8
14
  export default ArSyncApi;
data/core/ArSyncApi.js CHANGED
@@ -79,6 +79,16 @@ var ApiFetcher = /** @class */ (function () {
79
79
  }
80
80
  ApiFetcher.prototype.fetch = function (request) {
81
81
  var _this = this;
82
+ if (request.id != null) {
83
+ return new Promise(function (resolve, reject) {
84
+ _this.fetch({ api: request.api, params: { ids: [request.id] }, query: request.query }).then(function (result) {
85
+ if (result[0])
86
+ resolve(result[0]);
87
+ else
88
+ reject({ type: 'Not Found', retry: false });
89
+ }).catch(reject);
90
+ });
91
+ }
82
92
  return new Promise(function (resolve, reject) {
83
93
  _this.batches.push([request, { resolve: resolve, reject: reject }]);
84
94
  if (_this.batchFetchTimer)
@@ -108,7 +118,7 @@ var ApiFetcher = /** @class */ (function () {
108
118
  var callbacks = callbacksList[i];
109
119
  for (var _i = 0, callbacks_1 = callbacks; _i < callbacks_1.length; _i++) {
110
120
  var callback = callbacks_1[_i];
111
- if (result.data) {
121
+ if (result.data !== undefined) {
112
122
  callback.resolve(result.data);
113
123
  }
114
124
  else {