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