@mastra/libsql 1.15.0-alpha.0 → 1.15.0-alpha.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/CHANGELOG.md +139 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +148 -51
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +149 -52
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/datasets/index.d.ts +7 -7
- package/dist/storage/domains/datasets/index.d.ts.map +1 -1
- package/dist/storage/domains/experiments/index.d.ts +5 -1
- package/dist/storage/domains/experiments/index.d.ts.map +1 -1
- package/dist/storage/domains/scores/index.d.ts +9 -5
- package/dist/storage/domains/scores/index.d.ts.map +1 -1
- package/dist/storage/domains/utils.d.ts +34 -0
- package/dist/storage/domains/utils.d.ts.map +1 -0
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createClient } from '@libsql/client';
|
|
2
2
|
import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
|
|
3
|
-
import { createVectorErrorId, AgentsStorage, AGENTS_SCHEMA, TABLE_AGENTS, AGENT_VERSIONS_SCHEMA, TABLE_AGENT_VERSIONS, createStorageErrorId, normalizePerPage, calculatePagination, BackgroundTasksStorage, TABLE_BACKGROUND_TASKS, TABLE_SCHEMAS, BlobStore, TABLE_SKILL_BLOBS, SKILL_BLOBS_SCHEMA, ChannelsStorage, TABLE_CHANNEL_INSTALLATIONS, TABLE_CHANNEL_CONFIG, DatasetsStorage, DATASETS_SCHEMA, TABLE_DATASETS, DATASET_ITEMS_SCHEMA, TABLE_DATASET_ITEMS, DATASET_VERSIONS_SCHEMA, TABLE_DATASET_VERSIONS,
|
|
3
|
+
import { createVectorErrorId, AgentsStorage, AGENTS_SCHEMA, TABLE_AGENTS, AGENT_VERSIONS_SCHEMA, TABLE_AGENT_VERSIONS, createStorageErrorId, normalizePerPage, calculatePagination, BackgroundTasksStorage, TABLE_BACKGROUND_TASKS, TABLE_SCHEMAS, BlobStore, TABLE_SKILL_BLOBS, SKILL_BLOBS_SCHEMA, ChannelsStorage, TABLE_CHANNEL_INSTALLATIONS, TABLE_CHANNEL_CONFIG, DatasetsStorage, DATASETS_SCHEMA, TABLE_DATASETS, DATASET_ITEMS_SCHEMA, TABLE_DATASET_ITEMS, DATASET_VERSIONS_SCHEMA, TABLE_DATASET_VERSIONS, TABLE_EXPERIMENTS, TABLE_EXPERIMENT_RESULTS, ensureDate, safelyParseJSON, ExperimentsStorage, EXPERIMENTS_SCHEMA, EXPERIMENT_RESULTS_SCHEMA, FavoritesStorage, FAVORITES_SCHEMA, TABLE_FAVORITES, TABLE_SKILLS, HarnessStorage, TABLE_HARNESS_SESSIONS, MCPClientsStorage, MCP_CLIENTS_SCHEMA, TABLE_MCP_CLIENTS, MCP_CLIENT_VERSIONS_SCHEMA, TABLE_MCP_CLIENT_VERSIONS, MCPServersStorage, MCP_SERVERS_SCHEMA, TABLE_MCP_SERVERS, MCP_SERVER_VERSIONS_SCHEMA, TABLE_MCP_SERVER_VERSIONS, MemoryStorage, TABLE_THREADS, TABLE_RESOURCES, TABLE_MESSAGES, OBSERVATIONAL_MEMORY_TABLE_SCHEMA, NotificationsStorage, TABLE_NOTIFICATIONS, ObservabilityStorage, TABLE_SPANS, SPAN_SCHEMA, listTracesArgsSchema, toTraceSpans, PromptBlocksStorage, PROMPT_BLOCKS_SCHEMA, TABLE_PROMPT_BLOCKS, PROMPT_BLOCK_VERSIONS_SCHEMA, TABLE_PROMPT_BLOCK_VERSIONS, SchedulesStorage, TABLE_SCHEDULE_TRIGGERS, TABLE_SCHEDULES, ScorerDefinitionsStorage, SCORER_DEFINITIONS_SCHEMA, TABLE_SCORER_DEFINITIONS, SCORER_DEFINITION_VERSIONS_SCHEMA, TABLE_SCORER_DEFINITION_VERSIONS, ScoresStorage, TABLE_SCORERS, SCORERS_SCHEMA, transformScoreRow, SkillsStorage, SKILLS_SCHEMA, SKILL_VERSIONS_SCHEMA, TABLE_SKILL_VERSIONS, ThreadStateStorage, TABLE_THREAD_STATE, THREAD_STATE_SCHEMA, ToolProviderConnectionsStorage, TOOL_PROVIDER_CONNECTIONS_SCHEMA, TABLE_TOOL_PROVIDER_CONNECTIONS, WorkflowsStorage, TABLE_WORKFLOW_SNAPSHOT, WorkspacesStorage, WORKSPACES_SCHEMA, TABLE_WORKSPACES, WORKSPACE_VERSIONS_SCHEMA, TABLE_WORKSPACE_VERSIONS, MastraCompositeStore, getSqlType, parseDuration, TraceStatus, mergeWorkflowStepResult } from '@mastra/core/storage';
|
|
4
4
|
import { parseSqlIdentifier, parseFieldKey } from '@mastra/core/utils';
|
|
5
5
|
import { MastraVector, validateTopK, validateUpsertInput } from '@mastra/core/vector';
|
|
6
6
|
import { BaseFilterTranslator } from '@mastra/core/vector/filter';
|
|
@@ -3824,6 +3824,30 @@ var ChannelsLibSQL = class extends ChannelsStorage {
|
|
|
3824
3824
|
};
|
|
3825
3825
|
}
|
|
3826
3826
|
};
|
|
3827
|
+
|
|
3828
|
+
// src/storage/domains/utils.ts
|
|
3829
|
+
function tenancyWhere(filters) {
|
|
3830
|
+
const conditions = [];
|
|
3831
|
+
const params = [];
|
|
3832
|
+
if (filters?.organizationId !== void 0) {
|
|
3833
|
+
conditions.push("organizationId = ?");
|
|
3834
|
+
params.push(filters.organizationId);
|
|
3835
|
+
}
|
|
3836
|
+
if (filters?.projectId !== void 0) {
|
|
3837
|
+
conditions.push("projectId = ?");
|
|
3838
|
+
params.push(filters.projectId);
|
|
3839
|
+
}
|
|
3840
|
+
return { conditions, params };
|
|
3841
|
+
}
|
|
3842
|
+
function buildScopedWhere(idColumn, idValue, filters) {
|
|
3843
|
+
const { conditions, params } = tenancyWhere(filters);
|
|
3844
|
+
return {
|
|
3845
|
+
sql: [`${idColumn} = ?`, ...conditions].join(" AND "),
|
|
3846
|
+
args: [idValue, ...params]
|
|
3847
|
+
};
|
|
3848
|
+
}
|
|
3849
|
+
|
|
3850
|
+
// src/storage/domains/datasets/index.ts
|
|
3827
3851
|
function jsonbArg(value) {
|
|
3828
3852
|
return value === void 0 || value === null ? null : JSON.stringify(value);
|
|
3829
3853
|
}
|
|
@@ -3904,6 +3928,18 @@ var DatasetsLibSQL = class extends DatasetsStorage {
|
|
|
3904
3928
|
await this.#db.deleteData({ tableName: TABLE_DATASET_ITEMS });
|
|
3905
3929
|
await this.#db.deleteData({ tableName: TABLE_DATASETS });
|
|
3906
3930
|
}
|
|
3931
|
+
async experimentTablesExist() {
|
|
3932
|
+
try {
|
|
3933
|
+
const result = await this.#client.execute({
|
|
3934
|
+
sql: `SELECT COUNT(*) AS c FROM sqlite_master WHERE type = 'table' AND name IN (?, ?)`,
|
|
3935
|
+
args: [TABLE_EXPERIMENTS, TABLE_EXPERIMENT_RESULTS]
|
|
3936
|
+
});
|
|
3937
|
+
const row = result.rows?.[0];
|
|
3938
|
+
return Number(row?.c ?? 0) === 2;
|
|
3939
|
+
} catch {
|
|
3940
|
+
return false;
|
|
3941
|
+
}
|
|
3942
|
+
}
|
|
3907
3943
|
// --- Row transformers ---
|
|
3908
3944
|
transformDatasetRow(row) {
|
|
3909
3945
|
return {
|
|
@@ -3990,8 +4026,8 @@ var DatasetsLibSQL = class extends DatasetsStorage {
|
|
|
3990
4026
|
groundTruthSchema: input.groundTruthSchema ?? null,
|
|
3991
4027
|
requestContextSchema: input.requestContextSchema ?? null,
|
|
3992
4028
|
targetType: input.targetType ?? null,
|
|
3993
|
-
targetIds: input.targetIds
|
|
3994
|
-
scorerIds: input.scorerIds
|
|
4029
|
+
targetIds: input.targetIds ?? null,
|
|
4030
|
+
scorerIds: input.scorerIds ?? null,
|
|
3995
4031
|
version: 0,
|
|
3996
4032
|
organizationId: input.organizationId ?? null,
|
|
3997
4033
|
projectId: input.projectId ?? null,
|
|
@@ -4031,11 +4067,16 @@ var DatasetsLibSQL = class extends DatasetsStorage {
|
|
|
4031
4067
|
);
|
|
4032
4068
|
}
|
|
4033
4069
|
}
|
|
4034
|
-
async getDatasetById({
|
|
4070
|
+
async getDatasetById({
|
|
4071
|
+
id,
|
|
4072
|
+
filters
|
|
4073
|
+
}) {
|
|
4035
4074
|
try {
|
|
4075
|
+
const { conditions, params } = tenancyWhere(filters);
|
|
4076
|
+
const whereSql = ["id = ?", ...conditions].join(" AND ");
|
|
4036
4077
|
const result = await this.#client.execute({
|
|
4037
|
-
sql: `SELECT ${buildSelectColumns(TABLE_DATASETS)} FROM ${TABLE_DATASETS} WHERE
|
|
4038
|
-
args: [id]
|
|
4078
|
+
sql: `SELECT ${buildSelectColumns(TABLE_DATASETS)} FROM ${TABLE_DATASETS} WHERE ${whereSql}`,
|
|
4079
|
+
args: [id, ...params]
|
|
4039
4080
|
});
|
|
4040
4081
|
return result.rows?.[0] ? this.transformDatasetRow(result.rows[0]) : null;
|
|
4041
4082
|
} catch (error) {
|
|
@@ -4051,7 +4092,7 @@ var DatasetsLibSQL = class extends DatasetsStorage {
|
|
|
4051
4092
|
}
|
|
4052
4093
|
async _doUpdateDataset(args) {
|
|
4053
4094
|
try {
|
|
4054
|
-
const existing = await this.getDatasetById({ id: args.id });
|
|
4095
|
+
const existing = await this.getDatasetById({ id: args.id, filters: args.filters });
|
|
4055
4096
|
if (!existing) {
|
|
4056
4097
|
throw new MastraError({
|
|
4057
4098
|
id: createStorageErrorId("LIBSQL", "UPDATE_DATASET", "NOT_FOUND"),
|
|
@@ -4134,30 +4175,31 @@ var DatasetsLibSQL = class extends DatasetsStorage {
|
|
|
4134
4175
|
);
|
|
4135
4176
|
}
|
|
4136
4177
|
}
|
|
4137
|
-
async deleteDataset({ id }) {
|
|
4178
|
+
async deleteDataset({ id, filters }) {
|
|
4138
4179
|
try {
|
|
4139
|
-
|
|
4140
|
-
|
|
4180
|
+
const { conditions, params } = tenancyWhere(filters);
|
|
4181
|
+
const scopedWhere = ["id = ?", ...conditions].join(" AND ");
|
|
4182
|
+
const exists = await this.#client.execute({
|
|
4183
|
+
sql: `SELECT id FROM ${TABLE_DATASETS} WHERE ${scopedWhere}`,
|
|
4184
|
+
args: [id, ...params]
|
|
4185
|
+
});
|
|
4186
|
+
if (!exists.rows?.[0]) return;
|
|
4187
|
+
const experimentTablesExist = await this.experimentTablesExist();
|
|
4188
|
+
const statements = [];
|
|
4189
|
+
if (experimentTablesExist) {
|
|
4190
|
+
statements.push({
|
|
4141
4191
|
sql: `DELETE FROM ${TABLE_EXPERIMENT_RESULTS} WHERE experimentId IN (SELECT id FROM ${TABLE_EXPERIMENTS} WHERE datasetId = ?)`,
|
|
4142
4192
|
args: [id]
|
|
4143
4193
|
});
|
|
4144
|
-
|
|
4145
|
-
}
|
|
4146
|
-
try {
|
|
4147
|
-
await this.#client.execute({
|
|
4194
|
+
statements.push({
|
|
4148
4195
|
sql: `UPDATE ${TABLE_EXPERIMENTS} SET datasetId = NULL, datasetVersion = NULL WHERE datasetId = ?`,
|
|
4149
4196
|
args: [id]
|
|
4150
4197
|
});
|
|
4151
|
-
} catch {
|
|
4152
4198
|
}
|
|
4153
|
-
|
|
4154
|
-
|
|
4155
|
-
|
|
4156
|
-
|
|
4157
|
-
{ sql: `DELETE FROM ${TABLE_DATASETS} WHERE id = ?`, args: [id] }
|
|
4158
|
-
],
|
|
4159
|
-
"write"
|
|
4160
|
-
);
|
|
4199
|
+
statements.push({ sql: `DELETE FROM ${TABLE_DATASET_VERSIONS} WHERE datasetId = ?`, args: [id] });
|
|
4200
|
+
statements.push({ sql: `DELETE FROM ${TABLE_DATASET_ITEMS} WHERE datasetId = ?`, args: [id] });
|
|
4201
|
+
statements.push({ sql: `DELETE FROM ${TABLE_DATASETS} WHERE ${scopedWhere}`, args: [id, ...params] });
|
|
4202
|
+
await this.#client.batch(statements, "write");
|
|
4161
4203
|
} catch (error) {
|
|
4162
4204
|
throw new MastraError(
|
|
4163
4205
|
{
|
|
@@ -4190,6 +4232,21 @@ var DatasetsLibSQL = class extends DatasetsStorage {
|
|
|
4190
4232
|
filterConditions.push("candidateId = ?");
|
|
4191
4233
|
filterParams.push(args.filters.candidateId);
|
|
4192
4234
|
}
|
|
4235
|
+
if (args.filters?.targetType !== void 0) {
|
|
4236
|
+
filterConditions.push("targetType = ?");
|
|
4237
|
+
filterParams.push(args.filters.targetType);
|
|
4238
|
+
}
|
|
4239
|
+
if (args.filters?.targetIds !== void 0 && args.filters.targetIds.length > 0) {
|
|
4240
|
+
const placeholders = args.filters.targetIds.map(() => "?").join(",");
|
|
4241
|
+
filterConditions.push(
|
|
4242
|
+
`EXISTS (SELECT 1 FROM json_each(${TABLE_DATASETS}.targetIds) WHERE value IN (${placeholders}))`
|
|
4243
|
+
);
|
|
4244
|
+
for (const id of args.filters.targetIds) filterParams.push(id);
|
|
4245
|
+
}
|
|
4246
|
+
if (args.filters?.name !== void 0 && args.filters.name.length > 0) {
|
|
4247
|
+
filterConditions.push("LOWER(name) LIKE ?");
|
|
4248
|
+
filterParams.push(`%${args.filters.name.toLowerCase()}%`);
|
|
4249
|
+
}
|
|
4193
4250
|
const whereClause = filterConditions.length > 0 ? `WHERE ${filterConditions.join(" AND ")}` : "";
|
|
4194
4251
|
const countResult = await this.#client.execute({
|
|
4195
4252
|
sql: `SELECT COUNT(*) as count FROM ${TABLE_DATASETS} ${whereClause}`,
|
|
@@ -5155,9 +5212,10 @@ var ExperimentsLibSQL = class extends ExperimentsStorage {
|
|
|
5155
5212
|
}
|
|
5156
5213
|
async getExperimentById(args) {
|
|
5157
5214
|
try {
|
|
5215
|
+
const scoped = buildScopedWhere("id", args.id, args.filters);
|
|
5158
5216
|
const result = await this.#client.execute({
|
|
5159
|
-
sql: `SELECT ${buildSelectColumns(TABLE_EXPERIMENTS)} FROM ${TABLE_EXPERIMENTS} WHERE
|
|
5160
|
-
args:
|
|
5217
|
+
sql: `SELECT ${buildSelectColumns(TABLE_EXPERIMENTS)} FROM ${TABLE_EXPERIMENTS} WHERE ${scoped.sql}`,
|
|
5218
|
+
args: scoped.args
|
|
5161
5219
|
});
|
|
5162
5220
|
return result.rows?.[0] ? this.transformExperimentRow(result.rows[0]) : null;
|
|
5163
5221
|
} catch (error) {
|
|
@@ -5249,14 +5307,17 @@ var ExperimentsLibSQL = class extends ExperimentsStorage {
|
|
|
5249
5307
|
}
|
|
5250
5308
|
async deleteExperiment(args) {
|
|
5251
5309
|
try {
|
|
5252
|
-
|
|
5253
|
-
|
|
5254
|
-
|
|
5255
|
-
|
|
5256
|
-
await this.#client.
|
|
5257
|
-
|
|
5258
|
-
|
|
5259
|
-
|
|
5310
|
+
const parentScoped = buildScopedWhere("id", args.id, args.filters);
|
|
5311
|
+
const { conditions, params } = tenancyWhere(args.filters);
|
|
5312
|
+
const cascadeWhere = conditions.length ? `experimentId IN (SELECT id FROM ${TABLE_EXPERIMENTS} WHERE ${["id = ?", ...conditions].join(" AND ")})` : `experimentId = ?`;
|
|
5313
|
+
const cascadeArgs = conditions.length ? [args.id, ...params] : [args.id];
|
|
5314
|
+
await this.#client.batch(
|
|
5315
|
+
[
|
|
5316
|
+
{ sql: `DELETE FROM ${TABLE_EXPERIMENT_RESULTS} WHERE ${cascadeWhere}`, args: cascadeArgs },
|
|
5317
|
+
{ sql: `DELETE FROM ${TABLE_EXPERIMENTS} WHERE ${parentScoped.sql}`, args: parentScoped.args }
|
|
5318
|
+
],
|
|
5319
|
+
"write"
|
|
5320
|
+
);
|
|
5260
5321
|
} catch (error) {
|
|
5261
5322
|
throw new MastraError(
|
|
5262
5323
|
{
|
|
@@ -5394,9 +5455,10 @@ var ExperimentsLibSQL = class extends ExperimentsStorage {
|
|
|
5394
5455
|
}
|
|
5395
5456
|
async getExperimentResultById(args) {
|
|
5396
5457
|
try {
|
|
5458
|
+
const scoped = buildScopedWhere("id", args.id, args.filters);
|
|
5397
5459
|
const result = await this.#client.execute({
|
|
5398
|
-
sql: `SELECT ${buildSelectColumns(TABLE_EXPERIMENT_RESULTS)} FROM ${TABLE_EXPERIMENT_RESULTS} WHERE
|
|
5399
|
-
args:
|
|
5460
|
+
sql: `SELECT ${buildSelectColumns(TABLE_EXPERIMENT_RESULTS)} FROM ${TABLE_EXPERIMENT_RESULTS} WHERE ${scoped.sql}`,
|
|
5461
|
+
args: scoped.args
|
|
5400
5462
|
});
|
|
5401
5463
|
return result.rows?.[0] ? this.transformExperimentResultRow(result.rows[0]) : null;
|
|
5402
5464
|
} catch (error) {
|
|
@@ -5476,6 +5538,14 @@ var ExperimentsLibSQL = class extends ExperimentsStorage {
|
|
|
5476
5538
|
}
|
|
5477
5539
|
async deleteExperimentResults(args) {
|
|
5478
5540
|
try {
|
|
5541
|
+
const { conditions, params } = tenancyWhere(args.filters);
|
|
5542
|
+
if (conditions.length) {
|
|
5543
|
+
await this.#client.execute({
|
|
5544
|
+
sql: `DELETE FROM ${TABLE_EXPERIMENT_RESULTS} WHERE experimentId IN (SELECT id FROM ${TABLE_EXPERIMENTS} WHERE ${["id = ?", ...conditions].join(" AND ")})`,
|
|
5545
|
+
args: [args.experimentId, ...params]
|
|
5546
|
+
});
|
|
5547
|
+
return;
|
|
5548
|
+
}
|
|
5479
5549
|
await this.#client.execute({
|
|
5480
5550
|
sql: `DELETE FROM ${TABLE_EXPERIMENT_RESULTS} WHERE experimentId = ?`,
|
|
5481
5551
|
args: [args.experimentId]
|
|
@@ -11042,6 +11112,16 @@ var ScorerDefinitionsLibSQL = class extends ScorerDefinitionsStorage {
|
|
|
11042
11112
|
};
|
|
11043
11113
|
}
|
|
11044
11114
|
};
|
|
11115
|
+
function appendTenancyConditions(conditions, args, filters) {
|
|
11116
|
+
if (filters?.organizationId !== void 0) {
|
|
11117
|
+
conditions.push(`organizationId = ?`);
|
|
11118
|
+
args.push(filters.organizationId);
|
|
11119
|
+
}
|
|
11120
|
+
if (filters?.projectId !== void 0) {
|
|
11121
|
+
conditions.push(`projectId = ?`);
|
|
11122
|
+
args.push(filters.projectId);
|
|
11123
|
+
}
|
|
11124
|
+
}
|
|
11045
11125
|
var ScoresLibSQL = class _ScoresLibSQL extends ScoresStorage {
|
|
11046
11126
|
/**
|
|
11047
11127
|
* Scorer results accumulate as evals run. Single table, anchored on `createdAt`.
|
|
@@ -11062,7 +11142,7 @@ var ScoresLibSQL = class _ScoresLibSQL extends ScoresStorage {
|
|
|
11062
11142
|
await this.#db.alterTable({
|
|
11063
11143
|
tableName: TABLE_SCORERS,
|
|
11064
11144
|
schema: SCORERS_SCHEMA,
|
|
11065
|
-
ifNotExists: ["spanId", "requestContext"]
|
|
11145
|
+
ifNotExists: ["spanId", "requestContext", "organizationId", "projectId", "batchId", "datasetId", "datasetItemId"]
|
|
11066
11146
|
});
|
|
11067
11147
|
}
|
|
11068
11148
|
async dangerouslyClearAll() {
|
|
@@ -11079,13 +11159,18 @@ var ScoresLibSQL = class _ScoresLibSQL extends ScoresStorage {
|
|
|
11079
11159
|
}
|
|
11080
11160
|
async listScoresByRunId({
|
|
11081
11161
|
runId,
|
|
11082
|
-
pagination
|
|
11162
|
+
pagination,
|
|
11163
|
+
filters
|
|
11083
11164
|
}) {
|
|
11084
11165
|
try {
|
|
11085
11166
|
const { page, perPage: perPageInput } = pagination;
|
|
11167
|
+
const conditions = [`runId = ?`];
|
|
11168
|
+
const queryParams = [runId];
|
|
11169
|
+
appendTenancyConditions(conditions, queryParams, filters);
|
|
11170
|
+
const whereClause = `WHERE ${conditions.join(" AND ")}`;
|
|
11086
11171
|
const countResult = await this.#client.execute({
|
|
11087
|
-
sql: `SELECT COUNT(*) as count FROM ${TABLE_SCORERS}
|
|
11088
|
-
args:
|
|
11172
|
+
sql: `SELECT COUNT(*) as count FROM ${TABLE_SCORERS} ${whereClause}`,
|
|
11173
|
+
args: queryParams
|
|
11089
11174
|
});
|
|
11090
11175
|
const total = Number(countResult.rows?.[0]?.count ?? 0);
|
|
11091
11176
|
if (total === 0) {
|
|
@@ -11104,8 +11189,8 @@ var ScoresLibSQL = class _ScoresLibSQL extends ScoresStorage {
|
|
|
11104
11189
|
const limitValue = perPageInput === false ? total : perPage;
|
|
11105
11190
|
const end = perPageInput === false ? total : start + perPage;
|
|
11106
11191
|
const result = await this.#client.execute({
|
|
11107
|
-
sql: `SELECT ${buildSelectColumns(TABLE_SCORERS)} FROM ${TABLE_SCORERS}
|
|
11108
|
-
args: [
|
|
11192
|
+
sql: `SELECT ${buildSelectColumns(TABLE_SCORERS)} FROM ${TABLE_SCORERS} ${whereClause} ORDER BY createdAt DESC LIMIT ? OFFSET ?`,
|
|
11193
|
+
args: [...queryParams, limitValue, start]
|
|
11109
11194
|
});
|
|
11110
11195
|
const scores = result.rows?.map((row) => this.transformScoreRow(row)) ?? [];
|
|
11111
11196
|
return {
|
|
@@ -11133,7 +11218,8 @@ var ScoresLibSQL = class _ScoresLibSQL extends ScoresStorage {
|
|
|
11133
11218
|
entityId,
|
|
11134
11219
|
entityType,
|
|
11135
11220
|
source,
|
|
11136
|
-
pagination
|
|
11221
|
+
pagination,
|
|
11222
|
+
filters
|
|
11137
11223
|
}) {
|
|
11138
11224
|
try {
|
|
11139
11225
|
const { page, perPage: perPageInput } = pagination;
|
|
@@ -11155,6 +11241,7 @@ var ScoresLibSQL = class _ScoresLibSQL extends ScoresStorage {
|
|
|
11155
11241
|
conditions.push(`source = ?`);
|
|
11156
11242
|
queryParams.push(source);
|
|
11157
11243
|
}
|
|
11244
|
+
appendTenancyConditions(conditions, queryParams, filters);
|
|
11158
11245
|
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
11159
11246
|
const countResult = await this.#client.execute({
|
|
11160
11247
|
sql: `SELECT COUNT(*) as count FROM ${TABLE_SCORERS} ${whereClause}`,
|
|
@@ -11262,13 +11349,18 @@ var ScoresLibSQL = class _ScoresLibSQL extends ScoresStorage {
|
|
|
11262
11349
|
async listScoresByEntityId({
|
|
11263
11350
|
entityId,
|
|
11264
11351
|
entityType,
|
|
11265
|
-
pagination
|
|
11352
|
+
pagination,
|
|
11353
|
+
filters
|
|
11266
11354
|
}) {
|
|
11267
11355
|
try {
|
|
11268
11356
|
const { page, perPage: perPageInput } = pagination;
|
|
11357
|
+
const conditions = [`entityId = ?`, `entityType = ?`];
|
|
11358
|
+
const queryParams = [entityId, entityType];
|
|
11359
|
+
appendTenancyConditions(conditions, queryParams, filters);
|
|
11360
|
+
const whereClause = `WHERE ${conditions.join(" AND ")}`;
|
|
11269
11361
|
const countResult = await this.#client.execute({
|
|
11270
|
-
sql: `SELECT COUNT(*) as count FROM ${TABLE_SCORERS}
|
|
11271
|
-
args:
|
|
11362
|
+
sql: `SELECT COUNT(*) as count FROM ${TABLE_SCORERS} ${whereClause}`,
|
|
11363
|
+
args: queryParams
|
|
11272
11364
|
});
|
|
11273
11365
|
const total = Number(countResult.rows?.[0]?.count ?? 0);
|
|
11274
11366
|
if (total === 0) {
|
|
@@ -11287,8 +11379,8 @@ var ScoresLibSQL = class _ScoresLibSQL extends ScoresStorage {
|
|
|
11287
11379
|
const limitValue = perPageInput === false ? total : perPage;
|
|
11288
11380
|
const end = perPageInput === false ? total : start + perPage;
|
|
11289
11381
|
const result = await this.#client.execute({
|
|
11290
|
-
sql: `SELECT ${buildSelectColumns(TABLE_SCORERS)} FROM ${TABLE_SCORERS}
|
|
11291
|
-
args: [
|
|
11382
|
+
sql: `SELECT ${buildSelectColumns(TABLE_SCORERS)} FROM ${TABLE_SCORERS} ${whereClause} ORDER BY createdAt DESC LIMIT ? OFFSET ?`,
|
|
11383
|
+
args: [...queryParams, limitValue, start]
|
|
11292
11384
|
});
|
|
11293
11385
|
const scores = result.rows?.map((row) => this.transformScoreRow(row)) ?? [];
|
|
11294
11386
|
return {
|
|
@@ -11314,22 +11406,27 @@ var ScoresLibSQL = class _ScoresLibSQL extends ScoresStorage {
|
|
|
11314
11406
|
async listScoresBySpan({
|
|
11315
11407
|
traceId,
|
|
11316
11408
|
spanId,
|
|
11317
|
-
pagination
|
|
11409
|
+
pagination,
|
|
11410
|
+
filters
|
|
11318
11411
|
}) {
|
|
11319
11412
|
try {
|
|
11320
11413
|
const { page, perPage: perPageInput } = pagination;
|
|
11321
11414
|
const perPage = normalizePerPage(perPageInput, 100);
|
|
11322
11415
|
const { offset: start, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
|
|
11416
|
+
const conditions = [`traceId = ?`, `spanId = ?`];
|
|
11417
|
+
const queryParams = [traceId, spanId];
|
|
11418
|
+
appendTenancyConditions(conditions, queryParams, filters);
|
|
11419
|
+
const whereClause = `WHERE ${conditions.join(" AND ")}`;
|
|
11323
11420
|
const countSQLResult = await this.#client.execute({
|
|
11324
|
-
sql: `SELECT COUNT(*) as count FROM ${TABLE_SCORERS}
|
|
11325
|
-
args:
|
|
11421
|
+
sql: `SELECT COUNT(*) as count FROM ${TABLE_SCORERS} ${whereClause}`,
|
|
11422
|
+
args: queryParams
|
|
11326
11423
|
});
|
|
11327
11424
|
const total = Number(countSQLResult.rows?.[0]?.count ?? 0);
|
|
11328
11425
|
const limitValue = perPageInput === false ? total : perPage;
|
|
11329
11426
|
const end = perPageInput === false ? total : start + perPage;
|
|
11330
11427
|
const result = await this.#client.execute({
|
|
11331
|
-
sql: `SELECT ${buildSelectColumns(TABLE_SCORERS)} FROM ${TABLE_SCORERS}
|
|
11332
|
-
args: [
|
|
11428
|
+
sql: `SELECT ${buildSelectColumns(TABLE_SCORERS)} FROM ${TABLE_SCORERS} ${whereClause} ORDER BY createdAt DESC LIMIT ? OFFSET ?`,
|
|
11429
|
+
args: [...queryParams, limitValue, start]
|
|
11333
11430
|
});
|
|
11334
11431
|
const scores = result.rows?.map((row) => this.transformScoreRow(row)) ?? [];
|
|
11335
11432
|
return {
|