@ophan/cli 0.0.1 → 0.0.3

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,161 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.createTempDb = createTempDb;
40
- exports.createMockSupabase = createMockSupabase;
41
- const better_sqlite3_1 = __importDefault(require("better-sqlite3"));
42
- const path = __importStar(require("path"));
43
- const fs = __importStar(require("fs"));
44
- const os = __importStar(require("os"));
45
- const test_utils_1 = require("@ophan/core/test-utils");
46
- /**
47
- * Creates a temp directory with a real .ophan/index.db file.
48
- * Sync functions take rootPath and construct dbPath internally,
49
- * so we need an actual file on disk.
50
- */
51
- function createTempDb(setup) {
52
- const rootPath = fs.mkdtempSync(path.join(os.tmpdir(), "ophan-test-"));
53
- const ophanDir = path.join(rootPath, ".ophan");
54
- fs.mkdirSync(ophanDir, { recursive: true });
55
- const dbPath = path.join(ophanDir, "index.db");
56
- // Create a real file-based DB with the current schema
57
- const memDb = (0, test_utils_1.createTestDb)();
58
- // Serialize the in-memory DB to a file
59
- const db = new better_sqlite3_1.default(dbPath);
60
- db.exec(memDb.prepare("SELECT sql FROM sqlite_master WHERE type='table'")
61
- .all()
62
- .map((row) => row.sql + ";")
63
- .join("\n"));
64
- // Run setup callback if provided
65
- if (setup)
66
- setup(db);
67
- db.close();
68
- memDb.close();
69
- return {
70
- dbPath,
71
- rootPath,
72
- cleanup: () => {
73
- try {
74
- fs.rmSync(rootPath, { recursive: true, force: true });
75
- }
76
- catch {
77
- // best-effort cleanup
78
- }
79
- },
80
- };
81
- }
82
- /**
83
- * Creates a mock Supabase client that records calls and returns controlled responses.
84
- *
85
- * Usage:
86
- * const mock = createMockSupabase({
87
- * 'repos.upsert': { data: [{ id: 'repo-1' }], error: null },
88
- * 'function_analysis.select': { data: [], error: null },
89
- * })
90
- * await syncToSupabase(rootPath, mock.client, userId)
91
- * expect(mock.calls).toContainEqual(expect.objectContaining({ table: 'repos', method: 'upsert' }))
92
- */
93
- function createMockSupabase(responses = {}) {
94
- const calls = [];
95
- function createChain(table) {
96
- let primaryMethod = "";
97
- const resolve = () => {
98
- const key = `${table}.${primaryMethod}`;
99
- return responses[key] ?? { data: [], error: null };
100
- };
101
- const chain = {};
102
- const handler = {
103
- get(_, prop) {
104
- // Primary operations
105
- if (["select", "insert", "upsert", "update", "delete"].includes(prop)) {
106
- return (...args) => {
107
- primaryMethod = prop;
108
- calls.push({ table, method: prop, args });
109
- return new Proxy(chain, handler);
110
- };
111
- }
112
- // Filter/modifier methods — chainable
113
- if ([
114
- "eq",
115
- "in",
116
- "neq",
117
- "gt",
118
- "lt",
119
- "gte",
120
- "lte",
121
- "like",
122
- "ilike",
123
- "contains",
124
- "order",
125
- "limit",
126
- "range",
127
- "or",
128
- "not",
129
- "is",
130
- "head",
131
- ].includes(prop)) {
132
- return (...args) => {
133
- calls.push({ table, method: prop, args });
134
- return new Proxy(chain, handler);
135
- };
136
- }
137
- // Terminal methods
138
- if (prop === "single" || prop === "maybeSingle") {
139
- return (...args) => {
140
- calls.push({ table, method: prop, args });
141
- return Promise.resolve(resolve());
142
- };
143
- }
144
- // Thenable — allows `await supabase.from(...).select(...).eq(...)`
145
- if (prop === "then") {
146
- const result = resolve();
147
- return Promise.resolve(result).then.bind(Promise.resolve(result));
148
- }
149
- return new Proxy(chain, handler);
150
- },
151
- };
152
- return new Proxy(chain, handler);
153
- }
154
- const client = {
155
- from: (table) => {
156
- calls.push({ table, method: "from", args: [table] });
157
- return createChain(table);
158
- },
159
- };
160
- return { client: client, calls };
161
- }