@kaspernj/api-maker 1.0.203 → 1.0.206

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 (78) hide show
  1. package/{.eslintrc.js → .eslintrc.cjs} +0 -0
  2. package/__tests__/base-model.test.js +11 -9
  3. package/__tests__/cable-connection-pool.test.js +5 -3
  4. package/__tests__/cable-subscription-pool.test.js +1 -1
  5. package/__tests__/can-can.test.js +4 -3
  6. package/__tests__/collection.test.js +1 -1
  7. package/__tests__/custom-error.test.js +1 -1
  8. package/__tests__/merge.test.js +1 -1
  9. package/__tests__/model-name.test.js +3 -2
  10. package/__tests__/model-prop-type.test.js +3 -3
  11. package/__tests__/params.test.js +1 -1
  12. package/__tests__/routes-native.test.js +4 -4
  13. package/__tests__/routes.test.js +1 -1
  14. package/__tests__/serializer.test.js +2 -2
  15. package/__tests__/support/task.js +1 -1
  16. package/__tests__/support/user.js +2 -2
  17. package/jest.config.js +3 -2
  18. package/package.json +3 -2
  19. package/src/{api.js → api.mjs} +2 -2
  20. package/src/attribute-not-loaded-error.mjs +1 -0
  21. package/src/{base-error.cjs → base-error.mjs} +3 -3
  22. package/src/{base-model.cjs → base-model.mjs} +31 -35
  23. package/src/{cable-connection-pool.cjs → cable-connection-pool.mjs} +8 -7
  24. package/src/{cable-subscription-pool.cjs → cable-subscription-pool.mjs} +8 -8
  25. package/src/{cable-subscription.cjs → cable-subscription.mjs} +3 -3
  26. package/src/can-can-loader.jsx +4 -4
  27. package/src/{can-can.cjs → can-can.mjs} +10 -10
  28. package/src/channels-consumer.mjs +3 -0
  29. package/src/collection-loader.jsx +10 -10
  30. package/src/{collection.cjs → collection.mjs} +8 -8
  31. package/src/{command-submit-data.cjs → command-submit-data.mjs} +3 -3
  32. package/src/{commands-pool.cjs → commands-pool.mjs} +16 -16
  33. package/src/{config.js → config.mjs} +3 -2
  34. package/src/{custom-error.cjs → custom-error.mjs} +2 -2
  35. package/src/{deserializer.cjs → deserializer.mjs} +6 -6
  36. package/src/{destroy-error.cjs → destroy-error.mjs} +2 -2
  37. package/src/devise.mjs +4 -4
  38. package/src/{error-logger.cjs → error-logger.mjs} +5 -5
  39. package/src/{error-messages.cjs → error-messages.mjs} +2 -2
  40. package/src/event-connection.jsx +4 -4
  41. package/src/event-created.jsx +5 -5
  42. package/src/event-destroyed.jsx +4 -4
  43. package/src/event-emitter-listener.jsx +3 -3
  44. package/src/event-listener.jsx +3 -3
  45. package/src/event-model-class.jsx +4 -4
  46. package/src/event-updated.jsx +5 -5
  47. package/src/{instance-of-class-name.cjs → instance-of-class-name.mjs} +2 -2
  48. package/src/{key-value-store.cjs → key-value-store.mjs} +6 -5
  49. package/src/{logger.cjs → logger.mjs} +7 -5
  50. package/src/{merge.cjs → merge.mjs} +1 -1
  51. package/src/model-class-require.mjs +10 -0
  52. package/src/{model-events.cjs → model-events.mjs} +3 -3
  53. package/src/model-load-wrapper.jsx +9 -4
  54. package/src/{model-name.cjs → model-name.mjs} +7 -5
  55. package/src/{model-prop-type.cjs → model-prop-type.mjs} +3 -3
  56. package/src/model-recipes-model-loader.mjs +2 -2
  57. package/src/{models-response-reader.cjs → models-response-reader.mjs} +5 -5
  58. package/src/models.mjs.erb +16 -0
  59. package/src/{money-formatter.cjs → money-formatter.mjs} +4 -4
  60. package/src/not-loaded-error.mjs +1 -0
  61. package/src/{params.cjs → params.mjs} +5 -5
  62. package/src/{preloaded.cjs → preloaded.mjs} +3 -3
  63. package/src/{result.cjs → result.mjs} +1 -1
  64. package/src/{routes-native.cjs → routes-native.mjs} +8 -8
  65. package/src/{routes.cjs → routes.mjs} +3 -3
  66. package/src/{serializer.cjs → serializer.mjs} +2 -2
  67. package/src/{services.cjs → services.mjs} +6 -6
  68. package/src/{source-maps-loader.cjs → source-maps-loader.mjs} +4 -4
  69. package/src/updated-attribute.jsx +5 -5
  70. package/src/{validation-error.cjs → validation-error.mjs} +3 -3
  71. package/src/{validation-errors.cjs → validation-errors.mjs} +4 -4
  72. package/src/with-router.jsx +1 -1
  73. package/src/attribute-not-loaded-error.cjs +0 -1
  74. package/src/channels-consumer.cjs +0 -3
  75. package/src/model-class-require.cjs +0 -9
  76. package/src/model-recipes.mjs.erb +0 -3
  77. package/src/models.cjs +0 -7
  78. package/src/not-loaded-error.cjs +0 -1
File without changes
@@ -1,14 +1,16 @@
1
+ import BaseModel from "../src/base-model.mjs"
2
+ import CustomError from "../src/custom-error.mjs"
3
+ import {jest} from "@jest/globals"
4
+ import {JSDOM} from "jsdom"
5
+ import ValidationError from "../src/validation-error.mjs"
6
+ import User from "./support/user.mjs"
7
+
1
8
  jest.mock("@rails/actioncable", () => ({
2
9
  createConsumer: () => ({})
3
10
  }))
4
11
 
5
- const BaseModel = require("../src/base-model.cjs")
6
- const CustomError = require("../src/custom-error.cjs")
7
- const {JSDOM} = require("jsdom")
8
12
  const {window} = new JSDOM()
9
13
  const document = window.document
10
- const ValidationError = require("../src/validation-error.cjs")
11
- const User = require("./support/user")
12
14
 
13
15
  describe("BaseModel", () => {
14
16
  describe("identifierKey", () => {
@@ -48,20 +50,20 @@ describe("BaseModel", () => {
48
50
  const form = document.createElement("form")
49
51
  const model = new BaseModel()
50
52
  const dispatchEventSpy = jest.spyOn(form, "dispatchEvent").mockImplementation(() => "asd")
51
- const newCustomEventSpy = jest.spyOn(model, "newCustomEvent").mockImplementation(() => "asd")
53
+ const newCustomEventSpy = jest.spyOn(BaseModel, "newCustomEvent").mockImplementation(() => "asd")
52
54
 
53
55
  it("throws the validation errors if no options are given", () => {
54
- expect(() => model.parseValidationErrors(error)).toThrow(ValidationError)
56
+ expect(() => BaseModel.parseValidationErrors({error, model})).toThrow(ValidationError)
55
57
  })
56
58
 
57
59
  it("throws the validation errors and dispatches an event to the form", () => {
58
- expect(() => model.parseValidationErrors(error, {form})).toThrow(ValidationError)
60
+ expect(() => BaseModel.parseValidationErrors({error, model, options: {form}})).toThrow(ValidationError)
59
61
  expect(dispatchEventSpy).toHaveBeenCalled()
60
62
  expect(newCustomEventSpy).toHaveBeenCalled()
61
63
  })
62
64
 
63
65
  it("doesnt throw validation errors if disabled", () => {
64
- model.parseValidationErrors(error, {form, throwValidationError: false})
66
+ BaseModel.parseValidationErrors({error, model, options: {throwValidationError: false}})
65
67
  expect(dispatchEventSpy).toHaveBeenCalled()
66
68
  expect(newCustomEventSpy).toHaveBeenCalled()
67
69
  })
@@ -1,9 +1,11 @@
1
+ import CableConnectionPool from "../src/cable-connection-pool.mjs"
2
+ import CableSubscriptionPool from "../src/cable-subscription-pool.mjs"
3
+ import {digg} from "diggerize"
4
+ import {jest} from "@jest/globals"
5
+
1
6
  jest.mock("@rails/actioncable", () => ({
2
7
  createConsumer: () => ({})
3
8
  }))
4
- const CableConnectionPool = require("../src/cable-connection-pool.cjs")
5
- const CableSubscriptionPool = require("../src/cable-subscription-pool.cjs")
6
- const {digg} = require("diggerize")
7
9
 
8
10
  describe("CableConnectionPool", () => {
9
11
  describe("connectCreated", () => {
@@ -1,7 +1,7 @@
1
1
  jest.mock("@rails/actioncable", () => ({
2
2
  createConsumer: () => ({})
3
3
  }))
4
- const CableSubscriptionPool = require("../src/cable-subscription-pool.cjs")
4
+ import CableSubscriptionPool from "../src/cable-subscription-pool.mjs"
5
5
 
6
6
  describe("CableSubscriptionPool", () => {
7
7
  describe("onUnsubscribe", () => {
@@ -1,13 +1,14 @@
1
- const CanCan = require("../src/can-can.cjs")
1
+ import CanCan from "../src/can-can.mjs"
2
+ import {jest} from "@jest/globals"
2
3
 
3
- jest.mock("../src/services.cjs")
4
+ jest.mock("../src/services.mjs")
4
5
 
5
6
  describe("CanCan", () => {
6
7
  const canCan = CanCan.current()
7
8
 
8
9
  describe("resetAbilities", () => {
9
10
  test("that reset abilities and load abilities not have concurrency issues", async () => {
10
- const Services = require("../src/services.cjs")
11
+ import Services from "../src/services.mjs"
11
12
  const mockedCurrent = jest.fn().mockReturnValue({
12
13
  sendRequest: async () => ({abilities: ["loaded"]})
13
14
  })
@@ -1,4 +1,4 @@
1
- const Collection = require("../src/collection.cjs")
1
+ import Collection from "../src/collection.mjs"
2
2
 
3
3
  describe("Collection", () => {
4
4
  describe("count", () => {
@@ -1,4 +1,4 @@
1
- const CustomError = require("../src/custom-error.cjs")
1
+ import CustomError from "../src/custom-error.mjs"
2
2
 
3
3
  describe("CustomError", () => {
4
4
  it("handles when response is a string", () => {
@@ -1,4 +1,4 @@
1
- const {merge} = require("../src/merge.cjs")
1
+ import {merge} from "../src/merge.mjs"
2
2
 
3
3
  describe("merge", () => {
4
4
  it("merges an empty object and changes nothing", () => {
@@ -1,6 +1,7 @@
1
- const I18nOnSteroids = require("i18n-on-steroids")
1
+ import I18nOnSteroids from "i18n-on-steroids"
2
+ import ModelName from "../src/model-name.mjs"
3
+
2
4
  const i18n = new I18nOnSteroids()
3
- const ModelName = require("../src/model-name.cjs")
4
5
 
5
6
  const initializeI18n = () => {
6
7
  i18n.scanObject({
@@ -1,6 +1,6 @@
1
- const ModelPropType = require("../src/model-prop-type.cjs")
2
- const Task = require("./support/task")
3
- const User = require("./support/user")
1
+ import ModelPropType from "../src/model-prop-type.mjs"
2
+ import Task from "./support/task.mjs"
3
+ import User from "./support/user.mjs"
4
4
 
5
5
  describe("ModelPropType", () => {
6
6
  describe("ofModel", () => {
@@ -1,4 +1,4 @@
1
- const Params = require("../src/params.cjs")
1
+ import Params from "../src/params.mjs"
2
2
 
3
3
  describe("Params", () => {
4
4
  describe("change", () => {
@@ -1,4 +1,4 @@
1
- const RoutesNative = require("../src/routes-native.cjs")
1
+ import RoutesNative from "../src/routes-native.mjs"
2
2
  const testRoutes = () => ({
3
3
  routes: [
4
4
  {"name": "blank", "path": "/blank", "component": "blank"},
@@ -76,10 +76,10 @@ describe("RoutesNative", () => {
76
76
  })
77
77
 
78
78
  it("generates urls", () => {
79
- if (!global.location) global.location = {} // eslint-disable-line jest/no-if
79
+ if (!globalThis.location) globalThis.location = {} // eslint-disable-line jest/no-if
80
80
 
81
- global.location.host = "localhost"
82
- global.location.protocol = "http:"
81
+ globalThis.location.host = "localhost"
82
+ globalThis.location.protocol = "http:"
83
83
 
84
84
  const test = routesNative({args: {localized: true}, currentLocale: "en"})
85
85
  const daRoute = test.editDrinkUrl(5, {drink: {name: "Pina Colada"}, locale: "da"})
@@ -1,4 +1,4 @@
1
- const Routes = require("../src/routes.cjs")
1
+ import Routes from "../src/routes.mjs"
2
2
  const testRoutes = {
3
3
  routes: [
4
4
  {"name": "blank", "path": "/blank", "component": "blank"},
@@ -1,5 +1,5 @@
1
- const Serializer = require("../src/serializer.cjs")
2
- const User = require("./support/user")
1
+ import Serializer from "../src/serializer.mjs"
2
+ import User from "./support/user.mjs"
3
3
 
4
4
  describe("Serializer", () => {
5
5
  test("it serializes model classes", () => {
@@ -1,4 +1,4 @@
1
- module.exports = class Task {
1
+ export default class Task {
2
2
  static modelClassData () {
3
3
  return {
4
4
  attributes: [],
@@ -1,6 +1,6 @@
1
- const BaseModel = require("../../src/base-model.cjs")
1
+ import BaseModel from "../../src/base-model.mjs"
2
2
 
3
- module.exports = class User extends BaseModel {
3
+ export default class User extends BaseModel {
4
4
  static modelClassData () {
5
5
  return {
6
6
  attributes: [],
package/jest.config.js CHANGED
@@ -1,3 +1,4 @@
1
- module.exports = {
2
- testRegex: "__tests__/.*\.test\.js$" // eslint-disable-line no-useless-escape
1
+ export default {
2
+ testRegex: "__tests__/.*\.test\.(m|)js$", // eslint-disable-line no-useless-escape
3
+ transform: {}
3
4
  }
package/package.json CHANGED
@@ -16,7 +16,8 @@
16
16
  ]
17
17
  },
18
18
  "name": "@kaspernj/api-maker",
19
- "version": "1.0.203",
19
+ "version": "1.0.206",
20
+ "type": "module",
20
21
  "description": "",
21
22
  "main": "index.js",
22
23
  "repository": {
@@ -30,7 +31,7 @@
30
31
  },
31
32
  "homepage": "https://github.com/kaspernj/api_maker",
32
33
  "scripts": {
33
- "eslint": "eslint --ext .cjs,.js,.jsx",
34
+ "eslint": "eslint --ext .mjs,.js,.jsx",
34
35
  "eslint-find-rules": "eslint-find-rules",
35
36
  "test": "jest"
36
37
  },
@@ -1,5 +1,5 @@
1
- import config from "./config.js"
2
- import CustomError from "./custom-error.cjs"
1
+ import config from "./config.mjs"
2
+ import CustomError from "./custom-error.mjs"
3
3
  import FormDataObjectizer from "form-data-objectizer"
4
4
  import qs from "qs"
5
5
 
@@ -0,0 +1 @@
1
+ export default class AttributeNotLoadedError extends Error {}
@@ -1,5 +1,5 @@
1
- const {dig, digg} = require("diggerize")
2
- const errorMessages = require("./error-messages.cjs")
1
+ import {dig, digg} from "diggerize"
2
+ import errorMessages from "./error-messages.mjs"
3
3
 
4
4
  class BaseError extends Error {
5
5
  constructor (message, args = {}) {
@@ -37,4 +37,4 @@ class BaseError extends Error {
37
37
 
38
38
  BaseError.apiMakerType = "BaseError"
39
39
 
40
- module.exports = BaseError
40
+ export default BaseError
@@ -1,35 +1,34 @@
1
- const AttributeNotLoadedError = require("./attribute-not-loaded-error.cjs")
2
- const Collection = require("./collection.cjs")
3
- const CommandsPool = require("./commands-pool.cjs")
4
- const CustomError = require("./custom-error.cjs")
5
- const {digg} = require("diggerize")
6
- const FormDataObjectizer = require("form-data-objectizer")
7
- const inflection = require("inflection")
8
- const ModelName = require("./model-name.cjs")
9
- const NotLoadedError = require("./not-loaded-error.cjs")
10
- const objectToFormData = require("object-to-formdata").serialize
11
- const Services = require("./services.cjs")
12
- const ValidationError = require("./validation-error.cjs")
13
- const {ValidationErrors} = require("./validation-errors.cjs")
14
-
15
- const shared = {}
16
-
17
- const newCustomEvent = (validationErrors) => {
18
- return new CustomEvent("validation-errors", {detail: validationErrors})
19
- }
20
-
21
- const sendValidationErrorsEvent = (validationErrors, options) => {
22
- if (options && options.form) {
23
- const event = newCustomEvent(validationErrors)
24
- options.form.dispatchEvent(event)
25
- }
26
- }
1
+ import AttributeNotLoadedError from "./attribute-not-loaded-error.mjs"
2
+ import Collection from "./collection.mjs"
3
+ import CommandsPool from "./commands-pool.mjs"
4
+ import Config from "@kaspernj/api-maker/src/config.mjs"
5
+ import CustomError from "./custom-error.mjs"
6
+ import {digg} from "diggerize"
7
+ import FormDataObjectizer from "form-data-objectizer"
8
+ import inflection from "inflection"
9
+ import ModelName from "./model-name.mjs"
10
+ import NotLoadedError from "./not-loaded-error.mjs"
11
+ import objectToFormData from "object-to-formdata"
12
+ import Services from "./services.mjs"
13
+ import ValidationError from "./validation-error.mjs"
14
+ import {ValidationErrors} from "./validation-errors.mjs"
27
15
 
28
16
  class BaseModel {
29
17
  static modelClassData () {
30
18
  throw new Error("modelClassData should be overriden by child")
31
19
  }
32
20
 
21
+ static newCustomEvent = (validationErrors) => {
22
+ return new CustomEvent("validation-errors", {detail: validationErrors})
23
+ }
24
+
25
+ static sendValidationErrorsEvent = (validationErrors, options) => {
26
+ if (options && options.form) {
27
+ const event = BaseModel.newCustomEvent(validationErrors)
28
+ options.form.dispatchEvent(event)
29
+ }
30
+ }
31
+
33
32
  static async find (id) {
34
33
  const primaryKeyName = this.modelClassData().primaryKey
35
34
  const query = {}
@@ -56,17 +55,13 @@ class BaseModel {
56
55
  }
57
56
 
58
57
  static modelName () {
59
- return new ModelName({i18n: shared.i18n, modelClassData: this.modelClassData()})
58
+ return new ModelName({modelClassData: this.modelClassData()})
60
59
  }
61
60
 
62
61
  static ransack (query = {}) {
63
62
  return new Collection({modelClass: this}, {ransack: query})
64
63
  }
65
64
 
66
- static setI18n (i18n) {
67
- shared.i18n = i18n
68
- }
69
-
70
65
  constructor (args = {}) {
71
66
  this.changes = {}
72
67
  this.newRecord = args.isNewRecord
@@ -319,7 +314,7 @@ class BaseModel {
319
314
  validationErrors: digg(error, "args", "response", "validation_errors")
320
315
  })
321
316
 
322
- sendValidationErrorsEvent(validationErrors, options)
317
+ BaseModel.sendValidationErrorsEvent(validationErrors, options)
323
318
 
324
319
  if (!options || options.throwValidationError != false) {
325
320
  throw new ValidationError(validationErrors, digg(error, "args"))
@@ -328,8 +323,9 @@ class BaseModel {
328
323
 
329
324
  static humanAttributeName (attributeName) {
330
325
  const keyName = digg(this.modelClassData(), "i18nKey")
326
+ const i18n = Config.getI18n()
331
327
 
332
- if (shared.i18n) return shared.i18n.t(`activerecord.attributes.${keyName}.${BaseModel.snakeCase(attributeName)}`, {defaultValue: attributeName})
328
+ if (i18n) return i18n.t(`activerecord.attributes.${keyName}.${BaseModel.snakeCase(attributeName)}`, {defaultValue: attributeName})
333
329
 
334
330
  return inflection.humanize(attributeName)
335
331
  }
@@ -660,7 +656,7 @@ class BaseModel {
660
656
  if (args instanceof FormData) {
661
657
  postData = args
662
658
  } else {
663
- postData = objectToFormData(args, {}, null, "args")
659
+ postData = objectToFormData.serialize(args, {}, null, "args")
664
660
  }
665
661
  } else {
666
662
  postData = new FormData()
@@ -844,4 +840,4 @@ class BaseModel {
844
840
 
845
841
  BaseModel.apiMakerType = "BaseModel"
846
842
 
847
- module.exports = BaseModel
843
+ export default BaseModel
@@ -1,13 +1,14 @@
1
- const CableSubscriptionPool = require("./cable-subscription-pool.cjs")
2
- const CableSubscription = require("./cable-subscription.cjs")
3
- const {dig} = require("diggerize")
1
+ import CableSubscriptionPool from "./cable-subscription-pool.mjs"
2
+ import CableSubscription from "./cable-subscription.mjs"
3
+ import {dig} from "diggerize"
4
4
 
5
- module.exports = class ApiMakerCableConnectionPool {
5
+ const shared = {}
6
+
7
+ export default class ApiMakerCableConnectionPool {
6
8
  static current () {
7
- if (!global.apiMakerCableConnectionPool)
8
- global.apiMakerCableConnectionPool = new ApiMakerCableConnectionPool()
9
+ if (!shared.apiMakerCableConnectionPool) shared.apiMakerCableConnectionPool = new ApiMakerCableConnectionPool()
9
10
 
10
- return global.apiMakerCableConnectionPool
11
+ return shared.apiMakerCableConnectionPool
11
12
  }
12
13
 
13
14
  constructor () {
@@ -1,11 +1,11 @@
1
- const ChannelsConsumer = require("./channels-consumer.cjs")
2
- const CommandsPool = require("./commands-pool.cjs")
3
- const Deserializer = require("./deserializer.cjs")
4
- const {digg} = require("diggerize")
5
- const inflection = require("inflection")
6
- const Logger = require("./logger.cjs")
7
-
8
- module.exports = class ApiMakerCableSubscriptionPool {
1
+ import ChannelsConsumer from "./channels-consumer.mjs"
2
+ import CommandsPool from "./commands-pool.mjs"
3
+ import Deserializer from "./deserializer.mjs"
4
+ import {digg} from "diggerize"
5
+ import inflection from "inflection"
6
+ import Logger from "./logger.mjs"
7
+
8
+ export default class ApiMakerCableSubscriptionPool {
9
9
  constructor () {
10
10
  this.activeSubscriptions = 0
11
11
  this.connected = false
@@ -1,7 +1,7 @@
1
- const EventEmitter = require("events")
2
- const Logger = require("./logger.cjs")
1
+ import EventEmitter from "events"
2
+ import Logger from "./logger.mjs"
3
3
 
4
- module.exports = class ApiMakerCableSubscription {
4
+ export default class ApiMakerCableSubscription {
5
5
  constructor () {
6
6
  this.events = new EventEmitter()
7
7
  this.subscribed = true
@@ -1,9 +1,9 @@
1
1
  import ApiMakerEventEmitterListener from "./event-emitter-listener"
2
2
  import {digg, digs} from "diggerize"
3
- const CanCan = require("./can-can.cjs")
4
- const PropTypes = require("prop-types")
5
- const propTypesExact = require("prop-types-exact")
6
- const React = require("react")
3
+ import CanCan from "./can-can.mjs"
4
+ import PropTypes from "prop-types"
5
+ import propTypesExact from "prop-types-exact"
6
+ import React from "react"
7
7
 
8
8
  export default class ApiMakerCanCanLoader extends React.PureComponent {
9
9
  static propTypes = propTypesExact({
@@ -1,16 +1,16 @@
1
- const {digg} = require("diggerize")
2
- const EventEmitter = require("events")
3
- const inflection = require("inflection")
4
- const {ReadersWriterLock} = require("epic-locks")
5
- const Services = require("./services.cjs")
1
+ import {digg} from "diggerize"
2
+ import EventEmitter from "events"
3
+ import inflection from "inflection"
4
+ import {ReadersWriterLock} from "epic-locks"
5
+ import Services from "./services.mjs"
6
6
 
7
- module.exports = class ApiMakerCanCan {
7
+ const shared = {}
8
+
9
+ export default class ApiMakerCanCan {
8
10
  static current () {
9
- if (!global.currentApiMakerCanCan) {
10
- global.currentApiMakerCanCan = new ApiMakerCanCan()
11
- }
11
+ if (!shared.currentApiMakerCanCan) shared.currentApiMakerCanCan = new ApiMakerCanCan()
12
12
 
13
- return global.currentApiMakerCanCan
13
+ return shared.currentApiMakerCanCan
14
14
  }
15
15
 
16
16
  constructor () {
@@ -0,0 +1,3 @@
1
+ import {createConsumer} from "@rails/actioncable"
2
+
3
+ export default createConsumer()
@@ -1,13 +1,13 @@
1
- const Collection = require("@kaspernj/api-maker/src/collection")
2
- const {debounce} = require("debounce")
3
- const {digg, digs} = require("diggerize")
4
- const EventCreated = require("@kaspernj/api-maker/src/event-created").default
5
- const EventDestroyed = require("@kaspernj/api-maker/src/event-destroyed").default
6
- const EventUpdated = require("@kaspernj/api-maker/src/event-updated").default
7
- const instanceOfClassName = require("@kaspernj/api-maker/src/instance-of-class-name")
8
- const Params = require("@kaspernj/api-maker/src/params")
9
- const PropTypes = require("prop-types")
10
- const React = require("react")
1
+ import Collection from "@kaspernj/api-maker/src/collection"
2
+ import {debounce} from "debounce"
3
+ import {digg, digs} from "diggerize"
4
+ import EventCreated from "@kaspernj/api-maker/src/event-created"
5
+ import EventDestroyed from "@kaspernj/api-maker/src/event-destroyed"
6
+ import EventUpdated from "@kaspernj/api-maker/src/event-updated"
7
+ import instanceOfClassName from "@kaspernj/api-maker/src/instance-of-class-name"
8
+ import Params from "@kaspernj/api-maker/src/params"
9
+ import PropTypes from "prop-types"
10
+ import React from "react"
11
11
 
12
12
  import {LocationChanged} from "on-location-changed/src/location-changed-component"
13
13
 
@@ -1,10 +1,10 @@
1
- const cloneDeep = require("clone-deep")
2
- const CommandsPool = require("./commands-pool.cjs")
3
- const {digg} = require("diggerize")
4
- const inflection = require("inflection")
5
- const {merge} = require("./merge.cjs")
6
- const modelClassRequire = require("./model-class-require.cjs")
7
- const Result = require("./result.cjs")
1
+ import cloneDeep from "clone-deep"
2
+ import CommandsPool from "./commands-pool.mjs"
3
+ import {digg} from "diggerize"
4
+ import inflection from "inflection"
5
+ import {merge} from "./merge.mjs"
6
+ import modelClassRequire from "./model-class-require.mjs"
7
+ import Result from "./result.mjs"
8
8
 
9
9
  class ApiMakerCollection {
10
10
  constructor (args, queryArgs = {}) {
@@ -252,4 +252,4 @@ class ApiMakerCollection {
252
252
 
253
253
  ApiMakerCollection.apiMakerType = "Collection"
254
254
 
255
- module.exports = ApiMakerCollection
255
+ export default ApiMakerCollection
@@ -1,6 +1,6 @@
1
- const objectToFormData = require("object-to-formdata").serialize
1
+ import objectToFormData from "object-to-formdata"
2
2
 
3
- module.exports = class ApiMakerCommandSubmitData {
3
+ export default class ApiMakerCommandSubmitData {
4
4
  constructor (data) {
5
5
  this.data = data
6
6
  this.filesCount = 0
@@ -28,7 +28,7 @@ module.exports = class ApiMakerCommandSubmitData {
28
28
 
29
29
  objectForFormData.json = JSON.stringify(this.getJsonData())
30
30
 
31
- const formData = objectToFormData(objectForFormData)
31
+ const formData = objectToFormData.serialize(objectForFormData)
32
32
 
33
33
  return formData
34
34
  }
@@ -1,15 +1,17 @@
1
- const Api = require("./api.js").default
2
- const CommandSubmitData = require("./command-submit-data.cjs")
3
- const CustomError = require("./custom-error.cjs")
4
- const DestroyError = require("./destroy-error.cjs")
5
- const Deserializer = require("./deserializer.cjs")
6
- const {dig, digg} = require("diggerize")
7
- const FormDataObjectizer = require("form-data-objectizer")
8
- const Serializer = require("./serializer.cjs")
9
- const ValidationError = require("./validation-error.cjs")
10
- const {ValidationErrors} = require("./validation-errors.cjs")
11
-
12
- module.exports = class ApiMakerCommandsPool {
1
+ import Api from "./api.mjs"
2
+ import CommandSubmitData from "./command-submit-data.mjs"
3
+ import CustomError from "./custom-error.mjs"
4
+ import DestroyError from "./destroy-error.mjs"
5
+ import Deserializer from "./deserializer.mjs"
6
+ import {dig, digg} from "diggerize"
7
+ import FormDataObjectizer from "form-data-objectizer"
8
+ import Serializer from "./serializer.mjs"
9
+ import ValidationError from "./validation-error.mjs"
10
+ import {ValidationErrors} from "./validation-errors.mjs"
11
+
12
+ const shared = {}
13
+
14
+ export default class ApiMakerCommandsPool {
13
15
  static addCommand (data, args = {}) {
14
16
  let pool
15
17
 
@@ -31,11 +33,9 @@ module.exports = class ApiMakerCommandsPool {
31
33
  }
32
34
 
33
35
  static current () {
34
- if (!global.currentApiMakerCommandsPool) {
35
- global.currentApiMakerCommandsPool = new ApiMakerCommandsPool()
36
- }
36
+ if (!shared.currentApiMakerCommandsPool) shared.currentApiMakerCommandsPool = new ApiMakerCommandsPool()
37
37
 
38
- return global.currentApiMakerCommandsPool
38
+ return shared.currentApiMakerCommandsPool
39
39
  }
40
40
 
41
41
  static flush () {
@@ -15,15 +15,16 @@ const accessors = {
15
15
  currenciesCollection: {required: true},
16
16
  history: {required: false},
17
17
  host: {required: false},
18
+ i18n: {required: false},
18
19
  routes: {required: false},
19
20
  routeDefinitions: {required: false}
20
21
  }
21
22
 
22
23
  class ApiMakerConfig {
23
24
  constructor() {
24
- if (!global.apiMakerConfigGlobal) global.apiMakerConfigGlobal = {}
25
+ if (!globalThis.apiMakerConfigGlobal) globalThis.apiMakerConfigGlobal = {}
25
26
 
26
- this.global = global.apiMakerConfigGlobal
27
+ this.global = globalThis.apiMakerConfigGlobal
27
28
  }
28
29
  }
29
30
 
@@ -1,7 +1,7 @@
1
- const BaseError = require("./base-error.cjs")
1
+ import BaseError from "./base-error.mjs"
2
2
 
3
3
  class CustomError extends BaseError {}
4
4
 
5
5
  CustomError.apiMakerType = "CustomError"
6
6
 
7
- module.exports = CustomError
7
+ export default CustomError