bulltrackers-module 1.0.532 → 1.0.533

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.
@@ -28,10 +28,25 @@ try {
28
28
  function getRegistryFunctions(options = {}) {
29
29
  // Try to get from options first (injected)
30
30
  if (options.collectionRegistry) {
31
+ // Try to get getCollectionMetadata from injected registry, fallback to module-level if not available
32
+ let getMetadata = options.collectionRegistry.getCollectionMetadata;
33
+ if (!getMetadata && getCollectionMetadata) {
34
+ getMetadata = getCollectionMetadata;
35
+ }
36
+ // If still not available, try requiring the registry
37
+ if (!getMetadata) {
38
+ try {
39
+ const registryFallback = require('../../../../../../config/collection_registry');
40
+ getMetadata = registryFallback.getCollectionMetadata;
41
+ } catch (e) {
42
+ // getMetadata will be undefined, which is fine - we'll handle it gracefully
43
+ }
44
+ }
45
+
31
46
  return {
32
47
  getCollectionPath: options.collectionRegistry.getCollectionPath,
33
48
  resolvePath: options.collectionRegistry.resolvePath || resolvePath,
34
- getCollectionMetadata: options.collectionRegistry.getCollectionMetadata
49
+ getCollectionMetadata: getMetadata
35
50
  };
36
51
  }
37
52
 
@@ -42,14 +57,19 @@ function getRegistryFunctions(options = {}) {
42
57
 
43
58
  // Last resort: try to require again (in case it's available now)
44
59
  try {
45
- const registry = require('../../../../../../config/collection_registry');
60
+ const registryLastResort = require('../../../../../../config/collection_registry');
46
61
  return {
47
- getCollectionPath: registry.getCollectionPath,
48
- resolvePath: registry.resolvePath,
49
- getCollectionMetadata: registry.getCollectionMetadata
62
+ getCollectionPath: registryLastResort.getCollectionPath,
63
+ resolvePath: registryLastResort.resolvePath,
64
+ getCollectionMetadata: registryLastResort.getCollectionMetadata
50
65
  };
51
66
  } catch (error) {
52
- throw new Error('Collection registry functions not available. Please provide collectionRegistry in dependencies.');
67
+ // Return functions that might be available, with getCollectionMetadata as undefined
68
+ return {
69
+ getCollectionPath: getCollectionPath || null,
70
+ resolvePath: resolvePath || null,
71
+ getCollectionMetadata: getCollectionMetadata || null
72
+ };
53
73
  }
54
74
  }
55
75
 
@@ -120,47 +140,49 @@ function getLegacyPath(dataType, userCid, config = {}, params = {}, category = n
120
140
  const getMetadata = registryFuncs.getCollectionMetadata;
121
141
  const resolve = registryFuncs.resolvePath;
122
142
 
123
- // Check if getCollectionMetadata is available
124
- if (!getMetadata || typeof getMetadata !== 'function') {
125
- throw new Error('getCollectionMetadata is not available');
126
- }
127
-
128
- const metadata = getMetadata(category, subcategory);
129
- if (metadata && metadata.legacyPaths && metadata.legacyPaths.length > 0) {
130
- // Use first legacy path from registry (can be enhanced to try multiple)
131
- let legacyPathTemplate = metadata.legacyPaths[0];
132
-
133
- // Resolve dynamic segments in the legacy path
134
- const cid = String(userCid);
135
- const resolvedParams = {
136
- cid: cid,
137
- userCid: cid,
138
- firebaseUid: params.firebaseUid || '',
139
- username: params.username || '',
140
- date: params.date || '{date}',
141
- requestId: params.requestId || '{requestId}',
142
- piCid: params.piCid || cid,
143
- reviewId: params.reviewId || `{piCid}_{userCid}`,
144
- postId: params.postId || '{postId}',
145
- viewId: params.viewId || `{piCid}_{viewerCid}_{timestamp}`,
146
- watchlistId: params.watchlistId || '{watchlistId}',
147
- version: params.version || '{version}',
148
- ...params // Allow params to override defaults
149
- };
150
-
151
- // Resolve path template
152
- legacyPathTemplate = resolve(legacyPathTemplate, resolvedParams);
153
-
154
- // Replace any remaining placeholders
155
- for (const [key, value] of Object.entries(resolvedParams)) {
156
- legacyPathTemplate = legacyPathTemplate.replace(`{${key}}`, String(value));
143
+ // Check if getCollectionMetadata is available - if not, fall through to hardcoded map
144
+ if (getMetadata && typeof getMetadata === 'function') {
145
+ const metadata = getMetadata(category, subcategory);
146
+ if (metadata && metadata.legacyPaths && metadata.legacyPaths.length > 0) {
147
+ // Use first legacy path from registry (can be enhanced to try multiple)
148
+ let legacyPathTemplate = metadata.legacyPaths[0];
149
+
150
+ // Resolve dynamic segments in the legacy path
151
+ const cid = String(userCid);
152
+ const resolvedParams = {
153
+ cid: cid,
154
+ userCid: cid,
155
+ firebaseUid: params.firebaseUid || '',
156
+ username: params.username || '',
157
+ date: params.date || '{date}',
158
+ requestId: params.requestId || '{requestId}',
159
+ piCid: params.piCid || cid,
160
+ reviewId: params.reviewId || `{piCid}_{userCid}`,
161
+ postId: params.postId || '{postId}',
162
+ viewId: params.viewId || `{piCid}_{viewerCid}_{timestamp}`,
163
+ watchlistId: params.watchlistId || '{watchlistId}',
164
+ version: params.version || '{version}',
165
+ ...params // Allow params to override defaults
166
+ };
167
+
168
+ // Resolve path template
169
+ legacyPathTemplate = resolve(legacyPathTemplate, resolvedParams);
170
+
171
+ // Replace any remaining placeholders
172
+ for (const [key, value] of Object.entries(resolvedParams)) {
173
+ legacyPathTemplate = legacyPathTemplate.replace(`{${key}}`, String(value));
174
+ }
175
+
176
+ return legacyPathTemplate;
157
177
  }
158
-
159
- return legacyPathTemplate;
178
+ // If metadata exists but no legacyPaths, fall through to hardcoded map
160
179
  }
161
180
  } catch (error) {
162
181
  // Fall through to hardcoded map if registry lookup fails
163
- console.warn(`[getLegacyPath] Could not get legacy path from registry for ${category}/${subcategory}:`, error.message);
182
+ // Only log if it's not the expected "not available" error
183
+ if (error.message !== 'getCollectionMetadata is not available') {
184
+ console.warn(`[getLegacyPath] Could not get legacy path from registry for ${category}/${subcategory}:`, error.message);
185
+ }
164
186
  }
165
187
  }
166
188
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bulltrackers-module",
3
- "version": "1.0.532",
3
+ "version": "1.0.533",
4
4
  "description": "Helper Functions for Bulltrackers.",
5
5
  "main": "index.js",
6
6
  "files": [