@zodic/shared 0.0.175 → 0.0.176

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.
@@ -1,12 +1,11 @@
1
1
  import { DurableObjectState } from '@cloudflare/workers-types';
2
2
 
3
- export class ConceptNameDO extends DurableObject {
3
+ export class ConceptNameDO {
4
4
  state: DurableObjectState;
5
5
  env: any;
6
6
  names: { 'en-us': string[]; 'pt-br': string[] };
7
7
 
8
8
  constructor(state: DurableObjectState, env: any) {
9
- super(state, env); // ✅ Call super() for DurableObject
10
9
  this.state = state;
11
10
  this.env = env;
12
11
  this.names = { 'en-us': [], 'pt-br': [] };
@@ -24,22 +23,18 @@ export class ConceptNameDO extends DurableObject {
24
23
  }
25
24
 
26
25
  if (method === 'POST' && url.pathname === '/add-name') {
27
- try {
28
- const { language, name } = (await request.json()) as {
29
- language: 'en-us' | 'pt-br';
30
- name: string;
31
- };
32
-
33
- if (!['en-us', 'pt-br'].includes(language)) {
34
- return new Response('Invalid language', { status: 400 });
35
- }
36
-
37
- await this.addName(language, name);
38
- return new Response('OK', { status: 200 });
39
- } catch (error) {
40
- console.error('❌ Error processing request:', error);
41
- return new Response('Bad Request', { status: 400 });
26
+ const { language, name } = (await request.json()) as {
27
+ language: 'en-us' | 'pt-br';
28
+ name: string;
29
+ };
30
+
31
+ // ✅ Normalize language codes to match `generateBasicInfo`
32
+ if (!['en-us', 'pt-br'].includes(language)) {
33
+ return new Response('Invalid language', { status: 400 });
42
34
  }
35
+
36
+ await this.addName(language, name);
37
+ return new Response('OK', { status: 200 });
43
38
  }
44
39
 
45
40
  return new Response('Not Found', { status: 404 });
@@ -50,19 +45,14 @@ export class ConceptNameDO extends DurableObject {
50
45
  'en-us': string[];
51
46
  'pt-br': string[];
52
47
  }>('names');
53
-
54
48
  if (stored) {
55
49
  this.names = stored;
56
50
  }
57
51
  }
58
52
 
59
53
  async addName(language: 'en-us' | 'pt-br', name: string): Promise<void> {
60
- await this.loadNames(); // Ensure we have the latest names
61
-
62
54
  if (!this.names[language].includes(name)) {
63
55
  this.names[language].push(name);
64
-
65
- // ✅ Ensure concurrent writes do not overwrite existing stored data
66
56
  await this.state.storage.put('names', this.names);
67
57
  }
68
58
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zodic/shared",
3
- "version": "0.0.175",
3
+ "version": "0.0.176",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -26,7 +26,7 @@ export type CentralBindings = {
26
26
  KV_CONCEPT_FAILURES: KVNamespace;
27
27
  KV_CONCEPT_NAMES: KVNamespace;
28
28
  CONCEPT_GENERATION_QUEUE: Queue;
29
- CONCEPT_NAMES_DO: DurableObjectNamespace<ConceptNameDO>;
29
+ CONCEPT_NAMES_DO: DurableObjectNamespace;
30
30
 
31
31
  PROMPT_IMAGE_DESCRIBER: string;
32
32
  PROMPT_GENERATE_ARCHETYPE_BASIC_INFO: string;