@vsaas/loopback-datasource-juggler 13.0.3 → 13.1.1
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/LICENSE +0 -0
- package/NOTICE +0 -0
- package/dist/_virtual/_rolldown/runtime.js +2 -3
- package/dist/index.js +7 -6
- package/dist/lib/browser.depd.js +1 -2
- package/dist/lib/case-utils.js +1 -2
- package/dist/lib/connectors/kv-memory.js +1 -2
- package/dist/lib/connectors/memory.js +1 -2
- package/dist/lib/connectors/transient.js +1 -2
- package/dist/lib/dao.js +23 -13
- package/dist/lib/datasource.js +9 -10
- package/dist/lib/date-string.js +1 -2
- package/dist/lib/geo.js +1 -2
- package/dist/lib/globalize.js +1 -2
- package/dist/lib/hooks.js +1 -2
- package/dist/lib/id-utils.js +1 -2
- package/dist/lib/include.js +1 -2
- package/dist/lib/include_utils.js +1 -2
- package/dist/lib/introspection.js +1 -2
- package/dist/lib/jutil.js +1 -2
- package/dist/lib/kvao/delete-all.js +1 -2
- package/dist/lib/kvao/delete.js +1 -2
- package/dist/lib/kvao/expire.js +1 -2
- package/dist/lib/kvao/get.js +1 -2
- package/dist/lib/kvao/index.js +1 -2
- package/dist/lib/kvao/iterate-keys.js +1 -2
- package/dist/lib/kvao/keys.js +1 -2
- package/dist/lib/kvao/set.js +1 -2
- package/dist/lib/kvao/ttl.js +1 -2
- package/dist/lib/list.js +1 -2
- package/dist/lib/mixins.js +1 -2
- package/dist/lib/model-builder.js +19 -7
- package/dist/lib/model-definition.js +2 -3
- package/dist/lib/model-internals.js +1 -2
- package/dist/lib/model-utils.js +13 -3
- package/dist/lib/model.js +2 -3
- package/dist/lib/normalizers.js +190 -0
- package/dist/lib/observer.js +1 -2
- package/dist/lib/property-constraints.js +166 -0
- package/dist/lib/relation-definition.js +4 -5
- package/dist/lib/relations.js +1 -2
- package/dist/lib/scope.js +1 -2
- package/dist/lib/transaction.js +3 -4
- package/dist/lib/types.js +1 -2
- package/dist/lib/utils.js +4 -5
- package/dist/lib/validations.js +35 -2
- package/dist/package.js +3 -4
- package/package.json +11 -11
- package/types/inclusion-mixin.d.ts +0 -0
- package/types/kv-model.d.ts +0 -0
- package/types/model.d.ts +64 -0
- package/types/query.d.ts +0 -0
- package/types/relation-mixin.d.ts +0 -0
- package/types/relation.d.ts +0 -0
- package/types/scope.d.ts +0 -0
- package/types/transaction-mixin.d.ts +0 -0
- package/types/validation-mixin.d.ts +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const require_runtime = require("../_virtual/_rolldown/runtime.js");
|
|
3
|
-
const require_lib_types = require("./types.js");
|
|
4
3
|
const require_lib_model = require("./model.js");
|
|
5
4
|
const require_lib_model_builder = require("./model-builder.js");
|
|
6
|
-
|
|
5
|
+
const require_lib_types = require("./types.js");
|
|
6
|
+
// src/lib/model-definition.ts
|
|
7
7
|
var require_model_definition = /* @__PURE__ */ require_runtime.__commonJSMin(((exports, module) => {
|
|
8
8
|
const assert = require("assert");
|
|
9
9
|
const util = require("util");
|
|
@@ -229,5 +229,4 @@ var require_model_definition = /* @__PURE__ */ require_runtime.__commonJSMin(((e
|
|
|
229
229
|
return this.ids().length > 0;
|
|
230
230
|
};
|
|
231
231
|
}));
|
|
232
|
-
//#endregion
|
|
233
232
|
module.exports = require_model_definition();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
// src/lib/model-internals.ts
|
|
3
3
|
var require_model_internals = /* @__PURE__ */ require("../_virtual/_rolldown/runtime.js").__commonJSMin(((exports, module) => {
|
|
4
4
|
const outerFrames = [];
|
|
5
5
|
let activeInstance;
|
|
@@ -37,5 +37,4 @@ var require_model_internals = /* @__PURE__ */ require("../_virtual/_rolldown/run
|
|
|
37
37
|
getNestedModelOptions
|
|
38
38
|
};
|
|
39
39
|
}));
|
|
40
|
-
//#endregion
|
|
41
40
|
module.exports = require_model_internals();
|
package/dist/lib/model-utils.js
CHANGED
|
@@ -3,7 +3,8 @@ const require_lib_globalize = require("./globalize.js");
|
|
|
3
3
|
const require_lib_geo = require("./geo.js");
|
|
4
4
|
const require_lib_utils = require("./utils.js");
|
|
5
5
|
require("./model.js");
|
|
6
|
-
|
|
6
|
+
const require_lib_normalizers = require("./normalizers.js");
|
|
7
|
+
// src/lib/model-utils.ts
|
|
7
8
|
var require_model_utils = /* @__PURE__ */ require_runtime.__commonJSMin(((exports, module) => {
|
|
8
9
|
module.exports = ModelUtils;
|
|
9
10
|
/*!
|
|
@@ -12,6 +13,14 @@ var require_model_utils = /* @__PURE__ */ require_runtime.__commonJSMin(((export
|
|
|
12
13
|
const g = require_lib_globalize();
|
|
13
14
|
const geo = require_lib_geo;
|
|
14
15
|
const { fieldsToArray, sanitizeQuery: sanitizeQueryOrData, isPlainObject, isClass, toRegExp } = require_lib_utils;
|
|
16
|
+
const { getNormalizer, normalizeValue } = require_lib_normalizers;
|
|
17
|
+
const NORMALIZED_OPERATORS = /* @__PURE__ */ new Set([
|
|
18
|
+
null,
|
|
19
|
+
"eq",
|
|
20
|
+
"neq",
|
|
21
|
+
"inq",
|
|
22
|
+
"nin"
|
|
23
|
+
]);
|
|
15
24
|
/**
|
|
16
25
|
* A mixin to contain utility methods for DataAccessObject
|
|
17
26
|
*/
|
|
@@ -250,7 +259,7 @@ var require_model_utils = /* @__PURE__ */ require_runtime.__commonJSMin(((export
|
|
|
250
259
|
err.statusCode = 400;
|
|
251
260
|
throw err;
|
|
252
261
|
}
|
|
253
|
-
for (let k = 0; k < clauses.length; k++) self._coerce(clauses[k], options);
|
|
262
|
+
for (let k = 0; k < clauses.length; k++) self._coerce(clauses[k], options, modelDef);
|
|
254
263
|
where[p] = clauses;
|
|
255
264
|
continue;
|
|
256
265
|
}
|
|
@@ -343,6 +352,8 @@ var require_model_utils = /* @__PURE__ */ require_runtime.__commonJSMin(((export
|
|
|
343
352
|
} else val = isClass(DataType) ? new DataType(val) : DataType(val);
|
|
344
353
|
}
|
|
345
354
|
}
|
|
355
|
+
const normalize = getNormalizer(props[p]);
|
|
356
|
+
if (normalize !== void 0 && NORMALIZED_OPERATORS.has(operator)) val = normalizeValue(val, normalize);
|
|
346
357
|
if (operator && operator !== "eq") {
|
|
347
358
|
const value = {};
|
|
348
359
|
value[operator] = val;
|
|
@@ -365,5 +376,4 @@ var require_model_utils = /* @__PURE__ */ require_runtime.__commonJSMin(((export
|
|
|
365
376
|
return propType.hasOwnProperty("definition") && propType.definition.hasOwnProperty("properties");
|
|
366
377
|
}
|
|
367
378
|
}));
|
|
368
|
-
//#endregion
|
|
369
379
|
module.exports = require_model_utils();
|
package/dist/lib/model.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
const require_runtime = require("../_virtual/_rolldown/runtime.js");
|
|
2
2
|
const require_lib_globalize = require("./globalize.js");
|
|
3
3
|
const require_lib_jutil = require("./jutil.js");
|
|
4
|
-
const require_lib_utils = require("./utils.js");
|
|
5
4
|
const require_lib_list = require("./list.js");
|
|
6
5
|
const require_lib_model_utils = require("./model-utils.js");
|
|
7
6
|
const require_lib_observer = require("./observer.js");
|
|
8
7
|
const require_lib_hooks = require("./hooks.js");
|
|
9
8
|
const require_lib_validations = require("./validations.js");
|
|
9
|
+
const require_lib_utils = require("./utils.js");
|
|
10
10
|
const require_lib_id_utils = require("./id-utils.js");
|
|
11
11
|
const require_lib_model_internals = require("./model-internals.js");
|
|
12
|
-
|
|
12
|
+
// src/lib/model.ts
|
|
13
13
|
var require_model = /* @__PURE__ */ require_runtime.__commonJSMin(((exports, module) => {
|
|
14
14
|
/*!
|
|
15
15
|
* Module exports class Model
|
|
@@ -641,5 +641,4 @@ var require_model = /* @__PURE__ */ require_runtime.__commonJSMin(((exports, mod
|
|
|
641
641
|
jutil.mixin(ModelBaseClass, Hookable);
|
|
642
642
|
jutil.mixin(ModelBaseClass, validations.Validatable);
|
|
643
643
|
}));
|
|
644
|
-
//#endregion
|
|
645
644
|
module.exports = require_model();
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.js");
|
|
3
|
+
const require_lib_globalize = require("./globalize.js");
|
|
4
|
+
// src/lib/normalizers.ts
|
|
5
|
+
var require_normalizers = /* @__PURE__ */ require_runtime.__commonJSMin(((exports, module) => {
|
|
6
|
+
/*!
|
|
7
|
+
* Property normalizers rewrite string values before validation and persistence.
|
|
8
|
+
*
|
|
9
|
+
* A property opts in with `normalize: 'trim'` or an ordered list such as
|
|
10
|
+
* `normalize: ['trim', 'lowercase']`. Entries are names from the registry below
|
|
11
|
+
* or inline functions. Each step receives a string and returns a string, or
|
|
12
|
+
* null/undefined to stop the pipeline and store that value instead.
|
|
13
|
+
*/
|
|
14
|
+
const g = require_lib_globalize();
|
|
15
|
+
const INVISIBLE_CHARS = /[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F-\u009F\u00AD\u200B\u202A-\u202E\u2060\u2066-\u2069\uFEFF]/g;
|
|
16
|
+
const COMBINING_MARKS = /\p{Mn}/gu;
|
|
17
|
+
const NON_DIGITS = /\P{Nd}/gu;
|
|
18
|
+
const NON_ALPHANUMERIC = /[^\p{L}\p{Nd}]/gu;
|
|
19
|
+
const WHITESPACE_RUNS = /\s+/g;
|
|
20
|
+
const TAG_START = /[A-Za-z/!?]/;
|
|
21
|
+
const RAW_TEXT_TAG = /^<(script|style)[\s/>]/i;
|
|
22
|
+
const SCRIPT_CLOSE = /<\/script[^>]*(?:>|$)/gi;
|
|
23
|
+
const STYLE_CLOSE = /<\/style[^>]*(?:>|$)/gi;
|
|
24
|
+
const registry = Object.create(null);
|
|
25
|
+
registry.trim = (s) => s.trim();
|
|
26
|
+
registry.lowercase = (s) => s.toLowerCase();
|
|
27
|
+
registry.uppercase = (s) => s.toUpperCase();
|
|
28
|
+
registry.nfc = (s) => s.normalize("NFC");
|
|
29
|
+
registry.unaccent = (s) => s.normalize("NFD").replace(COMBINING_MARKS, "").normalize("NFC");
|
|
30
|
+
registry.collapseSpaces = (s) => s.replace(WHITESPACE_RUNS, " ");
|
|
31
|
+
registry.emptyToNull = (s) => s === "" ? null : s;
|
|
32
|
+
registry.stripInvisible = (s) => s.replace(INVISIBLE_CHARS, "");
|
|
33
|
+
registry.numeric = (s) => s.replace(NON_DIGITS, "");
|
|
34
|
+
registry.alphanumeric = (s) => s.replace(NON_ALPHANUMERIC, "");
|
|
35
|
+
registry.stripHtml = stripHtml;
|
|
36
|
+
/**
|
|
37
|
+
* Remove markup and keep the text, without decoding or escaping entities.
|
|
38
|
+
* Comments, doctypes, processing instructions and tags are dropped; script and
|
|
39
|
+
* style elements are dropped with their content. A `<` that does not start
|
|
40
|
+
* markup is kept as text, except when removing a tag would join it to the next
|
|
41
|
+
* character, so the output never contains markup and a second pass is a no-op.
|
|
42
|
+
* Runs in linear time.
|
|
43
|
+
*/
|
|
44
|
+
function stripHtml(s) {
|
|
45
|
+
if (s.indexOf("<") === -1) return s;
|
|
46
|
+
let hasGt = true;
|
|
47
|
+
let hasCommentEnd = true;
|
|
48
|
+
function markupEnd(lt) {
|
|
49
|
+
if (hasCommentEnd && s.startsWith("<!--", lt)) {
|
|
50
|
+
const close = s.indexOf("-->", lt + 2);
|
|
51
|
+
if (close !== -1) return close + 3;
|
|
52
|
+
hasCommentEnd = false;
|
|
53
|
+
}
|
|
54
|
+
const gt = hasGt ? s.indexOf(">", lt + 1) : -1;
|
|
55
|
+
if (gt === -1) {
|
|
56
|
+
hasGt = false;
|
|
57
|
+
return -1;
|
|
58
|
+
}
|
|
59
|
+
const raw = RAW_TEXT_TAG.exec(s.slice(lt, Math.min(gt + 1, lt + 8)));
|
|
60
|
+
if (raw) {
|
|
61
|
+
const closeTag = raw[1].toLowerCase() === "script" ? SCRIPT_CLOSE : STYLE_CLOSE;
|
|
62
|
+
closeTag.lastIndex = gt + 1;
|
|
63
|
+
const close = closeTag.exec(s);
|
|
64
|
+
return close ? close.index + close[0].length : s.length;
|
|
65
|
+
}
|
|
66
|
+
return gt + 1;
|
|
67
|
+
}
|
|
68
|
+
let out = "";
|
|
69
|
+
let i = 0;
|
|
70
|
+
while (i < s.length) {
|
|
71
|
+
const lt = s.indexOf("<", i);
|
|
72
|
+
if (lt === -1) {
|
|
73
|
+
out += s.slice(i);
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
out += s.slice(i, lt);
|
|
77
|
+
const end = TAG_START.test(s.charAt(lt + 1)) ? markupEnd(lt) : -1;
|
|
78
|
+
if (end === -1) {
|
|
79
|
+
out += "<";
|
|
80
|
+
i = lt + 1;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
let keep = out.length;
|
|
84
|
+
while (keep > 0 && out.charCodeAt(keep - 1) === 60) keep--;
|
|
85
|
+
out = out.slice(0, keep);
|
|
86
|
+
i = end;
|
|
87
|
+
}
|
|
88
|
+
return out;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Register a named normalizer usable from property definitions.
|
|
92
|
+
* Register before defining the models that reference it.
|
|
93
|
+
* @param {String} name Normalizer name
|
|
94
|
+
* @param {Function} fn `(value: string) => string | null | undefined`
|
|
95
|
+
*/
|
|
96
|
+
function registerNormalizer(name, fn) {
|
|
97
|
+
if (typeof name !== "string" || !name) throw new TypeError(g.f("Normalizer name must be a non-empty string"));
|
|
98
|
+
if (typeof fn !== "function") throw new TypeError(g.f("Normalizer \"%s\" must be a function", name));
|
|
99
|
+
if (registry[name]) throw new Error(g.f("Normalizer \"%s\" is already registered", name));
|
|
100
|
+
registry[name] = fn;
|
|
101
|
+
}
|
|
102
|
+
const compiled = /* @__PURE__ */ new WeakMap();
|
|
103
|
+
/**
|
|
104
|
+
* Get the compiled normalizer of a built property definition.
|
|
105
|
+
* Throws when the definition references an unknown normalizer or is applied to
|
|
106
|
+
* a non-string property.
|
|
107
|
+
* @param {Object} property Built property definition (with resolved `type`)
|
|
108
|
+
* @param {String} [label] `Model.property`, used in error messages
|
|
109
|
+
* @returns {Function|undefined}
|
|
110
|
+
*/
|
|
111
|
+
function getNormalizer(property, label) {
|
|
112
|
+
if (property == null || property.normalize == null || property.normalize === false) return;
|
|
113
|
+
let fn = compiled.get(property);
|
|
114
|
+
if (fn === void 0) {
|
|
115
|
+
fn = compile(property, label);
|
|
116
|
+
compiled.set(property, fn);
|
|
117
|
+
}
|
|
118
|
+
return fn || void 0;
|
|
119
|
+
}
|
|
120
|
+
function compile(property, label = "property") {
|
|
121
|
+
const spec = property.normalize;
|
|
122
|
+
const entries = Array.isArray(spec) ? spec : [spec];
|
|
123
|
+
if (!isStringType(property.type)) throw new Error(g.f("{{normalize}} is only supported on string properties, %s is not a string", label));
|
|
124
|
+
const steps = entries.map(function(entry) {
|
|
125
|
+
if (typeof entry === "function") return entry;
|
|
126
|
+
const step = typeof entry === "string" && registry[entry];
|
|
127
|
+
if (!step) throw new Error(g.f("Unknown normalizer %j for %s", entry, label));
|
|
128
|
+
return step;
|
|
129
|
+
});
|
|
130
|
+
if (steps.length === 0) return null;
|
|
131
|
+
if (steps.length === 1) return steps[0];
|
|
132
|
+
return function normalize(value) {
|
|
133
|
+
let result = value;
|
|
134
|
+
for (let i = 0; i < steps.length; i++) {
|
|
135
|
+
result = steps[i](result);
|
|
136
|
+
if (typeof result !== "string") return result;
|
|
137
|
+
}
|
|
138
|
+
return result;
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Apply a compiled normalizer to a string, or in place to the string items of
|
|
143
|
+
* an array. Other values are returned unchanged.
|
|
144
|
+
*/
|
|
145
|
+
function normalizeValue(value, normalize) {
|
|
146
|
+
if (typeof value === "string") return normalize(value);
|
|
147
|
+
if (Array.isArray(value)) {
|
|
148
|
+
for (let i = 0; i < value.length; i++) if (typeof value[i] === "string") value[i] = normalize(value[i]);
|
|
149
|
+
}
|
|
150
|
+
return value;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Normalize a plain data object in place, following embedded model
|
|
154
|
+
* definitions. Used where a write persists a data snapshot instead of the
|
|
155
|
+
* instance it validated.
|
|
156
|
+
* @param {Function} Model Model class owning `data`
|
|
157
|
+
* @param {Object} data Plain data keyed by property name
|
|
158
|
+
* @returns {Object} The same `data` object
|
|
159
|
+
*/
|
|
160
|
+
function normalizeData(Model, data) {
|
|
161
|
+
const properties = Model.definition.properties;
|
|
162
|
+
for (const key in data) {
|
|
163
|
+
const value = data[key];
|
|
164
|
+
const property = properties[key];
|
|
165
|
+
if (value == null || property === void 0) continue;
|
|
166
|
+
const normalize = getNormalizer(property);
|
|
167
|
+
if (normalize !== void 0) {
|
|
168
|
+
data[key] = normalizeValue(value, normalize);
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
const type = Array.isArray(property.type) ? property.type[0] : property.type;
|
|
172
|
+
if (typeof value !== "object" || !type || !type.definition) continue;
|
|
173
|
+
if (Array.isArray(value)) {
|
|
174
|
+
for (const item of value) if (item !== null && typeof item === "object") normalizeData(type, item);
|
|
175
|
+
} else normalizeData(type, value);
|
|
176
|
+
}
|
|
177
|
+
return data;
|
|
178
|
+
}
|
|
179
|
+
function isStringType(type) {
|
|
180
|
+
if (Array.isArray(type)) return type.length === 1 && type[0] === String;
|
|
181
|
+
return type === String;
|
|
182
|
+
}
|
|
183
|
+
module.exports = {
|
|
184
|
+
getNormalizer,
|
|
185
|
+
normalizeData,
|
|
186
|
+
normalizeValue,
|
|
187
|
+
registerNormalizer
|
|
188
|
+
};
|
|
189
|
+
}));
|
|
190
|
+
module.exports = require_normalizers();
|
package/dist/lib/observer.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const require_runtime = require("../_virtual/_rolldown/runtime.js");
|
|
3
3
|
const require_lib_utils = require("./utils.js");
|
|
4
|
-
|
|
4
|
+
// src/lib/observer.ts
|
|
5
5
|
var require_observer = /* @__PURE__ */ require_runtime.__commonJSMin(((exports, module) => {
|
|
6
6
|
const utils = require_lib_utils;
|
|
7
7
|
const debug = require("debug")("loopback:observer");
|
|
@@ -274,5 +274,4 @@ var require_observer = /* @__PURE__ */ require_runtime.__commonJSMin(((exports,
|
|
|
274
274
|
});
|
|
275
275
|
};
|
|
276
276
|
}));
|
|
277
|
-
//#endregion
|
|
278
277
|
module.exports = require_observer();
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.js");
|
|
3
|
+
const require_lib_globalize = require("./globalize.js");
|
|
4
|
+
// src/lib/property-constraints.ts
|
|
5
|
+
var require_property_constraints = /* @__PURE__ */ require_runtime.__commonJSMin(((exports, module) => {
|
|
6
|
+
/*!
|
|
7
|
+
* Declarative property constraints, using the JSON Schema keywords that
|
|
8
|
+
* loopback-swagger already publishes for a property:
|
|
9
|
+
*
|
|
10
|
+
* - strings: `minLength`, `maxLength` (Unicode characters), `pattern`, `format`
|
|
11
|
+
* - numbers: `minimum`/`min`, `maximum`/`max`
|
|
12
|
+
* - any primitive: `enum`
|
|
13
|
+
* - arrays: `minItems`, `maxItems`; the other keywords apply to each item
|
|
14
|
+
*
|
|
15
|
+
* Constraints only apply to present values. `null` and `undefined` pass;
|
|
16
|
+
* `required` decides whether a value must be present.
|
|
17
|
+
*/
|
|
18
|
+
const g = require_lib_globalize();
|
|
19
|
+
const EMAIL = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
|
20
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
21
|
+
const URI_SCHEME = /^[a-z][a-z0-9+.-]*:/i;
|
|
22
|
+
const FORMATS = {
|
|
23
|
+
email: {
|
|
24
|
+
check: (s) => EMAIL.test(s),
|
|
25
|
+
message: "is not a valid email address"
|
|
26
|
+
},
|
|
27
|
+
uri: {
|
|
28
|
+
check: isUri,
|
|
29
|
+
message: "is not a valid URI"
|
|
30
|
+
},
|
|
31
|
+
uuid: {
|
|
32
|
+
check: (s) => UUID.test(s),
|
|
33
|
+
message: "is not a valid UUID"
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
function isUri(value) {
|
|
37
|
+
if (!URI_SCHEME.test(value)) return false;
|
|
38
|
+
try {
|
|
39
|
+
new URL(value);
|
|
40
|
+
return true;
|
|
41
|
+
} catch {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function plural(count, noun) {
|
|
46
|
+
return `${count} ${noun}${count === 1 ? "" : "s"}`;
|
|
47
|
+
}
|
|
48
|
+
function exceedsLength(value, max) {
|
|
49
|
+
if (value.length <= max) return false;
|
|
50
|
+
let count = 0;
|
|
51
|
+
for (const _ of value) if (++count > max) return true;
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
function shorterThan(value, min) {
|
|
55
|
+
if (value.length < min) return true;
|
|
56
|
+
let count = 0;
|
|
57
|
+
for (const _ of value) if (++count >= min) return false;
|
|
58
|
+
return count < min;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Compile the constraints declared on a built property definition.
|
|
62
|
+
* Throws when a keyword does not fit the property type or has an invalid value.
|
|
63
|
+
* @param {Object} property Built property definition (with resolved `type`)
|
|
64
|
+
* @param {String} label `Model.property`, used in error messages
|
|
65
|
+
* @returns {Array} Constraints with `check(value)`, `code` and `message`
|
|
66
|
+
*/
|
|
67
|
+
function getPropertyConstraints(property, label) {
|
|
68
|
+
if (property == null || typeof property !== "object") return [];
|
|
69
|
+
const isArray = Array.isArray(property.type) || property.type === Array;
|
|
70
|
+
const itemType = Array.isArray(property.type) ? property.type[0] : isArray ? void 0 : property.type;
|
|
71
|
+
const constraints = [];
|
|
72
|
+
function invalid(message, ...args) {
|
|
73
|
+
return new Error(g.f("Invalid constraint on %s: " + message, label, ...args));
|
|
74
|
+
}
|
|
75
|
+
function count(keyword) {
|
|
76
|
+
const value = property[keyword];
|
|
77
|
+
if (!Number.isSafeInteger(value) || value < 0) throw invalid("{{%s}} must be a non-negative integer", keyword);
|
|
78
|
+
return value;
|
|
79
|
+
}
|
|
80
|
+
function limit(keyword, alias) {
|
|
81
|
+
const value = property[keyword];
|
|
82
|
+
const aliased = property[alias];
|
|
83
|
+
if (value != null && aliased != null && value !== aliased) throw invalid("{{%s}} and {{%s}} disagree", keyword, alias);
|
|
84
|
+
const resolved = value != null ? value : aliased;
|
|
85
|
+
if (resolved == null) return void 0;
|
|
86
|
+
if (typeof resolved !== "number" || !Number.isFinite(resolved)) throw invalid("{{%s}} must be a finite number", value != null ? keyword : alias);
|
|
87
|
+
return resolved;
|
|
88
|
+
}
|
|
89
|
+
function requireItemType(keyword, type, typeName) {
|
|
90
|
+
if (itemType !== type) throw invalid("{{%s}} only applies to %s properties", keyword, typeName);
|
|
91
|
+
}
|
|
92
|
+
function add(code, message, check) {
|
|
93
|
+
constraints.push({
|
|
94
|
+
code,
|
|
95
|
+
message,
|
|
96
|
+
check: isArray ? (value) => !Array.isArray(value) || value.every((item) => item == null || check(item)) : check
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
if (property.minLength != null) {
|
|
100
|
+
requireItemType("minLength", String, "string");
|
|
101
|
+
const min = count("minLength");
|
|
102
|
+
add("length.min", `must contain at least ${plural(min, "character")}`, (v) => !shorterThan(v, min));
|
|
103
|
+
}
|
|
104
|
+
if (property.maxLength != null) {
|
|
105
|
+
requireItemType("maxLength", String, "string");
|
|
106
|
+
const max = count("maxLength");
|
|
107
|
+
add("length.max", `must contain no more than ${plural(max, "character")}`, (v) => !exceedsLength(v, max));
|
|
108
|
+
}
|
|
109
|
+
if (property.pattern != null) {
|
|
110
|
+
requireItemType("pattern", String, "string");
|
|
111
|
+
let regex;
|
|
112
|
+
try {
|
|
113
|
+
regex = property.pattern instanceof RegExp ? property.pattern : new RegExp(property.pattern);
|
|
114
|
+
} catch (err) {
|
|
115
|
+
throw invalid("{{pattern}} is not a valid regular expression: %s", err.message);
|
|
116
|
+
}
|
|
117
|
+
if (regex.global || regex.sticky) regex = new RegExp(regex.source, regex.flags.replace(/[gy]/g, ""));
|
|
118
|
+
add("format", "is invalid", (v) => regex.test(v));
|
|
119
|
+
}
|
|
120
|
+
if (property.format != null && FORMATS[property.format]) {
|
|
121
|
+
requireItemType("format", String, "string");
|
|
122
|
+
const format = FORMATS[property.format];
|
|
123
|
+
add("format." + property.format, format.message, format.check);
|
|
124
|
+
}
|
|
125
|
+
const minimum = limit("minimum", "min");
|
|
126
|
+
const maximum = limit("maximum", "max");
|
|
127
|
+
if (minimum !== void 0) {
|
|
128
|
+
requireItemType(property.minimum != null ? "minimum" : "min", Number, "number");
|
|
129
|
+
add("range.min", `must be greater than or equal to ${minimum}`, (v) => v >= minimum);
|
|
130
|
+
}
|
|
131
|
+
if (maximum !== void 0) {
|
|
132
|
+
requireItemType(property.maximum != null ? "maximum" : "max", Number, "number");
|
|
133
|
+
add("range.max", `must be less than or equal to ${maximum}`, (v) => v <= maximum);
|
|
134
|
+
}
|
|
135
|
+
if (property.enum != null) {
|
|
136
|
+
if (itemType !== String && itemType !== Number && itemType !== Boolean) throw invalid("{{enum}} only applies to string, number and boolean properties");
|
|
137
|
+
if (!Array.isArray(property.enum) || property.enum.length === 0) throw invalid("{{enum}} must be a non-empty array");
|
|
138
|
+
const itemTypeName = itemType.name.toLowerCase();
|
|
139
|
+
if (property.enum.some((value) => typeof value !== itemTypeName)) throw invalid("{{enum}} values must be of type %s", itemTypeName);
|
|
140
|
+
const allowed = new Set(property.enum);
|
|
141
|
+
add("inclusion", `must be one of: ${property.enum.join(", ")}`, (v) => allowed.has(v));
|
|
142
|
+
}
|
|
143
|
+
if (property.minItems != null || property.maxItems != null) {
|
|
144
|
+
if (!isArray) throw invalid("{{minItems}} and {{maxItems}} only apply to array properties");
|
|
145
|
+
}
|
|
146
|
+
if (property.minItems != null) {
|
|
147
|
+
const min = count("minItems");
|
|
148
|
+
constraints.push({
|
|
149
|
+
code: "items.min",
|
|
150
|
+
message: `must contain at least ${plural(min, "item")}`,
|
|
151
|
+
check: (v) => !Array.isArray(v) || v.length >= min
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
if (property.maxItems != null) {
|
|
155
|
+
const max = count("maxItems");
|
|
156
|
+
constraints.push({
|
|
157
|
+
code: "items.max",
|
|
158
|
+
message: `must contain no more than ${plural(max, "item")}`,
|
|
159
|
+
check: (v) => !Array.isArray(v) || v.length <= max
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
return constraints;
|
|
163
|
+
}
|
|
164
|
+
module.exports = { getPropertyConstraints };
|
|
165
|
+
}));
|
|
166
|
+
module.exports = require_property_constraints();
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const require_runtime = require("../_virtual/_rolldown/runtime.js");
|
|
3
|
-
const require_lib_globalize = require("./globalize.js");
|
|
4
3
|
const require_lib_utils = require("./utils.js");
|
|
5
|
-
const require_lib_validations = require("./validations.js");
|
|
6
|
-
const require_lib_model = require("./model.js");
|
|
7
4
|
const require_lib_scope = require("./scope.js");
|
|
5
|
+
const require_lib_globalize = require("./globalize.js");
|
|
6
|
+
const require_lib_model = require("./model.js");
|
|
8
7
|
const require_lib_connectors_memory = require("./connectors/memory.js");
|
|
9
|
-
|
|
8
|
+
const require_lib_validations = require("./validations.js");
|
|
9
|
+
// src/lib/relation-definition.ts
|
|
10
10
|
var require_relation_definition = /* @__PURE__ */ require_runtime.__commonJSMin(((exports) => {
|
|
11
11
|
/*!
|
|
12
12
|
* Dependencies
|
|
@@ -2733,5 +2733,4 @@ var require_relation_definition = /* @__PURE__ */ require_runtime.__commonJSMin(
|
|
|
2733
2733
|
return cb.promise;
|
|
2734
2734
|
};
|
|
2735
2735
|
}));
|
|
2736
|
-
//#endregion
|
|
2737
2736
|
module.exports = require_relation_definition();
|
package/dist/lib/relations.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const require_runtime = require("../_virtual/_rolldown/runtime.js");
|
|
3
3
|
const require_lib_relation_definition = require("./relation-definition.js");
|
|
4
|
-
|
|
4
|
+
// src/lib/relations.ts
|
|
5
5
|
var require_relations = /* @__PURE__ */ require_runtime.__commonJSMin(((exports, module) => {
|
|
6
6
|
/*!
|
|
7
7
|
* Dependencies
|
|
@@ -590,5 +590,4 @@ var require_relations = /* @__PURE__ */ require_runtime.__commonJSMin(((exports,
|
|
|
590
590
|
return RelationDefinition.embedsMany(this, modelTo, params);
|
|
591
591
|
};
|
|
592
592
|
}));
|
|
593
|
-
//#endregion
|
|
594
593
|
module.exports = require_relations();
|
package/dist/lib/scope.js
CHANGED
|
@@ -3,7 +3,7 @@ const require_runtime = require("../_virtual/_rolldown/runtime.js");
|
|
|
3
3
|
const require_lib_globalize = require("./globalize.js");
|
|
4
4
|
const require_lib_utils = require("./utils.js");
|
|
5
5
|
const require_lib_model = require("./model.js");
|
|
6
|
-
|
|
6
|
+
// src/lib/scope.ts
|
|
7
7
|
var require_scope = /* @__PURE__ */ require_runtime.__commonJSMin(((exports) => {
|
|
8
8
|
const i8n = require("inflection");
|
|
9
9
|
const g = require_lib_globalize();
|
|
@@ -408,5 +408,4 @@ var require_scope = /* @__PURE__ */ require_runtime.__commonJSMin(((exports) =>
|
|
|
408
408
|
return definition;
|
|
409
409
|
}
|
|
410
410
|
}));
|
|
411
|
-
//#endregion
|
|
412
411
|
module.exports = require_scope();
|
package/dist/lib/transaction.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const require_runtime = require("../_virtual/_rolldown/runtime.js");
|
|
3
3
|
const require_lib_globalize = require("./globalize.js");
|
|
4
|
-
const
|
|
4
|
+
const require_lib_id_utils = require("./id-utils.js");
|
|
5
5
|
const require_lib_utils = require("./utils.js");
|
|
6
|
+
const require_lib_jutil = require("./jutil.js");
|
|
6
7
|
const require_lib_observer = require("./observer.js");
|
|
7
|
-
|
|
8
|
-
//#region src/lib/transaction.ts
|
|
8
|
+
// src/lib/transaction.ts
|
|
9
9
|
var require_transaction = /* @__PURE__ */ require_runtime.__commonJSMin(((exports, module) => {
|
|
10
10
|
const g = require_lib_globalize();
|
|
11
11
|
const debug = require("debug")("loopback:connector:transaction");
|
|
@@ -179,5 +179,4 @@ var require_transaction = /* @__PURE__ */ require_runtime.__commonJSMin(((export
|
|
|
179
179
|
}
|
|
180
180
|
TransactionMixin.Transaction = Transaction;
|
|
181
181
|
}));
|
|
182
|
-
//#endregion
|
|
183
182
|
module.exports = require_transaction();
|
package/dist/lib/types.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
const require_runtime = require("../_virtual/_rolldown/runtime.js");
|
|
3
3
|
const require_lib_date_string = require("./date-string.js");
|
|
4
4
|
const require_lib_geo = require("./geo.js");
|
|
5
|
-
|
|
5
|
+
// src/lib/types.ts
|
|
6
6
|
var require_types = /* @__PURE__ */ require_runtime.__commonJSMin(((exports, module) => {
|
|
7
7
|
const Types = {};
|
|
8
8
|
/**
|
|
@@ -54,5 +54,4 @@ var require_types = /* @__PURE__ */ require_runtime.__commonJSMin(((exports, mod
|
|
|
54
54
|
};
|
|
55
55
|
module.exports.Types = Types;
|
|
56
56
|
}));
|
|
57
|
-
//#endregion
|
|
58
57
|
module.exports = require_types();
|
package/dist/lib/utils.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const require_runtime = require("../_virtual/_rolldown/runtime.js");
|
|
3
3
|
const require_lib_globalize = require("./globalize.js");
|
|
4
|
-
|
|
4
|
+
// src/lib/utils.ts
|
|
5
5
|
var require_utils = /* @__PURE__ */ require_runtime.__commonJSMin(((exports) => {
|
|
6
6
|
exports.safeRequire = safeRequire;
|
|
7
7
|
exports.fieldsToArray = fieldsToArray;
|
|
@@ -50,11 +50,11 @@ var require_utils = /* @__PURE__ */ require_runtime.__commonJSMin(((exports) =>
|
|
|
50
50
|
"nilike",
|
|
51
51
|
"regexp"
|
|
52
52
|
]);
|
|
53
|
-
function safeRequire(module
|
|
53
|
+
function safeRequire(module) {
|
|
54
54
|
try {
|
|
55
|
-
return require(module
|
|
55
|
+
return require(module);
|
|
56
56
|
} catch {
|
|
57
|
-
g.log("Run \"{{npm install loopback-datasource-juggler}} %s\" command ", "to use {{loopback-datasource-juggler}} using %s database engine", module
|
|
57
|
+
g.log("Run \"{{npm install loopback-datasource-juggler}} %s\" command ", "to use {{loopback-datasource-juggler}} using %s database engine", module, module);
|
|
58
58
|
process.exit(1);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
@@ -655,5 +655,4 @@ Although supported, this is not a recommended practice: ${element.constructor.na
|
|
|
655
655
|
});
|
|
656
656
|
}
|
|
657
657
|
}));
|
|
658
|
-
//#endregion
|
|
659
658
|
module.exports = require_utils();
|
package/dist/lib/validations.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const require_runtime = require("../_virtual/_rolldown/runtime.js");
|
|
3
3
|
const require_lib_globalize = require("./globalize.js");
|
|
4
|
-
|
|
4
|
+
// src/lib/validations.ts
|
|
5
5
|
var require_validations = /* @__PURE__ */ require_runtime.__commonJSMin(((exports) => {
|
|
6
6
|
const g = require_lib_globalize();
|
|
7
7
|
const util = require("util");
|
|
@@ -10,6 +10,8 @@ var require_validations = /* @__PURE__ */ require_runtime.__commonJSMin(((export
|
|
|
10
10
|
*/
|
|
11
11
|
exports.ValidationError = ValidationError;
|
|
12
12
|
exports.Validatable = Validatable;
|
|
13
|
+
exports.addPropertyConstraints = addPropertyConstraints;
|
|
14
|
+
exports.checkPropertyConstraints = checkPropertyConstraints;
|
|
13
15
|
/**
|
|
14
16
|
* This class provides methods that add validation cababilities to models.
|
|
15
17
|
* Each of the validations runs when the `obj.isValid()` method is called.
|
|
@@ -354,6 +356,37 @@ var require_validations = /* @__PURE__ */ require_runtime.__commonJSMin(((export
|
|
|
354
356
|
} else err();
|
|
355
357
|
}
|
|
356
358
|
/*!
|
|
359
|
+
* Declarative property constraint (see property-constraints.js). Only present
|
|
360
|
+
* values are checked; `required` handles presence.
|
|
361
|
+
*/
|
|
362
|
+
function validateConstraint(attr, conf, err, _options) {
|
|
363
|
+
const value = this[attr];
|
|
364
|
+
if (value != null && !conf.check(value)) err();
|
|
365
|
+
}
|
|
366
|
+
/*!
|
|
367
|
+
* Register compiled property constraints as validations of `attr`.
|
|
368
|
+
*/
|
|
369
|
+
function addPropertyConstraints(cls, attr, constraints) {
|
|
370
|
+
for (const constraint of constraints) configure(cls, "constraint", [attr, constraint]);
|
|
371
|
+
}
|
|
372
|
+
/*!
|
|
373
|
+
* Run only the property constraints of `attrs`, for partial writes that skip
|
|
374
|
+
* full validation. Fills `inst.errors` like isValid() and returns validity.
|
|
375
|
+
*/
|
|
376
|
+
function checkPropertyConstraints(inst, attrs) {
|
|
377
|
+
const validations = inst.constructor.validations || {};
|
|
378
|
+
const errors = new Errors();
|
|
379
|
+
let valid = true;
|
|
380
|
+
Object.defineProperty(inst, "errors", {
|
|
381
|
+
enumerable: false,
|
|
382
|
+
configurable: true,
|
|
383
|
+
value: errors
|
|
384
|
+
});
|
|
385
|
+
for (const attr of attrs) for (const conf of validations[attr] || []) if (conf.validation === "constraint" && validationFailed(inst, attr, conf, {})) valid = false;
|
|
386
|
+
if (valid) cleanErrors(inst);
|
|
387
|
+
return valid;
|
|
388
|
+
}
|
|
389
|
+
/*!
|
|
357
390
|
* Custom validator
|
|
358
391
|
*/
|
|
359
392
|
function validateCustom(attr, conf, err, options, done) {
|
|
@@ -451,6 +484,7 @@ var require_validations = /* @__PURE__ */ require_runtime.__commonJSMin(((export
|
|
|
451
484
|
exclusion: validateExclusion,
|
|
452
485
|
format: validateFormat,
|
|
453
486
|
custom: validateCustom,
|
|
487
|
+
constraint: validateConstraint,
|
|
454
488
|
uniqueness: validateUniqueness,
|
|
455
489
|
date: validateDate
|
|
456
490
|
};
|
|
@@ -817,5 +851,4 @@ var require_validations = /* @__PURE__ */ require_runtime.__commonJSMin(((export
|
|
|
817
851
|
return value.slice(0, len - 4) + "..." + tail;
|
|
818
852
|
}
|
|
819
853
|
}));
|
|
820
|
-
//#endregion
|
|
821
854
|
module.exports = require_validations();
|