jason-rails 0.7.2 → 0.7.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e7f9c248374aaa06055ef47cfaed1c131b9341bee90708d215986e551ac4d9cc
4
- data.tar.gz: 6e414392f9658ddcfe77b299c2edcd352977652d07f046d8d707d6d9b3b37d8b
3
+ metadata.gz: c0ca4e6c931fdf041e8bd13a516e11d89699396691ff6328c73a0241f5672cc9
4
+ data.tar.gz: a0a6680af3dc06b0a5f96ee4f96513c172e12cf84cccc70339c0d46f7f0b742a
5
5
  SHA512:
6
- metadata.gz: 34c5b26b7b909e8f4a24ce47b5c74ca584f9aca49d379c70972bdea1899c74a333acce67c4afdb21b86ef7c9ee31fb5cadfe4cbc91528380c37f5482d6f4ec1c
7
- data.tar.gz: d6c760e610ddac664d3a95a60fce8c535b6485e745d3f58701bf67489f8a50f8b05d487af555e1ea392c8efaacaed8d8ca0f3fae36607d0bc90df129860398f9
6
+ metadata.gz: f39c46227135319c3c9bfe81fce8cbda84769bd9de3d14103604c95cb4106dc0ff00a362a340c2f9a981f412947116848b569d64d33c879b094c2bdd8a24a990
7
+ data.tar.gz: c9cd5cf85a36769697b50f7d68c4204b6d61db2169a3378000bab6b8f1a6c05f3ecc42322c6480ea22a3dced1cbcd4625c8b64eb554ed21b3611a92f203c92fc
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
- ## v0.7.2
2
- - Add JasonContext to exports, for use in scenarios where you need to forward the context into some other React reconciler (e.g. `react-three-fiber`)
1
+ ## v0.7.5.1
2
+ - Fix bug where axios errors get swallowed
3
+
4
+ ## v0.7.5
5
+ - Fixed JS errors when payloads arrive on websockets after the subscription has been unmounted
6
+ - Fixed errors during initialization due to calling `cache_all` on a Rails model before it had fully initialized.
7
+
8
+ ## v0.7.3
9
+ - Added: Add JasonContext to exports, for use in scenarios where you need to forward the context into some other React reconciler (e.g. `react-three-fiber`)
3
10
  - Fixed: Unneeded `reload` in Publisher resulting in extra database calls
4
11
 
5
12
  ## v0.7.1
data/README.md CHANGED
@@ -52,6 +52,11 @@ Jason.setup do |config|
52
52
  end
53
53
  ```
54
54
 
55
+ Mount the Jason engine in `routes.rb`
56
+ ```ruby
57
+ mount Jason::Engine => "/jason"
58
+ ```
59
+
55
60
  ### In your frontend code
56
61
 
57
62
  First you need to wrap your root component in a `JasonProvider`.
@@ -173,6 +178,15 @@ Development is primarily driven by the needs of projects we're using Jason in. I
173
178
  - Assess using RedisGraph for the graph diffing functionality, to see if this would provide a performance boost
174
179
  - Improve the Typescript definitions (ie remove the abundant `any` typing currently used)
175
180
 
181
+ ## Publishing a new version
182
+ - Update `version.rb`
183
+ - Update CHANGELOG
184
+ - `gem build`
185
+ - `gem push`
186
+ - `npm version [major/minor/patch]`
187
+ - `npm publish`
188
+ - Push new version to Github
189
+
176
190
  ## License
177
191
 
178
192
  The gem, npm package and source code in the git repository are available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -1,9 +1,10 @@
1
1
  import React from 'react';
2
- declare const JasonProvider: ({ reducers, middleware, enhancers, extraActions, children }: {
2
+ declare const JasonProvider: ({ reducers, middleware, enhancers, extraActions, transportOptions, children }: {
3
3
  reducers?: any;
4
4
  middleware?: any;
5
5
  enhancers?: any;
6
6
  extraActions?: any;
7
+ transportOptions?: any;
7
8
  children?: React.FC<{}> | undefined;
8
9
  }) => JSX.Element;
9
10
  export default JasonProvider;
@@ -7,8 +7,8 @@ const react_1 = __importDefault(require("react"));
7
7
  const useJason_1 = __importDefault(require("./useJason"));
8
8
  const react_redux_1 = require("react-redux");
9
9
  const JasonContext_1 = __importDefault(require("./JasonContext"));
10
- const JasonProvider = ({ reducers, middleware, enhancers, extraActions, children }) => {
11
- const [store, value] = useJason_1.default({ reducers, middleware, enhancers, extraActions });
10
+ const JasonProvider = ({ reducers, middleware, enhancers, extraActions, transportOptions = {}, children }) => {
11
+ const [store, value] = useJason_1.default({ reducers, middleware, enhancers, extraActions, transportOptions });
12
12
  if (!(store && value))
13
13
  return react_1.default.createElement("div", null); // Wait for async fetch of schema to complete
14
14
  return react_1.default.createElement(react_redux_1.Provider, { store: store },
@@ -29,6 +29,7 @@ function createOptDis(schema, dispatch, restClient, serverActionQueue) {
29
29
  .catch(error => {
30
30
  dispatch({ type: 'jason/upsert', payload: { error } });
31
31
  serverActionQueue.itemFailed(id, error);
32
+ Promise.reject(error);
32
33
  });
33
34
  }
34
35
  setInterval(dispatchServerAction, 10);
@@ -1,4 +1,4 @@
1
- export default function createTransportAdapter(jasonConfig: any, handlePayload: any, dispatch: any, onConnect: any): {
1
+ export default function createTransportAdapter(jasonConfig: any, handlePayload: any, dispatch: any, onConnect: any, transportOptions: any): {
2
2
  getPayload: (config: any, options: any) => void;
3
3
  createSubscription: (config: any) => void;
4
4
  removeSubscription: (config: any) => void;
@@ -5,10 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const actionCableAdapter_1 = __importDefault(require("./transportAdapters/actionCableAdapter"));
7
7
  const pusherAdapter_1 = __importDefault(require("./transportAdapters/pusherAdapter"));
8
- function createTransportAdapter(jasonConfig, handlePayload, dispatch, onConnect) {
8
+ function createTransportAdapter(jasonConfig, handlePayload, dispatch, onConnect, transportOptions) {
9
9
  const { transportService } = jasonConfig;
10
10
  if (transportService === 'action_cable') {
11
- return actionCableAdapter_1.default(jasonConfig, handlePayload, dispatch, onConnect);
11
+ return actionCableAdapter_1.default(jasonConfig, handlePayload, dispatch, onConnect, transportOptions);
12
12
  }
13
13
  else if (transportService === 'pusher') {
14
14
  return pusherAdapter_1.default(jasonConfig, handlePayload, dispatch);
@@ -7,11 +7,12 @@ export declare const JasonContext: import("react").Context<{
7
7
  subscribe: null;
8
8
  eager: (entity: any, id: any, relations: any) => void;
9
9
  }>;
10
- export declare const JasonProvider: ({ reducers, middleware, enhancers, extraActions, children }: {
10
+ export declare const JasonProvider: ({ reducers, middleware, enhancers, extraActions, transportOptions, children }: {
11
11
  reducers?: any;
12
12
  middleware?: any;
13
13
  enhancers?: any;
14
14
  extraActions?: any;
15
+ transportOptions?: any;
15
16
  children?: import("react").FC<{}> | undefined;
16
17
  }) => JSX.Element;
17
18
  export declare const useAct: typeof _useAct;
@@ -1,4 +1,4 @@
1
- export default function actionCableAdapter(jasonConfig: any, handlePayload: any, dispatch: any, onConnected: any): {
1
+ export default function actionCableAdapter(jasonConfig: any, handlePayload: any, dispatch: any, onConnected: any, transportOptions: any): {
2
2
  getPayload: (config: any, options: any) => void;
3
3
  createSubscription: (config: any) => void;
4
4
  removeSubscription: (config: any) => void;
@@ -7,9 +7,10 @@ const actioncable_1 = require("@rails/actioncable");
7
7
  const restClient_1 = __importDefault(require("../restClient"));
8
8
  const uuid_1 = require("uuid");
9
9
  const lodash_1 = __importDefault(require("lodash"));
10
- function actionCableAdapter(jasonConfig, handlePayload, dispatch, onConnected) {
10
+ function actionCableAdapter(jasonConfig, handlePayload, dispatch, onConnected, transportOptions) {
11
11
  const consumerId = uuid_1.v4();
12
- const consumer = actioncable_1.createConsumer();
12
+ const { cableUrl } = transportOptions;
13
+ const consumer = cableUrl ? actioncable_1.createConsumer(cableUrl) : actioncable_1.createConsumer();
13
14
  const subscription = (consumer.subscriptions.create({
14
15
  channel: 'Jason::Channel'
15
16
  }, {
@@ -33,7 +34,10 @@ function actionCableAdapter(jasonConfig, handlePayload, dispatch, onConnected) {
33
34
  }
34
35
  function removeSubscription(config) {
35
36
  restClient_1.default.post('/jason/api/remove_subscription', { config, consumerId })
36
- .catch(e => console.error(e));
37
+ .catch(e => {
38
+ console.error(e);
39
+ Promise.reject(e);
40
+ });
37
41
  }
38
42
  function getPayload(config, options) {
39
43
  restClient_1.default.post('/jason/api/get_payload', {
@@ -45,7 +49,10 @@ function actionCableAdapter(jasonConfig, handlePayload, dispatch, onConnected) {
45
49
  handlePayload(payload);
46
50
  });
47
51
  })
48
- .catch(e => console.error(e));
52
+ .catch(e => {
53
+ console.error(e);
54
+ Promise.reject(e);
55
+ });
49
56
  }
50
57
  function fullChannelName(channelName) {
51
58
  return channelName;
@@ -33,13 +33,19 @@ function pusherAdapter(jasonConfig, handlePayload, dispatch) {
33
33
  configToChannel[JSON.stringify(config)] = channelName;
34
34
  subscribeToChannel(channelName);
35
35
  })
36
- .catch(e => console.error(e));
36
+ .catch(e => {
37
+ console.error(e);
38
+ Promise.reject(e);
39
+ });
37
40
  }
38
41
  function removeSubscription(config) {
39
42
  const channelName = configToChannel[JSON.stringify(config)];
40
43
  unsubscribeFromChannel(fullChannelName(channelName));
41
44
  restClient_1.default.post('/jason/api/remove_subscription', { config, consumerId })
42
- .catch(e => console.error(e));
45
+ .catch(e => {
46
+ console.error(e);
47
+ Promise.reject(e);
48
+ });
43
49
  }
44
50
  function getPayload(config, options) {
45
51
  restClient_1.default.post('/jason/api/get_payload', {
@@ -51,7 +57,10 @@ function pusherAdapter(jasonConfig, handlePayload, dispatch) {
51
57
  handlePayload(payload);
52
58
  });
53
59
  })
54
- .catch(e => console.error(e));
60
+ .catch(e => {
61
+ console.error(e);
62
+ Promise.reject(e);
63
+ });
55
64
  }
56
65
  function subscribeToChannel(channelName) {
57
66
  const channel = pusher.subscribe(fullChannelName(channelName));
@@ -1,6 +1,7 @@
1
- export default function useJason({ reducers, middleware, enhancers, extraActions }: {
1
+ export default function useJason({ reducers, middleware, enhancers, transportOptions, extraActions }: {
2
2
  reducers?: any;
3
3
  middleware?: any[];
4
4
  enhancers?: any[];
5
5
  extraActions?: any;
6
+ transportOptions?: any;
6
7
  }): any[];
@@ -16,7 +16,7 @@ const humps_1 = require("humps");
16
16
  const blueimp_md5_1 = __importDefault(require("blueimp-md5"));
17
17
  const lodash_1 = __importDefault(require("lodash"));
18
18
  const react_1 = require("react");
19
- function useJason({ reducers, middleware = [], enhancers = [], extraActions }) {
19
+ function useJason({ reducers, middleware = [], enhancers = [], transportOptions = {}, extraActions }) {
20
20
  const [store, setStore] = react_1.useState(null);
21
21
  const [value, setValue] = react_1.useState(null);
22
22
  react_1.useEffect(() => {
@@ -37,7 +37,7 @@ function useJason({ reducers, middleware = [], enhancers = [], extraActions }) {
37
37
  let subOptions = {};
38
38
  function handlePayload(payload) {
39
39
  const { md5Hash } = payload;
40
- const { handlePayload } = payloadHandlers[md5Hash];
40
+ const { handlePayload } = payloadHandlers[md5Hash] || {};
41
41
  if (handlePayload) {
42
42
  handlePayload(payload);
43
43
  }
@@ -45,7 +45,7 @@ function useJason({ reducers, middleware = [], enhancers = [], extraActions }) {
45
45
  console.warn("Payload arrived with no handler", payload, payloadHandlers);
46
46
  }
47
47
  }
48
- const transportAdapter = createTransportAdapter_1.default(jasonConfig, handlePayload, dispatch, () => lodash_1.default.keys(configs).forEach(md5Hash => createSubscription(configs[md5Hash], subOptions[md5Hash])));
48
+ const transportAdapter = createTransportAdapter_1.default(jasonConfig, handlePayload, dispatch, () => lodash_1.default.keys(configs).forEach(md5Hash => createSubscription(configs[md5Hash], subOptions[md5Hash])), transportOptions);
49
49
  function createSubscription(config, options = {}) {
50
50
  // We need the hash to be consistent in Ruby / Javascript
51
51
  const hashableConfig = lodash_1.default(Object.assign({ conditions: {}, includes: {} }, config)).toPairs().sortBy(0).fromPairs().value();
data/client/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jamesr2323/jason",
3
- "version": "0.7.2",
3
+ "version": "0.7.5.1",
4
4
  "module": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "scripts": {
@@ -3,8 +3,8 @@ import useJason from './useJason'
3
3
  import { Provider } from 'react-redux'
4
4
  import JasonContext from './JasonContext'
5
5
 
6
- const JasonProvider = ({ reducers, middleware, enhancers, extraActions, children }: { reducers?: any, middleware?: any, enhancers?: any, extraActions?: any, children?: React.FC }) => {
7
- const [store, value] = useJason({ reducers, middleware, enhancers, extraActions })
6
+ const JasonProvider = ({ reducers, middleware, enhancers, extraActions, transportOptions = {}, children }: { reducers?: any, middleware?: any, enhancers?: any, extraActions?: any, transportOptions?: any, children?: React.FC }) => {
7
+ const [store, value] = useJason({ reducers, middleware, enhancers, extraActions, transportOptions })
8
8
 
9
9
  if(!(store && value)) return <div /> // Wait for async fetch of schema to complete
10
10
 
@@ -29,6 +29,8 @@ export default function createOptDis(schema, dispatch, restClient, serverActionQ
29
29
  .catch(error => {
30
30
  dispatch({ type: 'jason/upsert', payload: { error } })
31
31
  serverActionQueue.itemFailed(id, error)
32
+
33
+ Promise.reject(error)
32
34
  })
33
35
  }
34
36
 
@@ -1,10 +1,10 @@
1
1
  import actionCableAdapter from './transportAdapters/actionCableAdapter'
2
2
  import pusherAdapter from './transportAdapters/pusherAdapter'
3
3
 
4
- export default function createTransportAdapter(jasonConfig, handlePayload, dispatch, onConnect) {
4
+ export default function createTransportAdapter(jasonConfig, handlePayload, dispatch, onConnect, transportOptions) {
5
5
  const { transportService } = jasonConfig
6
6
  if (transportService === 'action_cable') {
7
- return actionCableAdapter(jasonConfig, handlePayload, dispatch, onConnect)
7
+ return actionCableAdapter(jasonConfig, handlePayload, dispatch, onConnect, transportOptions)
8
8
  } else if (transportService === 'pusher') {
9
9
  return pusherAdapter(jasonConfig, handlePayload, dispatch)
10
10
  } else {
@@ -3,10 +3,12 @@ import restClient from '../restClient'
3
3
  import { v4 as uuidv4 } from 'uuid'
4
4
  import _ from 'lodash'
5
5
 
6
- export default function actionCableAdapter(jasonConfig, handlePayload, dispatch, onConnected) {
6
+ export default function actionCableAdapter(jasonConfig, handlePayload, dispatch, onConnected, transportOptions) {
7
7
  const consumerId = uuidv4()
8
8
 
9
- const consumer = createConsumer()
9
+ const { cableUrl } = transportOptions
10
+ const consumer = cableUrl ? createConsumer(cableUrl) : createConsumer()
11
+
10
12
  const subscription = (consumer.subscriptions.create({
11
13
  channel: 'Jason::Channel'
12
14
  }, {
@@ -33,7 +35,10 @@ export default function actionCableAdapter(jasonConfig, handlePayload, dispatch,
33
35
 
34
36
  function removeSubscription(config) {
35
37
  restClient.post('/jason/api/remove_subscription', { config, consumerId })
36
- .catch(e => console.error(e))
38
+ .catch(e => {
39
+ console.error(e)
40
+ Promise.reject(e)
41
+ })
37
42
  }
38
43
 
39
44
  function getPayload(config, options) {
@@ -46,7 +51,10 @@ export default function actionCableAdapter(jasonConfig, handlePayload, dispatch,
46
51
  handlePayload(payload)
47
52
  })
48
53
  })
49
- .catch(e => console.error(e))
54
+ .catch(e => {
55
+ console.error(e)
56
+ Promise.reject(e)
57
+ })
50
58
  }
51
59
 
52
60
  function fullChannelName(channelName) {
@@ -31,14 +31,20 @@ export default function pusherAdapter(jasonConfig, handlePayload, dispatch) {
31
31
  configToChannel[JSON.stringify(config)] = channelName
32
32
  subscribeToChannel(channelName)
33
33
  })
34
- .catch(e => console.error(e))
34
+ .catch(e => {
35
+ console.error(e)
36
+ Promise.reject(e)
37
+ })
35
38
  }
36
39
 
37
40
  function removeSubscription(config) {
38
41
  const channelName = configToChannel[JSON.stringify(config)]
39
42
  unsubscribeFromChannel(fullChannelName(channelName))
40
43
  restClient.post('/jason/api/remove_subscription', { config, consumerId })
41
- .catch(e => console.error(e))
44
+ .catch(e => {
45
+ console.error(e)
46
+ Promise.reject(e)
47
+ })
42
48
  }
43
49
 
44
50
  function getPayload(config, options) {
@@ -51,7 +57,10 @@ export default function pusherAdapter(jasonConfig, handlePayload, dispatch) {
51
57
  handlePayload(payload)
52
58
  })
53
59
  })
54
- .catch(e => console.error(e))
60
+ .catch(e => {
61
+ console.error(e)
62
+ Promise.reject(e)
63
+ })
55
64
  }
56
65
 
57
66
  function subscribeToChannel(channelName) {
@@ -14,7 +14,7 @@ import md5 from 'blueimp-md5'
14
14
  import _ from 'lodash'
15
15
  import React, { useState, useEffect } from 'react'
16
16
 
17
- export default function useJason({ reducers, middleware = [], enhancers = [], extraActions }: { reducers?: any, middleware?: any[], enhancers?: any[], extraActions?: any }) {
17
+ export default function useJason({ reducers, middleware = [], enhancers = [], transportOptions = {}, extraActions }: { reducers?: any, middleware?: any[], enhancers?: any[], extraActions?: any, transportOptions?: any }) {
18
18
  const [store, setStore] = useState(null as any)
19
19
  const [value, setValue] = useState(null as any)
20
20
 
@@ -48,7 +48,7 @@ export default function useJason({ reducers, middleware = [], enhancers = [], ex
48
48
  function handlePayload(payload) {
49
49
  const { md5Hash } = payload
50
50
 
51
- const { handlePayload } = payloadHandlers[md5Hash]
51
+ const { handlePayload } = payloadHandlers[md5Hash] || {}
52
52
  if (handlePayload) {
53
53
  handlePayload(payload)
54
54
  } else {
@@ -56,7 +56,13 @@ export default function useJason({ reducers, middleware = [], enhancers = [], ex
56
56
  }
57
57
  }
58
58
 
59
- const transportAdapter = createTransportAdapater(jasonConfig, handlePayload, dispatch, () => _.keys(configs).forEach(md5Hash => createSubscription(configs[md5Hash], subOptions[md5Hash])))
59
+ const transportAdapter = createTransportAdapater(
60
+ jasonConfig,
61
+ handlePayload,
62
+ dispatch,
63
+ () => _.keys(configs).forEach(md5Hash => createSubscription(configs[md5Hash], subOptions[md5Hash])),
64
+ transportOptions
65
+ )
60
66
 
61
67
  function createSubscription(config, options = {}) {
62
68
  // We need the hash to be consistent in Ruby / Javascript
data/lib/jason/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Jason
2
- VERSION = "0.7.2"
2
+ VERSION = "0.7.5.1"
3
3
  end
data/lib/jason.rb CHANGED
@@ -51,7 +51,11 @@ module Jason
51
51
  puts "Old config was #{previous_schema[model]}"
52
52
  puts "New config is #{config}"
53
53
  puts "Rebuilding cache for #{model}"
54
- model.classify.constantize.cache_all
54
+
55
+ # This is necessary to ensure all Rails methods have been added to model before we attempt to cache.
56
+ Rails.configuration.after_initialize do
57
+ model.classify.constantize.cache_all
58
+ end
55
59
  puts "Done"
56
60
  end
57
61
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jason-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.7.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Rees
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-18 00:00:00.000000000 Z
11
+ date: 2022-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails