@isdk/ai-tool 0.0.3 → 0.0.5
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/dist/{chunk-DGMU4VSJ.mjs → chunk-6JC4ABGE.mjs} +130 -146
- package/dist/funcs.js +129 -145
- package/dist/funcs.mjs +2 -2
- package/dist/index.js +129 -145
- package/dist/index.mjs +2 -2
- package/dist/test/util.js +1 -2
- package/dist/test/util.mjs +2 -3
- package/docs/classes/AbortError.md +11 -11
- package/docs/classes/AlreadyExistsError.md +11 -11
- package/docs/classes/BaseError.md +11 -11
- package/docs/classes/ClientTools.md +51 -51
- package/docs/classes/CommonError.md +11 -11
- package/docs/classes/EventClient.md +73 -73
- package/docs/classes/EventServer.md +71 -71
- package/docs/classes/EventToolFunc.md +41 -41
- package/docs/classes/FStringPromptTemplate.md +18 -18
- package/docs/classes/FewShotPromptTemplate.md +22 -22
- package/docs/classes/GolangPromptTemplate.md +18 -18
- package/docs/classes/HFEnvironment.md +9 -9
- package/docs/classes/HFInterpreter.md +17 -17
- package/docs/classes/HFTemplate.md +4 -4
- package/docs/classes/HfPromptTemplate.md +18 -18
- package/docs/classes/NotFoundError.md +11 -11
- package/docs/classes/NotImplementationError.md +11 -11
- package/docs/classes/PromptExampleSelector.md +8 -8
- package/docs/classes/PromptTemplate.md +17 -17
- package/docs/classes/ReadableStreamError.md +11 -11
- package/docs/classes/ResClientTools.md +57 -57
- package/docs/classes/ResServerTools.md +55 -55
- package/docs/classes/SSEChannel.md +15 -15
- package/docs/classes/ServerTools.md +48 -48
- package/docs/classes/ToolFunc.md +38 -38
- package/docs/enums/ErrorCode.md +19 -19
- package/docs/enums/XXHashAlgorithm.md +2 -2
- package/docs/interfaces/AIChatAssistantMessageParam.md +6 -6
- package/docs/interfaces/AIChatContentPartImage.md +2 -2
- package/docs/interfaces/AIChatContentPartText.md +2 -2
- package/docs/interfaces/AIChatMessageParamBase.md +1 -1
- package/docs/interfaces/AIChatMessageToolCall.md +3 -3
- package/docs/interfaces/AIChatSystemMessageParam.md +3 -3
- package/docs/interfaces/AIChatToolMessageParam.md +4 -4
- package/docs/interfaces/AIChatUserMessageParam.md +7 -7
- package/docs/interfaces/AIResult.md +4 -4
- package/docs/interfaces/AIStreamCallbacksAndOptions.md +6 -6
- package/docs/interfaces/AIStreamParser.md +1 -1
- package/docs/interfaces/AIStreamParserOptions.md +1 -1
- package/docs/interfaces/BaseFunc.md +7 -7
- package/docs/interfaces/BaseFuncItem.md +6 -6
- package/docs/interfaces/ClientFuncItem.md +10 -10
- package/docs/interfaces/DotenvExpandOptions.md +3 -3
- package/docs/interfaces/DotenvExpandOutput.md +2 -2
- package/docs/interfaces/EventClientFuncParams.md +4 -4
- package/docs/interfaces/EventServerFuncParams.md +5 -5
- package/docs/interfaces/FewShotPromptTemplateOptions.md +11 -11
- package/docs/interfaces/FuncItem.md +7 -7
- package/docs/interfaces/FuncParam.md +5 -5
- package/docs/interfaces/PromptExampleSelectorOptions.md +2 -2
- package/docs/interfaces/PromptTemplateOptions.md +6 -6
- package/docs/interfaces/RemoteFuncItem.md +10 -10
- package/docs/interfaces/ResClientFuncParams.md +2 -2
- package/docs/interfaces/ResServerFuncParams.md +5 -5
- package/docs/interfaces/SanitizeFilenameOptions.md +2 -2
- package/docs/interfaces/ServerFuncItem.md +11 -11
- package/docs/interfaces/ServerFuncParams.md +2 -2
- package/docs/modules.md +110 -110
- package/package.json +12 -13
- /package/dist/{chunk-EZFPVSGF.mjs → chunk-U5DDQYSF.mjs} +0 -0
package/dist/funcs.js
CHANGED
|
@@ -392,8 +392,7 @@ var ToolFunc = class _ToolFunc extends import_property_manager.AdvancePropertyMa
|
|
|
392
392
|
runSync(params) {
|
|
393
393
|
const isPosParams = this.params && Array.isArray(this.params);
|
|
394
394
|
if (Array.isArray(params)) {
|
|
395
|
-
if (isPosParams)
|
|
396
|
-
return this.func(...params);
|
|
395
|
+
if (isPosParams) return this.func(...params);
|
|
397
396
|
throwError2("the function is not support array params, the params must be object!", this.name);
|
|
398
397
|
}
|
|
399
398
|
if (isPosParams) {
|
|
@@ -601,22 +600,19 @@ var SSEChannel = class {
|
|
|
601
600
|
* @throws Will throw an error if the channel is closed.
|
|
602
601
|
*/
|
|
603
602
|
publish(data, eventName) {
|
|
604
|
-
if (!this.active)
|
|
605
|
-
throwError2("Channel closed", "SSEChannel", SSEChannelAlreadyClosedErrCode);
|
|
603
|
+
if (!this.active) throwError2("Channel closed", "SSEChannel", SSEChannelAlreadyClosedErrCode);
|
|
606
604
|
let output;
|
|
607
605
|
let id;
|
|
608
606
|
let _eventName = eventName;
|
|
609
607
|
if (!data && !eventName) {
|
|
610
|
-
if (!this.clients.size)
|
|
611
|
-
return;
|
|
608
|
+
if (!this.clients.size) return;
|
|
612
609
|
output = "data: \n\n";
|
|
613
610
|
} else {
|
|
614
611
|
id = this.nextID++;
|
|
615
612
|
if (typeof data === "object") {
|
|
616
613
|
if (data.event) {
|
|
617
614
|
_eventName = data.event;
|
|
618
|
-
if (data.data !== void 0)
|
|
619
|
-
data = JSON.stringify(data.data);
|
|
615
|
+
if (data.data !== void 0) data = JSON.stringify(data.data);
|
|
620
616
|
} else {
|
|
621
617
|
data = JSON.stringify(data);
|
|
622
618
|
}
|
|
@@ -643,8 +639,7 @@ var SSEChannel = class {
|
|
|
643
639
|
* @throws Will throw an error if the channel is closed.
|
|
644
640
|
*/
|
|
645
641
|
subscribe(req, res, events) {
|
|
646
|
-
if (!this.active)
|
|
647
|
-
throwError2("Channel closed", "SSEChannel", SSEChannelAlreadyClosedErrCode);
|
|
642
|
+
if (!this.active) throwError2("Channel closed", "SSEChannel", SSEChannelAlreadyClosedErrCode);
|
|
648
643
|
const c = { req, res, events };
|
|
649
644
|
const maxStreamDuration = this.options.maxStreamDuration;
|
|
650
645
|
let cacheControl = "max-age=0, stale-while-revalidate=0, stale-if-error=0, no-transform";
|
|
@@ -805,8 +800,7 @@ var import_transformers = require("@xenova/transformers");
|
|
|
805
800
|
var import_secondary_cache = require("secondary-cache");
|
|
806
801
|
function _lrucache({ key, value, options } = {}) {
|
|
807
802
|
if (key === void 0) {
|
|
808
|
-
if (options)
|
|
809
|
-
this.cache.setDefaultOptions(options);
|
|
803
|
+
if (options) this.cache.setDefaultOptions(options);
|
|
810
804
|
} else if (value === null) {
|
|
811
805
|
return this.cache.del(key);
|
|
812
806
|
} else if (value !== void 0) {
|
|
@@ -1059,8 +1053,7 @@ async function _splitSegments({ texts, model } = {}) {
|
|
|
1059
1053
|
}
|
|
1060
1054
|
}
|
|
1061
1055
|
}
|
|
1062
|
-
if (segment.length)
|
|
1063
|
-
segments2.push([...segment]);
|
|
1056
|
+
if (segment.length) segments2.push([...segment]);
|
|
1064
1057
|
return segments2;
|
|
1065
1058
|
}
|
|
1066
1059
|
var splitSegments = new ServerTools("splitSegments", {
|
|
@@ -1668,8 +1661,7 @@ function tokenize(source, options = {}) {
|
|
|
1668
1661
|
while (predicate(src[cursorPosition])) {
|
|
1669
1662
|
if (src[cursorPosition] === "\\") {
|
|
1670
1663
|
++cursorPosition;
|
|
1671
|
-
if (cursorPosition >= src.length)
|
|
1672
|
-
throw new SyntaxError("Unexpected end of input");
|
|
1664
|
+
if (cursorPosition >= src.length) throw new SyntaxError("Unexpected end of input");
|
|
1673
1665
|
const escaped = src[cursorPosition++];
|
|
1674
1666
|
const unescaped = ESCAPE_CHARACTERS.get(escaped);
|
|
1675
1667
|
if (unescaped === void 0) {
|
|
@@ -1679,83 +1671,81 @@ function tokenize(source, options = {}) {
|
|
|
1679
1671
|
continue;
|
|
1680
1672
|
}
|
|
1681
1673
|
str += src[cursorPosition++];
|
|
1682
|
-
if (cursorPosition >= src.length)
|
|
1683
|
-
throw new SyntaxError("Unexpected end of input");
|
|
1674
|
+
if (cursorPosition >= src.length) throw new SyntaxError("Unexpected end of input");
|
|
1684
1675
|
}
|
|
1685
1676
|
return str;
|
|
1686
1677
|
};
|
|
1687
|
-
main:
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
continue;
|
|
1699
|
-
}
|
|
1700
|
-
}
|
|
1701
|
-
consumeWhile((char2) => /\s/.test(char2));
|
|
1702
|
-
const char = src[cursorPosition];
|
|
1703
|
-
if (char === "-" || char === "+") {
|
|
1704
|
-
const lastTokenType2 = tokens.at(-1)?.type;
|
|
1705
|
-
if (lastTokenType2 === TOKEN_TYPES.Text || lastTokenType2 === void 0) {
|
|
1706
|
-
throw new SyntaxError(`Unexpected character: ${char}`);
|
|
1707
|
-
}
|
|
1708
|
-
switch (lastTokenType2) {
|
|
1709
|
-
case TOKEN_TYPES.Identifier:
|
|
1710
|
-
case TOKEN_TYPES.NumericLiteral:
|
|
1711
|
-
case TOKEN_TYPES.BooleanLiteral:
|
|
1712
|
-
case TOKEN_TYPES.StringLiteral:
|
|
1713
|
-
case TOKEN_TYPES.CloseParen:
|
|
1714
|
-
case TOKEN_TYPES.CloseSquareBracket:
|
|
1715
|
-
break;
|
|
1716
|
-
default: {
|
|
1717
|
-
++cursorPosition;
|
|
1718
|
-
const num = consumeWhile(isInteger);
|
|
1719
|
-
tokens.push(
|
|
1720
|
-
new Token(`${char}${num}`, num.length > 0 ? TOKEN_TYPES.NumericLiteral : TOKEN_TYPES.UnaryOperator)
|
|
1721
|
-
);
|
|
1722
|
-
continue;
|
|
1723
|
-
}
|
|
1724
|
-
}
|
|
1678
|
+
main: while (cursorPosition < src.length) {
|
|
1679
|
+
const lastTokenType = tokens.at(-1)?.type;
|
|
1680
|
+
if (lastTokenType === void 0 || lastTokenType === TOKEN_TYPES.CloseStatement || lastTokenType === TOKEN_TYPES.CloseExpression) {
|
|
1681
|
+
let text = "";
|
|
1682
|
+
while (cursorPosition < src.length && // Keep going until we hit the next Jinja statement or expression
|
|
1683
|
+
!(src[cursorPosition] === "{" && (src[cursorPosition + 1] === "%" || src[cursorPosition + 1] === "{"))) {
|
|
1684
|
+
text += src[cursorPosition++];
|
|
1685
|
+
}
|
|
1686
|
+
if (text.length > 0) {
|
|
1687
|
+
tokens.push(new Token(text, TOKEN_TYPES.Text));
|
|
1688
|
+
continue;
|
|
1725
1689
|
}
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1690
|
+
}
|
|
1691
|
+
consumeWhile((char2) => /\s/.test(char2));
|
|
1692
|
+
const char = src[cursorPosition];
|
|
1693
|
+
if (char === "-" || char === "+") {
|
|
1694
|
+
const lastTokenType2 = tokens.at(-1)?.type;
|
|
1695
|
+
if (lastTokenType2 === TOKEN_TYPES.Text || lastTokenType2 === void 0) {
|
|
1696
|
+
throw new SyntaxError(`Unexpected character: ${char}`);
|
|
1697
|
+
}
|
|
1698
|
+
switch (lastTokenType2) {
|
|
1699
|
+
case TOKEN_TYPES.Identifier:
|
|
1700
|
+
case TOKEN_TYPES.NumericLiteral:
|
|
1701
|
+
case TOKEN_TYPES.BooleanLiteral:
|
|
1702
|
+
case TOKEN_TYPES.StringLiteral:
|
|
1703
|
+
case TOKEN_TYPES.CloseParen:
|
|
1704
|
+
case TOKEN_TYPES.CloseSquareBracket:
|
|
1705
|
+
break;
|
|
1706
|
+
default: {
|
|
1707
|
+
++cursorPosition;
|
|
1708
|
+
const num = consumeWhile(isInteger);
|
|
1709
|
+
tokens.push(
|
|
1710
|
+
new Token(`${char}${num}`, num.length > 0 ? TOKEN_TYPES.NumericLiteral : TOKEN_TYPES.UnaryOperator)
|
|
1711
|
+
);
|
|
1712
|
+
continue;
|
|
1732
1713
|
}
|
|
1733
1714
|
}
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
if (isInteger(char)) {
|
|
1742
|
-
const num = consumeWhile(isInteger);
|
|
1743
|
-
tokens.push(new Token(num, TOKEN_TYPES.NumericLiteral));
|
|
1744
|
-
continue;
|
|
1715
|
+
}
|
|
1716
|
+
for (const [char2, token] of ORDERED_MAPPING_TABLE) {
|
|
1717
|
+
const slice2 = src.slice(cursorPosition, cursorPosition + char2.length);
|
|
1718
|
+
if (slice2 === char2) {
|
|
1719
|
+
tokens.push(new Token(char2, token));
|
|
1720
|
+
cursorPosition += char2.length;
|
|
1721
|
+
continue main;
|
|
1745
1722
|
}
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1723
|
+
}
|
|
1724
|
+
if (char === "'" || char === '"') {
|
|
1725
|
+
++cursorPosition;
|
|
1726
|
+
const str = consumeWhile((c) => c !== char);
|
|
1727
|
+
tokens.push(new Token(str, TOKEN_TYPES.StringLiteral));
|
|
1728
|
+
++cursorPosition;
|
|
1729
|
+
continue;
|
|
1730
|
+
}
|
|
1731
|
+
if (isInteger(char)) {
|
|
1732
|
+
const num = consumeWhile(isInteger);
|
|
1733
|
+
tokens.push(new Token(num, TOKEN_TYPES.NumericLiteral));
|
|
1734
|
+
continue;
|
|
1735
|
+
}
|
|
1736
|
+
if (isWord(char)) {
|
|
1737
|
+
const word = consumeWhile(isWord);
|
|
1738
|
+
const type = Object.hasOwn(KEYWORDS, word) ? KEYWORDS[word] : TOKEN_TYPES.Identifier;
|
|
1739
|
+
if (type === TOKEN_TYPES.In && tokens.at(-1)?.type === TOKEN_TYPES.Not) {
|
|
1740
|
+
tokens.pop();
|
|
1741
|
+
tokens.push(new Token("not in", TOKEN_TYPES.NotIn));
|
|
1742
|
+
} else {
|
|
1743
|
+
tokens.push(new Token(word, type));
|
|
1756
1744
|
}
|
|
1757
|
-
|
|
1745
|
+
continue;
|
|
1758
1746
|
}
|
|
1747
|
+
throw new SyntaxError(`Unexpected character: ${char}`);
|
|
1748
|
+
}
|
|
1759
1749
|
return tokens;
|
|
1760
1750
|
}
|
|
1761
1751
|
|
|
@@ -3051,8 +3041,7 @@ var Interpreter = class {
|
|
|
3051
3041
|
return new StringValue(result);
|
|
3052
3042
|
}
|
|
3053
3043
|
evaluate(statement, environment) {
|
|
3054
|
-
if (statement === void 0)
|
|
3055
|
-
return new UndefinedValue();
|
|
3044
|
+
if (statement === void 0) return new UndefinedValue();
|
|
3056
3045
|
switch (statement.type) {
|
|
3057
3046
|
case "Program":
|
|
3058
3047
|
return this.evalProgram(statement, environment);
|
|
@@ -3869,8 +3858,7 @@ function createEventStreamTransformer(customParser) {
|
|
|
3869
3858
|
const parsedMessage = customParser ? customParser(event2.data, {
|
|
3870
3859
|
event: event2.event
|
|
3871
3860
|
}) : event2.data;
|
|
3872
|
-
if (parsedMessage)
|
|
3873
|
-
controller.enqueue(parsedMessage);
|
|
3861
|
+
if (parsedMessage) controller.enqueue(parsedMessage);
|
|
3874
3862
|
}
|
|
3875
3863
|
}
|
|
3876
3864
|
);
|
|
@@ -3886,15 +3874,13 @@ function createCallbacksTransformer(cb) {
|
|
|
3886
3874
|
const callbacks = cb || {};
|
|
3887
3875
|
return new TransformStream({
|
|
3888
3876
|
async start() {
|
|
3889
|
-
if (callbacks.onStart)
|
|
3890
|
-
await callbacks.onStart();
|
|
3877
|
+
if (callbacks.onStart) await callbacks.onStart();
|
|
3891
3878
|
},
|
|
3892
3879
|
async transform(message, controller) {
|
|
3893
3880
|
const content = typeof message === "string" ? message : message.content;
|
|
3894
3881
|
controller.enqueue(textEncoder.encode(content));
|
|
3895
3882
|
aggregatedResponse += content;
|
|
3896
|
-
if (callbacks.onToken)
|
|
3897
|
-
await callbacks.onToken(content);
|
|
3883
|
+
if (callbacks.onToken) await callbacks.onToken(content);
|
|
3898
3884
|
if (callbacks.onText && typeof message === "string") {
|
|
3899
3885
|
await callbacks.onText(message);
|
|
3900
3886
|
}
|
|
@@ -3914,8 +3900,7 @@ function trimStartOfStreamHelper() {
|
|
|
3914
3900
|
return (text) => {
|
|
3915
3901
|
if (isStreamStart) {
|
|
3916
3902
|
text = text.trimStart();
|
|
3917
|
-
if (text)
|
|
3918
|
-
isStreamStart = false;
|
|
3903
|
+
if (text) isStreamStart = false;
|
|
3919
3904
|
}
|
|
3920
3905
|
return text;
|
|
3921
3906
|
};
|
|
@@ -3942,10 +3927,8 @@ function readableFromAsyncIterable(iterable) {
|
|
|
3942
3927
|
return new ReadableStream({
|
|
3943
3928
|
async pull(controller) {
|
|
3944
3929
|
const { done, value } = await it.next();
|
|
3945
|
-
if (done)
|
|
3946
|
-
|
|
3947
|
-
else
|
|
3948
|
-
controller.enqueue(value);
|
|
3930
|
+
if (done) controller.close();
|
|
3931
|
+
else controller.enqueue(value);
|
|
3949
3932
|
},
|
|
3950
3933
|
async cancel(reason) {
|
|
3951
3934
|
await it.return?.(reason);
|
|
@@ -4018,8 +4001,7 @@ var XXHashAlgorithm = /* @__PURE__ */ ((XXHashAlgorithm2) => {
|
|
|
4018
4001
|
return XXHashAlgorithm2;
|
|
4019
4002
|
})(XXHashAlgorithm || {});
|
|
4020
4003
|
function xxhash(value, hashAlgo = 111 /* xxhash64 */, seed = SEED) {
|
|
4021
|
-
if (value.buffer)
|
|
4022
|
-
value = value.buffer;
|
|
4004
|
+
if (value.buffer) value = value.buffer;
|
|
4023
4005
|
let result;
|
|
4024
4006
|
if (hashAlgo !== 112 /* xxhash32 */) {
|
|
4025
4007
|
result = h64(value, seed);
|
|
@@ -4208,8 +4190,7 @@ function isObject(value) {
|
|
|
4208
4190
|
return !!value && value.constructor === Object;
|
|
4209
4191
|
}
|
|
4210
4192
|
function getKeysPath(value) {
|
|
4211
|
-
if (!value)
|
|
4212
|
-
return [];
|
|
4193
|
+
if (!value) return [];
|
|
4213
4194
|
return getKeys(value, [], "");
|
|
4214
4195
|
}
|
|
4215
4196
|
function getKeys(obj, paths, dot = ".") {
|
|
@@ -4243,30 +4224,14 @@ function loadFileFromPaths(filename, searchPaths, extNames) {
|
|
|
4243
4224
|
if (import_path2.default.isAbsolute(filename)) {
|
|
4244
4225
|
if (fs.existsSync(filename)) {
|
|
4245
4226
|
result = filename;
|
|
4227
|
+
} else {
|
|
4228
|
+
result = tryGetFilepath(import_path2.default.basename(filename), [import_path2.default.dirname(filename)], extNames);
|
|
4246
4229
|
}
|
|
4247
4230
|
} else {
|
|
4248
4231
|
if (!searchPaths) {
|
|
4249
4232
|
searchPaths = ["."];
|
|
4250
4233
|
}
|
|
4251
|
-
|
|
4252
|
-
for (const searchPath of searchPaths) {
|
|
4253
|
-
const filePath = import_path2.default.resolve(searchPath, filename);
|
|
4254
|
-
if (exts) {
|
|
4255
|
-
for (let i = 0; i < exts.length; i++) {
|
|
4256
|
-
const extName = exts[i] !== extNames[i] ? extNames[i] : "";
|
|
4257
|
-
const filenameWithExt = filePath + extName;
|
|
4258
|
-
if (fs.existsSync(filenameWithExt)) {
|
|
4259
|
-
result = filenameWithExt;
|
|
4260
|
-
break;
|
|
4261
|
-
}
|
|
4262
|
-
}
|
|
4263
|
-
} else {
|
|
4264
|
-
if (fs.existsSync(filePath)) {
|
|
4265
|
-
result = filePath;
|
|
4266
|
-
break;
|
|
4267
|
-
}
|
|
4268
|
-
}
|
|
4269
|
-
}
|
|
4234
|
+
result = tryGetFilepath(filename, searchPaths, extNames);
|
|
4270
4235
|
}
|
|
4271
4236
|
if (result) {
|
|
4272
4237
|
result = fs.readFileSync(result);
|
|
@@ -4275,6 +4240,29 @@ function loadFileFromPaths(filename, searchPaths, extNames) {
|
|
|
4275
4240
|
}
|
|
4276
4241
|
return result;
|
|
4277
4242
|
}
|
|
4243
|
+
function tryGetFilepath(filename, searchPaths, extNames) {
|
|
4244
|
+
let result;
|
|
4245
|
+
const exts = extNames ? extNames.map((ext) => getMultiLevelExtname(filename, extNameLevel(ext))) : void 0;
|
|
4246
|
+
for (const searchPath of searchPaths) {
|
|
4247
|
+
const filePath = import_path2.default.resolve(searchPath, filename);
|
|
4248
|
+
if (exts) {
|
|
4249
|
+
for (let i = 0; i < exts.length; i++) {
|
|
4250
|
+
const extName = exts[i] !== extNames[i] ? extNames[i] : "";
|
|
4251
|
+
const filenameWithExt = filePath + extName;
|
|
4252
|
+
if (fs.existsSync(filenameWithExt)) {
|
|
4253
|
+
result = filenameWithExt;
|
|
4254
|
+
break;
|
|
4255
|
+
}
|
|
4256
|
+
}
|
|
4257
|
+
} else {
|
|
4258
|
+
if (fs.existsSync(filePath)) {
|
|
4259
|
+
result = filePath;
|
|
4260
|
+
break;
|
|
4261
|
+
}
|
|
4262
|
+
}
|
|
4263
|
+
}
|
|
4264
|
+
return result;
|
|
4265
|
+
}
|
|
4278
4266
|
function loadTextFromPaths(filename, searchPaths, extNames, encoding = "utf8") {
|
|
4279
4267
|
const result = loadFileFromPaths(filename, searchPaths, extNames);
|
|
4280
4268
|
return result.toString(encoding);
|
|
@@ -4431,27 +4419,26 @@ function jsonFilterToWhere(filter, wrapKey) {
|
|
|
4431
4419
|
}
|
|
4432
4420
|
if (Array.isArray(filter)) {
|
|
4433
4421
|
andQuery.push(generateAndClause(filter, wrapKey));
|
|
4434
|
-
} else
|
|
4435
|
-
|
|
4436
|
-
|
|
4437
|
-
|
|
4438
|
-
|
|
4439
|
-
|
|
4422
|
+
} else for (const [key, value] of Object.entries(filter)) {
|
|
4423
|
+
if (key === "$and") {
|
|
4424
|
+
andQuery.push(`(${generateAndClause(filter[key], wrapKey)})`);
|
|
4425
|
+
} else if (key === "$or") {
|
|
4426
|
+
andQuery.push(`(${generateOrClause(filter[key], wrapKey)})`);
|
|
4427
|
+
} else {
|
|
4428
|
+
const tValue = typeof value;
|
|
4429
|
+
if (value == null) {
|
|
4430
|
+
andQuery.push(`${wrapKey(key)} IS NULL`);
|
|
4431
|
+
} else if (tValue === "object" && !Array.isArray(value)) {
|
|
4432
|
+
andQuery.push(generateCondition(wrapKey(key), value));
|
|
4433
|
+
} else if (tValue === "string") {
|
|
4434
|
+
andQuery.push(`${wrapKey(key)}='${value}'`);
|
|
4435
|
+
} else if (tValue === "number" || tValue === "boolean") {
|
|
4436
|
+
andQuery.push(`${wrapKey(key)}=${value}`);
|
|
4440
4437
|
} else {
|
|
4441
|
-
|
|
4442
|
-
if (value == null) {
|
|
4443
|
-
andQuery.push(`${wrapKey(key)} IS NULL`);
|
|
4444
|
-
} else if (tValue === "object" && !Array.isArray(value)) {
|
|
4445
|
-
andQuery.push(generateCondition(wrapKey(key), value));
|
|
4446
|
-
} else if (tValue === "string") {
|
|
4447
|
-
andQuery.push(`${wrapKey(key)}='${value}'`);
|
|
4448
|
-
} else if (tValue === "number" || tValue === "boolean") {
|
|
4449
|
-
andQuery.push(`${wrapKey(key)}=${value}`);
|
|
4450
|
-
} else {
|
|
4451
|
-
throw new Error(`Unsupported value type for key ${key}`);
|
|
4452
|
-
}
|
|
4438
|
+
throw new Error(`Unsupported value type for key ${key}`);
|
|
4453
4439
|
}
|
|
4454
4440
|
}
|
|
4441
|
+
}
|
|
4455
4442
|
;
|
|
4456
4443
|
return andQuery.length > 1 ? andQuery.join(" AND ") : andQuery[0];
|
|
4457
4444
|
}
|
|
@@ -4479,8 +4466,7 @@ var ClientTools = class _ClientTools extends ToolFunc {
|
|
|
4479
4466
|
"Content-Type": "application/json"
|
|
4480
4467
|
} });
|
|
4481
4468
|
const items = await res.json();
|
|
4482
|
-
if (items)
|
|
4483
|
-
this.loadFromSync(items);
|
|
4469
|
+
if (items) this.loadFromSync(items);
|
|
4484
4470
|
} else {
|
|
4485
4471
|
throwError2("missing apiRoot to load tools", "ClientTools");
|
|
4486
4472
|
}
|
|
@@ -4786,8 +4772,7 @@ var EventClient = class extends ResClientTools {
|
|
|
4786
4772
|
for (const event2 of events) {
|
|
4787
4773
|
if (!this._forwardEvents.has(event2)) {
|
|
4788
4774
|
this._forwardEvents.add(event2);
|
|
4789
|
-
if (this.on)
|
|
4790
|
-
this.on(event2, this.ebListener);
|
|
4775
|
+
if (this.on) this.on(event2, this.ebListener);
|
|
4791
4776
|
}
|
|
4792
4777
|
}
|
|
4793
4778
|
}
|
|
@@ -4806,8 +4791,7 @@ var EventClient = class extends ResClientTools {
|
|
|
4806
4791
|
for (const event2 of events) {
|
|
4807
4792
|
if (this._forwardEvents.has(event2)) {
|
|
4808
4793
|
this._forwardEvents.delete(event2);
|
|
4809
|
-
if (this.off)
|
|
4810
|
-
this.off(event2, this.ebListener);
|
|
4794
|
+
if (this.off) this.off(event2, this.ebListener);
|
|
4811
4795
|
}
|
|
4812
4796
|
}
|
|
4813
4797
|
}
|
package/dist/funcs.mjs
CHANGED