@kaspernj/api-maker 1.0.126 → 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.
- package/.eslintrc.js +33 -30
- package/__tests__/cable-connection-pool.test.js +4 -4
- package/__tests__/custom-error.test.js +13 -0
- package/__tests__/support/task.js +5 -5
- package/__tests__/support/user.js +5 -5
- package/package.json +5 -4
- package/src/api.cjs +15 -15
- package/src/base-model.cjs +82 -81
- package/src/cable-connection-pool.cjs +11 -11
- package/src/cable-subscription-pool.cjs +34 -34
- package/src/cable-subscription.cjs +2 -2
- package/src/can-can-loader.jsx +7 -7
- package/src/can-can.cjs +17 -16
- package/src/collection.cjs +36 -36
- package/src/command-submit-data.cjs +10 -11
- package/src/commands-pool.cjs +13 -13
- package/src/custom-error.cjs +20 -14
- package/src/deserializer.cjs +7 -7
- package/src/devise.cjs +15 -15
- package/src/error-logger.cjs +9 -9
- package/src/event-connection.jsx +6 -6
- package/src/event-created.jsx +8 -8
- package/src/event-destroyed.jsx +6 -6
- package/src/event-emitter-listener.jsx +6 -6
- package/src/event-listener.jsx +8 -8
- package/src/event-model-class.jsx +6 -6
- package/src/event-updated.jsx +10 -10
- package/src/instance-of-class-name.cjs +5 -7
- package/src/key-value-store.cjs +21 -18
- package/src/logger.cjs +4 -4
- package/src/merge.cjs +4 -4
- package/src/model-events.cjs +6 -5
- package/src/model-name.cjs +6 -5
- package/src/model-prop-type.cjs +11 -13
- package/src/model-recipes-loader.cjs +4 -4
- package/src/model-recipes-model-loader.cjs +39 -14
- package/src/models-response-reader.cjs +10 -10
- package/src/money-formatter.cjs +11 -11
- package/src/params.cjs +7 -7
- package/src/preloaded.cjs +6 -6
- package/src/resource-route.cjs +14 -12
- package/src/resource-routes.jsx +9 -4
- package/src/result.cjs +7 -7
- package/src/routes-native.cjs +6 -6
- package/src/routes.cjs +1 -1
- package/src/serializer.cjs +9 -9
- package/src/services.cjs +3 -3
- package/src/session-status-updater.cjs +14 -14
- package/src/source-maps-loader.cjs +11 -11
- package/src/translated-collections.cjs +2 -1
- package/src/updated-attribute.jsx +17 -14
- package/src/validation-error.cjs +5 -8
- package/src/validation-errors.cjs +16 -16
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
|
|
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
|
|
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
|
}
|
package/src/resource-route.cjs
CHANGED
|
@@ -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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
return [
|
|
76
|
+
{
|
|
77
|
+
path,
|
|
78
|
+
component
|
|
79
|
+
}
|
|
80
|
+
]
|
|
79
81
|
}
|
|
80
82
|
}
|
package/src/resource-routes.jsx
CHANGED
|
@@ -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
|
|
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
|
}
|
package/src/routes-native.cjs
CHANGED
|
@@ -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 +=
|
|
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
|
|
package/src/serializer.cjs
CHANGED
|
@@ -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
|
|
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
|
-
|
|
13
|
-
return
|
|
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")
|
|
@@ -1,37 +1,37 @@
|
|
|
1
1
|
const {digg} = require("diggerize")
|
|
2
2
|
const ModelEvents = require("./model-events.cjs")
|
|
3
3
|
const PropTypes = require("prop-types")
|
|
4
|
-
const
|
|
4
|
+
const propTypesExact = require("prop-types-exact")
|
|
5
5
|
const React = require("react")
|
|
6
6
|
|
|
7
7
|
export default class ApiMakerUpdatedAttribute extends React.PureComponent {
|
|
8
|
-
static propTypes =
|
|
8
|
+
static propTypes = propTypesExact({
|
|
9
9
|
attribute: PropTypes.string,
|
|
10
10
|
model: PropTypes.object.isRequired,
|
|
11
11
|
onValue: PropTypes.func
|
|
12
12
|
})
|
|
13
13
|
|
|
14
|
-
constructor(props) {
|
|
14
|
+
constructor (props) {
|
|
15
15
|
super(props)
|
|
16
16
|
this.state = {
|
|
17
17
|
model: this.props.model
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
componentDidMount() {
|
|
21
|
+
componentDidMount () {
|
|
22
22
|
this.setAttribute()
|
|
23
23
|
this.connect()
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
componentWillUnmount() {
|
|
26
|
+
componentWillUnmount () {
|
|
27
27
|
// Apparently 'componentWillUnmount' can be called without 'componentDidMount' was called. Several bug reports on this.
|
|
28
28
|
if (this.connectUpdated) {
|
|
29
29
|
this.connectUpdated.unsubscribe()
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
connect() {
|
|
34
|
-
this.connectUpdated = ModelEvents.connectUpdated(this.props.model, args => {
|
|
33
|
+
connect () {
|
|
34
|
+
this.connectUpdated = ModelEvents.connectUpdated(this.props.model, (args) => {
|
|
35
35
|
if (!this.props.attribute || args.model.isAttributeLoaded(this.props.attribute)) {
|
|
36
36
|
this.setState(
|
|
37
37
|
{model: args.model},
|
|
@@ -44,7 +44,7 @@ export default class ApiMakerUpdatedAttribute extends React.PureComponent {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
// This loads the model from the backend with the primary key and the attribute and calls setAttribute
|
|
47
|
-
async loadModelWithAttribute() {
|
|
47
|
+
async loadModelWithAttribute () {
|
|
48
48
|
const id = this.props.model.primaryKey()
|
|
49
49
|
const modelClass = this.props.model.modelClass()
|
|
50
50
|
const modelName = digg(modelClass.modelClassData(), "name")
|
|
@@ -56,7 +56,10 @@ export default class ApiMakerUpdatedAttribute extends React.PureComponent {
|
|
|
56
56
|
const select = {}
|
|
57
57
|
select[modelName] = [primaryKey, this.props.attribute]
|
|
58
58
|
|
|
59
|
-
const model = await modelClass
|
|
59
|
+
const model = await modelClass
|
|
60
|
+
.ransack(args)
|
|
61
|
+
.select(select)
|
|
62
|
+
.first()
|
|
60
63
|
|
|
61
64
|
this.setState(
|
|
62
65
|
{model},
|
|
@@ -64,14 +67,15 @@ export default class ApiMakerUpdatedAttribute extends React.PureComponent {
|
|
|
64
67
|
)
|
|
65
68
|
}
|
|
66
69
|
|
|
67
|
-
setAttribute() {
|
|
70
|
+
setAttribute () {
|
|
68
71
|
let newValue
|
|
69
72
|
|
|
70
73
|
if (this.props.onValue) {
|
|
71
74
|
newValue = this.props.onValue.apply(null, [{model: this.state.model}])
|
|
72
75
|
} else {
|
|
73
|
-
if (!this.state.model[this.props.attribute])
|
|
76
|
+
if (!this.state.model[this.props.attribute]) {
|
|
74
77
|
throw new Error(`No such method: ${digg(this.state.model.modelClassData(), "name")}#${this.props.attribute}()`)
|
|
78
|
+
}
|
|
75
79
|
|
|
76
80
|
newValue = this.state.model[this.props.attribute].apply(this.state.model)
|
|
77
81
|
}
|
|
@@ -81,9 +85,8 @@ export default class ApiMakerUpdatedAttribute extends React.PureComponent {
|
|
|
81
85
|
})
|
|
82
86
|
}
|
|
83
87
|
|
|
84
|
-
render() {
|
|
85
|
-
if (this.state.value === undefined)
|
|
86
|
-
return null
|
|
88
|
+
render () {
|
|
89
|
+
if (this.state.value === undefined) return null
|
|
87
90
|
|
|
88
91
|
return this.state.value
|
|
89
92
|
}
|
package/src/validation-error.cjs
CHANGED
|
@@ -1,25 +1,22 @@
|
|
|
1
1
|
const CustomError = require("./custom-error.cjs")
|
|
2
|
-
const {digg} = require("diggerize")
|
|
3
2
|
const inflection = require("inflection")
|
|
4
3
|
|
|
5
4
|
module.exports = class ValidationError extends CustomError {
|
|
6
|
-
constructor(validationErrors, args) {
|
|
5
|
+
constructor (validationErrors, args) {
|
|
7
6
|
super(validationErrors.getUnhandledErrorMessage() || validationErrors.getErrorMessage(), args)
|
|
8
7
|
this.validationErrors = validationErrors
|
|
9
8
|
}
|
|
10
9
|
|
|
11
|
-
hasUnhandledErrors() {
|
|
12
|
-
const unhandledError = this.validationErrors.getValidationErrors().find(validationError => !validationError.getHandled())
|
|
10
|
+
hasUnhandledErrors () {
|
|
11
|
+
const unhandledError = this.validationErrors.getValidationErrors().find((validationError) => !validationError.getHandled())
|
|
13
12
|
return Boolean(unhandledError)
|
|
14
13
|
}
|
|
15
14
|
|
|
16
|
-
hasValidationErrorForAttribute(attributeName) {
|
|
15
|
+
hasValidationErrorForAttribute (attributeName) {
|
|
17
16
|
const underscoredAttributeName = inflection.underscore(attributeName)
|
|
18
17
|
const foundAttribute = this.validationErrors.getValidationErrors().find((validationError) => validationError.getAttributeName() == underscoredAttributeName)
|
|
19
18
|
|
|
20
|
-
if (foundAttribute)
|
|
21
|
-
return true
|
|
22
|
-
}
|
|
19
|
+
if (foundAttribute) return true
|
|
23
20
|
|
|
24
21
|
return false
|
|
25
22
|
}
|