@uniformdev/redirect 19.25.1-alpha.8 → 19.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -45,8 +45,8 @@ type RedirectClientCacheOptions = {
45
45
  declare abstract class RedirectClientCache<RedirectClientCacheOptions> {
46
46
  options: RedirectClientCacheOptions;
47
47
  constructor(options: RedirectClientCacheOptions);
48
- abstract get(key: string): Promise<PathTrie<RedirectDefinition>> | undefined;
49
- abstract set(key: string, data: Promise<PathTrie<RedirectDefinition>>, refresh: () => Promise<PathTrie<RedirectDefinition>>): void;
48
+ abstract get(key: string): Promise<PathTrie<DirectionAwareRedirectDefinition>> | undefined;
49
+ abstract set(key: string, data: Promise<PathTrie<DirectionAwareRedirectDefinition>>, refresh: () => Promise<PathTrie<DirectionAwareRedirectDefinition>>): void;
50
50
  abstract refresh(): Promise<void[]>;
51
51
  }
52
52
 
@@ -90,13 +90,12 @@ declare class RedirectClient extends ApiClient<RedirectClientOptions> {
90
90
  total: number | undefined;
91
91
  }, void, unknown>;
92
92
  getRedirectTrie: (options?: {
93
- reverse?: boolean;
94
93
  bypassDataCache?: boolean;
95
- }) => Promise<PathTrie<RedirectDefinition>>;
94
+ }) => Promise<PathTrie<DirectionAwareRedirectDefinition>>;
96
95
  resetRedirectTrieDataCache: () => Promise<void>;
97
96
  upsertRedirect: (redirect: RedirectUpsertRequest['redirect']) => Promise<string>;
98
97
  deleteRedirect: (id: string) => Promise<string>;
99
- static processUrlBestMatch: (url: string, trie: PathTrie<RedirectDefinition>, options?: RedirectOptions) => Promise<RedirectResult | undefined>;
98
+ static processUrlBestMatch: (url: string, trie: PathTrie<DirectionAwareRedirectDefinition>, options?: RedirectOptions) => Promise<RedirectResult | undefined>;
100
99
  processUrlBestMatch: (url: string, options?: RedirectOptions) => Promise<RedirectResult | undefined>;
101
100
  processUrlAllMatches: (url: string, options?: RedirectOptions) => Promise<RedirectResult[]>;
102
101
  private assembleTrie;
@@ -372,6 +371,9 @@ type RedirectDefinition = RedirectGetResponse['redirects'][0];
372
371
  type RedirectDefinitions = {
373
372
  redirects: RedirectDefinition['redirect'][];
374
373
  };
374
+ type DirectionAwareRedirectDefinition = RedirectDefinition & {
375
+ reverse: boolean;
376
+ };
375
377
  type RedirectResult = {
376
378
  url: string;
377
379
  label?: string;
@@ -391,8 +393,8 @@ type RedirectClientGetRedirects = Pick<RedirectClientGetRequest, 'ids' | 'limit'
391
393
  declare class WithMemoryCache extends RedirectClientCache<RedirectClientCacheOptions> {
392
394
  constructor(options: RedirectClientCacheOptions);
393
395
  private static trieCache;
394
- get(key: string): Promise<PathTrie<RedirectDefinition>> | undefined;
395
- set(key: string, data: Promise<PathTrie<RedirectDefinition>> | undefined, refresh: (() => Promise<PathTrie<RedirectDefinition>>) | undefined): void;
396
+ get(key: string): Promise<PathTrie<DirectionAwareRedirectDefinition>> | undefined;
397
+ set(key: string, data: Promise<PathTrie<DirectionAwareRedirectDefinition>> | undefined, refresh: (() => Promise<PathTrie<DirectionAwareRedirectDefinition>>) | undefined): void;
396
398
  refresh(): Promise<void[]>;
397
399
  }
398
400
 
@@ -442,4 +444,4 @@ type ProcessedUrl = {
442
444
  */
443
445
  declare function processUrl(url: string): ProcessedUrl;
444
446
 
445
- export { ExtractWildcards, PathTrie, PathTrieData, ProcessedUrl, RedirectClient, RedirectClientGetRedirect, RedirectClientGetRedirects, RedirectClientGetRequest, RedirectClientOptions, RedirectDataCache, RedirectDefinition, RedirectDefinitions, RedirectDeleteRequest, RedirectDeleteResponse, RedirectFileConverter, RedirectFileConverterParams, RedirectGetRequest, RedirectGetResponse, RedirectOptions, RedirectResult, RedirectUpsertRequest, RedirectUpsertResponse, SourceAndTarget, SourceTargetAndWildcards, UncachedRedirectClient, Wildcard, WithMemoryCache, pathTrieReturn, processUrl };
447
+ export { DirectionAwareRedirectDefinition, ExtractWildcards, PathTrie, PathTrieData, ProcessedUrl, RedirectClient, RedirectClientGetRedirect, RedirectClientGetRedirects, RedirectClientGetRequest, RedirectClientOptions, RedirectDataCache, RedirectDefinition, RedirectDefinitions, RedirectDeleteRequest, RedirectDeleteResponse, RedirectFileConverter, RedirectFileConverterParams, RedirectGetRequest, RedirectGetResponse, RedirectOptions, RedirectResult, RedirectUpsertRequest, RedirectUpsertResponse, SourceAndTarget, SourceTargetAndWildcards, UncachedRedirectClient, Wildcard, WithMemoryCache, pathTrieReturn, processUrl };
package/dist/index.esm.js CHANGED
@@ -240,8 +240,8 @@ var _RedirectClient = class extends ApiClient {
240
240
  if (result)
241
241
  return result;
242
242
  }
243
- const ret = this.assembleTrie(projectId);
244
- (_b = this.options.dataCache) == null ? void 0 : _b.set(key, ret, () => this.assembleTrie(projectId));
243
+ const ret = this.assembleTrie();
244
+ (_b = this.options.dataCache) == null ? void 0 : _b.set(key, ret, () => this.assembleTrie());
245
245
  return ret;
246
246
  };
247
247
  this.resetRedirectTrieDataCache = async () => {
@@ -301,11 +301,11 @@ var _RedirectClient = class extends ApiClient {
301
301
  };
302
302
  this.processUrlBestMatch = async (url, options) => {
303
303
  var _a;
304
- const trie = await this.getRedirectTrie({ reverse: Boolean(options == null ? void 0 : options.reverse) });
304
+ const trie = await this.getRedirectTrie();
305
305
  return (_a = _RedirectClient.processHops(url, trie, true, options)) == null ? void 0 : _a[0];
306
306
  };
307
307
  this.processUrlAllMatches = async (url, options) => {
308
- const trie = await this.getRedirectTrie({ reverse: Boolean(options == null ? void 0 : options.reverse) });
308
+ const trie = await this.getRedirectTrie();
309
309
  return _RedirectClient.processHops(url, trie, false, options);
310
310
  };
311
311
  if (options.dataCache && options.dataCache.options.prePopulate) {
@@ -341,13 +341,21 @@ var _RedirectClient = class extends ApiClient {
341
341
  }
342
342
  }
343
343
  }
344
- async assembleTrie(projectId, options) {
344
+ async assembleTrie() {
345
345
  const trie = new PathTrie();
346
346
  for await (const redirect of this.getAllRedirects()) {
347
- const path = processUrl(
348
- (options == null ? void 0 : options.reverse) ? redirect.redirect.targetUrl : redirect.redirect.sourceUrl
349
- ).path;
350
- trie.insert(path, redirect);
347
+ const source = processUrl(redirect.redirect.sourceUrl);
348
+ const target = processUrl(redirect.redirect.targetUrl);
349
+ trie.insert(source.path, {
350
+ redirect: redirect.redirect,
351
+ metadata: redirect.metadata,
352
+ reverse: false
353
+ });
354
+ trie.insert(target.path, {
355
+ redirect: redirect.redirect,
356
+ metadata: redirect.metadata,
357
+ reverse: true
358
+ });
351
359
  }
352
360
  return trie;
353
361
  }
@@ -405,7 +413,9 @@ var _RedirectClient = class extends ApiClient {
405
413
  definition = trie.find(processedUrl.path, bestMatch);
406
414
  }
407
415
  if (definition == null ? void 0 : definition.length) {
408
- return definition.filter((def) => _RedirectClient.validateRedirect(url, def.data.redirect)).map(
416
+ return definition.filter(
417
+ (def) => def.data.reverse === Boolean(options == null ? void 0 : options.reverse) && _RedirectClient.validateRedirect(url, def.data.redirect)
418
+ ).map(
409
419
  (def) => this.processDefinitionToResults(processedUrl, def.data, def.variables, options)
410
420
  ).filter((r) => Boolean(r));
411
421
  }
package/dist/index.js CHANGED
@@ -566,8 +566,8 @@ var _RedirectClient = class extends import_api.ApiClient {
566
566
  if (result)
567
567
  return result;
568
568
  }
569
- const ret = this.assembleTrie(projectId);
570
- (_b = this.options.dataCache) == null ? void 0 : _b.set(key, ret, () => this.assembleTrie(projectId));
569
+ const ret = this.assembleTrie();
570
+ (_b = this.options.dataCache) == null ? void 0 : _b.set(key, ret, () => this.assembleTrie());
571
571
  return ret;
572
572
  };
573
573
  this.resetRedirectTrieDataCache = async () => {
@@ -627,11 +627,11 @@ var _RedirectClient = class extends import_api.ApiClient {
627
627
  };
628
628
  this.processUrlBestMatch = async (url, options) => {
629
629
  var _a;
630
- const trie = await this.getRedirectTrie({ reverse: Boolean(options == null ? void 0 : options.reverse) });
630
+ const trie = await this.getRedirectTrie();
631
631
  return (_a = _RedirectClient.processHops(url, trie, true, options)) == null ? void 0 : _a[0];
632
632
  };
633
633
  this.processUrlAllMatches = async (url, options) => {
634
- const trie = await this.getRedirectTrie({ reverse: Boolean(options == null ? void 0 : options.reverse) });
634
+ const trie = await this.getRedirectTrie();
635
635
  return _RedirectClient.processHops(url, trie, false, options);
636
636
  };
637
637
  if (options.dataCache && options.dataCache.options.prePopulate) {
@@ -667,13 +667,21 @@ var _RedirectClient = class extends import_api.ApiClient {
667
667
  }
668
668
  }
669
669
  }
670
- async assembleTrie(projectId, options) {
670
+ async assembleTrie() {
671
671
  const trie = new PathTrie();
672
672
  for await (const redirect of this.getAllRedirects()) {
673
- const path = processUrl(
674
- (options == null ? void 0 : options.reverse) ? redirect.redirect.targetUrl : redirect.redirect.sourceUrl
675
- ).path;
676
- trie.insert(path, redirect);
673
+ const source = processUrl(redirect.redirect.sourceUrl);
674
+ const target = processUrl(redirect.redirect.targetUrl);
675
+ trie.insert(source.path, {
676
+ redirect: redirect.redirect,
677
+ metadata: redirect.metadata,
678
+ reverse: false
679
+ });
680
+ trie.insert(target.path, {
681
+ redirect: redirect.redirect,
682
+ metadata: redirect.metadata,
683
+ reverse: true
684
+ });
677
685
  }
678
686
  return trie;
679
687
  }
@@ -731,7 +739,9 @@ var _RedirectClient = class extends import_api.ApiClient {
731
739
  definition = trie.find(processedUrl.path, bestMatch);
732
740
  }
733
741
  if (definition == null ? void 0 : definition.length) {
734
- return definition.filter((def) => _RedirectClient.validateRedirect(url, def.data.redirect)).map(
742
+ return definition.filter(
743
+ (def) => def.data.reverse === Boolean(options == null ? void 0 : options.reverse) && _RedirectClient.validateRedirect(url, def.data.redirect)
744
+ ).map(
735
745
  (def) => this.processDefinitionToResults(processedUrl, def.data, def.variables, options)
736
746
  ).filter((r) => Boolean(r));
737
747
  }
package/dist/index.mjs CHANGED
@@ -240,8 +240,8 @@ var _RedirectClient = class extends ApiClient {
240
240
  if (result)
241
241
  return result;
242
242
  }
243
- const ret = this.assembleTrie(projectId);
244
- (_b = this.options.dataCache) == null ? void 0 : _b.set(key, ret, () => this.assembleTrie(projectId));
243
+ const ret = this.assembleTrie();
244
+ (_b = this.options.dataCache) == null ? void 0 : _b.set(key, ret, () => this.assembleTrie());
245
245
  return ret;
246
246
  };
247
247
  this.resetRedirectTrieDataCache = async () => {
@@ -301,11 +301,11 @@ var _RedirectClient = class extends ApiClient {
301
301
  };
302
302
  this.processUrlBestMatch = async (url, options) => {
303
303
  var _a;
304
- const trie = await this.getRedirectTrie({ reverse: Boolean(options == null ? void 0 : options.reverse) });
304
+ const trie = await this.getRedirectTrie();
305
305
  return (_a = _RedirectClient.processHops(url, trie, true, options)) == null ? void 0 : _a[0];
306
306
  };
307
307
  this.processUrlAllMatches = async (url, options) => {
308
- const trie = await this.getRedirectTrie({ reverse: Boolean(options == null ? void 0 : options.reverse) });
308
+ const trie = await this.getRedirectTrie();
309
309
  return _RedirectClient.processHops(url, trie, false, options);
310
310
  };
311
311
  if (options.dataCache && options.dataCache.options.prePopulate) {
@@ -341,13 +341,21 @@ var _RedirectClient = class extends ApiClient {
341
341
  }
342
342
  }
343
343
  }
344
- async assembleTrie(projectId, options) {
344
+ async assembleTrie() {
345
345
  const trie = new PathTrie();
346
346
  for await (const redirect of this.getAllRedirects()) {
347
- const path = processUrl(
348
- (options == null ? void 0 : options.reverse) ? redirect.redirect.targetUrl : redirect.redirect.sourceUrl
349
- ).path;
350
- trie.insert(path, redirect);
347
+ const source = processUrl(redirect.redirect.sourceUrl);
348
+ const target = processUrl(redirect.redirect.targetUrl);
349
+ trie.insert(source.path, {
350
+ redirect: redirect.redirect,
351
+ metadata: redirect.metadata,
352
+ reverse: false
353
+ });
354
+ trie.insert(target.path, {
355
+ redirect: redirect.redirect,
356
+ metadata: redirect.metadata,
357
+ reverse: true
358
+ });
351
359
  }
352
360
  return trie;
353
361
  }
@@ -405,7 +413,9 @@ var _RedirectClient = class extends ApiClient {
405
413
  definition = trie.find(processedUrl.path, bestMatch);
406
414
  }
407
415
  if (definition == null ? void 0 : definition.length) {
408
- return definition.filter((def) => _RedirectClient.validateRedirect(url, def.data.redirect)).map(
416
+ return definition.filter(
417
+ (def) => def.data.reverse === Boolean(options == null ? void 0 : options.reverse) && _RedirectClient.validateRedirect(url, def.data.redirect)
418
+ ).map(
409
419
  (def) => this.processDefinitionToResults(processedUrl, def.data, def.variables, options)
410
420
  ).filter((r) => Boolean(r));
411
421
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/redirect",
3
- "version": "19.25.1-alpha.8+dfec6f601",
3
+ "version": "19.26.0",
4
4
  "description": "Uniform redirect client",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./dist/index.js",
@@ -32,12 +32,12 @@
32
32
  "/dist"
33
33
  ],
34
34
  "dependencies": {
35
- "@uniformdev/context": "19.25.1-alpha.8+dfec6f601",
35
+ "@uniformdev/context": "19.26.0",
36
36
  "p-limit": "^3.1.0",
37
37
  "rfdc": "^1.3.0"
38
38
  },
39
39
  "publishConfig": {
40
40
  "access": "public"
41
41
  },
42
- "gitHead": "dfec6f6014629a7f86d8778af3af37d96b3cf9e6"
42
+ "gitHead": "860f4f8ae7161b5fb0b7a670bdfd1566fce45bee"
43
43
  }