You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This document tracks the migration of all CoffeeScript code in the `@cocalc/database` package to TypeScript. The goal is to eliminate the 7,262 lines of CoffeeScript code across 8 files while maintaining backward compatibility and ensuring comprehensive test coverage.
10
+
This document tracks the migration of all CoffeeScript code in the `@cocalc/database` package to TypeScript. The goal is to eliminate the 6,827 lines of CoffeeScript code across 5 files while maintaining backward compatibility and ensuring comprehensive test coverage.
11
11
12
12
**WARNING**: This is the single scariest chunk of CoffeeScript left in CoCalc!
4.**Each module adds methods** to the class through CoffeeScript's class extension syntax
83
+
5.**Mixed implementation**: `postgres-ops.ts` is TypeScript, while other `postgres-*.coffee` modules still use CoffeeScript wrappers
84
84
85
85
### Two Database Access Patterns
86
86
@@ -166,7 +166,7 @@ coverageThreshold: {
166
166
167
167
#### 1.3 Decaffeinate Tool Testing ✅
168
168
169
-
Tested `decaffeinate` with sample code from `postgres-ops.coffee`:
169
+
Tested `decaffeinate` with sample code from the former `postgres-ops.coffee`:
170
170
171
171
```bash
172
172
cat << 'EOF' | npx decaffeinate --use-js-modules
@@ -190,6 +190,38 @@ EOF
190
190
191
191
**Conclusion**: `decaffeinate` is a good starting point but requires manual cleanup and TypeScript transformation. The output is readable and provides a solid foundation for conversion.
192
192
193
+
#### 1.4 Recommended Decaffeinate Parameters ✅
194
+
195
+
Based on the `postgres-user-query-queue` migration, the following parameters produce optimal output:
196
+
197
+
```bash
198
+
npx decaffeinate \
199
+
--use-js-modules \
200
+
--loose \
201
+
--optional-chaining \
202
+
--logical-assignment \
203
+
<filename>.coffee
204
+
```
205
+
206
+
**Parameter explanations:**
207
+
208
+
-`--use-js-modules`: Converts `require`/`module.exports` to ES6 `import`/`export` (cleaner, modern)
209
+
-`--loose`: Enables all loose transformations for simpler output
210
+
-`--optional-chaining`: Uses `?.` operator for safer property access
5.**Fix `delete` operators**: Add type assertions `(obj as any).prop` for delete operations
220
+
6.**Export cleanup**: Change `export { _ClassName as ClassName }` to `export class ClassName`
221
+
7.**Metrics imports**: Fix missing default exports (e.g., `import * as metrics` instead of `import metrics`)
222
+
223
+
**Time savings**: Using decaffeinate reduces migration time by ~50% compared to manual rewriting, while still producing clean, idiomatic TypeScript after manual fixes.
- **Remove `decaffeinate` from devDependencies** (no longer needed)
596
626
- Update exports in `package.json` if needed
597
-
- Remove `filesystem-bucket.coffee` (migrate to TypeScript first)
598
627
599
628
**Updated build script:**
600
629
@@ -697,16 +726,49 @@ pnpm test --watch
697
726
698
727
- **postgres-ops**: Migrated to TypeScript, split into `postgres/ops/backup.ts`, `postgres/ops/restore.ts`, and `postgres/ops/utils.ts`; tests split accordingly
699
728
- **filesystem-bucket**: Migrated to TypeScript with new tests
729
+
- **postgres-user-query-queue**: Migrated to TypeScript as `user-query/queue.ts` with 17 comprehensive tests; all tests pass (17/17 ✅)
0 commit comments