@nhtio/validation 0.1.0-master-f8c72f13 → 0.1.0-master-649f9ed8
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/index.cjs +304 -28
- package/index.cjs.map +1 -1
- package/index.mjs +306 -30
- package/index.mjs.map +1 -1
- package/package.json +3 -2
- package/private/patches/knex.d.ts +6 -0
- package/private/utils.d.ts +82 -2
package/index.cjs
CHANGED
|
@@ -13870,7 +13870,7 @@ const knexMessages = {
|
|
|
13870
13870
|
"knex.internal": "Database validation error on {{#label}}"
|
|
13871
13871
|
};
|
|
13872
13872
|
const knexClientCache = new WeakMap();
|
|
13873
|
-
const isReference = (obj, root) => {
|
|
13873
|
+
const isReference$1 = (obj, root) => {
|
|
13874
13874
|
return root.isRef(obj);
|
|
13875
13875
|
};
|
|
13876
13876
|
const resolveKnex = (connection) => {
|
|
@@ -13917,9 +13917,26 @@ const getMergableMessages = (schema) => {
|
|
|
13917
13917
|
return {};
|
|
13918
13918
|
};
|
|
13919
13919
|
function setKnexConnection(connection) {
|
|
13920
|
-
if ("
|
|
13921
|
-
this.$_terms.keys
|
|
13922
|
-
|
|
13920
|
+
if ("undefined" !== typeof this.$_terms) {
|
|
13921
|
+
if ("keys" in this.$_terms && null !== this.$_terms.keys) this.$_terms.keys.forEach((item, index) => {
|
|
13922
|
+
this.$_terms.keys[index].schema = setKnexConnection.call(item.schema, connection);
|
|
13923
|
+
});
|
|
13924
|
+
if ("matches" in this.$_terms && null !== this.$_terms.matches) this.$_terms.matches = this.$_terms.matches.map((match$2) => {
|
|
13925
|
+
return {
|
|
13926
|
+
...match$2,
|
|
13927
|
+
schema: match$2.schema ? setKnexConnection.call(match$2.schema, connection) : void 0,
|
|
13928
|
+
switch: match$2.switch ? match$2.switch.map((branch) => ({
|
|
13929
|
+
is: branch.is ? setKnexConnection.call(branch.is, connection) : void 0,
|
|
13930
|
+
then: branch.then ? setKnexConnection.call(branch.then, connection) : void 0,
|
|
13931
|
+
else: branch.else ? setKnexConnection.call(branch.else, connection) : void 0
|
|
13932
|
+
})) : void 0
|
|
13933
|
+
};
|
|
13934
|
+
});
|
|
13935
|
+
if ("_exclusions" in this.$_terms && null !== this.$_terms._exclusions) this.$_terms._exclusions = this.$_terms._exclusions.map((exclusion) => setKnexConnection.call(exclusion, connection));
|
|
13936
|
+
if ("_inclusions" in this.$_terms && null !== this.$_terms._inclusions) this.$_terms._inclusions = this.$_terms._inclusions.map((inclusion) => setKnexConnection.call(inclusion, connection));
|
|
13937
|
+
if ("_requireds" in this.$_terms && null !== this.$_terms._requireds) this.$_terms._requireds = this.$_terms._requireds.map((required) => setKnexConnection.call(required, connection));
|
|
13938
|
+
if ("items" in this.$_terms && null !== this.$_terms.items) this.$_terms.items = this.$_terms.items.map((item) => setKnexConnection.call(item, connection));
|
|
13939
|
+
}
|
|
13923
13940
|
const toSet = this.$_knex || this.$_getFlag("knexConnection") || connection;
|
|
13924
13941
|
this.$_knex = toSet;
|
|
13925
13942
|
return this.$_setFlag("knexConnection", toSet);
|
|
@@ -13941,6 +13958,28 @@ const knex$1 = (schema, root, args$1) => {
|
|
|
13941
13958
|
const originalMessages = getMergableMessages(schema);
|
|
13942
13959
|
const mergedMessages = import_messages.merge(originalMessages, knexMessages);
|
|
13943
13960
|
prototype._definition.messages = mergedMessages;
|
|
13961
|
+
prototype._definition.flags.knexConnection = {
|
|
13962
|
+
default: void 0,
|
|
13963
|
+
setter: "knex"
|
|
13964
|
+
};
|
|
13965
|
+
prototype._definition.flags.knexFunctionArgs = {
|
|
13966
|
+
default: {},
|
|
13967
|
+
setter: "setKnexFunctionArgs"
|
|
13968
|
+
};
|
|
13969
|
+
if (!prototype.setKnexFunctionArgs) prototype.setKnexFunctionArgs = function(knexFunctionArgs) {
|
|
13970
|
+
return this.$_setFlag("knexFunctionArgs", knexFunctionArgs);
|
|
13971
|
+
};
|
|
13972
|
+
if (!prototype.setArgsForFnCall) prototype.setArgsForFnCall = function(id, knexFunctionArgs) {
|
|
13973
|
+
const currentArgs = this.$_getFlag("knexFunctionArgs") || {};
|
|
13974
|
+
knexFunctionArgs = {
|
|
13975
|
+
...currentArgs,
|
|
13976
|
+
[id]: knexFunctionArgs
|
|
13977
|
+
};
|
|
13978
|
+
return this.$_setFlag("knexFunctionArgs", knexFunctionArgs);
|
|
13979
|
+
};
|
|
13980
|
+
if (!prototype.getArgsForFnCall) prototype.getArgsForFnCall = function(id) {
|
|
13981
|
+
return this.$_getFlag("knexFunctionArgs")[id];
|
|
13982
|
+
};
|
|
13944
13983
|
if (!prototype.knex) prototype.knex = function(connection) {
|
|
13945
13984
|
return setKnexConnection.call(this, connection);
|
|
13946
13985
|
};
|
|
@@ -13953,13 +13992,19 @@ const knex$1 = (schema, root, args$1) => {
|
|
|
13953
13992
|
filter: () => {},
|
|
13954
13993
|
...options
|
|
13955
13994
|
};
|
|
13956
|
-
|
|
13957
|
-
|
|
13995
|
+
const returnable = this.setArgsForFnCall("uniqueInDb", {
|
|
13996
|
+
table,
|
|
13997
|
+
column,
|
|
13998
|
+
options: opts
|
|
13999
|
+
});
|
|
14000
|
+
let connection = findKnexConnection.call(returnable);
|
|
14001
|
+
return returnable.external(async (value, helpers) => {
|
|
13958
14002
|
const { prefs, state, error, schema: localSchema } = helpers;
|
|
13959
14003
|
if (!connection && localSchema._flags) connection = localSchema._flags.knexConnection;
|
|
13960
14004
|
if (!connection) return error("knex.missingConnection", { value });
|
|
13961
|
-
const
|
|
13962
|
-
const
|
|
14005
|
+
const { table: tableArg, column: columnArg, options: optsArg } = localSchema.getArgsForFnCall("uniqueInDb");
|
|
14006
|
+
const resolvedTable = isReference$1(tableArg, localSchema.$_root) ? tableArg.resolve(value, state, prefs) : tableArg;
|
|
14007
|
+
const resolvedColumn = isReference$1(columnArg, localSchema.$_root) ? columnArg.resolve(value, state, prefs) : columnArg;
|
|
13963
14008
|
if (!resolvedTable || typeof resolvedTable !== "string") return error("knex.invalidTable", {
|
|
13964
14009
|
value,
|
|
13965
14010
|
table: resolvedTable,
|
|
@@ -13971,14 +14016,14 @@ const knex$1 = (schema, root, args$1) => {
|
|
|
13971
14016
|
column: resolvedColumn
|
|
13972
14017
|
});
|
|
13973
14018
|
if (value === null || value === void 0) return value;
|
|
14019
|
+
const { client, query } = resolveQueryBuilder(connection, resolvedTable);
|
|
13974
14020
|
try {
|
|
13975
|
-
const { client, query } = resolveQueryBuilder(connection, resolvedTable);
|
|
13976
14021
|
query.select(resolvedColumn).limit(1);
|
|
13977
|
-
if (
|
|
14022
|
+
if (optsArg.caseInsensitive) query.whereRaw(`lower(${resolvedColumn}) = ?`, [client.raw("lower(?)", [value])]);
|
|
13978
14023
|
else query.where(resolvedColumn, value);
|
|
13979
|
-
if (
|
|
14024
|
+
if (optsArg.filter) {
|
|
13980
14025
|
const { error: errorFn, warn: warnFn, message: messageFn,...safeHelpers } = helpers;
|
|
13981
|
-
await
|
|
14026
|
+
await optsArg.filter(query, value, resolvedColumn, safeHelpers);
|
|
13982
14027
|
}
|
|
13983
14028
|
const row = await query.first();
|
|
13984
14029
|
if (row) return error("knex.unique", {
|
|
@@ -14003,13 +14048,19 @@ const knex$1 = (schema, root, args$1) => {
|
|
|
14003
14048
|
filter: () => {},
|
|
14004
14049
|
...options
|
|
14005
14050
|
};
|
|
14006
|
-
|
|
14007
|
-
|
|
14051
|
+
const returnable = this.setArgsForFnCall("existsInDb", {
|
|
14052
|
+
table,
|
|
14053
|
+
column,
|
|
14054
|
+
options: opts
|
|
14055
|
+
});
|
|
14056
|
+
let connection = findKnexConnection.call(returnable);
|
|
14057
|
+
return returnable.external(async (value, helpers) => {
|
|
14008
14058
|
const { prefs, state, error, schema: localSchema } = helpers;
|
|
14009
14059
|
if (!connection && localSchema._flags) connection = localSchema._flags.knexConnection;
|
|
14010
14060
|
if (!connection) return error("knex.missingConnection", { value });
|
|
14011
|
-
const
|
|
14012
|
-
const
|
|
14061
|
+
const { table: tableArg, column: columnArg, options: optsArg } = localSchema.getArgsForFnCall("existsInDb");
|
|
14062
|
+
const resolvedTable = isReference$1(tableArg, localSchema.$_root) ? tableArg.resolve(value, state, prefs) : tableArg;
|
|
14063
|
+
const resolvedColumn = isReference$1(columnArg, localSchema.$_root) ? columnArg.resolve(value, state, prefs) : columnArg;
|
|
14013
14064
|
if (!resolvedTable || typeof resolvedTable !== "string") return error("knex.invalidTable", {
|
|
14014
14065
|
value,
|
|
14015
14066
|
table: resolvedTable,
|
|
@@ -14021,14 +14072,14 @@ const knex$1 = (schema, root, args$1) => {
|
|
|
14021
14072
|
column: resolvedColumn
|
|
14022
14073
|
});
|
|
14023
14074
|
if (value === null || value === void 0) return value;
|
|
14075
|
+
const { client, query } = resolveQueryBuilder(connection, resolvedTable);
|
|
14024
14076
|
try {
|
|
14025
|
-
const { client, query } = resolveQueryBuilder(connection, resolvedTable);
|
|
14026
14077
|
query.select(resolvedColumn).limit(1);
|
|
14027
|
-
if (
|
|
14078
|
+
if (optsArg.caseInsensitive) query.whereRaw(`lower(${resolvedColumn}) = ?`, [client.raw("lower(?)", [value])]);
|
|
14028
14079
|
else query.where(resolvedColumn, value);
|
|
14029
|
-
if (
|
|
14080
|
+
if (optsArg.filter) {
|
|
14030
14081
|
const { error: errorFn, warn: warnFn, message: messageFn,...safeHelpers } = helpers;
|
|
14031
|
-
await
|
|
14082
|
+
await optsArg.filter(query, value, resolvedColumn, safeHelpers);
|
|
14032
14083
|
}
|
|
14033
14084
|
const row = await query.first();
|
|
14034
14085
|
if (!row) return error("knex.exists", {
|
|
@@ -110857,6 +110908,132 @@ function strFromU8(dat, latin1) {
|
|
|
110857
110908
|
}
|
|
110858
110909
|
}
|
|
110859
110910
|
var import_semver = __toESM(require_semver());
|
|
110911
|
+
var StringifiedFunctionParser = class StringifiedFunctionParser {
|
|
110912
|
+
#namedBindings;
|
|
110913
|
+
#argNames;
|
|
110914
|
+
#functionBody;
|
|
110915
|
+
#isExpressionBody = false;
|
|
110916
|
+
#isAsync = false;
|
|
110917
|
+
#isGenerator = false;
|
|
110918
|
+
constructor(functionString, namedBindings) {
|
|
110919
|
+
this.#namedBindings = new Map();
|
|
110920
|
+
this.#argNames = [];
|
|
110921
|
+
this.#functionBody = "";
|
|
110922
|
+
if (isPlainObject(namedBindings)) Object.entries(namedBindings).forEach(([key, value]) => {
|
|
110923
|
+
this.#namedBindings.set(key, value);
|
|
110924
|
+
});
|
|
110925
|
+
const trimmed = functionString.trim();
|
|
110926
|
+
this.#parseArgNames(trimmed);
|
|
110927
|
+
this.#parseFunctionBody(trimmed);
|
|
110928
|
+
}
|
|
110929
|
+
#parseArgNames(trimmed) {
|
|
110930
|
+
const patterns = [
|
|
110931
|
+
/^\s*(?:async\s+)?\(([^)]*)\)\s*=>/,
|
|
110932
|
+
/^\s*(?:async\s+)?([a-zA-Z_$][a-zA-Z0-9_$]*)\s*=>/,
|
|
110933
|
+
/^\s*(?:async\s+)?function\s*(?:\*\s*)?(?:[a-zA-Z_$][a-zA-Z0-9_$]*)?\s*\(([^)]*)\)/,
|
|
110934
|
+
/^\s*(?:async\s+)?(?:\*\s*)?([a-zA-Z_$][a-zA-Z0-9_$]*)\s*\(([^)]*)\)\s*\{/
|
|
110935
|
+
];
|
|
110936
|
+
let paramString = "";
|
|
110937
|
+
for (const pattern of patterns) {
|
|
110938
|
+
const match$2 = trimmed.match(pattern);
|
|
110939
|
+
if (match$2) {
|
|
110940
|
+
paramString = match$2[1] || match$2[2] || "";
|
|
110941
|
+
break;
|
|
110942
|
+
}
|
|
110943
|
+
}
|
|
110944
|
+
if (!paramString || !paramString.trim()) return;
|
|
110945
|
+
const args$1 = [];
|
|
110946
|
+
let current = "";
|
|
110947
|
+
let depth = 0;
|
|
110948
|
+
let inString = false;
|
|
110949
|
+
let stringChar = "";
|
|
110950
|
+
for (let i$4 = 0; i$4 < paramString.length; i$4++) {
|
|
110951
|
+
const char = paramString[i$4];
|
|
110952
|
+
const prevChar = i$4 > 0 ? paramString[i$4 - 1] : "";
|
|
110953
|
+
if ((char === "\"" || char === "'" || char === "`") && prevChar !== "\\") {
|
|
110954
|
+
if (!inString) {
|
|
110955
|
+
inString = true;
|
|
110956
|
+
stringChar = char;
|
|
110957
|
+
} else if (char === stringChar) inString = false;
|
|
110958
|
+
}
|
|
110959
|
+
if (!inString) {
|
|
110960
|
+
if (char === "{" || char === "[" || char === "(") depth++;
|
|
110961
|
+
else if (char === "}" || char === "]" || char === ")") depth--;
|
|
110962
|
+
if (char === "," && depth === 0) {
|
|
110963
|
+
const processed = this.#processParameter(current.trim());
|
|
110964
|
+
if (processed) args$1.push(processed);
|
|
110965
|
+
current = "";
|
|
110966
|
+
continue;
|
|
110967
|
+
}
|
|
110968
|
+
}
|
|
110969
|
+
current += char;
|
|
110970
|
+
}
|
|
110971
|
+
if (current.trim()) {
|
|
110972
|
+
const processed = this.#processParameter(current.trim());
|
|
110973
|
+
if (processed) args$1.push(processed);
|
|
110974
|
+
}
|
|
110975
|
+
this.#argNames.push(...args$1);
|
|
110976
|
+
}
|
|
110977
|
+
#processParameter(param) {
|
|
110978
|
+
if (!param) return "";
|
|
110979
|
+
param = param.trim();
|
|
110980
|
+
if (param.startsWith("...")) return param.slice(3).trim().split(/[\s=]/)[0];
|
|
110981
|
+
if (param.startsWith("{") || param.startsWith("[")) return param.split(/[\s=:]/)[0];
|
|
110982
|
+
const nameMatch = param.match(/^([a-zA-Z_$][a-zA-Z0-9_$]*)/);
|
|
110983
|
+
return nameMatch ? nameMatch[1] : "";
|
|
110984
|
+
}
|
|
110985
|
+
#parseFunctionBody(trimmed) {
|
|
110986
|
+
this.#isAsync = /^\s*async\s+/.test(trimmed);
|
|
110987
|
+
const arrowExpressionMatch = trimmed.match(/^\s*(async\s+)?(?:\([^)]*\)|[a-zA-Z_$][a-zA-Z0-9_$]*)\s*=>\s*(.+)$/s);
|
|
110988
|
+
if (arrowExpressionMatch && !arrowExpressionMatch[2].trimStart().startsWith("{")) {
|
|
110989
|
+
this.#isExpressionBody = true;
|
|
110990
|
+
this.#functionBody = arrowExpressionMatch[2].trim();
|
|
110991
|
+
return;
|
|
110992
|
+
}
|
|
110993
|
+
const arrowBlockMatch = trimmed.match(/^\s*(async\s+)?(?:\([^)]*\)|[a-zA-Z_$][a-zA-Z0-9_$]*)\s*=>\s*\{([\s\S]*)\}\s*$/);
|
|
110994
|
+
if (arrowBlockMatch) {
|
|
110995
|
+
this.#functionBody = arrowBlockMatch[2].trim();
|
|
110996
|
+
return;
|
|
110997
|
+
}
|
|
110998
|
+
const functionMatch = trimmed.match(/^\s*(async\s+)?function\s*(\*\s*)?(?:[a-zA-Z_$][a-zA-Z0-9_$]*)?\s*\([^)]*\)\s*\{([\s\S]*)\}\s*$/);
|
|
110999
|
+
if (functionMatch) {
|
|
111000
|
+
this.#isGenerator = !!functionMatch[2];
|
|
111001
|
+
this.#functionBody = functionMatch[3].trim();
|
|
111002
|
+
return;
|
|
111003
|
+
}
|
|
111004
|
+
const methodMatch = trimmed.match(/^\s*(async\s+)?(\*\s*)?[a-zA-Z_$][a-zA-Z0-9_$]*\s*\([^)]*\)\s*\{([\s\S]*)\}\s*$/);
|
|
111005
|
+
if (methodMatch) {
|
|
111006
|
+
this.#isGenerator = !!methodMatch[2];
|
|
111007
|
+
this.#functionBody = methodMatch[3].trim();
|
|
111008
|
+
return;
|
|
111009
|
+
}
|
|
111010
|
+
const firstBrace = trimmed.indexOf("{");
|
|
111011
|
+
const lastBrace = trimmed.lastIndexOf("}");
|
|
111012
|
+
if (firstBrace !== -1 && lastBrace !== -1 && lastBrace > firstBrace) {
|
|
111013
|
+
this.#functionBody = trimmed.substring(firstBrace + 1, lastBrace);
|
|
111014
|
+
return;
|
|
111015
|
+
}
|
|
111016
|
+
}
|
|
111017
|
+
asFunction() {
|
|
111018
|
+
const functionBody = this.#isExpressionBody ? `return ${this.#functionBody}` : this.#functionBody;
|
|
111019
|
+
const bindingNames = Array.from(this.#namedBindings.keys());
|
|
111020
|
+
const allParams = [...bindingNames, ...this.#argNames];
|
|
111021
|
+
const paramList = allParams.join(", ");
|
|
111022
|
+
let functionCode = "";
|
|
111023
|
+
if (this.#isAsync) functionCode = this.#isGenerator ? `async function*(${paramList}) { ${functionBody} }` : `async function(${paramList}) { ${functionBody} }`;
|
|
111024
|
+
else functionCode = this.#isGenerator ? `function*(${paramList}) { ${functionBody} }` : `function(${paramList}) { ${functionBody} }`;
|
|
111025
|
+
const callable = new Function(`return ${functionCode}`)();
|
|
111026
|
+
const namedBindingValues = Array.from(this.#namedBindings.values());
|
|
111027
|
+
function wrapper(...args$1) {
|
|
111028
|
+
return callable.call(this, ...namedBindingValues, ...args$1);
|
|
111029
|
+
}
|
|
111030
|
+
return wrapper;
|
|
111031
|
+
}
|
|
111032
|
+
static parse(functionString, namedBindings) {
|
|
111033
|
+
const parser = new StringifiedFunctionParser(functionString, namedBindings);
|
|
111034
|
+
return parser.asFunction();
|
|
111035
|
+
}
|
|
111036
|
+
};
|
|
110860
111037
|
const utoa = (data) => {
|
|
110861
111038
|
const buffer$2 = strToU8(data);
|
|
110862
111039
|
const zipped = zlibSync(buffer$2, { level: 9 });
|
|
@@ -110872,7 +111049,74 @@ const atou = (base64) => {
|
|
|
110872
111049
|
}
|
|
110873
111050
|
return decodeURIComponent(escape(binary));
|
|
110874
111051
|
};
|
|
110875
|
-
const
|
|
111052
|
+
const defaultEncoderOptions = { withDatabase: false };
|
|
111053
|
+
const isDehydratedValue = (value) => {
|
|
111054
|
+
return isPlainObject(value) && "_encodedType" in value && "_encodedValueType" in value && "_encodedValue" in value;
|
|
111055
|
+
};
|
|
111056
|
+
const dehydrateValue = (type, value) => {
|
|
111057
|
+
if ("function" === typeof value) value = value.toString();
|
|
111058
|
+
return {
|
|
111059
|
+
_encodedType: type,
|
|
111060
|
+
_encodedValueType: typeof value,
|
|
111061
|
+
_encodedValue: value
|
|
111062
|
+
};
|
|
111063
|
+
};
|
|
111064
|
+
const dehydrateKnexConnection = (connection) => {
|
|
111065
|
+
if (isPlainObject(connection)) {
|
|
111066
|
+
if ("getReadClient" in connection) return dehydrateValue("knexConnection", connection.getReadClient());
|
|
111067
|
+
return dehydrateValue("knexConnection", connection);
|
|
111068
|
+
} else if ("function" === typeof connection && "undefined" !== typeof connection.client && isPlainObject(connection.client.config)) return dehydrateValue("knexConnection", connection.client.config);
|
|
111069
|
+
throw new TypeError("Cannot dehydrate unexpected type of Knex connection");
|
|
111070
|
+
};
|
|
111071
|
+
const rehydrateKnexConnection = (dehydrated) => {
|
|
111072
|
+
const db = knex.default;
|
|
111073
|
+
return db(dehydrated._encodedValue);
|
|
111074
|
+
};
|
|
111075
|
+
const rehydrateFunction = (functionString, namedBindings) => {
|
|
111076
|
+
return StringifiedFunctionParser.parse(functionString, namedBindings);
|
|
111077
|
+
};
|
|
111078
|
+
const isReference = (obj, root) => {
|
|
111079
|
+
return root.isRef(obj);
|
|
111080
|
+
};
|
|
111081
|
+
const rehydrateDatabaseFunction = (dehydrated) => {
|
|
111082
|
+
const { _encodedValue: encodedValue } = dehydrated;
|
|
111083
|
+
const { connection: dehydratedConnection, external } = encodedValue;
|
|
111084
|
+
const connection = "function" === typeof dehydratedConnection && "knex" === dehydratedConnection.name ? dehydratedConnection : rehydrateKnexConnection(dehydratedConnection);
|
|
111085
|
+
const rehydratedMethod = rehydrateFunction(external.method, {
|
|
111086
|
+
connection,
|
|
111087
|
+
isReference,
|
|
111088
|
+
resolveQueryBuilder
|
|
111089
|
+
});
|
|
111090
|
+
return {
|
|
111091
|
+
...external,
|
|
111092
|
+
method: rehydratedMethod
|
|
111093
|
+
};
|
|
111094
|
+
};
|
|
111095
|
+
const rehydrateValue = (dehydrated) => {
|
|
111096
|
+
const { _encodedType: encodedType, _encodedValue: encodedValue } = dehydrated;
|
|
111097
|
+
if (encodedType === "function") {
|
|
111098
|
+
const returnable = rehydrateFunction(encodedValue);
|
|
111099
|
+
if (typeof returnable !== "function") throw new TypeError("Rehydrated value is not a function");
|
|
111100
|
+
return returnable;
|
|
111101
|
+
} else if (encodedType === "knexConnection") return rehydrateKnexConnection(dehydrated);
|
|
111102
|
+
else if (encodedType === "databaseFunction") return rehydrateDatabaseFunction(dehydrated);
|
|
111103
|
+
return encodedValue;
|
|
111104
|
+
};
|
|
111105
|
+
const isDatabaseRelatedFunction = (fn$1) => {
|
|
111106
|
+
const functionString = fn$1.toString();
|
|
111107
|
+
return functionString.includes("connection =") && functionString.includes(".knexConnection");
|
|
111108
|
+
};
|
|
111109
|
+
const isExternalsWithDatabaseRelatedFunctionality = (obj) => {
|
|
111110
|
+
return Array.isArray(obj) && obj.some((item) => isPlainObject(item) && "method" in item && "function" === typeof item.method && isDatabaseRelatedFunction(item.method));
|
|
111111
|
+
};
|
|
111112
|
+
const hasExternalsWithDatabaseRelatedFunctionality = (obj) => {
|
|
111113
|
+
return isPlainObject(obj) && "externals" in obj && isExternalsWithDatabaseRelatedFunctionality(obj.externals);
|
|
111114
|
+
};
|
|
111115
|
+
const encode = (schema, options = {}) => {
|
|
111116
|
+
const opts = {
|
|
111117
|
+
...defaultEncoderOptions,
|
|
111118
|
+
...options
|
|
111119
|
+
};
|
|
110876
111120
|
const description$1 = schema.describe();
|
|
110877
111121
|
for (const key in description$1.keys) {
|
|
110878
111122
|
if ("undefined" === typeof description$1.keys[key] || "undefined" === typeof description$1.keys[key].rules) continue;
|
|
@@ -110885,25 +111129,57 @@ const encode = (schema) => {
|
|
|
110885
111129
|
});
|
|
110886
111130
|
}
|
|
110887
111131
|
const json$1 = JSON.stringify({
|
|
110888
|
-
version: "0.1.0-master-
|
|
111132
|
+
version: "0.1.0-master-649f9ed8",
|
|
110889
111133
|
schema: description$1
|
|
110890
|
-
}, (
|
|
111134
|
+
}, (key, value) => {
|
|
110891
111135
|
if (typeof value === "bigint") return value.toString();
|
|
110892
111136
|
if (typeof value === "undefined") return null;
|
|
110893
111137
|
if (value instanceof DateTime) return value.toObject();
|
|
110894
111138
|
else if (value instanceof Date) return DateTime.fromJSDate(value).toObject();
|
|
111139
|
+
if (hasExternalsWithDatabaseRelatedFunctionality(value)) {
|
|
111140
|
+
const connection = value.flags.knexConnection;
|
|
111141
|
+
value.externals = value.externals.filter((external) => {
|
|
111142
|
+
if (isDatabaseRelatedFunction(external.method) && !opts.withDatabase) return false;
|
|
111143
|
+
return true;
|
|
111144
|
+
}).map((external) => {
|
|
111145
|
+
if (isDatabaseRelatedFunction(external.method)) return dehydrateValue("databaseFunction", {
|
|
111146
|
+
external: {
|
|
111147
|
+
...external,
|
|
111148
|
+
method: external.method.toString()
|
|
111149
|
+
},
|
|
111150
|
+
connection: dehydrateKnexConnection(connection)
|
|
111151
|
+
});
|
|
111152
|
+
});
|
|
111153
|
+
}
|
|
111154
|
+
if (key === "knexConnection") if (!opts.withDatabase) return void 0;
|
|
111155
|
+
else return dehydrateKnexConnection(value);
|
|
111156
|
+
else if (typeof value === "function") if (isDatabaseRelatedFunction(value) && !opts.withDatabase) return dehydrateValue("function", () => {});
|
|
111157
|
+
else return dehydrateValue("function", value);
|
|
110895
111158
|
return value;
|
|
110896
111159
|
});
|
|
110897
111160
|
return utoa(json$1);
|
|
110898
111161
|
};
|
|
110899
|
-
const decode = (base64) => {
|
|
111162
|
+
const decode = (base64, options = {}) => {
|
|
111163
|
+
const opts = {
|
|
111164
|
+
...defaultEncoderOptions,
|
|
111165
|
+
...options
|
|
111166
|
+
};
|
|
110900
111167
|
const json$1 = atou(base64);
|
|
110901
|
-
const description$1 = JSON.parse(json$1)
|
|
111168
|
+
const description$1 = JSON.parse(json$1, (_, value) => {
|
|
111169
|
+
if (!opts.withDatabase) {
|
|
111170
|
+
if (isPlainObject(value) && "knexConnection" in value) {
|
|
111171
|
+
delete value["knexConnection"];
|
|
111172
|
+
return value;
|
|
111173
|
+
}
|
|
111174
|
+
}
|
|
111175
|
+
if (isDehydratedValue(value)) return rehydrateValue(value);
|
|
111176
|
+
return value;
|
|
111177
|
+
});
|
|
110902
111178
|
if (!isPlainObject(description$1) || !("version" in description$1) || !("schema" in description$1) || typeof description$1.version !== "string" || !isPlainObject(description$1.schema)) throw new TypeError("Not a valid encoded schema");
|
|
110903
111179
|
const { version: schemaVersion, schema } = description$1;
|
|
110904
|
-
if (import_semver.valid("0.1.0-master-
|
|
111180
|
+
if (import_semver.valid("0.1.0-master-649f9ed8")) {
|
|
110905
111181
|
if (!import_semver.valid(import_semver.coerce(schemaVersion))) throw new TypeError(`Invalid schema version: ${schemaVersion}`);
|
|
110906
|
-
if (import_semver.gt(import_semver.coerce(schemaVersion), "0.1.0-master-
|
|
111182
|
+
if (import_semver.gt(import_semver.coerce(schemaVersion), "0.1.0-master-649f9ed8")) throw new TypeError(`Schema version ${schemaVersion} is not compatible with current version 0.1.0-master-649f9ed8`);
|
|
110907
111183
|
}
|
|
110908
111184
|
return validator.build(schema);
|
|
110909
111185
|
};
|
|
@@ -112357,7 +112633,7 @@ init_esm();
|
|
|
112357
112633
|
var import_lib = __toESM(require_lib$3());
|
|
112358
112634
|
var import_lib$1 = __toESM(require_lib$2());
|
|
112359
112635
|
var import_lib$2 = __toESM(require_lib());
|
|
112360
|
-
const version = "0.1.0-master-
|
|
112636
|
+
const version = "0.1.0-master-649f9ed8";
|
|
112361
112637
|
Object.defineProperty(exports, "ValidationError", {
|
|
112362
112638
|
enumerable: true,
|
|
112363
112639
|
get: function() {
|