@kaspernj/api-maker 1.0.192 → 1.0.195
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/package.json +1 -1
- package/src/base-error.cjs +10 -7
- package/src/base-model.cjs +1 -1
- package/src/collection-loader.jsx +3 -2
- package/src/link.jsx +1 -1
- package/src/validation-error.cjs +7 -3
- package/src/validation-errors.cjs +1 -2
package/package.json
CHANGED
package/src/base-error.cjs
CHANGED
|
@@ -5,11 +5,15 @@ class BaseError extends Error {
|
|
|
5
5
|
constructor (message, args = {}) {
|
|
6
6
|
let messageToUse = message
|
|
7
7
|
|
|
8
|
-
if (
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
if ("addResponseErrorsToErrorMessage" in args && !args.addResponseErrorsToErrorMessage) {
|
|
9
|
+
messageToUse = message
|
|
10
|
+
} else {
|
|
11
|
+
if (typeof args.response == "object" && dig(args, "response", "errors")) {
|
|
12
|
+
if (message) {
|
|
13
|
+
messageToUse = `${messageToUse}: ${errorMessages(args).join(". ")}`
|
|
14
|
+
} else {
|
|
15
|
+
messageToUse = errorMessages(args).join(". ")
|
|
16
|
+
}
|
|
13
17
|
}
|
|
14
18
|
}
|
|
15
19
|
|
|
@@ -17,8 +21,7 @@ class BaseError extends Error {
|
|
|
17
21
|
this.args = args
|
|
18
22
|
|
|
19
23
|
// Maintains proper stack trace for where our error was thrown (only available on V8)
|
|
20
|
-
if (Error.captureStackTrace)
|
|
21
|
-
Error.captureStackTrace(this, BaseError)
|
|
24
|
+
if (Error.captureStackTrace) Error.captureStackTrace(this, BaseError)
|
|
22
25
|
}
|
|
23
26
|
|
|
24
27
|
errorMessages () {
|
package/src/base-model.cjs
CHANGED
|
@@ -311,7 +311,7 @@ class BaseModel {
|
|
|
311
311
|
}
|
|
312
312
|
|
|
313
313
|
static parseValidationErrors ({error, model, options}) {
|
|
314
|
-
if (!(error instanceof
|
|
314
|
+
if (!(error instanceof ValidationError)) return
|
|
315
315
|
if (!error.args.response.validation_errors) return
|
|
316
316
|
|
|
317
317
|
const validationErrors = new ValidationErrors({
|
|
@@ -14,6 +14,7 @@ import {LocationChanged} from "on-location-changed/src/location-changed-componen
|
|
|
14
14
|
export default class CollectionLoader extends React.PureComponent {
|
|
15
15
|
static defaultProps = {
|
|
16
16
|
destroyEnabled: true,
|
|
17
|
+
groupBy: ["id"],
|
|
17
18
|
noRecordsAvailableContent: undefined,
|
|
18
19
|
noRecordsFoundContent: undefined,
|
|
19
20
|
preloads: [],
|
|
@@ -100,9 +101,9 @@ export default class CollectionLoader extends React.PureComponent {
|
|
|
100
101
|
const {abilities, collection, groupBy, modelClass, onModelsLoaded, preloads, select, selectColumns} = this.props
|
|
101
102
|
const {qParams, queryPageName, queryQName} = digs(this.shape, "qParams", "queryPageName", "queryQName")
|
|
102
103
|
|
|
103
|
-
let query = collection?.clone() || modelClass
|
|
104
|
+
let query = collection?.clone() || modelClass.ransack()
|
|
104
105
|
|
|
105
|
-
if (groupBy) query = query.groupBy(groupBy)
|
|
106
|
+
if (groupBy) query = query.groupBy(...groupBy)
|
|
106
107
|
|
|
107
108
|
query = query
|
|
108
109
|
.ransack(qParams)
|
package/src/link.jsx
CHANGED
|
@@ -17,7 +17,7 @@ export default class Link extends React.PureComponent {
|
|
|
17
17
|
if (!e.defaultPrevented && !e.ctrlKey && !e.metaKey) {
|
|
18
18
|
e.preventDefault()
|
|
19
19
|
|
|
20
|
-
const history =
|
|
20
|
+
const history = globalThis.apiMakerConfigGlobal?.history
|
|
21
21
|
|
|
22
22
|
if (!history) throw new Error("History hasn't been set in the API maker configuration")
|
|
23
23
|
|
package/src/validation-error.cjs
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
const
|
|
1
|
+
const BaseError = require("./base-error.cjs")
|
|
2
2
|
const inflection = require("inflection")
|
|
3
3
|
|
|
4
|
-
class ValidationError extends
|
|
4
|
+
class ValidationError extends BaseError {
|
|
5
5
|
constructor (validationErrors, args) {
|
|
6
|
-
|
|
6
|
+
const errorMessage = validationErrors.getUnhandledErrorMessage() || validationErrors.getErrorMessage()
|
|
7
|
+
const forwardedArgs = {addResponseErrorsToErrorMessage: false}
|
|
8
|
+
const newArgs = Object.assign({}, args, forwardedArgs)
|
|
9
|
+
|
|
10
|
+
super(errorMessage, newArgs)
|
|
7
11
|
this.validationErrors = validationErrors
|
|
8
12
|
}
|
|
9
13
|
|
|
@@ -96,8 +96,7 @@ class ValidationErrors {
|
|
|
96
96
|
return this.validationErrors
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
getValidationErrorsForInput (
|
|
100
|
-
const {attribute, inputName, onMatchValidationError} = args
|
|
99
|
+
getValidationErrorsForInput ({attribute, inputName, onMatchValidationError}) {
|
|
101
100
|
const validationErrors = this.validationErrors.filter((validationError) => {
|
|
102
101
|
if (onMatchValidationError) {
|
|
103
102
|
return onMatchValidationError(validationError)
|