@upstash/redis 1.36.0-rc.7 → 1.36.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/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
- createIndex: () => createIndex,
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,8 +98,18 @@ 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
112
+ var MAX_BUFFER_SIZE = 1024 * 1024;
106
113
  var HttpClient = class {
107
114
  baseUrl;
108
115
  headers;
@@ -226,11 +233,16 @@ var HttpClient = class {
226
233
  const decoder = new TextDecoder();
227
234
  (async () => {
228
235
  try {
236
+ let buffer = "";
229
237
  while (true) {
230
238
  const { value, done } = await reader.read();
231
239
  if (done) break;
232
- const chunk = decoder.decode(value);
233
- const lines = chunk.split("\n");
240
+ buffer += decoder.decode(value, { stream: true });
241
+ const lines = buffer.split("\n");
242
+ buffer = lines.pop() || "";
243
+ if (buffer.length > MAX_BUFFER_SIZE) {
244
+ throw new Error("Buffer size exceeded (1MB)");
245
+ }
234
246
  for (const line of lines) {
235
247
  if (line.startsWith("data: ")) {
236
248
  const data = line.slice(6);
@@ -348,7 +360,7 @@ var EXCLUDE_COMMANDS = /* @__PURE__ */ new Set([
348
360
  "zrange",
349
361
  "exec"
350
362
  ]);
351
- function createAutoPipelineProxy(_redis, json) {
363
+ function createAutoPipelineProxy(_redis, namespace = "root") {
352
364
  const redis = _redis;
353
365
  if (!redis.autoPipelineExecutor) {
354
366
  redis.autoPipelineExecutor = new AutoPipelineExecutor(redis);
@@ -358,29 +370,31 @@ function createAutoPipelineProxy(_redis, json) {
358
370
  if (command === "pipelineCounter") {
359
371
  return redis2.autoPipelineExecutor.pipelineCounter;
360
372
  }
361
- if (command === "json") {
362
- return createAutoPipelineProxy(redis2, true);
373
+ if (namespace === "root" && command === "json") {
374
+ return createAutoPipelineProxy(redis2, "json");
375
+ }
376
+ if (namespace === "root" && command === "functions") {
377
+ return createAutoPipelineProxy(redis2, "functions");
363
378
  }
364
- const commandInRedisButNotPipeline = command in redis2 && !(command in redis2.autoPipelineExecutor.pipeline);
365
- const isCommandExcluded = EXCLUDE_COMMANDS.has(command);
366
- if (commandInRedisButNotPipeline || isCommandExcluded) {
367
- return redis2[command];
379
+ if (namespace === "root") {
380
+ const commandInRedisButNotPipeline = command in redis2 && !(command in redis2.autoPipelineExecutor.pipeline);
381
+ const isCommandExcluded = EXCLUDE_COMMANDS.has(command);
382
+ if (commandInRedisButNotPipeline || isCommandExcluded) {
383
+ return redis2[command];
384
+ }
368
385
  }
369
- const isFunction = json ? typeof redis2.autoPipelineExecutor.pipeline.json[command] === "function" : typeof redis2.autoPipelineExecutor.pipeline[command] === "function";
386
+ const pipeline = redis2.autoPipelineExecutor.pipeline;
387
+ const targetFunction = namespace === "json" ? pipeline.json[command] : namespace === "functions" ? pipeline.functions[command] : pipeline[command];
388
+ const isFunction = typeof targetFunction === "function";
370
389
  if (isFunction) {
371
390
  return (...args) => {
372
- return redis2.autoPipelineExecutor.withAutoPipeline((pipeline) => {
373
- if (json) {
374
- pipeline.json[command](
375
- ...args
376
- );
377
- } else {
378
- pipeline[command](...args);
379
- }
391
+ return redis2.autoPipelineExecutor.withAutoPipeline((pipeline2) => {
392
+ const targetFunction2 = namespace === "json" ? pipeline2.json[command] : namespace === "functions" ? pipeline2.functions[command] : pipeline2[command];
393
+ targetFunction2(...args);
380
394
  });
381
395
  };
382
396
  }
383
- return redis2.autoPipelineExecutor.pipeline[command];
397
+ return targetFunction;
384
398
  }
385
399
  });
386
400
  }
@@ -403,7 +417,7 @@ var AutoPipelineExecutor = class {
403
417
  this.activePipeline = pipeline;
404
418
  this.indexInCurrentPipeline = 0;
405
419
  }
406
- const index2 = this.indexInCurrentPipeline++;
420
+ const index = this.indexInCurrentPipeline++;
407
421
  executeWithPipeline(pipeline);
408
422
  const pipelineDone = this.deferExecution().then(() => {
409
423
  if (!this.pipelinePromises.has(pipeline)) {
@@ -415,7 +429,7 @@ var AutoPipelineExecutor = class {
415
429
  return this.pipelinePromises.get(pipeline);
416
430
  });
417
431
  const results = await pipelineDone;
418
- const commandResult = results[index2];
432
+ const commandResult = results[index];
419
433
  if (commandResult.error) {
420
434
  throw new UpstashError(`Command failed: ${commandResult.error}`);
421
435
  }
@@ -673,6 +687,23 @@ var ExpireAtCommand = class extends Command {
673
687
  }
674
688
  };
675
689
 
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
+
676
707
  // pkg/commands/flushall.ts
677
708
  var FlushAllCommand = class extends Command {
678
709
  constructor(args, opts) {
@@ -695,6 +726,85 @@ var FlushDBCommand = class extends Command {
695
726
  }
696
727
  };
697
728
 
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
+
698
808
  // pkg/commands/geo_add.ts
699
809
  var GeoAddCommand = class extends Command {
700
810
  constructor([key, arg1, ...arg2], opts) {
@@ -1041,7 +1151,7 @@ var HGetCommand = class extends Command {
1041
1151
  };
1042
1152
 
1043
1153
  // pkg/commands/hgetall.ts
1044
- function deserialize(result) {
1154
+ function deserialize3(result) {
1045
1155
  if (result.length === 0) {
1046
1156
  return null;
1047
1157
  }
@@ -1061,7 +1171,7 @@ function deserialize(result) {
1061
1171
  var HGetAllCommand = class extends Command {
1062
1172
  constructor(cmd, opts) {
1063
1173
  super(["hgetall", ...cmd], {
1064
- deserialize: (result) => deserialize(result),
1174
+ deserialize: (result) => deserialize3(result),
1065
1175
  ...opts
1066
1176
  });
1067
1177
  }
@@ -1096,7 +1206,7 @@ var HLenCommand = class extends Command {
1096
1206
  };
1097
1207
 
1098
1208
  // pkg/commands/hmget.ts
1099
- function deserialize2(fields, result) {
1209
+ function deserialize4(fields, result) {
1100
1210
  if (result.every((field) => field === null)) {
1101
1211
  return null;
1102
1212
  }
@@ -1113,7 +1223,7 @@ function deserialize2(fields, result) {
1113
1223
  var HMGetCommand = class extends Command {
1114
1224
  constructor([key, ...fields], opts) {
1115
1225
  super(["hmget", key, ...fields], {
1116
- deserialize: (result) => deserialize2(fields, result),
1226
+ deserialize: (result) => deserialize4(fields, result),
1117
1227
  ...opts
1118
1228
  });
1119
1229
  }
@@ -1127,7 +1237,7 @@ var HMSetCommand = class extends Command {
1127
1237
  };
1128
1238
 
1129
1239
  // pkg/commands/hrandfield.ts
1130
- function deserialize3(result) {
1240
+ function deserialize5(result) {
1131
1241
  if (result.length === 0) {
1132
1242
  return null;
1133
1243
  }
@@ -1154,7 +1264,7 @@ var HRandFieldCommand = class extends Command {
1154
1264
  }
1155
1265
  super(command, {
1156
1266
  // @ts-expect-error to silence compiler
1157
- deserialize: cmd[2] ? (result) => deserialize3(result) : opts?.deserialize,
1267
+ deserialize: cmd[2] ? (result) => deserialize5(result) : opts?.deserialize,
1158
1268
  ...opts
1159
1269
  });
1160
1270
  }
@@ -2124,7 +2234,7 @@ var XPendingCommand = class extends Command {
2124
2234
  };
2125
2235
 
2126
2236
  // pkg/commands/xrange.ts
2127
- function deserialize4(result) {
2237
+ function deserialize6(result) {
2128
2238
  const obj = {};
2129
2239
  for (const e of result) {
2130
2240
  for (let i = 0; i < e.length; i += 2) {
@@ -2153,7 +2263,7 @@ var XRangeCommand = class extends Command {
2153
2263
  command.push("COUNT", count);
2154
2264
  }
2155
2265
  super(command, {
2156
- deserialize: (result) => deserialize4(result),
2266
+ deserialize: (result) => deserialize6(result),
2157
2267
  ...opts
2158
2268
  });
2159
2269
  }
@@ -2216,12 +2326,12 @@ var XRevRangeCommand = class extends Command {
2216
2326
  command.push("COUNT", count);
2217
2327
  }
2218
2328
  super(command, {
2219
- deserialize: (result) => deserialize5(result),
2329
+ deserialize: (result) => deserialize7(result),
2220
2330
  ...opts
2221
2331
  });
2222
2332
  }
2223
2333
  };
2224
- function deserialize5(result) {
2334
+ function deserialize7(result) {
2225
2335
  const obj = {};
2226
2336
  for (const e of result) {
2227
2337
  for (let i = 0; i < e.length; i += 2) {
@@ -2491,354 +2601,6 @@ var ZUnionStoreCommand = class extends Command {
2491
2601
  }
2492
2602
  };
2493
2603
 
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) {
2533
- return rawResponse.map((itemRaw) => {
2534
- const raw = itemRaw;
2535
- const key = raw[0];
2536
- const score = raw[1];
2537
- const rawFields = raw[2];
2538
- if (rawFields === void 0) {
2539
- return { key, score };
2540
- }
2541
- if (!Array.isArray(rawFields) || rawFields.length === 0) {
2542
- return { key, score, data: {} };
2543
- }
2544
- let data = {};
2545
- for (const fieldRaw of rawFields) {
2546
- const key2 = fieldRaw[0];
2547
- const value = fieldRaw[1];
2548
- const pathParts = key2.split(".");
2549
- if (pathParts.length == 1) {
2550
- data[key2] = value;
2551
- } else {
2552
- let currentObj = data;
2553
- for (let i = 0; i < pathParts.length - 1; i++) {
2554
- const pathPart = pathParts[i];
2555
- if (!(pathPart in currentObj)) {
2556
- currentObj[pathPart] = {};
2557
- }
2558
- currentObj = currentObj[pathPart];
2559
- }
2560
- currentObj[pathParts.at(-1)] = value;
2561
- }
2562
- }
2563
- if ("$" in data) {
2564
- data = data["$"];
2565
- }
2566
- return { key, score, data };
2567
- });
2568
- }
2569
- function deserializeDescribeResponse(rawResponse) {
2570
- const description = {};
2571
- for (let i = 0; i < rawResponse.length; i += 2) {
2572
- const descriptor = rawResponse[i];
2573
- switch (descriptor) {
2574
- case "name": {
2575
- description["name"] = rawResponse[i + 1];
2576
- break;
2577
- }
2578
- case "type": {
2579
- description["dataType"] = rawResponse[i + 1].toLowerCase();
2580
- break;
2581
- }
2582
- case "prefixes": {
2583
- description["prefixes"] = rawResponse[i + 1];
2584
- break;
2585
- }
2586
- case "language": {
2587
- description["language"] = rawResponse[i + 1];
2588
- break;
2589
- }
2590
- case "schema": {
2591
- const schema = {};
2592
- for (const fieldDescription of rawResponse[i + 1]) {
2593
- const fieldName = fieldDescription[0];
2594
- const fieldInfo = { type: fieldDescription[1] };
2595
- if (fieldDescription.length > 2) {
2596
- for (let j = 2; j < fieldDescription.length; j++) {
2597
- const fieldOption = fieldDescription[j];
2598
- switch (fieldOption) {
2599
- case "NOSTEM": {
2600
- fieldInfo.noStem = true;
2601
- break;
2602
- }
2603
- case "NOTOKENIZE": {
2604
- fieldInfo.noTokenize = true;
2605
- break;
2606
- }
2607
- case "FAST": {
2608
- fieldInfo.fast = true;
2609
- break;
2610
- }
2611
- }
2612
- }
2613
- }
2614
- schema[fieldName] = fieldInfo;
2615
- }
2616
- description["schema"] = schema;
2617
- break;
2618
- }
2619
- }
2620
- }
2621
- return description;
2622
- }
2623
- function parseCountResponse(rawResponse) {
2624
- return typeof rawResponse === "number" ? rawResponse : Number.parseInt(rawResponse, 10);
2625
- }
2626
-
2627
- // pkg/commands/search/command-builder.ts
2628
- function buildQueryCommand(redisCommand, name, options) {
2629
- const query = JSON.stringify(options?.filter ?? {});
2630
- const command = [redisCommand, name, query];
2631
- if (options?.limit !== void 0) {
2632
- command.push("LIMIT", options.limit.toString());
2633
- }
2634
- if (options?.offset !== void 0) {
2635
- command.push("OFFSET", options.offset.toString());
2636
- }
2637
- if (options?.select && Object.keys(options.select).length === 0) {
2638
- command.push("NOCONTENT");
2639
- }
2640
- if (options?.orderBy) {
2641
- command.push("SORTBY");
2642
- for (const [field, direction] of Object.entries(options.orderBy)) {
2643
- command.push(field, direction);
2644
- }
2645
- }
2646
- if (options?.highlight) {
2647
- command.push(
2648
- "HIGHLIGHT",
2649
- "FIELDS",
2650
- options.highlight.fields.length.toString(),
2651
- ...options.highlight.fields
2652
- );
2653
- if (options.highlight.preTag && options.highlight.postTag) {
2654
- command.push("TAGS", options.highlight.preTag, options.highlight.postTag);
2655
- }
2656
- }
2657
- if (options?.select && Object.keys(options.select).length > 0) {
2658
- command.push(
2659
- "RETURN",
2660
- Object.keys(options.select).length.toString(),
2661
- ...Object.keys(options.select)
2662
- );
2663
- }
2664
- return command;
2665
- }
2666
- function buildCreateIndexCommand(props) {
2667
- const { name, schema, dataType, prefix, language } = props;
2668
- const prefixArray = Array.isArray(prefix) ? prefix : [prefix];
2669
- const payload = [
2670
- name,
2671
- "ON",
2672
- dataType.toUpperCase(),
2673
- "PREFIX",
2674
- prefixArray.length.toString(),
2675
- ...prefixArray,
2676
- ...language ? ["LANGUAGE", language] : [],
2677
- "SCHEMA"
2678
- ];
2679
- const fields = flattenSchema(schema);
2680
- for (const field of fields) {
2681
- payload.push(field.path, field.type);
2682
- if (field.fast) {
2683
- payload.push("FAST");
2684
- }
2685
- if (field.noTokenize) {
2686
- payload.push("NOTOKENIZE");
2687
- }
2688
- if (field.noStem) {
2689
- payload.push("NOSTEM");
2690
- }
2691
- }
2692
- return ["SEARCH.CREATE", ...payload];
2693
- }
2694
-
2695
- // pkg/commands/search/search.ts
2696
- var SearchIndex = class {
2697
- name;
2698
- schema;
2699
- client;
2700
- constructor({ name, schema, client }) {
2701
- this.name = name;
2702
- this.schema = schema;
2703
- this.client = client;
2704
- }
2705
- async waitIndexing() {
2706
- const command = ["SEARCH.WAITINDEXING", this.name];
2707
- const result = await new ExecCommand(command).exec(
2708
- this.client
2709
- );
2710
- return result;
2711
- }
2712
- async describe() {
2713
- const command = ["SEARCH.DESCRIBE", this.name];
2714
- const rawResult = await new ExecCommand(command).exec(
2715
- this.client
2716
- );
2717
- return deserializeDescribeResponse(rawResult);
2718
- }
2719
- async query(options) {
2720
- const command = buildQueryCommand("SEARCH.QUERY", this.name, options);
2721
- const rawResult = await new ExecCommand(command).exec(
2722
- this.client
2723
- );
2724
- return deserializeQueryResponse(rawResult);
2725
- }
2726
- async count({ filter }) {
2727
- const command = buildQueryCommand("SEARCH.COUNT", this.name, { filter });
2728
- const rawResult = await new ExecCommand(command).exec(
2729
- this.client
2730
- );
2731
- return { count: parseCountResponse(rawResult) };
2732
- }
2733
- async drop() {
2734
- const command = ["SEARCH.DROP", this.name];
2735
- const result = await new ExecCommand(command).exec(
2736
- this.client
2737
- );
2738
- return result;
2739
- }
2740
- };
2741
- async function createIndex(props) {
2742
- const { name, schema, client } = props;
2743
- const createIndexCommand = buildCreateIndexCommand(props);
2744
- await new ExecCommand(createIndexCommand).exec(client);
2745
- return index(client, name, schema);
2746
- }
2747
- function index(client, name, schema) {
2748
- return new SearchIndex({ name, schema, client });
2749
- }
2750
-
2751
- // pkg/commands/search/schema-builder.ts
2752
- var BUILD = Symbol("build");
2753
- var TextFieldBuilder = class _TextFieldBuilder {
2754
- _noTokenize;
2755
- _noStem;
2756
- constructor(noTokenize = { noTokenize: false }, noStem = { noStem: false }) {
2757
- this._noTokenize = noTokenize;
2758
- this._noStem = noStem;
2759
- }
2760
- noTokenize() {
2761
- return new _TextFieldBuilder({ noTokenize: true }, this._noStem);
2762
- }
2763
- noStem() {
2764
- return new _TextFieldBuilder(this._noTokenize, { noStem: true });
2765
- }
2766
- [BUILD]() {
2767
- return this._noTokenize.noTokenize || this._noStem.noStem ? {
2768
- type: "TEXT",
2769
- ...this._noTokenize.noTokenize ? { noTokenize: true } : {},
2770
- ...this._noStem.noStem ? { noStem: true } : {}
2771
- } : "TEXT";
2772
- }
2773
- };
2774
- var NumericFieldBuilder = class {
2775
- type;
2776
- constructor(type) {
2777
- this.type = type;
2778
- }
2779
- [BUILD]() {
2780
- return {
2781
- type: this.type,
2782
- fast: true
2783
- };
2784
- }
2785
- };
2786
- var BoolFieldBuilder = class _BoolFieldBuilder {
2787
- _fast;
2788
- constructor(fast = { fast: false }) {
2789
- this._fast = fast;
2790
- }
2791
- fast() {
2792
- return new _BoolFieldBuilder({ fast: true });
2793
- }
2794
- [BUILD]() {
2795
- return this._fast.fast ? {
2796
- type: "BOOL",
2797
- fast: true
2798
- } : "BOOL";
2799
- }
2800
- };
2801
- var DateFieldBuilder = class _DateFieldBuilder {
2802
- _fast;
2803
- constructor(fast = { fast: false }) {
2804
- this._fast = fast;
2805
- }
2806
- fast() {
2807
- return new _DateFieldBuilder({ fast: true });
2808
- }
2809
- [BUILD]() {
2810
- return this._fast.fast ? {
2811
- type: "DATE",
2812
- fast: true
2813
- } : "DATE";
2814
- }
2815
- };
2816
- var s = {
2817
- string() {
2818
- return new TextFieldBuilder();
2819
- },
2820
- number(type = "F64") {
2821
- return new NumericFieldBuilder(type);
2822
- },
2823
- boolean() {
2824
- return new BoolFieldBuilder();
2825
- },
2826
- date() {
2827
- return new DateFieldBuilder();
2828
- },
2829
- object(fields) {
2830
- const result = {};
2831
- for (const [key, value] of Object.entries(fields)) {
2832
- if (value && typeof value === "object" && BUILD in value) {
2833
- result[key] = value[BUILD]();
2834
- } else {
2835
- result[key] = value;
2836
- }
2837
- }
2838
- return result;
2839
- }
2840
- };
2841
-
2842
2604
  // pkg/commands/psubscribe.ts
2843
2605
  var PSubscribeCommand = class extends Command {
2844
2606
  constructor(cmd, opts) {
@@ -3412,7 +3174,7 @@ var Pipeline = class {
3412
3174
  /**
3413
3175
  * @see https://redis.io/commands/lset
3414
3176
  */
3415
- lset = (key, index2, value) => this.chain(new LSetCommand([key, index2, value], this.commandOptions));
3177
+ lset = (key, index, value) => this.chain(new LSetCommand([key, index, value], this.commandOptions));
3416
3178
  /**
3417
3179
  * @see https://redis.io/commands/ltrim
3418
3180
  */
@@ -3864,6 +3626,38 @@ var Pipeline = class {
3864
3626
  type: (...args) => this.chain(new JsonTypeCommand(args, this.commandOptions))
3865
3627
  };
3866
3628
  }
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
+ }
3867
3661
  };
3868
3662
 
3869
3663
  // pkg/script.ts
@@ -3925,8 +3719,8 @@ var Script = class {
3925
3719
  /**
3926
3720
  * Compute the sha1 hash of the script and return its hex representation.
3927
3721
  */
3928
- async digest(s2) {
3929
- const data = new TextEncoder().encode(s2);
3722
+ async digest(s) {
3723
+ const data = new TextEncoder().encode(s);
3930
3724
  const hashBuffer = await import_uncrypto.subtle.digest("SHA-1", data);
3931
3725
  const hashArray = [...new Uint8Array(hashBuffer)];
3932
3726
  return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
@@ -3989,8 +3783,8 @@ var ScriptRO = class {
3989
3783
  /**
3990
3784
  * Compute the sha1 hash of the script and return its hex representation.
3991
3785
  */
3992
- async digest(s2) {
3993
- const data = new TextEncoder().encode(s2);
3786
+ async digest(s) {
3787
+ const data = new TextEncoder().encode(s);
3994
3788
  const hashBuffer = await import_uncrypto2.subtle.digest("SHA-1", data);
3995
3789
  const hashArray = [...new Uint8Array(hashBuffer)];
3996
3790
  return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
@@ -4125,6 +3919,40 @@ var Redis = class {
4125
3919
  type: (...args) => new JsonTypeCommand(args, this.opts).exec(this.client)
4126
3920
  };
4127
3921
  }
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
+ }
4128
3956
  /**
4129
3957
  * Wrap a new middleware around the HTTP client.
4130
3958
  */
@@ -4175,19 +4003,6 @@ var Redis = class {
4175
4003
  createScript(script, opts) {
4176
4004
  return opts?.readonly ? new ScriptRO(this, script) : new Script(this, script);
4177
4005
  }
4178
- get search() {
4179
- return {
4180
- createIndex: (props) => {
4181
- return createIndex({
4182
- ...props,
4183
- client: this.client
4184
- });
4185
- },
4186
- index: (name, schema) => {
4187
- return index(this.client, name, schema);
4188
- }
4189
- };
4190
- }
4191
4006
  /**
4192
4007
  * Create a new pipeline that allows you to send requests in bulk.
4193
4008
  *
@@ -4524,7 +4339,7 @@ var Redis = class {
4524
4339
  /**
4525
4340
  * @see https://redis.io/commands/lset
4526
4341
  */
4527
- lset = (key, index2, value) => new LSetCommand([key, index2, value], this.opts).exec(this.client);
4342
+ lset = (key, index, value) => new LSetCommand([key, index, value], this.opts).exec(this.client);
4528
4343
  /**
4529
4344
  * @see https://redis.io/commands/ltrim
4530
4345
  */
@@ -4895,7 +4710,7 @@ var Redis = class {
4895
4710
  };
4896
4711
 
4897
4712
  // version.ts
4898
- var VERSION = "v1.36.0-rc.7";
4713
+ var VERSION = "v1.36.1";
4899
4714
 
4900
4715
  // platforms/nodejs.ts
4901
4716
  if (typeof atob === "undefined") {
@@ -4953,18 +4768,20 @@ var Redis2 = class _Redis extends Redis {
4953
4768
  keepAlive: configOrRequester.keepAlive,
4954
4769
  readYourWrites: configOrRequester.readYourWrites
4955
4770
  });
4771
+ const safeEnv = typeof process === "object" && process && typeof process.env === "object" && process.env ? process.env : {};
4956
4772
  super(client, {
4957
4773
  automaticDeserialization: configOrRequester.automaticDeserialization,
4958
- enableTelemetry: configOrRequester.enableTelemetry ?? !process.env.UPSTASH_DISABLE_TELEMETRY,
4774
+ enableTelemetry: configOrRequester.enableTelemetry ?? !safeEnv.UPSTASH_DISABLE_TELEMETRY,
4959
4775
  latencyLogging: configOrRequester.latencyLogging,
4960
4776
  enableAutoPipelining: configOrRequester.enableAutoPipelining
4961
4777
  });
4778
+ const nodeVersion = typeof process === "object" && process ? process.version : void 0;
4962
4779
  this.addTelemetry({
4963
4780
  runtime: (
4964
4781
  // @ts-expect-error to silence compiler
4965
- typeof EdgeRuntime === "string" ? "edge-light" : `node@${process.version}`
4782
+ typeof EdgeRuntime === "string" ? "edge-light" : nodeVersion ? `node@${nodeVersion}` : "unknown"
4966
4783
  ),
4967
- platform: process.env.UPSTASH_CONSOLE ? "console" : process.env.VERCEL ? "vercel" : process.env.AWS_REGION ? "aws" : "unknown",
4784
+ platform: safeEnv.UPSTASH_CONSOLE ? "console" : safeEnv.VERCEL ? "vercel" : safeEnv.AWS_REGION ? "aws" : "unknown",
4968
4785
  sdk: `@upstash/redis@${VERSION}`
4969
4786
  });
4970
4787
  if (this.enableAutoPipelining) {
@@ -4985,7 +4802,7 @@ var Redis2 = class _Redis extends Redis {
4985
4802
  * that may use different naming conventions.
4986
4803
  */
4987
4804
  static fromEnv(config) {
4988
- if (process.env === void 0) {
4805
+ if (typeof process !== "object" || !process || typeof process.env !== "object" || !process.env) {
4989
4806
  throw new TypeError(
4990
4807
  '[Upstash Redis] Unable to get environment variables, `process.env` is undefined. If you are deploying to cloudflare, please import from "@upstash/redis/cloudflare" instead'
4991
4808
  );
@@ -5006,8 +4823,5 @@ var Redis2 = class _Redis extends Redis {
5006
4823
  // Annotate the CommonJS export names for ESM import in node:
5007
4824
  0 && (module.exports = {
5008
4825
  Redis,
5009
- createIndex,
5010
- errors,
5011
- index,
5012
- s
4826
+ errors
5013
4827
  });