hikoutei 0.10.22-dev → 0.10.24-dev
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/dist/api/Hikoutei.d.ts.map +1 -1
- package/dist/api/Hikoutei.js +8 -4
- package/dist/api/Hikoutei.js.map +1 -1
- package/dist/api/index.d.ts +2 -2
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +1 -1
- package/dist/api/index.js.map +1 -1
- package/dist/api/syncRuntime.d.ts +8 -1
- package/dist/api/syncRuntime.d.ts.map +1 -1
- package/dist/api/syncRuntime.js +5 -0
- package/dist/api/syncRuntime.js.map +1 -1
- package/dist/cli/adoptArgs.d.ts +8 -0
- package/dist/cli/adoptArgs.d.ts.map +1 -1
- package/dist/cli/adoptArgs.js +40 -12
- package/dist/cli/adoptArgs.js.map +1 -1
- package/dist/cli/adoptMain.d.ts +17 -0
- package/dist/cli/adoptMain.d.ts.map +1 -1
- package/dist/cli/adoptMain.js +76 -5
- package/dist/cli/adoptMain.js.map +1 -1
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +5 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/infer.d.ts +118 -0
- package/dist/cli/infer.d.ts.map +1 -0
- package/dist/cli/infer.js +319 -0
- package/dist/cli/infer.js.map +1 -0
- package/dist/cli/inferArgs.d.ts +54 -0
- package/dist/cli/inferArgs.d.ts.map +1 -0
- package/dist/cli/inferArgs.js +123 -0
- package/dist/cli/inferArgs.js.map +1 -0
- package/dist/cli/inferMain.d.ts +66 -0
- package/dist/cli/inferMain.d.ts.map +1 -0
- package/dist/cli/inferMain.js +281 -0
- package/dist/cli/inferMain.js.map +1 -0
- package/dist/composition/localRuntime.d.ts.map +1 -1
- package/dist/composition/localRuntime.js +3 -1
- package/dist/composition/localRuntime.js.map +1 -1
- package/dist/contracts/api/descriptorFile.d.ts +116 -0
- package/dist/contracts/api/descriptorFile.d.ts.map +1 -0
- package/dist/contracts/api/descriptorFile.js +179 -0
- package/dist/contracts/api/descriptorFile.js.map +1 -0
- package/dist/{sheets/providers/google-sheets-api → contracts/sheets}/model/conflictProjection.d.ts +3 -3
- package/dist/contracts/sheets/model/conflictProjection.d.ts.map +1 -0
- package/dist/{sheets/providers/google-sheets-api → contracts/sheets}/model/conflictProjection.js +4 -4
- package/dist/contracts/sheets/model/conflictProjection.js.map +1 -0
- package/dist/contracts/sheets/timing.d.ts +33 -4
- package/dist/contracts/sheets/timing.d.ts.map +1 -1
- package/dist/contracts/sheets/timing.js +14 -4
- package/dist/contracts/sheets/timing.js.map +1 -1
- package/dist/sync/inbound/autoSystemConflictResolution.js +1 -1
- package/dist/sync/inbound/autoSystemConflictResolution.js.map +1 -1
- package/dist/sync-engine/api/entity.d.ts +1 -0
- package/dist/sync-engine/api/entity.d.ts.map +1 -1
- package/dist/sync-engine/api/entity.js +1 -0
- package/dist/sync-engine/api/entity.js.map +1 -1
- package/dist/sync-engine/api/hikouteiCore.d.ts +31 -1
- package/dist/sync-engine/api/hikouteiCore.d.ts.map +1 -1
- package/dist/sync-engine/api/hikouteiCore.js +29 -0
- package/dist/sync-engine/api/hikouteiCore.js.map +1 -1
- package/dist/sync-engine/sync/service/syncAutoStart.d.ts +8 -1
- package/dist/sync-engine/sync/service/syncAutoStart.d.ts.map +1 -1
- package/dist/sync-engine/sync/service/syncAutoStart.js +14 -7
- package/dist/sync-engine/sync/service/syncAutoStart.js.map +1 -1
- package/dist/sync-engine/sync/sheetsContract/conflictProjectionRegistration.js +1 -1
- package/dist/sync-engine/sync/sheetsContract/conflictProjectionRegistration.js.map +1 -1
- package/package.json +1 -1
- package/dist/sheets/providers/google-sheets-api/model/conflictProjection.d.ts.map +0 -1
- package/dist/sheets/providers/google-sheets-api/model/conflictProjection.js.map +0 -1
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Production wiring for `hikoutei infer`.
|
|
3
|
+
*
|
|
4
|
+
* Owns the real-world dependencies the pure core avoids: resolving the
|
|
5
|
+
* spreadsheet id and credentials, reading one tab range through the Sheets
|
|
6
|
+
* API (read-only — no writes, no provisioning), and mapping outcomes to
|
|
7
|
+
* exit codes. Tests drive `runInferCli` with a fake reader and never touch
|
|
8
|
+
* the network or credentials.
|
|
9
|
+
*
|
|
10
|
+
* Exit codes: 0 success, 1 runtime failure (tab not found, empty tab,
|
|
11
|
+
* missing credentials, read failure), 2 argument errors.
|
|
12
|
+
*/
|
|
13
|
+
import { type InferOptions } from "./inferArgs.js";
|
|
14
|
+
import { type InferTabGrid, type InferTabReader } from "./infer.js";
|
|
15
|
+
export interface RunInferCliInput {
|
|
16
|
+
readonly options: InferOptions;
|
|
17
|
+
readonly env: Readonly<Record<string, string | undefined>>;
|
|
18
|
+
readonly reader: InferTabReader;
|
|
19
|
+
readonly output: {
|
|
20
|
+
readonly write: (text: string) => void;
|
|
21
|
+
};
|
|
22
|
+
readonly error: {
|
|
23
|
+
readonly write: (text: string) => void;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Runs the infer flow. Never throws: every failure becomes a non-zero exit
|
|
28
|
+
* code with a machine-readable `hikoutei-infer:<code>:` line on stderr.
|
|
29
|
+
*/
|
|
30
|
+
export declare function runInferCli(input: RunInferCliInput): Promise<number>;
|
|
31
|
+
/**
|
|
32
|
+
* Writes the descriptor-file JSON text to `path`.
|
|
33
|
+
*
|
|
34
|
+
* Parent directories are never created: a missing parent fails with
|
|
35
|
+
* `emit_parent_missing`. An existing file is left untouched unless `force`
|
|
36
|
+
* is set (`emit_exists` otherwise). Throws `InferError` with a stable code
|
|
37
|
+
* so the flow maps it to the machine-readable stderr line; the path itself
|
|
38
|
+
* is never echoed (it may embed user directory layout).
|
|
39
|
+
*/
|
|
40
|
+
export declare function emitDescriptorFile(path: string, json: string, options: {
|
|
41
|
+
readonly force: boolean;
|
|
42
|
+
}): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Extracts the spreadsheet ID from a Google Sheets URL.
|
|
45
|
+
*
|
|
46
|
+
* Accepts `/spreadsheets/d/<ID>` and a top-level `/d/<ID>` right after the
|
|
47
|
+
* host (with query/fragment/trailing suffixes tolerated); anything deeper
|
|
48
|
+
* (e.g. `/document/d/<ID>`) is rejected. Mirrors the sync engine's
|
|
49
|
+
* `parseSpreadsheetIdFromUrl` without importing its module graph.
|
|
50
|
+
*/
|
|
51
|
+
export declare function parseInferSpreadsheetId(url: string): string | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Validates the raw `spreadsheets.get` grid payload for one tab.
|
|
54
|
+
*
|
|
55
|
+
* Untrusted SDK data: the response must list the requested tab and carry
|
|
56
|
+
* grid rows; a tab without a header row is `empty_tab`. Throws `InferError`
|
|
57
|
+
* (`tab_not_found`, `empty_tab`, `malformed_grid`); never echoes payloads.
|
|
58
|
+
*/
|
|
59
|
+
export declare function extractInferGrid(data: unknown, tabName: string, limit: number): InferTabGrid;
|
|
60
|
+
/**
|
|
61
|
+
* Runs the `hikoutei infer` CLI with the given argument vector (without the
|
|
62
|
+
* leading "infer" subcommand). Exported so the bin router can delegate and
|
|
63
|
+
* tests can drive it with injected argv.
|
|
64
|
+
*/
|
|
65
|
+
export declare function runInferMain(argv: readonly string[]): Promise<number>;
|
|
66
|
+
//# sourceMappingURL=inferMain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inferMain.d.ts","sourceRoot":"","sources":["../../../../../../src/inferMain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAOH,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAKL,KAAK,YAAY,EACjB,KAAK,cAAc,EACpB,MAAM,YAAY,CAAC;AASpB,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;IAC/B,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;IAC3D,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAChC,QAAQ,CAAC,MAAM,EAAE;QAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;KAAE,CAAC;IAC5D,QAAQ,CAAC,KAAK,EAAE;QAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;KAAE,CAAC;CAC5D;AAED;;;GAGG;AACH,wBAAsB,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,CAkD1E;AAED;;;;;;;;GAQG;AACH,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE;IAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GACnC,OAAO,CAAC,IAAI,CAAC,CAmBf;AA2BD;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAYvE;AAmDD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,YAAY,CAmC5F;AAED;;;;GAIG;AACH,wBAAsB,YAAY,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CA6B3E"}
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Production wiring for `hikoutei infer`.
|
|
3
|
+
*
|
|
4
|
+
* Owns the real-world dependencies the pure core avoids: resolving the
|
|
5
|
+
* spreadsheet id and credentials, reading one tab range through the Sheets
|
|
6
|
+
* API (read-only — no writes, no provisioning), and mapping outcomes to
|
|
7
|
+
* exit codes. Tests drive `runInferCli` with a fake reader and never touch
|
|
8
|
+
* the network or credentials.
|
|
9
|
+
*
|
|
10
|
+
* Exit codes: 0 success, 1 runtime failure (tab not found, empty tab,
|
|
11
|
+
* missing credentials, read failure), 2 argument errors.
|
|
12
|
+
*/
|
|
13
|
+
import { access, writeFile } from "node:fs/promises";
|
|
14
|
+
import { GoogleAuth } from "google-auth-library";
|
|
15
|
+
import { sheets } from "@googleapis/sheets";
|
|
16
|
+
import { parseInferArgs } from "./inferArgs.js";
|
|
17
|
+
import { INFER_ERROR_PREFIX, inferFromGrid, InferError, serializeInferDescriptorFile, } from "./infer.js";
|
|
18
|
+
import { SETUP_ARG_ERROR_EXIT_CODE, SETUP_RUNTIME_ERROR_EXIT_CODE, } from "./errors.js";
|
|
19
|
+
import { httpStatusOf } from "./sdkError.js";
|
|
20
|
+
import { SPREADSHEETS_SCOPE } from "./sheetsFactory.js";
|
|
21
|
+
import { isModuleMainEntry } from "./setup.js";
|
|
22
|
+
/**
|
|
23
|
+
* Runs the infer flow. Never throws: every failure becomes a non-zero exit
|
|
24
|
+
* code with a machine-readable `hikoutei-infer:<code>:` line on stderr.
|
|
25
|
+
*/
|
|
26
|
+
export async function runInferCli(input) {
|
|
27
|
+
const spreadsheetUrl = input.options.spreadsheetUrl ?? input.env.HIKOUTEI_SYNC_SPREADSHEET_URL;
|
|
28
|
+
if (spreadsheetUrl === undefined || spreadsheetUrl.trim() === "") {
|
|
29
|
+
input.error.write(`${INFER_ERROR_PREFIX}:invalid_args: missing spreadsheet URL — pass --spreadsheet <url> or set HIKOUTEI_SYNC_SPREADSHEET_URL.\n`);
|
|
30
|
+
return SETUP_ARG_ERROR_EXIT_CODE;
|
|
31
|
+
}
|
|
32
|
+
const spreadsheetId = parseInferSpreadsheetId(spreadsheetUrl);
|
|
33
|
+
if (spreadsheetId === undefined) {
|
|
34
|
+
input.error.write(`${INFER_ERROR_PREFIX}:spreadsheet_url_invalid: could not extract a spreadsheet ID — expected a URL of the form https://docs.google.com/spreadsheets/d/<SPREADSHEET_ID>/edit.\n`);
|
|
35
|
+
return SETUP_RUNTIME_ERROR_EXIT_CODE;
|
|
36
|
+
}
|
|
37
|
+
const credentialsPath = input.options.credentialsPath ?? input.env.GOOGLE_APPLICATION_CREDENTIALS;
|
|
38
|
+
if (credentialsPath === undefined || credentialsPath.trim() === "") {
|
|
39
|
+
input.error.write(`${INFER_ERROR_PREFIX}:missing_credentials: no service-account credentials found — pass --credentials <path> or set GOOGLE_APPLICATION_CREDENTIALS (run \`npx hikoutei setup\` to provision them).\n`);
|
|
40
|
+
return SETUP_RUNTIME_ERROR_EXIT_CODE;
|
|
41
|
+
}
|
|
42
|
+
let grid;
|
|
43
|
+
try {
|
|
44
|
+
grid = await input.reader({ spreadsheetId, tabName: input.options.tabName, limit: input.options.limit });
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
return reportInferError(input, error);
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
const result = inferFromGrid(grid, { ...(input.options.pkHeader === undefined ? {} : { pkHeader: input.options.pkHeader }) });
|
|
51
|
+
// Stdout contract is unchanged (block + summary); `--emit` only adds
|
|
52
|
+
// the descriptor-file side effect below.
|
|
53
|
+
input.output.write(`${result.tsBlock}\n\n${result.summary}\n`);
|
|
54
|
+
if (input.options.emitPath !== undefined) {
|
|
55
|
+
try {
|
|
56
|
+
await emitDescriptorFile(input.options.emitPath, serializeInferDescriptorFile(result), { force: input.options.force });
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
return reportInferError(input, error);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return 0;
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
return reportInferError(input, error);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Writes the descriptor-file JSON text to `path`.
|
|
70
|
+
*
|
|
71
|
+
* Parent directories are never created: a missing parent fails with
|
|
72
|
+
* `emit_parent_missing`. An existing file is left untouched unless `force`
|
|
73
|
+
* is set (`emit_exists` otherwise). Throws `InferError` with a stable code
|
|
74
|
+
* so the flow maps it to the machine-readable stderr line; the path itself
|
|
75
|
+
* is never echoed (it may embed user directory layout).
|
|
76
|
+
*/
|
|
77
|
+
export async function emitDescriptorFile(path, json, options) {
|
|
78
|
+
try {
|
|
79
|
+
await writeFile(path, json, options.force ? {} : { flag: "wx" });
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
const code = error?.code;
|
|
83
|
+
if (code === "ENOENT") {
|
|
84
|
+
throw new InferError("emit_parent_missing", "could not write the descriptor file — the parent directory does not exist.");
|
|
85
|
+
}
|
|
86
|
+
if (code === "EEXIST") {
|
|
87
|
+
throw new InferError("emit_exists", "the descriptor file already exists — pass --force to overwrite it.");
|
|
88
|
+
}
|
|
89
|
+
throw new InferError("emit_write_failed", "could not write the descriptor file.");
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/** Maps an infer failure to the machine-readable CLI error line. */
|
|
93
|
+
function reportInferError(input, error) {
|
|
94
|
+
const code = error instanceof InferError
|
|
95
|
+
? error.code
|
|
96
|
+
: typeof error?.code === "string"
|
|
97
|
+
? error.code
|
|
98
|
+
: "unexpected";
|
|
99
|
+
if (code === "invalid_args" || code === "pk_not_found") {
|
|
100
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
101
|
+
input.error.write(`${INFER_ERROR_PREFIX}:${code === "pk_not_found" ? "invalid_args" : code}: ${message}\n`);
|
|
102
|
+
return SETUP_ARG_ERROR_EXIT_CODE;
|
|
103
|
+
}
|
|
104
|
+
if (error instanceof InferError) {
|
|
105
|
+
input.error.write(`${INFER_ERROR_PREFIX}:${error.code}: ${error.message}\n`);
|
|
106
|
+
return SETUP_RUNTIME_ERROR_EXIT_CODE;
|
|
107
|
+
}
|
|
108
|
+
// Uncoded reader/SDK failures carry no safe detail (messages may embed
|
|
109
|
+
// URLs or key material), so report the bare HTTP status when one exists.
|
|
110
|
+
const status = httpStatusOf(error);
|
|
111
|
+
input.error.write(`${INFER_ERROR_PREFIX}:${code}: ${status === undefined ? "could not sample the tab" : `sheet read failed with HTTP ${status}`}.\n`);
|
|
112
|
+
return SETUP_RUNTIME_ERROR_EXIT_CODE;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Extracts the spreadsheet ID from a Google Sheets URL.
|
|
116
|
+
*
|
|
117
|
+
* Accepts `/spreadsheets/d/<ID>` and a top-level `/d/<ID>` right after the
|
|
118
|
+
* host (with query/fragment/trailing suffixes tolerated); anything deeper
|
|
119
|
+
* (e.g. `/document/d/<ID>`) is rejected. Mirrors the sync engine's
|
|
120
|
+
* `parseSpreadsheetIdFromUrl` without importing its module graph.
|
|
121
|
+
*/
|
|
122
|
+
export function parseInferSpreadsheetId(url) {
|
|
123
|
+
if (typeof url !== "string" || url.trim() === "")
|
|
124
|
+
return undefined;
|
|
125
|
+
const withoutScheme = url.replace(/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//, "");
|
|
126
|
+
const path = withoutScheme.split(/[?#]/, 1)[0] ?? "";
|
|
127
|
+
const segments = path.split("/");
|
|
128
|
+
const dIndex = segments.findIndex((segment) => segment === "d");
|
|
129
|
+
if (dIndex < 0)
|
|
130
|
+
return undefined;
|
|
131
|
+
const previous = segments[dIndex - 1];
|
|
132
|
+
if (previous !== "spreadsheets" && dIndex !== 1)
|
|
133
|
+
return undefined;
|
|
134
|
+
const id = segments[dIndex + 1];
|
|
135
|
+
if (id === undefined || id.length === 0 || /[\s?#]/.test(id))
|
|
136
|
+
return undefined;
|
|
137
|
+
return id;
|
|
138
|
+
}
|
|
139
|
+
/** Quotes a tab name for A1-notation ranges (single quotes doubled). */
|
|
140
|
+
function quoteA1TabName(tabName) {
|
|
141
|
+
return `'${tabName.replace(/'/g, "''")}'`;
|
|
142
|
+
}
|
|
143
|
+
/** Production reader: one read-only tab-range fetch through the Sheets API. */
|
|
144
|
+
async function createSheetsTabReader(credentialsPath) {
|
|
145
|
+
try {
|
|
146
|
+
await access(credentialsPath);
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
throw new InferError("missing_credentials", `cannot read the credentials file — check the path or run \`npx hikoutei setup\`.`);
|
|
150
|
+
}
|
|
151
|
+
// The boundary cast keeps any google-auth-library version mismatch between
|
|
152
|
+
// the top-level package and googleapis-common contained in this module.
|
|
153
|
+
const auth = new GoogleAuth({
|
|
154
|
+
keyFile: credentialsPath,
|
|
155
|
+
scopes: [SPREADSHEETS_SCOPE],
|
|
156
|
+
});
|
|
157
|
+
const client = sheets({ version: "v4", auth });
|
|
158
|
+
return async (input) => {
|
|
159
|
+
let data;
|
|
160
|
+
try {
|
|
161
|
+
const response = await client.spreadsheets.get({
|
|
162
|
+
spreadsheetId: input.spreadsheetId,
|
|
163
|
+
includeGridData: true,
|
|
164
|
+
ranges: [`${quoteA1TabName(input.tabName)}!A1:ZZ${input.limit + 1}`],
|
|
165
|
+
fields: "sheets(properties.title,data.rowData.values(userEnteredValue,effectiveValue,formattedValue,userEnteredFormat.numberFormat,effectiveFormat.numberFormat))",
|
|
166
|
+
});
|
|
167
|
+
data = response.data;
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
// A bad range is how the API reports an unknown tab (400); a missing
|
|
171
|
+
// spreadsheet surfaces as 404. Anything else is a read failure whose
|
|
172
|
+
// raw detail is never echoed (it may embed URLs or key material).
|
|
173
|
+
const status = httpStatusOf(error);
|
|
174
|
+
if (status === 400 || status === 404) {
|
|
175
|
+
throw new InferError("tab_not_found", `Tab "${input.tabName}" was not found in the spreadsheet.`);
|
|
176
|
+
}
|
|
177
|
+
throw new InferError("read_failed", status === undefined ? "could not sample the tab" : `sheet read failed with HTTP ${status}`);
|
|
178
|
+
}
|
|
179
|
+
return extractInferGrid(data, input.tabName, input.limit);
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Validates the raw `spreadsheets.get` grid payload for one tab.
|
|
184
|
+
*
|
|
185
|
+
* Untrusted SDK data: the response must list the requested tab and carry
|
|
186
|
+
* grid rows; a tab without a header row is `empty_tab`. Throws `InferError`
|
|
187
|
+
* (`tab_not_found`, `empty_tab`, `malformed_grid`); never echoes payloads.
|
|
188
|
+
*/
|
|
189
|
+
export function extractInferGrid(data, tabName, limit) {
|
|
190
|
+
if (!isRecord(data))
|
|
191
|
+
throw new InferError("malformed_grid", "the sheet read returned a non-object payload");
|
|
192
|
+
const sheetsValue = data.sheets;
|
|
193
|
+
if (!Array.isArray(sheetsValue) || sheetsValue.length === 0) {
|
|
194
|
+
throw new InferError("tab_not_found", `Tab "${tabName}" was not found in the spreadsheet.`);
|
|
195
|
+
}
|
|
196
|
+
const sheet = sheetsValue.find((entry) => isRecord(entry) && isRecord(entry.properties) && entry.properties.title === tabName);
|
|
197
|
+
if (sheet === undefined || !isRecord(sheet)) {
|
|
198
|
+
throw new InferError("tab_not_found", `Tab "${tabName}" was not found in the spreadsheet.`);
|
|
199
|
+
}
|
|
200
|
+
const gridData = sheet.data;
|
|
201
|
+
if (!Array.isArray(gridData) || gridData.length === 0) {
|
|
202
|
+
throw new InferError("empty_tab", `Tab "${tabName}" has no header row.`);
|
|
203
|
+
}
|
|
204
|
+
const rowData = [];
|
|
205
|
+
for (const grid of gridData) {
|
|
206
|
+
if (!isRecord(grid) || grid.rowData === undefined)
|
|
207
|
+
continue;
|
|
208
|
+
if (!Array.isArray(grid.rowData))
|
|
209
|
+
throw new InferError("malformed_grid", "the sheet read returned a malformed grid");
|
|
210
|
+
rowData.push(...grid.rowData);
|
|
211
|
+
}
|
|
212
|
+
if (rowData.length === 0) {
|
|
213
|
+
throw new InferError("empty_tab", `Tab "${tabName}" has no header row.`);
|
|
214
|
+
}
|
|
215
|
+
const first = rowData[0];
|
|
216
|
+
if (!isRecord(first) || !Array.isArray(first.values)) {
|
|
217
|
+
throw new InferError("empty_tab", `Tab "${tabName}" has no header row.`);
|
|
218
|
+
}
|
|
219
|
+
return {
|
|
220
|
+
tabName,
|
|
221
|
+
headerCells: first.values,
|
|
222
|
+
dataCells: rowData.slice(1, limit + 1).map((row) => {
|
|
223
|
+
if (!isRecord(row))
|
|
224
|
+
return [];
|
|
225
|
+
return Array.isArray(row.values) ? row.values : [];
|
|
226
|
+
}),
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Runs the `hikoutei infer` CLI with the given argument vector (without the
|
|
231
|
+
* leading "infer" subcommand). Exported so the bin router can delegate and
|
|
232
|
+
* tests can drive it with injected argv.
|
|
233
|
+
*/
|
|
234
|
+
export async function runInferMain(argv) {
|
|
235
|
+
const parsed = parseInferArgs(argv);
|
|
236
|
+
if (parsed.status === "help") {
|
|
237
|
+
process.stdout.write(`${parsed.helpText}\n`);
|
|
238
|
+
return 0;
|
|
239
|
+
}
|
|
240
|
+
if (parsed.status === "invalid") {
|
|
241
|
+
process.stderr.write(`${INFER_ERROR_PREFIX}:${parsed.failure.code}: ${parsed.failure.message}\n`);
|
|
242
|
+
process.stderr.write("Run `hikoutei infer --help` for usage.\n");
|
|
243
|
+
return SETUP_ARG_ERROR_EXIT_CODE;
|
|
244
|
+
}
|
|
245
|
+
const options = parsed.options;
|
|
246
|
+
try {
|
|
247
|
+
const credentialsPath = options.credentialsPath ?? process.env.GOOGLE_APPLICATION_CREDENTIALS;
|
|
248
|
+
if (credentialsPath === undefined || credentialsPath.trim() === "") {
|
|
249
|
+
process.stderr.write(`${INFER_ERROR_PREFIX}:missing_credentials: no service-account credentials found — pass --credentials <path> or set GOOGLE_APPLICATION_CREDENTIALS (run \`npx hikoutei setup\` to provision them).\n`);
|
|
250
|
+
return SETUP_RUNTIME_ERROR_EXIT_CODE;
|
|
251
|
+
}
|
|
252
|
+
const reader = await createSheetsTabReader(credentialsPath);
|
|
253
|
+
return await runInferCli({ options, env: process.env, reader, output: process.stdout, error: process.stderr });
|
|
254
|
+
}
|
|
255
|
+
catch (error) {
|
|
256
|
+
const code = error instanceof InferError ? error.code : "unexpected";
|
|
257
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
258
|
+
process.stderr.write(`${INFER_ERROR_PREFIX}:${code}: ${message}\n`);
|
|
259
|
+
return SETUP_RUNTIME_ERROR_EXIT_CODE;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
// ESM entrypoint guard: run main() only when this file is the process entry,
|
|
263
|
+
// never when merely imported (see setup.ts for the same pattern).
|
|
264
|
+
if (isModuleMainEntry(process.argv[1], import.meta.url)) {
|
|
265
|
+
runInferMain(process.argv.slice(2))
|
|
266
|
+
.then((code) => {
|
|
267
|
+
process.exitCode = code;
|
|
268
|
+
})
|
|
269
|
+
.catch((error) => {
|
|
270
|
+
process.stderr.write(`${INFER_ERROR_PREFIX}:unexpected: ${safeReason(error)}\n`);
|
|
271
|
+
process.exitCode = SETUP_RUNTIME_ERROR_EXIT_CODE;
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
/** Strict sanitizer: only Error-shaped reasons are ever printed. */
|
|
275
|
+
function safeReason(error) {
|
|
276
|
+
return error instanceof Error ? `${error.name}: ${error.message}` : String(error);
|
|
277
|
+
}
|
|
278
|
+
function isRecord(value) {
|
|
279
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
280
|
+
}
|
|
281
|
+
//# sourceMappingURL=inferMain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inferMain.js","sourceRoot":"","sources":["../../../../../../src/inferMain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,OAAO,EAAE,cAAc,EAAqB,MAAM,gBAAgB,CAAC;AACnE,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,UAAU,EACV,4BAA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QAAQ,GAAG,6BAA6B,CAAC;IACnD,CAAC,CAAC,CAAC;AACP,CAAC;AAED,oEAAoE;AACpE,SAAS,UAAU,CAAC,KAAc;IAChC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACpF,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localRuntime.d.ts","sourceRoot":"","sources":["../../../../../../src/localRuntime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAEL,KAAK,qCAAqC,EAC3C,MAAM,yFAAyF,CAAC;AAUjG,OAAO,KAAK,EACV,+BAA+B,EAChC,MAAM,uCAAuC,CAAC;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAC1E,OAAO,EAGL,KAAK,wBAAwB,EAC7B,KAAK,QAAQ,EACd,MAAM,2CAA2C,CAAC;
|
|
1
|
+
{"version":3,"file":"localRuntime.d.ts","sourceRoot":"","sources":["../../../../../../src/localRuntime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAEL,KAAK,qCAAqC,EAC3C,MAAM,yFAAyF,CAAC;AAUjG,OAAO,KAAK,EACV,+BAA+B,EAChC,MAAM,uCAAuC,CAAC;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAC1E,OAAO,EAGL,KAAK,wBAAwB,EAC7B,KAAK,QAAQ,EACd,MAAM,2CAA2C,CAAC;AAwBnD,mEAAmE;AACnE,MAAM,WAAW,wBAAwB;IACvC,sEAAsE;IACtE,QAAQ,CAAC,SAAS,EAAE,qCAAqC,CAAC;IAC1D,uEAAuE;IACvE,QAAQ,CAAC,iBAAiB,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACjE,mEAAmE;IACnE,QAAQ,CAAC,yBAAyB,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,+BAA+B,CAAC;CAC3F;AAED;;;GAGG;AACH,wBAAsB,8BAA8B,CAClD,QAAQ,EAAE,SAAS,cAAc,EAAE,GAClC,OAAO,CAAC,wBAAwB,CAAC,CAYnC;AAED;;;;;;;;GAQG;AACH,wBAAsB,6BAA6B,CACjD,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,QAAQ,CAAC,CAsCnB"}
|
|
@@ -15,6 +15,7 @@ import { initializeMikroOrmScalarStorage, } from "../persistence/providers/mikro
|
|
|
15
15
|
import { MikroOrmScalarPersistenceProvider, } from "../persistence/providers/mikro-orm/api/MikroOrmScalarPersistenceProvider.js";
|
|
16
16
|
import { createInternalHikoutei, resolveDefaultDbPath, } from "../sync-engine/api/hikouteiCore.js";
|
|
17
17
|
import { getRegisteredEntityTokens, } from "../sync-engine/api/entity.js";
|
|
18
|
+
import { mergeEntitiesAndDescriptors } from "../sync-engine/api/hikouteiCore.js";
|
|
18
19
|
import { resolveEntityDescriptors, } from "../sync-engine/api/internalEntityRegistry.js";
|
|
19
20
|
import { HIKOUTEI_ERROR_CODES, HikouteiError, } from "../sync-engine/api/errors.js";
|
|
20
21
|
import { describeErrorForInternalLog, HIKOUTEI_LOG_LEVELS, logHikouteiInternalEvent, } from "../contracts/shared/observability/internalLog.js";
|
|
@@ -44,7 +45,8 @@ export async function createLocalTypedSheetsRuntime(options) {
|
|
|
44
45
|
const startedAt = Date.now();
|
|
45
46
|
try {
|
|
46
47
|
const dbName = options.dbName ?? resolveDefaultDbPath();
|
|
47
|
-
|
|
48
|
+
// File-form descriptors ride the same builder path as the public factory.
|
|
49
|
+
const entities = mergeEntitiesAndDescriptors(options.entities ?? getRegisteredEntityTokens(), options.descriptors);
|
|
48
50
|
const descriptors = resolveEntityDescriptors(entities, throwHikouteiResolutionError);
|
|
49
51
|
// Load the current provider only when a runtime is opened. Importing the
|
|
50
52
|
// root package alone must not require MikroORM or expose its module graph.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localRuntime.js","sourceRoot":"","sources":["../../../../../../src/localRuntime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EACL,iCAAiC,GAElC,MAAM,yFAAyF,CAAC;AACjG,OAAO,EACL,+BAA+B,GAChC,MAAM,mFAAmF,CAAC;AAC3F,OAAO,EACL,iCAAiC,GAClC,MAAM,4FAA4F,CAAC;AAQpG,OAAO,EACL,sBAAsB,EACtB,oBAAoB,GAGrB,MAAM,2CAA2C,CAAC;AACnD,OAAO,EACL,yBAAyB,GAC1B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,wBAAwB,GAEzB,MAAM,qDAAqD,CAAC;AAC7D,OAAO,EACL,oBAAoB,EACpB,aAAa,GACd,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,2BAA2B,EAC3B,mBAAmB,EACnB,wBAAwB,GACzB,MAAM,yDAAyD,CAAC;AACjE,OAAO,EACL,uBAAuB,EACvB,mBAAmB,GACpB,MAAM,uDAAuD,CAAC;AAa/D;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,8BAA8B,CAClD,QAAmC;IAEnC,MAAM,SAAS,GAAG,iCAAiC,CAAC,QAAQ,CAAC,CAAC;IAC9D,OAAO;QACL,SAAS;QACT,iBAAiB,EAAE,CAAC,MAAc,EAAE,EAAE,CACpC,+BAA+B,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,CAAC,QAAQ,EAAE,CAAC;QAC3E,yBAAyB,EAAE,CAAC,OAAgB,EAAE,EAAE,CAC9C,IAAI,iCAAiC,CACnC,OAA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E,QAAQ,EAAE,WAAW,CAAC,IAAI,EAAE;SACvC,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC;IAClB,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,wBAAwB,CAAC;YACvB,KAAK,EAAE,mBAAmB,CAAC,mBAAmB;YAC9C,KAAK,EAAE,mBAAmB,CAAC,KAAK;YAChC,SAAS,EAAE,uBAAuB,CAAC,OAAO;YAC1C,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS;YAClC,GAAG,2BAA2B,CAAC,KAAK,CAAC;SACtC,CAAC,CAAC;QACH,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,SAAS,4BAA4B,CACnC,OAA0C;IAE1C,QAAQ,OAAO,CAAC,IAAI,EAAE,CAAC;QACrB,KAAK,eAAe;YAClB,MAAM,IAAI,aAAa,CACrB,oBAAoB,CAAC,yBAAyB,EAC9C,gFAAgF,CACjF,CAAC;QACJ,KAAK,gBAAgB;YACnB,MAAM,IAAI,aAAa,CACrB,oBAAoB,CAAC,gBAAgB,EACrC,gBAAgB,OAAO,CAAC,UAAU,iCAAiC,CACpE,CAAC;QACJ,KAAK,iBAAiB;YACpB,MAAM,IAAI,aAAa,CACrB,oBAAoB,CAAC,gBAAgB,EACrC,UAAU,OAAO,CAAC,SAAS,4BAA4B,OAAO,CAAC,eAAe,UAAU,OAAO,CAAC,gBAAgB,IAAI,CACrH,CAAC;IACN,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Versioned file form of an entity descriptor (`infer --emit`, startup
|
|
3
|
+
* `descriptors`, `adopt --descriptor`).
|
|
4
|
+
*
|
|
5
|
+
* The sheet→DB loop closes to two steps: `infer --emit desc.json` writes
|
|
6
|
+
* this file once, then `createTypedSheets({ descriptors })` and
|
|
7
|
+
* `adopt --descriptor desc.json` consume it. The file is DATA, never code:
|
|
8
|
+
* it is parsed as JSON, validated with the same rules
|
|
9
|
+
* `defineTypedSheetsEntity` enforces, and registered through the same
|
|
10
|
+
* builder — no codegen, no eval, no lifecycle bypass.
|
|
11
|
+
*
|
|
12
|
+
* Schema (v1):
|
|
13
|
+
* ```json
|
|
14
|
+
* {
|
|
15
|
+
* "hikouteiDescriptor": 1,
|
|
16
|
+
* "name": "Invoice",
|
|
17
|
+
* "tableName": "invoices",
|
|
18
|
+
* "properties": {
|
|
19
|
+
* "invoiceNo": { "header": "Invoice No", "type": "string", "primary": true },
|
|
20
|
+
* "total": { "header": "Total", "type": "number", "nullable": true }
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
* Property keys are the camelCase entity property names; `header` preserves
|
|
25
|
+
* the original sheet header so adopt can derive its header→property
|
|
26
|
+
* columnMap without manual `--map` flags. `type`/`primary`/`nullable` carry
|
|
27
|
+
* the exact `defineTypedSheetsEntity` property options (minus the `header`).
|
|
28
|
+
*/
|
|
29
|
+
import { type HikouteiEntity, type HikouteiEntityDescriptorInput, type HikouteiScalarType } from "./entity.js";
|
|
30
|
+
/** The only descriptor file version accepted by this build. */
|
|
31
|
+
export declare const HIKOUTEI_DESCRIPTOR_FILE_VERSION: 1;
|
|
32
|
+
/** One property entry in a descriptor file: sheet header + scalar options. */
|
|
33
|
+
export interface HikouteiDescriptorFileProperty {
|
|
34
|
+
/** Original sheet header; adopt derives its columnMap from these. */
|
|
35
|
+
readonly header: string;
|
|
36
|
+
/** Scalar value type stored in the entity table. */
|
|
37
|
+
readonly type: HikouteiScalarType;
|
|
38
|
+
/** Marks this field as the single primary-key/business-key column. */
|
|
39
|
+
readonly primary?: boolean;
|
|
40
|
+
/** Allows `null` values for this field. */
|
|
41
|
+
readonly nullable?: boolean;
|
|
42
|
+
}
|
|
43
|
+
/** Versioned descriptor file shape: entity identity + headed properties. */
|
|
44
|
+
export interface HikouteiDescriptorFile {
|
|
45
|
+
/** Schema version tag; must equal `HIKOUTEI_DESCRIPTOR_FILE_VERSION`. */
|
|
46
|
+
readonly hikouteiDescriptor: typeof HIKOUTEI_DESCRIPTOR_FILE_VERSION;
|
|
47
|
+
/** Stable entity name used by the manager and internal service mappings. */
|
|
48
|
+
readonly name: string;
|
|
49
|
+
/** SQLite table name that stores this entity's rows. */
|
|
50
|
+
readonly tableName: string;
|
|
51
|
+
/** Headed property declarations keyed by property name. */
|
|
52
|
+
readonly properties: Readonly<Record<string, HikouteiDescriptorFileProperty>>;
|
|
53
|
+
}
|
|
54
|
+
/** One headed column used to build a descriptor file (e.g. from inference). */
|
|
55
|
+
export interface HikouteiDescriptorColumn {
|
|
56
|
+
/** camelCase entity property name. */
|
|
57
|
+
readonly property: string;
|
|
58
|
+
/** Original sheet header preserved for adopt's column mapping. */
|
|
59
|
+
readonly header: string;
|
|
60
|
+
/** Inferred scalar type. */
|
|
61
|
+
readonly type: HikouteiScalarType;
|
|
62
|
+
/** True for the single primary-key/business-key column. */
|
|
63
|
+
readonly primary: boolean;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Builds a versioned descriptor file from headed columns.
|
|
67
|
+
*
|
|
68
|
+
* Pure constructor shared by `infer --emit`: the caller supplies the entity
|
|
69
|
+
* identity plus one entry per sampled column, and the file preserves every
|
|
70
|
+
* original header for the later `adopt --descriptor` columnMap.
|
|
71
|
+
*/
|
|
72
|
+
export declare function buildDescriptorFile(input: {
|
|
73
|
+
readonly name: string;
|
|
74
|
+
readonly tableName: string;
|
|
75
|
+
readonly columns: readonly HikouteiDescriptorColumn[];
|
|
76
|
+
}): HikouteiDescriptorFile;
|
|
77
|
+
/** Serializes a descriptor file to stable JSON (2-space, trailing newline). */
|
|
78
|
+
export declare function serializeDescriptorFile(file: HikouteiDescriptorFile): string;
|
|
79
|
+
/**
|
|
80
|
+
* Validates an unknown JSON value as a descriptor file.
|
|
81
|
+
*
|
|
82
|
+
* Checks the version tag and the header/type envelope here, then runs the
|
|
83
|
+
* scalar core through `defineTypedSheetsEntity`'s own rules by promoting the
|
|
84
|
+
* stripped input with `resolveEntityDescriptor` semantics: the returned file
|
|
85
|
+
* is guaranteed to satisfy the builder, so a later
|
|
86
|
+
* `defineTypedSheetsEntityFromDescriptorFile()` cannot fail on shape.
|
|
87
|
+
* Throws a typed `HikouteiError` (`INVALID_ENTITY_DESCRIPTOR`) on a version
|
|
88
|
+
* mismatch or any malformed field.
|
|
89
|
+
*/
|
|
90
|
+
export declare function parseDescriptorFile(value: unknown): HikouteiDescriptorFile;
|
|
91
|
+
/**
|
|
92
|
+
* Strips the file envelope (`hikouteiDescriptor`, `header`) down to the
|
|
93
|
+
* plain builder input. The result flows through `defineTypedSheetsEntity`
|
|
94
|
+
* unchanged, so file-registered entities take the exact same path as
|
|
95
|
+
* code-registered ones (the token needs no TS types at runtime — only this
|
|
96
|
+
* resolved descriptor object).
|
|
97
|
+
*/
|
|
98
|
+
export declare function descriptorFileToEntityInput(file: HikouteiDescriptorFile): HikouteiEntityDescriptorInput;
|
|
99
|
+
/**
|
|
100
|
+
* Registers a descriptor file through the same builder code entities use.
|
|
101
|
+
*
|
|
102
|
+
* The JSON object is never evaluated: it is validated by
|
|
103
|
+
* `parseDescriptorFile` (or structurally by the caller) and promoted to a
|
|
104
|
+
* plain `HikouteiEntityDescriptorInput` before `defineTypedSheetsEntity`
|
|
105
|
+
* validates and resolves it. The returned token is indistinguishable from a
|
|
106
|
+
* code-registered one (CRUD, sync projection, adoption).
|
|
107
|
+
*/
|
|
108
|
+
export declare function defineTypedSheetsEntityFromDescriptorFile(file: HikouteiDescriptorFile): HikouteiEntity;
|
|
109
|
+
/**
|
|
110
|
+
* Derives adopt's header→property columnMap from the file's `header` fields.
|
|
111
|
+
*
|
|
112
|
+
* Replaces manual `--map Header=property` for the infer case: every headed
|
|
113
|
+
* property contributes one `header → property` binding.
|
|
114
|
+
*/
|
|
115
|
+
export declare function descriptorFileColumnMap(file: HikouteiDescriptorFile): Record<string, string>;
|
|
116
|
+
//# sourceMappingURL=descriptorFile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