@zodic/shared 0.0.178 → 0.0.179

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,16 +1,15 @@
1
1
  import { DurableObjectState } from '@cloudflare/workers-types';
2
- import { BackendBindings, ConceptProgress } from '../../types';
3
2
 
4
3
  export class ConceptNameDO {
5
4
  state: DurableObjectState;
6
- env: BackendBindings;
5
+ env: any;
7
6
  names: { 'en-us': string[]; 'pt-br': string[] };
8
7
  count: number;
9
8
  timestamps: number[];
10
9
 
11
10
  static TOTAL_NAMES = 1728; // Maximum total names to be generated
12
11
 
13
- constructor(state: DurableObjectState, env: BackendBindings) {
12
+ constructor(state: DurableObjectState, env: any) {
14
13
  this.state = state;
15
14
  this.env = env;
16
15
  this.names = { 'en-us': [], 'pt-br': [] };
@@ -61,11 +60,17 @@ export class ConceptNameDO {
61
60
  return this.names;
62
61
  }
63
62
 
64
- async getProgress(): Promise<ConceptProgress> {
63
+ async getProgress(): Promise<{
64
+ count: number;
65
+ total: number;
66
+ progress: string;
67
+ ratePerMinute: number;
68
+ estimatedTimeMinutes: number | 'N/A';
69
+ }> {
65
70
  if (this.count === 0) {
66
71
  this.count = (await this.state.storage.get<number>('count')) || 0;
67
72
  }
68
- if (this.timestamps.length === 0) {
73
+ if (!Array.isArray(this.timestamps) || this.timestamps.length === 0) {
69
74
  this.timestamps =
70
75
  (await this.state.storage.get<number[]>('timestamps')) || [];
71
76
  }
@@ -73,7 +78,10 @@ export class ConceptNameDO {
73
78
  const now = Date.now();
74
79
  const oneMinuteAgo = now - 60 * 1000;
75
80
 
76
- const recentTimestamps = this.timestamps.filter((ts) => ts >= oneMinuteAgo);
81
+ const recentTimestamps = Array.isArray(this.timestamps)
82
+ ? this.timestamps.filter((ts) => ts >= oneMinuteAgo)
83
+ : []; // ✅ Ensure it's an array before calling filter
84
+
77
85
  const ratePerMinute = recentTimestamps.length;
78
86
 
79
87
  const remainingNames = ConceptNameDO.TOTAL_NAMES - this.count;
@@ -110,7 +118,12 @@ export class ConceptNameDO {
110
118
  recordTimestamp(): void {
111
119
  const now = Date.now();
112
120
 
113
- // Keep only the last 60 timestamps
121
+ // Ensure timestamps is always an array before modifying
122
+ if (!Array.isArray(this.timestamps)) {
123
+ this.timestamps = [];
124
+ }
125
+
126
+ // ✅ Keep only the last 60 timestamps
114
127
  if (this.timestamps.length >= 60) {
115
128
  this.timestamps.splice(0, this.timestamps.length - 59);
116
129
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zodic/shared",
3
- "version": "0.0.178",
3
+ "version": "0.0.179",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "publishConfig": {