@gonvex/cli 0.5.2-staging.2 → 0.5.2-staging.21

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.
@@ -0,0 +1,106 @@
1
+ import { nativeLocalBindings } from "./native-local-bindings.js";
2
+ import { rolldown } from "rolldown";
3
+ import { createHash } from "node:crypto";
4
+ import { readFile, readdir, writeFile, mkdir } from "node:fs/promises";
5
+ import { dirname, join, relative, resolve } from "node:path";
6
+ import { compileLocalSchema } from "./local-schema.js";
7
+ export async function projectLocalSchema(root) {
8
+ const migrationDirectory = join(root, "migrations");
9
+ const names = (await readdir(migrationDirectory).catch(() => [])).filter((name) => name.endsWith(".sql")).sort();
10
+ const migrations = await Promise.all(names.map(async (name) => ({ name, sql: await readFile(join(migrationDirectory, name), "utf8") })));
11
+ const tenantMigrations = migrations.filter(({ sql }) => !/gonvex:scope\s+(control|landlord)/.test(sql));
12
+ const digest = createHash("sha256").update("local-schema-v1").update(JSON.stringify(tenantMigrations)).digest("hex");
13
+ const cacheFile = join(root, "gonvex", "_build", `local-schema-${digest}.json`);
14
+ let schema;
15
+ try {
16
+ schema = JSON.parse(await readFile(cacheFile, "utf8"));
17
+ }
18
+ catch {
19
+ schema = await compileLocalSchema(tenantMigrations);
20
+ await mkdir(dirname(cacheFile), { recursive: true });
21
+ await writeFile(cacheFile, JSON.stringify(schema));
22
+ }
23
+ return schema;
24
+ }
25
+ export async function localBindings(root, manifest) {
26
+ const reducers = Object.entries(manifest.functions).filter(([, entry]) => entry.localExecution === 1);
27
+ if (!reducers.length)
28
+ return {};
29
+ const schema = await projectLocalSchema(root);
30
+ const generatedDirectory = join(root, "gonvex", "_generated");
31
+ const imports = reducers.map(([, entry], index) => {
32
+ let file = relative(generatedDirectory, resolve(root, entry.file)).replaceAll("\\", "/").replace(/\.(?:tsx?|mts|cts)$/, ".js");
33
+ if (!file.startsWith("."))
34
+ file = `./${file}`;
35
+ return `import { ${entry.handler} as reducer${index} } from ${JSON.stringify(file)};`;
36
+ });
37
+ const entryFile = join(root, "gonvex", "_build", "local-entry.ts");
38
+ await mkdir(dirname(entryFile), { recursive: true });
39
+ await writeFile(entryFile, `${imports.join("\n")}\nexport const localReducers = {${reducers.map(([path], index) => `${JSON.stringify(path)}: reducer${index}`).join(",")}};`);
40
+ const bundle = await rolldown({
41
+ input: entryFile, cwd: root, platform: "browser", tsconfig: false,
42
+ // These declarations describe server entry points. Their definitions and
43
+ // schema construction are unnecessary when only Reducer exports are used.
44
+ treeshake: { manualPureFunctions: ["action", "internalReducer", "query", "internalQuery", "liveQuery", "replicaCollection", "visibility", "cron", "tenantCron", "schema"] },
45
+ resolve: { conditionNames: ["browser", "import", "default"], mainFields: ["browser", "module", "main"] },
46
+ });
47
+ let localCode;
48
+ const webChunks = {};
49
+ try {
50
+ const output = await bundle.generate({ format: "esm", codeSplitting: false });
51
+ if (output.output.length !== 1 || output.output[0]?.type !== "chunk")
52
+ throw new Error("Local Reducers must compile into one self-contained module");
53
+ localCode = output.output[0].code;
54
+ // Browser controls preload their own Reducers. Unopened features keep
55
+ // their code on disk instead of importing every application module at boot.
56
+ const lazyEntry = join(root, 'gonvex', '_build', 'local-lazy-entry.ts');
57
+ const loaders = reducers.map(([path, entry]) => {
58
+ let file = relative(dirname(lazyEntry), resolve(root, entry.file)).replaceAll('\\', '/').replace(/\.(?:tsx?|mts|cts)$/, '.js');
59
+ if (!file.startsWith('.'))
60
+ file = `./${file}`;
61
+ return `${JSON.stringify(path)}: () => import(${JSON.stringify(file)}).then(module => module.${entry.handler})`;
62
+ });
63
+ await writeFile(lazyEntry, `export const localReducers = {${loaders.join(',')}};`);
64
+ const lazyBundle = await rolldown({ input: lazyEntry, cwd: root, platform: 'browser', tsconfig: false,
65
+ treeshake: { manualPureFunctions: ['action', 'internalReducer', 'query', 'internalQuery', 'liveQuery', 'replicaCollection', 'visibility', 'cron', 'tenantCron', 'schema'] },
66
+ resolve: { conditionNames: ['browser', 'import', 'default'], mainFields: ['browser', 'module', 'main'] },
67
+ });
68
+ let web;
69
+ try {
70
+ web = await lazyBundle.generate({ format: 'esm', entryFileNames: 'local-reducers.js', chunkFileNames: 'local-reducer-[name]-[hash].js' });
71
+ }
72
+ finally {
73
+ await lazyBundle.close();
74
+ }
75
+ for (const chunk of web.output) {
76
+ if (chunk.type !== "chunk")
77
+ throw new Error("Unexpected local Reducer asset");
78
+ webChunks[chunk.fileName] = chunk.code;
79
+ }
80
+ }
81
+ finally {
82
+ await bundle.close();
83
+ }
84
+ const contractBytes = manifest.module.files["client-contract.json"];
85
+ const clientContract = contractBytes ? JSON.parse(Buffer.from(contractBytes, "base64").toString()) : undefined;
86
+ const header = "// Generated by Gonvex. Do not edit.\n";
87
+ // Tables each locally executing Reducer needs resident, limited to tables the
88
+ // client can actually hydrate through a generated local collection.
89
+ const localTables = new Set(Object.entries(manifest.functions).filter(([path]) => path.startsWith("__local.")).map(([, entry]) => entry.replica?.table));
90
+ const localDependencies = Object.fromEntries(reducers
91
+ .map(([path, entry]) => [path, (entry.localDependencies ?? []).filter((table) => localTables.has(table))])
92
+ .filter(([, tables]) => tables.length > 0));
93
+ const native = await nativeLocalBindings(root, localCode, schema, {
94
+ clientContract, artifactHash: manifest.module.hash, tables: Object.keys(schema),
95
+ collections: Object.entries(manifest.functions).filter(([path]) => path.startsWith("__local.")).map(([path, entry]) => ({ kind: "query", path, delivery: "replica", replica: entry.replica })),
96
+ });
97
+ return {
98
+ ...native,
99
+ "local-schema.ts": `${header}export const localSchema = ${JSON.stringify(schema)} as const;\n`,
100
+ ...Object.fromEntries(Object.entries(webChunks).map(([name, code]) => [name, header + code])),
101
+ "local-reducers.d.ts": `${header}import type { ReducerDefinition } from "@gonvex/module-sdk";\nexport declare const localReducers: Readonly<Record<string, () => Promise<ReducerDefinition<any, any>>>>;\n`,
102
+ "local-runtime.ts": `${header}export {localRuntime} from "./local-executor.js";\n`,
103
+ "local-executor.ts": `${header}import { createPortableReducer } from "@gonvex/local-runtime/portable-client";\nimport { localSchema } from "./local-schema.js";\nimport { localReducers } from "./local-reducers.js";\nexport const localRuntime = { mode: "portable" as const, clientContract: ${JSON.stringify(clientContract)}, artifactHash: ${JSON.stringify(manifest.module.hash)}, tables: ${JSON.stringify(Object.keys(schema))}, collections: ${JSON.stringify(Object.entries(manifest.functions).filter(([path]) => path.startsWith("__local.")).map(([path, entry]) => ({ kind: "query", path, delivery: "replica", replica: entry.replica })))} as const, localDependencies: ${JSON.stringify(localDependencies)} as const, create: () => createPortableReducer({schema: localSchema, reducers: localReducers, artifactHash: ${JSON.stringify(manifest.module.hash)}}) };\n`,
104
+ };
105
+ }
106
+ //# sourceMappingURL=local-bindings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local-bindings.js","sourceRoot":"","sources":["../src/local-bindings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAGvD,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,IAAY;IACnD,MAAM,kBAAkB,GAAG,IAAI,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;IACpD,MAAM,KAAK,GAAG,CAAC,MAAM,OAAO,CAAC,kBAAkB,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,EAAc,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,E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B,EAAE,GAAG,MAAM,2KAA2K;QAC3M,kBAAkB,EAAE,GAAG,MAAM,qDAAqD;QAClF,mBAAmB,EAAE,GAAG,MAAM,oQAAoQ,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,mBAAmB,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,kBAAkB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,EAAC,IAAI,EAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAC,SAAS,EAAE,OAAO,EAAC,KAAK,CAAC,OAAO,EAAC,CAAC,CAAC,CAAC,iCAAiC,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,+GAA+G,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS;KACp1B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,58 @@
1
+ export type LocalTableAccess = {
2
+ table: string;
3
+ operation: string;
4
+ /** False only for inserts with an intent-generated key: they never read locally. */
5
+ reads: boolean;
6
+ /** Project-relative `file:line`. */
7
+ site: string;
8
+ };
9
+ export type UnresolvedLocalAccess = {
10
+ operation: string;
11
+ site: string;
12
+ expression: string;
13
+ };
14
+ export type LocalReducerAnalysis = {
15
+ path: string;
16
+ accesses: LocalTableAccess[];
17
+ unresolved: UnresolvedLocalAccess[];
18
+ rawQueries: string[];
19
+ };
20
+ export type LocalReducerSource = {
21
+ /** Public function path. */
22
+ path: string;
23
+ /** Project-relative module file. */
24
+ file: string;
25
+ /** Exported binding that holds the Reducer definition. */
26
+ exportName: string;
27
+ };
28
+ export type LocalDependencyViolation = {
29
+ reducer: string;
30
+ table: string;
31
+ operation: string;
32
+ site: string;
33
+ reason: string;
34
+ };
35
+ /**
36
+ * Whether an access reads the table locally. The analysis checks inserts for
37
+ * an explicit `_id`; a table keyed by another column is treated as read by any
38
+ * insert, since the row may carry that key.
39
+ */
40
+ export declare function readsLocally(access: LocalTableAccess, tableKeys: ReadonlyMap<string, string>): boolean;
41
+ /** Tables a Reducer needs in the Local Replica to run locally, sorted. */
42
+ export declare function localDependencyTables(analysis: LocalReducerAnalysis, tableKeys: ReadonlyMap<string, string>): string[];
43
+ /** Accesses a local run cannot complete. `tableKeys` maps every local-schema table to its key. */
44
+ export declare function localDependencyViolations(analyses: readonly LocalReducerAnalysis[], localTables: ReadonlySet<string>, tableKeys: ReadonlyMap<string, string>): LocalDependencyViolation[];
45
+ /** A readable report grouped by table, for CLI errors and warnings. */
46
+ export declare function formatLocalDependencyViolations(violations: readonly LocalDependencyViolation[]): string;
47
+ /**
48
+ * Analyze the table dependencies of locally executing Reducers. Loads the
49
+ * TypeScript compiler bundled with the CLI on first use.
50
+ */
51
+ export declare function analyzeLocalReducerDependencies(input: {
52
+ root: string;
53
+ backendDir: string;
54
+ files: readonly string[];
55
+ reducers: readonly LocalReducerSource[];
56
+ /** Project-relative tsconfig whose compiler options (paths, resolution) apply to the backend. */
57
+ tsconfig?: string;
58
+ }): Promise<LocalReducerAnalysis[]>;