@vsaas/loopback-datasource-juggler 11.2.0 → 12.0.0

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.
@@ -194,6 +194,9 @@ var require_validations = /* @__PURE__ */ require_runtime.__commonJSMin(((export
194
194
  /**
195
195
  * Validate using custom asynchronous validation function.
196
196
  *
197
+ * The validator uses the callback-style signature `(err, done)` or
198
+ * `(err, options, done)`.
199
+ *
197
200
  * Example:
198
201
  *```js
199
202
  * User.validateAsync('name', customValidator, {message: 'Bad name'});
@@ -223,6 +226,40 @@ var require_validations = /* @__PURE__ */ require_runtime.__commonJSMin(((export
223
226
  */
224
227
  Validatable.validateAsync = getConfigurator("custom", { async: true });
225
228
  /**
229
+ * Validate using a custom promise-based validation function.
230
+ *
231
+ * The validator receives validation options as its first argument and should
232
+ * either resolve when valid or throw/reject when invalid.
233
+ *
234
+ * Example:
235
+ *```js
236
+ * User.validatePromise('name', async function(options) {
237
+ * await Promise.resolve();
238
+ * if (this.name === 'bad') {
239
+ * throw new Error('Bad name');
240
+ * }
241
+ * });
242
+ * var user = new User({name: 'Peter'});
243
+ * user.isValid(function (isValid) {
244
+ * isValid; // true
245
+ * })
246
+ * user.name = 'bad';
247
+ * user.isValid(function (isValid) {
248
+ * isValid; // false
249
+ * })
250
+ * ```
251
+ *
252
+ * @param {String} propertyName Property name to validate.
253
+ * @param {Function} validatorFn Custom validation function.
254
+ * @options {Object} options Configuration parameters; see below.
255
+ * @property {String} message Optional error message if property is not valid. Default error message: " is invalid".
256
+ * @property {Boolean} allowNull Whether null values are allowed.
257
+ */
258
+ Validatable.validatePromise = getConfigurator("custom", {
259
+ async: true,
260
+ promise: true
261
+ });
262
+ /**
226
263
  * Validate uniqueness of the value for a property in the collection of models.
227
264
  *
228
265
  * Not available for all connectors. Currently supported with these connectors:
@@ -324,9 +361,49 @@ var require_validations = /* @__PURE__ */ require_runtime.__commonJSMin(((export
324
361
  done = options;
325
362
  options = {};
326
363
  }
327
- if (!done) conf.customValidator.call(this, err, options);
328
- else if (conf.customValidator.length === 3) conf.customValidator.call(this, err, options, done);
329
- else conf.customValidator.call(this, err, done);
364
+ if (!done) return conf.customValidator.call(this, err, options);
365
+ if (conf.options && conf.options.promise) return validatePromiseCustom.call(this, attr, conf, err, options, done);
366
+ if (conf.customValidator.length === 3) return conf.customValidator.call(this, err, options, done);
367
+ return conf.customValidator.call(this, err, done);
368
+ }
369
+ function validatePromiseCustom(attr, conf, err, options, done) {
370
+ let result;
371
+ try {
372
+ result = conf.customValidator.call(this, options);
373
+ } catch (reason) {
374
+ handleCustomValidatorRejection.call(this, attr, conf, err, reason);
375
+ done();
376
+ return;
377
+ }
378
+ if (!isPromiseLike(result)) {
379
+ done();
380
+ return result;
381
+ }
382
+ result.then(function() {
383
+ done();
384
+ }, function(reason) {
385
+ handleCustomValidatorRejection.call(this, attr, conf, err, reason);
386
+ done();
387
+ }.bind(this));
388
+ return result;
389
+ }
390
+ function handleCustomValidatorRejection(attr, conf, err, reason) {
391
+ const message = getCustomValidatorRejectionMessage(conf, reason);
392
+ if (!message) {
393
+ err();
394
+ return;
395
+ }
396
+ err(false);
397
+ this.errors.add(attr, message, conf.code || conf.validation);
398
+ }
399
+ function getCustomValidatorRejectionMessage(conf, reason) {
400
+ if (typeof conf.message === "string") return conf.message;
401
+ if (reason instanceof Error && reason.message) return reason.message;
402
+ if (typeof reason === "string") return reason;
403
+ return null;
404
+ }
405
+ function isPromiseLike(value) {
406
+ return value != null && typeof value.then === "function";
330
407
  }
331
408
  function escapeStringRegexp(str) {
332
409
  if (typeof str !== "string") throw new TypeError("Expected a string");
package/dist/package.js CHANGED
@@ -2,7 +2,7 @@
2
2
  var require_package = /* @__PURE__ */ require("./_virtual/_rolldown/runtime.js").__commonJSMin(((exports, module) => {
3
3
  module.exports = {
4
4
  "name": "@vsaas/loopback-datasource-juggler",
5
- "version": "11.2.0",
5
+ "version": "12.0.0",
6
6
  "description": "Fork of loopback-datasource-juggler for LoopBack 3 style applications",
7
7
  "keywords": [
8
8
  "Connector",
@@ -81,7 +81,7 @@ var require_package = /* @__PURE__ */ require("./_virtual/_rolldown/runtime.js")
81
81
  "typescript": "catalog:",
82
82
  "vitest": "catalog:"
83
83
  },
84
- "engines": { "node": ">=20" }
84
+ "engines": { "node": ">=24" }
85
85
  };
86
86
  }));
87
87
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vsaas/loopback-datasource-juggler",
3
- "version": "11.2.0",
3
+ "version": "12.0.0",
4
4
  "description": "Fork of loopback-datasource-juggler for LoopBack 3 style applications",
5
5
  "keywords": [
6
6
  "Connector",
@@ -56,8 +56,8 @@
56
56
  "inflection": "^3.0.2",
57
57
  "minimatch": "10.2.4",
58
58
  "neotraverse": "^0.6.18",
59
- "qs": "6.15.0",
60
- "@vsaas/loopback-connector": "^11.0.3"
59
+ "qs": "^6.15.2",
60
+ "@vsaas/loopback-connector": "^12.0.0"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@types/node": "25.5.0",
@@ -71,7 +71,7 @@
71
71
  "loopback-connector-throwing": "1.0.0"
72
72
  },
73
73
  "engines": {
74
- "node": ">=20"
74
+ "node": ">=24"
75
75
  },
76
76
  "scripts": {
77
77
  "build": "tsdown",
@@ -3,7 +3,7 @@
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
5
5
 
6
- import { Callback, Options, PromiseOrVoid } from './common';
6
+ import { Callback, Options, PromiseOrVoid } from "./common";
7
7
 
8
8
  /**
9
9
  * This class provides methods that add validation cababilities to models.
@@ -196,11 +196,18 @@ export interface Validatable {
196
196
  * @property {String} message Optional error message if property is not valid. Default error message: " is invalid".
197
197
  * @property {Boolean} allowNull Whether null values are allowed.
198
198
  */
199
- validate(propertyName: string, validatorFn: Function, options?: Options): void;
199
+ validate(
200
+ propertyName: string,
201
+ validatorFn: Function,
202
+ options?: Options,
203
+ ): void;
200
204
 
201
205
  /**
202
206
  * Validate using custom asynchronous validation function.
203
207
  *
208
+ * The validator uses the callback-style signature `(err, done)` or
209
+ * `(err, options, done)`.
210
+ *
204
211
  * Example:
205
212
  *```js
206
213
  * User.validateAsync('name', customValidator, {message: 'Bad name'});
@@ -228,7 +235,47 @@ export interface Validatable {
228
235
  * @property {String} message Optional error message if property is not valid. Default error message: " is invalid".
229
236
  * @property {Boolean} allowNull Whether null values are allowed.
230
237
  */
231
- validateAsync(propertyName: string, validatorFn: Function, options?: Options): void;
238
+ validateAsync(
239
+ propertyName: string,
240
+ validatorFn: Function,
241
+ options?: Options,
242
+ ): void;
243
+
244
+ /**
245
+ * Validate using a custom promise-based validation function.
246
+ *
247
+ * The validator receives validation options as its first argument and should
248
+ * either resolve when valid or throw/reject when invalid.
249
+ *
250
+ * Example:
251
+ *```js
252
+ * User.validatePromise('name', async function(options) {
253
+ * await Promise.resolve();
254
+ * if (this.name === 'bad') {
255
+ * throw new Error('Bad name');
256
+ * }
257
+ * });
258
+ * var user = new User({name: 'Peter'});
259
+ * user.isValid(function (isValid) {
260
+ * isValid; // true
261
+ * })
262
+ * user.name = 'bad';
263
+ * user.isValid(function (isValid) {
264
+ * isValid; // false
265
+ * })
266
+ * ```
267
+ *
268
+ * @param {String} propertyName Property name to validate.
269
+ * @param {Function} validatorFn Custom validation function.
270
+ * @options {Object} options Configuration parameters; see below.
271
+ * @property {String} message Optional error message if property is not valid. Default error message: " is invalid".
272
+ * @property {Boolean} allowNull Whether null values are allowed.
273
+ */
274
+ validatePromise(
275
+ propertyName: string,
276
+ validatorFn: Function,
277
+ options?: Options,
278
+ ): void;
232
279
 
233
280
  /**
234
281
  * Validate uniqueness of the value for a property in the collection of models.
@@ -257,7 +304,11 @@ export interface Validatable {
257
304
  * @property {String} if Validate only if `if` exists.
258
305
  * @property {String} unless Validate only if `unless` exists.
259
306
  */
260
- validatesUniquenessOf(propertyName: string, validatorFn: Function, options?: Options): void;
307
+ validatesUniquenessOf(
308
+ propertyName: string,
309
+ validatorFn: Function,
310
+ options?: Options,
311
+ ): void;
261
312
 
262
313
  /**
263
314
  * Validate if a value for a property is a Date.
@@ -271,7 +322,11 @@ export interface Validatable {
271
322
  * @options {Object} options Configuration parameters; see below.
272
323
  * @property {String} message Error message to use instead of default.
273
324
  */
274
- validatesDateOf(propertyName: string, validatorFn: Function, options?: Options): void;
325
+ validatesDateOf(
326
+ propertyName: string,
327
+ validatorFn: Function,
328
+ options?: Options,
329
+ ): void;
275
330
  }
276
331
 
277
332
  /**