@kaspernj/api-maker 1.0.123 → 1.0.127

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.
Files changed (58) hide show
  1. package/.eslintrc.js +39 -33
  2. package/__tests__/cable-connection-pool.test.js +4 -4
  3. package/__tests__/custom-error.test.js +13 -0
  4. package/__tests__/model-name.test.js +16 -10
  5. package/__tests__/routes-native.test.js +15 -33
  6. package/__tests__/support/task.js +5 -5
  7. package/__tests__/support/user.js +5 -5
  8. package/index.js +0 -4
  9. package/package.json +6 -5
  10. package/src/api.cjs +15 -15
  11. package/src/base-model.cjs +85 -80
  12. package/src/cable-connection-pool.cjs +11 -11
  13. package/src/cable-subscription-pool.cjs +34 -34
  14. package/src/cable-subscription.cjs +2 -2
  15. package/src/can-can-loader.jsx +7 -7
  16. package/src/can-can.cjs +17 -16
  17. package/src/collection.cjs +36 -36
  18. package/src/command-submit-data.cjs +10 -11
  19. package/src/commands-pool.cjs +13 -13
  20. package/src/custom-error.cjs +20 -14
  21. package/src/deserializer.cjs +7 -7
  22. package/src/devise.cjs +15 -15
  23. package/src/error-logger.cjs +9 -9
  24. package/src/event-connection.jsx +6 -6
  25. package/src/event-created.jsx +8 -8
  26. package/src/event-destroyed.jsx +6 -6
  27. package/src/event-emitter-listener.jsx +6 -6
  28. package/src/event-listener.jsx +8 -8
  29. package/src/event-model-class.jsx +6 -6
  30. package/src/event-updated.jsx +10 -10
  31. package/src/instance-of-class-name.cjs +5 -7
  32. package/src/key-value-store.cjs +21 -18
  33. package/src/logger.cjs +4 -4
  34. package/src/merge.cjs +4 -4
  35. package/src/model-events.cjs +6 -5
  36. package/src/model-name.cjs +6 -5
  37. package/src/model-prop-type.cjs +11 -13
  38. package/src/model-recipes-loader.cjs +4 -4
  39. package/src/model-recipes-model-loader.cjs +45 -15
  40. package/src/models-response-reader.cjs +10 -10
  41. package/src/money-formatter.cjs +11 -11
  42. package/src/params.cjs +7 -7
  43. package/src/preloaded.cjs +6 -6
  44. package/src/resource-route.cjs +14 -12
  45. package/src/resource-routes.jsx +9 -4
  46. package/src/result.cjs +7 -7
  47. package/src/routes-native.cjs +6 -6
  48. package/src/routes.cjs +1 -1
  49. package/src/serializer.cjs +9 -9
  50. package/src/services.cjs +3 -3
  51. package/src/session-status-updater.cjs +14 -14
  52. package/src/source-maps-loader.cjs +11 -11
  53. package/src/translated-collections.cjs +2 -1
  54. package/src/updated-attribute.jsx +17 -14
  55. package/src/validation-error.cjs +5 -8
  56. package/src/validation-errors.cjs +16 -16
  57. package/src/event-location-changed.jsx +0 -21
  58. package/src/history-listener.jsx +0 -20
@@ -3,15 +3,15 @@ const formatNumber = require("format-number")
3
3
  const replaceall = require("replaceall")
4
4
 
5
5
  module.exports = class MoneyFormatter {
6
- static fromMoney(money, args = {}) {
6
+ static fromMoney (money, args = {}) {
7
7
  return new MoneyFormatter(money, args)
8
8
  }
9
9
 
10
- static format(money, args = {}) {
10
+ static format (money, args = {}) {
11
11
  return MoneyFormatter.fromMoney(money, args).toString()
12
12
  }
13
13
 
14
- static stringToFloat(moneyString) {
14
+ static stringToFloat (moneyString) {
15
15
  let unformatted = replaceall(I18n.t("number.currency.format.delimiter"), "", moneyString)
16
16
 
17
17
  unformatted = replaceall(I18n.t("number.currency.format.separator"), ".", unformatted)
@@ -20,17 +20,17 @@ module.exports = class MoneyFormatter {
20
20
  return float
21
21
  }
22
22
 
23
- static amountFromMoney(money) {
24
- if (money.hasOwnProperty("amount")) {
23
+ static amountFromMoney (money) {
24
+ if ("amount" in money) {
25
25
  return parseFloat(money.amount)
26
- } else if (money.hasOwnProperty("fractional")) {
26
+ } else if ("fractional" in money) {
27
27
  return parseFloat(money.fractional)
28
28
  }
29
29
 
30
30
  throw new Error(`Couldn't figure out amount from: ${JSON.stringify(money, null, 2)}`)
31
31
  }
32
32
 
33
- static currencyFromMoney(money) {
33
+ static currencyFromMoney (money) {
34
34
  let currencyString
35
35
 
36
36
  if (typeof money.currency == "string") {
@@ -54,14 +54,14 @@ module.exports = class MoneyFormatter {
54
54
  return moneyCurrency
55
55
  }
56
56
 
57
- constructor(money, args = {}) {
57
+ constructor (money, args = {}) {
58
58
  this.args = args
59
59
  this.money = money
60
60
  this.amount = MoneyFormatter.amountFromMoney(money)
61
61
  this.currency = MoneyFormatter.currencyFromMoney(money)
62
62
  }
63
63
 
64
- toString() {
64
+ toString () {
65
65
  const amount = (this.amount / 100).toFixed(this.decimalDigits())
66
66
  const formatOptions = {
67
67
  prefix: this.prefix(),
@@ -72,7 +72,7 @@ module.exports = class MoneyFormatter {
72
72
  return formatNumber(formatOptions)(amount)
73
73
  }
74
74
 
75
- decimalDigits() {
75
+ decimalDigits () {
76
76
  if (this.args.decimals !== null) {
77
77
  return this.args.decimals
78
78
  }
@@ -80,7 +80,7 @@ module.exports = class MoneyFormatter {
80
80
  return this.currency.decimal_digits
81
81
  }
82
82
 
83
- prefix() {
83
+ prefix () {
84
84
  if (this.args.excludeCurrency) {
85
85
  return ""
86
86
  }
package/src/params.cjs CHANGED
@@ -3,15 +3,15 @@ const {merge} = require("./merge.cjs")
3
3
  const qs = require("qs")
4
4
 
5
5
  module.exports = class Params {
6
- static parse() {
6
+ static parse () {
7
7
  return qs.parse(global.location.search.substr(1))
8
8
  }
9
9
 
10
- static change(given) {
10
+ static change (given) {
11
11
  return merge(Params.parse(), given)
12
12
  }
13
13
 
14
- static changeParams(given, opts = {}) {
14
+ static changeParams (given, opts = {}) {
15
15
  const params = Params.change(given)
16
16
  const newParams = qs.stringify(params)
17
17
  const newPath = `${location.pathname}?${newParams}`
@@ -21,24 +21,24 @@ module.exports = class Params {
21
21
  appHistory.push(newPath)
22
22
  }
23
23
 
24
- static serializeForm(form) {
24
+ static serializeForm (form) {
25
25
  const hash = formSerialize(form, {empty: true, hash: true})
26
26
  return Params.setUndefined(hash)
27
27
  }
28
28
 
29
29
  // This is used to set all empty values to 'undefined' which makes qs removed those elements from the query string
30
- static setUndefined(given) {
30
+ static setUndefined (given) {
31
31
  if (Array.isArray(given)) {
32
32
  if (given.length == 0)
33
33
  return undefined
34
34
 
35
- return given.map(givenI => Params.setUndefined(givenI))
35
+ return given.map((givenI) => Params.setUndefined(givenI))
36
36
  } else if (typeof given === "object") {
37
37
  if (Object.keys(given).length == 0)
38
38
  return undefined
39
39
 
40
40
  const newGiven = {}
41
- for(const key in given) {
41
+ for (const key in given) {
42
42
  newGiven[key] = Params.setUndefined(given[key])
43
43
  }
44
44
 
package/src/preloaded.cjs CHANGED
@@ -2,21 +2,21 @@ const {digg} = require("diggerize")
2
2
  const inflection = require("inflection")
3
3
 
4
4
  module.exports = class ApiMakerPreloaded {
5
- constructor(response) {
5
+ constructor (response) {
6
6
  this.response = response
7
7
  this.loadPreloadedModels()
8
8
  }
9
9
 
10
- loadPreloadedModels() {
10
+ loadPreloadedModels () {
11
11
  this.preloaded = {}
12
12
 
13
13
  for (const preloadedType in this.response.preloaded) {
14
14
  const modelClassName = inflection.classify(preloadedType)
15
- const modelClass = digg(require("@kaspernj/api-maker/src/models"), modelClassName)
15
+ const ModelClass = digg(require("@kaspernj/api-maker/src/models"), modelClassName)
16
16
 
17
- for(const preloadedId in this.response.preloaded[preloadedType]) {
17
+ for (const preloadedId in this.response.preloaded[preloadedType]) {
18
18
  const preloadedData = this.response.preloaded[preloadedType][preloadedId]
19
- const model = new modelClass({data: preloadedData, isNewRecord: false})
19
+ const model = new ModelClass({data: preloadedData, isNewRecord: false})
20
20
 
21
21
  if (!this.preloaded[preloadedType]) {
22
22
  this.preloaded[preloadedType] = {}
@@ -33,7 +33,7 @@ module.exports = class ApiMakerPreloaded {
33
33
  }
34
34
  }
35
35
 
36
- getModel(type, id) {
36
+ getModel (type, id) {
37
37
  if (!this.preloaded[type] || !this.preloaded[type][id]) {
38
38
  throw new Error(`Could not find a ${type} by that ID: ${id}`)
39
39
  }
@@ -2,7 +2,7 @@ const {digg} = require("diggerize")
2
2
  const inflection = require("inflection")
3
3
 
4
4
  module.exports = class ApiMakerResourceRoute {
5
- constructor({jsRoutes, locales, requireComponent, routeDefinition}) {
5
+ constructor ({jsRoutes, locales, requireComponent, routeDefinition}) {
6
6
  this.jsRoutes = jsRoutes
7
7
  this.locales = locales
8
8
  this.requireComponent = requireComponent
@@ -13,7 +13,7 @@ module.exports = class ApiMakerResourceRoute {
13
13
  }
14
14
  }
15
15
 
16
- routesResult() {
16
+ routesResult () {
17
17
  if (digg(this, "locales")) {
18
18
  return this.withLocale()
19
19
  } else {
@@ -21,11 +21,11 @@ module.exports = class ApiMakerResourceRoute {
21
21
  }
22
22
  }
23
23
 
24
- findRouteParams() {
24
+ findRouteParams () {
25
25
  const result = []
26
26
  const parts = digg(this, "routeDefinition", "path").split("/")
27
27
 
28
- for(const part of parts) {
28
+ for (const part of parts) {
29
29
  if (part.match(/^:([a-z_]+)$/))
30
30
  result.push(part)
31
31
  }
@@ -33,18 +33,18 @@ module.exports = class ApiMakerResourceRoute {
33
33
  return result
34
34
  }
35
35
 
36
- requireComponentFromCaller() {
36
+ requireComponentFromCaller () {
37
37
  return this.requireComponent({
38
38
  routeDefinition: digg(this, "routeDefinition")
39
39
  })
40
40
  }
41
41
 
42
- withLocale() {
42
+ withLocale () {
43
43
  const component = this.requireComponentFromCaller()
44
44
  const Locales = require("shared/locales").default
45
45
  const routes = []
46
46
 
47
- for(const locale of Locales.availableLocales()) {
47
+ for (const locale of Locales.availableLocales()) {
48
48
  const routePathName = `${inflection.camelize(digg(this, "routeDefinition", "name"), true)}Path`
49
49
  const params = this.findRouteParams()
50
50
 
@@ -62,7 +62,7 @@ module.exports = class ApiMakerResourceRoute {
62
62
  return routes
63
63
  }
64
64
 
65
- withoutLocale() {
65
+ withoutLocale () {
66
66
  const routePathName = inflection.camelize(digg(this, "routeDefinition", "name"), true)
67
67
  const routePathMethod = this.jsRoutes[`${routePathName}Path`]
68
68
 
@@ -72,9 +72,11 @@ module.exports = class ApiMakerResourceRoute {
72
72
  const path = routePathMethod.apply(null, this.findRouteParams())
73
73
  const component = this.requireComponentFromCaller()
74
74
 
75
- return [{
76
- path,
77
- component
78
- }]
75
+ return [
76
+ {
77
+ path,
78
+ component
79
+ }
80
+ ]
79
81
  }
80
82
  }
@@ -4,18 +4,23 @@ const ResourceRoute = require("./resource-route.cjs")
4
4
  const {Route} = require("react-router-dom")
5
5
 
6
6
  export default class ApiMakerResourceRoutes {
7
- static readRoutes({jsRoutes, locales, requireComponent, routeDefinitions}) {
7
+ static readRoutes ({jsRoutes, locales, requireComponent, routeDefinitions}) {
8
8
  if (!routeDefinitions)
9
9
  throw new Error("Please pass 'routeDefinitions' to this method")
10
10
 
11
11
  const routes = []
12
12
 
13
- for(const routeDefinition of routeDefinitions.routes) {
13
+ for (const routeDefinition of routeDefinitions.routes) {
14
14
  const resourceRoute = new ResourceRoute({jsRoutes, locales, requireComponent, routeDefinition})
15
15
 
16
- for(const newRoute of resourceRoute.routesResult()) {
16
+ for (const newRoute of resourceRoute.routesResult()) {
17
17
  routes.push(
18
- <Route exact key={`route-${digg(newRoute, "path")}`} path={digg(newRoute, "path")} component={digg(newRoute, "component")} />
18
+ <Route
19
+ component={digg(newRoute, "component")}
20
+ exact
21
+ key={`route-${digg(newRoute, "path")}`}
22
+ path={digg(newRoute, "path")}
23
+ />
19
24
  )
20
25
  }
21
26
  }
package/src/result.cjs CHANGED
@@ -1,29 +1,29 @@
1
1
  module.exports = class ApiMakerResult {
2
- constructor(data) {
2
+ constructor (data) {
3
3
  this.data = data
4
4
  }
5
5
 
6
- currentPage() {
6
+ currentPage () {
7
7
  return this.data.response.meta.currentPage
8
8
  }
9
9
 
10
- models() {
10
+ models () {
11
11
  return this.data.models
12
12
  }
13
13
 
14
- modelClass() {
14
+ modelClass () {
15
15
  return this.data.collection.modelClass()
16
16
  }
17
17
 
18
- perPage() {
18
+ perPage () {
19
19
  return this.data.response.meta.perPage
20
20
  }
21
21
 
22
- totalCount() {
22
+ totalCount () {
23
23
  return this.data.response.meta.totalCount
24
24
  }
25
25
 
26
- totalPages() {
26
+ totalPages () {
27
27
  return this.data.response.meta.totalPages
28
28
  }
29
29
  }
@@ -3,13 +3,13 @@ const inflection = require("inflection")
3
3
  const qs = require("qs")
4
4
 
5
5
  module.exports = class ApiMakerRoutesNative {
6
- constructor({getLocale}) {
6
+ constructor ({getLocale}) {
7
7
  this.getLocale = getLocale
8
8
  this.routeDefinitions = []
9
9
  this.routeTranslationParts = {}
10
10
  }
11
11
 
12
- loadRouteDefinitions(routeDefinitions, routeDefinitionArgs) {
12
+ loadRouteDefinitions (routeDefinitions, routeDefinitionArgs) {
13
13
  for (const routeDefinition of digg(routeDefinitions, "routes")) {
14
14
  const {name, path} = digs(routeDefinition, "name", "path")
15
15
  const rawPathParts = path.split("/")
@@ -62,7 +62,7 @@ module.exports = class ApiMakerRoutesNative {
62
62
  }
63
63
  }
64
64
 
65
- loadRouteTranslations(i18n) {
65
+ loadRouteTranslations (i18n) {
66
66
  const locales = digg(i18n, "locales")
67
67
 
68
68
  for (const locale in locales) {
@@ -77,7 +77,7 @@ module.exports = class ApiMakerRoutesNative {
77
77
  }
78
78
  }
79
79
 
80
- translateRoute({args, localizedRoutes, pathParts, url}) {
80
+ translateRoute ({args, localizedRoutes, pathParts, url}) {
81
81
  let options
82
82
 
83
83
  // Extract options from args if any
@@ -137,7 +137,7 @@ module.exports = class ApiMakerRoutesNative {
137
137
  throw new Error("Unhandled state")
138
138
  }
139
139
 
140
- addHostToRoute({host, port, protocol, translatedRoute}) {
140
+ addHostToRoute ({host, port, protocol, translatedRoute}) {
141
141
  let fullUrl = ""
142
142
 
143
143
  const hostToUse = host || global.location && global.location.host
@@ -150,7 +150,7 @@ module.exports = class ApiMakerRoutesNative {
150
150
  } else if (global.location && global.location.protocol) {
151
151
  fullUrl += `${global.location.protocol}//`
152
152
  } else {
153
- fullUrl += `https://`
153
+ fullUrl += "https://"
154
154
  }
155
155
 
156
156
  fullUrl += hostToUse
package/src/routes.cjs CHANGED
@@ -2,7 +2,7 @@ const {digg} = require("diggerize")
2
2
  const inflection = require("inflection")
3
3
 
4
4
  module.exports = class ApiMakerRoutes {
5
- constructor({jsRoutes, locale, routeDefinitions}) {
5
+ constructor ({jsRoutes, locale, routeDefinitions}) {
6
6
  this.jsRoutes = jsRoutes
7
7
  this.routeDefinitions = routeDefinitions
8
8
 
@@ -1,34 +1,34 @@
1
1
  const {digg} = require("diggerize")
2
2
 
3
3
  module.exports = class Serializer {
4
- static serialize(arg) {
4
+ static serialize (arg) {
5
5
  const serialize = new Serializer(arg)
6
6
 
7
7
  return serialize.serialize()
8
8
  }
9
9
 
10
- constructor(arg) {
10
+ constructor (arg) {
11
11
  this.arg = arg
12
12
  }
13
13
 
14
- serialize() {
14
+ serialize () {
15
15
  return this.serializeArgument(this.arg)
16
16
  }
17
17
 
18
- serializeArgument(arg) {
19
- if (typeof arg == "function" && arg["modelClassData"] && arg["modelName"]) {
18
+ serializeArgument (arg) {
19
+ if (typeof arg == "function" && arg.modelClassData && arg.modelName) {
20
20
  return {
21
21
  api_maker_type: "resource",
22
22
  name: digg(arg.modelClassData(), "name")
23
23
  }
24
24
  } else if (arg instanceof Date) {
25
- let offsetNumber = parseInt((arg.getTimezoneOffset() / 60) * 100)
25
+ let offsetNumber = parseInt((arg.getTimezoneOffset() / 60) * 100, 10)
26
26
 
27
27
  offsetNumber = -offsetNumber
28
28
 
29
29
  let offset = `${offsetNumber}`
30
30
 
31
- while(offset.length < 4) {
31
+ while (offset.length < 4) {
32
32
  offset = `0${offset}`
33
33
  }
34
34
 
@@ -45,11 +45,11 @@ module.exports = class Serializer {
45
45
  }
46
46
  }
47
47
 
48
- serializeArray(arg) {
48
+ serializeArray (arg) {
49
49
  return arg.map((value) => this.serializeArgument(value))
50
50
  }
51
51
 
52
- serializeObject(arg) {
52
+ serializeObject (arg) {
53
53
  const newObject = {}
54
54
 
55
55
  for (const key in arg) {
package/src/services.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  const CommandsPool = require("./commands-pool.cjs")
2
2
 
3
3
  module.exports = class ApiMakerServices {
4
- static current() {
4
+ static current () {
5
5
  if (!global.currentApiMakerService) {
6
6
  global.currentApiMakerService = new ApiMakerServices()
7
7
  }
@@ -9,8 +9,8 @@ module.exports = class ApiMakerServices {
9
9
  return global.currentApiMakerService
10
10
  }
11
11
 
12
- async sendRequest(serviceName, args) {
13
- return await CommandsPool.addCommand({
12
+ sendRequest (serviceName, args) {
13
+ return CommandsPool.addCommand({
14
14
  args: {
15
15
  service_args: args,
16
16
  service_name: serviceName
@@ -3,14 +3,14 @@ const inflection = require("inflection")
3
3
  const wakeEvent = require("wake-event")
4
4
 
5
5
  module.exports = class ApiMakerSessionStatusUpdater {
6
- static current() {
6
+ static current () {
7
7
  if (!global.apiMakerSessionStatusUpdater)
8
8
  global.apiMakerSessionStatusUpdater = new ApiMakerSessionStatusUpdater()
9
9
 
10
10
  return global.apiMakerSessionStatusUpdater
11
11
  }
12
12
 
13
- constructor(args = {}) {
13
+ constructor (args = {}) {
14
14
  this.debugging = args.debug || false
15
15
  this.events = {}
16
16
  this.timeout = args.timeout || 600000
@@ -19,20 +19,20 @@ module.exports = class ApiMakerSessionStatusUpdater {
19
19
  this.connectWakeEvent()
20
20
  }
21
21
 
22
- connectOnlineEvent() {
22
+ connectOnlineEvent () {
23
23
  global.addEventListener("online", () => this.updateSessionStatus(), false)
24
24
  }
25
25
 
26
- connectWakeEvent() {
26
+ connectWakeEvent () {
27
27
  wakeEvent(() => this.updateSessionStatus())
28
28
  }
29
29
 
30
- debug(message) {
30
+ debug (message) {
31
31
  if (this.debugging)
32
32
  console.log(`ApiMakerSessionStatusUpdater: ${message}`)
33
33
  }
34
34
 
35
- async sessionStatus() {
35
+ async sessionStatus () {
36
36
  return new Promise((resolve) => {
37
37
  const xhr = new XMLHttpRequest()
38
38
  xhr.open("POST", "/api_maker/session_statuses", true)
@@ -44,11 +44,11 @@ module.exports = class ApiMakerSessionStatusUpdater {
44
44
  })
45
45
  }
46
46
 
47
- onSignedOut(callback) {
47
+ onSignedOut (callback) {
48
48
  this.addEvent("onSignedOut", callback)
49
49
  }
50
50
 
51
- startTimeout() {
51
+ startTimeout () {
52
52
  this.debug("startTimeout")
53
53
 
54
54
  if (this.updateTimeout)
@@ -63,12 +63,12 @@ module.exports = class ApiMakerSessionStatusUpdater {
63
63
  )
64
64
  }
65
65
 
66
- stopTimeout() {
66
+ stopTimeout () {
67
67
  if (this.updateTimeout)
68
68
  clearTimeout(this.updateTimeout)
69
69
  }
70
70
 
71
- async updateSessionStatus() {
71
+ async updateSessionStatus () {
72
72
  this.debug("updateSessionStatus")
73
73
 
74
74
  const result = await this.sessionStatus()
@@ -78,7 +78,7 @@ module.exports = class ApiMakerSessionStatusUpdater {
78
78
  this.updateUserSessionsFromResult(result)
79
79
  }
80
80
 
81
- updateMetaElementsFromResult(result) {
81
+ updateMetaElementsFromResult (result) {
82
82
  this.debug("updateMetaElementsFromResult")
83
83
  const csrfTokenElement = document.querySelector("meta[name='csrf-token']")
84
84
 
@@ -90,13 +90,13 @@ module.exports = class ApiMakerSessionStatusUpdater {
90
90
  }
91
91
  }
92
92
 
93
- updateUserSessionsFromResult(result) {
94
- for(const scopeName in result.scopes) {
93
+ updateUserSessionsFromResult (result) {
94
+ for (const scopeName in result.scopes) {
95
95
  this.updateUserSessionScopeFromResult(scopeName, result.scopes[scopeName])
96
96
  }
97
97
  }
98
98
 
99
- updateUserSessionScopeFromResult(scopeName, scope) {
99
+ updateUserSessionScopeFromResult (scopeName, scope) {
100
100
  const deviseIsSignedInMethodName = `is${inflection.camelize(scopeName)}SignedIn`
101
101
 
102
102
  if (!(deviseIsSignedInMethodName in Devise)) {
@@ -9,24 +9,24 @@ if (SourceMapConsumer.initialize) {
9
9
  }
10
10
 
11
11
  module.exports = class SourceMapsLoader {
12
- constructor() {
12
+ constructor () {
13
13
  this.sourceMaps = []
14
14
  this.srcLoaded = {}
15
15
  }
16
16
 
17
- loadSourceMapsForScriptTags(callback) {
17
+ loadSourceMapsForScriptTags (callback) {
18
18
  this.loadSourceMapsForScriptTagsCallback = callback
19
19
  }
20
20
 
21
- sourceMapForSource(callback) {
21
+ sourceMapForSource (callback) {
22
22
  this.sourceMapForSourceCallback = callback
23
23
  }
24
24
 
25
- async loadSourceMaps() {
25
+ async loadSourceMaps () {
26
26
  const scripts = document.querySelectorAll("script")
27
27
  const promises = []
28
28
 
29
- for(const script of scripts) {
29
+ for (const script of scripts) {
30
30
  const src = this.loadSourceMapsForScriptTagsCallback(script)
31
31
 
32
32
  if (src && !this.srcLoaded[src]) {
@@ -40,7 +40,7 @@ module.exports = class SourceMapsLoader {
40
40
  await Promise.all(promises)
41
41
  }
42
42
 
43
- async loadSourceMapForSource(src) {
43
+ async loadSourceMapForSource (src) {
44
44
  const url = this.loadUrl(src)
45
45
  const originalUrl = `${url.origin}${url.pathname}`
46
46
 
@@ -65,30 +65,30 @@ module.exports = class SourceMapsLoader {
65
65
  this.sourceMaps.push({consumer, originalUrl, src})
66
66
  }
67
67
 
68
- loadUrl(url) {
68
+ loadUrl (url) {
69
69
  const parser = document.createElement("a")
70
70
  parser.href = url
71
71
 
72
72
  return parser
73
73
  }
74
74
 
75
- loadXhr(xhr, postData) {
75
+ loadXhr (xhr, postData) {
76
76
  return new Promise((resolve) => {
77
77
  xhr.onload = () => resolve()
78
78
  xhr.send(postData)
79
79
  })
80
80
  }
81
81
 
82
- parseStackTrace(stackTrace) {
82
+ parseStackTrace (stackTrace) {
83
83
  return this.getStackTraceData(stackTrace)
84
84
  .map((traceData) => `at ${traceData.methodName} (${traceData.fileString})`)
85
85
  }
86
86
 
87
- getStackTraceData(stackTrace) {
87
+ getStackTraceData (stackTrace) {
88
88
  const stack = stackTraceParser.parse(stackTrace)
89
89
  const newSourceMap = []
90
90
 
91
- for(const trace of stack) {
91
+ for (const trace of stack) {
92
92
  const sourceMapData = this.sourceMaps.find((sourceMapData) => sourceMapData.originalUrl == trace.file)
93
93
  let filePath, fileString, original
94
94
 
@@ -1,7 +1,8 @@
1
+ const {digg} = require("diggerize")
1
2
  const translatedCollectionsData = require("./translated-collections-data").default
2
3
 
3
4
  export default class ApiMakerTranslatedCollections {
4
- static get(modelClass, collectionName) {
5
+ static get (modelClass, collectionName) {
5
6
  const locale = I18n.locale
6
7
  const modelClassName = digg(modelClass.modelClassData(), "name")
7
8
  const collection = digg(translatedCollectionsData, modelClassName, collectionName, locale, "collection_array")