@webneat/codewiki 0.0.1
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.
- package/LICENSE +21 -0
- package/README.md +59 -0
- package/dist/cli/bin.cjs +3206 -0
- package/dist/cli/bin.cjs.map +1 -0
- package/dist/cli/bin.d.cts +1 -0
- package/dist/cli/bin.d.ts +1 -0
- package/dist/cli/bin.js +3183 -0
- package/dist/cli/bin.js.map +1 -0
- package/dist/cli/index.cjs +3209 -0
- package/dist/cli/index.cjs.map +1 -0
- package/dist/cli/index.d.cts +5 -0
- package/dist/cli/index.d.ts +5 -0
- package/dist/cli/index.js +3179 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/index.cjs +2453 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1678 -0
- package/dist/index.d.ts +1678 -0
- package/dist/index.js +2418 -0
- package/dist/index.js.map +1 -0
- package/migrations/v0.0.1.sql +138 -0
- package/package.json +75 -0
|
@@ -0,0 +1,3209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all3) => {
|
|
9
|
+
for (var name in all3)
|
|
10
|
+
__defProp(target, name, { get: all3[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc2) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc2 = __getOwnPropDesc(from, key)) || desc2.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/cli/index.ts
|
|
31
|
+
var cli_exports = {};
|
|
32
|
+
__export(cli_exports, {
|
|
33
|
+
run: () => run
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(cli_exports);
|
|
36
|
+
var import_commander30 = require("commander");
|
|
37
|
+
|
|
38
|
+
// src/cli/commands/update.ts
|
|
39
|
+
var import_commander = require("commander");
|
|
40
|
+
|
|
41
|
+
// src/cli/env.ts
|
|
42
|
+
var import_fs2 = require("fs");
|
|
43
|
+
|
|
44
|
+
// src/internals/context.ts
|
|
45
|
+
var import_typescript = __toESM(require("typescript"), 1);
|
|
46
|
+
var import_url = require("url");
|
|
47
|
+
var import_better_sqlite3 = __toESM(require("better-sqlite3"), 1);
|
|
48
|
+
var import_promises2 = require("fs/promises");
|
|
49
|
+
var import_path2 = __toESM(require("path"), 1);
|
|
50
|
+
var import_better_sqlite32 = require("drizzle-orm/better-sqlite3");
|
|
51
|
+
|
|
52
|
+
// src/internals/errors.ts
|
|
53
|
+
var import_errors = __toESM(require("@webneat/errors"), 1);
|
|
54
|
+
var err = (0, import_errors.default)({
|
|
55
|
+
file_outside_project_path: (data) => `File "${data.file_path}" is outside project path "${data.project_path}"`,
|
|
56
|
+
file_not_found: (data) => `File not found: ${data.path}`,
|
|
57
|
+
db_error: (data) => `Database error in ${data.operation}: ${data.reason}`,
|
|
58
|
+
symbol_meta_parse_error: (data) => `Failed to parse symbol metadata for symbol ${data.symbol_id}: ${data.reason}`,
|
|
59
|
+
exported_symbol_not_found: (data) => `Exported symbol "${data.name}" not found in file with id ${data.file_id}`,
|
|
60
|
+
module_resolution_failed: (data) => `Failed to resolve module "${data.module}" from "${data.from}"`,
|
|
61
|
+
exporter_file_not_found: (data) => `Exporter file not found at "${data.path}" for module "${data.module}"`,
|
|
62
|
+
ast_parse_error: (data) => `AST parsing error in ${data.operation}: ${data.reason}`,
|
|
63
|
+
config_not_found: (data) => `No config found in database at ${data.db_path}`,
|
|
64
|
+
config_invalid_node_modules_paths: (data) => `Invalid node_modules_paths stored in database ${data.db_path}: ${data.reason}`,
|
|
65
|
+
symbol_missing_text: (data) => `Symbol ${data.symbol_id} (${data.name}) has no source text`,
|
|
66
|
+
symbol_node_not_found: (data) => `Symbol node not found for ${data.name} in ${data.file_path}`,
|
|
67
|
+
symbol_not_found: (data) => `Symbol "${data.name}" not found in file "${data.path}"`,
|
|
68
|
+
describe_dependency_failed: (data) => `Failed to describe ${data.package}#${data.name}: ${data.reason}`,
|
|
69
|
+
// CLI errors
|
|
70
|
+
could_not_read_file: (data) => `Could not read file ${data.path}: ${data.reason}`,
|
|
71
|
+
invalid_json: (data) => `Invalid JSON: ${data.reason}`,
|
|
72
|
+
invalid_config: (data) => `Invalid configuration: ${JSON.stringify(data.errors)}`,
|
|
73
|
+
invalid_type: (data) => `Invalid entity type: ${data.type}. Must be one of: dependency, symbol, file, directory`
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// src/db/migrate.ts
|
|
77
|
+
var import_promises = require("fs/promises");
|
|
78
|
+
var import_path = require("path");
|
|
79
|
+
var import_drizzle_orm2 = require("drizzle-orm");
|
|
80
|
+
|
|
81
|
+
// src/db/schema.ts
|
|
82
|
+
var schema_exports = {};
|
|
83
|
+
__export(schema_exports, {
|
|
84
|
+
configs: () => configs,
|
|
85
|
+
directories: () => directories,
|
|
86
|
+
directories_relations: () => directories_relations,
|
|
87
|
+
external_dependencies: () => external_dependencies,
|
|
88
|
+
external_dependencies_relations: () => external_dependencies_relations,
|
|
89
|
+
external_imports: () => external_imports,
|
|
90
|
+
external_imports_relations: () => external_imports_relations,
|
|
91
|
+
files: () => files,
|
|
92
|
+
files_relations: () => files_relations,
|
|
93
|
+
imports: () => imports,
|
|
94
|
+
imports_relations: () => imports_relations,
|
|
95
|
+
migrations: () => migrations,
|
|
96
|
+
symbol_external_links: () => symbol_external_links,
|
|
97
|
+
symbol_external_links_relations: () => symbol_external_links_relations,
|
|
98
|
+
symbol_internal_links: () => symbol_internal_links,
|
|
99
|
+
symbol_internal_links_relations: () => symbol_internal_links_relations,
|
|
100
|
+
symbols: () => symbols,
|
|
101
|
+
symbols_relations: () => symbols_relations
|
|
102
|
+
});
|
|
103
|
+
var import_drizzle_orm = require("drizzle-orm");
|
|
104
|
+
var import_sqlite_core = require("drizzle-orm/sqlite-core");
|
|
105
|
+
var timestamps = {
|
|
106
|
+
created_at: (0, import_sqlite_core.integer)("created_at", { mode: "timestamp" }).default(import_drizzle_orm.sql`(unixepoch())`).notNull(),
|
|
107
|
+
updated_at: (0, import_sqlite_core.integer)("updated_at", { mode: "timestamp" }).default(import_drizzle_orm.sql`(unixepoch())`).notNull()
|
|
108
|
+
};
|
|
109
|
+
var migrations = (0, import_sqlite_core.sqliteTable)("migrations", {
|
|
110
|
+
id: (0, import_sqlite_core.integer)("id").primaryKey({ autoIncrement: true }),
|
|
111
|
+
name: (0, import_sqlite_core.text)("name").notNull().unique(),
|
|
112
|
+
created_at: timestamps.created_at
|
|
113
|
+
});
|
|
114
|
+
var configs = (0, import_sqlite_core.sqliteTable)("configs", {
|
|
115
|
+
id: (0, import_sqlite_core.integer)("id").primaryKey({ autoIncrement: false }).notNull().default(1),
|
|
116
|
+
project_path: (0, import_sqlite_core.text)("project_path").notNull(),
|
|
117
|
+
description: (0, import_sqlite_core.text)("description"),
|
|
118
|
+
package_json_path: (0, import_sqlite_core.text)("package_json_path"),
|
|
119
|
+
node_modules_paths: (0, import_sqlite_core.text)("node_modules_paths"),
|
|
120
|
+
...timestamps
|
|
121
|
+
});
|
|
122
|
+
var directories = (0, import_sqlite_core.sqliteTable)(
|
|
123
|
+
"directories",
|
|
124
|
+
{
|
|
125
|
+
id: (0, import_sqlite_core.integer)("id").primaryKey({ autoIncrement: true }),
|
|
126
|
+
parent_id: (0, import_sqlite_core.integer)("parent_id").references(() => directories.id, { onDelete: "cascade" }),
|
|
127
|
+
path: (0, import_sqlite_core.text)("path").notNull().unique(),
|
|
128
|
+
description: (0, import_sqlite_core.text)("description"),
|
|
129
|
+
state: (0, import_sqlite_core.text)("state").$type().notNull().default("to_describe"),
|
|
130
|
+
error: (0, import_sqlite_core.text)("error"),
|
|
131
|
+
...timestamps
|
|
132
|
+
},
|
|
133
|
+
(table) => ({
|
|
134
|
+
parent_idx: (0, import_sqlite_core.index)("directories_parent_idx").on(table.parent_id),
|
|
135
|
+
path_idx: (0, import_sqlite_core.index)("directories_path_idx").on(table.path),
|
|
136
|
+
state_idx: (0, import_sqlite_core.index)("directories_state_idx").on(table.state)
|
|
137
|
+
})
|
|
138
|
+
);
|
|
139
|
+
var files = (0, import_sqlite_core.sqliteTable)(
|
|
140
|
+
"files",
|
|
141
|
+
{
|
|
142
|
+
id: (0, import_sqlite_core.integer)("id").primaryKey({ autoIncrement: true }),
|
|
143
|
+
directory_id: (0, import_sqlite_core.integer)("directory_id").notNull().references(() => directories.id, { onDelete: "cascade" }),
|
|
144
|
+
path: (0, import_sqlite_core.text)("path").notNull().unique(),
|
|
145
|
+
hash: (0, import_sqlite_core.text)("hash"),
|
|
146
|
+
description: (0, import_sqlite_core.text)("description"),
|
|
147
|
+
state: (0, import_sqlite_core.text)("state").$type().notNull().default("to_scan"),
|
|
148
|
+
error: (0, import_sqlite_core.text)("error"),
|
|
149
|
+
...timestamps
|
|
150
|
+
},
|
|
151
|
+
(table) => ({
|
|
152
|
+
directory_idx: (0, import_sqlite_core.index)("files_directory_idx").on(table.directory_id),
|
|
153
|
+
path_idx: (0, import_sqlite_core.index)("files_path_idx").on(table.path),
|
|
154
|
+
hash_idx: (0, import_sqlite_core.index)("files_hash_idx").on(table.hash),
|
|
155
|
+
state_idx: (0, import_sqlite_core.index)("files_state_idx").on(table.state)
|
|
156
|
+
})
|
|
157
|
+
);
|
|
158
|
+
var external_dependencies = (0, import_sqlite_core.sqliteTable)(
|
|
159
|
+
"external_dependencies",
|
|
160
|
+
{
|
|
161
|
+
id: (0, import_sqlite_core.integer)("id").primaryKey({ autoIncrement: true }),
|
|
162
|
+
package: (0, import_sqlite_core.text)("package").notNull(),
|
|
163
|
+
subpath: (0, import_sqlite_core.text)("subpath"),
|
|
164
|
+
name: (0, import_sqlite_core.text)("name"),
|
|
165
|
+
version: (0, import_sqlite_core.text)("version"),
|
|
166
|
+
github_repo: (0, import_sqlite_core.text)("github_repo"),
|
|
167
|
+
is_builtin: (0, import_sqlite_core.integer)("is_builtin", { mode: "boolean" }).default(false).notNull(),
|
|
168
|
+
description: (0, import_sqlite_core.text)("description"),
|
|
169
|
+
state: (0, import_sqlite_core.text)("state").$type().notNull().default("to_describe"),
|
|
170
|
+
error: (0, import_sqlite_core.text)("error"),
|
|
171
|
+
...timestamps
|
|
172
|
+
},
|
|
173
|
+
(table) => ({
|
|
174
|
+
state_idx: (0, import_sqlite_core.index)("external_dependencies_state_idx").on(table.state),
|
|
175
|
+
package_subpath_name_unique: (0, import_sqlite_core.uniqueIndex)("external_dependencies_package_subpath_name_unique").on(table.package, table.subpath, table.name)
|
|
176
|
+
})
|
|
177
|
+
);
|
|
178
|
+
var external_imports = (0, import_sqlite_core.sqliteTable)(
|
|
179
|
+
"external_imports",
|
|
180
|
+
{
|
|
181
|
+
id: (0, import_sqlite_core.integer)("id").primaryKey({ autoIncrement: true }),
|
|
182
|
+
file_id: (0, import_sqlite_core.integer)("file_id").notNull().references(() => files.id, { onDelete: "cascade" }),
|
|
183
|
+
external_dependency_id: (0, import_sqlite_core.integer)("external_dependency_id").notNull().references(() => external_dependencies.id, { onDelete: "cascade" }),
|
|
184
|
+
alias: (0, import_sqlite_core.text)("alias").notNull(),
|
|
185
|
+
is_dynamic: (0, import_sqlite_core.integer)("is_dynamic", { mode: "boolean" }).default(false).notNull(),
|
|
186
|
+
...timestamps
|
|
187
|
+
},
|
|
188
|
+
(table) => ({
|
|
189
|
+
file_idx: (0, import_sqlite_core.index)("external_imports_file_idx").on(table.file_id),
|
|
190
|
+
external_dependency_idx: (0, import_sqlite_core.index)("external_imports_external_dependency_idx").on(table.external_dependency_id)
|
|
191
|
+
})
|
|
192
|
+
);
|
|
193
|
+
var imports = (0, import_sqlite_core.sqliteTable)(
|
|
194
|
+
"imports",
|
|
195
|
+
{
|
|
196
|
+
id: (0, import_sqlite_core.integer)("id").primaryKey({ autoIncrement: true }),
|
|
197
|
+
exporter_file_id: (0, import_sqlite_core.integer)("exporter_file_id").notNull().references(() => files.id, { onDelete: "cascade" }),
|
|
198
|
+
importer_file_id: (0, import_sqlite_core.integer)("importer_file_id").notNull().references(() => files.id, { onDelete: "cascade" }),
|
|
199
|
+
symbol_id: (0, import_sqlite_core.integer)("symbol_id").references(() => symbols.id, { onDelete: "set null" }),
|
|
200
|
+
name: (0, import_sqlite_core.text)("name").notNull(),
|
|
201
|
+
alias: (0, import_sqlite_core.text)("alias").notNull(),
|
|
202
|
+
is_dynamic: (0, import_sqlite_core.integer)("is_dynamic", { mode: "boolean" }).default(false).notNull(),
|
|
203
|
+
state: (0, import_sqlite_core.text)("state").$type().notNull().default("to_link"),
|
|
204
|
+
error: (0, import_sqlite_core.text)("error"),
|
|
205
|
+
...timestamps
|
|
206
|
+
},
|
|
207
|
+
(table) => ({
|
|
208
|
+
exporter_file_idx: (0, import_sqlite_core.index)("imports_exporter_file_idx").on(table.exporter_file_id),
|
|
209
|
+
importer_file_idx: (0, import_sqlite_core.index)("imports_importer_file_idx").on(table.importer_file_id),
|
|
210
|
+
symbol_idx: (0, import_sqlite_core.index)("imports_symbol_idx").on(table.symbol_id),
|
|
211
|
+
state_idx: (0, import_sqlite_core.index)("imports_state_idx").on(table.state)
|
|
212
|
+
})
|
|
213
|
+
);
|
|
214
|
+
var symbols = (0, import_sqlite_core.sqliteTable)(
|
|
215
|
+
"symbols",
|
|
216
|
+
{
|
|
217
|
+
id: (0, import_sqlite_core.integer)("id").primaryKey({ autoIncrement: true }),
|
|
218
|
+
file_id: (0, import_sqlite_core.integer)("file_id").notNull().references(() => files.id, { onDelete: "cascade" }),
|
|
219
|
+
type: (0, import_sqlite_core.text)("type").notNull(),
|
|
220
|
+
// 'function', 'class', 'variable', 'type', 'class_method', 'class_property', 'other'
|
|
221
|
+
name: (0, import_sqlite_core.text)("name").notNull(),
|
|
222
|
+
text: (0, import_sqlite_core.text)("text"),
|
|
223
|
+
// source code
|
|
224
|
+
meta: (0, import_sqlite_core.text)("meta"),
|
|
225
|
+
// JSON details
|
|
226
|
+
description: (0, import_sqlite_core.text)("description"),
|
|
227
|
+
is_exported: (0, import_sqlite_core.integer)("is_exported", { mode: "boolean" }).default(false).notNull(),
|
|
228
|
+
state: (0, import_sqlite_core.text)("state").$type().notNull().default("to_link"),
|
|
229
|
+
error: (0, import_sqlite_core.text)("error"),
|
|
230
|
+
...timestamps
|
|
231
|
+
},
|
|
232
|
+
(table) => ({
|
|
233
|
+
file_idx: (0, import_sqlite_core.index)("symbols_file_idx").on(table.file_id),
|
|
234
|
+
type_idx: (0, import_sqlite_core.index)("symbols_type_idx").on(table.type),
|
|
235
|
+
name_idx: (0, import_sqlite_core.index)("symbols_name_idx").on(table.name),
|
|
236
|
+
is_exported_idx: (0, import_sqlite_core.index)("symbols_is_exported_idx").on(table.is_exported),
|
|
237
|
+
state_idx: (0, import_sqlite_core.index)("symbols_state_idx").on(table.state)
|
|
238
|
+
})
|
|
239
|
+
);
|
|
240
|
+
var symbol_internal_links = (0, import_sqlite_core.sqliteTable)(
|
|
241
|
+
"symbol_internal_links",
|
|
242
|
+
{
|
|
243
|
+
id: (0, import_sqlite_core.integer)("id").primaryKey({ autoIncrement: true }),
|
|
244
|
+
from_file_id: (0, import_sqlite_core.integer)("from_file_id").notNull().references(() => files.id, { onDelete: "cascade" }),
|
|
245
|
+
to_file_id: (0, import_sqlite_core.integer)("to_file_id").notNull().references(() => files.id, { onDelete: "cascade" }),
|
|
246
|
+
from_symbol_id: (0, import_sqlite_core.integer)("from_symbol_id").notNull().references(() => symbols.id, { onDelete: "cascade" }),
|
|
247
|
+
to_symbol_id: (0, import_sqlite_core.integer)("to_symbol_id").notNull().references(() => symbols.id, { onDelete: "cascade" }),
|
|
248
|
+
state: (0, import_sqlite_core.text)("state").$type().notNull().default("pending"),
|
|
249
|
+
error: (0, import_sqlite_core.text)("error"),
|
|
250
|
+
...timestamps
|
|
251
|
+
},
|
|
252
|
+
(table) => ({
|
|
253
|
+
from_file_idx: (0, import_sqlite_core.index)("symbol_internal_links_from_file_idx").on(table.from_file_id),
|
|
254
|
+
to_file_idx: (0, import_sqlite_core.index)("symbol_internal_links_to_file_idx").on(table.to_file_id),
|
|
255
|
+
from_symbol_idx: (0, import_sqlite_core.index)("symbol_internal_links_from_symbol_idx").on(table.from_symbol_id),
|
|
256
|
+
to_symbol_idx: (0, import_sqlite_core.index)("symbol_internal_links_to_symbol_idx").on(table.to_symbol_id),
|
|
257
|
+
state_idx: (0, import_sqlite_core.index)("symbol_internal_links_state_idx").on(table.state)
|
|
258
|
+
})
|
|
259
|
+
);
|
|
260
|
+
var symbol_external_links = (0, import_sqlite_core.sqliteTable)(
|
|
261
|
+
"symbol_external_links",
|
|
262
|
+
{
|
|
263
|
+
id: (0, import_sqlite_core.integer)("id").primaryKey({ autoIncrement: true }),
|
|
264
|
+
symbol_id: (0, import_sqlite_core.integer)("symbol_id").notNull().references(() => symbols.id, { onDelete: "cascade" }),
|
|
265
|
+
external_import_id: (0, import_sqlite_core.integer)("external_import_id").notNull().references(() => external_imports.id, { onDelete: "cascade" }),
|
|
266
|
+
...timestamps
|
|
267
|
+
},
|
|
268
|
+
(table) => ({
|
|
269
|
+
symbol_idx: (0, import_sqlite_core.index)("symbol_external_links_symbol_idx").on(table.symbol_id),
|
|
270
|
+
external_import_idx: (0, import_sqlite_core.index)("symbol_external_links_external_import_idx").on(table.external_import_id)
|
|
271
|
+
})
|
|
272
|
+
);
|
|
273
|
+
var directories_relations = (0, import_drizzle_orm.relations)(directories, ({ one, many }) => ({
|
|
274
|
+
parent: one(directories, {
|
|
275
|
+
fields: [directories.parent_id],
|
|
276
|
+
references: [directories.id],
|
|
277
|
+
relationName: "subdirectories"
|
|
278
|
+
}),
|
|
279
|
+
subdirectories: many(directories, {
|
|
280
|
+
relationName: "subdirectories"
|
|
281
|
+
}),
|
|
282
|
+
files: many(files)
|
|
283
|
+
}));
|
|
284
|
+
var files_relations = (0, import_drizzle_orm.relations)(files, ({ one, many }) => ({
|
|
285
|
+
directory: one(directories, {
|
|
286
|
+
fields: [files.directory_id],
|
|
287
|
+
references: [directories.id]
|
|
288
|
+
}),
|
|
289
|
+
external_imports: many(external_imports),
|
|
290
|
+
imports_as_exporter: many(imports, {
|
|
291
|
+
relationName: "imports_as_exporter"
|
|
292
|
+
}),
|
|
293
|
+
imports_as_importer: many(imports, {
|
|
294
|
+
relationName: "imports_as_importer"
|
|
295
|
+
}),
|
|
296
|
+
symbols: many(symbols),
|
|
297
|
+
internal_links_from: many(symbol_internal_links, {
|
|
298
|
+
relationName: "file_internal_links_from"
|
|
299
|
+
}),
|
|
300
|
+
internal_links_to: many(symbol_internal_links, {
|
|
301
|
+
relationName: "file_internal_links_to"
|
|
302
|
+
})
|
|
303
|
+
}));
|
|
304
|
+
var external_dependencies_relations = (0, import_drizzle_orm.relations)(external_dependencies, ({ many }) => ({
|
|
305
|
+
imports: many(external_imports),
|
|
306
|
+
symbol_external_links: many(symbol_external_links)
|
|
307
|
+
}));
|
|
308
|
+
var external_imports_relations = (0, import_drizzle_orm.relations)(external_imports, ({ one }) => ({
|
|
309
|
+
file: one(files, {
|
|
310
|
+
fields: [external_imports.file_id],
|
|
311
|
+
references: [files.id]
|
|
312
|
+
}),
|
|
313
|
+
external_dependency: one(external_dependencies, {
|
|
314
|
+
fields: [external_imports.external_dependency_id],
|
|
315
|
+
references: [external_dependencies.id]
|
|
316
|
+
})
|
|
317
|
+
}));
|
|
318
|
+
var imports_relations = (0, import_drizzle_orm.relations)(imports, ({ one }) => ({
|
|
319
|
+
exporter_file: one(files, {
|
|
320
|
+
fields: [imports.exporter_file_id],
|
|
321
|
+
references: [files.id],
|
|
322
|
+
relationName: "imports_as_exporter"
|
|
323
|
+
}),
|
|
324
|
+
importer_file: one(files, {
|
|
325
|
+
fields: [imports.importer_file_id],
|
|
326
|
+
references: [files.id],
|
|
327
|
+
relationName: "imports_as_importer"
|
|
328
|
+
}),
|
|
329
|
+
symbol: one(symbols, {
|
|
330
|
+
fields: [imports.symbol_id],
|
|
331
|
+
references: [symbols.id]
|
|
332
|
+
})
|
|
333
|
+
}));
|
|
334
|
+
var symbols_relations = (0, import_drizzle_orm.relations)(symbols, ({ one, many }) => ({
|
|
335
|
+
file: one(files, {
|
|
336
|
+
fields: [symbols.file_id],
|
|
337
|
+
references: [files.id]
|
|
338
|
+
}),
|
|
339
|
+
imports: many(imports),
|
|
340
|
+
internal_links_from: many(symbol_internal_links, {
|
|
341
|
+
relationName: "internal_links_from"
|
|
342
|
+
}),
|
|
343
|
+
internal_links_to: many(symbol_internal_links, {
|
|
344
|
+
relationName: "internal_links_to"
|
|
345
|
+
}),
|
|
346
|
+
external_links: many(symbol_external_links)
|
|
347
|
+
}));
|
|
348
|
+
var symbol_internal_links_relations = (0, import_drizzle_orm.relations)(symbol_internal_links, ({ one }) => ({
|
|
349
|
+
from_file: one(files, {
|
|
350
|
+
fields: [symbol_internal_links.from_file_id],
|
|
351
|
+
references: [files.id],
|
|
352
|
+
relationName: "file_internal_links_from"
|
|
353
|
+
}),
|
|
354
|
+
to_file: one(files, {
|
|
355
|
+
fields: [symbol_internal_links.to_file_id],
|
|
356
|
+
references: [files.id],
|
|
357
|
+
relationName: "file_internal_links_to"
|
|
358
|
+
}),
|
|
359
|
+
from_symbol: one(symbols, {
|
|
360
|
+
fields: [symbol_internal_links.from_symbol_id],
|
|
361
|
+
references: [symbols.id],
|
|
362
|
+
relationName: "internal_links_from"
|
|
363
|
+
}),
|
|
364
|
+
to_symbol: one(symbols, {
|
|
365
|
+
fields: [symbol_internal_links.to_symbol_id],
|
|
366
|
+
references: [symbols.id],
|
|
367
|
+
relationName: "internal_links_to"
|
|
368
|
+
})
|
|
369
|
+
}));
|
|
370
|
+
var symbol_external_links_relations = (0, import_drizzle_orm.relations)(symbol_external_links, ({ one }) => ({
|
|
371
|
+
symbol: one(symbols, {
|
|
372
|
+
fields: [symbol_external_links.symbol_id],
|
|
373
|
+
references: [symbols.id]
|
|
374
|
+
}),
|
|
375
|
+
external_import: one(external_imports, {
|
|
376
|
+
fields: [symbol_external_links.external_import_id],
|
|
377
|
+
references: [external_imports.id]
|
|
378
|
+
})
|
|
379
|
+
}));
|
|
380
|
+
|
|
381
|
+
// src/db/migrate.ts
|
|
382
|
+
async function migrate(ctx) {
|
|
383
|
+
const [migration_filenames, applied_migration_names] = await Promise.all([get_migration_filenames(ctx), get_applied_migration_names(ctx)]);
|
|
384
|
+
for (const filename of migration_filenames) {
|
|
385
|
+
if (applied_migration_names.has(filename)) continue;
|
|
386
|
+
await apply_migration(ctx, filename);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
async function get_migration_filenames({ migrations_path }) {
|
|
390
|
+
const filenames = /* @__PURE__ */ new Set();
|
|
391
|
+
for (const entry of await (0, import_promises.readdir)(migrations_path, { withFileTypes: true })) {
|
|
392
|
+
if (!entry.isFile() || !entry.name.endsWith(".sql")) continue;
|
|
393
|
+
filenames.add(entry.name);
|
|
394
|
+
}
|
|
395
|
+
return filenames;
|
|
396
|
+
}
|
|
397
|
+
async function get_applied_migration_names({ db: db6 }) {
|
|
398
|
+
const res = db6.get(import_drizzle_orm2.sql`SELECT name FROM sqlite_master WHERE type='table' AND name='migrations'`);
|
|
399
|
+
if (!res) return /* @__PURE__ */ new Set();
|
|
400
|
+
const applied = await db6.select({ name: migrations.name }).from(migrations);
|
|
401
|
+
return new Set(applied.map((x) => x.name));
|
|
402
|
+
}
|
|
403
|
+
async function apply_migration({ sqlite, migrations_path }, filename) {
|
|
404
|
+
const file_path = (0, import_path.join)(migrations_path, filename);
|
|
405
|
+
const queries = await (0, import_promises.readFile)(file_path, "utf-8");
|
|
406
|
+
sqlite.transaction(() => {
|
|
407
|
+
sqlite.exec(queries);
|
|
408
|
+
sqlite.prepare("INSERT INTO migrations (name) VALUES (?)").run(filename);
|
|
409
|
+
})();
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// src/db/configs.ts
|
|
413
|
+
var configs_exports = {};
|
|
414
|
+
__export(configs_exports, {
|
|
415
|
+
get: () => get,
|
|
416
|
+
upsert: () => upsert
|
|
417
|
+
});
|
|
418
|
+
var import_drizzle_orm4 = require("drizzle-orm");
|
|
419
|
+
|
|
420
|
+
// src/db/common.ts
|
|
421
|
+
var import_drizzle_orm3 = require("drizzle-orm");
|
|
422
|
+
function safe_query(operation, fn) {
|
|
423
|
+
return err.safe(fn, (reason, ...args) => err.new("db_error", { operation, args: args.slice(1), reason }));
|
|
424
|
+
}
|
|
425
|
+
function do_search(db6, table, options) {
|
|
426
|
+
if (!options.select.includes("id")) options.select.push("id");
|
|
427
|
+
return db6.select(fields(table, options.select)).from(table).where(conditions(table, options.where)).orderBy(order(table, options.order_by)).offset(options.offset).limit(options.limit).all();
|
|
428
|
+
}
|
|
429
|
+
function fields(table, fields2) {
|
|
430
|
+
const res = {};
|
|
431
|
+
for (const field of fields2) res[field] = table[field];
|
|
432
|
+
return res;
|
|
433
|
+
}
|
|
434
|
+
function conditions(table, filters) {
|
|
435
|
+
if (!filters || Object.keys(filters).length === 0) return void 0;
|
|
436
|
+
const parts = [];
|
|
437
|
+
for (const [field, value] of Object.entries(filters)) {
|
|
438
|
+
if (Array.isArray(value) && value.length > 0) {
|
|
439
|
+
const field_conditions = value.map((v) => condition(table, field, v));
|
|
440
|
+
parts.push((0, import_drizzle_orm3.or)(...field_conditions));
|
|
441
|
+
} else {
|
|
442
|
+
parts.push(condition(table, field, value));
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
return (0, import_drizzle_orm3.and)(...parts);
|
|
446
|
+
}
|
|
447
|
+
function condition(table, field, value) {
|
|
448
|
+
if (typeof value === "object" && value !== null) {
|
|
449
|
+
if ("contains" in value) return (0, import_drizzle_orm3.like)(table[field], `%${value.contains}%`);
|
|
450
|
+
if ("starts_with" in value) return (0, import_drizzle_orm3.like)(table[field], `${value.starts_with}%`);
|
|
451
|
+
if ("ends_with" in value) return (0, import_drizzle_orm3.like)(table[field], `%${value.ends_with}`);
|
|
452
|
+
return (0, import_drizzle_orm3.eq)(table[field], JSON.stringify(value));
|
|
453
|
+
}
|
|
454
|
+
return (0, import_drizzle_orm3.eq)(table[field], value);
|
|
455
|
+
}
|
|
456
|
+
function order(table, [field, direction]) {
|
|
457
|
+
return direction === "asc" ? (0, import_drizzle_orm3.asc)(table[field]) : (0, import_drizzle_orm3.desc)(table[field]);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
// src/db/configs.ts
|
|
461
|
+
var get = safe_query(
|
|
462
|
+
"configs.get",
|
|
463
|
+
(ctx) => ctx.db.select().from(configs).where((0, import_drizzle_orm4.eq)(configs.id, 1)).get()
|
|
464
|
+
);
|
|
465
|
+
var upsert = safe_query(
|
|
466
|
+
"configs.upsert",
|
|
467
|
+
(ctx, data) => ctx.db.insert(configs).values({ id: 1, ...data }).onConflictDoUpdate({
|
|
468
|
+
target: configs.id,
|
|
469
|
+
set: { ...data, updated_at: import_drizzle_orm4.sql`(unixepoch())` }
|
|
470
|
+
}).run()
|
|
471
|
+
);
|
|
472
|
+
|
|
473
|
+
// src/db/files.ts
|
|
474
|
+
var files_exports = {};
|
|
475
|
+
__export(files_exports, {
|
|
476
|
+
all: () => all,
|
|
477
|
+
by_directory_path: () => by_directory_path,
|
|
478
|
+
by_id: () => by_id,
|
|
479
|
+
by_id_and_state: () => by_id_and_state,
|
|
480
|
+
by_path: () => by_path,
|
|
481
|
+
by_state: () => by_state,
|
|
482
|
+
del: () => del,
|
|
483
|
+
del_by_dir: () => del_by_dir,
|
|
484
|
+
get_directory_ids: () => get_directory_ids,
|
|
485
|
+
imported_by: () => imported_by,
|
|
486
|
+
importing: () => importing,
|
|
487
|
+
insert: () => insert,
|
|
488
|
+
search: () => search,
|
|
489
|
+
update: () => update,
|
|
490
|
+
update_many: () => update_many,
|
|
491
|
+
using_dependency: () => using_dependency
|
|
492
|
+
});
|
|
493
|
+
var import_drizzle_orm5 = require("drizzle-orm");
|
|
494
|
+
|
|
495
|
+
// src/internals/utils.ts
|
|
496
|
+
var import_fs = require("fs");
|
|
497
|
+
var parse_json = err.safe(JSON.parse, (reason, text2) => err.new("invalid_json", { reason, text: text2 }));
|
|
498
|
+
var read_file = err.safe(
|
|
499
|
+
(path6) => (0, import_fs.readFileSync)(path6, "utf-8"),
|
|
500
|
+
(reason, path6) => err.new("could_not_read_file", { path: path6, reason })
|
|
501
|
+
);
|
|
502
|
+
function group_by_unique(items, key) {
|
|
503
|
+
const groups = {};
|
|
504
|
+
for (const item of items) {
|
|
505
|
+
groups[key(item)] = item;
|
|
506
|
+
}
|
|
507
|
+
return groups;
|
|
508
|
+
}
|
|
509
|
+
function expand({ items, get_children, get_key }) {
|
|
510
|
+
const visited = /* @__PURE__ */ new Set();
|
|
511
|
+
const result = [];
|
|
512
|
+
const queue = [...items];
|
|
513
|
+
while (queue.length > 0) {
|
|
514
|
+
const item = queue.shift();
|
|
515
|
+
const key = get_key(item);
|
|
516
|
+
if (err.any(key)) return key;
|
|
517
|
+
if (visited.has(key)) continue;
|
|
518
|
+
visited.add(key);
|
|
519
|
+
result.push(item);
|
|
520
|
+
const children3 = get_children(item);
|
|
521
|
+
if (err.any(children3)) return children3;
|
|
522
|
+
queue.push(...children3);
|
|
523
|
+
}
|
|
524
|
+
return result;
|
|
525
|
+
}
|
|
526
|
+
function uniq(items) {
|
|
527
|
+
return [...new Set(items)];
|
|
528
|
+
}
|
|
529
|
+
function merge(a, b) {
|
|
530
|
+
const res = { ...a };
|
|
531
|
+
for (const key of Object.keys(b)) {
|
|
532
|
+
if (b[key] !== void 0) res[key] = b[key];
|
|
533
|
+
}
|
|
534
|
+
return res;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
// src/db/defaults.ts
|
|
538
|
+
var files2 = {
|
|
539
|
+
select: ["id", "directory_id", "path", "state", "error"],
|
|
540
|
+
order_by: ["id", "asc"],
|
|
541
|
+
limit: 20,
|
|
542
|
+
offset: 0,
|
|
543
|
+
where: {}
|
|
544
|
+
};
|
|
545
|
+
var directories2 = {
|
|
546
|
+
select: ["id", "parent_id", "path", "state", "error"],
|
|
547
|
+
order_by: ["id", "asc"],
|
|
548
|
+
limit: 20,
|
|
549
|
+
offset: 0,
|
|
550
|
+
where: {}
|
|
551
|
+
};
|
|
552
|
+
var symbols2 = {
|
|
553
|
+
select: ["id", "file_id", "type", "name", "meta", "is_exported", "state", "error"],
|
|
554
|
+
order_by: ["id", "asc"],
|
|
555
|
+
limit: 20,
|
|
556
|
+
offset: 0,
|
|
557
|
+
where: {}
|
|
558
|
+
};
|
|
559
|
+
var external_dependencies2 = {
|
|
560
|
+
select: ["id", "package", "subpath", "name", "state", "error"],
|
|
561
|
+
order_by: ["id", "asc"],
|
|
562
|
+
limit: 20,
|
|
563
|
+
offset: 0,
|
|
564
|
+
where: {}
|
|
565
|
+
};
|
|
566
|
+
|
|
567
|
+
// src/db/files.ts
|
|
568
|
+
var default_select_fields = ["id", "directory_id", "path", "state", "error"];
|
|
569
|
+
var all = safe_query("files.all", (ctx) => ctx.db.select().from(files).all());
|
|
570
|
+
var search = safe_query("files.search", (ctx, options = {}) => {
|
|
571
|
+
return do_search(ctx.db, files, merge(files2, options));
|
|
572
|
+
});
|
|
573
|
+
var by_id = safe_query("files.by_id", (ctx, id) => ctx.db.select().from(files).where((0, import_drizzle_orm5.eq)(files.id, id)).get());
|
|
574
|
+
var by_path = safe_query(
|
|
575
|
+
"files.by_path",
|
|
576
|
+
(ctx, path6) => ctx.db.select().from(files).where((0, import_drizzle_orm5.eq)(files.path, path6)).get()
|
|
577
|
+
);
|
|
578
|
+
var by_state = safe_query(
|
|
579
|
+
"files.by_state",
|
|
580
|
+
(ctx, state) => ctx.db.select().from(files).where((0, import_drizzle_orm5.eq)(files.state, state)).all()
|
|
581
|
+
);
|
|
582
|
+
var insert = safe_query("files.insert", (ctx, values) => ctx.db.insert(files).values(values).run());
|
|
583
|
+
var update = safe_query(
|
|
584
|
+
"files.update",
|
|
585
|
+
(ctx, file_id, values) => ctx.db.update(files).set(values).where((0, import_drizzle_orm5.eq)(files.id, file_id)).run()
|
|
586
|
+
);
|
|
587
|
+
var update_many = safe_query(
|
|
588
|
+
"files.update_many",
|
|
589
|
+
(ctx, file_ids, values) => ctx.db.update(files).set(values).where((0, import_drizzle_orm5.inArray)(files.id, file_ids)).run()
|
|
590
|
+
);
|
|
591
|
+
var by_id_and_state = safe_query(
|
|
592
|
+
"files.by_id_and_state",
|
|
593
|
+
(ctx, params) => ctx.db.select().from(files).where((0, import_drizzle_orm5.and)((0, import_drizzle_orm5.eq)(files.id, params.id), (0, import_drizzle_orm5.eq)(files.state, params.state))).get()
|
|
594
|
+
);
|
|
595
|
+
var del = safe_query("files.delete", (ctx, file_id) => ctx.db.delete(files).where((0, import_drizzle_orm5.eq)(files.id, file_id)).run());
|
|
596
|
+
var del_by_dir = safe_query(
|
|
597
|
+
"files.delete_by_dir",
|
|
598
|
+
(ctx, directory_id) => ctx.db.delete(files).where((0, import_drizzle_orm5.eq)(files.directory_id, directory_id)).run()
|
|
599
|
+
);
|
|
600
|
+
var get_directory_ids = safe_query(
|
|
601
|
+
"files.get_directory_ids",
|
|
602
|
+
(ctx, file_ids) => ctx.db.select({ directory_id: files.directory_id }).from(files).where((0, import_drizzle_orm5.inArray)(files.id, file_ids)).all().map((x) => x.directory_id)
|
|
603
|
+
);
|
|
604
|
+
var by_directory_path = safe_query("files.by_directory_path", (ctx, dir_path, recursive = false) => {
|
|
605
|
+
let dir_ids;
|
|
606
|
+
if (recursive) {
|
|
607
|
+
if (dir_path === "/") {
|
|
608
|
+
dir_ids = ctx.db.select({ id: directories.id }).from(directories).all().map((d) => d.id);
|
|
609
|
+
} else {
|
|
610
|
+
dir_ids = ctx.db.select({ id: directories.id }).from(directories).where((0, import_drizzle_orm5.or)((0, import_drizzle_orm5.eq)(directories.path, dir_path), (0, import_drizzle_orm5.like)(directories.path, `${dir_path}/%`))).all().map((d) => d.id);
|
|
611
|
+
}
|
|
612
|
+
} else {
|
|
613
|
+
const dir = ctx.db.select({ id: directories.id }).from(directories).where((0, import_drizzle_orm5.eq)(directories.path, dir_path)).get();
|
|
614
|
+
dir_ids = dir ? [dir.id] : [];
|
|
615
|
+
}
|
|
616
|
+
if (dir_ids.length === 0) return [];
|
|
617
|
+
return ctx.db.select().from(files).where((0, import_drizzle_orm5.inArray)(files.directory_id, dir_ids)).all();
|
|
618
|
+
});
|
|
619
|
+
var using_dependency = safe_query(
|
|
620
|
+
"files.using_dependency",
|
|
621
|
+
(ctx, external_dependency_id, fields_to_select = default_select_fields) => {
|
|
622
|
+
if (!fields_to_select.includes("id")) fields_to_select.push("id");
|
|
623
|
+
const imports2 = ctx.db.select({ file_id: external_imports.file_id }).from(external_imports).where((0, import_drizzle_orm5.eq)(external_imports.external_dependency_id, external_dependency_id)).all();
|
|
624
|
+
const file_ids = uniq(imports2.map((i) => i.file_id));
|
|
625
|
+
if (file_ids.length === 0) return [];
|
|
626
|
+
return ctx.db.select(fields(files, fields_to_select)).from(files).where((0, import_drizzle_orm5.inArray)(files.id, file_ids)).all();
|
|
627
|
+
}
|
|
628
|
+
);
|
|
629
|
+
var imported_by = safe_query(
|
|
630
|
+
"files.imported_by",
|
|
631
|
+
(ctx, file_id, fields_to_select = default_select_fields) => {
|
|
632
|
+
if (!fields_to_select.includes("id")) fields_to_select.push("id");
|
|
633
|
+
const import_rows = ctx.db.select({ id: imports.exporter_file_id }).from(imports).where((0, import_drizzle_orm5.eq)(imports.importer_file_id, file_id)).all();
|
|
634
|
+
const file_ids = uniq(import_rows.map((i) => i.id));
|
|
635
|
+
if (file_ids.length === 0) return [];
|
|
636
|
+
return ctx.db.select(fields(files, fields_to_select)).from(files).where((0, import_drizzle_orm5.inArray)(files.id, file_ids)).all();
|
|
637
|
+
}
|
|
638
|
+
);
|
|
639
|
+
var importing = safe_query(
|
|
640
|
+
"files.importing",
|
|
641
|
+
(ctx, file_id, fields_to_select = default_select_fields) => {
|
|
642
|
+
if (!fields_to_select.includes("id")) fields_to_select.push("id");
|
|
643
|
+
const import_records = ctx.db.select({ importer_file_id: imports.importer_file_id }).from(imports).where((0, import_drizzle_orm5.eq)(imports.exporter_file_id, file_id)).all();
|
|
644
|
+
const file_ids = uniq(import_records.map((i) => i.importer_file_id));
|
|
645
|
+
if (file_ids.length === 0) return [];
|
|
646
|
+
return ctx.db.select(fields(files, fields_to_select)).from(files).where((0, import_drizzle_orm5.inArray)(files.id, file_ids)).all();
|
|
647
|
+
}
|
|
648
|
+
);
|
|
649
|
+
|
|
650
|
+
// src/db/directories.ts
|
|
651
|
+
var directories_exports = {};
|
|
652
|
+
__export(directories_exports, {
|
|
653
|
+
by_id: () => by_id2,
|
|
654
|
+
by_id_and_state: () => by_id_and_state2,
|
|
655
|
+
by_path: () => by_path2,
|
|
656
|
+
by_state: () => by_state2,
|
|
657
|
+
insert: () => insert2,
|
|
658
|
+
search: () => search2,
|
|
659
|
+
update: () => update2,
|
|
660
|
+
update_many: () => update_many2
|
|
661
|
+
});
|
|
662
|
+
var import_drizzle_orm6 = require("drizzle-orm");
|
|
663
|
+
var by_id2 = safe_query(
|
|
664
|
+
"directories.by_id",
|
|
665
|
+
(ctx, id) => ctx.db.select().from(directories).where((0, import_drizzle_orm6.eq)(directories.id, id)).get()
|
|
666
|
+
);
|
|
667
|
+
var by_path2 = safe_query(
|
|
668
|
+
"directories.by_path",
|
|
669
|
+
(ctx, path6) => ctx.db.select().from(directories).where((0, import_drizzle_orm6.eq)(directories.path, path6)).get()
|
|
670
|
+
);
|
|
671
|
+
var by_state2 = safe_query(
|
|
672
|
+
"directories.by_state",
|
|
673
|
+
(ctx, state) => ctx.db.select().from(directories).where((0, import_drizzle_orm6.eq)(directories.state, state)).all()
|
|
674
|
+
);
|
|
675
|
+
var insert2 = safe_query(
|
|
676
|
+
"directories.insert",
|
|
677
|
+
(ctx, values) => ctx.db.insert(directories).values(values).returning().get()
|
|
678
|
+
);
|
|
679
|
+
var update2 = safe_query(
|
|
680
|
+
"directories.update",
|
|
681
|
+
(ctx, id, values) => ctx.db.update(directories).set(values).where((0, import_drizzle_orm6.eq)(directories.id, id)).run()
|
|
682
|
+
);
|
|
683
|
+
var update_many2 = safe_query(
|
|
684
|
+
"directories.update_many",
|
|
685
|
+
(ctx, ids, values) => ctx.db.update(directories).set(values).where((0, import_drizzle_orm6.inArray)(directories.id, ids)).run()
|
|
686
|
+
);
|
|
687
|
+
var by_id_and_state2 = safe_query(
|
|
688
|
+
"directories.by_id_and_state",
|
|
689
|
+
(ctx, params) => ctx.db.select().from(directories).where((0, import_drizzle_orm6.and)((0, import_drizzle_orm6.eq)(directories.id, params.id), (0, import_drizzle_orm6.eq)(directories.state, params.state))).get()
|
|
690
|
+
);
|
|
691
|
+
var search2 = safe_query("directories.search", (ctx, options = {}) => {
|
|
692
|
+
return do_search(ctx.db, directories, merge(directories2, options));
|
|
693
|
+
});
|
|
694
|
+
|
|
695
|
+
// src/db/imports.ts
|
|
696
|
+
var imports_exports = {};
|
|
697
|
+
__export(imports_exports, {
|
|
698
|
+
by_exporter_file: () => by_exporter_file,
|
|
699
|
+
by_importer_file: () => by_importer_file,
|
|
700
|
+
by_state: () => by_state3,
|
|
701
|
+
del_by_importer_file: () => del_by_importer_file,
|
|
702
|
+
insert_many: () => insert_many,
|
|
703
|
+
update: () => update3
|
|
704
|
+
});
|
|
705
|
+
var import_drizzle_orm7 = require("drizzle-orm");
|
|
706
|
+
var by_exporter_file = safe_query(
|
|
707
|
+
"imports.by_exporter_file",
|
|
708
|
+
(ctx, exporter_file_id) => ctx.db.select().from(imports).where((0, import_drizzle_orm7.eq)(imports.exporter_file_id, exporter_file_id)).all()
|
|
709
|
+
);
|
|
710
|
+
var by_importer_file = safe_query(
|
|
711
|
+
"imports.by_importer_file",
|
|
712
|
+
(ctx, importer_file_id) => ctx.db.select().from(imports).where((0, import_drizzle_orm7.eq)(imports.importer_file_id, importer_file_id)).all()
|
|
713
|
+
);
|
|
714
|
+
var insert_many = safe_query("imports.insert_many", (ctx, values) => ctx.db.insert(imports).values(values).run());
|
|
715
|
+
var del_by_importer_file = safe_query(
|
|
716
|
+
"imports.del_by_importer_file",
|
|
717
|
+
(ctx, file_id) => ctx.db.delete(imports).where((0, import_drizzle_orm7.eq)(imports.importer_file_id, file_id)).run()
|
|
718
|
+
);
|
|
719
|
+
var by_state3 = safe_query(
|
|
720
|
+
"imports.by_state",
|
|
721
|
+
(ctx, state) => ctx.db.select().from(imports).where((0, import_drizzle_orm7.eq)(imports.state, state)).all()
|
|
722
|
+
);
|
|
723
|
+
var update3 = safe_query(
|
|
724
|
+
"imports.update",
|
|
725
|
+
(ctx, id, data) => ctx.db.update(imports).set(data).where((0, import_drizzle_orm7.eq)(imports.id, id)).run()
|
|
726
|
+
);
|
|
727
|
+
|
|
728
|
+
// src/db/symbols.ts
|
|
729
|
+
var symbols_exports = {};
|
|
730
|
+
__export(symbols_exports, {
|
|
731
|
+
by_file: () => by_file,
|
|
732
|
+
by_file_and_name: () => by_file_and_name,
|
|
733
|
+
by_id: () => by_id3,
|
|
734
|
+
by_id_and_state: () => by_id_and_state3,
|
|
735
|
+
by_state: () => by_state4,
|
|
736
|
+
del_by_file: () => del_by_file,
|
|
737
|
+
insert_many: () => insert_many2,
|
|
738
|
+
meta: () => meta,
|
|
739
|
+
referenced_by: () => referenced_by,
|
|
740
|
+
referencing: () => referencing,
|
|
741
|
+
search: () => search3,
|
|
742
|
+
update: () => update4,
|
|
743
|
+
using_dependency: () => using_dependency2
|
|
744
|
+
});
|
|
745
|
+
var import_drizzle_orm8 = require("drizzle-orm");
|
|
746
|
+
var insert_many2 = safe_query("symbols.insert_many", (ctx, values) => ctx.db.insert(symbols).values(values).run());
|
|
747
|
+
var del_by_file = safe_query(
|
|
748
|
+
"symbols.delete_by_file",
|
|
749
|
+
(ctx, file_id) => ctx.db.delete(symbols).where((0, import_drizzle_orm8.eq)(symbols.file_id, file_id)).run()
|
|
750
|
+
);
|
|
751
|
+
var by_file_and_name = safe_query(
|
|
752
|
+
"symbols.by_file_and_name",
|
|
753
|
+
(ctx, params) => ctx.db.select().from(symbols).where((0, import_drizzle_orm8.and)((0, import_drizzle_orm8.eq)(symbols.file_id, params.file_id), (0, import_drizzle_orm8.eq)(symbols.name, params.name), (0, import_drizzle_orm8.eq)(symbols.is_exported, params.is_exported))).get()
|
|
754
|
+
);
|
|
755
|
+
var by_state4 = safe_query(
|
|
756
|
+
"symbols.by_state",
|
|
757
|
+
(ctx, state) => ctx.db.select().from(symbols).where((0, import_drizzle_orm8.eq)(symbols.state, state)).all()
|
|
758
|
+
);
|
|
759
|
+
var by_file = safe_query(
|
|
760
|
+
"symbols.by_file",
|
|
761
|
+
(ctx, file_id) => ctx.db.select().from(symbols).where((0, import_drizzle_orm8.eq)(symbols.file_id, file_id)).all()
|
|
762
|
+
);
|
|
763
|
+
var update4 = safe_query(
|
|
764
|
+
"symbols.update",
|
|
765
|
+
(ctx, id, data) => ctx.db.update(symbols).set(data).where((0, import_drizzle_orm8.eq)(symbols.id, id)).run()
|
|
766
|
+
);
|
|
767
|
+
var by_id3 = safe_query("symbols.by_id", (ctx, id) => ctx.db.select().from(symbols).where((0, import_drizzle_orm8.eq)(symbols.id, id)).get());
|
|
768
|
+
var by_id_and_state3 = safe_query(
|
|
769
|
+
"symbols.by_id_and_state",
|
|
770
|
+
(ctx, params) => ctx.db.select().from(symbols).where((0, import_drizzle_orm8.and)((0, import_drizzle_orm8.eq)(symbols.id, params.id), (0, import_drizzle_orm8.eq)(symbols.state, params.state))).get()
|
|
771
|
+
);
|
|
772
|
+
function meta(symbol) {
|
|
773
|
+
return err.catch(
|
|
774
|
+
() => JSON.parse(symbol.meta),
|
|
775
|
+
(reason) => err.new("symbol_meta_parse_error", { reason, symbol_id: symbol.id, meta: symbol.meta })
|
|
776
|
+
);
|
|
777
|
+
}
|
|
778
|
+
var search3 = safe_query("symbols.search", (ctx, options = {}) => {
|
|
779
|
+
return do_search(ctx.db, symbols, merge(symbols2, options));
|
|
780
|
+
});
|
|
781
|
+
var referenced_by = safe_query(
|
|
782
|
+
"symbols.referenced_by",
|
|
783
|
+
(ctx, symbol_id, fields_to_select = symbols2.select) => {
|
|
784
|
+
if (!fields_to_select.includes("id")) fields_to_select.push("id");
|
|
785
|
+
const link_records = ctx.db.select({ id: symbol_internal_links.to_symbol_id }).from(symbol_internal_links).where((0, import_drizzle_orm8.eq)(symbol_internal_links.from_symbol_id, symbol_id)).all();
|
|
786
|
+
const symbol_ids = uniq(link_records.map((i) => i.id).filter((id) => id !== null));
|
|
787
|
+
if (symbol_ids.length === 0) return [];
|
|
788
|
+
return ctx.db.select(fields(symbols, fields_to_select)).from(symbols).where((0, import_drizzle_orm8.inArray)(symbols.id, symbol_ids)).all();
|
|
789
|
+
}
|
|
790
|
+
);
|
|
791
|
+
var referencing = safe_query(
|
|
792
|
+
"symbols.referencing",
|
|
793
|
+
(ctx, symbol_id, fields_to_select = symbols2.select) => {
|
|
794
|
+
if (!fields_to_select.includes("id")) fields_to_select.push("id");
|
|
795
|
+
const link_records = ctx.db.select({ id: symbol_internal_links.from_symbol_id }).from(symbol_internal_links).where((0, import_drizzle_orm8.eq)(symbol_internal_links.to_symbol_id, symbol_id)).all();
|
|
796
|
+
const symbol_ids = uniq(link_records.map((i) => i.id).filter((id) => id !== null));
|
|
797
|
+
if (symbol_ids.length === 0) return [];
|
|
798
|
+
return ctx.db.select(fields(symbols, fields_to_select)).from(symbols).where((0, import_drizzle_orm8.inArray)(symbols.id, symbol_ids)).all();
|
|
799
|
+
}
|
|
800
|
+
);
|
|
801
|
+
var using_dependency2 = safe_query(
|
|
802
|
+
"symbols.using_dependency",
|
|
803
|
+
(ctx, dependency_id, fields_to_select = symbols2.select) => {
|
|
804
|
+
if (!fields_to_select.includes("id")) fields_to_select.push("id");
|
|
805
|
+
const link_records = ctx.db.select({ symbol_id: symbol_external_links.symbol_id }).from(symbol_external_links).innerJoin(external_imports, (0, import_drizzle_orm8.eq)(symbol_external_links.external_import_id, external_imports.id)).where((0, import_drizzle_orm8.eq)(external_imports.external_dependency_id, dependency_id)).all();
|
|
806
|
+
const symbol_ids = uniq(link_records.map((i) => i.symbol_id));
|
|
807
|
+
if (symbol_ids.length === 0) return [];
|
|
808
|
+
return ctx.db.select(fields(symbols, fields_to_select)).from(symbols).where((0, import_drizzle_orm8.inArray)(symbols.id, symbol_ids)).all();
|
|
809
|
+
}
|
|
810
|
+
);
|
|
811
|
+
|
|
812
|
+
// src/db/external_dependencies.ts
|
|
813
|
+
var external_dependencies_exports = {};
|
|
814
|
+
__export(external_dependencies_exports, {
|
|
815
|
+
all: () => all2,
|
|
816
|
+
by_id: () => by_id4,
|
|
817
|
+
by_package_subpath_and_name: () => by_package_subpath_and_name,
|
|
818
|
+
by_state: () => by_state5,
|
|
819
|
+
get_or_create: () => get_or_create,
|
|
820
|
+
insert: () => insert3,
|
|
821
|
+
search: () => search4,
|
|
822
|
+
update: () => update5,
|
|
823
|
+
used_by_file: () => used_by_file,
|
|
824
|
+
used_by_symbol: () => used_by_symbol
|
|
825
|
+
});
|
|
826
|
+
var import_drizzle_orm9 = require("drizzle-orm");
|
|
827
|
+
var by_id4 = safe_query(
|
|
828
|
+
"external_dependencies.by_id",
|
|
829
|
+
(ctx, id) => ctx.db.select().from(external_dependencies).where((0, import_drizzle_orm9.eq)(external_dependencies.id, id)).get()
|
|
830
|
+
);
|
|
831
|
+
var by_state5 = safe_query(
|
|
832
|
+
"external_dependencies.by_state",
|
|
833
|
+
(ctx, state) => ctx.db.select().from(external_dependencies).where((0, import_drizzle_orm9.eq)(external_dependencies.state, state)).all()
|
|
834
|
+
);
|
|
835
|
+
var by_package_subpath_and_name = safe_query(
|
|
836
|
+
"external_dependencies.by_package_subpath_and_name",
|
|
837
|
+
(ctx, params) => ctx.db.select().from(external_dependencies).where(
|
|
838
|
+
(0, import_drizzle_orm9.and)(
|
|
839
|
+
(0, import_drizzle_orm9.eq)(external_dependencies.package, params.package),
|
|
840
|
+
params.subpath === null ? import_drizzle_orm9.sql`${external_dependencies.subpath} IS NULL` : (0, import_drizzle_orm9.eq)(external_dependencies.subpath, params.subpath),
|
|
841
|
+
params.name === null ? import_drizzle_orm9.sql`${external_dependencies.name} IS NULL` : (0, import_drizzle_orm9.eq)(external_dependencies.name, params.name)
|
|
842
|
+
)
|
|
843
|
+
).get()
|
|
844
|
+
);
|
|
845
|
+
var insert3 = safe_query(
|
|
846
|
+
"external_dependencies.insert",
|
|
847
|
+
(ctx, value) => ctx.db.insert(external_dependencies).values(value).returning().get()
|
|
848
|
+
);
|
|
849
|
+
var update5 = safe_query(
|
|
850
|
+
"external_dependencies.update",
|
|
851
|
+
(ctx, id, data) => ctx.db.update(external_dependencies).set(data).where((0, import_drizzle_orm9.eq)(external_dependencies.id, id)).run()
|
|
852
|
+
);
|
|
853
|
+
var all2 = safe_query("external_dependencies.all", (ctx) => ctx.db.select().from(external_dependencies).all());
|
|
854
|
+
function get_or_create(ctx, value) {
|
|
855
|
+
return err.pipe(
|
|
856
|
+
() => by_package_subpath_and_name(ctx, { package: value.package, subpath: value.subpath ?? null, name: value.name ?? null }),
|
|
857
|
+
(existing) => existing || insert3(ctx, value)
|
|
858
|
+
);
|
|
859
|
+
}
|
|
860
|
+
var search4 = safe_query(
|
|
861
|
+
"external_dependencies.search",
|
|
862
|
+
(ctx, options = {}) => {
|
|
863
|
+
return do_search(ctx.db, external_dependencies, merge(external_dependencies2, options));
|
|
864
|
+
}
|
|
865
|
+
);
|
|
866
|
+
var used_by_file = safe_query(
|
|
867
|
+
"external_dependencies.used_by_file",
|
|
868
|
+
(ctx, file_id, fields_to_select = external_dependencies2.select) => {
|
|
869
|
+
if (!fields_to_select.includes("id")) fields_to_select.push("id");
|
|
870
|
+
const imports_records = ctx.db.select({ external_dependency_id: external_imports.external_dependency_id }).from(external_imports).where((0, import_drizzle_orm9.eq)(external_imports.file_id, file_id)).all();
|
|
871
|
+
const dependency_ids = uniq(imports_records.map((r) => r.external_dependency_id));
|
|
872
|
+
if (dependency_ids.length === 0) return [];
|
|
873
|
+
return ctx.db.select(fields(external_dependencies, fields_to_select)).from(external_dependencies).where((0, import_drizzle_orm9.inArray)(external_dependencies.id, dependency_ids)).all();
|
|
874
|
+
}
|
|
875
|
+
);
|
|
876
|
+
var used_by_symbol = safe_query(
|
|
877
|
+
"external_dependencies.used_by_symbol",
|
|
878
|
+
(ctx, symbol_id, fields_to_select = external_dependencies2.select) => {
|
|
879
|
+
if (!fields_to_select.includes("id")) fields_to_select.push("id");
|
|
880
|
+
const link_records = ctx.db.select({ external_import_id: symbol_external_links.external_import_id }).from(symbol_external_links).where((0, import_drizzle_orm9.eq)(symbol_external_links.symbol_id, symbol_id)).all();
|
|
881
|
+
if (link_records.length === 0) return [];
|
|
882
|
+
const external_import_ids = uniq(link_records.map((r) => r.external_import_id));
|
|
883
|
+
const imports_records = ctx.db.select({ external_dependency_id: external_imports.external_dependency_id }).from(external_imports).where((0, import_drizzle_orm9.inArray)(external_imports.id, external_import_ids)).all();
|
|
884
|
+
const dependency_ids = uniq(imports_records.map((r) => r.external_dependency_id));
|
|
885
|
+
if (dependency_ids.length === 0) return [];
|
|
886
|
+
return ctx.db.select(fields(external_dependencies, fields_to_select)).from(external_dependencies).where((0, import_drizzle_orm9.inArray)(external_dependencies.id, dependency_ids)).all();
|
|
887
|
+
}
|
|
888
|
+
);
|
|
889
|
+
|
|
890
|
+
// src/db/external_imports.ts
|
|
891
|
+
var external_imports_exports = {};
|
|
892
|
+
__export(external_imports_exports, {
|
|
893
|
+
by_external_dependency: () => by_external_dependency,
|
|
894
|
+
by_file: () => by_file2,
|
|
895
|
+
by_symbol: () => by_symbol,
|
|
896
|
+
del_by_file: () => del_by_file2,
|
|
897
|
+
insert_many: () => insert_many3
|
|
898
|
+
});
|
|
899
|
+
var import_drizzle_orm10 = require("drizzle-orm");
|
|
900
|
+
var insert_many3 = safe_query(
|
|
901
|
+
"external_imports.insert_many",
|
|
902
|
+
(ctx, values) => ctx.db.insert(external_imports).values(values).run()
|
|
903
|
+
);
|
|
904
|
+
var del_by_file2 = safe_query(
|
|
905
|
+
"external_imports.delete_by_file",
|
|
906
|
+
(ctx, file_id) => ctx.db.delete(external_imports).where((0, import_drizzle_orm10.eq)(external_imports.file_id, file_id)).run()
|
|
907
|
+
);
|
|
908
|
+
var by_file2 = safe_query(
|
|
909
|
+
"external_imports.by_file",
|
|
910
|
+
(ctx, file_id) => ctx.db.select().from(external_imports).where((0, import_drizzle_orm10.eq)(external_imports.file_id, file_id)).all()
|
|
911
|
+
);
|
|
912
|
+
var by_external_dependency = safe_query(
|
|
913
|
+
"external_imports.by_external_dependency",
|
|
914
|
+
(ctx, external_dependency_id) => ctx.db.select().from(external_imports).where((0, import_drizzle_orm10.eq)(external_imports.external_dependency_id, external_dependency_id)).all()
|
|
915
|
+
);
|
|
916
|
+
var by_symbol = safe_query(
|
|
917
|
+
"external_imports.by_symbol",
|
|
918
|
+
(ctx, symbol_id) => ctx.db.query.symbol_external_links.findMany({
|
|
919
|
+
where: (0, import_drizzle_orm10.eq)(symbol_external_links.symbol_id, symbol_id),
|
|
920
|
+
with: {
|
|
921
|
+
external_import: {
|
|
922
|
+
with: {
|
|
923
|
+
external_dependency: true
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
})
|
|
928
|
+
);
|
|
929
|
+
|
|
930
|
+
// src/db/symbol_internal_links.ts
|
|
931
|
+
var symbol_internal_links_exports = {};
|
|
932
|
+
__export(symbol_internal_links_exports, {
|
|
933
|
+
by_from_symbol: () => by_from_symbol,
|
|
934
|
+
del_by_from_symbol: () => del_by_from_symbol,
|
|
935
|
+
exists: () => exists,
|
|
936
|
+
insert: () => insert4
|
|
937
|
+
});
|
|
938
|
+
var import_drizzle_orm11 = require("drizzle-orm");
|
|
939
|
+
var by_from_symbol = safe_query(
|
|
940
|
+
"symbol_internal_links.by_from_symbol",
|
|
941
|
+
(ctx, from_symbol_id) => ctx.db.query.symbol_internal_links.findMany({
|
|
942
|
+
where: (0, import_drizzle_orm11.eq)(symbol_internal_links.from_symbol_id, from_symbol_id),
|
|
943
|
+
with: {
|
|
944
|
+
to_symbol: {
|
|
945
|
+
with: {
|
|
946
|
+
file: true
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
})
|
|
951
|
+
);
|
|
952
|
+
var insert4 = safe_query(
|
|
953
|
+
"symbol_internal_links.insert",
|
|
954
|
+
(ctx, value) => ctx.db.insert(symbol_internal_links).values(value).run()
|
|
955
|
+
);
|
|
956
|
+
var exists = safe_query(
|
|
957
|
+
"symbol_internal_links.exists",
|
|
958
|
+
(ctx, params) => ctx.db.select({ id: symbol_internal_links.id }).from(symbol_internal_links).where((0, import_drizzle_orm11.and)((0, import_drizzle_orm11.eq)(symbol_internal_links.from_symbol_id, params.from_symbol_id), (0, import_drizzle_orm11.eq)(symbol_internal_links.to_symbol_id, params.to_symbol_id))).get()
|
|
959
|
+
);
|
|
960
|
+
var del_by_from_symbol = safe_query(
|
|
961
|
+
"symbol_internal_links.del_by_from_symbol",
|
|
962
|
+
(ctx, from_symbol_id) => ctx.db.delete(symbol_internal_links).where((0, import_drizzle_orm11.eq)(symbol_internal_links.from_symbol_id, from_symbol_id)).run()
|
|
963
|
+
);
|
|
964
|
+
|
|
965
|
+
// src/db/symbol_external_links.ts
|
|
966
|
+
var symbol_external_links_exports = {};
|
|
967
|
+
__export(symbol_external_links_exports, {
|
|
968
|
+
by_external_import: () => by_external_import,
|
|
969
|
+
by_symbol: () => by_symbol2,
|
|
970
|
+
del_by_symbol: () => del_by_symbol,
|
|
971
|
+
exists: () => exists2,
|
|
972
|
+
insert: () => insert5
|
|
973
|
+
});
|
|
974
|
+
var import_drizzle_orm12 = require("drizzle-orm");
|
|
975
|
+
var by_symbol2 = safe_query(
|
|
976
|
+
"symbol_external_links.by_symbol",
|
|
977
|
+
(ctx, symbol_id) => ctx.db.select().from(symbol_external_links).where((0, import_drizzle_orm12.eq)(symbol_external_links.symbol_id, symbol_id)).all()
|
|
978
|
+
);
|
|
979
|
+
var insert5 = safe_query(
|
|
980
|
+
"symbol_external_links.insert",
|
|
981
|
+
(ctx, value) => ctx.db.insert(symbol_external_links).values(value).run()
|
|
982
|
+
);
|
|
983
|
+
var by_external_import = safe_query(
|
|
984
|
+
"symbol_external_links.by_external_import",
|
|
985
|
+
(ctx, external_import_id) => ctx.db.select().from(symbol_external_links).where((0, import_drizzle_orm12.eq)(symbol_external_links.external_import_id, external_import_id)).all()
|
|
986
|
+
);
|
|
987
|
+
var exists2 = safe_query(
|
|
988
|
+
"symbol_external_links.exists",
|
|
989
|
+
(ctx, params) => ctx.db.select({ id: symbol_external_links.id }).from(symbol_external_links).where((0, import_drizzle_orm12.and)((0, import_drizzle_orm12.eq)(symbol_external_links.symbol_id, params.symbol_id), (0, import_drizzle_orm12.eq)(symbol_external_links.external_import_id, params.external_import_id))).get()
|
|
990
|
+
);
|
|
991
|
+
var del_by_symbol = safe_query(
|
|
992
|
+
"symbol_external_links.del_by_symbol",
|
|
993
|
+
(ctx, symbol_id) => ctx.db.delete(symbol_external_links).where((0, import_drizzle_orm12.eq)(symbol_external_links.symbol_id, symbol_id)).run()
|
|
994
|
+
);
|
|
995
|
+
|
|
996
|
+
// src/internals/context.ts
|
|
997
|
+
var import_meta = {};
|
|
998
|
+
async function create_context(sqlite, db6, config) {
|
|
999
|
+
const project_path = import_path2.default.resolve(config.project_path);
|
|
1000
|
+
const currentDir = (0, import_path2.dirname)((0, import_url.fileURLToPath)(import_meta.url));
|
|
1001
|
+
const migrations_path = currentDir.includes("/dist") ? (0, import_path2.join)(currentDir, "../migrations") : (0, import_path2.join)(currentDir, "../../migrations");
|
|
1002
|
+
const tsconfig_path = (0, import_path2.join)(project_path, "tsconfig.json");
|
|
1003
|
+
if (!import_typescript.default.sys.fileExists(tsconfig_path)) {
|
|
1004
|
+
throw err.new("file_not_found", { path: tsconfig_path });
|
|
1005
|
+
}
|
|
1006
|
+
const tsconfig = import_typescript.default.parseJsonConfigFileContent(import_typescript.default.readConfigFile(tsconfig_path, import_typescript.default.sys.readFile).config, import_typescript.default.sys, project_path);
|
|
1007
|
+
const program = import_typescript.default.createProgram({ rootNames: tsconfig.fileNames, options: tsconfig.options });
|
|
1008
|
+
const package_json_path = config.package_json_path ?? import_path2.default.join(project_path, "package.json");
|
|
1009
|
+
const node_modules_paths = config.node_modules_paths ?? [import_path2.default.join(project_path, "node_modules")];
|
|
1010
|
+
const dependencies2 = await get_dependencies(package_json_path, node_modules_paths);
|
|
1011
|
+
const ctx = { db: db6, sqlite, migrations_path, project_path, program, dependencies: dependencies2 };
|
|
1012
|
+
await migrate(ctx);
|
|
1013
|
+
err.or_throw(
|
|
1014
|
+
configs_exports.upsert(ctx, {
|
|
1015
|
+
project_path,
|
|
1016
|
+
description: config.description ?? null,
|
|
1017
|
+
package_json_path: config.package_json_path ?? null,
|
|
1018
|
+
node_modules_paths: config.node_modules_paths ? JSON.stringify(config.node_modules_paths) : null
|
|
1019
|
+
})
|
|
1020
|
+
);
|
|
1021
|
+
return ctx;
|
|
1022
|
+
}
|
|
1023
|
+
async function context_from_config(config) {
|
|
1024
|
+
const sqlite = new import_better_sqlite3.default(config.db_path);
|
|
1025
|
+
sqlite.pragma("foreign_keys = ON");
|
|
1026
|
+
const db6 = (0, import_better_sqlite32.drizzle)(sqlite, { schema: schema_exports });
|
|
1027
|
+
return create_context(sqlite, db6, config);
|
|
1028
|
+
}
|
|
1029
|
+
async function context_from_db(db_path) {
|
|
1030
|
+
const sqlite = new import_better_sqlite3.default(db_path);
|
|
1031
|
+
sqlite.pragma("foreign_keys = ON");
|
|
1032
|
+
const db6 = (0, import_better_sqlite32.drizzle)(sqlite, { schema: schema_exports });
|
|
1033
|
+
const temp_ctx = { db: db6, sqlite };
|
|
1034
|
+
const stored = err.or_throw(configs_exports.get(temp_ctx));
|
|
1035
|
+
if (!stored) {
|
|
1036
|
+
sqlite.close();
|
|
1037
|
+
throw err.new("config_not_found", { db_path });
|
|
1038
|
+
}
|
|
1039
|
+
let node_modules_paths;
|
|
1040
|
+
if (stored.node_modules_paths) {
|
|
1041
|
+
try {
|
|
1042
|
+
node_modules_paths = JSON.parse(stored.node_modules_paths);
|
|
1043
|
+
} catch (parse_error) {
|
|
1044
|
+
sqlite.close();
|
|
1045
|
+
throw err.new("config_invalid_node_modules_paths", { db_path, reason: parse_error });
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
return create_context(sqlite, db6, {
|
|
1049
|
+
db_path,
|
|
1050
|
+
project_path: stored.project_path,
|
|
1051
|
+
description: stored.description ?? void 0,
|
|
1052
|
+
package_json_path: stored.package_json_path ?? void 0,
|
|
1053
|
+
node_modules_paths
|
|
1054
|
+
});
|
|
1055
|
+
}
|
|
1056
|
+
async function get_dependencies(package_json_path, node_modules_paths) {
|
|
1057
|
+
const dependencies2 = {};
|
|
1058
|
+
const package_json = JSON.parse(await (0, import_promises2.readFile)(package_json_path, "utf-8"));
|
|
1059
|
+
const packages = { ...package_json.dependencies ?? {}, ...package_json.devDependencies ?? {} };
|
|
1060
|
+
for (const [name, version] of Object.entries(packages)) {
|
|
1061
|
+
dependencies2[name] = { name, version, github_repo: await get_github_repo(node_modules_paths, name) };
|
|
1062
|
+
}
|
|
1063
|
+
return dependencies2;
|
|
1064
|
+
}
|
|
1065
|
+
async function get_github_repo(node_modules_paths, package_name) {
|
|
1066
|
+
for (const node_modules_path of node_modules_paths) {
|
|
1067
|
+
try {
|
|
1068
|
+
const package_json_path = import_path2.default.join(node_modules_path, package_name, "package.json");
|
|
1069
|
+
const package_json = JSON.parse(await (0, import_promises2.readFile)(package_json_path, "utf-8"));
|
|
1070
|
+
const url = package_json.repository?.url || package_json.repository;
|
|
1071
|
+
if (typeof url === "string") {
|
|
1072
|
+
let repo = url.split("/").slice(-2).join("/");
|
|
1073
|
+
if (repo.endsWith(".git")) repo = repo.slice(0, -4);
|
|
1074
|
+
return repo.split(":").pop();
|
|
1075
|
+
}
|
|
1076
|
+
} catch {
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
return void 0;
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
// src/cli/env.ts
|
|
1083
|
+
var env = {
|
|
1084
|
+
read_file,
|
|
1085
|
+
file_exists: (path6) => (0, import_fs2.existsSync)(path6),
|
|
1086
|
+
argv: () => process.argv,
|
|
1087
|
+
log: (...args) => console.log(...args),
|
|
1088
|
+
error: (...args) => console.error(...args),
|
|
1089
|
+
exit: (code) => process.exit(code)
|
|
1090
|
+
};
|
|
1091
|
+
|
|
1092
|
+
// src/cli/commands/_common.ts
|
|
1093
|
+
var import_zod2 = require("zod");
|
|
1094
|
+
|
|
1095
|
+
// src/cli/schema.ts
|
|
1096
|
+
var import_zod = require("zod");
|
|
1097
|
+
var Config = import_zod.z.object({
|
|
1098
|
+
db_path: import_zod.z.string().describe("Path to SQLite database"),
|
|
1099
|
+
project_path: import_zod.z.string().describe("Path to TypeScript project"),
|
|
1100
|
+
description: import_zod.z.string().optional(),
|
|
1101
|
+
package_json_path: import_zod.z.string().optional(),
|
|
1102
|
+
node_modules_paths: import_zod.z.array(import_zod.z.string()).optional()
|
|
1103
|
+
});
|
|
1104
|
+
var StringFilter = import_zod.z.union([
|
|
1105
|
+
import_zod.z.string(),
|
|
1106
|
+
import_zod.z.object({ contains: import_zod.z.string() }),
|
|
1107
|
+
import_zod.z.object({ starts_with: import_zod.z.string() }),
|
|
1108
|
+
import_zod.z.object({ ends_with: import_zod.z.string() })
|
|
1109
|
+
]);
|
|
1110
|
+
var OrderDirection = import_zod.z.enum(["asc", "desc"]);
|
|
1111
|
+
var FileField = import_zod.z.enum(["id", "directory_id", "path", "description", "state", "error"]);
|
|
1112
|
+
var FileState = import_zod.z.enum(["to_scan", "to_describe", "ready"]);
|
|
1113
|
+
var FileSearchOptions = import_zod.z.object({
|
|
1114
|
+
select: import_zod.z.array(FileField).optional(),
|
|
1115
|
+
limit: import_zod.z.number().int().positive().optional(),
|
|
1116
|
+
offset: import_zod.z.number().int().nonnegative().optional(),
|
|
1117
|
+
where: import_zod.z.object({
|
|
1118
|
+
id: import_zod.z.number().optional(),
|
|
1119
|
+
directory_id: import_zod.z.number().optional(),
|
|
1120
|
+
path: StringFilter.optional(),
|
|
1121
|
+
description: StringFilter.optional(),
|
|
1122
|
+
state: import_zod.z.union([FileState, import_zod.z.object({ contains: import_zod.z.string() })]).optional(),
|
|
1123
|
+
error: StringFilter.optional()
|
|
1124
|
+
}).optional(),
|
|
1125
|
+
order_by: import_zod.z.tuple([FileField, OrderDirection]).optional()
|
|
1126
|
+
});
|
|
1127
|
+
var FileRelationOptions = import_zod.z.object({
|
|
1128
|
+
select: import_zod.z.array(FileField).optional(),
|
|
1129
|
+
limit: import_zod.z.number().int().positive().optional(),
|
|
1130
|
+
offset: import_zod.z.number().int().nonnegative().optional(),
|
|
1131
|
+
deep: import_zod.z.boolean().optional()
|
|
1132
|
+
});
|
|
1133
|
+
var SymbolField = import_zod.z.enum(["id", "file_id", "type", "name", "text", "meta", "description", "is_exported", "state", "error"]);
|
|
1134
|
+
var SymbolType = import_zod.z.enum(["function", "class", "class_method", "class_property", "variable", "type"]);
|
|
1135
|
+
var SymbolState = import_zod.z.enum(["to_link", "to_describe", "ready"]);
|
|
1136
|
+
var SymbolSearchOptions = import_zod.z.object({
|
|
1137
|
+
select: import_zod.z.array(SymbolField).optional(),
|
|
1138
|
+
limit: import_zod.z.number().int().positive().optional(),
|
|
1139
|
+
offset: import_zod.z.number().int().nonnegative().optional(),
|
|
1140
|
+
where: import_zod.z.object({
|
|
1141
|
+
id: import_zod.z.number().optional(),
|
|
1142
|
+
file_id: import_zod.z.number().optional(),
|
|
1143
|
+
type: import_zod.z.union([SymbolType, import_zod.z.object({ contains: import_zod.z.string() })]).optional(),
|
|
1144
|
+
name: StringFilter.optional(),
|
|
1145
|
+
text: StringFilter.optional(),
|
|
1146
|
+
meta: StringFilter.optional(),
|
|
1147
|
+
description: StringFilter.optional(),
|
|
1148
|
+
is_exported: import_zod.z.boolean().optional(),
|
|
1149
|
+
state: import_zod.z.union([SymbolState, import_zod.z.object({ contains: import_zod.z.string() })]).optional(),
|
|
1150
|
+
error: StringFilter.optional()
|
|
1151
|
+
}).optional(),
|
|
1152
|
+
order_by: import_zod.z.tuple([SymbolField, OrderDirection]).optional()
|
|
1153
|
+
});
|
|
1154
|
+
var SymbolRelationOptions = import_zod.z.object({
|
|
1155
|
+
select: import_zod.z.array(SymbolField).optional(),
|
|
1156
|
+
limit: import_zod.z.number().int().positive().optional(),
|
|
1157
|
+
offset: import_zod.z.number().int().nonnegative().optional(),
|
|
1158
|
+
deep: import_zod.z.boolean().optional()
|
|
1159
|
+
});
|
|
1160
|
+
var DirectoryField = import_zod.z.enum(["id", "parent_id", "path", "description", "state", "error"]);
|
|
1161
|
+
var DirectoryState = import_zod.z.enum(["to_describe", "ready"]);
|
|
1162
|
+
var DirectorySearchOptions = import_zod.z.object({
|
|
1163
|
+
select: import_zod.z.array(DirectoryField).optional(),
|
|
1164
|
+
limit: import_zod.z.number().int().positive().optional(),
|
|
1165
|
+
offset: import_zod.z.number().int().nonnegative().optional(),
|
|
1166
|
+
where: import_zod.z.object({
|
|
1167
|
+
id: import_zod.z.number().optional(),
|
|
1168
|
+
parent_id: import_zod.z.number().optional(),
|
|
1169
|
+
path: StringFilter.optional(),
|
|
1170
|
+
description: StringFilter.optional(),
|
|
1171
|
+
state: import_zod.z.union([DirectoryState, import_zod.z.object({ contains: import_zod.z.string() })]).optional(),
|
|
1172
|
+
error: StringFilter.optional()
|
|
1173
|
+
}).optional(),
|
|
1174
|
+
order_by: import_zod.z.tuple([DirectoryField, OrderDirection]).optional()
|
|
1175
|
+
});
|
|
1176
|
+
var DirectoryRelationOptions = import_zod.z.object({
|
|
1177
|
+
select: import_zod.z.array(DirectoryField).optional(),
|
|
1178
|
+
limit: import_zod.z.number().int().positive().optional(),
|
|
1179
|
+
offset: import_zod.z.number().int().nonnegative().optional(),
|
|
1180
|
+
deep: import_zod.z.boolean().optional()
|
|
1181
|
+
});
|
|
1182
|
+
var DependencyField = import_zod.z.enum(["id", "package", "subpath", "name", "version", "github_repo", "is_builtin", "description", "state", "error"]);
|
|
1183
|
+
var DependencyState = import_zod.z.enum(["to_describe", "ready"]);
|
|
1184
|
+
var DependencySearchOptions = import_zod.z.object({
|
|
1185
|
+
select: import_zod.z.array(DependencyField).optional(),
|
|
1186
|
+
limit: import_zod.z.number().int().positive().optional(),
|
|
1187
|
+
offset: import_zod.z.number().int().nonnegative().optional(),
|
|
1188
|
+
where: import_zod.z.object({
|
|
1189
|
+
id: import_zod.z.number().optional(),
|
|
1190
|
+
package: StringFilter.optional(),
|
|
1191
|
+
subpath: StringFilter.optional(),
|
|
1192
|
+
name: StringFilter.optional(),
|
|
1193
|
+
version: StringFilter.optional(),
|
|
1194
|
+
github_repo: StringFilter.optional(),
|
|
1195
|
+
is_builtin: import_zod.z.boolean().optional(),
|
|
1196
|
+
description: StringFilter.optional(),
|
|
1197
|
+
state: import_zod.z.union([DependencyState, import_zod.z.object({ contains: import_zod.z.string() })]).optional(),
|
|
1198
|
+
error: StringFilter.optional()
|
|
1199
|
+
}).optional(),
|
|
1200
|
+
order_by: import_zod.z.tuple([DependencyField, OrderDirection]).optional()
|
|
1201
|
+
});
|
|
1202
|
+
var DependencySelectOptions = import_zod.z.object({
|
|
1203
|
+
select: import_zod.z.array(DependencyField).optional(),
|
|
1204
|
+
limit: import_zod.z.number().int().positive().optional(),
|
|
1205
|
+
offset: import_zod.z.number().int().nonnegative().optional()
|
|
1206
|
+
});
|
|
1207
|
+
|
|
1208
|
+
// src/update/track_changes.ts
|
|
1209
|
+
var import_path3 = __toESM(require("path"), 1);
|
|
1210
|
+
var import_typescript2 = require("typescript");
|
|
1211
|
+
var import_promises3 = require("fs/promises");
|
|
1212
|
+
|
|
1213
|
+
// src/update/events.ts
|
|
1214
|
+
function file_updated(ctx, file_id) {
|
|
1215
|
+
const impacted_files_ids = err.or_throw(
|
|
1216
|
+
expand({
|
|
1217
|
+
items: [file_id],
|
|
1218
|
+
get_key: (id) => id,
|
|
1219
|
+
get_children: (id) => {
|
|
1220
|
+
const imports2 = imports_exports.by_exporter_file(ctx, id);
|
|
1221
|
+
if (err.any(imports2)) return imports2;
|
|
1222
|
+
return imports2.map((x) => x.importer_file_id);
|
|
1223
|
+
}
|
|
1224
|
+
})
|
|
1225
|
+
);
|
|
1226
|
+
const dir_ids = err.or_throw(files_exports.get_directory_ids(ctx, impacted_files_ids));
|
|
1227
|
+
const impacted_dirs_ids = err.or_throw(
|
|
1228
|
+
expand({
|
|
1229
|
+
items: dir_ids,
|
|
1230
|
+
get_key: (id) => id,
|
|
1231
|
+
get_children: (id) => {
|
|
1232
|
+
const dir = directories_exports.by_id(ctx, id);
|
|
1233
|
+
if (err.any(dir)) return dir;
|
|
1234
|
+
return dir?.parent_id ? [dir.parent_id] : [];
|
|
1235
|
+
}
|
|
1236
|
+
})
|
|
1237
|
+
);
|
|
1238
|
+
err.or_throw(files_exports.update_many(ctx, impacted_files_ids, { state: "to_scan" }));
|
|
1239
|
+
err.or_throw(directories_exports.update_many(ctx, impacted_dirs_ids, { state: "to_describe" }));
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
// src/update/track_changes.ts
|
|
1243
|
+
async function track_changes(ctx) {
|
|
1244
|
+
const db_files = err.or_throw(files_exports.all(ctx));
|
|
1245
|
+
const { created, updated, deleted } = await changes(ctx, get_source_files(ctx), db_files);
|
|
1246
|
+
for (const { source_file, hash } of created) handle_new_source_file(ctx, source_file, hash);
|
|
1247
|
+
for (const { db_file, hash } of updated) handle_changed_source_file(ctx, db_file, hash);
|
|
1248
|
+
for (const { db_file } of deleted) handle_deleted_source_file(ctx, db_file);
|
|
1249
|
+
}
|
|
1250
|
+
function get_source_files(ctx) {
|
|
1251
|
+
const src_files = [];
|
|
1252
|
+
for (const file of ctx.program.getSourceFiles()) {
|
|
1253
|
+
if (ctx.program.isSourceFileDefaultLibrary(file)) continue;
|
|
1254
|
+
if (ctx.program.isSourceFileFromExternalLibrary(file)) continue;
|
|
1255
|
+
if (!import_path3.default.resolve(file.fileName).startsWith(ctx.project_path)) continue;
|
|
1256
|
+
src_files.push(file);
|
|
1257
|
+
}
|
|
1258
|
+
return src_files;
|
|
1259
|
+
}
|
|
1260
|
+
function handle_new_source_file(ctx, file, hash) {
|
|
1261
|
+
const file_path = err.or_throw(get_file_path(ctx, file));
|
|
1262
|
+
const dirs_paths = err.or_throw(get_parents_paths(ctx, file));
|
|
1263
|
+
let parent_dir_id = null;
|
|
1264
|
+
for (const dir_path of dirs_paths) {
|
|
1265
|
+
let dir = err.or_throw(directories_exports.by_path(ctx, dir_path));
|
|
1266
|
+
if (dir) {
|
|
1267
|
+
err.or_throw(directories_exports.update(ctx, dir.id, { state: "to_describe" }));
|
|
1268
|
+
} else {
|
|
1269
|
+
dir = err.or_throw(directories_exports.insert(ctx, { path: dir_path, state: "to_describe", parent_id: parent_dir_id }));
|
|
1270
|
+
}
|
|
1271
|
+
parent_dir_id = dir.id;
|
|
1272
|
+
}
|
|
1273
|
+
err.or_throw(files_exports.insert(ctx, { directory_id: parent_dir_id, path: file_path, state: "to_scan", hash }));
|
|
1274
|
+
}
|
|
1275
|
+
function handle_changed_source_file(ctx, db_file, hash) {
|
|
1276
|
+
file_updated(ctx, db_file.id);
|
|
1277
|
+
err.or_throw(files_exports.update(ctx, db_file.id, { hash }));
|
|
1278
|
+
}
|
|
1279
|
+
function handle_deleted_source_file(ctx, db_file) {
|
|
1280
|
+
err.or_throw(handle_changed_source_file(ctx, db_file, ""));
|
|
1281
|
+
err.or_throw(files_exports.del(ctx, db_file.id));
|
|
1282
|
+
}
|
|
1283
|
+
async function changes(ctx, source_files, db_files) {
|
|
1284
|
+
const created = [];
|
|
1285
|
+
const updated = [];
|
|
1286
|
+
const deleted = [];
|
|
1287
|
+
const db_files_index = group_by_unique(db_files, (x) => x.path);
|
|
1288
|
+
const source_files_index = group_by_unique(source_files, (x) => err.or(get_file_path(ctx, x), ""));
|
|
1289
|
+
const filenames = new Set(Object.keys(source_files_index).concat(Object.keys(db_files_index)));
|
|
1290
|
+
for (const filename of filenames) {
|
|
1291
|
+
const db_file = db_files_index[filename];
|
|
1292
|
+
const source_file = source_files_index[filename];
|
|
1293
|
+
if (!db_file && source_file) created.push({ source_file, hash: await file_signature(source_file.fileName) });
|
|
1294
|
+
if (db_file && !source_file) deleted.push({ db_file });
|
|
1295
|
+
if (db_file && source_file) {
|
|
1296
|
+
const hash = await file_signature(source_file.fileName);
|
|
1297
|
+
if (db_file.hash !== hash) updated.push({ db_file, source_file, hash });
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
return { created, updated, deleted };
|
|
1301
|
+
}
|
|
1302
|
+
function get_file_path(ctx, file) {
|
|
1303
|
+
const absolute_path = import_path3.default.resolve(file.fileName);
|
|
1304
|
+
if (absolute_path.startsWith(ctx.project_path)) return absolute_path.slice(ctx.project_path.length);
|
|
1305
|
+
return err.new("file_outside_project_path", { file_path: absolute_path, project_path: ctx.project_path });
|
|
1306
|
+
}
|
|
1307
|
+
function get_parents_paths(ctx, file) {
|
|
1308
|
+
const file_path = get_file_path(ctx, file);
|
|
1309
|
+
if (err.any(file_path)) return file_path;
|
|
1310
|
+
const dirs = [];
|
|
1311
|
+
let current = import_path3.default.dirname(file_path);
|
|
1312
|
+
while (current !== import_path3.default.sep) {
|
|
1313
|
+
dirs.push(current);
|
|
1314
|
+
current = import_path3.default.dirname(current);
|
|
1315
|
+
}
|
|
1316
|
+
dirs.push(current);
|
|
1317
|
+
return dirs.reverse();
|
|
1318
|
+
}
|
|
1319
|
+
async function file_signature(file_path) {
|
|
1320
|
+
const stats = await (0, import_promises3.stat)(file_path);
|
|
1321
|
+
return `${stats.mtimeMs}:${stats.size}`;
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
// src/update/sync_external_dependencies.ts
|
|
1325
|
+
async function sync_external_dependencies(ctx) {
|
|
1326
|
+
const db_deps = err.or_throw(external_dependencies_exports.all(ctx));
|
|
1327
|
+
for (const ctx_dep of Object.values(ctx.dependencies)) {
|
|
1328
|
+
const existing = db_deps.filter((d) => d.package === ctx_dep.name);
|
|
1329
|
+
if (existing.length === 0) continue;
|
|
1330
|
+
const needs_update = existing.some((d) => d.version !== ctx_dep.version || (d.github_repo || "") !== (ctx_dep.github_repo || ""));
|
|
1331
|
+
if (!needs_update) continue;
|
|
1332
|
+
for (const db_dep of existing) {
|
|
1333
|
+
err.or_throw(
|
|
1334
|
+
external_dependencies_exports.update(ctx, db_dep.id, {
|
|
1335
|
+
version: ctx_dep.version,
|
|
1336
|
+
github_repo: ctx_dep.github_repo,
|
|
1337
|
+
state: "to_describe",
|
|
1338
|
+
error: null
|
|
1339
|
+
})
|
|
1340
|
+
);
|
|
1341
|
+
const files5 = err.or_throw(files_exports.using_dependency(ctx, db_dep.id, ["id"]));
|
|
1342
|
+
for (const file of files5) file_updated(ctx, file.id);
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
// src/update/scan_files/scan_files.ts
|
|
1348
|
+
var import_path5 = __toESM(require("path"), 1);
|
|
1349
|
+
var import_typescript10 = __toESM(require("typescript"), 1);
|
|
1350
|
+
|
|
1351
|
+
// src/update/scan_files/imports.ts
|
|
1352
|
+
var import_typescript4 = __toESM(require("typescript"), 1);
|
|
1353
|
+
|
|
1354
|
+
// src/update/scan_files/common.ts
|
|
1355
|
+
var import_path4 = __toESM(require("path"), 1);
|
|
1356
|
+
var import_typescript3 = __toESM(require("typescript"), 1);
|
|
1357
|
+
function is_external_module(ctx, source_file, module_path) {
|
|
1358
|
+
const resolved = import_typescript3.default.resolveModuleName(module_path, source_file.fileName, ctx.program.getCompilerOptions(), import_typescript3.default.sys);
|
|
1359
|
+
if (!resolved.resolvedModule) return true;
|
|
1360
|
+
const resolved_path = import_path4.default.resolve(resolved.resolvedModule.resolvedFileName);
|
|
1361
|
+
return !resolved_path.startsWith(ctx.project_path);
|
|
1362
|
+
}
|
|
1363
|
+
function has_export_modifier(node) {
|
|
1364
|
+
if (!import_typescript3.default.canHaveModifiers(node)) return false;
|
|
1365
|
+
const modifiers = import_typescript3.default.getModifiers(node);
|
|
1366
|
+
if (!modifiers) return false;
|
|
1367
|
+
return modifiers.some((m) => m.kind === import_typescript3.default.SyntaxKind.ExportKeyword);
|
|
1368
|
+
}
|
|
1369
|
+
function has_default_modifier(node) {
|
|
1370
|
+
if (!import_typescript3.default.canHaveModifiers(node)) return false;
|
|
1371
|
+
const modifiers = import_typescript3.default.getModifiers(node);
|
|
1372
|
+
if (!modifiers) return false;
|
|
1373
|
+
return modifiers.some((m) => m.kind === import_typescript3.default.SyntaxKind.DefaultKeyword);
|
|
1374
|
+
}
|
|
1375
|
+
function extract_parameters(node, source_file) {
|
|
1376
|
+
return node.parameters.map((param) => ({
|
|
1377
|
+
name: import_typescript3.default.isIdentifier(param.name) ? param.name.text : param.name.getText(source_file),
|
|
1378
|
+
type: param.type ? param.type.getText(source_file) : null,
|
|
1379
|
+
optional: !!param.questionToken,
|
|
1380
|
+
rest: !!param.dotDotDotToken,
|
|
1381
|
+
default: param.initializer ? param.initializer.getText(source_file) : null
|
|
1382
|
+
}));
|
|
1383
|
+
}
|
|
1384
|
+
function extract_type_parameters(node, source_file) {
|
|
1385
|
+
if (!("typeParameters" in node) || !node.typeParameters) return [];
|
|
1386
|
+
return node.typeParameters.map((tp) => tp.getText(source_file));
|
|
1387
|
+
}
|
|
1388
|
+
function extract_jsdoc_comment(node, source_file) {
|
|
1389
|
+
const sf = source_file || node.getSourceFile();
|
|
1390
|
+
if (!sf) return null;
|
|
1391
|
+
const sourceText = sf.getFullText();
|
|
1392
|
+
const ranges = import_typescript3.default.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
1393
|
+
if (!ranges || ranges.length === 0) return null;
|
|
1394
|
+
const lastComment = ranges[ranges.length - 1];
|
|
1395
|
+
if (!lastComment) return null;
|
|
1396
|
+
const commentText = sourceText.slice(lastComment.pos, lastComment.end);
|
|
1397
|
+
if (commentText.startsWith("/**")) {
|
|
1398
|
+
return commentText;
|
|
1399
|
+
}
|
|
1400
|
+
return null;
|
|
1401
|
+
}
|
|
1402
|
+
function extract_decorators(node, source_file) {
|
|
1403
|
+
if (!import_typescript3.default.canHaveDecorators(node)) return [];
|
|
1404
|
+
const decorators = import_typescript3.default.getDecorators(node);
|
|
1405
|
+
if (!decorators) return [];
|
|
1406
|
+
const sf = source_file || node.getSourceFile();
|
|
1407
|
+
return decorators.map((decorator) => {
|
|
1408
|
+
const expr = decorator.expression;
|
|
1409
|
+
if (import_typescript3.default.isIdentifier(expr)) {
|
|
1410
|
+
return { name: expr.text };
|
|
1411
|
+
}
|
|
1412
|
+
if (import_typescript3.default.isCallExpression(expr) && import_typescript3.default.isIdentifier(expr.expression)) {
|
|
1413
|
+
return {
|
|
1414
|
+
name: expr.expression.text,
|
|
1415
|
+
arguments: expr.arguments.map((arg) => arg.getText(sf))
|
|
1416
|
+
};
|
|
1417
|
+
}
|
|
1418
|
+
return { name: decorator.expression.getText(sf) };
|
|
1419
|
+
});
|
|
1420
|
+
}
|
|
1421
|
+
function is_builtin_module(package_name) {
|
|
1422
|
+
const builtins = [
|
|
1423
|
+
"fs",
|
|
1424
|
+
"path",
|
|
1425
|
+
"http",
|
|
1426
|
+
"https",
|
|
1427
|
+
"url",
|
|
1428
|
+
"crypto",
|
|
1429
|
+
"os",
|
|
1430
|
+
"util",
|
|
1431
|
+
"stream",
|
|
1432
|
+
"events",
|
|
1433
|
+
"buffer",
|
|
1434
|
+
"child_process",
|
|
1435
|
+
"cluster",
|
|
1436
|
+
"dns",
|
|
1437
|
+
"net",
|
|
1438
|
+
"tls",
|
|
1439
|
+
"dgram",
|
|
1440
|
+
"readline",
|
|
1441
|
+
"repl",
|
|
1442
|
+
"vm",
|
|
1443
|
+
"zlib",
|
|
1444
|
+
"assert",
|
|
1445
|
+
"querystring",
|
|
1446
|
+
"string_decoder",
|
|
1447
|
+
"timers",
|
|
1448
|
+
"tty",
|
|
1449
|
+
"v8",
|
|
1450
|
+
"worker_threads"
|
|
1451
|
+
];
|
|
1452
|
+
return builtins.includes(package_name) || package_name.startsWith("node:");
|
|
1453
|
+
}
|
|
1454
|
+
function is_dynamic_import(node) {
|
|
1455
|
+
if (!import_typescript3.default.isCallExpression(node)) return false;
|
|
1456
|
+
if (node.expression.kind !== import_typescript3.default.SyntaxKind.ImportKeyword) return false;
|
|
1457
|
+
if (node.arguments.length !== 1) return false;
|
|
1458
|
+
const arg = node.arguments[0];
|
|
1459
|
+
if (!arg) return false;
|
|
1460
|
+
return import_typescript3.default.isStringLiteral(arg);
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
// src/update/scan_files/imports.ts
|
|
1464
|
+
function is_import(ctx, source_file, node) {
|
|
1465
|
+
if (!import_typescript4.default.isImportDeclaration(node) || !node.moduleSpecifier || !import_typescript4.default.isStringLiteral(node.moduleSpecifier)) return false;
|
|
1466
|
+
return !is_external_module(ctx, source_file, node.moduleSpecifier.text);
|
|
1467
|
+
}
|
|
1468
|
+
function extract_import(ctx, source_file, node, file_id) {
|
|
1469
|
+
const imports2 = [];
|
|
1470
|
+
const clause = node.importClause;
|
|
1471
|
+
if (!clause || !node.moduleSpecifier || !import_typescript4.default.isStringLiteral(node.moduleSpecifier)) return imports2;
|
|
1472
|
+
const exporter_file_id = resolve_exporter_file(ctx, source_file, node.moduleSpecifier.text);
|
|
1473
|
+
if (err.any(exporter_file_id)) return imports2;
|
|
1474
|
+
if (clause.name) {
|
|
1475
|
+
imports2.push({
|
|
1476
|
+
importer_file_id: file_id,
|
|
1477
|
+
exporter_file_id,
|
|
1478
|
+
name: "default",
|
|
1479
|
+
alias: clause.name.text,
|
|
1480
|
+
state: "to_link"
|
|
1481
|
+
});
|
|
1482
|
+
}
|
|
1483
|
+
if (clause.namedBindings && import_typescript4.default.isNamedImports(clause.namedBindings)) {
|
|
1484
|
+
for (const element of clause.namedBindings.elements) {
|
|
1485
|
+
imports2.push({
|
|
1486
|
+
importer_file_id: file_id,
|
|
1487
|
+
exporter_file_id,
|
|
1488
|
+
name: (element.propertyName || element.name).text,
|
|
1489
|
+
alias: element.name.text,
|
|
1490
|
+
state: "to_link"
|
|
1491
|
+
});
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
if (clause.namedBindings && import_typescript4.default.isNamespaceImport(clause.namedBindings)) {
|
|
1495
|
+
imports2.push({
|
|
1496
|
+
importer_file_id: file_id,
|
|
1497
|
+
exporter_file_id,
|
|
1498
|
+
name: "*",
|
|
1499
|
+
alias: clause.namedBindings.name.text,
|
|
1500
|
+
state: "to_link"
|
|
1501
|
+
});
|
|
1502
|
+
}
|
|
1503
|
+
return imports2;
|
|
1504
|
+
}
|
|
1505
|
+
function extract_dynamic_import(ctx, source_file, node, file_id) {
|
|
1506
|
+
const arg = node.arguments[0];
|
|
1507
|
+
const module_specifier = arg.text;
|
|
1508
|
+
const exporter_file_id = resolve_exporter_file(ctx, source_file, module_specifier);
|
|
1509
|
+
if (err.any(exporter_file_id)) return null;
|
|
1510
|
+
return {
|
|
1511
|
+
importer_file_id: file_id,
|
|
1512
|
+
exporter_file_id,
|
|
1513
|
+
name: "*",
|
|
1514
|
+
alias: "__dynamic_import__",
|
|
1515
|
+
state: "to_link",
|
|
1516
|
+
is_dynamic: true
|
|
1517
|
+
};
|
|
1518
|
+
}
|
|
1519
|
+
function resolve_exporter_file(ctx, source_file, module_specifier) {
|
|
1520
|
+
const resolution = import_typescript4.default.resolveModuleName(module_specifier, source_file.fileName, ctx.program.getCompilerOptions(), import_typescript4.default.sys);
|
|
1521
|
+
if (!resolution.resolvedModule) {
|
|
1522
|
+
return err.new("module_resolution_failed", { module: module_specifier, from: source_file.fileName });
|
|
1523
|
+
}
|
|
1524
|
+
const resolved_path = resolution.resolvedModule.resolvedFileName;
|
|
1525
|
+
const file_path = resolved_path.startsWith(ctx.project_path) ? resolved_path.slice(ctx.project_path.length) : resolved_path;
|
|
1526
|
+
const file = files_exports.by_path(ctx, file_path);
|
|
1527
|
+
if (err.any(file)) return file;
|
|
1528
|
+
if (!file) {
|
|
1529
|
+
return err.new("exporter_file_not_found", { path: file_path, module: module_specifier });
|
|
1530
|
+
}
|
|
1531
|
+
return file.id;
|
|
1532
|
+
}
|
|
1533
|
+
|
|
1534
|
+
// src/update/scan_files/external_imports.ts
|
|
1535
|
+
var import_typescript5 = __toESM(require("typescript"), 1);
|
|
1536
|
+
function is_external_import(ctx, source_file, node) {
|
|
1537
|
+
if (!import_typescript5.default.isImportDeclaration(node) || !node.moduleSpecifier || !import_typescript5.default.isStringLiteral(node.moduleSpecifier)) return false;
|
|
1538
|
+
return is_external_module(ctx, source_file, node.moduleSpecifier.text);
|
|
1539
|
+
}
|
|
1540
|
+
function parse_module_specifier(spec) {
|
|
1541
|
+
let is_builtin = false;
|
|
1542
|
+
let normalized = spec;
|
|
1543
|
+
if (spec.startsWith("node:")) {
|
|
1544
|
+
normalized = spec.slice(5);
|
|
1545
|
+
is_builtin = true;
|
|
1546
|
+
} else {
|
|
1547
|
+
is_builtin = is_builtin_module(spec);
|
|
1548
|
+
}
|
|
1549
|
+
if (normalized.startsWith("@")) {
|
|
1550
|
+
const parts = normalized.split("/");
|
|
1551
|
+
if (parts.length <= 2) {
|
|
1552
|
+
return { pkg: normalized, subpath: null, is_builtin };
|
|
1553
|
+
}
|
|
1554
|
+
const pkg = `${parts[0]}/${parts[1]}`;
|
|
1555
|
+
const subpath = "/" + parts.slice(2).join("/");
|
|
1556
|
+
return { pkg, subpath, is_builtin };
|
|
1557
|
+
} else {
|
|
1558
|
+
const slash_idx = normalized.indexOf("/");
|
|
1559
|
+
if (slash_idx === -1) {
|
|
1560
|
+
return { pkg: normalized, subpath: null, is_builtin };
|
|
1561
|
+
}
|
|
1562
|
+
const pkg = normalized.slice(0, slash_idx);
|
|
1563
|
+
const subpath = normalized.slice(slash_idx);
|
|
1564
|
+
return { pkg, subpath, is_builtin };
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
function extract_external_import_info(node) {
|
|
1568
|
+
const results = [];
|
|
1569
|
+
const module_specifier = node.moduleSpecifier.text;
|
|
1570
|
+
const { pkg, subpath, is_builtin } = parse_module_specifier(module_specifier);
|
|
1571
|
+
const clause = node.importClause;
|
|
1572
|
+
if (!clause) {
|
|
1573
|
+
results.push({
|
|
1574
|
+
package: pkg,
|
|
1575
|
+
subpath,
|
|
1576
|
+
name: null,
|
|
1577
|
+
alias: "__side_effect__",
|
|
1578
|
+
is_builtin
|
|
1579
|
+
});
|
|
1580
|
+
return results;
|
|
1581
|
+
}
|
|
1582
|
+
if (clause.name) {
|
|
1583
|
+
results.push({
|
|
1584
|
+
package: pkg,
|
|
1585
|
+
subpath,
|
|
1586
|
+
name: "default",
|
|
1587
|
+
alias: clause.name.text,
|
|
1588
|
+
is_builtin
|
|
1589
|
+
});
|
|
1590
|
+
}
|
|
1591
|
+
if (clause.namedBindings && import_typescript5.default.isNamedImports(clause.namedBindings)) {
|
|
1592
|
+
for (const element of clause.namedBindings.elements) {
|
|
1593
|
+
results.push({
|
|
1594
|
+
package: pkg,
|
|
1595
|
+
subpath,
|
|
1596
|
+
name: (element.propertyName || element.name).text,
|
|
1597
|
+
alias: element.name.text,
|
|
1598
|
+
is_builtin
|
|
1599
|
+
});
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
if (clause.namedBindings && import_typescript5.default.isNamespaceImport(clause.namedBindings)) {
|
|
1603
|
+
results.push({
|
|
1604
|
+
package: pkg,
|
|
1605
|
+
subpath,
|
|
1606
|
+
name: "*",
|
|
1607
|
+
alias: clause.namedBindings.name.text,
|
|
1608
|
+
is_builtin
|
|
1609
|
+
});
|
|
1610
|
+
}
|
|
1611
|
+
return results;
|
|
1612
|
+
}
|
|
1613
|
+
function extract_external_import(ctx, node, file_id) {
|
|
1614
|
+
const infos = extract_external_import_info(node);
|
|
1615
|
+
const external_imports2 = [];
|
|
1616
|
+
for (const info of infos) {
|
|
1617
|
+
const dep_meta = Object.values(ctx.dependencies).find((dep) => info.package.startsWith(dep.name));
|
|
1618
|
+
const dependency = external_dependencies_exports.get_or_create(ctx, {
|
|
1619
|
+
package: info.package,
|
|
1620
|
+
subpath: info.subpath,
|
|
1621
|
+
name: info.name,
|
|
1622
|
+
version: dep_meta?.version,
|
|
1623
|
+
github_repo: dep_meta?.github_repo,
|
|
1624
|
+
is_builtin: info.is_builtin,
|
|
1625
|
+
state: "to_describe"
|
|
1626
|
+
});
|
|
1627
|
+
if (err.any(dependency)) return dependency;
|
|
1628
|
+
external_imports2.push({ file_id, external_dependency_id: dependency.id, alias: info.alias, is_dynamic: false });
|
|
1629
|
+
}
|
|
1630
|
+
return external_imports2;
|
|
1631
|
+
}
|
|
1632
|
+
function extract_external_dynamic_import(ctx, node, file_id) {
|
|
1633
|
+
const arg = node.arguments[0];
|
|
1634
|
+
const module_specifier = arg.text;
|
|
1635
|
+
const { pkg, subpath, is_builtin } = parse_module_specifier(module_specifier);
|
|
1636
|
+
const dep_meta = Object.values(ctx.dependencies).find((dep) => pkg.startsWith(dep.name));
|
|
1637
|
+
const dependency = external_dependencies_exports.get_or_create(ctx, {
|
|
1638
|
+
package: pkg,
|
|
1639
|
+
subpath,
|
|
1640
|
+
name: "*",
|
|
1641
|
+
version: dep_meta?.version,
|
|
1642
|
+
github_repo: dep_meta?.github_repo,
|
|
1643
|
+
is_builtin,
|
|
1644
|
+
state: "to_describe"
|
|
1645
|
+
});
|
|
1646
|
+
if (err.any(dependency)) return dependency;
|
|
1647
|
+
return { file_id, external_dependency_id: dependency.id, alias: "__dynamic_import__", is_dynamic: true };
|
|
1648
|
+
}
|
|
1649
|
+
|
|
1650
|
+
// src/update/scan_files/types.ts
|
|
1651
|
+
var import_typescript6 = __toESM(require("typescript"), 1);
|
|
1652
|
+
function is_type(node) {
|
|
1653
|
+
return import_typescript6.default.isTypeAliasDeclaration(node) || import_typescript6.default.isInterfaceDeclaration(node) || import_typescript6.default.isEnumDeclaration(node);
|
|
1654
|
+
}
|
|
1655
|
+
function extract_type_symbol(node, file_id, source_file) {
|
|
1656
|
+
const meta2 = import_typescript6.default.isEnumDeclaration(node) ? extract_enum_meta(node, source_file) : import_typescript6.default.isInterfaceDeclaration(node) ? extract_interface_meta(node, source_file) : extract_type_alias_meta(node, source_file);
|
|
1657
|
+
return {
|
|
1658
|
+
file_id,
|
|
1659
|
+
type: "type",
|
|
1660
|
+
name: node.name.text,
|
|
1661
|
+
text: node.getText(source_file),
|
|
1662
|
+
meta: JSON.stringify(meta2),
|
|
1663
|
+
is_exported: has_export_modifier(node),
|
|
1664
|
+
state: "to_link"
|
|
1665
|
+
};
|
|
1666
|
+
}
|
|
1667
|
+
function extract_enum_meta(node, source_file) {
|
|
1668
|
+
const enum_values = {};
|
|
1669
|
+
for (const member of node.members) {
|
|
1670
|
+
if (import_typescript6.default.isIdentifier(member.name) || import_typescript6.default.isStringLiteral(member.name)) {
|
|
1671
|
+
const name = member.name.text;
|
|
1672
|
+
const value = member.initializer ? member.initializer.getText(source_file) : "auto";
|
|
1673
|
+
enum_values[name] = value;
|
|
1674
|
+
}
|
|
1675
|
+
}
|
|
1676
|
+
return {
|
|
1677
|
+
kind: "enum",
|
|
1678
|
+
type_parameters: [],
|
|
1679
|
+
extends: [],
|
|
1680
|
+
members: [],
|
|
1681
|
+
enum_values,
|
|
1682
|
+
decorators: extract_decorators(node, source_file),
|
|
1683
|
+
comment: extract_jsdoc_comment(node, source_file)
|
|
1684
|
+
};
|
|
1685
|
+
}
|
|
1686
|
+
function extract_interface_meta(node, source_file) {
|
|
1687
|
+
const members = [];
|
|
1688
|
+
for (const member of node.members) {
|
|
1689
|
+
if (import_typescript6.default.isPropertySignature(member) && import_typescript6.default.isIdentifier(member.name)) {
|
|
1690
|
+
members.push({
|
|
1691
|
+
name: member.name.text,
|
|
1692
|
+
type: member.type ? member.type.getText(source_file) : "any",
|
|
1693
|
+
optional: !!member.questionToken
|
|
1694
|
+
});
|
|
1695
|
+
} else if (import_typescript6.default.isMethodSignature(member) && import_typescript6.default.isIdentifier(member.name)) {
|
|
1696
|
+
const params = member.parameters.map((p) => {
|
|
1697
|
+
const param_type = p.type ? p.type.getText(source_file) : "any";
|
|
1698
|
+
return `${p.name.getText(source_file)}: ${param_type}`;
|
|
1699
|
+
}).join(", ");
|
|
1700
|
+
const return_type = member.type ? member.type.getText(source_file) : "void";
|
|
1701
|
+
members.push({
|
|
1702
|
+
name: member.name.text,
|
|
1703
|
+
type: `(${params}) => ${return_type}`,
|
|
1704
|
+
optional: !!member.questionToken
|
|
1705
|
+
});
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
const extends_clauses = node.heritageClauses?.filter((c) => c.token === import_typescript6.default.SyntaxKind.ExtendsKeyword).flatMap((c) => c.types.map((t) => t.expression.getText(source_file))) || [];
|
|
1709
|
+
return {
|
|
1710
|
+
kind: "interface",
|
|
1711
|
+
type_parameters: extract_type_parameters(node, source_file),
|
|
1712
|
+
extends: extends_clauses,
|
|
1713
|
+
members,
|
|
1714
|
+
enum_values: {},
|
|
1715
|
+
decorators: extract_decorators(node, source_file),
|
|
1716
|
+
comment: extract_jsdoc_comment(node, source_file)
|
|
1717
|
+
};
|
|
1718
|
+
}
|
|
1719
|
+
function extract_type_alias_meta(node, source_file) {
|
|
1720
|
+
return {
|
|
1721
|
+
kind: "type_alias",
|
|
1722
|
+
type_parameters: extract_type_parameters(node, source_file),
|
|
1723
|
+
extends: [],
|
|
1724
|
+
members: [],
|
|
1725
|
+
enum_values: {},
|
|
1726
|
+
decorators: extract_decorators(node, source_file),
|
|
1727
|
+
comment: extract_jsdoc_comment(node, source_file)
|
|
1728
|
+
};
|
|
1729
|
+
}
|
|
1730
|
+
|
|
1731
|
+
// src/update/scan_files/functions.ts
|
|
1732
|
+
var import_typescript7 = __toESM(require("typescript"), 1);
|
|
1733
|
+
function is_function(node) {
|
|
1734
|
+
if (!import_typescript7.default.isFunctionDeclaration(node)) return false;
|
|
1735
|
+
return !!node.name || has_default_modifier(node);
|
|
1736
|
+
}
|
|
1737
|
+
function extract_function_symbol(node, file_id, source_file) {
|
|
1738
|
+
const is_default = has_default_modifier(node);
|
|
1739
|
+
const name = is_default ? "default" : node.name?.text || "default";
|
|
1740
|
+
const meta2 = {
|
|
1741
|
+
kind: "function_declaration",
|
|
1742
|
+
parameters: extract_parameters(node, source_file),
|
|
1743
|
+
return_type: node.type ? node.type.getText(source_file) : null,
|
|
1744
|
+
type_parameters: extract_type_parameters(node, source_file),
|
|
1745
|
+
modifiers: {
|
|
1746
|
+
async: !!node.modifiers?.some((m) => m.kind === import_typescript7.default.SyntaxKind.AsyncKeyword),
|
|
1747
|
+
generator: !!node.asteriskToken
|
|
1748
|
+
},
|
|
1749
|
+
decorators: extract_decorators(node, source_file),
|
|
1750
|
+
comment: extract_jsdoc_comment(node, source_file)
|
|
1751
|
+
};
|
|
1752
|
+
return {
|
|
1753
|
+
file_id,
|
|
1754
|
+
type: "function",
|
|
1755
|
+
name,
|
|
1756
|
+
text: node.getText(source_file),
|
|
1757
|
+
meta: JSON.stringify(meta2),
|
|
1758
|
+
is_exported: has_export_modifier(node),
|
|
1759
|
+
state: "to_link"
|
|
1760
|
+
};
|
|
1761
|
+
}
|
|
1762
|
+
|
|
1763
|
+
// src/update/scan_files/variables.ts
|
|
1764
|
+
var import_typescript8 = __toESM(require("typescript"), 1);
|
|
1765
|
+
function is_function_declaration(declaration) {
|
|
1766
|
+
return !!(declaration.initializer && (import_typescript8.default.isArrowFunction(declaration.initializer) || import_typescript8.default.isFunctionExpression(declaration.initializer)));
|
|
1767
|
+
}
|
|
1768
|
+
function extract_variable_symbol(node, file_id, source_file) {
|
|
1769
|
+
const symbols4 = [];
|
|
1770
|
+
const is_exported = has_export_modifier(node);
|
|
1771
|
+
const declaration_kind = node.declarationList.flags & import_typescript8.default.NodeFlags.Const ? "const" : node.declarationList.flags & import_typescript8.default.NodeFlags.Let ? "let" : "var";
|
|
1772
|
+
for (const declaration of node.declarationList.declarations) {
|
|
1773
|
+
if (!import_typescript8.default.isIdentifier(declaration.name)) continue;
|
|
1774
|
+
if (is_function_declaration(declaration)) {
|
|
1775
|
+
const func_node = declaration.initializer;
|
|
1776
|
+
const meta2 = {
|
|
1777
|
+
kind: import_typescript8.default.isArrowFunction(func_node) ? "arrow_function" : "function_expression",
|
|
1778
|
+
parameters: extract_parameters(func_node, source_file),
|
|
1779
|
+
return_type: func_node.type ? func_node.type.getText(source_file) : null,
|
|
1780
|
+
type_parameters: extract_type_parameters(func_node, source_file),
|
|
1781
|
+
modifiers: {
|
|
1782
|
+
async: !!func_node.modifiers?.some((m) => m.kind === import_typescript8.default.SyntaxKind.AsyncKeyword),
|
|
1783
|
+
generator: import_typescript8.default.isFunctionExpression(func_node) && !!func_node.asteriskToken
|
|
1784
|
+
},
|
|
1785
|
+
decorators: extract_decorators(node, source_file),
|
|
1786
|
+
comment: extract_jsdoc_comment(node, source_file)
|
|
1787
|
+
};
|
|
1788
|
+
symbols4.push({
|
|
1789
|
+
file_id,
|
|
1790
|
+
type: "function",
|
|
1791
|
+
name: declaration.name.text,
|
|
1792
|
+
text: node.getText(source_file),
|
|
1793
|
+
meta: JSON.stringify(meta2),
|
|
1794
|
+
is_exported,
|
|
1795
|
+
state: "to_link"
|
|
1796
|
+
});
|
|
1797
|
+
} else {
|
|
1798
|
+
const meta2 = {
|
|
1799
|
+
declaration_kind,
|
|
1800
|
+
type: declaration.type ? declaration.type.getText(source_file) : null,
|
|
1801
|
+
value: declaration.initializer ? declaration.initializer.getText(source_file) : null,
|
|
1802
|
+
decorators: extract_decorators(node, source_file),
|
|
1803
|
+
comment: extract_jsdoc_comment(node, source_file)
|
|
1804
|
+
};
|
|
1805
|
+
symbols4.push({
|
|
1806
|
+
file_id,
|
|
1807
|
+
type: "variable",
|
|
1808
|
+
name: declaration.name.text,
|
|
1809
|
+
text: node.getText(source_file),
|
|
1810
|
+
meta: JSON.stringify(meta2),
|
|
1811
|
+
is_exported,
|
|
1812
|
+
state: "to_link"
|
|
1813
|
+
});
|
|
1814
|
+
}
|
|
1815
|
+
}
|
|
1816
|
+
return symbols4;
|
|
1817
|
+
}
|
|
1818
|
+
|
|
1819
|
+
// src/update/scan_files/classes.ts
|
|
1820
|
+
var import_typescript9 = __toESM(require("typescript"), 1);
|
|
1821
|
+
function is_class(node) {
|
|
1822
|
+
if (!import_typescript9.default.isClassDeclaration(node)) return false;
|
|
1823
|
+
return !!node.name || has_default_modifier(node);
|
|
1824
|
+
}
|
|
1825
|
+
function extract_class_symbol(node, file_id, source_file) {
|
|
1826
|
+
const is_default = has_default_modifier(node);
|
|
1827
|
+
const name = is_default ? "default" : node.name?.text || "default";
|
|
1828
|
+
const meta2 = {
|
|
1829
|
+
extends: node.heritageClauses?.find((c) => c.token === import_typescript9.default.SyntaxKind.ExtendsKeyword)?.types[0]?.expression.getText(source_file) || null,
|
|
1830
|
+
implements: node.heritageClauses?.find((c) => c.token === import_typescript9.default.SyntaxKind.ImplementsKeyword)?.types.map((t) => t.expression.getText(source_file)) || [],
|
|
1831
|
+
type_parameters: extract_type_parameters(node, source_file),
|
|
1832
|
+
modifiers: {
|
|
1833
|
+
abstract: !!node.modifiers?.some((m) => m.kind === import_typescript9.default.SyntaxKind.AbstractKeyword)
|
|
1834
|
+
},
|
|
1835
|
+
decorators: extract_decorators(node, source_file),
|
|
1836
|
+
comment: extract_jsdoc_comment(node, source_file)
|
|
1837
|
+
};
|
|
1838
|
+
return {
|
|
1839
|
+
file_id,
|
|
1840
|
+
type: "class",
|
|
1841
|
+
name,
|
|
1842
|
+
text: node.getText(source_file),
|
|
1843
|
+
meta: JSON.stringify(meta2),
|
|
1844
|
+
is_exported: has_export_modifier(node),
|
|
1845
|
+
state: "to_link"
|
|
1846
|
+
};
|
|
1847
|
+
}
|
|
1848
|
+
function get_visibility(member) {
|
|
1849
|
+
if (!import_typescript9.default.canHaveModifiers(member)) return null;
|
|
1850
|
+
const modifiers = import_typescript9.default.getModifiers(member);
|
|
1851
|
+
if (!modifiers) return null;
|
|
1852
|
+
if (modifiers.some((m) => m.kind === import_typescript9.default.SyntaxKind.PrivateKeyword)) return "private";
|
|
1853
|
+
if (modifiers.some((m) => m.kind === import_typescript9.default.SyntaxKind.ProtectedKeyword)) return "protected";
|
|
1854
|
+
if (modifiers.some((m) => m.kind === import_typescript9.default.SyntaxKind.PublicKeyword)) return "public";
|
|
1855
|
+
return null;
|
|
1856
|
+
}
|
|
1857
|
+
function extract_class_fields(node, file_id, source_file) {
|
|
1858
|
+
const symbols4 = [];
|
|
1859
|
+
if (!node.name) return symbols4;
|
|
1860
|
+
const class_name = node.name.text;
|
|
1861
|
+
node.members.forEach((member) => {
|
|
1862
|
+
if (import_typescript9.default.isMethodDeclaration(member) && member.name && import_typescript9.default.isIdentifier(member.name)) {
|
|
1863
|
+
const meta2 = {
|
|
1864
|
+
class_name,
|
|
1865
|
+
visibility: get_visibility(member),
|
|
1866
|
+
parameters: extract_parameters(member, source_file),
|
|
1867
|
+
return_type: member.type ? member.type.getText(source_file) : null,
|
|
1868
|
+
type_parameters: extract_type_parameters(member, source_file),
|
|
1869
|
+
modifiers: {
|
|
1870
|
+
static: !!member.modifiers?.some((m) => m.kind === import_typescript9.default.SyntaxKind.StaticKeyword),
|
|
1871
|
+
async: !!member.modifiers?.some((m) => m.kind === import_typescript9.default.SyntaxKind.AsyncKeyword),
|
|
1872
|
+
abstract: !!member.modifiers?.some((m) => m.kind === import_typescript9.default.SyntaxKind.AbstractKeyword),
|
|
1873
|
+
readonly: !!member.modifiers?.some((m) => m.kind === import_typescript9.default.SyntaxKind.ReadonlyKeyword)
|
|
1874
|
+
},
|
|
1875
|
+
decorators: extract_decorators(member, source_file),
|
|
1876
|
+
comment: extract_jsdoc_comment(member, source_file)
|
|
1877
|
+
};
|
|
1878
|
+
symbols4.push({
|
|
1879
|
+
file_id,
|
|
1880
|
+
type: "class_method",
|
|
1881
|
+
name: `${class_name}.${member.name.text}`,
|
|
1882
|
+
text: member.getText(source_file),
|
|
1883
|
+
meta: JSON.stringify(meta2),
|
|
1884
|
+
is_exported: false,
|
|
1885
|
+
state: "to_link"
|
|
1886
|
+
});
|
|
1887
|
+
}
|
|
1888
|
+
if (import_typescript9.default.isPropertyDeclaration(member) && member.name && import_typescript9.default.isIdentifier(member.name)) {
|
|
1889
|
+
const meta2 = {
|
|
1890
|
+
class_name,
|
|
1891
|
+
visibility: get_visibility(member),
|
|
1892
|
+
type: member.type ? member.type.getText(source_file) : null,
|
|
1893
|
+
optional: !!member.questionToken,
|
|
1894
|
+
modifiers: {
|
|
1895
|
+
static: !!member.modifiers?.some((m) => m.kind === import_typescript9.default.SyntaxKind.StaticKeyword),
|
|
1896
|
+
readonly: !!member.modifiers?.some((m) => m.kind === import_typescript9.default.SyntaxKind.ReadonlyKeyword),
|
|
1897
|
+
abstract: !!member.modifiers?.some((m) => m.kind === import_typescript9.default.SyntaxKind.AbstractKeyword)
|
|
1898
|
+
},
|
|
1899
|
+
decorators: extract_decorators(member, source_file),
|
|
1900
|
+
comment: extract_jsdoc_comment(member, source_file)
|
|
1901
|
+
};
|
|
1902
|
+
symbols4.push({
|
|
1903
|
+
file_id,
|
|
1904
|
+
type: "class_property",
|
|
1905
|
+
name: `${class_name}.${member.name.text}`,
|
|
1906
|
+
text: member.getText(source_file),
|
|
1907
|
+
meta: JSON.stringify(meta2),
|
|
1908
|
+
is_exported: false,
|
|
1909
|
+
state: "to_link"
|
|
1910
|
+
});
|
|
1911
|
+
}
|
|
1912
|
+
});
|
|
1913
|
+
return symbols4;
|
|
1914
|
+
}
|
|
1915
|
+
|
|
1916
|
+
// src/update/scan_files/scan_files.ts
|
|
1917
|
+
async function scan_files(ctx) {
|
|
1918
|
+
const files5 = err.or_throw(files_exports.by_state(ctx, "to_scan"));
|
|
1919
|
+
for (const file of files5) {
|
|
1920
|
+
const res = scan_file(ctx, file);
|
|
1921
|
+
if (err.any(res)) {
|
|
1922
|
+
err.or_throw(files_exports.update(ctx, file.id, { error: String(res) }));
|
|
1923
|
+
} else {
|
|
1924
|
+
err.or_throw(files_exports.update(ctx, file.id, { state: "to_describe", error: null }));
|
|
1925
|
+
}
|
|
1926
|
+
}
|
|
1927
|
+
}
|
|
1928
|
+
function scan_file(ctx, file) {
|
|
1929
|
+
return err.pipe(
|
|
1930
|
+
() => symbols_exports.del_by_file(ctx, file.id),
|
|
1931
|
+
() => imports_exports.del_by_importer_file(ctx, file.id),
|
|
1932
|
+
() => external_imports_exports.del_by_file(ctx, file.id),
|
|
1933
|
+
() => get_source_file(ctx, file.path),
|
|
1934
|
+
(source_file) => parse_file(ctx, source_file, file.id),
|
|
1935
|
+
({ imports: imports2, symbols: symbols4, external_imports: external_imports2 }) => err.pipe(
|
|
1936
|
+
() => external_imports2.length && external_imports_exports.insert_many(ctx, external_imports2),
|
|
1937
|
+
() => imports2.length && imports_exports.insert_many(ctx, imports2),
|
|
1938
|
+
() => symbols4.length && symbols_exports.insert_many(ctx, symbols4)
|
|
1939
|
+
)
|
|
1940
|
+
);
|
|
1941
|
+
}
|
|
1942
|
+
function get_source_file(ctx, file_path) {
|
|
1943
|
+
const source_file = ctx.program.getSourceFile(import_path5.default.join(ctx.project_path, file_path));
|
|
1944
|
+
if (!source_file) return err.new("file_not_found", { path: file_path });
|
|
1945
|
+
return source_file;
|
|
1946
|
+
}
|
|
1947
|
+
function parse_file(ctx, source_file, file_id) {
|
|
1948
|
+
const imports2 = [];
|
|
1949
|
+
const symbols4 = [];
|
|
1950
|
+
const external_imports2 = [];
|
|
1951
|
+
function find_dynamic_imports(node) {
|
|
1952
|
+
if (is_dynamic_import(node)) {
|
|
1953
|
+
const arg = node.arguments[0];
|
|
1954
|
+
if (is_external_module(ctx, source_file, arg.text)) {
|
|
1955
|
+
const result = extract_external_dynamic_import(ctx, node, file_id);
|
|
1956
|
+
if (err.any(result)) return result;
|
|
1957
|
+
external_imports2.push(result);
|
|
1958
|
+
} else {
|
|
1959
|
+
const result = extract_dynamic_import(ctx, source_file, node, file_id);
|
|
1960
|
+
if (result) imports2.push(result);
|
|
1961
|
+
}
|
|
1962
|
+
}
|
|
1963
|
+
import_typescript10.default.forEachChild(node, find_dynamic_imports);
|
|
1964
|
+
}
|
|
1965
|
+
let error = void 0;
|
|
1966
|
+
import_typescript10.default.forEachChild(source_file, (statement) => {
|
|
1967
|
+
if (error) return;
|
|
1968
|
+
const res = parse_node(ctx, source_file, statement, file_id);
|
|
1969
|
+
if (err.any(res)) {
|
|
1970
|
+
error = res;
|
|
1971
|
+
return;
|
|
1972
|
+
}
|
|
1973
|
+
imports2.push(...res.imports);
|
|
1974
|
+
symbols4.push(...res.symbols);
|
|
1975
|
+
external_imports2.push(...res.external_imports);
|
|
1976
|
+
error = find_dynamic_imports(statement);
|
|
1977
|
+
});
|
|
1978
|
+
if (error) return error;
|
|
1979
|
+
return { imports: imports2, symbols: symbols4, external_imports: external_imports2 };
|
|
1980
|
+
}
|
|
1981
|
+
function parse_node(ctx, source_file, node, file_id) {
|
|
1982
|
+
const imports2 = [];
|
|
1983
|
+
const symbols4 = [];
|
|
1984
|
+
const external_imports2 = [];
|
|
1985
|
+
if (is_external_import(ctx, source_file, node)) {
|
|
1986
|
+
const result = extract_external_import(ctx, node, file_id);
|
|
1987
|
+
if (err.any(result)) return result;
|
|
1988
|
+
external_imports2.push(...result);
|
|
1989
|
+
} else if (is_import(ctx, source_file, node)) {
|
|
1990
|
+
imports2.push(...extract_import(ctx, source_file, node, file_id));
|
|
1991
|
+
} else if (import_typescript10.default.isExportAssignment(node) && !node.isExportEquals) {
|
|
1992
|
+
symbols4.push({
|
|
1993
|
+
file_id,
|
|
1994
|
+
type: "variable",
|
|
1995
|
+
name: "default",
|
|
1996
|
+
text: node.getText(source_file),
|
|
1997
|
+
meta: JSON.stringify({
|
|
1998
|
+
declaration_kind: "const",
|
|
1999
|
+
type: null,
|
|
2000
|
+
value: node.expression.getText(source_file),
|
|
2001
|
+
decorators: [],
|
|
2002
|
+
comment: null
|
|
2003
|
+
}),
|
|
2004
|
+
is_exported: true,
|
|
2005
|
+
state: "to_link"
|
|
2006
|
+
});
|
|
2007
|
+
} else if (import_typescript10.default.isExportDeclaration(node) && node.exportClause && import_typescript10.default.isNamedExports(node.exportClause) && !node.moduleSpecifier) {
|
|
2008
|
+
for (const element of node.exportClause.elements) {
|
|
2009
|
+
if (element.name.text === "default") {
|
|
2010
|
+
const localName = element.propertyName?.text || element.name.text;
|
|
2011
|
+
symbols4.push({
|
|
2012
|
+
file_id,
|
|
2013
|
+
type: "variable",
|
|
2014
|
+
name: "default",
|
|
2015
|
+
text: node.getText(source_file),
|
|
2016
|
+
meta: JSON.stringify({ declaration_kind: "const", type: null, value: localName, is_reexport: true, decorators: [], comment: null }),
|
|
2017
|
+
is_exported: true,
|
|
2018
|
+
state: "to_link"
|
|
2019
|
+
});
|
|
2020
|
+
}
|
|
2021
|
+
}
|
|
2022
|
+
} else if (is_type(node)) {
|
|
2023
|
+
symbols4.push(extract_type_symbol(node, file_id, source_file));
|
|
2024
|
+
} else if (is_function(node)) {
|
|
2025
|
+
symbols4.push(extract_function_symbol(node, file_id, source_file));
|
|
2026
|
+
} else if (import_typescript10.default.isVariableStatement(node)) {
|
|
2027
|
+
symbols4.push(...extract_variable_symbol(node, file_id, source_file));
|
|
2028
|
+
} else if (is_class(node)) {
|
|
2029
|
+
symbols4.push(extract_class_symbol(node, file_id, source_file));
|
|
2030
|
+
symbols4.push(...extract_class_fields(node, file_id, source_file));
|
|
2031
|
+
}
|
|
2032
|
+
return { imports: imports2, symbols: symbols4, external_imports: external_imports2 };
|
|
2033
|
+
}
|
|
2034
|
+
|
|
2035
|
+
// src/update/link_imports.ts
|
|
2036
|
+
async function link_imports(ctx) {
|
|
2037
|
+
const imports2 = err.or_throw(imports_exports.by_state(ctx, "to_link"));
|
|
2038
|
+
let i = 0;
|
|
2039
|
+
for (const import_ of imports2) {
|
|
2040
|
+
const res = link_import(ctx, import_);
|
|
2041
|
+
if (err.any(res)) err.or_throw(imports_exports.update(ctx, import_.id, { error: String(res) }));
|
|
2042
|
+
}
|
|
2043
|
+
}
|
|
2044
|
+
function link_import(ctx, import_) {
|
|
2045
|
+
if (import_.name === "*") {
|
|
2046
|
+
return imports_exports.update(ctx, import_.id, { state: "ready", error: null });
|
|
2047
|
+
}
|
|
2048
|
+
const symbol = symbols_exports.by_file_and_name(ctx, { file_id: import_.exporter_file_id, name: import_.name, is_exported: true });
|
|
2049
|
+
if (err.any(symbol)) return symbol;
|
|
2050
|
+
if (!symbol) return err.new("exported_symbol_not_found", { name: import_.name, file_id: import_.exporter_file_id });
|
|
2051
|
+
return imports_exports.update(ctx, import_.id, { symbol_id: symbol.id, state: "ready", error: null });
|
|
2052
|
+
}
|
|
2053
|
+
|
|
2054
|
+
// src/update/link_symbols.ts
|
|
2055
|
+
var import_path6 = __toESM(require("path"), 1);
|
|
2056
|
+
var import_typescript11 = __toESM(require("typescript"), 1);
|
|
2057
|
+
async function link_symbols(ctx) {
|
|
2058
|
+
const symbols4 = err.or_throw(symbols_exports.by_state(ctx, "to_link"));
|
|
2059
|
+
let i = 0;
|
|
2060
|
+
for (const symbol of symbols4) {
|
|
2061
|
+
const res = link_symbol(ctx, symbol);
|
|
2062
|
+
if (err.any(res)) {
|
|
2063
|
+
err.or_throw(symbols_exports.update(ctx, symbol.id, { error: String(res) }));
|
|
2064
|
+
}
|
|
2065
|
+
}
|
|
2066
|
+
}
|
|
2067
|
+
function link_symbol(ctx, symbol) {
|
|
2068
|
+
if (!symbol.text) return err.new("symbol_missing_text", { symbol_id: symbol.id, name: symbol.name });
|
|
2069
|
+
const resolutions = find_symbol_references(ctx, symbol);
|
|
2070
|
+
if (err.any(resolutions)) return resolutions;
|
|
2071
|
+
for (const resolution of resolutions) {
|
|
2072
|
+
if (resolution.type === "internal") create_internal_link(ctx, symbol, resolution);
|
|
2073
|
+
if (resolution.type === "external") create_external_link(ctx, symbol, resolution);
|
|
2074
|
+
}
|
|
2075
|
+
return symbols_exports.update(ctx, symbol.id, { state: "to_describe", error: null });
|
|
2076
|
+
}
|
|
2077
|
+
function find_symbol_references(ctx, symbol) {
|
|
2078
|
+
const file = files_exports.by_id(ctx, symbol.file_id);
|
|
2079
|
+
if (err.any(file)) return file;
|
|
2080
|
+
if (!file) return err.new("file_not_found", { path: `file_id=${symbol.file_id}` });
|
|
2081
|
+
const file_path = import_path6.default.join(ctx.project_path, file.path);
|
|
2082
|
+
const source_file = ctx.program.getSourceFile(file_path);
|
|
2083
|
+
if (!source_file) return err.new("file_not_found", { path: file_path });
|
|
2084
|
+
const symbol_node = find_symbol_node(source_file, symbol);
|
|
2085
|
+
if (!symbol_node) return err.new("symbol_node_not_found", { symbol_id: symbol.id, name: symbol.name, file_path: file.path });
|
|
2086
|
+
const type_checker = ctx.program.getTypeChecker();
|
|
2087
|
+
const resolutions = [];
|
|
2088
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2089
|
+
function visit(node) {
|
|
2090
|
+
const ts_symbol = type_checker.getSymbolAtLocation(node);
|
|
2091
|
+
if (!import_typescript11.default.isIdentifier(node) || is_declaration(node.parent, node) || !ts_symbol) {
|
|
2092
|
+
import_typescript11.default.forEachChild(node, visit);
|
|
2093
|
+
return;
|
|
2094
|
+
}
|
|
2095
|
+
const resolution = resolve_ts_symbol(ctx, type_checker, ts_symbol, symbol);
|
|
2096
|
+
if (resolution) {
|
|
2097
|
+
const key = `${resolution.type}:${resolution.type === "internal" ? resolution.symbol_id : resolution.external_import_id}`;
|
|
2098
|
+
if (!seen.has(key)) {
|
|
2099
|
+
seen.add(key);
|
|
2100
|
+
resolutions.push(resolution);
|
|
2101
|
+
}
|
|
2102
|
+
}
|
|
2103
|
+
import_typescript11.default.forEachChild(node, visit);
|
|
2104
|
+
}
|
|
2105
|
+
visit(symbol_node);
|
|
2106
|
+
return resolutions;
|
|
2107
|
+
}
|
|
2108
|
+
function resolve_ts_symbol(ctx, type_checker, ts_symbol, from_symbol) {
|
|
2109
|
+
let symbol_to_use = ts_symbol;
|
|
2110
|
+
if (ts_symbol.flags & import_typescript11.default.SymbolFlags.Alias) {
|
|
2111
|
+
symbol_to_use = type_checker.getAliasedSymbol(ts_symbol) || symbol_to_use;
|
|
2112
|
+
}
|
|
2113
|
+
const declarations = symbol_to_use.getDeclarations();
|
|
2114
|
+
if (!declarations || declarations.length === 0 || !declarations[0]) return null;
|
|
2115
|
+
const declaration_source_file = declarations[0].getSourceFile();
|
|
2116
|
+
if (declaration_source_file.fileName.includes("/lib.") && !declaration_source_file.fileName.includes("node_modules")) {
|
|
2117
|
+
return null;
|
|
2118
|
+
}
|
|
2119
|
+
if (!declaration_source_file.fileName.startsWith(ctx.project_path) || declaration_source_file.fileName.includes("node_modules")) {
|
|
2120
|
+
const external_import_links = external_imports_exports.by_file(ctx, from_symbol.file_id);
|
|
2121
|
+
if (err.any(external_import_links)) return null;
|
|
2122
|
+
for (const ext_import of external_import_links) {
|
|
2123
|
+
const ext_dep = external_dependencies_exports.by_id(ctx, ext_import.external_dependency_id);
|
|
2124
|
+
if (err.any(ext_dep) || !ext_dep) continue;
|
|
2125
|
+
if (ext_import.alias === symbol_to_use.name || ext_dep.name === symbol_to_use.name) {
|
|
2126
|
+
return { type: "external", external_import_id: ext_import.id };
|
|
2127
|
+
}
|
|
2128
|
+
}
|
|
2129
|
+
return null;
|
|
2130
|
+
}
|
|
2131
|
+
let file_path = declaration_source_file.fileName;
|
|
2132
|
+
if (file_path.startsWith(ctx.project_path)) {
|
|
2133
|
+
file_path = file_path.substring(ctx.project_path.length);
|
|
2134
|
+
}
|
|
2135
|
+
const file = files_exports.by_path(ctx, file_path);
|
|
2136
|
+
if (err.any(file) || !file) return null;
|
|
2137
|
+
if (file.id === from_symbol.file_id) {
|
|
2138
|
+
const file_symbols2 = symbols_exports.by_file(ctx, file.id);
|
|
2139
|
+
if (err.any(file_symbols2)) return null;
|
|
2140
|
+
for (const file_symbol of file_symbols2) {
|
|
2141
|
+
if (file_symbol.name === symbol_to_use.name && file_symbol.id !== from_symbol.id) {
|
|
2142
|
+
return { type: "internal", symbol_id: file_symbol.id, file_id: file.id };
|
|
2143
|
+
}
|
|
2144
|
+
}
|
|
2145
|
+
return null;
|
|
2146
|
+
}
|
|
2147
|
+
const file_symbols = symbols_exports.by_file(ctx, file.id);
|
|
2148
|
+
if (err.any(file_symbols)) return null;
|
|
2149
|
+
for (const file_symbol of file_symbols) {
|
|
2150
|
+
if (file_symbol.name === symbol_to_use.name) {
|
|
2151
|
+
return { type: "internal", symbol_id: file_symbol.id, file_id: file.id };
|
|
2152
|
+
}
|
|
2153
|
+
}
|
|
2154
|
+
return null;
|
|
2155
|
+
}
|
|
2156
|
+
function find_symbol_node(source_file, symbol) {
|
|
2157
|
+
let result;
|
|
2158
|
+
function visit(node) {
|
|
2159
|
+
if (result) return;
|
|
2160
|
+
if (matches_symbol(node, symbol)) {
|
|
2161
|
+
result = node;
|
|
2162
|
+
return;
|
|
2163
|
+
}
|
|
2164
|
+
import_typescript11.default.forEachChild(node, visit);
|
|
2165
|
+
}
|
|
2166
|
+
visit(source_file);
|
|
2167
|
+
return result;
|
|
2168
|
+
}
|
|
2169
|
+
function matches_symbol(node, symbol) {
|
|
2170
|
+
if (symbol.name === "default") {
|
|
2171
|
+
if (symbol.type === "function" && import_typescript11.default.isFunctionDeclaration(node)) return has_default_modifier(node);
|
|
2172
|
+
if (symbol.type === "class" && import_typescript11.default.isClassDeclaration(node)) return has_default_modifier(node);
|
|
2173
|
+
if (symbol.type === "variable") {
|
|
2174
|
+
if (import_typescript11.default.isExportAssignment(node) && !node.isExportEquals) return true;
|
|
2175
|
+
if (import_typescript11.default.isExportDeclaration(node) && node.exportClause && import_typescript11.default.isNamedExports(node.exportClause)) {
|
|
2176
|
+
return node.exportClause.elements.some((element) => element.name.text === "default");
|
|
2177
|
+
}
|
|
2178
|
+
}
|
|
2179
|
+
}
|
|
2180
|
+
if (symbol.type === "function") {
|
|
2181
|
+
if (import_typescript11.default.isVariableStatement(node)) {
|
|
2182
|
+
const declarations = node.declarationList.declarations;
|
|
2183
|
+
for (const decl of declarations) {
|
|
2184
|
+
if (import_typescript11.default.isIdentifier(decl.name) && decl.name.text === symbol.name) {
|
|
2185
|
+
const initializer = decl.initializer;
|
|
2186
|
+
if (initializer && (import_typescript11.default.isArrowFunction(initializer) || import_typescript11.default.isFunctionExpression(initializer))) {
|
|
2187
|
+
return true;
|
|
2188
|
+
}
|
|
2189
|
+
}
|
|
2190
|
+
}
|
|
2191
|
+
return false;
|
|
2192
|
+
}
|
|
2193
|
+
if (import_typescript11.default.isFunctionDeclaration(node)) {
|
|
2194
|
+
return get_node_name(node) === symbol.name;
|
|
2195
|
+
}
|
|
2196
|
+
return false;
|
|
2197
|
+
}
|
|
2198
|
+
if (symbol.type === "class") {
|
|
2199
|
+
if (!import_typescript11.default.isClassDeclaration(node)) return false;
|
|
2200
|
+
return get_node_name(node) === symbol.name;
|
|
2201
|
+
}
|
|
2202
|
+
if (symbol.type === "type") {
|
|
2203
|
+
if (!import_typescript11.default.isTypeAliasDeclaration(node) && !import_typescript11.default.isInterfaceDeclaration(node) && !import_typescript11.default.isEnumDeclaration(node)) return false;
|
|
2204
|
+
return get_node_name(node) === symbol.name;
|
|
2205
|
+
}
|
|
2206
|
+
if (symbol.type === "variable") {
|
|
2207
|
+
if (import_typescript11.default.isVariableStatement(node)) {
|
|
2208
|
+
const declarations = node.declarationList.declarations;
|
|
2209
|
+
for (const decl of declarations) {
|
|
2210
|
+
if (import_typescript11.default.isIdentifier(decl.name) && decl.name.text === symbol.name) {
|
|
2211
|
+
const initializer = decl.initializer;
|
|
2212
|
+
if (!initializer || !import_typescript11.default.isArrowFunction(initializer) && !import_typescript11.default.isFunctionExpression(initializer)) {
|
|
2213
|
+
return true;
|
|
2214
|
+
}
|
|
2215
|
+
}
|
|
2216
|
+
}
|
|
2217
|
+
}
|
|
2218
|
+
return false;
|
|
2219
|
+
}
|
|
2220
|
+
if (symbol.type === "class_method") {
|
|
2221
|
+
if (!import_typescript11.default.isMethodDeclaration(node)) return false;
|
|
2222
|
+
const method_name = get_node_name(node);
|
|
2223
|
+
if (!method_name) return false;
|
|
2224
|
+
const class_node = node.parent;
|
|
2225
|
+
if (!class_node || !import_typescript11.default.isClassDeclaration(class_node)) return false;
|
|
2226
|
+
const class_name = get_node_name(class_node);
|
|
2227
|
+
if (!class_name) return false;
|
|
2228
|
+
return `${class_name}.${method_name}` === symbol.name;
|
|
2229
|
+
}
|
|
2230
|
+
if (symbol.type === "class_property") {
|
|
2231
|
+
if (!import_typescript11.default.isPropertyDeclaration(node)) return false;
|
|
2232
|
+
const prop_name = get_node_name(node);
|
|
2233
|
+
if (!prop_name) return false;
|
|
2234
|
+
const class_node = node.parent;
|
|
2235
|
+
if (!class_node || !import_typescript11.default.isClassDeclaration(class_node)) return false;
|
|
2236
|
+
const class_name = get_node_name(class_node);
|
|
2237
|
+
if (!class_name) return false;
|
|
2238
|
+
return `${class_name}.${prop_name}` === symbol.name;
|
|
2239
|
+
}
|
|
2240
|
+
return false;
|
|
2241
|
+
}
|
|
2242
|
+
function get_node_name(node) {
|
|
2243
|
+
if (!("name" in node)) return void 0;
|
|
2244
|
+
const nodeWithName = node;
|
|
2245
|
+
if (nodeWithName.name && import_typescript11.default.isIdentifier(nodeWithName.name)) {
|
|
2246
|
+
return nodeWithName.name.text;
|
|
2247
|
+
}
|
|
2248
|
+
return void 0;
|
|
2249
|
+
}
|
|
2250
|
+
function is_declaration(parent, identifier) {
|
|
2251
|
+
if (!parent) return false;
|
|
2252
|
+
if (import_typescript11.default.isFunctionDeclaration(parent) && parent.name === identifier) return true;
|
|
2253
|
+
if (import_typescript11.default.isClassDeclaration(parent) && parent.name === identifier) return true;
|
|
2254
|
+
if (import_typescript11.default.isInterfaceDeclaration(parent) && parent.name === identifier) return true;
|
|
2255
|
+
if (import_typescript11.default.isTypeAliasDeclaration(parent) && parent.name === identifier) return true;
|
|
2256
|
+
if (import_typescript11.default.isEnumDeclaration(parent) && parent.name === identifier) return true;
|
|
2257
|
+
if (import_typescript11.default.isVariableDeclaration(parent) && parent.name === identifier) return true;
|
|
2258
|
+
if (import_typescript11.default.isParameter(parent) && parent.name === identifier) return true;
|
|
2259
|
+
if (import_typescript11.default.isPropertyDeclaration(parent) && parent.name === identifier) return true;
|
|
2260
|
+
if (import_typescript11.default.isMethodDeclaration(parent) && parent.name === identifier) return true;
|
|
2261
|
+
if (import_typescript11.default.isTypeParameterDeclaration(parent) && parent.name === identifier) return true;
|
|
2262
|
+
if (import_typescript11.default.isImportClause(parent) && parent.name === identifier) return true;
|
|
2263
|
+
if (import_typescript11.default.isImportSpecifier(parent) && (parent.name === identifier || parent.propertyName === identifier)) return true;
|
|
2264
|
+
if (import_typescript11.default.isNamespaceImport(parent) && parent.name === identifier) return true;
|
|
2265
|
+
return false;
|
|
2266
|
+
}
|
|
2267
|
+
function create_internal_link(ctx, from_symbol, resolution) {
|
|
2268
|
+
const existing = symbol_internal_links_exports.exists(ctx, {
|
|
2269
|
+
from_symbol_id: from_symbol.id,
|
|
2270
|
+
to_symbol_id: resolution.symbol_id
|
|
2271
|
+
});
|
|
2272
|
+
if (err.any(existing)) return existing;
|
|
2273
|
+
if (existing) return;
|
|
2274
|
+
return symbol_internal_links_exports.insert(ctx, {
|
|
2275
|
+
from_file_id: from_symbol.file_id,
|
|
2276
|
+
to_file_id: resolution.file_id,
|
|
2277
|
+
from_symbol_id: from_symbol.id,
|
|
2278
|
+
to_symbol_id: resolution.symbol_id,
|
|
2279
|
+
state: "pending"
|
|
2280
|
+
});
|
|
2281
|
+
}
|
|
2282
|
+
function create_external_link(ctx, from_symbol, resolution) {
|
|
2283
|
+
const existing = symbol_external_links_exports.exists(ctx, {
|
|
2284
|
+
symbol_id: from_symbol.id,
|
|
2285
|
+
external_import_id: resolution.external_import_id
|
|
2286
|
+
});
|
|
2287
|
+
if (err.any(existing)) return existing;
|
|
2288
|
+
if (existing) return;
|
|
2289
|
+
return symbol_external_links_exports.insert(ctx, {
|
|
2290
|
+
symbol_id: from_symbol.id,
|
|
2291
|
+
external_import_id: resolution.external_import_id
|
|
2292
|
+
});
|
|
2293
|
+
}
|
|
2294
|
+
|
|
2295
|
+
// src/update/index.ts
|
|
2296
|
+
async function update6(ctx) {
|
|
2297
|
+
await track_changes(ctx);
|
|
2298
|
+
await sync_external_dependencies(ctx);
|
|
2299
|
+
await scan_files(ctx);
|
|
2300
|
+
await link_imports(ctx);
|
|
2301
|
+
await link_symbols(ctx);
|
|
2302
|
+
}
|
|
2303
|
+
|
|
2304
|
+
// src/counts.ts
|
|
2305
|
+
var import_drizzle_orm13 = require("drizzle-orm");
|
|
2306
|
+
var counts = safe_query("counts", (ctx) => {
|
|
2307
|
+
const symbol_counts = ctx.db.select({ state: symbols.state, count: (0, import_drizzle_orm13.count)() }).from(symbols).groupBy(symbols.state).all();
|
|
2308
|
+
const file_counts = ctx.db.select({ state: files.state, count: (0, import_drizzle_orm13.count)() }).from(files).groupBy(files.state).all();
|
|
2309
|
+
const dir_counts = ctx.db.select({ state: directories.state, count: (0, import_drizzle_orm13.count)() }).from(directories).groupBy(directories.state).all();
|
|
2310
|
+
const dep_counts = ctx.db.select({ state: external_dependencies.state, count: (0, import_drizzle_orm13.count)() }).from(external_dependencies).groupBy(external_dependencies.state).all();
|
|
2311
|
+
return {
|
|
2312
|
+
symbols: get_groups(symbol_counts, ["to_link", "to_describe", "ready"]),
|
|
2313
|
+
files: get_groups(file_counts, ["to_scan", "to_describe", "ready"]),
|
|
2314
|
+
directories: get_groups(dir_counts, ["to_describe", "ready"]),
|
|
2315
|
+
dependencies: get_groups(dep_counts, ["to_describe", "ready"])
|
|
2316
|
+
};
|
|
2317
|
+
});
|
|
2318
|
+
function get_groups(items, states) {
|
|
2319
|
+
const groups = { total: 0 };
|
|
2320
|
+
for (const state of states) groups[state] = 0;
|
|
2321
|
+
for (const item of items) {
|
|
2322
|
+
if (!states.includes(item.state)) continue;
|
|
2323
|
+
groups[item.state] = (groups[item.state] || 0) + item.count;
|
|
2324
|
+
groups.total += item.count;
|
|
2325
|
+
}
|
|
2326
|
+
return groups;
|
|
2327
|
+
}
|
|
2328
|
+
|
|
2329
|
+
// src/files.ts
|
|
2330
|
+
function files_wiki(ctx) {
|
|
2331
|
+
return {
|
|
2332
|
+
get: (id) => get2(ctx, id),
|
|
2333
|
+
search: (options) => search5(ctx, options),
|
|
2334
|
+
set_description: (id, description) => set_description(ctx, id, description),
|
|
2335
|
+
imported_by_file: (file_id, options) => imported_by_file(ctx, file_id, options),
|
|
2336
|
+
importing_file: (file_id, options) => importing_file(ctx, file_id, options),
|
|
2337
|
+
importing_dependency: (dependency_id, options) => importing_dependency(ctx, dependency_id, options)
|
|
2338
|
+
};
|
|
2339
|
+
}
|
|
2340
|
+
function get2(ctx, id) {
|
|
2341
|
+
return err.or_throw(files_exports.by_id(ctx, id)) ?? null;
|
|
2342
|
+
}
|
|
2343
|
+
function search5(ctx, options) {
|
|
2344
|
+
return err.or_throw(files_exports.search(ctx, options));
|
|
2345
|
+
}
|
|
2346
|
+
function set_description(ctx, id, description) {
|
|
2347
|
+
err.or_throw(files_exports.update(ctx, id, { description }));
|
|
2348
|
+
}
|
|
2349
|
+
function imported_by_file(ctx, file_id, options = {}) {
|
|
2350
|
+
let imported_files = err.or_throw(files_exports.imported_by(ctx, file_id, options.select));
|
|
2351
|
+
if (options.deep) {
|
|
2352
|
+
imported_files = err.or_throw(
|
|
2353
|
+
expand({
|
|
2354
|
+
items: imported_files,
|
|
2355
|
+
get_children: (file) => files_exports.imported_by(ctx, file.id, options.select),
|
|
2356
|
+
get_key: (file) => file.id
|
|
2357
|
+
})
|
|
2358
|
+
);
|
|
2359
|
+
}
|
|
2360
|
+
const start = options.offset ?? 0;
|
|
2361
|
+
const end = options.limit ? start + options.limit : imported_files.length;
|
|
2362
|
+
return imported_files.slice(start, end);
|
|
2363
|
+
}
|
|
2364
|
+
function importing_file(ctx, file_id, options = {}) {
|
|
2365
|
+
let importing_files = err.or_throw(files_exports.importing(ctx, file_id, options.select));
|
|
2366
|
+
if (options.deep) {
|
|
2367
|
+
importing_files = err.or_throw(
|
|
2368
|
+
expand({
|
|
2369
|
+
items: importing_files,
|
|
2370
|
+
get_children: (file) => files_exports.importing(ctx, file.id, options.select),
|
|
2371
|
+
get_key: (file) => file.id
|
|
2372
|
+
})
|
|
2373
|
+
);
|
|
2374
|
+
}
|
|
2375
|
+
const start = options.offset ?? 0;
|
|
2376
|
+
const end = options.limit ? start + options.limit : importing_files.length;
|
|
2377
|
+
return importing_files.slice(start, end);
|
|
2378
|
+
}
|
|
2379
|
+
function importing_dependency(ctx, dependency_id, options = {}) {
|
|
2380
|
+
let files_using_dependency = err.or_throw(files_exports.using_dependency(ctx, dependency_id, options.select));
|
|
2381
|
+
if (options.deep) {
|
|
2382
|
+
files_using_dependency = err.or_throw(
|
|
2383
|
+
expand({
|
|
2384
|
+
items: files_using_dependency,
|
|
2385
|
+
get_children: (file) => files_exports.importing(ctx, file.id, options.select),
|
|
2386
|
+
get_key: (file) => file.id
|
|
2387
|
+
})
|
|
2388
|
+
);
|
|
2389
|
+
}
|
|
2390
|
+
const start = options.offset ?? 0;
|
|
2391
|
+
const end = options.limit ? start + options.limit : files_using_dependency.length;
|
|
2392
|
+
return files_using_dependency.slice(start, end);
|
|
2393
|
+
}
|
|
2394
|
+
|
|
2395
|
+
// src/symbols.ts
|
|
2396
|
+
function symbols_wiki(ctx) {
|
|
2397
|
+
return {
|
|
2398
|
+
get: (id) => get3(ctx, id),
|
|
2399
|
+
search: (options) => search6(ctx, options),
|
|
2400
|
+
set_description: (id, description) => set_description2(ctx, id, description),
|
|
2401
|
+
referencing_symbol: (symbol_id, options) => referencing_symbol(ctx, symbol_id, options),
|
|
2402
|
+
referenced_by_symbol: (symbol_id, options) => referenced_by_symbol(ctx, symbol_id, options),
|
|
2403
|
+
using_dependency: (dependency_id, options) => using_dependency3(ctx, dependency_id, options)
|
|
2404
|
+
};
|
|
2405
|
+
}
|
|
2406
|
+
function get3(ctx, id) {
|
|
2407
|
+
return err.or_throw(symbols_exports.by_id(ctx, id)) ?? null;
|
|
2408
|
+
}
|
|
2409
|
+
function search6(ctx, options) {
|
|
2410
|
+
return err.or_throw(symbols_exports.search(ctx, options));
|
|
2411
|
+
}
|
|
2412
|
+
function set_description2(ctx, id, description) {
|
|
2413
|
+
err.or_throw(symbols_exports.update(ctx, id, { description }));
|
|
2414
|
+
}
|
|
2415
|
+
function referenced_by_symbol(ctx, symbol_id, options = {}) {
|
|
2416
|
+
let referenced_symbols = err.or_throw(symbols_exports.referenced_by(ctx, symbol_id, options.select));
|
|
2417
|
+
if (options.deep) {
|
|
2418
|
+
referenced_symbols = err.or_throw(
|
|
2419
|
+
expand({
|
|
2420
|
+
items: referenced_symbols,
|
|
2421
|
+
get_children: (symbol) => symbols_exports.referenced_by(ctx, symbol.id, options.select),
|
|
2422
|
+
get_key: (symbol) => symbol.id
|
|
2423
|
+
})
|
|
2424
|
+
);
|
|
2425
|
+
}
|
|
2426
|
+
const start = options.offset ?? 0;
|
|
2427
|
+
const end = options.limit ? start + options.limit : referenced_symbols.length;
|
|
2428
|
+
return referenced_symbols.slice(start, end);
|
|
2429
|
+
}
|
|
2430
|
+
function referencing_symbol(ctx, symbol_id, options = {}) {
|
|
2431
|
+
let referencing_symbols = err.or_throw(symbols_exports.referencing(ctx, symbol_id, options.select));
|
|
2432
|
+
if (options.deep) {
|
|
2433
|
+
referencing_symbols = err.or_throw(
|
|
2434
|
+
expand({
|
|
2435
|
+
items: referencing_symbols,
|
|
2436
|
+
get_children: (symbol) => symbols_exports.referencing(ctx, symbol.id, options.select),
|
|
2437
|
+
get_key: (symbol) => symbol.id
|
|
2438
|
+
})
|
|
2439
|
+
);
|
|
2440
|
+
}
|
|
2441
|
+
const start = options.offset ?? 0;
|
|
2442
|
+
const end = options.limit ? start + options.limit : referencing_symbols.length;
|
|
2443
|
+
return referencing_symbols.slice(start, end);
|
|
2444
|
+
}
|
|
2445
|
+
function using_dependency3(ctx, dependency_id, options = {}) {
|
|
2446
|
+
let symbols_using_dep = err.or_throw(symbols_exports.using_dependency(ctx, dependency_id, options.select));
|
|
2447
|
+
if (options.deep) {
|
|
2448
|
+
symbols_using_dep = err.or_throw(
|
|
2449
|
+
expand({
|
|
2450
|
+
items: symbols_using_dep,
|
|
2451
|
+
get_children: (symbol) => symbols_exports.referencing(ctx, symbol.id, options.select),
|
|
2452
|
+
get_key: (symbol) => symbol.id
|
|
2453
|
+
})
|
|
2454
|
+
);
|
|
2455
|
+
}
|
|
2456
|
+
const start = options.offset ?? 0;
|
|
2457
|
+
const end = options.limit ? start + options.limit : symbols_using_dep.length;
|
|
2458
|
+
return symbols_using_dep.slice(start, end);
|
|
2459
|
+
}
|
|
2460
|
+
|
|
2461
|
+
// src/directories.ts
|
|
2462
|
+
function directories_wiki(ctx) {
|
|
2463
|
+
return {
|
|
2464
|
+
get: (id) => get4(ctx, id),
|
|
2465
|
+
search: (options) => search7(ctx, options),
|
|
2466
|
+
set_description: (id, description) => set_description3(ctx, id, description),
|
|
2467
|
+
children: (parent_id, options) => children(ctx, parent_id, options),
|
|
2468
|
+
files: (directory_id, options) => directory_files(ctx, directory_id, options)
|
|
2469
|
+
};
|
|
2470
|
+
}
|
|
2471
|
+
function get4(ctx, id) {
|
|
2472
|
+
return err.or_throw(directories_exports.by_id(ctx, id)) ?? null;
|
|
2473
|
+
}
|
|
2474
|
+
function search7(ctx, options) {
|
|
2475
|
+
return err.or_throw(directories_exports.search(ctx, options));
|
|
2476
|
+
}
|
|
2477
|
+
function set_description3(ctx, id, description) {
|
|
2478
|
+
err.or_throw(directories_exports.update(ctx, id, { description }));
|
|
2479
|
+
}
|
|
2480
|
+
function children(ctx, parent_id, options = {}) {
|
|
2481
|
+
let child_directories = err.or_throw(directories_exports.search(ctx, { select: options.select, where: { parent_id }, limit: 1e4 }));
|
|
2482
|
+
if (options.deep) {
|
|
2483
|
+
child_directories = err.or_throw(
|
|
2484
|
+
expand({
|
|
2485
|
+
items: child_directories,
|
|
2486
|
+
get_children: (dir) => directories_exports.search(ctx, { select: options.select, where: { parent_id: dir.id }, limit: 1e4 }),
|
|
2487
|
+
get_key: (dir) => dir.id
|
|
2488
|
+
})
|
|
2489
|
+
);
|
|
2490
|
+
}
|
|
2491
|
+
const start = options.offset ?? 0;
|
|
2492
|
+
const end = options.limit ? start + options.limit : child_directories.length;
|
|
2493
|
+
return child_directories.slice(start, end);
|
|
2494
|
+
}
|
|
2495
|
+
function directory_files(ctx, directory_id, options = {}) {
|
|
2496
|
+
let files_list = err.or_throw(files_exports.search(ctx, { select: options.select, where: { directory_id }, limit: 1e4 }));
|
|
2497
|
+
if (options.deep) {
|
|
2498
|
+
const all_subdirs = err.or_throw(
|
|
2499
|
+
expand({
|
|
2500
|
+
items: err.or_throw(directories_exports.search(ctx, { select: ["id"], where: { parent_id: directory_id }, limit: 1e4 })),
|
|
2501
|
+
get_children: (dir) => directories_exports.search(ctx, { select: ["id"], where: { parent_id: dir.id }, limit: 1e4 }),
|
|
2502
|
+
get_key: (dir) => dir.id
|
|
2503
|
+
})
|
|
2504
|
+
);
|
|
2505
|
+
for (const subdir of all_subdirs) {
|
|
2506
|
+
const subdir_files = err.or_throw(
|
|
2507
|
+
files_exports.search(ctx, { select: options.select, where: { directory_id: subdir.id }, limit: 1e4 })
|
|
2508
|
+
);
|
|
2509
|
+
subdir_files.forEach((x) => files_list.push(x));
|
|
2510
|
+
}
|
|
2511
|
+
}
|
|
2512
|
+
const start = options.offset ?? 0;
|
|
2513
|
+
const end = options.limit ? start + options.limit : files_list.length;
|
|
2514
|
+
return files_list.slice(start, end);
|
|
2515
|
+
}
|
|
2516
|
+
|
|
2517
|
+
// src/dependencies.ts
|
|
2518
|
+
function dependencies_wiki(ctx) {
|
|
2519
|
+
return {
|
|
2520
|
+
get: (id) => get5(ctx, id),
|
|
2521
|
+
search: (options) => search8(ctx, options),
|
|
2522
|
+
set_description: (id, description) => set_description4(ctx, id, description),
|
|
2523
|
+
used_by_file: (file_id, options) => used_by_file2(ctx, file_id, options),
|
|
2524
|
+
used_by_symbol: (symbol_id, options) => used_by_symbol2(ctx, symbol_id, options)
|
|
2525
|
+
};
|
|
2526
|
+
}
|
|
2527
|
+
function get5(ctx, id) {
|
|
2528
|
+
return err.or_throw(external_dependencies_exports.by_id(ctx, id)) ?? null;
|
|
2529
|
+
}
|
|
2530
|
+
function search8(ctx, options) {
|
|
2531
|
+
return err.or_throw(external_dependencies_exports.search(ctx, options));
|
|
2532
|
+
}
|
|
2533
|
+
function set_description4(ctx, id, description) {
|
|
2534
|
+
err.or_throw(external_dependencies_exports.update(ctx, id, { description, state: "ready", error: null }));
|
|
2535
|
+
}
|
|
2536
|
+
function used_by_file2(ctx, file_id, options) {
|
|
2537
|
+
return err.or_throw(external_dependencies_exports.used_by_file(ctx, file_id, options?.select));
|
|
2538
|
+
}
|
|
2539
|
+
function used_by_symbol2(ctx, symbol_id, options) {
|
|
2540
|
+
return err.or_throw(external_dependencies_exports.used_by_symbol(ctx, symbol_id, options?.select));
|
|
2541
|
+
}
|
|
2542
|
+
|
|
2543
|
+
// src/index.ts
|
|
2544
|
+
async function create(config) {
|
|
2545
|
+
const ctx = await context_from_config(config);
|
|
2546
|
+
return {
|
|
2547
|
+
config,
|
|
2548
|
+
update: () => update6(ctx),
|
|
2549
|
+
counts: () => err.or_throw(counts(ctx)),
|
|
2550
|
+
files: files_wiki(ctx),
|
|
2551
|
+
symbols: symbols_wiki(ctx),
|
|
2552
|
+
directories: directories_wiki(ctx),
|
|
2553
|
+
dependencies: dependencies_wiki(ctx)
|
|
2554
|
+
};
|
|
2555
|
+
}
|
|
2556
|
+
async function load(db_path) {
|
|
2557
|
+
const ctx = await context_from_db(db_path);
|
|
2558
|
+
const stored = ctx.db.select().from(schema_exports.configs).get();
|
|
2559
|
+
const config = {
|
|
2560
|
+
db_path,
|
|
2561
|
+
project_path: stored.project_path,
|
|
2562
|
+
description: stored.description ?? void 0,
|
|
2563
|
+
package_json_path: stored.package_json_path ?? void 0,
|
|
2564
|
+
node_modules_paths: stored.node_modules_paths ? JSON.parse(stored.node_modules_paths) : void 0
|
|
2565
|
+
};
|
|
2566
|
+
return {
|
|
2567
|
+
config,
|
|
2568
|
+
update: () => update6(ctx),
|
|
2569
|
+
counts: () => err.or_throw(counts(ctx)),
|
|
2570
|
+
files: files_wiki(ctx),
|
|
2571
|
+
symbols: symbols_wiki(ctx),
|
|
2572
|
+
directories: directories_wiki(ctx),
|
|
2573
|
+
dependencies: dependencies_wiki(ctx)
|
|
2574
|
+
};
|
|
2575
|
+
}
|
|
2576
|
+
|
|
2577
|
+
// src/cli/commands/_common.ts
|
|
2578
|
+
var config_path = "codewiki.json";
|
|
2579
|
+
async function load_wiki() {
|
|
2580
|
+
try {
|
|
2581
|
+
const content = err.or_throw(env.read_file(config_path));
|
|
2582
|
+
const raw_config = err.or_throw(parse_json(content));
|
|
2583
|
+
const res = Config.safeParse(raw_config);
|
|
2584
|
+
if (!res.success) throw err.new("invalid_config", { errors: res.error.issues });
|
|
2585
|
+
const config = res.data;
|
|
2586
|
+
if (env.file_exists(config.db_path)) return load(config.db_path);
|
|
2587
|
+
return create(config);
|
|
2588
|
+
} catch (error) {
|
|
2589
|
+
if (error.type === "could_not_read_file") {
|
|
2590
|
+
env.error(`Error: Configuration file ${config_path} not found`);
|
|
2591
|
+
} else if (error.type === "invalid_json") {
|
|
2592
|
+
env.error(`Error: Invalid JSON in ${config_path}`);
|
|
2593
|
+
} else if (error.type === "invalid_config") {
|
|
2594
|
+
env.error("Error: Invalid configuration");
|
|
2595
|
+
} else if (error.message) {
|
|
2596
|
+
env.error(`Error: ${error.message}`);
|
|
2597
|
+
} else {
|
|
2598
|
+
env.error(`Error: ${String(error)}`);
|
|
2599
|
+
}
|
|
2600
|
+
process.exit(1);
|
|
2601
|
+
}
|
|
2602
|
+
}
|
|
2603
|
+
function parse_options(options_json, schema, context) {
|
|
2604
|
+
let parsed_json;
|
|
2605
|
+
try {
|
|
2606
|
+
parsed_json = err.or_throw(parse_json(options_json));
|
|
2607
|
+
} catch (error) {
|
|
2608
|
+
env.log(`Error: Invalid JSON in ${context}`);
|
|
2609
|
+
const error_msg = error.data?.reason?.message || "JSON parse error";
|
|
2610
|
+
env.log(` ${error_msg}`);
|
|
2611
|
+
process.exit(1);
|
|
2612
|
+
}
|
|
2613
|
+
const validation_result = schema.safeParse(parsed_json);
|
|
2614
|
+
if (!validation_result.success) {
|
|
2615
|
+
env.log(`Error: Invalid options format in ${context}`);
|
|
2616
|
+
env.log("");
|
|
2617
|
+
for (const issue of validation_result.error.issues) {
|
|
2618
|
+
const path6 = issue.path.length > 0 ? issue.path.join(".") : "root";
|
|
2619
|
+
env.log(` \u2022 ${path6}: ${issue.message}`);
|
|
2620
|
+
}
|
|
2621
|
+
env.log("");
|
|
2622
|
+
env.log(`Run 'codewiki ${context.split(" ")[0]} --help' for usage information`);
|
|
2623
|
+
process.exit(1);
|
|
2624
|
+
}
|
|
2625
|
+
return validation_result.data;
|
|
2626
|
+
}
|
|
2627
|
+
|
|
2628
|
+
// src/cli/utils.ts
|
|
2629
|
+
var import_dedent = __toESM(require("dedent"), 1);
|
|
2630
|
+
function format_counts(counts2) {
|
|
2631
|
+
const total_to_describe = Object.values(counts2).reduce((a, b) => a + b.to_describe, 0);
|
|
2632
|
+
return import_dedent.default`
|
|
2633
|
+
stats:
|
|
2634
|
+
directories: ${count_text(counts2.directories)}
|
|
2635
|
+
files: ${count_text(counts2.files)}
|
|
2636
|
+
symbols: ${count_text(counts2.symbols)}
|
|
2637
|
+
dependencies: ${count_text(counts2.dependencies)}
|
|
2638
|
+
|
|
2639
|
+
${total_to_describe} items to describe, run \`codewiki describe\` to start describing the codebase
|
|
2640
|
+
`;
|
|
2641
|
+
}
|
|
2642
|
+
function count_text({ total, ...states }) {
|
|
2643
|
+
return `${total} (${Object.entries(states).map(([name, value]) => `${value} ${name.replace("_", " ")}`).join(", ")})`;
|
|
2644
|
+
}
|
|
2645
|
+
|
|
2646
|
+
// src/cli/commands/update.ts
|
|
2647
|
+
var update7 = new import_commander.Command("update");
|
|
2648
|
+
update7.description("Reads current files and updates the wiki database");
|
|
2649
|
+
update7.action(async () => {
|
|
2650
|
+
const wiki = await load_wiki();
|
|
2651
|
+
await wiki.update();
|
|
2652
|
+
env.log("Update complete.\n");
|
|
2653
|
+
const counts2 = wiki.counts();
|
|
2654
|
+
const status2 = format_counts(counts2);
|
|
2655
|
+
env.log(status2);
|
|
2656
|
+
});
|
|
2657
|
+
|
|
2658
|
+
// src/cli/commands/status.ts
|
|
2659
|
+
var import_commander2 = require("commander");
|
|
2660
|
+
var status = new import_commander2.Command("status");
|
|
2661
|
+
status.description("Show the status of the wiki");
|
|
2662
|
+
status.action(async () => {
|
|
2663
|
+
const wiki = await load_wiki();
|
|
2664
|
+
const counts2 = wiki.counts();
|
|
2665
|
+
env.log(format_counts(counts2));
|
|
2666
|
+
});
|
|
2667
|
+
|
|
2668
|
+
// src/cli/commands/describe.ts
|
|
2669
|
+
var import_dedent2 = __toESM(require("dedent"), 1);
|
|
2670
|
+
var import_commander3 = require("commander");
|
|
2671
|
+
var describe = new import_commander3.Command("describe");
|
|
2672
|
+
describe.description("Show the next item to describe");
|
|
2673
|
+
describe.action(async () => {
|
|
2674
|
+
const wiki = await load_wiki();
|
|
2675
|
+
const next = get_next_to_describe(wiki);
|
|
2676
|
+
if (!next) return env.log("All items are described!");
|
|
2677
|
+
if (next.type === "dependency") return describe_dependency(next.entity);
|
|
2678
|
+
env.log(
|
|
2679
|
+
`All external dependencies are described, and we don't support describing other items yet (we are implementing the right order ...). You are done for now!`
|
|
2680
|
+
);
|
|
2681
|
+
});
|
|
2682
|
+
function describe_dependency(dep) {
|
|
2683
|
+
env.log(import_dedent2.default`
|
|
2684
|
+
Your task is to describe the following dependency:
|
|
2685
|
+
|
|
2686
|
+
import { ${dep.name} } from '${dep.package}${dep.subpath || ""}'
|
|
2687
|
+
|
|
2688
|
+
package: ${dep.package}
|
|
2689
|
+
version: ${dep.version}
|
|
2690
|
+
github: ${dep.github_repo || "N/A"}
|
|
2691
|
+
|
|
2692
|
+
Write a concise developer documentation on the usage of this \`${dep.name}\` into a markdown file, then run the following command to save the description:
|
|
2693
|
+
\`codewiki dependencies set-description ${dep.id} <markdown-file>\`
|
|
2694
|
+
`);
|
|
2695
|
+
}
|
|
2696
|
+
function get_next_to_describe(wiki) {
|
|
2697
|
+
const deps = wiki.dependencies.search({
|
|
2698
|
+
where: { state: "to_describe" },
|
|
2699
|
+
limit: 1,
|
|
2700
|
+
select: ["id", "package", "subpath", "name", "version", "github_repo"]
|
|
2701
|
+
});
|
|
2702
|
+
if (deps.length > 0) {
|
|
2703
|
+
return { type: "dependency", entity: deps[0] };
|
|
2704
|
+
}
|
|
2705
|
+
const symbols4 = wiki.symbols.search({
|
|
2706
|
+
where: { state: "to_describe" },
|
|
2707
|
+
limit: 1,
|
|
2708
|
+
select: ["id", "name", "type", "file_id", "is_exported"]
|
|
2709
|
+
});
|
|
2710
|
+
if (symbols4.length > 0) {
|
|
2711
|
+
return { type: "symbol", entity: symbols4[0] };
|
|
2712
|
+
}
|
|
2713
|
+
const files5 = wiki.files.search({
|
|
2714
|
+
where: { state: "to_describe" },
|
|
2715
|
+
limit: 1,
|
|
2716
|
+
select: ["id", "path"]
|
|
2717
|
+
});
|
|
2718
|
+
if (files5.length > 0) {
|
|
2719
|
+
return { type: "file", entity: files5[0] };
|
|
2720
|
+
}
|
|
2721
|
+
const directories4 = wiki.directories.search({
|
|
2722
|
+
where: { state: "to_describe" },
|
|
2723
|
+
limit: 1,
|
|
2724
|
+
select: ["id", "path"]
|
|
2725
|
+
});
|
|
2726
|
+
if (directories4.length > 0) {
|
|
2727
|
+
return { type: "directory", entity: directories4[0] };
|
|
2728
|
+
}
|
|
2729
|
+
return null;
|
|
2730
|
+
}
|
|
2731
|
+
|
|
2732
|
+
// src/cli/commands/files/index.ts
|
|
2733
|
+
var import_commander10 = require("commander");
|
|
2734
|
+
var import_dedent3 = __toESM(require("dedent"), 1);
|
|
2735
|
+
|
|
2736
|
+
// src/cli/commands/files/get.ts
|
|
2737
|
+
var import_commander4 = require("commander");
|
|
2738
|
+
var get6 = new import_commander4.Command("get");
|
|
2739
|
+
get6.description("Get a file by ID");
|
|
2740
|
+
get6.argument("<id>", "File ID");
|
|
2741
|
+
get6.action(async (id) => {
|
|
2742
|
+
const wiki = await load_wiki();
|
|
2743
|
+
const file = wiki.files.get(Number(id));
|
|
2744
|
+
env.log(JSON.stringify(file, null, 2));
|
|
2745
|
+
});
|
|
2746
|
+
|
|
2747
|
+
// src/cli/commands/files/search.ts
|
|
2748
|
+
var import_commander5 = require("commander");
|
|
2749
|
+
var search9 = new import_commander5.Command("search");
|
|
2750
|
+
search9.description("Search files with JSON options");
|
|
2751
|
+
search9.argument("<options>", "JSON options for search");
|
|
2752
|
+
search9.action(async (options_json) => {
|
|
2753
|
+
const wiki = await load_wiki();
|
|
2754
|
+
const options = parse_options(options_json, FileSearchOptions, "files search");
|
|
2755
|
+
const results = wiki.files.search(options);
|
|
2756
|
+
env.log(JSON.stringify(results, null, 2));
|
|
2757
|
+
});
|
|
2758
|
+
|
|
2759
|
+
// src/cli/commands/files/set-description.ts
|
|
2760
|
+
var import_fs3 = require("fs");
|
|
2761
|
+
var import_commander6 = require("commander");
|
|
2762
|
+
var set_description5 = new import_commander6.Command("set-description");
|
|
2763
|
+
set_description5.description("Set description for a file");
|
|
2764
|
+
set_description5.argument("<file-id>", "File ID");
|
|
2765
|
+
set_description5.argument("<markdown-file>", "Path to markdown file");
|
|
2766
|
+
set_description5.action(async (id, file) => {
|
|
2767
|
+
const wiki = await load_wiki();
|
|
2768
|
+
try {
|
|
2769
|
+
const content = (0, import_fs3.readFileSync)(file, "utf-8");
|
|
2770
|
+
wiki.files.set_description(Number(id), content);
|
|
2771
|
+
env.log("Description saved. Run `codewiki describe` to describe the next item.");
|
|
2772
|
+
} catch (err2) {
|
|
2773
|
+
env.error(`Error: ${err2.message}`);
|
|
2774
|
+
env.exit(1);
|
|
2775
|
+
}
|
|
2776
|
+
});
|
|
2777
|
+
|
|
2778
|
+
// src/cli/commands/files/imported-by-file.ts
|
|
2779
|
+
var import_commander7 = require("commander");
|
|
2780
|
+
var imported_by_file2 = new import_commander7.Command("imported-by-file");
|
|
2781
|
+
imported_by_file2.description("Files imported by the given file");
|
|
2782
|
+
imported_by_file2.argument("<file-id>", "File ID");
|
|
2783
|
+
imported_by_file2.argument("<options>", "JSON options");
|
|
2784
|
+
imported_by_file2.action(async (file_id, options_json) => {
|
|
2785
|
+
const wiki = await load_wiki();
|
|
2786
|
+
const options = parse_options(options_json, FileRelationOptions, "files imported-by-file");
|
|
2787
|
+
const results = wiki.files.imported_by_file(Number(file_id), options);
|
|
2788
|
+
env.log(JSON.stringify(results, null, 2));
|
|
2789
|
+
});
|
|
2790
|
+
|
|
2791
|
+
// src/cli/commands/files/importing-file.ts
|
|
2792
|
+
var import_commander8 = require("commander");
|
|
2793
|
+
var importing_file2 = new import_commander8.Command("importing-file");
|
|
2794
|
+
importing_file2.description("Files importing the given file");
|
|
2795
|
+
importing_file2.argument("<file-id>", "File ID");
|
|
2796
|
+
importing_file2.argument("<options>", "JSON options");
|
|
2797
|
+
importing_file2.action(async (file_id, options_json) => {
|
|
2798
|
+
const wiki = await load_wiki();
|
|
2799
|
+
const options = parse_options(options_json, FileRelationOptions, "files importing-file");
|
|
2800
|
+
const results = wiki.files.importing_file(Number(file_id), options);
|
|
2801
|
+
env.log(JSON.stringify(results, null, 2));
|
|
2802
|
+
});
|
|
2803
|
+
|
|
2804
|
+
// src/cli/commands/files/importing-dependency.ts
|
|
2805
|
+
var import_commander9 = require("commander");
|
|
2806
|
+
var importing_dependency2 = new import_commander9.Command("importing-dependency");
|
|
2807
|
+
importing_dependency2.description("Files importing the given dependency");
|
|
2808
|
+
importing_dependency2.argument("<dep-id>", "Dependency ID");
|
|
2809
|
+
importing_dependency2.argument("<options>", "JSON options");
|
|
2810
|
+
importing_dependency2.action(async (dep_id, options_json) => {
|
|
2811
|
+
const wiki = await load_wiki();
|
|
2812
|
+
const options = parse_options(options_json, FileRelationOptions, "files importing-dependency");
|
|
2813
|
+
const results = wiki.files.importing_dependency(Number(dep_id), options);
|
|
2814
|
+
env.log(JSON.stringify(results, null, 2));
|
|
2815
|
+
});
|
|
2816
|
+
|
|
2817
|
+
// src/cli/commands/files/index.ts
|
|
2818
|
+
var files3 = new import_commander10.Command("files");
|
|
2819
|
+
files3.description("Explore files");
|
|
2820
|
+
files3.addCommand(get6);
|
|
2821
|
+
files3.addCommand(search9);
|
|
2822
|
+
files3.addCommand(set_description5);
|
|
2823
|
+
files3.addCommand(imported_by_file2);
|
|
2824
|
+
files3.addCommand(importing_file2);
|
|
2825
|
+
files3.addCommand(importing_dependency2);
|
|
2826
|
+
files3.addHelpText("after", import_dedent3.default`
|
|
2827
|
+
|
|
2828
|
+
<search-options> is a JSON string following the type SearchOptions:
|
|
2829
|
+
|
|
2830
|
+
type FileField = "id" | "directory_id" | "path" | "description" | "state" | "error"
|
|
2831
|
+
type SearchOptions = {
|
|
2832
|
+
select?: Array<FileField>
|
|
2833
|
+
limit?: number
|
|
2834
|
+
offset?: number
|
|
2835
|
+
where?: Record<FileField, string | { contains: string } | { starts_with: string } | { ends_with: string }>
|
|
2836
|
+
order_by?: [FileField, 'asc' | 'desc']
|
|
2837
|
+
}
|
|
2838
|
+
|
|
2839
|
+
<relation-options> is a JSON string following the type RelationOptions:
|
|
2840
|
+
|
|
2841
|
+
type RelationOptions = {
|
|
2842
|
+
select?: Array<FileField>
|
|
2843
|
+
limit?: number
|
|
2844
|
+
offset?: number
|
|
2845
|
+
deep?: boolean
|
|
2846
|
+
}
|
|
2847
|
+
|
|
2848
|
+
Examples:
|
|
2849
|
+
codewiki files search '{"limit": 10}'
|
|
2850
|
+
codewiki files search '{"where": {"state": "ready"}, "limit": 5}'
|
|
2851
|
+
codewiki files search '{"where": {"path": {"contains": "test"}}, "limit": 10}'
|
|
2852
|
+
codewiki files imported-by-file 123 '{"limit": 10}'
|
|
2853
|
+
`);
|
|
2854
|
+
|
|
2855
|
+
// src/cli/commands/symbols/index.ts
|
|
2856
|
+
var import_commander17 = require("commander");
|
|
2857
|
+
var import_dedent4 = __toESM(require("dedent"), 1);
|
|
2858
|
+
|
|
2859
|
+
// src/cli/commands/symbols/get.ts
|
|
2860
|
+
var import_commander11 = require("commander");
|
|
2861
|
+
var get7 = new import_commander11.Command("get");
|
|
2862
|
+
get7.description("Get a symbol by ID");
|
|
2863
|
+
get7.argument("<id>", "Symbol ID");
|
|
2864
|
+
get7.action(async (id) => {
|
|
2865
|
+
const wiki = await load_wiki();
|
|
2866
|
+
const symbol = wiki.symbols.get(Number(id));
|
|
2867
|
+
env.log(JSON.stringify(symbol, null, 2));
|
|
2868
|
+
});
|
|
2869
|
+
|
|
2870
|
+
// src/cli/commands/symbols/search.ts
|
|
2871
|
+
var import_commander12 = require("commander");
|
|
2872
|
+
var search10 = new import_commander12.Command("search");
|
|
2873
|
+
search10.description("Search symbols with JSON options");
|
|
2874
|
+
search10.argument("<options>", "JSON options");
|
|
2875
|
+
search10.action(async (options_json) => {
|
|
2876
|
+
const wiki = await load_wiki();
|
|
2877
|
+
const options = parse_options(options_json, SymbolSearchOptions, "symbols search");
|
|
2878
|
+
const results = wiki.symbols.search(options);
|
|
2879
|
+
env.log(JSON.stringify(results, null, 2));
|
|
2880
|
+
});
|
|
2881
|
+
|
|
2882
|
+
// src/cli/commands/symbols/set-description.ts
|
|
2883
|
+
var import_fs4 = require("fs");
|
|
2884
|
+
var import_commander13 = require("commander");
|
|
2885
|
+
var set_description6 = new import_commander13.Command("set-description");
|
|
2886
|
+
set_description6.description("Set description for a symbol");
|
|
2887
|
+
set_description6.argument("<symbol-id>", "Symbol ID");
|
|
2888
|
+
set_description6.argument("<markdown-file>", "Path to markdown file");
|
|
2889
|
+
set_description6.action(async (id, file) => {
|
|
2890
|
+
const wiki = await load_wiki();
|
|
2891
|
+
try {
|
|
2892
|
+
const content = (0, import_fs4.readFileSync)(file, "utf-8");
|
|
2893
|
+
wiki.symbols.set_description(Number(id), content);
|
|
2894
|
+
env.log("Description saved. Run `codewiki describe` to describe the next item.");
|
|
2895
|
+
} catch (err2) {
|
|
2896
|
+
env.error(`Error: ${err2.message}`);
|
|
2897
|
+
env.exit(1);
|
|
2898
|
+
}
|
|
2899
|
+
});
|
|
2900
|
+
|
|
2901
|
+
// src/cli/commands/symbols/referencing-symbol.ts
|
|
2902
|
+
var import_commander14 = require("commander");
|
|
2903
|
+
var referencing_symbol2 = new import_commander14.Command("referencing-symbol");
|
|
2904
|
+
referencing_symbol2.description("Symbols referencing the given symbol");
|
|
2905
|
+
referencing_symbol2.argument("<symbol-id>", "Symbol ID");
|
|
2906
|
+
referencing_symbol2.argument("<options>", "JSON options");
|
|
2907
|
+
referencing_symbol2.action(async (symbol_id, options_json) => {
|
|
2908
|
+
const wiki = await load_wiki();
|
|
2909
|
+
const options = parse_options(options_json, SymbolRelationOptions, "symbols referencing-symbol");
|
|
2910
|
+
const results = wiki.symbols.referencing_symbol(Number(symbol_id), options);
|
|
2911
|
+
env.log(JSON.stringify(results, null, 2));
|
|
2912
|
+
});
|
|
2913
|
+
|
|
2914
|
+
// src/cli/commands/symbols/referenced-by-symbol.ts
|
|
2915
|
+
var import_commander15 = require("commander");
|
|
2916
|
+
var referenced_by_symbol2 = new import_commander15.Command("referenced-by-symbol");
|
|
2917
|
+
referenced_by_symbol2.description("Symbols referenced by the given symbol");
|
|
2918
|
+
referenced_by_symbol2.argument("<symbol-id>", "Symbol ID");
|
|
2919
|
+
referenced_by_symbol2.argument("<options>", "JSON options");
|
|
2920
|
+
referenced_by_symbol2.action(async (symbol_id, options_json) => {
|
|
2921
|
+
const wiki = await load_wiki();
|
|
2922
|
+
const options = parse_options(options_json, SymbolRelationOptions, "symbols referenced-by-symbol");
|
|
2923
|
+
const results = wiki.symbols.referenced_by_symbol(Number(symbol_id), options);
|
|
2924
|
+
env.log(JSON.stringify(results, null, 2));
|
|
2925
|
+
});
|
|
2926
|
+
|
|
2927
|
+
// src/cli/commands/symbols/using-dependency.ts
|
|
2928
|
+
var import_commander16 = require("commander");
|
|
2929
|
+
var using_dependency4 = new import_commander16.Command("using-dependency");
|
|
2930
|
+
using_dependency4.description("Symbols using the given dependency");
|
|
2931
|
+
using_dependency4.argument("<dep-id>", "Dependency ID");
|
|
2932
|
+
using_dependency4.argument("<options>", "JSON options");
|
|
2933
|
+
using_dependency4.action(async (dep_id, options_json) => {
|
|
2934
|
+
const wiki = await load_wiki();
|
|
2935
|
+
const options = parse_options(options_json, SymbolRelationOptions, "symbols using-dependency");
|
|
2936
|
+
const results = wiki.symbols.using_dependency(Number(dep_id), options);
|
|
2937
|
+
env.log(JSON.stringify(results, null, 2));
|
|
2938
|
+
});
|
|
2939
|
+
|
|
2940
|
+
// src/cli/commands/symbols/index.ts
|
|
2941
|
+
var symbols3 = new import_commander17.Command("symbols");
|
|
2942
|
+
symbols3.description("Explore symbols");
|
|
2943
|
+
symbols3.addCommand(get7);
|
|
2944
|
+
symbols3.addCommand(search10);
|
|
2945
|
+
symbols3.addCommand(set_description6);
|
|
2946
|
+
symbols3.addCommand(referencing_symbol2);
|
|
2947
|
+
symbols3.addCommand(referenced_by_symbol2);
|
|
2948
|
+
symbols3.addCommand(using_dependency4);
|
|
2949
|
+
symbols3.addHelpText("after", import_dedent4.default`
|
|
2950
|
+
|
|
2951
|
+
<search-options> is a JSON string following the type SearchOptions:
|
|
2952
|
+
|
|
2953
|
+
type SymbolField = "id" | "file_id" | "type" | "name" | "text" | "meta" | "description" | "is_exported" | "state" | "error"
|
|
2954
|
+
type SearchOptions = {
|
|
2955
|
+
select?: Array<SymbolField>
|
|
2956
|
+
limit?: number
|
|
2957
|
+
offset?: number
|
|
2958
|
+
where?: Record<SymbolField, string | { contains: string } | { starts_with: string } | { ends_with: string }>
|
|
2959
|
+
order_by?: [SymbolField, 'asc' | 'desc']
|
|
2960
|
+
}
|
|
2961
|
+
|
|
2962
|
+
<relation-options> is a JSON string following the type RelationOptions:
|
|
2963
|
+
|
|
2964
|
+
type RelationOptions = {
|
|
2965
|
+
select?: Array<SymbolField>
|
|
2966
|
+
limit?: number
|
|
2967
|
+
offset?: number
|
|
2968
|
+
deep?: boolean
|
|
2969
|
+
}
|
|
2970
|
+
|
|
2971
|
+
Examples:
|
|
2972
|
+
codewiki symbols search '{"limit": 10}'
|
|
2973
|
+
codewiki symbols search '{"where": {"type": "function"}, "limit": 5}'
|
|
2974
|
+
codewiki symbols search '{"where": {"name": {"starts_with": "test"}}, "limit": 10}'
|
|
2975
|
+
codewiki symbols referencing-symbol 123 '{"limit": 10}'
|
|
2976
|
+
`);
|
|
2977
|
+
|
|
2978
|
+
// src/cli/commands/directories/index.ts
|
|
2979
|
+
var import_commander23 = require("commander");
|
|
2980
|
+
var import_dedent5 = __toESM(require("dedent"), 1);
|
|
2981
|
+
|
|
2982
|
+
// src/cli/commands/directories/get.ts
|
|
2983
|
+
var import_commander18 = require("commander");
|
|
2984
|
+
var get8 = new import_commander18.Command("get");
|
|
2985
|
+
get8.description("Get a directory by ID");
|
|
2986
|
+
get8.argument("<id>", "Directory ID");
|
|
2987
|
+
get8.action(async (id) => {
|
|
2988
|
+
const wiki = await load_wiki();
|
|
2989
|
+
const directory = wiki.directories.get(Number(id));
|
|
2990
|
+
env.log(JSON.stringify(directory, null, 2));
|
|
2991
|
+
});
|
|
2992
|
+
|
|
2993
|
+
// src/cli/commands/directories/search.ts
|
|
2994
|
+
var import_commander19 = require("commander");
|
|
2995
|
+
var search11 = new import_commander19.Command("search");
|
|
2996
|
+
search11.description("Search directories with JSON options");
|
|
2997
|
+
search11.argument("<options>", "JSON options");
|
|
2998
|
+
search11.action(async (options_json) => {
|
|
2999
|
+
const wiki = await load_wiki();
|
|
3000
|
+
const options = parse_options(options_json, DirectorySearchOptions, "directories search");
|
|
3001
|
+
const results = wiki.directories.search(options);
|
|
3002
|
+
env.log(JSON.stringify(results, null, 2));
|
|
3003
|
+
});
|
|
3004
|
+
|
|
3005
|
+
// src/cli/commands/directories/set-description.ts
|
|
3006
|
+
var import_fs5 = require("fs");
|
|
3007
|
+
var import_commander20 = require("commander");
|
|
3008
|
+
var set_description7 = new import_commander20.Command("set-description");
|
|
3009
|
+
set_description7.description("Set description for a directory");
|
|
3010
|
+
set_description7.argument("<directory-id>", "Directory ID");
|
|
3011
|
+
set_description7.argument("<markdown-file>", "Path to markdown file");
|
|
3012
|
+
set_description7.action(async (id, file) => {
|
|
3013
|
+
const wiki = await load_wiki();
|
|
3014
|
+
try {
|
|
3015
|
+
const content = (0, import_fs5.readFileSync)(file, "utf-8");
|
|
3016
|
+
wiki.directories.set_description(Number(id), content);
|
|
3017
|
+
env.log("Description saved. Run `codewiki describe` to describe the next item.");
|
|
3018
|
+
} catch (err2) {
|
|
3019
|
+
env.error(`Error: ${err2.message}`);
|
|
3020
|
+
env.exit(1);
|
|
3021
|
+
}
|
|
3022
|
+
});
|
|
3023
|
+
|
|
3024
|
+
// src/cli/commands/directories/children.ts
|
|
3025
|
+
var import_commander21 = require("commander");
|
|
3026
|
+
var children2 = new import_commander21.Command("children");
|
|
3027
|
+
children2.description("Child directories of the given directory");
|
|
3028
|
+
children2.argument("<parent-id>", "Parent directory ID");
|
|
3029
|
+
children2.argument("<options>", "JSON options");
|
|
3030
|
+
children2.action(async (parent_id, options_json) => {
|
|
3031
|
+
const wiki = await load_wiki();
|
|
3032
|
+
const options = parse_options(options_json, DirectoryRelationOptions, "directories children");
|
|
3033
|
+
const results = wiki.directories.children(Number(parent_id), options);
|
|
3034
|
+
env.log(JSON.stringify(results, null, 2));
|
|
3035
|
+
});
|
|
3036
|
+
|
|
3037
|
+
// src/cli/commands/directories/files.ts
|
|
3038
|
+
var import_commander22 = require("commander");
|
|
3039
|
+
var files4 = new import_commander22.Command("files");
|
|
3040
|
+
files4.description("Files in the given directory");
|
|
3041
|
+
files4.argument("<directory-id>", "Directory ID");
|
|
3042
|
+
files4.argument("<options>", "JSON options");
|
|
3043
|
+
files4.action(async (directory_id, options_json) => {
|
|
3044
|
+
const wiki = await load_wiki();
|
|
3045
|
+
const options = parse_options(options_json, FileRelationOptions, "directories files");
|
|
3046
|
+
const results = wiki.directories.files(Number(directory_id), options);
|
|
3047
|
+
env.log(JSON.stringify(results, null, 2));
|
|
3048
|
+
});
|
|
3049
|
+
|
|
3050
|
+
// src/cli/commands/directories/index.ts
|
|
3051
|
+
var directories3 = new import_commander23.Command("directories");
|
|
3052
|
+
directories3.description("Explore directories");
|
|
3053
|
+
directories3.addCommand(get8);
|
|
3054
|
+
directories3.addCommand(search11);
|
|
3055
|
+
directories3.addCommand(set_description7);
|
|
3056
|
+
directories3.addCommand(children2);
|
|
3057
|
+
directories3.addCommand(files4);
|
|
3058
|
+
directories3.addHelpText("after", import_dedent5.default`
|
|
3059
|
+
|
|
3060
|
+
<search-options> is a JSON string following the type SearchOptions:
|
|
3061
|
+
|
|
3062
|
+
type DirectoryField = "id" | "parent_id" | "path" | "description" | "state" | "error"
|
|
3063
|
+
type SearchOptions = {
|
|
3064
|
+
select?: Array<DirectoryField>
|
|
3065
|
+
limit?: number
|
|
3066
|
+
offset?: number
|
|
3067
|
+
where?: Record<DirectoryField, string | { contains: string } | { starts_with: string } | { ends_with: string }>
|
|
3068
|
+
order_by?: [DirectoryField, 'asc' | 'desc']
|
|
3069
|
+
}
|
|
3070
|
+
|
|
3071
|
+
<relation-options> is a JSON string following the type RelationOptions:
|
|
3072
|
+
|
|
3073
|
+
type RelationOptions = {
|
|
3074
|
+
select?: Array<DirectoryField> | Array<FileField>
|
|
3075
|
+
limit?: number
|
|
3076
|
+
offset?: number
|
|
3077
|
+
deep?: boolean
|
|
3078
|
+
}
|
|
3079
|
+
|
|
3080
|
+
Examples:
|
|
3081
|
+
codewiki directories search '{"limit": 10}'
|
|
3082
|
+
codewiki directories search '{"where": {"path": {"contains": "src"}}, "limit": 5}'
|
|
3083
|
+
codewiki directories children 123 '{"limit": 10, "deep": true}'
|
|
3084
|
+
codewiki directories files 123 '{"limit": 20}'
|
|
3085
|
+
`);
|
|
3086
|
+
|
|
3087
|
+
// src/cli/commands/dependencies/index.ts
|
|
3088
|
+
var import_commander29 = require("commander");
|
|
3089
|
+
var import_dedent6 = __toESM(require("dedent"), 1);
|
|
3090
|
+
|
|
3091
|
+
// src/cli/commands/dependencies/get.ts
|
|
3092
|
+
var import_commander24 = require("commander");
|
|
3093
|
+
var get9 = new import_commander24.Command("get");
|
|
3094
|
+
get9.description("Get a dependency by ID");
|
|
3095
|
+
get9.argument("<id>", "Dependency ID");
|
|
3096
|
+
get9.action(async (id) => {
|
|
3097
|
+
const wiki = await load_wiki();
|
|
3098
|
+
const dependency = wiki.dependencies.get(Number(id));
|
|
3099
|
+
env.log(JSON.stringify(dependency, null, 2));
|
|
3100
|
+
});
|
|
3101
|
+
|
|
3102
|
+
// src/cli/commands/dependencies/search.ts
|
|
3103
|
+
var import_commander25 = require("commander");
|
|
3104
|
+
var search12 = new import_commander25.Command("search");
|
|
3105
|
+
search12.description("Search dependencies with JSON options");
|
|
3106
|
+
search12.argument("<options>", "JSON options");
|
|
3107
|
+
search12.action(async (options_json) => {
|
|
3108
|
+
const wiki = await load_wiki();
|
|
3109
|
+
const options = parse_options(options_json, DependencySearchOptions, "dependencies search");
|
|
3110
|
+
const results = wiki.dependencies.search(options);
|
|
3111
|
+
env.log(JSON.stringify(results, null, 2));
|
|
3112
|
+
});
|
|
3113
|
+
|
|
3114
|
+
// src/cli/commands/dependencies/set-description.ts
|
|
3115
|
+
var import_fs6 = require("fs");
|
|
3116
|
+
var import_commander26 = require("commander");
|
|
3117
|
+
var set_description8 = new import_commander26.Command("set-description");
|
|
3118
|
+
set_description8.description("Set description for a dependency");
|
|
3119
|
+
set_description8.argument("<dependency-id>", "Dependency ID");
|
|
3120
|
+
set_description8.argument("<markdown-file>", "Path to markdown file");
|
|
3121
|
+
set_description8.action(async (id, file) => {
|
|
3122
|
+
const wiki = await load_wiki();
|
|
3123
|
+
try {
|
|
3124
|
+
const content = (0, import_fs6.readFileSync)(file, "utf-8");
|
|
3125
|
+
wiki.dependencies.set_description(Number(id), content);
|
|
3126
|
+
env.log("Description saved. Run `codewiki describe` to describe the next item.");
|
|
3127
|
+
} catch (err2) {
|
|
3128
|
+
env.error(`Error: ${err2.message}`);
|
|
3129
|
+
env.exit(1);
|
|
3130
|
+
}
|
|
3131
|
+
});
|
|
3132
|
+
|
|
3133
|
+
// src/cli/commands/dependencies/used-by-file.ts
|
|
3134
|
+
var import_commander27 = require("commander");
|
|
3135
|
+
var used_by_file3 = new import_commander27.Command("used-by-file");
|
|
3136
|
+
used_by_file3.description("Dependencies used by the given file");
|
|
3137
|
+
used_by_file3.argument("<file-id>", "File ID");
|
|
3138
|
+
used_by_file3.argument("<options>", "JSON options");
|
|
3139
|
+
used_by_file3.action(async (file_id, options_json) => {
|
|
3140
|
+
const wiki = await load_wiki();
|
|
3141
|
+
const options = parse_options(options_json, DependencySelectOptions, "dependencies used-by-file");
|
|
3142
|
+
const results = wiki.dependencies.used_by_file(Number(file_id), options);
|
|
3143
|
+
env.log(JSON.stringify(results, null, 2));
|
|
3144
|
+
});
|
|
3145
|
+
|
|
3146
|
+
// src/cli/commands/dependencies/used-by-symbol.ts
|
|
3147
|
+
var import_commander28 = require("commander");
|
|
3148
|
+
var used_by_symbol3 = new import_commander28.Command("used-by-symbol");
|
|
3149
|
+
used_by_symbol3.description("Dependencies used by the given symbol");
|
|
3150
|
+
used_by_symbol3.argument("<symbol-id>", "Symbol ID");
|
|
3151
|
+
used_by_symbol3.argument("<options>", "JSON options");
|
|
3152
|
+
used_by_symbol3.action(async (symbol_id, options_json) => {
|
|
3153
|
+
const wiki = await load_wiki();
|
|
3154
|
+
const options = parse_options(options_json, DependencySelectOptions, "dependencies used-by-symbol");
|
|
3155
|
+
const results = wiki.dependencies.used_by_symbol(Number(symbol_id), options);
|
|
3156
|
+
env.log(JSON.stringify(results, null, 2));
|
|
3157
|
+
});
|
|
3158
|
+
|
|
3159
|
+
// src/cli/commands/dependencies/index.ts
|
|
3160
|
+
var dependencies = new import_commander29.Command("dependencies");
|
|
3161
|
+
dependencies.description("Explore dependencies");
|
|
3162
|
+
dependencies.addCommand(get9);
|
|
3163
|
+
dependencies.addCommand(search12);
|
|
3164
|
+
dependencies.addCommand(set_description8);
|
|
3165
|
+
dependencies.addCommand(used_by_file3);
|
|
3166
|
+
dependencies.addCommand(used_by_symbol3);
|
|
3167
|
+
dependencies.addHelpText("after", import_dedent6.default`
|
|
3168
|
+
|
|
3169
|
+
<search-options> is a JSON string following the type SearchOptions:
|
|
3170
|
+
|
|
3171
|
+
type DependencyField = "id" | "package" | "subpath" | "name" | "version" | "github_repo" | "is_builtin" | "description" | "state" | "error"
|
|
3172
|
+
type SearchOptions = {
|
|
3173
|
+
select?: Array<DependencyField>
|
|
3174
|
+
limit?: number
|
|
3175
|
+
offset?: number
|
|
3176
|
+
where?: Record<DependencyField, string | { contains: string } | { starts_with: string } | { ends_with: string }>
|
|
3177
|
+
order_by?: [DependencyField, 'asc' | 'desc']
|
|
3178
|
+
}
|
|
3179
|
+
|
|
3180
|
+
<select-options> is a JSON string following the type SelectOptions:
|
|
3181
|
+
|
|
3182
|
+
type SelectOptions = {
|
|
3183
|
+
select?: Array<DependencyField>
|
|
3184
|
+
limit?: number
|
|
3185
|
+
offset?: number
|
|
3186
|
+
}
|
|
3187
|
+
|
|
3188
|
+
Examples:
|
|
3189
|
+
codewiki dependencies search '{"limit": 10}'
|
|
3190
|
+
codewiki dependencies search '{"where": {"is_builtin": false}, "limit": 5}'
|
|
3191
|
+
codewiki dependencies search '{"where": {"package": {"starts_with": "@types"}}, "limit": 10}'
|
|
3192
|
+
codewiki dependencies used-by-file 123 '{"limit": 10}'
|
|
3193
|
+
`);
|
|
3194
|
+
|
|
3195
|
+
// src/cli/commands/index.ts
|
|
3196
|
+
var commands = [update7, status, describe, files3, symbols3, directories3, dependencies];
|
|
3197
|
+
|
|
3198
|
+
// src/cli/index.ts
|
|
3199
|
+
async function run(argv) {
|
|
3200
|
+
const program = new import_commander30.Command();
|
|
3201
|
+
program.name("codewiki").description("Describe and explore TypeScript codebases").version("0.0.1");
|
|
3202
|
+
for (const cmd of commands) program.addCommand(cmd);
|
|
3203
|
+
return program.parseAsync(argv, { from: "user" });
|
|
3204
|
+
}
|
|
3205
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
3206
|
+
0 && (module.exports = {
|
|
3207
|
+
run
|
|
3208
|
+
});
|
|
3209
|
+
//# sourceMappingURL=index.cjs.map
|