@upstash/redis 1.36.0 → 1.37.0-rc
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-4AG3JMXU.mjs → chunk-D4C7KXWT.mjs} +295 -199
- package/cloudflare.d.mts +2 -2
- package/cloudflare.d.ts +2 -2
- package/cloudflare.js +306 -214
- package/cloudflare.mjs +10 -14
- package/fastly.d.mts +2 -2
- package/fastly.d.ts +2 -2
- package/fastly.js +297 -201
- package/fastly.mjs +1 -1
- package/nodejs.d.mts +144 -3
- package/nodejs.d.ts +144 -3
- package/nodejs.js +462 -213
- 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,15 +99,6 @@ 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
104
|
var HttpClient = class {
|
|
@@ -354,7 +346,7 @@ var EXCLUDE_COMMANDS = /* @__PURE__ */ new Set([
|
|
|
354
346
|
"zrange",
|
|
355
347
|
"exec"
|
|
356
348
|
]);
|
|
357
|
-
function createAutoPipelineProxy(_redis,
|
|
349
|
+
function createAutoPipelineProxy(_redis, json) {
|
|
358
350
|
const redis = _redis;
|
|
359
351
|
if (!redis.autoPipelineExecutor) {
|
|
360
352
|
redis.autoPipelineExecutor = new AutoPipelineExecutor(redis);
|
|
@@ -364,31 +356,29 @@ function createAutoPipelineProxy(_redis, namespace = "root") {
|
|
|
364
356
|
if (command === "pipelineCounter") {
|
|
365
357
|
return redis2.autoPipelineExecutor.pipelineCounter;
|
|
366
358
|
}
|
|
367
|
-
if (
|
|
368
|
-
return createAutoPipelineProxy(redis2,
|
|
359
|
+
if (command === "json") {
|
|
360
|
+
return createAutoPipelineProxy(redis2, true);
|
|
369
361
|
}
|
|
370
|
-
|
|
371
|
-
|
|
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];
|
|
372
366
|
}
|
|
373
|
-
|
|
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";
|
|
367
|
+
const isFunction = json ? typeof redis2.autoPipelineExecutor.pipeline.json[command] === "function" : typeof redis2.autoPipelineExecutor.pipeline[command] === "function";
|
|
383
368
|
if (isFunction) {
|
|
384
369
|
return (...args) => {
|
|
385
|
-
return redis2.autoPipelineExecutor.withAutoPipeline((
|
|
386
|
-
|
|
387
|
-
|
|
370
|
+
return redis2.autoPipelineExecutor.withAutoPipeline((pipeline) => {
|
|
371
|
+
if (json) {
|
|
372
|
+
pipeline.json[command](
|
|
373
|
+
...args
|
|
374
|
+
);
|
|
375
|
+
} else {
|
|
376
|
+
pipeline[command](...args);
|
|
377
|
+
}
|
|
388
378
|
});
|
|
389
379
|
};
|
|
390
380
|
}
|
|
391
|
-
return
|
|
381
|
+
return redis2.autoPipelineExecutor.pipeline[command];
|
|
392
382
|
}
|
|
393
383
|
});
|
|
394
384
|
}
|
|
@@ -681,23 +671,6 @@ var ExpireAtCommand = class extends Command {
|
|
|
681
671
|
}
|
|
682
672
|
};
|
|
683
673
|
|
|
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
|
-
|
|
701
674
|
// pkg/commands/flushall.ts
|
|
702
675
|
var FlushAllCommand = class extends Command {
|
|
703
676
|
constructor(args, opts) {
|
|
@@ -720,85 +693,6 @@ var FlushDBCommand = class extends Command {
|
|
|
720
693
|
}
|
|
721
694
|
};
|
|
722
695
|
|
|
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
|
-
|
|
802
696
|
// pkg/commands/geo_add.ts
|
|
803
697
|
var GeoAddCommand = class extends Command {
|
|
804
698
|
constructor([key, arg1, ...arg2], opts) {
|
|
@@ -1145,7 +1039,7 @@ var HGetCommand = class extends Command {
|
|
|
1145
1039
|
};
|
|
1146
1040
|
|
|
1147
1041
|
// pkg/commands/hgetall.ts
|
|
1148
|
-
function
|
|
1042
|
+
function deserialize(result) {
|
|
1149
1043
|
if (result.length === 0) {
|
|
1150
1044
|
return null;
|
|
1151
1045
|
}
|
|
@@ -1165,7 +1059,7 @@ function deserialize3(result) {
|
|
|
1165
1059
|
var HGetAllCommand = class extends Command {
|
|
1166
1060
|
constructor(cmd, opts) {
|
|
1167
1061
|
super(["hgetall", ...cmd], {
|
|
1168
|
-
deserialize: (result) =>
|
|
1062
|
+
deserialize: (result) => deserialize(result),
|
|
1169
1063
|
...opts
|
|
1170
1064
|
});
|
|
1171
1065
|
}
|
|
@@ -1200,7 +1094,7 @@ var HLenCommand = class extends Command {
|
|
|
1200
1094
|
};
|
|
1201
1095
|
|
|
1202
1096
|
// pkg/commands/hmget.ts
|
|
1203
|
-
function
|
|
1097
|
+
function deserialize2(fields, result) {
|
|
1204
1098
|
if (result.every((field) => field === null)) {
|
|
1205
1099
|
return null;
|
|
1206
1100
|
}
|
|
@@ -1217,7 +1111,7 @@ function deserialize4(fields, result) {
|
|
|
1217
1111
|
var HMGetCommand = class extends Command {
|
|
1218
1112
|
constructor([key, ...fields], opts) {
|
|
1219
1113
|
super(["hmget", key, ...fields], {
|
|
1220
|
-
deserialize: (result) =>
|
|
1114
|
+
deserialize: (result) => deserialize2(fields, result),
|
|
1221
1115
|
...opts
|
|
1222
1116
|
});
|
|
1223
1117
|
}
|
|
@@ -1231,7 +1125,7 @@ var HMSetCommand = class extends Command {
|
|
|
1231
1125
|
};
|
|
1232
1126
|
|
|
1233
1127
|
// pkg/commands/hrandfield.ts
|
|
1234
|
-
function
|
|
1128
|
+
function deserialize3(result) {
|
|
1235
1129
|
if (result.length === 0) {
|
|
1236
1130
|
return null;
|
|
1237
1131
|
}
|
|
@@ -1258,7 +1152,7 @@ var HRandFieldCommand = class extends Command {
|
|
|
1258
1152
|
}
|
|
1259
1153
|
super(command, {
|
|
1260
1154
|
// @ts-expect-error to silence compiler
|
|
1261
|
-
deserialize: cmd[2] ? (result) =>
|
|
1155
|
+
deserialize: cmd[2] ? (result) => deserialize3(result) : opts?.deserialize,
|
|
1262
1156
|
...opts
|
|
1263
1157
|
});
|
|
1264
1158
|
}
|
|
@@ -2228,7 +2122,7 @@ var XPendingCommand = class extends Command {
|
|
|
2228
2122
|
};
|
|
2229
2123
|
|
|
2230
2124
|
// pkg/commands/xrange.ts
|
|
2231
|
-
function
|
|
2125
|
+
function deserialize4(result) {
|
|
2232
2126
|
const obj = {};
|
|
2233
2127
|
for (const e of result) {
|
|
2234
2128
|
for (let i = 0; i < e.length; i += 2) {
|
|
@@ -2257,7 +2151,7 @@ var XRangeCommand = class extends Command {
|
|
|
2257
2151
|
command.push("COUNT", count);
|
|
2258
2152
|
}
|
|
2259
2153
|
super(command, {
|
|
2260
|
-
deserialize: (result) =>
|
|
2154
|
+
deserialize: (result) => deserialize4(result),
|
|
2261
2155
|
...opts
|
|
2262
2156
|
});
|
|
2263
2157
|
}
|
|
@@ -2320,12 +2214,12 @@ var XRevRangeCommand = class extends Command {
|
|
|
2320
2214
|
command.push("COUNT", count);
|
|
2321
2215
|
}
|
|
2322
2216
|
super(command, {
|
|
2323
|
-
deserialize: (result) =>
|
|
2217
|
+
deserialize: (result) => deserialize5(result),
|
|
2324
2218
|
...opts
|
|
2325
2219
|
});
|
|
2326
2220
|
}
|
|
2327
2221
|
};
|
|
2328
|
-
function
|
|
2222
|
+
function deserialize5(result) {
|
|
2329
2223
|
const obj = {};
|
|
2330
2224
|
for (const e of result) {
|
|
2331
2225
|
for (let i = 0; i < e.length; i += 2) {
|
|
@@ -2595,6 +2489,265 @@ var ZUnionStoreCommand = class extends Command {
|
|
|
2595
2489
|
}
|
|
2596
2490
|
};
|
|
2597
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("SORTBY");
|
|
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
|
+
"RETURN",
|
|
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
|
+
|
|
2598
2751
|
// pkg/commands/psubscribe.ts
|
|
2599
2752
|
var PSubscribeCommand = class extends Command {
|
|
2600
2753
|
constructor(cmd, opts) {
|
|
@@ -3620,38 +3773,6 @@ var Pipeline = class {
|
|
|
3620
3773
|
type: (...args) => this.chain(new JsonTypeCommand(args, this.commandOptions))
|
|
3621
3774
|
};
|
|
3622
3775
|
}
|
|
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
|
-
}
|
|
3655
3776
|
};
|
|
3656
3777
|
|
|
3657
3778
|
// pkg/script.ts
|
|
@@ -3713,8 +3834,8 @@ var Script = class {
|
|
|
3713
3834
|
/**
|
|
3714
3835
|
* Compute the sha1 hash of the script and return its hex representation.
|
|
3715
3836
|
*/
|
|
3716
|
-
async digest(
|
|
3717
|
-
const data = new TextEncoder().encode(
|
|
3837
|
+
async digest(s2) {
|
|
3838
|
+
const data = new TextEncoder().encode(s2);
|
|
3718
3839
|
const hashBuffer = await import_uncrypto.subtle.digest("SHA-1", data);
|
|
3719
3840
|
const hashArray = [...new Uint8Array(hashBuffer)];
|
|
3720
3841
|
return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
@@ -3777,8 +3898,8 @@ var ScriptRO = class {
|
|
|
3777
3898
|
/**
|
|
3778
3899
|
* Compute the sha1 hash of the script and return its hex representation.
|
|
3779
3900
|
*/
|
|
3780
|
-
async digest(
|
|
3781
|
-
const data = new TextEncoder().encode(
|
|
3901
|
+
async digest(s2) {
|
|
3902
|
+
const data = new TextEncoder().encode(s2);
|
|
3782
3903
|
const hashBuffer = await import_uncrypto2.subtle.digest("SHA-1", data);
|
|
3783
3904
|
const hashArray = [...new Uint8Array(hashBuffer)];
|
|
3784
3905
|
return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
@@ -3913,40 +4034,6 @@ var Redis = class {
|
|
|
3913
4034
|
type: (...args) => new JsonTypeCommand(args, this.opts).exec(this.client)
|
|
3914
4035
|
};
|
|
3915
4036
|
}
|
|
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
|
-
}
|
|
3950
4037
|
/**
|
|
3951
4038
|
* Wrap a new middleware around the HTTP client.
|
|
3952
4039
|
*/
|
|
@@ -3997,6 +4084,16 @@ var Redis = class {
|
|
|
3997
4084
|
createScript(script, opts) {
|
|
3998
4085
|
return opts?.readonly ? new ScriptRO(this, script) : new Script(this, script);
|
|
3999
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
|
+
}
|
|
4000
4097
|
/**
|
|
4001
4098
|
* Create a new pipeline that allows you to send requests in bulk.
|
|
4002
4099
|
*
|
|
@@ -4704,7 +4801,160 @@ var Redis = class {
|
|
|
4704
4801
|
};
|
|
4705
4802
|
|
|
4706
4803
|
// version.ts
|
|
4707
|
-
var VERSION = "v1.
|
|
4804
|
+
var VERSION = "v1.37.0-rc";
|
|
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
|
+
};
|
|
4708
4958
|
|
|
4709
4959
|
// platforms/nodejs.ts
|
|
4710
4960
|
if (typeof atob === "undefined") {
|
|
@@ -4762,20 +5012,18 @@ var Redis2 = class _Redis extends Redis {
|
|
|
4762
5012
|
keepAlive: configOrRequester.keepAlive,
|
|
4763
5013
|
readYourWrites: configOrRequester.readYourWrites
|
|
4764
5014
|
});
|
|
4765
|
-
const safeEnv = typeof process === "object" && process && typeof process.env === "object" && process.env ? process.env : {};
|
|
4766
5015
|
super(client, {
|
|
4767
5016
|
automaticDeserialization: configOrRequester.automaticDeserialization,
|
|
4768
|
-
enableTelemetry: configOrRequester.enableTelemetry ?? !
|
|
5017
|
+
enableTelemetry: configOrRequester.enableTelemetry ?? !process.env.UPSTASH_DISABLE_TELEMETRY,
|
|
4769
5018
|
latencyLogging: configOrRequester.latencyLogging,
|
|
4770
5019
|
enableAutoPipelining: configOrRequester.enableAutoPipelining
|
|
4771
5020
|
});
|
|
4772
|
-
const nodeVersion = typeof process === "object" && process ? process.version : void 0;
|
|
4773
5021
|
this.addTelemetry({
|
|
4774
5022
|
runtime: (
|
|
4775
5023
|
// @ts-expect-error to silence compiler
|
|
4776
|
-
typeof EdgeRuntime === "string" ? "edge-light" :
|
|
5024
|
+
typeof EdgeRuntime === "string" ? "edge-light" : `node@${process.version}`
|
|
4777
5025
|
),
|
|
4778
|
-
platform:
|
|
5026
|
+
platform: process.env.UPSTASH_CONSOLE ? "console" : process.env.VERCEL ? "vercel" : process.env.AWS_REGION ? "aws" : "unknown",
|
|
4779
5027
|
sdk: `@upstash/redis@${VERSION}`
|
|
4780
5028
|
});
|
|
4781
5029
|
if (this.enableAutoPipelining) {
|
|
@@ -4796,7 +5044,7 @@ var Redis2 = class _Redis extends Redis {
|
|
|
4796
5044
|
* that may use different naming conventions.
|
|
4797
5045
|
*/
|
|
4798
5046
|
static fromEnv(config) {
|
|
4799
|
-
if (
|
|
5047
|
+
if (process.env === void 0) {
|
|
4800
5048
|
throw new TypeError(
|
|
4801
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'
|
|
4802
5050
|
);
|
|
@@ -4817,5 +5065,6 @@ var Redis2 = class _Redis extends Redis {
|
|
|
4817
5065
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4818
5066
|
0 && (module.exports = {
|
|
4819
5067
|
Redis,
|
|
4820
|
-
errors
|
|
5068
|
+
errors,
|
|
5069
|
+
s
|
|
4821
5070
|
});
|