@zodic/shared 0.0.174 → 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.
@@ -2,7 +2,7 @@ import { and, eq } from 'drizzle-orm';
2
2
  import { inject, injectable } from 'inversify';
3
3
  import 'reflect-metadata';
4
4
  import { v4 as uuidv4 } from 'uuid';
5
- import { schema } from '../..';
5
+ import { ConceptNameDO, schema } from '../..';
6
6
  import { Concept, ControlNetConfig, Languages } from '../../types';
7
7
  import {
8
8
  KVConcept,
@@ -35,9 +35,9 @@ export class ConceptService {
35
35
  const kvKeyPT = buildConceptKVKey('pt-br', conceptSlug, combinationString);
36
36
  const failureKey = `failures:basic-info:${conceptSlug}:${combinationString}`;
37
37
 
38
- const doUrl = `${this.context.env.API_BASE_URL}/api/concept-names/${conceptSlug}`;
39
-
40
- console.log('!-- doUrl: ', doUrl);
38
+ // Use Durable Object stub
39
+ const id = this.context.env.CONCEPT_NAMES_DO.idFromName(conceptSlug);
40
+ const stub = this.context.env.CONCEPT_NAMES_DO.get(id);
41
41
 
42
42
  let attempts = 0;
43
43
  const maxAttempts = 3;
@@ -51,7 +51,7 @@ export class ConceptService {
51
51
  // ✅ Fetch the latest name list from Durable Object
52
52
  let allNamesEN: string[] = [];
53
53
  let allNamesPT: string[] = [];
54
- const response = await fetch(doUrl);
54
+ const response = await stub.fetch('https://internal/names');
55
55
  if (response.ok) {
56
56
  const data = (await response.json()) as {
57
57
  'en-us': string[];
@@ -60,8 +60,8 @@ export class ConceptService {
60
60
  allNamesEN = data['en-us'] || [];
61
61
  allNamesPT = data['pt-br'] || [];
62
62
  } else {
63
- console.log('!-- Error on fetching url: ', doUrl);
64
- console.log('!-- Response: ', JSON.stringify(response, null, 2));
63
+ console.log('!-- Error fetching names from Durable Object');
64
+ console.log('!-- Response:', await response.text());
65
65
  }
66
66
 
67
67
  // ✅ Fetch existing KV data to backfill Durable Object if necessary
@@ -71,37 +71,19 @@ export class ConceptService {
71
71
  // 🔥 If names already exist in KV but not in DO, add them
72
72
  if (existingEN.name && !allNamesEN.includes(existingEN.name)) {
73
73
  console.log(`⚡ Backfilling existing name to DO: ${existingEN.name}`);
74
- try {
75
- await fetch(`${doUrl}/add`, {
76
- method: 'POST',
77
- body: JSON.stringify({
78
- language: 'en-us',
79
- name: existingEN.name,
80
- }),
81
- headers: { 'Content-Type': 'application/json' },
82
- });
83
- } catch (e) {
84
- console.log(
85
- `!-- Error on fetch ConceptNames ${(e as Error).message}`
86
- );
87
- }
74
+ await stub.fetch('https://internal/add-name', {
75
+ method: 'POST',
76
+ body: JSON.stringify({ language: 'en-us', name: existingEN.name }),
77
+ headers: { 'Content-Type': 'application/json' },
78
+ });
88
79
  }
89
80
  if (existingPT.name && !allNamesPT.includes(existingPT.name)) {
90
81
  console.log(`⚡ Backfilling existing name to DO: ${existingPT.name}`);
91
- try {
92
- await fetch(`${doUrl}/add`, {
93
- method: 'POST',
94
- body: JSON.stringify({
95
- language: 'pt-br',
96
- name: existingPT.name,
97
- }),
98
- headers: { 'Content-Type': 'application/json' },
99
- });
100
- } catch (e) {
101
- console.log(
102
- `!-- Error on fetch ConceptNames ${(e as Error).message}`
103
- );
104
- }
82
+ await stub.fetch('https://internal/add-name', {
83
+ method: 'POST',
84
+ body: JSON.stringify({ language: 'pt-br', name: existingPT.name }),
85
+ headers: { 'Content-Type': 'application/json' },
86
+ });
105
87
  }
106
88
 
107
89
  // ✅ Skip generation if basic info already exists and override is false
@@ -145,13 +127,13 @@ export class ConceptService {
145
127
  }
146
128
 
147
129
  // ✅ **Immediately update Durable Object with the new name**
148
- await fetch(`${doUrl}/add`, {
130
+ await stub.fetch('https://internal/add-name', {
149
131
  method: 'POST',
150
132
  body: JSON.stringify({ language: 'en-us', name: nameEN }),
151
133
  headers: { 'Content-Type': 'application/json' },
152
134
  });
153
135
 
154
- await fetch(`${doUrl}/add`, {
136
+ await stub.fetch('https://internal/add-name', {
155
137
  method: 'POST',
156
138
  body: JSON.stringify({ language: 'pt-br', name: namePT }),
157
139
  headers: { 'Content-Type': 'application/json' },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zodic/shared",
3
- "version": "0.0.174",
3
+ "version": "0.0.176",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -9,6 +9,7 @@ import {
9
9
  import { DrizzleD1Database } from 'drizzle-orm/d1';
10
10
  import { Context, Env } from 'hono';
11
11
  import type { Container } from 'inversify';
12
+ import { ConceptNameDO } from '../../app';
12
13
 
13
14
  export type CentralBindings = {
14
15
  TEST_IMAGES_BUCKET: R2Bucket;