@upstash/redis 1.36.1 → 1.37.0-rc.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/{chunk-LLI2WIYN.mjs → chunk-PDHDP2I5.mjs} +297 -207
- package/cloudflare.d.mts +2 -2
- package/cloudflare.d.ts +2 -2
- package/cloudflare.js +308 -222
- package/cloudflare.mjs +10 -14
- package/fastly.d.mts +2 -2
- package/fastly.d.ts +2 -2
- package/fastly.js +299 -209
- package/fastly.mjs +1 -1
- package/nodejs.d.mts +144 -3
- package/nodejs.d.ts +144 -3
- package/nodejs.js +464 -221
- package/nodejs.mjs +160 -8
- package/package.json +1 -1
- package/{zmscore-0SAuWM0q.d.mts → zmscore-BpOSd5F5.d.mts} +347 -126
- package/{zmscore-0SAuWM0q.d.ts → zmscore-BpOSd5F5.d.ts} +347 -126
package/nodejs.js
CHANGED
|
@@ -21,7 +21,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var nodejs_exports = {};
|
|
22
22
|
__export(nodejs_exports, {
|
|
23
23
|
Redis: () => Redis2,
|
|
24
|
-
errors: () => error_exports
|
|
24
|
+
errors: () => error_exports,
|
|
25
|
+
s: () => s
|
|
25
26
|
});
|
|
26
27
|
module.exports = __toCommonJS(nodejs_exports);
|
|
27
28
|
|
|
@@ -98,18 +99,8 @@ function mergeHeaders(...headers) {
|
|
|
98
99
|
}
|
|
99
100
|
return merged;
|
|
100
101
|
}
|
|
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
|
-
}
|
|
110
102
|
|
|
111
103
|
// pkg/http.ts
|
|
112
|
-
var MAX_BUFFER_SIZE = 1024 * 1024;
|
|
113
104
|
var HttpClient = class {
|
|
114
105
|
baseUrl;
|
|
115
106
|
headers;
|
|
@@ -233,16 +224,11 @@ var HttpClient = class {
|
|
|
233
224
|
const decoder = new TextDecoder();
|
|
234
225
|
(async () => {
|
|
235
226
|
try {
|
|
236
|
-
let buffer = "";
|
|
237
227
|
while (true) {
|
|
238
228
|
const { value, done } = await reader.read();
|
|
239
229
|
if (done) break;
|
|
240
|
-
|
|
241
|
-
const lines =
|
|
242
|
-
buffer = lines.pop() || "";
|
|
243
|
-
if (buffer.length > MAX_BUFFER_SIZE) {
|
|
244
|
-
throw new Error("Buffer size exceeded (1MB)");
|
|
245
|
-
}
|
|
230
|
+
const chunk = decoder.decode(value);
|
|
231
|
+
const lines = chunk.split("\n");
|
|
246
232
|
for (const line of lines) {
|
|
247
233
|
if (line.startsWith("data: ")) {
|
|
248
234
|
const data = line.slice(6);
|
|
@@ -360,7 +346,7 @@ var EXCLUDE_COMMANDS = /* @__PURE__ */ new Set([
|
|
|
360
346
|
"zrange",
|
|
361
347
|
"exec"
|
|
362
348
|
]);
|
|
363
|
-
function createAutoPipelineProxy(_redis,
|
|
349
|
+
function createAutoPipelineProxy(_redis, json) {
|
|
364
350
|
const redis = _redis;
|
|
365
351
|
if (!redis.autoPipelineExecutor) {
|
|
366
352
|
redis.autoPipelineExecutor = new AutoPipelineExecutor(redis);
|
|
@@ -370,31 +356,29 @@ function createAutoPipelineProxy(_redis, namespace = "root") {
|
|
|
370
356
|
if (command === "pipelineCounter") {
|
|
371
357
|
return redis2.autoPipelineExecutor.pipelineCounter;
|
|
372
358
|
}
|
|
373
|
-
if (
|
|
374
|
-
return createAutoPipelineProxy(redis2,
|
|
375
|
-
}
|
|
376
|
-
if (namespace === "root" && command === "functions") {
|
|
377
|
-
return createAutoPipelineProxy(redis2, "functions");
|
|
359
|
+
if (command === "json") {
|
|
360
|
+
return createAutoPipelineProxy(redis2, true);
|
|
378
361
|
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
return redis2[command];
|
|
384
|
-
}
|
|
362
|
+
const commandInRedisButNotPipeline = command in redis2 && !(command in redis2.autoPipelineExecutor.pipeline);
|
|
363
|
+
const isCommandExcluded = EXCLUDE_COMMANDS.has(command);
|
|
364
|
+
if (commandInRedisButNotPipeline || isCommandExcluded) {
|
|
365
|
+
return redis2[command];
|
|
385
366
|
}
|
|
386
|
-
const
|
|
387
|
-
const targetFunction = namespace === "json" ? pipeline.json[command] : namespace === "functions" ? pipeline.functions[command] : pipeline[command];
|
|
388
|
-
const isFunction = typeof targetFunction === "function";
|
|
367
|
+
const isFunction = json ? typeof redis2.autoPipelineExecutor.pipeline.json[command] === "function" : typeof redis2.autoPipelineExecutor.pipeline[command] === "function";
|
|
389
368
|
if (isFunction) {
|
|
390
369
|
return (...args) => {
|
|
391
|
-
return redis2.autoPipelineExecutor.withAutoPipeline((
|
|
392
|
-
|
|
393
|
-
|
|
370
|
+
return redis2.autoPipelineExecutor.withAutoPipeline((pipeline) => {
|
|
371
|
+
if (json) {
|
|
372
|
+
pipeline.json[command](
|
|
373
|
+
...args
|
|
374
|
+
);
|
|
375
|
+
} else {
|
|
376
|
+
pipeline[command](...args);
|
|
377
|
+
}
|
|
394
378
|
});
|
|
395
379
|
};
|
|
396
380
|
}
|
|
397
|
-
return
|
|
381
|
+
return redis2.autoPipelineExecutor.pipeline[command];
|
|
398
382
|
}
|
|
399
383
|
});
|
|
400
384
|
}
|
|
@@ -687,23 +671,6 @@ var ExpireAtCommand = class extends Command {
|
|
|
687
671
|
}
|
|
688
672
|
};
|
|
689
673
|
|
|
690
|
-
// pkg/commands/fcall.ts
|
|
691
|
-
var FCallCommand = class extends Command {
|
|
692
|
-
constructor([functionName, keys, args], opts) {
|
|
693
|
-
super(["fcall", functionName, ...keys ? [keys.length, ...keys] : [0], ...args ?? []], opts);
|
|
694
|
-
}
|
|
695
|
-
};
|
|
696
|
-
|
|
697
|
-
// pkg/commands/fcall_ro.ts
|
|
698
|
-
var FCallRoCommand = class extends Command {
|
|
699
|
-
constructor([functionName, keys, args], opts) {
|
|
700
|
-
super(
|
|
701
|
-
["fcall_ro", functionName, ...keys ? [keys.length, ...keys] : [0], ...args ?? []],
|
|
702
|
-
opts
|
|
703
|
-
);
|
|
704
|
-
}
|
|
705
|
-
};
|
|
706
|
-
|
|
707
674
|
// pkg/commands/flushall.ts
|
|
708
675
|
var FlushAllCommand = class extends Command {
|
|
709
676
|
constructor(args, opts) {
|
|
@@ -726,85 +693,6 @@ var FlushDBCommand = class extends Command {
|
|
|
726
693
|
}
|
|
727
694
|
};
|
|
728
695
|
|
|
729
|
-
// pkg/commands/function_delete.ts
|
|
730
|
-
var FunctionDeleteCommand = class extends Command {
|
|
731
|
-
constructor([libraryName], opts) {
|
|
732
|
-
super(["function", "delete", libraryName], opts);
|
|
733
|
-
}
|
|
734
|
-
};
|
|
735
|
-
|
|
736
|
-
// pkg/commands/function_flush.ts
|
|
737
|
-
var FunctionFlushCommand = class extends Command {
|
|
738
|
-
constructor(opts) {
|
|
739
|
-
super(["function", "flush"], opts);
|
|
740
|
-
}
|
|
741
|
-
};
|
|
742
|
-
|
|
743
|
-
// pkg/commands/function_list.ts
|
|
744
|
-
var FunctionListCommand = class extends Command {
|
|
745
|
-
constructor([args], opts) {
|
|
746
|
-
const command = ["function", "list"];
|
|
747
|
-
if (args?.libraryName) {
|
|
748
|
-
command.push("libraryname", args.libraryName);
|
|
749
|
-
}
|
|
750
|
-
if (args?.withCode) {
|
|
751
|
-
command.push("withcode");
|
|
752
|
-
}
|
|
753
|
-
super(command, { deserialize, ...opts });
|
|
754
|
-
}
|
|
755
|
-
};
|
|
756
|
-
function deserialize(result) {
|
|
757
|
-
if (!Array.isArray(result)) return [];
|
|
758
|
-
return result.map((libRaw) => {
|
|
759
|
-
const lib = kvArrayToObject(libRaw);
|
|
760
|
-
const functionsParsed = lib.functions.map(
|
|
761
|
-
(fnRaw) => kvArrayToObject(fnRaw)
|
|
762
|
-
);
|
|
763
|
-
return {
|
|
764
|
-
libraryName: lib.library_name,
|
|
765
|
-
engine: lib.engine,
|
|
766
|
-
functions: functionsParsed.map((fn) => ({
|
|
767
|
-
name: fn.name,
|
|
768
|
-
description: fn.description ?? void 0,
|
|
769
|
-
flags: fn.flags
|
|
770
|
-
})),
|
|
771
|
-
libraryCode: lib.library_code
|
|
772
|
-
};
|
|
773
|
-
});
|
|
774
|
-
}
|
|
775
|
-
|
|
776
|
-
// pkg/commands/function_load.ts
|
|
777
|
-
var FunctionLoadCommand = class extends Command {
|
|
778
|
-
constructor([args], opts) {
|
|
779
|
-
super(["function", "load", ...args.replace ? ["replace"] : [], args.code], opts);
|
|
780
|
-
}
|
|
781
|
-
};
|
|
782
|
-
|
|
783
|
-
// pkg/commands/function_stats.ts
|
|
784
|
-
var FunctionStatsCommand = class extends Command {
|
|
785
|
-
constructor(opts) {
|
|
786
|
-
super(["function", "stats"], { deserialize: deserialize2, ...opts });
|
|
787
|
-
}
|
|
788
|
-
};
|
|
789
|
-
function deserialize2(result) {
|
|
790
|
-
const rawEngines = kvArrayToObject(kvArrayToObject(result).engines);
|
|
791
|
-
const parsedEngines = Object.fromEntries(
|
|
792
|
-
Object.entries(rawEngines).map(([key, value]) => [key, kvArrayToObject(value)])
|
|
793
|
-
);
|
|
794
|
-
const final = {
|
|
795
|
-
engines: Object.fromEntries(
|
|
796
|
-
Object.entries(parsedEngines).map(([key, value]) => [
|
|
797
|
-
key,
|
|
798
|
-
{
|
|
799
|
-
librariesCount: value.libraries_count,
|
|
800
|
-
functionsCount: value.functions_count
|
|
801
|
-
}
|
|
802
|
-
])
|
|
803
|
-
)
|
|
804
|
-
};
|
|
805
|
-
return final;
|
|
806
|
-
}
|
|
807
|
-
|
|
808
696
|
// pkg/commands/geo_add.ts
|
|
809
697
|
var GeoAddCommand = class extends Command {
|
|
810
698
|
constructor([key, arg1, ...arg2], opts) {
|
|
@@ -1151,7 +1039,7 @@ var HGetCommand = class extends Command {
|
|
|
1151
1039
|
};
|
|
1152
1040
|
|
|
1153
1041
|
// pkg/commands/hgetall.ts
|
|
1154
|
-
function
|
|
1042
|
+
function deserialize(result) {
|
|
1155
1043
|
if (result.length === 0) {
|
|
1156
1044
|
return null;
|
|
1157
1045
|
}
|
|
@@ -1171,7 +1059,7 @@ function deserialize3(result) {
|
|
|
1171
1059
|
var HGetAllCommand = class extends Command {
|
|
1172
1060
|
constructor(cmd, opts) {
|
|
1173
1061
|
super(["hgetall", ...cmd], {
|
|
1174
|
-
deserialize: (result) =>
|
|
1062
|
+
deserialize: (result) => deserialize(result),
|
|
1175
1063
|
...opts
|
|
1176
1064
|
});
|
|
1177
1065
|
}
|
|
@@ -1206,7 +1094,7 @@ var HLenCommand = class extends Command {
|
|
|
1206
1094
|
};
|
|
1207
1095
|
|
|
1208
1096
|
// pkg/commands/hmget.ts
|
|
1209
|
-
function
|
|
1097
|
+
function deserialize2(fields, result) {
|
|
1210
1098
|
if (result.every((field) => field === null)) {
|
|
1211
1099
|
return null;
|
|
1212
1100
|
}
|
|
@@ -1223,7 +1111,7 @@ function deserialize4(fields, result) {
|
|
|
1223
1111
|
var HMGetCommand = class extends Command {
|
|
1224
1112
|
constructor([key, ...fields], opts) {
|
|
1225
1113
|
super(["hmget", key, ...fields], {
|
|
1226
|
-
deserialize: (result) =>
|
|
1114
|
+
deserialize: (result) => deserialize2(fields, result),
|
|
1227
1115
|
...opts
|
|
1228
1116
|
});
|
|
1229
1117
|
}
|
|
@@ -1237,7 +1125,7 @@ var HMSetCommand = class extends Command {
|
|
|
1237
1125
|
};
|
|
1238
1126
|
|
|
1239
1127
|
// pkg/commands/hrandfield.ts
|
|
1240
|
-
function
|
|
1128
|
+
function deserialize3(result) {
|
|
1241
1129
|
if (result.length === 0) {
|
|
1242
1130
|
return null;
|
|
1243
1131
|
}
|
|
@@ -1264,7 +1152,7 @@ var HRandFieldCommand = class extends Command {
|
|
|
1264
1152
|
}
|
|
1265
1153
|
super(command, {
|
|
1266
1154
|
// @ts-expect-error to silence compiler
|
|
1267
|
-
deserialize: cmd[2] ? (result) =>
|
|
1155
|
+
deserialize: cmd[2] ? (result) => deserialize3(result) : opts?.deserialize,
|
|
1268
1156
|
...opts
|
|
1269
1157
|
});
|
|
1270
1158
|
}
|
|
@@ -2234,7 +2122,7 @@ var XPendingCommand = class extends Command {
|
|
|
2234
2122
|
};
|
|
2235
2123
|
|
|
2236
2124
|
// pkg/commands/xrange.ts
|
|
2237
|
-
function
|
|
2125
|
+
function deserialize4(result) {
|
|
2238
2126
|
const obj = {};
|
|
2239
2127
|
for (const e of result) {
|
|
2240
2128
|
for (let i = 0; i < e.length; i += 2) {
|
|
@@ -2263,7 +2151,7 @@ var XRangeCommand = class extends Command {
|
|
|
2263
2151
|
command.push("COUNT", count);
|
|
2264
2152
|
}
|
|
2265
2153
|
super(command, {
|
|
2266
|
-
deserialize: (result) =>
|
|
2154
|
+
deserialize: (result) => deserialize4(result),
|
|
2267
2155
|
...opts
|
|
2268
2156
|
});
|
|
2269
2157
|
}
|
|
@@ -2326,12 +2214,12 @@ var XRevRangeCommand = class extends Command {
|
|
|
2326
2214
|
command.push("COUNT", count);
|
|
2327
2215
|
}
|
|
2328
2216
|
super(command, {
|
|
2329
|
-
deserialize: (result) =>
|
|
2217
|
+
deserialize: (result) => deserialize5(result),
|
|
2330
2218
|
...opts
|
|
2331
2219
|
});
|
|
2332
2220
|
}
|
|
2333
2221
|
};
|
|
2334
|
-
function
|
|
2222
|
+
function deserialize5(result) {
|
|
2335
2223
|
const obj = {};
|
|
2336
2224
|
for (const e of result) {
|
|
2337
2225
|
for (let i = 0; i < e.length; i += 2) {
|
|
@@ -2601,6 +2489,265 @@ var ZUnionStoreCommand = class extends Command {
|
|
|
2601
2489
|
}
|
|
2602
2490
|
};
|
|
2603
2491
|
|
|
2492
|
+
// pkg/commands/search/types.ts
|
|
2493
|
+
var FIELD_TYPES = ["TEXT", "U64", "I64", "F64", "BOOL", "DATE"];
|
|
2494
|
+
|
|
2495
|
+
// pkg/commands/search/utils.ts
|
|
2496
|
+
function isFieldType(value) {
|
|
2497
|
+
return typeof value === "string" && FIELD_TYPES.includes(value);
|
|
2498
|
+
}
|
|
2499
|
+
function isDetailedField(value) {
|
|
2500
|
+
return typeof value === "object" && value !== null && "type" in value && isFieldType(value.type);
|
|
2501
|
+
}
|
|
2502
|
+
function isNestedSchema(value) {
|
|
2503
|
+
return typeof value === "object" && value !== null && !isDetailedField(value);
|
|
2504
|
+
}
|
|
2505
|
+
function flattenSchema(schema, pathPrefix = []) {
|
|
2506
|
+
const fields = [];
|
|
2507
|
+
for (const [key, value] of Object.entries(schema)) {
|
|
2508
|
+
const currentPath = [...pathPrefix, key];
|
|
2509
|
+
const pathString = currentPath.join(".");
|
|
2510
|
+
if (isFieldType(value)) {
|
|
2511
|
+
fields.push({
|
|
2512
|
+
path: pathString,
|
|
2513
|
+
type: value
|
|
2514
|
+
});
|
|
2515
|
+
} else if (isDetailedField(value)) {
|
|
2516
|
+
fields.push({
|
|
2517
|
+
path: pathString,
|
|
2518
|
+
type: value.type,
|
|
2519
|
+
fast: "fast" in value ? value.fast : void 0,
|
|
2520
|
+
noTokenize: "noTokenize" in value ? value.noTokenize : void 0,
|
|
2521
|
+
noStem: "noStem" in value ? value.noStem : void 0,
|
|
2522
|
+
from: "from" in value ? value.from : void 0
|
|
2523
|
+
});
|
|
2524
|
+
} else if (isNestedSchema(value)) {
|
|
2525
|
+
const nestedFields = flattenSchema(value, currentPath);
|
|
2526
|
+
fields.push(...nestedFields);
|
|
2527
|
+
}
|
|
2528
|
+
}
|
|
2529
|
+
return fields;
|
|
2530
|
+
}
|
|
2531
|
+
function deserializeQueryResponse(rawResponse) {
|
|
2532
|
+
return rawResponse.map((itemRaw) => {
|
|
2533
|
+
const raw = itemRaw;
|
|
2534
|
+
const key = raw[0];
|
|
2535
|
+
const score = raw[1];
|
|
2536
|
+
const rawFields = raw[2];
|
|
2537
|
+
if (rawFields === void 0) {
|
|
2538
|
+
return { key, score };
|
|
2539
|
+
}
|
|
2540
|
+
if (!Array.isArray(rawFields) || rawFields.length === 0) {
|
|
2541
|
+
return { key, score, data: {} };
|
|
2542
|
+
}
|
|
2543
|
+
let data = {};
|
|
2544
|
+
for (const fieldRaw of rawFields) {
|
|
2545
|
+
const key2 = fieldRaw[0];
|
|
2546
|
+
const value = fieldRaw[1];
|
|
2547
|
+
const pathParts = key2.split(".");
|
|
2548
|
+
if (pathParts.length == 1) {
|
|
2549
|
+
data[key2] = value;
|
|
2550
|
+
} else {
|
|
2551
|
+
let currentObj = data;
|
|
2552
|
+
for (let i = 0; i < pathParts.length - 1; i++) {
|
|
2553
|
+
const pathPart = pathParts[i];
|
|
2554
|
+
if (!(pathPart in currentObj)) {
|
|
2555
|
+
currentObj[pathPart] = {};
|
|
2556
|
+
}
|
|
2557
|
+
currentObj = currentObj[pathPart];
|
|
2558
|
+
}
|
|
2559
|
+
currentObj[pathParts.at(-1)] = value;
|
|
2560
|
+
}
|
|
2561
|
+
}
|
|
2562
|
+
if ("$" in data) {
|
|
2563
|
+
data = data["$"];
|
|
2564
|
+
}
|
|
2565
|
+
return { key, score, data };
|
|
2566
|
+
});
|
|
2567
|
+
}
|
|
2568
|
+
function deserializeDescribeResponse(rawResponse) {
|
|
2569
|
+
const description = {};
|
|
2570
|
+
for (let i = 0; i < rawResponse.length; i += 2) {
|
|
2571
|
+
const descriptor = rawResponse[i];
|
|
2572
|
+
switch (descriptor) {
|
|
2573
|
+
case "name": {
|
|
2574
|
+
description["name"] = rawResponse[i + 1];
|
|
2575
|
+
break;
|
|
2576
|
+
}
|
|
2577
|
+
case "type": {
|
|
2578
|
+
description["dataType"] = rawResponse[i + 1].toLowerCase();
|
|
2579
|
+
break;
|
|
2580
|
+
}
|
|
2581
|
+
case "prefixes": {
|
|
2582
|
+
description["prefixes"] = rawResponse[i + 1];
|
|
2583
|
+
break;
|
|
2584
|
+
}
|
|
2585
|
+
case "language": {
|
|
2586
|
+
description["language"] = rawResponse[i + 1];
|
|
2587
|
+
break;
|
|
2588
|
+
}
|
|
2589
|
+
case "schema": {
|
|
2590
|
+
const schema = {};
|
|
2591
|
+
for (const fieldDescription of rawResponse[i + 1]) {
|
|
2592
|
+
const fieldName = fieldDescription[0];
|
|
2593
|
+
const fieldInfo = { type: fieldDescription[1] };
|
|
2594
|
+
if (fieldDescription.length > 2) {
|
|
2595
|
+
for (let j = 2; j < fieldDescription.length; j++) {
|
|
2596
|
+
const fieldOption = fieldDescription[j];
|
|
2597
|
+
switch (fieldOption) {
|
|
2598
|
+
case "NOSTEM": {
|
|
2599
|
+
fieldInfo.noStem = true;
|
|
2600
|
+
break;
|
|
2601
|
+
}
|
|
2602
|
+
case "NOTOKENIZE": {
|
|
2603
|
+
fieldInfo.noTokenize = true;
|
|
2604
|
+
break;
|
|
2605
|
+
}
|
|
2606
|
+
case "FAST": {
|
|
2607
|
+
fieldInfo.fast = true;
|
|
2608
|
+
break;
|
|
2609
|
+
}
|
|
2610
|
+
}
|
|
2611
|
+
}
|
|
2612
|
+
}
|
|
2613
|
+
schema[fieldName] = fieldInfo;
|
|
2614
|
+
}
|
|
2615
|
+
description["schema"] = schema;
|
|
2616
|
+
break;
|
|
2617
|
+
}
|
|
2618
|
+
}
|
|
2619
|
+
}
|
|
2620
|
+
return description;
|
|
2621
|
+
}
|
|
2622
|
+
function parseCountResponse(rawResponse) {
|
|
2623
|
+
return typeof rawResponse === "number" ? rawResponse : Number.parseInt(rawResponse, 10);
|
|
2624
|
+
}
|
|
2625
|
+
|
|
2626
|
+
// pkg/commands/search/command-builder.ts
|
|
2627
|
+
function buildQueryCommand(redisCommand, name, options) {
|
|
2628
|
+
const query = JSON.stringify(options?.filter ?? {});
|
|
2629
|
+
const command = [redisCommand, name, query];
|
|
2630
|
+
if (options?.limit !== void 0) {
|
|
2631
|
+
command.push("LIMIT", options.limit.toString());
|
|
2632
|
+
}
|
|
2633
|
+
if (options?.offset !== void 0) {
|
|
2634
|
+
command.push("OFFSET", options.offset.toString());
|
|
2635
|
+
}
|
|
2636
|
+
if (options?.select && Object.keys(options.select).length === 0) {
|
|
2637
|
+
command.push("NOCONTENT");
|
|
2638
|
+
}
|
|
2639
|
+
if (options?.orderBy) {
|
|
2640
|
+
command.push("ORDERBY");
|
|
2641
|
+
for (const [field, direction] of Object.entries(options.orderBy)) {
|
|
2642
|
+
command.push(field, direction);
|
|
2643
|
+
}
|
|
2644
|
+
}
|
|
2645
|
+
if (options?.highlight) {
|
|
2646
|
+
command.push(
|
|
2647
|
+
"HIGHLIGHT",
|
|
2648
|
+
"FIELDS",
|
|
2649
|
+
options.highlight.fields.length.toString(),
|
|
2650
|
+
...options.highlight.fields
|
|
2651
|
+
);
|
|
2652
|
+
if (options.highlight.preTag && options.highlight.postTag) {
|
|
2653
|
+
command.push("TAGS", options.highlight.preTag, options.highlight.postTag);
|
|
2654
|
+
}
|
|
2655
|
+
}
|
|
2656
|
+
if (options?.select && Object.keys(options.select).length > 0) {
|
|
2657
|
+
command.push(
|
|
2658
|
+
"SELECT",
|
|
2659
|
+
Object.keys(options.select).length.toString(),
|
|
2660
|
+
...Object.keys(options.select)
|
|
2661
|
+
);
|
|
2662
|
+
}
|
|
2663
|
+
return command;
|
|
2664
|
+
}
|
|
2665
|
+
function buildCreateIndexCommand(params) {
|
|
2666
|
+
const { name, schema, dataType, prefix, language, skipInitialScan, existsOk } = params;
|
|
2667
|
+
const prefixArray = Array.isArray(prefix) ? prefix : [prefix];
|
|
2668
|
+
const payload = [
|
|
2669
|
+
name,
|
|
2670
|
+
...skipInitialScan ? ["SKIPINITIALSCAN"] : [],
|
|
2671
|
+
...existsOk ? ["EXISTSOK"] : [],
|
|
2672
|
+
"ON",
|
|
2673
|
+
dataType.toUpperCase(),
|
|
2674
|
+
"PREFIX",
|
|
2675
|
+
prefixArray.length.toString(),
|
|
2676
|
+
...prefixArray,
|
|
2677
|
+
...language ? ["LANGUAGE", language] : [],
|
|
2678
|
+
"SCHEMA"
|
|
2679
|
+
];
|
|
2680
|
+
const fields = flattenSchema(schema);
|
|
2681
|
+
for (const field of fields) {
|
|
2682
|
+
payload.push(field.path, field.type);
|
|
2683
|
+
if (field.fast) {
|
|
2684
|
+
payload.push("FAST");
|
|
2685
|
+
}
|
|
2686
|
+
if (field.noTokenize) {
|
|
2687
|
+
payload.push("NOTOKENIZE");
|
|
2688
|
+
}
|
|
2689
|
+
if (field.noStem) {
|
|
2690
|
+
payload.push("NOSTEM");
|
|
2691
|
+
}
|
|
2692
|
+
if (field.from) {
|
|
2693
|
+
payload.push("FROM", field.from);
|
|
2694
|
+
}
|
|
2695
|
+
}
|
|
2696
|
+
return ["SEARCH.CREATE", ...payload];
|
|
2697
|
+
}
|
|
2698
|
+
|
|
2699
|
+
// pkg/commands/search/search.ts
|
|
2700
|
+
var SearchIndex = class {
|
|
2701
|
+
name;
|
|
2702
|
+
schema;
|
|
2703
|
+
client;
|
|
2704
|
+
constructor({ name, schema, client }) {
|
|
2705
|
+
this.name = name;
|
|
2706
|
+
this.schema = schema;
|
|
2707
|
+
this.client = client;
|
|
2708
|
+
}
|
|
2709
|
+
async waitIndexing() {
|
|
2710
|
+
const command = ["SEARCH.WAITINDEXING", this.name];
|
|
2711
|
+
await new ExecCommand(command).exec(this.client);
|
|
2712
|
+
}
|
|
2713
|
+
async describe() {
|
|
2714
|
+
const command = ["SEARCH.DESCRIBE", this.name];
|
|
2715
|
+
const rawResult = await new ExecCommand(command).exec(
|
|
2716
|
+
this.client
|
|
2717
|
+
);
|
|
2718
|
+
return deserializeDescribeResponse(rawResult);
|
|
2719
|
+
}
|
|
2720
|
+
async query(options) {
|
|
2721
|
+
const command = buildQueryCommand("SEARCH.QUERY", this.name, options);
|
|
2722
|
+
const rawResult = await new ExecCommand(command).exec(
|
|
2723
|
+
this.client
|
|
2724
|
+
);
|
|
2725
|
+
return deserializeQueryResponse(rawResult);
|
|
2726
|
+
}
|
|
2727
|
+
async count({ filter }) {
|
|
2728
|
+
const command = buildQueryCommand("SEARCH.COUNT", this.name, { filter });
|
|
2729
|
+
const rawResult = await new ExecCommand(command).exec(
|
|
2730
|
+
this.client
|
|
2731
|
+
);
|
|
2732
|
+
return { count: parseCountResponse(rawResult) };
|
|
2733
|
+
}
|
|
2734
|
+
async drop() {
|
|
2735
|
+
const command = ["SEARCH.DROP", this.name];
|
|
2736
|
+
const result = await new ExecCommand(command).exec(this.client);
|
|
2737
|
+
return result;
|
|
2738
|
+
}
|
|
2739
|
+
};
|
|
2740
|
+
async function createIndex(client, params) {
|
|
2741
|
+
const { name, schema } = params;
|
|
2742
|
+
const createIndexCommand = buildCreateIndexCommand(params);
|
|
2743
|
+
await new ExecCommand(createIndexCommand).exec(client);
|
|
2744
|
+
return initIndex(client, { name, schema });
|
|
2745
|
+
}
|
|
2746
|
+
function initIndex(client, params) {
|
|
2747
|
+
const { name, schema } = params;
|
|
2748
|
+
return new SearchIndex({ name, schema, client });
|
|
2749
|
+
}
|
|
2750
|
+
|
|
2604
2751
|
// pkg/commands/psubscribe.ts
|
|
2605
2752
|
var PSubscribeCommand = class extends Command {
|
|
2606
2753
|
constructor(cmd, opts) {
|
|
@@ -3626,38 +3773,6 @@ var Pipeline = class {
|
|
|
3626
3773
|
type: (...args) => this.chain(new JsonTypeCommand(args, this.commandOptions))
|
|
3627
3774
|
};
|
|
3628
3775
|
}
|
|
3629
|
-
get functions() {
|
|
3630
|
-
return {
|
|
3631
|
-
/**
|
|
3632
|
-
* @see https://redis.io/docs/latest/commands/function-load/
|
|
3633
|
-
*/
|
|
3634
|
-
load: (...args) => this.chain(new FunctionLoadCommand(args, this.commandOptions)),
|
|
3635
|
-
/**
|
|
3636
|
-
* @see https://redis.io/docs/latest/commands/function-list/
|
|
3637
|
-
*/
|
|
3638
|
-
list: (...args) => this.chain(new FunctionListCommand(args, this.commandOptions)),
|
|
3639
|
-
/**
|
|
3640
|
-
* @see https://redis.io/docs/latest/commands/function-delete/
|
|
3641
|
-
*/
|
|
3642
|
-
delete: (...args) => this.chain(new FunctionDeleteCommand(args, this.commandOptions)),
|
|
3643
|
-
/**
|
|
3644
|
-
* @see https://redis.io/docs/latest/commands/function-flush/
|
|
3645
|
-
*/
|
|
3646
|
-
flush: () => this.chain(new FunctionFlushCommand(this.commandOptions)),
|
|
3647
|
-
/**
|
|
3648
|
-
* @see https://redis.io/docs/latest/commands/function-stats/
|
|
3649
|
-
*/
|
|
3650
|
-
stats: () => this.chain(new FunctionStatsCommand(this.commandOptions)),
|
|
3651
|
-
/**
|
|
3652
|
-
* @see https://redis.io/docs/latest/commands/fcall/
|
|
3653
|
-
*/
|
|
3654
|
-
call: (...args) => this.chain(new FCallCommand(args, this.commandOptions)),
|
|
3655
|
-
/**
|
|
3656
|
-
* @see https://redis.io/docs/latest/commands/fcall_ro/
|
|
3657
|
-
*/
|
|
3658
|
-
callRo: (...args) => this.chain(new FCallRoCommand(args, this.commandOptions))
|
|
3659
|
-
};
|
|
3660
|
-
}
|
|
3661
3776
|
};
|
|
3662
3777
|
|
|
3663
3778
|
// pkg/script.ts
|
|
@@ -3719,8 +3834,8 @@ var Script = class {
|
|
|
3719
3834
|
/**
|
|
3720
3835
|
* Compute the sha1 hash of the script and return its hex representation.
|
|
3721
3836
|
*/
|
|
3722
|
-
async digest(
|
|
3723
|
-
const data = new TextEncoder().encode(
|
|
3837
|
+
async digest(s2) {
|
|
3838
|
+
const data = new TextEncoder().encode(s2);
|
|
3724
3839
|
const hashBuffer = await import_uncrypto.subtle.digest("SHA-1", data);
|
|
3725
3840
|
const hashArray = [...new Uint8Array(hashBuffer)];
|
|
3726
3841
|
return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
@@ -3783,8 +3898,8 @@ var ScriptRO = class {
|
|
|
3783
3898
|
/**
|
|
3784
3899
|
* Compute the sha1 hash of the script and return its hex representation.
|
|
3785
3900
|
*/
|
|
3786
|
-
async digest(
|
|
3787
|
-
const data = new TextEncoder().encode(
|
|
3901
|
+
async digest(s2) {
|
|
3902
|
+
const data = new TextEncoder().encode(s2);
|
|
3788
3903
|
const hashBuffer = await import_uncrypto2.subtle.digest("SHA-1", data);
|
|
3789
3904
|
const hashArray = [...new Uint8Array(hashBuffer)];
|
|
3790
3905
|
return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
@@ -3919,40 +4034,6 @@ var Redis = class {
|
|
|
3919
4034
|
type: (...args) => new JsonTypeCommand(args, this.opts).exec(this.client)
|
|
3920
4035
|
};
|
|
3921
4036
|
}
|
|
3922
|
-
get functions() {
|
|
3923
|
-
return {
|
|
3924
|
-
/**
|
|
3925
|
-
* @see https://redis.io/docs/latest/commands/function-load/
|
|
3926
|
-
*/
|
|
3927
|
-
load: (...args) => new FunctionLoadCommand(args, this.opts).exec(this.client),
|
|
3928
|
-
/**
|
|
3929
|
-
* @see https://redis.io/docs/latest/commands/function-list/
|
|
3930
|
-
*/
|
|
3931
|
-
list: (...args) => new FunctionListCommand(args, this.opts).exec(this.client),
|
|
3932
|
-
/**
|
|
3933
|
-
* @see https://redis.io/docs/latest/commands/function-delete/
|
|
3934
|
-
*/
|
|
3935
|
-
delete: (...args) => new FunctionDeleteCommand(args, this.opts).exec(this.client),
|
|
3936
|
-
/**
|
|
3937
|
-
* @see https://redis.io/docs/latest/commands/function-flush/
|
|
3938
|
-
*/
|
|
3939
|
-
flush: () => new FunctionFlushCommand(this.opts).exec(this.client),
|
|
3940
|
-
/**
|
|
3941
|
-
* @see https://redis.io/docs/latest/commands/function-stats/
|
|
3942
|
-
*
|
|
3943
|
-
* Note: `running_script` field is not supported and therefore not included in the type.
|
|
3944
|
-
*/
|
|
3945
|
-
stats: () => new FunctionStatsCommand(this.opts).exec(this.client),
|
|
3946
|
-
/**
|
|
3947
|
-
* @see https://redis.io/docs/latest/commands/fcall/
|
|
3948
|
-
*/
|
|
3949
|
-
call: (...args) => new FCallCommand(args, this.opts).exec(this.client),
|
|
3950
|
-
/**
|
|
3951
|
-
* @see https://redis.io/docs/latest/commands/fcall_ro/
|
|
3952
|
-
*/
|
|
3953
|
-
callRo: (...args) => new FCallRoCommand(args, this.opts).exec(this.client)
|
|
3954
|
-
};
|
|
3955
|
-
}
|
|
3956
4037
|
/**
|
|
3957
4038
|
* Wrap a new middleware around the HTTP client.
|
|
3958
4039
|
*/
|
|
@@ -4003,6 +4084,16 @@ var Redis = class {
|
|
|
4003
4084
|
createScript(script, opts) {
|
|
4004
4085
|
return opts?.readonly ? new ScriptRO(this, script) : new Script(this, script);
|
|
4005
4086
|
}
|
|
4087
|
+
get search() {
|
|
4088
|
+
return {
|
|
4089
|
+
createIndex: (params) => {
|
|
4090
|
+
return createIndex(this.client, params);
|
|
4091
|
+
},
|
|
4092
|
+
index: (params) => {
|
|
4093
|
+
return initIndex(this.client, params);
|
|
4094
|
+
}
|
|
4095
|
+
};
|
|
4096
|
+
}
|
|
4006
4097
|
/**
|
|
4007
4098
|
* Create a new pipeline that allows you to send requests in bulk.
|
|
4008
4099
|
*
|
|
@@ -4710,7 +4801,160 @@ var Redis = class {
|
|
|
4710
4801
|
};
|
|
4711
4802
|
|
|
4712
4803
|
// version.ts
|
|
4713
|
-
var VERSION = "v1.
|
|
4804
|
+
var VERSION = "v1.37.0-rc.1";
|
|
4805
|
+
|
|
4806
|
+
// pkg/commands/search/schema-builder.ts
|
|
4807
|
+
var BUILD = Symbol("build");
|
|
4808
|
+
var TextFieldBuilder = class _TextFieldBuilder {
|
|
4809
|
+
_noTokenize;
|
|
4810
|
+
_noStem;
|
|
4811
|
+
_from;
|
|
4812
|
+
constructor(noTokenize = { noTokenize: false }, noStem = { noStem: false }, from = { from: null }) {
|
|
4813
|
+
this._noTokenize = noTokenize;
|
|
4814
|
+
this._noStem = noStem;
|
|
4815
|
+
this._from = from;
|
|
4816
|
+
}
|
|
4817
|
+
noTokenize() {
|
|
4818
|
+
return new _TextFieldBuilder({ noTokenize: true }, this._noStem, this._from);
|
|
4819
|
+
}
|
|
4820
|
+
noStem() {
|
|
4821
|
+
return new _TextFieldBuilder(this._noTokenize, { noStem: true }, this._from);
|
|
4822
|
+
}
|
|
4823
|
+
from(field) {
|
|
4824
|
+
return new _TextFieldBuilder(this._noTokenize, this._noStem, { from: field });
|
|
4825
|
+
}
|
|
4826
|
+
[BUILD]() {
|
|
4827
|
+
const hasOptions = this._noTokenize.noTokenize || this._noStem.noStem || Boolean(this._from.from);
|
|
4828
|
+
return hasOptions ? {
|
|
4829
|
+
type: "TEXT",
|
|
4830
|
+
...this._noTokenize.noTokenize ? { noTokenize: true } : {},
|
|
4831
|
+
...this._noStem.noStem ? { noStem: true } : {},
|
|
4832
|
+
...this._from.from ? { from: this._from.from } : {}
|
|
4833
|
+
} : "TEXT";
|
|
4834
|
+
}
|
|
4835
|
+
};
|
|
4836
|
+
var NumericFieldBuilder = class _NumericFieldBuilder {
|
|
4837
|
+
type;
|
|
4838
|
+
_from;
|
|
4839
|
+
constructor(type, from = { from: null }) {
|
|
4840
|
+
this.type = type;
|
|
4841
|
+
this._from = from;
|
|
4842
|
+
}
|
|
4843
|
+
from(field) {
|
|
4844
|
+
return new _NumericFieldBuilder(this.type, { from: field });
|
|
4845
|
+
}
|
|
4846
|
+
[BUILD]() {
|
|
4847
|
+
return this._from.from ? {
|
|
4848
|
+
type: this.type,
|
|
4849
|
+
fast: true,
|
|
4850
|
+
from: this._from.from
|
|
4851
|
+
} : {
|
|
4852
|
+
type: this.type,
|
|
4853
|
+
fast: true
|
|
4854
|
+
};
|
|
4855
|
+
}
|
|
4856
|
+
};
|
|
4857
|
+
var BoolFieldBuilder = class _BoolFieldBuilder {
|
|
4858
|
+
_fast;
|
|
4859
|
+
_from;
|
|
4860
|
+
constructor(fast = { fast: false }, from = { from: null }) {
|
|
4861
|
+
this._fast = fast;
|
|
4862
|
+
this._from = from;
|
|
4863
|
+
}
|
|
4864
|
+
fast() {
|
|
4865
|
+
return new _BoolFieldBuilder({ fast: true }, this._from);
|
|
4866
|
+
}
|
|
4867
|
+
from(field) {
|
|
4868
|
+
return new _BoolFieldBuilder(this._fast, { from: field });
|
|
4869
|
+
}
|
|
4870
|
+
[BUILD]() {
|
|
4871
|
+
const hasFast = this._fast.fast;
|
|
4872
|
+
const hasFrom = Boolean(this._from.from);
|
|
4873
|
+
if (hasFast && hasFrom) {
|
|
4874
|
+
return {
|
|
4875
|
+
type: "BOOL",
|
|
4876
|
+
fast: true,
|
|
4877
|
+
from: this._from.from
|
|
4878
|
+
};
|
|
4879
|
+
}
|
|
4880
|
+
if (hasFast) {
|
|
4881
|
+
return {
|
|
4882
|
+
type: "BOOL",
|
|
4883
|
+
fast: true
|
|
4884
|
+
};
|
|
4885
|
+
}
|
|
4886
|
+
if (hasFrom) {
|
|
4887
|
+
return {
|
|
4888
|
+
type: "BOOL",
|
|
4889
|
+
from: this._from.from
|
|
4890
|
+
};
|
|
4891
|
+
}
|
|
4892
|
+
return "BOOL";
|
|
4893
|
+
}
|
|
4894
|
+
};
|
|
4895
|
+
var DateFieldBuilder = class _DateFieldBuilder {
|
|
4896
|
+
_fast;
|
|
4897
|
+
_from;
|
|
4898
|
+
constructor(fast = { fast: false }, from = { from: null }) {
|
|
4899
|
+
this._fast = fast;
|
|
4900
|
+
this._from = from;
|
|
4901
|
+
}
|
|
4902
|
+
fast() {
|
|
4903
|
+
return new _DateFieldBuilder({ fast: true }, this._from);
|
|
4904
|
+
}
|
|
4905
|
+
from(field) {
|
|
4906
|
+
return new _DateFieldBuilder(this._fast, { from: field });
|
|
4907
|
+
}
|
|
4908
|
+
[BUILD]() {
|
|
4909
|
+
const hasFast = this._fast.fast;
|
|
4910
|
+
const hasFrom = Boolean(this._from.from);
|
|
4911
|
+
if (hasFast && hasFrom) {
|
|
4912
|
+
return {
|
|
4913
|
+
type: "DATE",
|
|
4914
|
+
fast: true,
|
|
4915
|
+
from: this._from.from
|
|
4916
|
+
};
|
|
4917
|
+
}
|
|
4918
|
+
if (hasFast) {
|
|
4919
|
+
return {
|
|
4920
|
+
type: "DATE",
|
|
4921
|
+
fast: true
|
|
4922
|
+
};
|
|
4923
|
+
}
|
|
4924
|
+
if (hasFrom) {
|
|
4925
|
+
return {
|
|
4926
|
+
type: "DATE",
|
|
4927
|
+
from: this._from.from
|
|
4928
|
+
};
|
|
4929
|
+
}
|
|
4930
|
+
return "DATE";
|
|
4931
|
+
}
|
|
4932
|
+
};
|
|
4933
|
+
var s = {
|
|
4934
|
+
string() {
|
|
4935
|
+
return new TextFieldBuilder();
|
|
4936
|
+
},
|
|
4937
|
+
number(type = "F64") {
|
|
4938
|
+
return new NumericFieldBuilder(type);
|
|
4939
|
+
},
|
|
4940
|
+
boolean() {
|
|
4941
|
+
return new BoolFieldBuilder();
|
|
4942
|
+
},
|
|
4943
|
+
date() {
|
|
4944
|
+
return new DateFieldBuilder();
|
|
4945
|
+
},
|
|
4946
|
+
object(fields) {
|
|
4947
|
+
const result = {};
|
|
4948
|
+
for (const [key, value] of Object.entries(fields)) {
|
|
4949
|
+
if (value && typeof value === "object" && BUILD in value) {
|
|
4950
|
+
result[key] = value[BUILD]();
|
|
4951
|
+
} else {
|
|
4952
|
+
result[key] = value;
|
|
4953
|
+
}
|
|
4954
|
+
}
|
|
4955
|
+
return result;
|
|
4956
|
+
}
|
|
4957
|
+
};
|
|
4714
4958
|
|
|
4715
4959
|
// platforms/nodejs.ts
|
|
4716
4960
|
if (typeof atob === "undefined") {
|
|
@@ -4768,20 +5012,18 @@ var Redis2 = class _Redis extends Redis {
|
|
|
4768
5012
|
keepAlive: configOrRequester.keepAlive,
|
|
4769
5013
|
readYourWrites: configOrRequester.readYourWrites
|
|
4770
5014
|
});
|
|
4771
|
-
const safeEnv = typeof process === "object" && process && typeof process.env === "object" && process.env ? process.env : {};
|
|
4772
5015
|
super(client, {
|
|
4773
5016
|
automaticDeserialization: configOrRequester.automaticDeserialization,
|
|
4774
|
-
enableTelemetry: configOrRequester.enableTelemetry ?? !
|
|
5017
|
+
enableTelemetry: configOrRequester.enableTelemetry ?? !process.env.UPSTASH_DISABLE_TELEMETRY,
|
|
4775
5018
|
latencyLogging: configOrRequester.latencyLogging,
|
|
4776
5019
|
enableAutoPipelining: configOrRequester.enableAutoPipelining
|
|
4777
5020
|
});
|
|
4778
|
-
const nodeVersion = typeof process === "object" && process ? process.version : void 0;
|
|
4779
5021
|
this.addTelemetry({
|
|
4780
5022
|
runtime: (
|
|
4781
5023
|
// @ts-expect-error to silence compiler
|
|
4782
|
-
typeof EdgeRuntime === "string" ? "edge-light" :
|
|
5024
|
+
typeof EdgeRuntime === "string" ? "edge-light" : `node@${process.version}`
|
|
4783
5025
|
),
|
|
4784
|
-
platform:
|
|
5026
|
+
platform: process.env.UPSTASH_CONSOLE ? "console" : process.env.VERCEL ? "vercel" : process.env.AWS_REGION ? "aws" : "unknown",
|
|
4785
5027
|
sdk: `@upstash/redis@${VERSION}`
|
|
4786
5028
|
});
|
|
4787
5029
|
if (this.enableAutoPipelining) {
|
|
@@ -4802,7 +5044,7 @@ var Redis2 = class _Redis extends Redis {
|
|
|
4802
5044
|
* that may use different naming conventions.
|
|
4803
5045
|
*/
|
|
4804
5046
|
static fromEnv(config) {
|
|
4805
|
-
if (
|
|
5047
|
+
if (process.env === void 0) {
|
|
4806
5048
|
throw new TypeError(
|
|
4807
5049
|
'[Upstash Redis] Unable to get environment variables, `process.env` is undefined. If you are deploying to cloudflare, please import from "@upstash/redis/cloudflare" instead'
|
|
4808
5050
|
);
|
|
@@ -4823,5 +5065,6 @@ var Redis2 = class _Redis extends Redis {
|
|
|
4823
5065
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4824
5066
|
0 && (module.exports = {
|
|
4825
5067
|
Redis,
|
|
4826
|
-
errors
|
|
5068
|
+
errors,
|
|
5069
|
+
s
|
|
4827
5070
|
});
|