@mastra/libsql 0.13.8-alpha.0 → 0.13.8-alpha.2
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/CHANGELOG.md +18 -0
- package/package.json +18 -5
- package/.turbo/turbo-build.log +0 -4
- package/eslint.config.js +0 -6
- package/src/index.ts +0 -3
- package/src/storage/domains/legacy-evals/index.ts +0 -149
- package/src/storage/domains/memory/index.ts +0 -937
- package/src/storage/domains/observability/index.ts +0 -237
- package/src/storage/domains/operations/index.ts +0 -506
- package/src/storage/domains/scores/index.ts +0 -226
- package/src/storage/domains/traces/index.ts +0 -150
- package/src/storage/domains/utils.ts +0 -272
- package/src/storage/domains/workflows/index.ts +0 -421
- package/src/storage/index.test.ts +0 -16
- package/src/storage/index.ts +0 -499
- package/src/vector/filter.test.ts +0 -906
- package/src/vector/filter.ts +0 -131
- package/src/vector/index.test.ts +0 -1693
- package/src/vector/index.ts +0 -515
- package/src/vector/prompt.ts +0 -101
- package/src/vector/sql-builder.ts +0 -548
- package/tsconfig.build.json +0 -9
- package/tsconfig.json +0 -5
- package/tsup.config.ts +0 -17
- package/vitest.config.ts +0 -11
package/src/vector/filter.ts
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import { BaseFilterTranslator } from '@mastra/core/vector/filter';
|
|
2
|
-
import type { VectorFilter, OperatorSupport, OperatorValueMap, VectorFieldValue } from '@mastra/core/vector/filter';
|
|
3
|
-
|
|
4
|
-
type LibSQLOperatorValueMap = Omit<
|
|
5
|
-
OperatorValueMap,
|
|
6
|
-
'$regex' | '$options' | '$in' | '$all' | '$nin' | '$eq' | '$ne'
|
|
7
|
-
> & {
|
|
8
|
-
$size: number;
|
|
9
|
-
$contains: VectorFieldValue | Record<string, unknown>;
|
|
10
|
-
$all: VectorFieldValue;
|
|
11
|
-
$in: VectorFieldValue;
|
|
12
|
-
$nin: VectorFieldValue;
|
|
13
|
-
$eq: VectorFieldValue;
|
|
14
|
-
$ne: VectorFieldValue;
|
|
15
|
-
};
|
|
16
|
-
export type LibSQLVectorFilter = VectorFilter<keyof LibSQLOperatorValueMap, LibSQLOperatorValueMap>;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Translates MongoDB-style filters to LibSQL compatible filters.
|
|
20
|
-
*
|
|
21
|
-
* Key differences from MongoDB:
|
|
22
|
-
*
|
|
23
|
-
* Logical Operators ($and, $or, $nor):
|
|
24
|
-
* - Can be used at the top level or nested within fields
|
|
25
|
-
* - Can take either a single condition or an array of conditions
|
|
26
|
-
*
|
|
27
|
-
*/
|
|
28
|
-
export class LibSQLFilterTranslator extends BaseFilterTranslator<LibSQLVectorFilter> {
|
|
29
|
-
protected override getSupportedOperators(): OperatorSupport {
|
|
30
|
-
return {
|
|
31
|
-
...BaseFilterTranslator.DEFAULT_OPERATORS,
|
|
32
|
-
regex: [],
|
|
33
|
-
custom: ['$contains', '$size'],
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
translate(filter?: LibSQLVectorFilter): LibSQLVectorFilter {
|
|
38
|
-
if (this.isEmpty(filter)) {
|
|
39
|
-
return filter;
|
|
40
|
-
}
|
|
41
|
-
this.validateFilter(filter);
|
|
42
|
-
return this.translateNode(filter);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
private translateNode(node: LibSQLVectorFilter, currentPath: string = ''): any {
|
|
46
|
-
if (this.isRegex(node)) {
|
|
47
|
-
throw new Error('Direct regex pattern format is not supported in LibSQL');
|
|
48
|
-
}
|
|
49
|
-
// Helper to wrap result with path if needed
|
|
50
|
-
const withPath = (result: any) => (currentPath ? { [currentPath]: result } : result);
|
|
51
|
-
|
|
52
|
-
// Handle primitives
|
|
53
|
-
if (this.isPrimitive(node)) {
|
|
54
|
-
return withPath({ $eq: this.normalizeComparisonValue(node) });
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Handle arrays
|
|
58
|
-
if (Array.isArray(node)) {
|
|
59
|
-
return withPath({ $in: this.normalizeArrayValues(node) });
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Handle regex
|
|
63
|
-
// TODO: Look more into regex support for LibSQL
|
|
64
|
-
// if (node instanceof RegExp) {
|
|
65
|
-
// return withPath(this.translateRegexPattern(node.source, node.flags));
|
|
66
|
-
// }
|
|
67
|
-
|
|
68
|
-
const entries = Object.entries(node as Record<string, any>);
|
|
69
|
-
const result: Record<string, any> = {};
|
|
70
|
-
|
|
71
|
-
// if ('$options' in node && !('$regex' in node)) {
|
|
72
|
-
// throw new Error('$options is not valid without $regex');
|
|
73
|
-
// }
|
|
74
|
-
|
|
75
|
-
// TODO: Look more into regex support for LibSQL
|
|
76
|
-
// // Handle special regex object format
|
|
77
|
-
// if ('$regex' in node) {
|
|
78
|
-
// const options = (node as any).$options || '';
|
|
79
|
-
// return withPath(this.translateRegexPattern(node.$regex, options));
|
|
80
|
-
// }
|
|
81
|
-
|
|
82
|
-
// Process remaining entries
|
|
83
|
-
for (const [key, value] of entries) {
|
|
84
|
-
// // Skip options as they're handled with $regex
|
|
85
|
-
// if (key === '$options') continue;
|
|
86
|
-
|
|
87
|
-
const newPath = currentPath ? `${currentPath}.${key}` : key;
|
|
88
|
-
|
|
89
|
-
if (this.isLogicalOperator(key)) {
|
|
90
|
-
result[key] = Array.isArray(value)
|
|
91
|
-
? value.map((filter: LibSQLVectorFilter) => this.translateNode(filter))
|
|
92
|
-
: this.translateNode(value);
|
|
93
|
-
} else if (this.isOperator(key)) {
|
|
94
|
-
if (this.isArrayOperator(key) && !Array.isArray(value) && key !== '$elemMatch') {
|
|
95
|
-
result[key] = [value];
|
|
96
|
-
} else if (this.isBasicOperator(key) && Array.isArray(value)) {
|
|
97
|
-
result[key] = JSON.stringify(value);
|
|
98
|
-
} else {
|
|
99
|
-
result[key] = value;
|
|
100
|
-
}
|
|
101
|
-
} else if (typeof value === 'object' && value !== null) {
|
|
102
|
-
// Handle nested objects
|
|
103
|
-
const hasOperators = Object.keys(value).some(k => this.isOperator(k));
|
|
104
|
-
if (hasOperators) {
|
|
105
|
-
result[newPath] = this.translateNode(value);
|
|
106
|
-
} else {
|
|
107
|
-
Object.assign(result, this.translateNode(value, newPath));
|
|
108
|
-
}
|
|
109
|
-
} else {
|
|
110
|
-
result[newPath] = this.translateNode(value);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return result;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// TODO: Look more into regex support for LibSQL
|
|
118
|
-
// private translateRegexPattern(pattern: string, options: string = ''): any {
|
|
119
|
-
// if (!options) return { $regex: pattern };
|
|
120
|
-
|
|
121
|
-
// const flags = options
|
|
122
|
-
// .split('')
|
|
123
|
-
// .filter(f => 'imsux'.includes(f))
|
|
124
|
-
// .join('');
|
|
125
|
-
|
|
126
|
-
// return {
|
|
127
|
-
// $regex: pattern,
|
|
128
|
-
// $options: flags,
|
|
129
|
-
// };
|
|
130
|
-
// }
|
|
131
|
-
}
|