@upstash/redis 1.36.0-rc.3 → 1.36.0
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/{chunk-2HN5OIX5.mjs → chunk-4AG3JMXU.mjs} +215 -404
- package/cloudflare.d.mts +2 -2
- package/cloudflare.d.ts +2 -2
- package/cloudflare.js +222 -379
- package/cloudflare.mjs +14 -10
- package/fastly.d.mts +2 -2
- package/fastly.d.ts +2 -2
- package/fastly.js +209 -370
- package/fastly.mjs +1 -1
- package/nodejs.d.mts +3 -94
- package/nodejs.d.ts +3 -94
- package/nodejs.js +217 -407
- package/nodejs.mjs +9 -13
- package/package.json +1 -1
- package/{zmscore-DQw_6S0p.d.mts → zmscore-0SAuWM0q.d.mts} +125 -218
- package/{zmscore-DQw_6S0p.d.ts → zmscore-0SAuWM0q.d.ts} +125 -218
package/nodejs.js
CHANGED
|
@@ -21,10 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var nodejs_exports = {};
|
|
22
22
|
__export(nodejs_exports, {
|
|
23
23
|
Redis: () => Redis2,
|
|
24
|
-
|
|
25
|
-
errors: () => error_exports,
|
|
26
|
-
index: () => index,
|
|
27
|
-
s: () => s
|
|
24
|
+
errors: () => error_exports
|
|
28
25
|
});
|
|
29
26
|
module.exports = __toCommonJS(nodejs_exports);
|
|
30
27
|
|
|
@@ -101,6 +98,15 @@ function mergeHeaders(...headers) {
|
|
|
101
98
|
}
|
|
102
99
|
return merged;
|
|
103
100
|
}
|
|
101
|
+
function kvArrayToObject(v) {
|
|
102
|
+
if (typeof v === "object" && v !== null && !Array.isArray(v)) return v;
|
|
103
|
+
if (!Array.isArray(v)) return {};
|
|
104
|
+
const obj = {};
|
|
105
|
+
for (let i = 0; i < v.length; i += 2) {
|
|
106
|
+
if (typeof v[i] === "string") obj[v[i]] = v[i + 1];
|
|
107
|
+
}
|
|
108
|
+
return obj;
|
|
109
|
+
}
|
|
104
110
|
|
|
105
111
|
// pkg/http.ts
|
|
106
112
|
var HttpClient = class {
|
|
@@ -348,7 +354,7 @@ var EXCLUDE_COMMANDS = /* @__PURE__ */ new Set([
|
|
|
348
354
|
"zrange",
|
|
349
355
|
"exec"
|
|
350
356
|
]);
|
|
351
|
-
function createAutoPipelineProxy(_redis,
|
|
357
|
+
function createAutoPipelineProxy(_redis, namespace = "root") {
|
|
352
358
|
const redis = _redis;
|
|
353
359
|
if (!redis.autoPipelineExecutor) {
|
|
354
360
|
redis.autoPipelineExecutor = new AutoPipelineExecutor(redis);
|
|
@@ -358,29 +364,31 @@ function createAutoPipelineProxy(_redis, json) {
|
|
|
358
364
|
if (command === "pipelineCounter") {
|
|
359
365
|
return redis2.autoPipelineExecutor.pipelineCounter;
|
|
360
366
|
}
|
|
361
|
-
if (command === "json") {
|
|
362
|
-
return createAutoPipelineProxy(redis2,
|
|
367
|
+
if (namespace === "root" && command === "json") {
|
|
368
|
+
return createAutoPipelineProxy(redis2, "json");
|
|
363
369
|
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
if (commandInRedisButNotPipeline || isCommandExcluded) {
|
|
367
|
-
return redis2[command];
|
|
370
|
+
if (namespace === "root" && command === "functions") {
|
|
371
|
+
return createAutoPipelineProxy(redis2, "functions");
|
|
368
372
|
}
|
|
369
|
-
|
|
373
|
+
if (namespace === "root") {
|
|
374
|
+
const commandInRedisButNotPipeline = command in redis2 && !(command in redis2.autoPipelineExecutor.pipeline);
|
|
375
|
+
const isCommandExcluded = EXCLUDE_COMMANDS.has(command);
|
|
376
|
+
if (commandInRedisButNotPipeline || isCommandExcluded) {
|
|
377
|
+
return redis2[command];
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
const pipeline = redis2.autoPipelineExecutor.pipeline;
|
|
381
|
+
const targetFunction = namespace === "json" ? pipeline.json[command] : namespace === "functions" ? pipeline.functions[command] : pipeline[command];
|
|
382
|
+
const isFunction = typeof targetFunction === "function";
|
|
370
383
|
if (isFunction) {
|
|
371
384
|
return (...args) => {
|
|
372
|
-
return redis2.autoPipelineExecutor.withAutoPipeline((
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
...args
|
|
376
|
-
);
|
|
377
|
-
} else {
|
|
378
|
-
pipeline[command](...args);
|
|
379
|
-
}
|
|
385
|
+
return redis2.autoPipelineExecutor.withAutoPipeline((pipeline2) => {
|
|
386
|
+
const targetFunction2 = namespace === "json" ? pipeline2.json[command] : namespace === "functions" ? pipeline2.functions[command] : pipeline2[command];
|
|
387
|
+
targetFunction2(...args);
|
|
380
388
|
});
|
|
381
389
|
};
|
|
382
390
|
}
|
|
383
|
-
return
|
|
391
|
+
return targetFunction;
|
|
384
392
|
}
|
|
385
393
|
});
|
|
386
394
|
}
|
|
@@ -403,7 +411,7 @@ var AutoPipelineExecutor = class {
|
|
|
403
411
|
this.activePipeline = pipeline;
|
|
404
412
|
this.indexInCurrentPipeline = 0;
|
|
405
413
|
}
|
|
406
|
-
const
|
|
414
|
+
const index = this.indexInCurrentPipeline++;
|
|
407
415
|
executeWithPipeline(pipeline);
|
|
408
416
|
const pipelineDone = this.deferExecution().then(() => {
|
|
409
417
|
if (!this.pipelinePromises.has(pipeline)) {
|
|
@@ -415,7 +423,7 @@ var AutoPipelineExecutor = class {
|
|
|
415
423
|
return this.pipelinePromises.get(pipeline);
|
|
416
424
|
});
|
|
417
425
|
const results = await pipelineDone;
|
|
418
|
-
const commandResult = results[
|
|
426
|
+
const commandResult = results[index];
|
|
419
427
|
if (commandResult.error) {
|
|
420
428
|
throw new UpstashError(`Command failed: ${commandResult.error}`);
|
|
421
429
|
}
|
|
@@ -673,6 +681,23 @@ var ExpireAtCommand = class extends Command {
|
|
|
673
681
|
}
|
|
674
682
|
};
|
|
675
683
|
|
|
684
|
+
// pkg/commands/fcall.ts
|
|
685
|
+
var FCallCommand = class extends Command {
|
|
686
|
+
constructor([functionName, keys, args], opts) {
|
|
687
|
+
super(["fcall", functionName, ...keys ? [keys.length, ...keys] : [0], ...args ?? []], opts);
|
|
688
|
+
}
|
|
689
|
+
};
|
|
690
|
+
|
|
691
|
+
// pkg/commands/fcall_ro.ts
|
|
692
|
+
var FCallRoCommand = class extends Command {
|
|
693
|
+
constructor([functionName, keys, args], opts) {
|
|
694
|
+
super(
|
|
695
|
+
["fcall_ro", functionName, ...keys ? [keys.length, ...keys] : [0], ...args ?? []],
|
|
696
|
+
opts
|
|
697
|
+
);
|
|
698
|
+
}
|
|
699
|
+
};
|
|
700
|
+
|
|
676
701
|
// pkg/commands/flushall.ts
|
|
677
702
|
var FlushAllCommand = class extends Command {
|
|
678
703
|
constructor(args, opts) {
|
|
@@ -695,6 +720,85 @@ var FlushDBCommand = class extends Command {
|
|
|
695
720
|
}
|
|
696
721
|
};
|
|
697
722
|
|
|
723
|
+
// pkg/commands/function_delete.ts
|
|
724
|
+
var FunctionDeleteCommand = class extends Command {
|
|
725
|
+
constructor([libraryName], opts) {
|
|
726
|
+
super(["function", "delete", libraryName], opts);
|
|
727
|
+
}
|
|
728
|
+
};
|
|
729
|
+
|
|
730
|
+
// pkg/commands/function_flush.ts
|
|
731
|
+
var FunctionFlushCommand = class extends Command {
|
|
732
|
+
constructor(opts) {
|
|
733
|
+
super(["function", "flush"], opts);
|
|
734
|
+
}
|
|
735
|
+
};
|
|
736
|
+
|
|
737
|
+
// pkg/commands/function_list.ts
|
|
738
|
+
var FunctionListCommand = class extends Command {
|
|
739
|
+
constructor([args], opts) {
|
|
740
|
+
const command = ["function", "list"];
|
|
741
|
+
if (args?.libraryName) {
|
|
742
|
+
command.push("libraryname", args.libraryName);
|
|
743
|
+
}
|
|
744
|
+
if (args?.withCode) {
|
|
745
|
+
command.push("withcode");
|
|
746
|
+
}
|
|
747
|
+
super(command, { deserialize, ...opts });
|
|
748
|
+
}
|
|
749
|
+
};
|
|
750
|
+
function deserialize(result) {
|
|
751
|
+
if (!Array.isArray(result)) return [];
|
|
752
|
+
return result.map((libRaw) => {
|
|
753
|
+
const lib = kvArrayToObject(libRaw);
|
|
754
|
+
const functionsParsed = lib.functions.map(
|
|
755
|
+
(fnRaw) => kvArrayToObject(fnRaw)
|
|
756
|
+
);
|
|
757
|
+
return {
|
|
758
|
+
libraryName: lib.library_name,
|
|
759
|
+
engine: lib.engine,
|
|
760
|
+
functions: functionsParsed.map((fn) => ({
|
|
761
|
+
name: fn.name,
|
|
762
|
+
description: fn.description ?? void 0,
|
|
763
|
+
flags: fn.flags
|
|
764
|
+
})),
|
|
765
|
+
libraryCode: lib.library_code
|
|
766
|
+
};
|
|
767
|
+
});
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
// pkg/commands/function_load.ts
|
|
771
|
+
var FunctionLoadCommand = class extends Command {
|
|
772
|
+
constructor([args], opts) {
|
|
773
|
+
super(["function", "load", ...args.replace ? ["replace"] : [], args.code], opts);
|
|
774
|
+
}
|
|
775
|
+
};
|
|
776
|
+
|
|
777
|
+
// pkg/commands/function_stats.ts
|
|
778
|
+
var FunctionStatsCommand = class extends Command {
|
|
779
|
+
constructor(opts) {
|
|
780
|
+
super(["function", "stats"], { deserialize: deserialize2, ...opts });
|
|
781
|
+
}
|
|
782
|
+
};
|
|
783
|
+
function deserialize2(result) {
|
|
784
|
+
const rawEngines = kvArrayToObject(kvArrayToObject(result).engines);
|
|
785
|
+
const parsedEngines = Object.fromEntries(
|
|
786
|
+
Object.entries(rawEngines).map(([key, value]) => [key, kvArrayToObject(value)])
|
|
787
|
+
);
|
|
788
|
+
const final = {
|
|
789
|
+
engines: Object.fromEntries(
|
|
790
|
+
Object.entries(parsedEngines).map(([key, value]) => [
|
|
791
|
+
key,
|
|
792
|
+
{
|
|
793
|
+
librariesCount: value.libraries_count,
|
|
794
|
+
functionsCount: value.functions_count
|
|
795
|
+
}
|
|
796
|
+
])
|
|
797
|
+
)
|
|
798
|
+
};
|
|
799
|
+
return final;
|
|
800
|
+
}
|
|
801
|
+
|
|
698
802
|
// pkg/commands/geo_add.ts
|
|
699
803
|
var GeoAddCommand = class extends Command {
|
|
700
804
|
constructor([key, arg1, ...arg2], opts) {
|
|
@@ -1041,7 +1145,7 @@ var HGetCommand = class extends Command {
|
|
|
1041
1145
|
};
|
|
1042
1146
|
|
|
1043
1147
|
// pkg/commands/hgetall.ts
|
|
1044
|
-
function
|
|
1148
|
+
function deserialize3(result) {
|
|
1045
1149
|
if (result.length === 0) {
|
|
1046
1150
|
return null;
|
|
1047
1151
|
}
|
|
@@ -1061,7 +1165,7 @@ function deserialize(result) {
|
|
|
1061
1165
|
var HGetAllCommand = class extends Command {
|
|
1062
1166
|
constructor(cmd, opts) {
|
|
1063
1167
|
super(["hgetall", ...cmd], {
|
|
1064
|
-
deserialize: (result) =>
|
|
1168
|
+
deserialize: (result) => deserialize3(result),
|
|
1065
1169
|
...opts
|
|
1066
1170
|
});
|
|
1067
1171
|
}
|
|
@@ -1096,7 +1200,7 @@ var HLenCommand = class extends Command {
|
|
|
1096
1200
|
};
|
|
1097
1201
|
|
|
1098
1202
|
// pkg/commands/hmget.ts
|
|
1099
|
-
function
|
|
1203
|
+
function deserialize4(fields, result) {
|
|
1100
1204
|
if (result.every((field) => field === null)) {
|
|
1101
1205
|
return null;
|
|
1102
1206
|
}
|
|
@@ -1113,7 +1217,7 @@ function deserialize2(fields, result) {
|
|
|
1113
1217
|
var HMGetCommand = class extends Command {
|
|
1114
1218
|
constructor([key, ...fields], opts) {
|
|
1115
1219
|
super(["hmget", key, ...fields], {
|
|
1116
|
-
deserialize: (result) =>
|
|
1220
|
+
deserialize: (result) => deserialize4(fields, result),
|
|
1117
1221
|
...opts
|
|
1118
1222
|
});
|
|
1119
1223
|
}
|
|
@@ -1127,7 +1231,7 @@ var HMSetCommand = class extends Command {
|
|
|
1127
1231
|
};
|
|
1128
1232
|
|
|
1129
1233
|
// pkg/commands/hrandfield.ts
|
|
1130
|
-
function
|
|
1234
|
+
function deserialize5(result) {
|
|
1131
1235
|
if (result.length === 0) {
|
|
1132
1236
|
return null;
|
|
1133
1237
|
}
|
|
@@ -1154,7 +1258,7 @@ var HRandFieldCommand = class extends Command {
|
|
|
1154
1258
|
}
|
|
1155
1259
|
super(command, {
|
|
1156
1260
|
// @ts-expect-error to silence compiler
|
|
1157
|
-
deserialize: cmd[2] ? (result) =>
|
|
1261
|
+
deserialize: cmd[2] ? (result) => deserialize5(result) : opts?.deserialize,
|
|
1158
1262
|
...opts
|
|
1159
1263
|
});
|
|
1160
1264
|
}
|
|
@@ -2124,7 +2228,7 @@ var XPendingCommand = class extends Command {
|
|
|
2124
2228
|
};
|
|
2125
2229
|
|
|
2126
2230
|
// pkg/commands/xrange.ts
|
|
2127
|
-
function
|
|
2231
|
+
function deserialize6(result) {
|
|
2128
2232
|
const obj = {};
|
|
2129
2233
|
for (const e of result) {
|
|
2130
2234
|
for (let i = 0; i < e.length; i += 2) {
|
|
@@ -2153,7 +2257,7 @@ var XRangeCommand = class extends Command {
|
|
|
2153
2257
|
command.push("COUNT", count);
|
|
2154
2258
|
}
|
|
2155
2259
|
super(command, {
|
|
2156
|
-
deserialize: (result) =>
|
|
2260
|
+
deserialize: (result) => deserialize6(result),
|
|
2157
2261
|
...opts
|
|
2158
2262
|
});
|
|
2159
2263
|
}
|
|
@@ -2216,12 +2320,12 @@ var XRevRangeCommand = class extends Command {
|
|
|
2216
2320
|
command.push("COUNT", count);
|
|
2217
2321
|
}
|
|
2218
2322
|
super(command, {
|
|
2219
|
-
deserialize: (result) =>
|
|
2323
|
+
deserialize: (result) => deserialize7(result),
|
|
2220
2324
|
...opts
|
|
2221
2325
|
});
|
|
2222
2326
|
}
|
|
2223
2327
|
};
|
|
2224
|
-
function
|
|
2328
|
+
function deserialize7(result) {
|
|
2225
2329
|
const obj = {};
|
|
2226
2330
|
for (const e of result) {
|
|
2227
2331
|
for (let i = 0; i < e.length; i += 2) {
|
|
@@ -2491,352 +2595,6 @@ var ZUnionStoreCommand = class extends Command {
|
|
|
2491
2595
|
}
|
|
2492
2596
|
};
|
|
2493
2597
|
|
|
2494
|
-
// pkg/commands/search/types.ts
|
|
2495
|
-
var FIELD_TYPES = ["TEXT", "U64", "I64", "F64", "BOOL", "DATE"];
|
|
2496
|
-
|
|
2497
|
-
// pkg/commands/search/utils.ts
|
|
2498
|
-
function isFieldType(value) {
|
|
2499
|
-
return typeof value === "string" && FIELD_TYPES.includes(value);
|
|
2500
|
-
}
|
|
2501
|
-
function isDetailedField(value) {
|
|
2502
|
-
return typeof value === "object" && value !== null && "type" in value && isFieldType(value.type);
|
|
2503
|
-
}
|
|
2504
|
-
function isNestedSchema(value) {
|
|
2505
|
-
return typeof value === "object" && value !== null && !isDetailedField(value);
|
|
2506
|
-
}
|
|
2507
|
-
function flattenSchema(schema, pathPrefix = []) {
|
|
2508
|
-
const fields = [];
|
|
2509
|
-
for (const [key, value] of Object.entries(schema)) {
|
|
2510
|
-
const currentPath = [...pathPrefix, key];
|
|
2511
|
-
const pathString = currentPath.join(".");
|
|
2512
|
-
if (isFieldType(value)) {
|
|
2513
|
-
fields.push({
|
|
2514
|
-
path: pathString,
|
|
2515
|
-
type: value
|
|
2516
|
-
});
|
|
2517
|
-
} else if (isDetailedField(value)) {
|
|
2518
|
-
fields.push({
|
|
2519
|
-
path: pathString,
|
|
2520
|
-
type: value.type,
|
|
2521
|
-
fast: "fast" in value ? value.fast : void 0,
|
|
2522
|
-
noTokenize: "noTokenize" in value ? value.noTokenize : void 0,
|
|
2523
|
-
noStem: "noStem" in value ? value.noStem : void 0
|
|
2524
|
-
});
|
|
2525
|
-
} else if (isNestedSchema(value)) {
|
|
2526
|
-
const nestedFields = flattenSchema(value, currentPath);
|
|
2527
|
-
fields.push(...nestedFields);
|
|
2528
|
-
}
|
|
2529
|
-
}
|
|
2530
|
-
return fields;
|
|
2531
|
-
}
|
|
2532
|
-
function deserializeQueryResponse(rawResponse, options) {
|
|
2533
|
-
const hasEmptySelect = options?.select && Object.keys(options.select).length === 0;
|
|
2534
|
-
return rawResponse.map((itemRaw) => {
|
|
2535
|
-
const raw = itemRaw;
|
|
2536
|
-
const key = raw[0];
|
|
2537
|
-
const score = raw[1];
|
|
2538
|
-
const rawFields = raw[2];
|
|
2539
|
-
if (hasEmptySelect) {
|
|
2540
|
-
return { key, score };
|
|
2541
|
-
}
|
|
2542
|
-
if (!Array.isArray(rawFields) || rawFields.length === 0) {
|
|
2543
|
-
return { key, score, data: {} };
|
|
2544
|
-
}
|
|
2545
|
-
const mergedFields = {};
|
|
2546
|
-
for (const fieldRaw of rawFields) {
|
|
2547
|
-
const fieldObj = kvArrayToObject(fieldRaw);
|
|
2548
|
-
Object.assign(mergedFields, fieldObj);
|
|
2549
|
-
}
|
|
2550
|
-
if ("$" in mergedFields) {
|
|
2551
|
-
const data2 = mergedFields["$"];
|
|
2552
|
-
return { key, score, data: data2 };
|
|
2553
|
-
}
|
|
2554
|
-
const data = dotNotationToNested(mergedFields);
|
|
2555
|
-
return { key, score, data };
|
|
2556
|
-
});
|
|
2557
|
-
}
|
|
2558
|
-
function parseFieldInfo(fieldRaw) {
|
|
2559
|
-
const fieldType = fieldRaw[1];
|
|
2560
|
-
const options = fieldRaw.slice(2);
|
|
2561
|
-
const fieldInfo = { type: fieldType };
|
|
2562
|
-
for (const option of options) {
|
|
2563
|
-
switch (option.toUpperCase()) {
|
|
2564
|
-
case "NOTOKENIZE":
|
|
2565
|
-
fieldInfo.noTokenize = true;
|
|
2566
|
-
break;
|
|
2567
|
-
case "NOSTEM":
|
|
2568
|
-
fieldInfo.noStem = true;
|
|
2569
|
-
break;
|
|
2570
|
-
case "FAST":
|
|
2571
|
-
fieldInfo.fast = true;
|
|
2572
|
-
break;
|
|
2573
|
-
}
|
|
2574
|
-
}
|
|
2575
|
-
return fieldInfo;
|
|
2576
|
-
}
|
|
2577
|
-
function deserializeDescribeResponse(rawResponse) {
|
|
2578
|
-
const raw = kvArrayToObject(rawResponse);
|
|
2579
|
-
const schema = {};
|
|
2580
|
-
if (Array.isArray(raw.schema)) {
|
|
2581
|
-
for (const fieldRaw of raw.schema) {
|
|
2582
|
-
if (Array.isArray(fieldRaw) && fieldRaw.length >= 2) {
|
|
2583
|
-
const fieldName = fieldRaw[0];
|
|
2584
|
-
schema[fieldName] = parseFieldInfo(fieldRaw);
|
|
2585
|
-
}
|
|
2586
|
-
}
|
|
2587
|
-
}
|
|
2588
|
-
return {
|
|
2589
|
-
name: raw.name,
|
|
2590
|
-
dataType: raw.type.toLowerCase(),
|
|
2591
|
-
prefixes: raw.prefixes,
|
|
2592
|
-
...raw.language && { language: raw.language },
|
|
2593
|
-
schema
|
|
2594
|
-
};
|
|
2595
|
-
}
|
|
2596
|
-
function parseCountResponse(rawResponse) {
|
|
2597
|
-
return typeof rawResponse === "number" ? rawResponse : parseInt(rawResponse, 10);
|
|
2598
|
-
}
|
|
2599
|
-
function kvArrayToObject(v) {
|
|
2600
|
-
if (typeof v === "object" && v !== null && !Array.isArray(v)) return v;
|
|
2601
|
-
if (!Array.isArray(v)) return {};
|
|
2602
|
-
const obj = {};
|
|
2603
|
-
for (let i = 0; i < v.length; i += 2) {
|
|
2604
|
-
if (typeof v[i] === "string") obj[v[i]] = v[i + 1];
|
|
2605
|
-
}
|
|
2606
|
-
return obj;
|
|
2607
|
-
}
|
|
2608
|
-
function dotNotationToNested(obj) {
|
|
2609
|
-
const result = {};
|
|
2610
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
2611
|
-
const parts = key.split(".");
|
|
2612
|
-
let current = result;
|
|
2613
|
-
for (let i = 0; i < parts.length - 1; i++) {
|
|
2614
|
-
const part = parts[i];
|
|
2615
|
-
if (!(part in current)) {
|
|
2616
|
-
current[part] = {};
|
|
2617
|
-
}
|
|
2618
|
-
current = current[part];
|
|
2619
|
-
}
|
|
2620
|
-
current[parts[parts.length - 1]] = value;
|
|
2621
|
-
}
|
|
2622
|
-
return result;
|
|
2623
|
-
}
|
|
2624
|
-
|
|
2625
|
-
// pkg/commands/search/command-builder.ts
|
|
2626
|
-
function buildQueryCommand(redisCommand, name, options) {
|
|
2627
|
-
const query = JSON.stringify(options?.filter);
|
|
2628
|
-
const command = [redisCommand, name, query];
|
|
2629
|
-
if (options?.limit !== void 0) {
|
|
2630
|
-
command.push("LIMIT", options.limit.toString());
|
|
2631
|
-
}
|
|
2632
|
-
if (options?.offset !== void 0) {
|
|
2633
|
-
command.push("OFFSET", options.offset.toString());
|
|
2634
|
-
}
|
|
2635
|
-
if (options?.select && Object.keys(options.select).length === 0) {
|
|
2636
|
-
command.push("NOCONTENT");
|
|
2637
|
-
}
|
|
2638
|
-
if (options?.orderBy) {
|
|
2639
|
-
command.push("SORTBY");
|
|
2640
|
-
Object.entries(options.orderBy).forEach(([field, direction]) => {
|
|
2641
|
-
command.push(field, direction);
|
|
2642
|
-
});
|
|
2643
|
-
}
|
|
2644
|
-
if (options?.highlight) {
|
|
2645
|
-
command.push(
|
|
2646
|
-
"HIGHLIGHT",
|
|
2647
|
-
"FIELDS",
|
|
2648
|
-
options.highlight.fields.length.toString(),
|
|
2649
|
-
...options.highlight.fields
|
|
2650
|
-
);
|
|
2651
|
-
if (options.highlight.preTag && options.highlight.postTag) {
|
|
2652
|
-
command.push("TAGS", options.highlight.preTag, options.highlight.postTag);
|
|
2653
|
-
}
|
|
2654
|
-
}
|
|
2655
|
-
if (options?.select && Object.keys(options.select).length > 0) {
|
|
2656
|
-
command.push(
|
|
2657
|
-
"RETURN",
|
|
2658
|
-
Object.keys(options.select).length.toString(),
|
|
2659
|
-
...Object.keys(options.select)
|
|
2660
|
-
);
|
|
2661
|
-
}
|
|
2662
|
-
return command;
|
|
2663
|
-
}
|
|
2664
|
-
function buildCreateIndexCommand(props) {
|
|
2665
|
-
const { name, schema, dataType, prefix, language } = props;
|
|
2666
|
-
const prefixArray = Array.isArray(prefix) ? prefix : [prefix];
|
|
2667
|
-
const payload = [
|
|
2668
|
-
name,
|
|
2669
|
-
"ON",
|
|
2670
|
-
dataType.toUpperCase(),
|
|
2671
|
-
"PREFIX",
|
|
2672
|
-
prefixArray.length.toString(),
|
|
2673
|
-
...prefixArray,
|
|
2674
|
-
...language ? ["LANGUAGE", language] : [],
|
|
2675
|
-
"SCHEMA"
|
|
2676
|
-
];
|
|
2677
|
-
const fields = flattenSchema(schema);
|
|
2678
|
-
for (const field of fields) {
|
|
2679
|
-
payload.push(field.path, field.type);
|
|
2680
|
-
if (field.fast) {
|
|
2681
|
-
payload.push("FAST");
|
|
2682
|
-
}
|
|
2683
|
-
if (field.noTokenize) {
|
|
2684
|
-
payload.push("NOTOKENIZE");
|
|
2685
|
-
}
|
|
2686
|
-
if (field.noStem) {
|
|
2687
|
-
payload.push("NOSTEM");
|
|
2688
|
-
}
|
|
2689
|
-
}
|
|
2690
|
-
return ["SEARCH.CREATE", ...payload];
|
|
2691
|
-
}
|
|
2692
|
-
|
|
2693
|
-
// pkg/commands/search/search.ts
|
|
2694
|
-
var SearchIndex = class {
|
|
2695
|
-
name;
|
|
2696
|
-
schema;
|
|
2697
|
-
client;
|
|
2698
|
-
constructor({ name, schema, client }) {
|
|
2699
|
-
this.name = name;
|
|
2700
|
-
this.schema = schema;
|
|
2701
|
-
this.client = client;
|
|
2702
|
-
}
|
|
2703
|
-
async waitIndexing() {
|
|
2704
|
-
const command = ["SEARCH.COMMIT", this.name];
|
|
2705
|
-
const result = await new ExecCommand(command).exec(
|
|
2706
|
-
this.client
|
|
2707
|
-
);
|
|
2708
|
-
return result;
|
|
2709
|
-
}
|
|
2710
|
-
async describe() {
|
|
2711
|
-
const command = ["SEARCH.DESCRIBE", this.name];
|
|
2712
|
-
const rawResult = await new ExecCommand(command).exec(
|
|
2713
|
-
this.client
|
|
2714
|
-
);
|
|
2715
|
-
return deserializeDescribeResponse(rawResult);
|
|
2716
|
-
}
|
|
2717
|
-
async query(options) {
|
|
2718
|
-
const command = buildQueryCommand("SEARCH.QUERY", this.name, options);
|
|
2719
|
-
const rawResult = await new ExecCommand(command).exec(
|
|
2720
|
-
this.client
|
|
2721
|
-
);
|
|
2722
|
-
return deserializeQueryResponse(rawResult, options);
|
|
2723
|
-
}
|
|
2724
|
-
async count({ filter }) {
|
|
2725
|
-
const command = buildQueryCommand("SEARCH.COUNT", this.name, { filter });
|
|
2726
|
-
const rawResult = await new ExecCommand(command).exec(
|
|
2727
|
-
this.client
|
|
2728
|
-
);
|
|
2729
|
-
return { count: parseCountResponse(rawResult) };
|
|
2730
|
-
}
|
|
2731
|
-
async drop() {
|
|
2732
|
-
const command = ["SEARCH.DROP", this.name];
|
|
2733
|
-
const result = await new ExecCommand(command).exec(
|
|
2734
|
-
this.client
|
|
2735
|
-
);
|
|
2736
|
-
return result;
|
|
2737
|
-
}
|
|
2738
|
-
};
|
|
2739
|
-
async function createIndex(props) {
|
|
2740
|
-
const { name, schema, client } = props;
|
|
2741
|
-
const createIndexCommand = buildCreateIndexCommand(props);
|
|
2742
|
-
await new ExecCommand(createIndexCommand).exec(client);
|
|
2743
|
-
return index(client, name, schema);
|
|
2744
|
-
}
|
|
2745
|
-
function index(client, name, schema) {
|
|
2746
|
-
return new SearchIndex({ name, schema, client });
|
|
2747
|
-
}
|
|
2748
|
-
|
|
2749
|
-
// pkg/commands/search/schema-builder.ts
|
|
2750
|
-
var BUILD = Symbol("build");
|
|
2751
|
-
var TextFieldBuilder = class _TextFieldBuilder {
|
|
2752
|
-
_noTokenize;
|
|
2753
|
-
_noStem;
|
|
2754
|
-
constructor(noTokenize = { noTokenize: false }, noStem = { noStem: false }) {
|
|
2755
|
-
this._noTokenize = noTokenize;
|
|
2756
|
-
this._noStem = noStem;
|
|
2757
|
-
}
|
|
2758
|
-
noTokenize() {
|
|
2759
|
-
return new _TextFieldBuilder({ noTokenize: true }, this._noStem);
|
|
2760
|
-
}
|
|
2761
|
-
noStem() {
|
|
2762
|
-
return new _TextFieldBuilder(this._noTokenize, { noStem: true });
|
|
2763
|
-
}
|
|
2764
|
-
[BUILD]() {
|
|
2765
|
-
return this._noTokenize.noTokenize || this._noStem.noStem ? {
|
|
2766
|
-
type: "TEXT",
|
|
2767
|
-
...this._noTokenize.noTokenize ? { noTokenize: true } : {},
|
|
2768
|
-
...this._noStem.noStem ? { noStem: true } : {}
|
|
2769
|
-
} : "TEXT";
|
|
2770
|
-
}
|
|
2771
|
-
};
|
|
2772
|
-
var NumericFieldBuilder = class {
|
|
2773
|
-
type;
|
|
2774
|
-
constructor(type) {
|
|
2775
|
-
this.type = type;
|
|
2776
|
-
}
|
|
2777
|
-
[BUILD]() {
|
|
2778
|
-
return {
|
|
2779
|
-
type: this.type,
|
|
2780
|
-
fast: true
|
|
2781
|
-
};
|
|
2782
|
-
}
|
|
2783
|
-
};
|
|
2784
|
-
var BoolFieldBuilder = class _BoolFieldBuilder {
|
|
2785
|
-
_fast;
|
|
2786
|
-
constructor(fast = { fast: false }) {
|
|
2787
|
-
this._fast = fast;
|
|
2788
|
-
}
|
|
2789
|
-
fast() {
|
|
2790
|
-
return new _BoolFieldBuilder({ fast: true });
|
|
2791
|
-
}
|
|
2792
|
-
[BUILD]() {
|
|
2793
|
-
return this._fast.fast ? {
|
|
2794
|
-
type: "BOOL",
|
|
2795
|
-
fast: true
|
|
2796
|
-
} : "BOOL";
|
|
2797
|
-
}
|
|
2798
|
-
};
|
|
2799
|
-
var DateFieldBuilder = class _DateFieldBuilder {
|
|
2800
|
-
_fast;
|
|
2801
|
-
constructor(fast = { fast: false }) {
|
|
2802
|
-
this._fast = fast;
|
|
2803
|
-
}
|
|
2804
|
-
fast() {
|
|
2805
|
-
return new _DateFieldBuilder({ fast: true });
|
|
2806
|
-
}
|
|
2807
|
-
[BUILD]() {
|
|
2808
|
-
return this._fast.fast ? {
|
|
2809
|
-
type: "DATE",
|
|
2810
|
-
fast: true
|
|
2811
|
-
} : "DATE";
|
|
2812
|
-
}
|
|
2813
|
-
};
|
|
2814
|
-
var s = {
|
|
2815
|
-
string() {
|
|
2816
|
-
return new TextFieldBuilder();
|
|
2817
|
-
},
|
|
2818
|
-
number(type = "F64") {
|
|
2819
|
-
return new NumericFieldBuilder(type);
|
|
2820
|
-
},
|
|
2821
|
-
boolean() {
|
|
2822
|
-
return new BoolFieldBuilder();
|
|
2823
|
-
},
|
|
2824
|
-
date() {
|
|
2825
|
-
return new DateFieldBuilder();
|
|
2826
|
-
},
|
|
2827
|
-
object(fields) {
|
|
2828
|
-
const result = {};
|
|
2829
|
-
for (const [key, value] of Object.entries(fields)) {
|
|
2830
|
-
if (value && typeof value === "object" && BUILD in value) {
|
|
2831
|
-
result[key] = value[BUILD]();
|
|
2832
|
-
} else {
|
|
2833
|
-
result[key] = value;
|
|
2834
|
-
}
|
|
2835
|
-
}
|
|
2836
|
-
return result;
|
|
2837
|
-
}
|
|
2838
|
-
};
|
|
2839
|
-
|
|
2840
2598
|
// pkg/commands/psubscribe.ts
|
|
2841
2599
|
var PSubscribeCommand = class extends Command {
|
|
2842
2600
|
constructor(cmd, opts) {
|
|
@@ -3410,7 +3168,7 @@ var Pipeline = class {
|
|
|
3410
3168
|
/**
|
|
3411
3169
|
* @see https://redis.io/commands/lset
|
|
3412
3170
|
*/
|
|
3413
|
-
lset = (key,
|
|
3171
|
+
lset = (key, index, value) => this.chain(new LSetCommand([key, index, value], this.commandOptions));
|
|
3414
3172
|
/**
|
|
3415
3173
|
* @see https://redis.io/commands/ltrim
|
|
3416
3174
|
*/
|
|
@@ -3862,6 +3620,38 @@ var Pipeline = class {
|
|
|
3862
3620
|
type: (...args) => this.chain(new JsonTypeCommand(args, this.commandOptions))
|
|
3863
3621
|
};
|
|
3864
3622
|
}
|
|
3623
|
+
get functions() {
|
|
3624
|
+
return {
|
|
3625
|
+
/**
|
|
3626
|
+
* @see https://redis.io/docs/latest/commands/function-load/
|
|
3627
|
+
*/
|
|
3628
|
+
load: (...args) => this.chain(new FunctionLoadCommand(args, this.commandOptions)),
|
|
3629
|
+
/**
|
|
3630
|
+
* @see https://redis.io/docs/latest/commands/function-list/
|
|
3631
|
+
*/
|
|
3632
|
+
list: (...args) => this.chain(new FunctionListCommand(args, this.commandOptions)),
|
|
3633
|
+
/**
|
|
3634
|
+
* @see https://redis.io/docs/latest/commands/function-delete/
|
|
3635
|
+
*/
|
|
3636
|
+
delete: (...args) => this.chain(new FunctionDeleteCommand(args, this.commandOptions)),
|
|
3637
|
+
/**
|
|
3638
|
+
* @see https://redis.io/docs/latest/commands/function-flush/
|
|
3639
|
+
*/
|
|
3640
|
+
flush: () => this.chain(new FunctionFlushCommand(this.commandOptions)),
|
|
3641
|
+
/**
|
|
3642
|
+
* @see https://redis.io/docs/latest/commands/function-stats/
|
|
3643
|
+
*/
|
|
3644
|
+
stats: () => this.chain(new FunctionStatsCommand(this.commandOptions)),
|
|
3645
|
+
/**
|
|
3646
|
+
* @see https://redis.io/docs/latest/commands/fcall/
|
|
3647
|
+
*/
|
|
3648
|
+
call: (...args) => this.chain(new FCallCommand(args, this.commandOptions)),
|
|
3649
|
+
/**
|
|
3650
|
+
* @see https://redis.io/docs/latest/commands/fcall_ro/
|
|
3651
|
+
*/
|
|
3652
|
+
callRo: (...args) => this.chain(new FCallRoCommand(args, this.commandOptions))
|
|
3653
|
+
};
|
|
3654
|
+
}
|
|
3865
3655
|
};
|
|
3866
3656
|
|
|
3867
3657
|
// pkg/script.ts
|
|
@@ -3923,8 +3713,8 @@ var Script = class {
|
|
|
3923
3713
|
/**
|
|
3924
3714
|
* Compute the sha1 hash of the script and return its hex representation.
|
|
3925
3715
|
*/
|
|
3926
|
-
async digest(
|
|
3927
|
-
const data = new TextEncoder().encode(
|
|
3716
|
+
async digest(s) {
|
|
3717
|
+
const data = new TextEncoder().encode(s);
|
|
3928
3718
|
const hashBuffer = await import_uncrypto.subtle.digest("SHA-1", data);
|
|
3929
3719
|
const hashArray = [...new Uint8Array(hashBuffer)];
|
|
3930
3720
|
return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
@@ -3987,8 +3777,8 @@ var ScriptRO = class {
|
|
|
3987
3777
|
/**
|
|
3988
3778
|
* Compute the sha1 hash of the script and return its hex representation.
|
|
3989
3779
|
*/
|
|
3990
|
-
async digest(
|
|
3991
|
-
const data = new TextEncoder().encode(
|
|
3780
|
+
async digest(s) {
|
|
3781
|
+
const data = new TextEncoder().encode(s);
|
|
3992
3782
|
const hashBuffer = await import_uncrypto2.subtle.digest("SHA-1", data);
|
|
3993
3783
|
const hashArray = [...new Uint8Array(hashBuffer)];
|
|
3994
3784
|
return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
@@ -4123,6 +3913,40 @@ var Redis = class {
|
|
|
4123
3913
|
type: (...args) => new JsonTypeCommand(args, this.opts).exec(this.client)
|
|
4124
3914
|
};
|
|
4125
3915
|
}
|
|
3916
|
+
get functions() {
|
|
3917
|
+
return {
|
|
3918
|
+
/**
|
|
3919
|
+
* @see https://redis.io/docs/latest/commands/function-load/
|
|
3920
|
+
*/
|
|
3921
|
+
load: (...args) => new FunctionLoadCommand(args, this.opts).exec(this.client),
|
|
3922
|
+
/**
|
|
3923
|
+
* @see https://redis.io/docs/latest/commands/function-list/
|
|
3924
|
+
*/
|
|
3925
|
+
list: (...args) => new FunctionListCommand(args, this.opts).exec(this.client),
|
|
3926
|
+
/**
|
|
3927
|
+
* @see https://redis.io/docs/latest/commands/function-delete/
|
|
3928
|
+
*/
|
|
3929
|
+
delete: (...args) => new FunctionDeleteCommand(args, this.opts).exec(this.client),
|
|
3930
|
+
/**
|
|
3931
|
+
* @see https://redis.io/docs/latest/commands/function-flush/
|
|
3932
|
+
*/
|
|
3933
|
+
flush: () => new FunctionFlushCommand(this.opts).exec(this.client),
|
|
3934
|
+
/**
|
|
3935
|
+
* @see https://redis.io/docs/latest/commands/function-stats/
|
|
3936
|
+
*
|
|
3937
|
+
* Note: `running_script` field is not supported and therefore not included in the type.
|
|
3938
|
+
*/
|
|
3939
|
+
stats: () => new FunctionStatsCommand(this.opts).exec(this.client),
|
|
3940
|
+
/**
|
|
3941
|
+
* @see https://redis.io/docs/latest/commands/fcall/
|
|
3942
|
+
*/
|
|
3943
|
+
call: (...args) => new FCallCommand(args, this.opts).exec(this.client),
|
|
3944
|
+
/**
|
|
3945
|
+
* @see https://redis.io/docs/latest/commands/fcall_ro/
|
|
3946
|
+
*/
|
|
3947
|
+
callRo: (...args) => new FCallRoCommand(args, this.opts).exec(this.client)
|
|
3948
|
+
};
|
|
3949
|
+
}
|
|
4126
3950
|
/**
|
|
4127
3951
|
* Wrap a new middleware around the HTTP client.
|
|
4128
3952
|
*/
|
|
@@ -4173,19 +3997,6 @@ var Redis = class {
|
|
|
4173
3997
|
createScript(script, opts) {
|
|
4174
3998
|
return opts?.readonly ? new ScriptRO(this, script) : new Script(this, script);
|
|
4175
3999
|
}
|
|
4176
|
-
get search() {
|
|
4177
|
-
return {
|
|
4178
|
-
createIndex: (props) => {
|
|
4179
|
-
return createIndex({
|
|
4180
|
-
...props,
|
|
4181
|
-
client: this.client
|
|
4182
|
-
});
|
|
4183
|
-
},
|
|
4184
|
-
index: (name, schema) => {
|
|
4185
|
-
return index(this.client, name, schema);
|
|
4186
|
-
}
|
|
4187
|
-
};
|
|
4188
|
-
}
|
|
4189
4000
|
/**
|
|
4190
4001
|
* Create a new pipeline that allows you to send requests in bulk.
|
|
4191
4002
|
*
|
|
@@ -4522,7 +4333,7 @@ var Redis = class {
|
|
|
4522
4333
|
/**
|
|
4523
4334
|
* @see https://redis.io/commands/lset
|
|
4524
4335
|
*/
|
|
4525
|
-
lset = (key,
|
|
4336
|
+
lset = (key, index, value) => new LSetCommand([key, index, value], this.opts).exec(this.client);
|
|
4526
4337
|
/**
|
|
4527
4338
|
* @see https://redis.io/commands/ltrim
|
|
4528
4339
|
*/
|
|
@@ -4893,7 +4704,7 @@ var Redis = class {
|
|
|
4893
4704
|
};
|
|
4894
4705
|
|
|
4895
4706
|
// version.ts
|
|
4896
|
-
var VERSION = "v1.36.0
|
|
4707
|
+
var VERSION = "v1.36.0";
|
|
4897
4708
|
|
|
4898
4709
|
// platforms/nodejs.ts
|
|
4899
4710
|
if (typeof atob === "undefined") {
|
|
@@ -4951,18 +4762,20 @@ var Redis2 = class _Redis extends Redis {
|
|
|
4951
4762
|
keepAlive: configOrRequester.keepAlive,
|
|
4952
4763
|
readYourWrites: configOrRequester.readYourWrites
|
|
4953
4764
|
});
|
|
4765
|
+
const safeEnv = typeof process === "object" && process && typeof process.env === "object" && process.env ? process.env : {};
|
|
4954
4766
|
super(client, {
|
|
4955
4767
|
automaticDeserialization: configOrRequester.automaticDeserialization,
|
|
4956
|
-
enableTelemetry: configOrRequester.enableTelemetry ?? !
|
|
4768
|
+
enableTelemetry: configOrRequester.enableTelemetry ?? !safeEnv.UPSTASH_DISABLE_TELEMETRY,
|
|
4957
4769
|
latencyLogging: configOrRequester.latencyLogging,
|
|
4958
4770
|
enableAutoPipelining: configOrRequester.enableAutoPipelining
|
|
4959
4771
|
});
|
|
4772
|
+
const nodeVersion = typeof process === "object" && process ? process.version : void 0;
|
|
4960
4773
|
this.addTelemetry({
|
|
4961
4774
|
runtime: (
|
|
4962
4775
|
// @ts-expect-error to silence compiler
|
|
4963
|
-
typeof EdgeRuntime === "string" ? "edge-light" : `node@${
|
|
4776
|
+
typeof EdgeRuntime === "string" ? "edge-light" : nodeVersion ? `node@${nodeVersion}` : "unknown"
|
|
4964
4777
|
),
|
|
4965
|
-
platform:
|
|
4778
|
+
platform: safeEnv.UPSTASH_CONSOLE ? "console" : safeEnv.VERCEL ? "vercel" : safeEnv.AWS_REGION ? "aws" : "unknown",
|
|
4966
4779
|
sdk: `@upstash/redis@${VERSION}`
|
|
4967
4780
|
});
|
|
4968
4781
|
if (this.enableAutoPipelining) {
|
|
@@ -4983,7 +4796,7 @@ var Redis2 = class _Redis extends Redis {
|
|
|
4983
4796
|
* that may use different naming conventions.
|
|
4984
4797
|
*/
|
|
4985
4798
|
static fromEnv(config) {
|
|
4986
|
-
if (process.env
|
|
4799
|
+
if (typeof process !== "object" || !process || typeof process.env !== "object" || !process.env) {
|
|
4987
4800
|
throw new TypeError(
|
|
4988
4801
|
'[Upstash Redis] Unable to get environment variables, `process.env` is undefined. If you are deploying to cloudflare, please import from "@upstash/redis/cloudflare" instead'
|
|
4989
4802
|
);
|
|
@@ -5004,8 +4817,5 @@ var Redis2 = class _Redis extends Redis {
|
|
|
5004
4817
|
// Annotate the CommonJS export names for ESM import in node:
|
|
5005
4818
|
0 && (module.exports = {
|
|
5006
4819
|
Redis,
|
|
5007
|
-
|
|
5008
|
-
errors,
|
|
5009
|
-
index,
|
|
5010
|
-
s
|
|
4820
|
+
errors
|
|
5011
4821
|
});
|