@zodic/shared 0.0.198 → 0.0.200

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.
@@ -1221,4 +1221,61 @@ export class ConceptService {
1221
1221
  message: `Duplicate names processed and regenerated for ${conceptSlug}.`,
1222
1222
  };
1223
1223
  }
1224
+
1225
+ async cacheConceptNamesInBatches(conceptSlug: Concept, batchSize = 500) {
1226
+ console.log(
1227
+ `🔄 Fetching all EN names for '${conceptSlug}' from KV in batches...`
1228
+ );
1229
+
1230
+ const kvStore = this.context.env.KV_CONCEPTS;
1231
+ const kvCacheStore = this.context.env.KV_CONCEPT_CACHE;
1232
+ let cursor: string | undefined = undefined;
1233
+ let nameKeyMap: Record<string, string> = {}; // { name: kvKey }
1234
+ let totalKeysScanned = 0;
1235
+ let batchIndex = 0;
1236
+ const prefix = `concepts:en-us:${conceptSlug}:`; // ✅ Fetch only for this concept
1237
+
1238
+ do {
1239
+ const response: KVNamespaceListResult<KVConcept> = await kvStore.list({
1240
+ prefix,
1241
+ cursor,
1242
+ limit: batchSize, // ✅ Fetch in batches
1243
+ });
1244
+
1245
+ const {
1246
+ keys,
1247
+ cursor: newCursor,
1248
+ }: { keys: KVNamespaceListKey<KVConcept>[]; cursor?: string } = response;
1249
+ totalKeysScanned += keys.length;
1250
+
1251
+ for (const key of keys) {
1252
+ const kvData = await kvStore.get<KVConcept>(key.name, 'json');
1253
+ if (kvData?.name) {
1254
+ nameKeyMap[kvData.name] = key.name; // Map name to its KV key
1255
+ }
1256
+ }
1257
+
1258
+ // ✅ Store this batch separately for the concept to avoid exceeding KV limits
1259
+ await kvCacheStore.put(
1260
+ `cache:concepts:en-us:${conceptSlug}:${batchIndex}`,
1261
+ JSON.stringify(nameKeyMap)
1262
+ );
1263
+ console.log(
1264
+ `📦 Stored batch ${batchIndex} for ${conceptSlug}, ${
1265
+ Object.keys(nameKeyMap).length
1266
+ } names`
1267
+ );
1268
+
1269
+ batchIndex++;
1270
+ nameKeyMap = {}; // ✅ Clear for the next batch
1271
+ cursor = newCursor;
1272
+ } while (cursor);
1273
+
1274
+ console.log(
1275
+ `✅ Cached ${totalKeysScanned} EN names for ${conceptSlug} in ${batchIndex} batches.`
1276
+ );
1277
+ return {
1278
+ message: `Cached ${totalKeysScanned} EN names for ${conceptSlug} in ${batchIndex} batches.`,
1279
+ };
1280
+ }
1224
1281
  }
package/data/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './zodiacSignCombinations';
package/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './app';
2
+ export * from './data';
2
3
  export * as schema from './db/schema';
3
4
  export * from './middleware';
4
5
  export * from './types';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zodic/shared",
3
- "version": "0.0.198",
3
+ "version": "0.0.200",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -25,6 +25,7 @@ export type CentralBindings = {
25
25
  KV_CONCEPT_FAILURES: KVNamespace;
26
26
  KV_CONCEPT_NAMES: KVNamespace;
27
27
  KV_API_USAGE: KVNamespace;
28
+ KV_CONCEPT_CACHE: KVNamespace;
28
29
  CONCEPT_GENERATION_QUEUE: Queue;
29
30
  CONCEPT_NAMES_DO: DurableObjectNamespace;
30
31
  CROWN_QUEUE: Queue;
@@ -130,6 +131,7 @@ export type BackendBindings = Env &
130
131
  | 'LANTERN_QUEUE'
131
132
  | 'ORB_QUEUE'
132
133
  | 'KV_API_USAGE'
134
+ | 'KV_CONCEPT_CACHE'
133
135
  >;
134
136
 
135
137
  export type BackendCtx = Context<