@danielfgray/pg-sourcerer 0.2.2 → 0.4.0
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/bin/pgsourcerer +2 -0
- package/dist/__tests__/fixtures/index.d.ts +15 -0
- package/dist/__tests__/fixtures/index.d.ts.map +1 -0
- package/dist/__tests__/fixtures/index.js +19 -0
- package/dist/__tests__/fixtures/index.js.map +1 -0
- package/dist/__tests__/fixtures/introspection.json +40522 -0
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js +7 -46
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +38 -5
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +13 -2
- package/dist/config.js.map +1 -1
- package/dist/{lib/conjure.d.ts → conjure/index.d.ts} +62 -3
- package/dist/conjure/index.d.ts.map +1 -0
- package/dist/{lib/conjure.js → conjure/index.js} +124 -3
- package/dist/conjure/index.js.map +1 -0
- package/dist/conjure/signature.d.ts +85 -0
- package/dist/conjure/signature.d.ts.map +1 -0
- package/dist/conjure/signature.js +130 -0
- package/dist/conjure/signature.js.map +1 -0
- package/dist/conjure/types.d.ts +97 -0
- package/dist/conjure/types.d.ts.map +1 -0
- package/dist/conjure/types.js +206 -0
- package/dist/conjure/types.js.map +1 -0
- package/dist/errors.d.ts +114 -139
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +82 -36
- package/dist/errors.js.map +1 -1
- package/dist/generate.d.ts +45 -46
- package/dist/generate.d.ts.map +1 -1
- package/dist/generate.js +86 -59
- package/dist/generate.js.map +1 -1
- package/dist/hex/builder.d.ts +12 -0
- package/dist/hex/builder.d.ts.map +1 -0
- package/dist/hex/builder.js +64 -0
- package/dist/hex/builder.js.map +1 -0
- package/dist/hex/ddl.d.ts +53 -0
- package/dist/hex/ddl.d.ts.map +1 -0
- package/dist/hex/ddl.js +306 -0
- package/dist/hex/ddl.js.map +1 -0
- package/dist/hex/index.d.ts +105 -0
- package/dist/hex/index.d.ts.map +1 -0
- package/dist/hex/index.js +81 -0
- package/dist/hex/index.js.map +1 -0
- package/dist/hex/primitives.d.ts +23 -0
- package/dist/hex/primitives.d.ts.map +1 -0
- package/dist/hex/primitives.js +38 -0
- package/dist/hex/primitives.js.map +1 -0
- package/dist/hex/query.d.ts +116 -0
- package/dist/hex/query.d.ts.map +1 -0
- package/dist/hex/query.js +219 -0
- package/dist/hex/query.js.map +1 -0
- package/dist/hex/types.d.ts +287 -0
- package/dist/hex/types.d.ts.map +1 -0
- package/dist/hex/types.js +431 -0
- package/dist/hex/types.js.map +1 -0
- package/dist/index.d.ts +17 -25
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +33 -44
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +76 -140
- package/dist/init.js.map +1 -1
- package/dist/ir/extensions/queries.d.ts +6 -6
- package/dist/ir/extensions/queries.d.ts.map +1 -1
- package/dist/ir/extensions/queries.js +6 -4
- package/dist/ir/extensions/queries.js.map +1 -1
- package/dist/ir/extensions/schema-builder.d.ts.map +1 -1
- package/dist/ir/extensions/schema-builder.js.map +1 -1
- package/dist/ir/index.d.ts.map +1 -1
- package/dist/ir/index.js.map +1 -1
- package/dist/ir/relation-graph.d.ts.map +1 -1
- package/dist/ir/relation-graph.js +8 -8
- package/dist/ir/relation-graph.js.map +1 -1
- package/dist/ir/semantic-ir.d.ts +38 -0
- package/dist/ir/semantic-ir.d.ts.map +1 -1
- package/dist/ir/semantic-ir.js +50 -2
- package/dist/ir/semantic-ir.js.map +1 -1
- package/dist/ir/smart-tags.d.ts.map +1 -1
- package/dist/ir/smart-tags.js.map +1 -1
- package/dist/lib/field-utils.d.ts.map +1 -1
- package/dist/lib/field-utils.js +7 -7
- package/dist/lib/field-utils.js.map +1 -1
- package/dist/lib/join-graph.d.ts +95 -0
- package/dist/lib/join-graph.d.ts.map +1 -0
- package/dist/lib/join-graph.js +305 -0
- package/dist/lib/join-graph.js.map +1 -0
- package/dist/lib/picker.d.ts +60 -0
- package/dist/lib/picker.d.ts.map +1 -0
- package/dist/lib/picker.js +325 -0
- package/dist/lib/picker.js.map +1 -0
- package/dist/plugins/arktype.d.ts +20 -24
- package/dist/plugins/arktype.d.ts.map +1 -1
- package/dist/plugins/arktype.js +462 -386
- package/dist/plugins/arktype.js.map +1 -1
- package/dist/plugins/effect/http.d.ts +7 -0
- package/dist/plugins/effect/http.d.ts.map +1 -0
- package/dist/plugins/effect/http.js +460 -0
- package/dist/plugins/effect/http.js.map +1 -0
- package/dist/plugins/effect/index.d.ts +22 -0
- package/dist/plugins/effect/index.d.ts.map +1 -0
- package/dist/plugins/effect/index.js +65 -0
- package/dist/plugins/effect/index.js.map +1 -0
- package/dist/plugins/effect/models.d.ts +6 -0
- package/dist/plugins/effect/models.d.ts.map +1 -0
- package/dist/plugins/effect/models.js +116 -0
- package/dist/plugins/effect/models.js.map +1 -0
- package/dist/plugins/effect/repos.d.ts +21 -0
- package/dist/plugins/effect/repos.d.ts.map +1 -0
- package/dist/plugins/effect/repos.js +131 -0
- package/dist/plugins/effect/repos.js.map +1 -0
- package/dist/plugins/effect/schemas.d.ts +7 -0
- package/dist/plugins/effect/schemas.d.ts.map +1 -0
- package/dist/plugins/effect/schemas.js +75 -0
- package/dist/plugins/effect/schemas.js.map +1 -0
- package/dist/plugins/effect/shared.d.ts +116 -0
- package/dist/plugins/effect/shared.d.ts.map +1 -0
- package/dist/plugins/effect/shared.js +164 -0
- package/dist/plugins/effect/shared.js.map +1 -0
- package/dist/plugins/http-elysia.d.ts +20 -27
- package/dist/plugins/http-elysia.d.ts.map +1 -1
- package/dist/plugins/http-elysia.js +350 -475
- package/dist/plugins/http-elysia.js.map +1 -1
- package/dist/plugins/http-express.d.ts +20 -31
- package/dist/plugins/http-express.d.ts.map +1 -1
- package/dist/plugins/http-express.js +281 -268
- package/dist/plugins/http-express.js.map +1 -1
- package/dist/plugins/http-hono.d.ts +17 -33
- package/dist/plugins/http-hono.d.ts.map +1 -1
- package/dist/plugins/http-hono.js +317 -341
- package/dist/plugins/http-hono.js.map +1 -1
- package/dist/plugins/http-orpc.d.ts +34 -33
- package/dist/plugins/http-orpc.d.ts.map +1 -1
- package/dist/plugins/http-orpc.js +345 -257
- package/dist/plugins/http-orpc.js.map +1 -1
- package/dist/plugins/http-trpc.d.ts +33 -35
- package/dist/plugins/http-trpc.d.ts.map +1 -1
- package/dist/plugins/http-trpc.js +337 -241
- package/dist/plugins/http-trpc.js.map +1 -1
- package/dist/plugins/kysely.d.ts +54 -59
- package/dist/plugins/kysely.d.ts.map +1 -1
- package/dist/plugins/kysely.js +826 -687
- package/dist/plugins/kysely.js.map +1 -1
- package/dist/plugins/sql-queries.d.ts +38 -44
- package/dist/plugins/sql-queries.d.ts.map +1 -1
- package/dist/plugins/sql-queries.js +497 -897
- package/dist/plugins/sql-queries.js.map +1 -1
- package/dist/plugins/types.d.ts +12 -20
- package/dist/plugins/types.d.ts.map +1 -1
- package/dist/plugins/types.js +84 -227
- package/dist/plugins/types.js.map +1 -1
- package/dist/plugins/valibot.d.ts +7 -44
- package/dist/plugins/valibot.d.ts.map +1 -1
- package/dist/plugins/valibot.js +376 -382
- package/dist/plugins/valibot.js.map +1 -1
- package/dist/plugins/zod.d.ts +20 -24
- package/dist/plugins/zod.d.ts.map +1 -1
- package/dist/plugins/zod.js +370 -367
- package/dist/plugins/zod.js.map +1 -1
- package/dist/runtime/emit.d.ts +64 -0
- package/dist/runtime/emit.d.ts.map +1 -0
- package/dist/runtime/emit.js +445 -0
- package/dist/runtime/emit.js.map +1 -0
- package/dist/runtime/errors.d.ts +36 -0
- package/dist/runtime/errors.d.ts.map +1 -0
- package/dist/runtime/errors.js +29 -0
- package/dist/runtime/errors.js.map +1 -0
- package/dist/runtime/file-assignment.d.ts +161 -0
- package/dist/runtime/file-assignment.d.ts.map +1 -0
- package/dist/runtime/file-assignment.js +195 -0
- package/dist/runtime/file-assignment.js.map +1 -0
- package/dist/runtime/orchestrator.d.ts +62 -0
- package/dist/runtime/orchestrator.d.ts.map +1 -0
- package/dist/runtime/orchestrator.js +99 -0
- package/dist/runtime/orchestrator.js.map +1 -0
- package/dist/runtime/registry.d.ts +268 -0
- package/dist/runtime/registry.d.ts.map +1 -0
- package/dist/runtime/registry.js +436 -0
- package/dist/runtime/registry.js.map +1 -0
- package/dist/runtime/types.d.ts +182 -0
- package/dist/runtime/types.d.ts.map +1 -0
- package/dist/runtime/types.js +2 -0
- package/dist/runtime/types.js.map +1 -0
- package/dist/runtime/validation.d.ts +41 -0
- package/dist/runtime/validation.d.ts.map +1 -0
- package/dist/runtime/validation.js +70 -0
- package/dist/runtime/validation.js.map +1 -0
- package/dist/services/config-loader.d.ts.map +1 -1
- package/dist/services/config-loader.js +15 -6
- package/dist/services/config-loader.js.map +1 -1
- package/dist/services/config.d.ts +55 -25
- package/dist/services/config.d.ts.map +1 -1
- package/dist/services/config.js +60 -34
- package/dist/services/config.js.map +1 -1
- package/dist/services/file-writer.d.ts +3 -3
- package/dist/services/file-writer.d.ts.map +1 -1
- package/dist/services/file-writer.js +6 -8
- package/dist/services/file-writer.js.map +1 -1
- package/dist/services/inflection.d.ts +126 -27
- package/dist/services/inflection.d.ts.map +1 -1
- package/dist/services/inflection.js +300 -72
- package/dist/services/inflection.js.map +1 -1
- package/dist/services/introspection.d.ts.map +1 -1
- package/dist/services/introspection.js +6 -6
- package/dist/services/introspection.js.map +1 -1
- package/dist/services/ir-builder.d.ts.map +1 -1
- package/dist/services/ir-builder.js +73 -77
- package/dist/services/ir-builder.js.map +1 -1
- package/dist/services/ir.d.ts.map +1 -1
- package/dist/services/ir.js.map +1 -1
- package/dist/services/pg-types.d.ts.map +1 -1
- package/dist/services/pg-types.js +3 -3
- package/dist/services/pg-types.js.map +1 -1
- package/dist/services/smart-tags-parser.d.ts.map +1 -1
- package/dist/services/smart-tags-parser.js +4 -4
- package/dist/services/smart-tags-parser.js.map +1 -1
- package/dist/services/type-hints.d.ts.map +1 -1
- package/dist/services/type-hints.js +1 -1
- package/dist/services/type-hints.js.map +1 -1
- package/dist/services/user-module-parser.d.ts +46 -0
- package/dist/services/user-module-parser.d.ts.map +1 -0
- package/dist/services/user-module-parser.js +181 -0
- package/dist/services/user-module-parser.js.map +1 -0
- package/dist/shared/converters.d.ts +60 -0
- package/dist/shared/converters.d.ts.map +1 -0
- package/dist/shared/converters.js +168 -0
- package/dist/shared/converters.js.map +1 -0
- package/dist/shared/query-types.d.ts +95 -0
- package/dist/shared/query-types.d.ts.map +1 -0
- package/dist/shared/query-types.js +9 -0
- package/dist/shared/query-types.js.map +1 -0
- package/dist/testing.d.ts +125 -37
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +134 -42
- package/dist/testing.js.map +1 -1
- package/dist/user-module.d.ts +86 -0
- package/dist/user-module.d.ts.map +1 -0
- package/dist/user-module.js +55 -0
- package/dist/user-module.js.map +1 -0
- package/package.json +10 -6
- package/dist/lib/conjure.d.ts.map +0 -1
- package/dist/lib/conjure.js.map +0 -1
- package/dist/lib/hex.d.ts +0 -119
- package/dist/lib/hex.d.ts.map +0 -1
- package/dist/lib/hex.js +0 -188
- package/dist/lib/hex.js.map +0 -1
- package/dist/plugins/effect.d.ts +0 -53
- package/dist/plugins/effect.d.ts.map +0 -1
- package/dist/plugins/effect.js +0 -1074
- package/dist/plugins/effect.js.map +0 -1
- package/dist/plugins/kysely/queries.d.ts +0 -92
- package/dist/plugins/kysely/queries.d.ts.map +0 -1
- package/dist/plugins/kysely/queries.js +0 -1169
- package/dist/plugins/kysely/queries.js.map +0 -1
- package/dist/plugins/kysely/shared.d.ts +0 -59
- package/dist/plugins/kysely/shared.d.ts.map +0 -1
- package/dist/plugins/kysely/shared.js +0 -247
- package/dist/plugins/kysely/shared.js.map +0 -1
- package/dist/plugins/kysely/types.d.ts +0 -22
- package/dist/plugins/kysely/types.d.ts.map +0 -1
- package/dist/plugins/kysely/types.js +0 -428
- package/dist/plugins/kysely/types.js.map +0 -1
- package/dist/services/artifact-store.d.ts +0 -65
- package/dist/services/artifact-store.d.ts.map +0 -1
- package/dist/services/artifact-store.js +0 -57
- package/dist/services/artifact-store.js.map +0 -1
- package/dist/services/core-providers.d.ts +0 -15
- package/dist/services/core-providers.d.ts.map +0 -1
- package/dist/services/core-providers.js +0 -23
- package/dist/services/core-providers.js.map +0 -1
- package/dist/services/emissions.d.ts +0 -103
- package/dist/services/emissions.d.ts.map +0 -1
- package/dist/services/emissions.js +0 -241
- package/dist/services/emissions.js.map +0 -1
- package/dist/services/execution.d.ts +0 -35
- package/dist/services/execution.d.ts.map +0 -1
- package/dist/services/execution.js +0 -86
- package/dist/services/execution.js.map +0 -1
- package/dist/services/file-builder.d.ts +0 -85
- package/dist/services/file-builder.d.ts.map +0 -1
- package/dist/services/file-builder.js +0 -112
- package/dist/services/file-builder.js.map +0 -1
- package/dist/services/plugin-meta.d.ts +0 -33
- package/dist/services/plugin-meta.d.ts.map +0 -1
- package/dist/services/plugin-meta.js +0 -24
- package/dist/services/plugin-meta.js.map +0 -1
- package/dist/services/plugin-runner.d.ts +0 -42
- package/dist/services/plugin-runner.d.ts.map +0 -1
- package/dist/services/plugin-runner.js +0 -84
- package/dist/services/plugin-runner.js.map +0 -1
- package/dist/services/plugin.d.ts +0 -421
- package/dist/services/plugin.d.ts.map +0 -1
- package/dist/services/plugin.js +0 -197
- package/dist/services/plugin.js.map +0 -1
- package/dist/services/resolution.d.ts +0 -38
- package/dist/services/resolution.d.ts.map +0 -1
- package/dist/services/resolution.js +0 -242
- package/dist/services/resolution.js.map +0 -1
- package/dist/services/service-registry.d.ts +0 -74
- package/dist/services/service-registry.d.ts.map +0 -1
- package/dist/services/service-registry.js +0 -61
- package/dist/services/service-registry.js.map +0 -1
- package/dist/services/symbols.d.ts +0 -144
- package/dist/services/symbols.d.ts.map +0 -1
- package/dist/services/symbols.js +0 -144
- package/dist/services/symbols.js.map +0 -1
package/dist/cli.d.ts
CHANGED
package/dist/cli.js
CHANGED
|
@@ -1,24 +1,13 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
2
1
|
/**
|
|
3
2
|
* pg-sourcerer CLI
|
|
4
|
-
*
|
|
5
|
-
* Command-line interface for code generation from PostgreSQL schema.
|
|
6
|
-
*
|
|
7
|
-
* Log verbosity is controlled via the built-in --log-level flag:
|
|
8
|
-
* --log-level debug Show detailed output (table names, file paths)
|
|
9
|
-
* --log-level info Default - show progress messages
|
|
10
|
-
* --log-level none Suppress all output except errors
|
|
11
3
|
*/
|
|
12
4
|
import { Command, Options } from "@effect/cli";
|
|
13
5
|
import { NodeContext, NodeRuntime } from "@effect/platform-node";
|
|
14
6
|
import { Console, Effect, Option } from "effect";
|
|
15
7
|
import { runGenerate } from "./generate.js";
|
|
16
8
|
import { runInit } from "./init.js";
|
|
17
|
-
import {
|
|
9
|
+
import { ConfigWithFallback, FileConfigProvider } from "./services/config.js";
|
|
18
10
|
import packageJson from "../package.json" with { type: "json" };
|
|
19
|
-
// ============================================================================
|
|
20
|
-
// Options
|
|
21
|
-
// ============================================================================
|
|
22
11
|
const configPath = Options.file("config").pipe(Options.withAlias("c"), Options.withDescription("Path to config file"), Options.optional);
|
|
23
12
|
const outputDir = Options.directory("output").pipe(Options.withAlias("o"), Options.withDescription("Override output directory"), Options.optional);
|
|
24
13
|
const dryRun = Options.boolean("dry-run").pipe(Options.withAlias("n"), Options.withDescription("Show what would be generated without writing files"), Options.withDefault(false));
|
|
@@ -33,49 +22,21 @@ const runGenerateCommand = (args) => {
|
|
|
33
22
|
const suffix = args.dryRun ? " (dry run)" : "";
|
|
34
23
|
return Console.log(`\n✓ Generated ${args.dryRun ? total : written} files${suffix}`);
|
|
35
24
|
};
|
|
36
|
-
// Build config layer based on whether explicit path was provided
|
|
37
25
|
const configOpts = {
|
|
38
26
|
configPath: Option.getOrUndefined(args.configPath),
|
|
39
27
|
};
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
Effect.catchTags({
|
|
45
|
-
ConfigInvalid: (error) => logErrorWithDetails(error, error.errors),
|
|
46
|
-
PluginCycle: (error) => Console.error(`\n✗ Error: ${error._tag}`).pipe(Effect.andThen(Console.error(` ${error.message}`)), Effect.andThen(Console.error(` Cycle: ${error.cycle.join(" → ")}`)), Effect.andThen(Effect.fail(error))),
|
|
47
|
-
}),
|
|
48
|
-
// Generic fallback for remaining tagged errors (GenerateError types)
|
|
49
|
-
Effect.catchAll((error) => {
|
|
50
|
-
// Handle tagged errors with _tag property
|
|
51
|
-
if (error && typeof error === "object" && "_tag" in error) {
|
|
52
|
-
const taggedError = error;
|
|
53
|
-
return Console.error(`\n✗ Error: ${taggedError._tag}`).pipe(Effect.andThen(Console.error(` ${taggedError.message ?? String(error)}`)), Effect.andThen(Effect.fail(error)));
|
|
54
|
-
}
|
|
55
|
-
// Plain errors (e.g., from init prompts)
|
|
56
|
-
return Console.error(`\n✗ Error: ${error instanceof Error ? error.message : String(error)}`).pipe(Effect.andThen(Effect.fail(error)));
|
|
28
|
+
const configLayer = ConfigWithFallback(FileConfigProvider(configOpts), () => FileConfigProvider(configOpts));
|
|
29
|
+
return runGenerate(opts).pipe(Effect.provide(configLayer), Effect.tap(logSuccess), Effect.catchTags({
|
|
30
|
+
ConfigNotFound: () => Console.log("No config file found. Running init...").pipe(Effect.zipRight(runInit), Effect.tap(() => Console.log("\nRun 'pgsourcerer' again to generate code."))),
|
|
31
|
+
ConfigInvalid: error => Effect.forEach(error.errors, e => Console.error(` - ${e}`)),
|
|
57
32
|
}));
|
|
58
33
|
};
|
|
59
|
-
/** Log an error with a list of detail messages */
|
|
60
|
-
const logErrorWithDetails = (error, details) => Console.error(`\n✗ Error: ${error._tag}`).pipe(Effect.andThen(Console.error(` ${error.message}`)), Effect.andThen(Effect.forEach(details, e => Console.error(` - ${e}`))), Effect.andThen(Effect.fail(error)));
|
|
61
|
-
// ============================================================================
|
|
62
|
-
// Commands
|
|
63
|
-
// ============================================================================
|
|
64
34
|
const generateCommand = Command.make("generate", { configPath, outputDir, dryRun }, runGenerateCommand);
|
|
65
|
-
|
|
66
|
-
* Init command - just runs prompts and writes config file.
|
|
67
|
-
* Does NOT run generate afterwards (user runs that separately).
|
|
68
|
-
*/
|
|
69
|
-
const initCommand = Command.make("init", {}, () => runInit.pipe(Effect.tap(() => Console.log("\nRun 'pgsourcerer' to generate code.")), Effect.asVoid));
|
|
70
|
-
// Root command runs generate by default (which triggers init if no config)
|
|
35
|
+
const initCommand = Command.make("init", {}, () => runInit.pipe(Effect.tap(() => Console.log("\nRun 'pgsourcerer' to generate code."))));
|
|
71
36
|
const rootCommand = Command.make("pgsourcerer", { configPath, outputDir, dryRun }, runGenerateCommand).pipe(Command.withSubcommands([generateCommand, initCommand]));
|
|
72
|
-
// ============================================================================
|
|
73
|
-
// CLI App
|
|
74
|
-
// ============================================================================
|
|
75
37
|
const cli = Command.run(rootCommand, {
|
|
76
38
|
name: "pgsourcerer",
|
|
77
39
|
version: packageJson.version,
|
|
78
40
|
});
|
|
79
|
-
|
|
80
|
-
cli(process.argv).pipe(Effect.provide(NodeContext.layer), NodeRuntime.runMain);
|
|
41
|
+
NodeRuntime.runMain(cli(process.argv).pipe(Effect.provide(NodeContext.layer)));
|
|
81
42
|
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,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AAC,IAAI,CAAC,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,CAChD,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAC,CAAC,CACrF,CAAC;AAEF,MAAM,WAAW,GAAG,OAAO,CAAC,IAAI,CAC9B,aAAa,EACb,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,EACjC,kBAAkB,CACnB,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,eAAe,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;AAEhE,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE;IACnC,IAAI,EAAE,aAAa;IACnB,OAAO,EAAE,WAAW,CAAC,OAAO;CAC7B,CAAC,CAAC;AAEH,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC"}
|
package/dist/config.d.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { Schema as S } from "effect";
|
|
5
5
|
import type { InflectionConfig } from "./services/inflection.js";
|
|
6
|
+
import type { Plugin } from "./runtime/types.js";
|
|
6
7
|
/**
|
|
7
8
|
* Type hint match criteria
|
|
8
9
|
*/
|
|
@@ -36,7 +37,7 @@ export type TypeHint = S.Schema.Type<typeof TypeHint>;
|
|
|
36
37
|
*/
|
|
37
38
|
export declare const Config: S.Struct<{
|
|
38
39
|
/** Database connection string */
|
|
39
|
-
connectionString:
|
|
40
|
+
connectionString: S.propertySignature<S.SchemaClass<string, string, never>>;
|
|
40
41
|
/** PostgreSQL role to assume during introspection (for RLS-aware generation) */
|
|
41
42
|
role: S.optional<typeof S.String>;
|
|
42
43
|
/** PostgreSQL schemas to introspect */
|
|
@@ -62,9 +63,14 @@ export declare const Config: S.Struct<{
|
|
|
62
63
|
/** Inflection configuration (validated as Any, properly typed in ConfigInput) */
|
|
63
64
|
inflection: S.optional<typeof S.Any>;
|
|
64
65
|
/** Plugins to run */
|
|
65
|
-
plugins: S.Array$<typeof S.Any
|
|
66
|
+
plugins: S.propertySignature<S.Array$<typeof S.Any>>;
|
|
66
67
|
/** Formatter callback to transform generated code before writing (validated as Any, properly typed in ConfigInput) */
|
|
67
68
|
formatter: S.optional<typeof S.String>;
|
|
69
|
+
/**
|
|
70
|
+
* Default file name for symbols that don't match any rule.
|
|
71
|
+
* Relative to outputDir. Default: "index.ts"
|
|
72
|
+
*/
|
|
73
|
+
defaultFile: S.optional<typeof S.String>;
|
|
68
74
|
}>;
|
|
69
75
|
export type Config = S.Schema.Type<typeof Config>;
|
|
70
76
|
/**
|
|
@@ -101,8 +107,23 @@ export interface ConfigInput {
|
|
|
101
107
|
* ```
|
|
102
108
|
*/
|
|
103
109
|
readonly inflection?: InflectionConfig;
|
|
104
|
-
/**
|
|
105
|
-
|
|
110
|
+
/**
|
|
111
|
+
* Plugins to run.
|
|
112
|
+
*
|
|
113
|
+
* Accepts individual plugins or arrays of plugins (presets).
|
|
114
|
+
* Arrays are flattened at runtime, allowing plugin functions to return
|
|
115
|
+
* multiple sub-plugins that work together.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```typescript
|
|
119
|
+
* plugins: [
|
|
120
|
+
* types(), // Single plugin
|
|
121
|
+
* effect(), // Preset returning multiple plugins
|
|
122
|
+
* [zod(), kysely()], // Explicit array
|
|
123
|
+
* ]
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
readonly plugins: readonly (Plugin | readonly Plugin[])[];
|
|
106
127
|
/**
|
|
107
128
|
* Formatter command to run on generated files after writing.
|
|
108
129
|
* The command will be run with the output directory as the argument.
|
|
@@ -116,6 +137,11 @@ export interface ConfigInput {
|
|
|
116
137
|
* ```
|
|
117
138
|
*/
|
|
118
139
|
readonly formatter?: string;
|
|
140
|
+
/**
|
|
141
|
+
* Default file name for symbols that don't match any rule.
|
|
142
|
+
* Relative to outputDir. Default: "index.ts"
|
|
143
|
+
*/
|
|
144
|
+
readonly defaultFile?: string;
|
|
119
145
|
}
|
|
120
146
|
/**
|
|
121
147
|
* Resolved configuration with all defaults applied
|
|
@@ -127,7 +153,14 @@ export interface ResolvedConfig {
|
|
|
127
153
|
readonly outputDir: string;
|
|
128
154
|
readonly typeHints: readonly TypeHint[];
|
|
129
155
|
readonly inflection?: InflectionConfig;
|
|
130
|
-
|
|
156
|
+
/** Plugins after flattening presets */
|
|
157
|
+
readonly plugins: readonly Plugin[];
|
|
131
158
|
readonly formatter?: string;
|
|
159
|
+
readonly defaultFile?: string;
|
|
160
|
+
/**
|
|
161
|
+
* Directory containing the config file.
|
|
162
|
+
* Used to resolve relative paths in userModule() references.
|
|
163
|
+
*/
|
|
164
|
+
readonly configDir?: string;
|
|
132
165
|
}
|
|
133
166
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,MAAM,IAAI,CAAC,EAAE,MAAM,QAAQ,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,MAAM,IAAI,CAAC,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAEjD;;GAEG;AACH,eAAO,MAAM,aAAa;;;;;EAKxB,CAAC;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,aAAa,CA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cAAc;IAC7B,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,SAAS,QAAQ,EAAE,CAAC;IACxC,QAAQ,CAAC,UAAU,CAAC,EAAE,gBAAgB,CAAC;IACvC,uCAAuC;IACvC,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B;;;OAGG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B"}
|
package/dist/config.js
CHANGED
|
@@ -28,7 +28,11 @@ export const TypeHint = S.Struct({
|
|
|
28
28
|
*/
|
|
29
29
|
export const Config = S.Struct({
|
|
30
30
|
/** Database connection string */
|
|
31
|
-
connectionString: S.String
|
|
31
|
+
connectionString: S.propertySignature(S.String.annotations({
|
|
32
|
+
message: () => "must be a string - set DATABASE_URL env var or add connectionString to config",
|
|
33
|
+
})).annotations({
|
|
34
|
+
missingMessage: () => "is required - set DATABASE_URL env var or add connectionString to config",
|
|
35
|
+
}),
|
|
32
36
|
/** PostgreSQL role to assume during introspection (for RLS-aware generation) */
|
|
33
37
|
role: S.optional(S.String),
|
|
34
38
|
/** PostgreSQL schemas to introspect */
|
|
@@ -40,8 +44,15 @@ export const Config = S.Struct({
|
|
|
40
44
|
/** Inflection configuration (validated as Any, properly typed in ConfigInput) */
|
|
41
45
|
inflection: S.optional(S.Any),
|
|
42
46
|
/** Plugins to run */
|
|
43
|
-
plugins: S.Array(S.Any)
|
|
47
|
+
plugins: S.propertySignature(S.Array(S.Any)).annotations({
|
|
48
|
+
missingMessage: () => "is required - add at least one plugin to your config",
|
|
49
|
+
}),
|
|
44
50
|
/** Formatter callback to transform generated code before writing (validated as Any, properly typed in ConfigInput) */
|
|
45
51
|
formatter: S.optional(S.String),
|
|
52
|
+
/**
|
|
53
|
+
* Default file name for symbols that don't match any rule.
|
|
54
|
+
* Relative to outputDir. Default: "index.ts"
|
|
55
|
+
*/
|
|
56
|
+
defaultFile: S.optional(S.String),
|
|
46
57
|
});
|
|
47
58
|
//# sourceMappingURL=config.js.map
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,MAAM,IAAI,CAAC,EAAE,MAAM,QAAQ,
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,MAAM,IAAI,CAAC,EAAE,MAAM,QAAQ,CAAC;AAIrC;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC;IACpC,MAAM,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC;IAC5B,KAAK,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC;IAC3B,MAAM,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC;IAC5B,MAAM,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC;CAC7B,CAAC,CAAC;AAGH;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,KAAK,EAAE,aAAa;IACpB,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;CACrD,CAAC,CAAC;AAGH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;IACH,WAAW,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC;CAClC,CAAC,CAAC"}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* ```typescript
|
|
9
|
-
* import { conjure, cast } from "
|
|
9
|
+
* import { conjure, cast } from "./index.js"
|
|
10
10
|
*
|
|
11
11
|
* // Method chains
|
|
12
12
|
* const schema = conjure.id("z")
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
*/
|
|
36
36
|
import recast from "recast";
|
|
37
37
|
import type { namedTypes as n } from "ast-types";
|
|
38
|
-
import type { ExpressionKind, StatementKind, TSTypeKind, SpreadElementKind, RestElementKind } from "ast-types/lib/gen/kinds.js";
|
|
38
|
+
import type { ExpressionKind, StatementKind, PatternKind, TSTypeKind, SpreadElementKind, RestElementKind } from "ast-types/lib/gen/kinds.js";
|
|
39
39
|
/**
|
|
40
40
|
* The ast-types library uses "Kind" union types that are incompatible with
|
|
41
41
|
* exactOptionalPropertyTypes. We define explicit cast functions that convert
|
|
@@ -139,6 +139,8 @@ export interface ObjBuilder {
|
|
|
139
139
|
spread(expr: n.Expression): ObjBuilder;
|
|
140
140
|
/** Add a shorthand property: `key` (where key is also the value identifier) */
|
|
141
141
|
shorthand(key: string): ObjBuilder;
|
|
142
|
+
/** Add properties from entries: `{ key: value, ... }` */
|
|
143
|
+
fromEntries(entries: Array<[string, n.Expression]>): ObjBuilder;
|
|
142
144
|
/** Finalize and return the object expression */
|
|
143
145
|
build(): n.ObjectExpression;
|
|
144
146
|
}
|
|
@@ -165,6 +167,8 @@ export interface FnBuilder {
|
|
|
165
167
|
restParam(name: string, type?: n.TSType): FnBuilder;
|
|
166
168
|
/** Add a parameter with a default value */
|
|
167
169
|
defaultParam(name: string, defaultValue: n.Expression, type?: n.TSType): FnBuilder;
|
|
170
|
+
/** Add a raw pattern parameter (e.g., destructured object from param.destructured()) */
|
|
171
|
+
rawParam(pattern: PatternKind): FnBuilder;
|
|
168
172
|
/** Set the return type annotation */
|
|
169
173
|
returns(type: n.TSType): FnBuilder;
|
|
170
174
|
/** Set the function body */
|
|
@@ -268,6 +272,8 @@ export declare const conjure: {
|
|
|
268
272
|
readonly obj: () => ObjBuilder;
|
|
269
273
|
/** Start an array literal builder */
|
|
270
274
|
readonly arr: (...elements: n.Expression[]) => ArrBuilder;
|
|
275
|
+
/** Create an array expression directly (handles type casting) */
|
|
276
|
+
readonly arrExpr: (...elements: n.Expression[]) => recast.types.namedTypes.ArrayExpression;
|
|
271
277
|
/** Start a function builder */
|
|
272
278
|
readonly fn: () => FnBuilder;
|
|
273
279
|
/** String literal */
|
|
@@ -282,6 +288,22 @@ export declare const conjure: {
|
|
|
282
288
|
readonly undefined: () => recast.types.namedTypes.Identifier;
|
|
283
289
|
/** Template literal */
|
|
284
290
|
readonly template: (quasis: string[], ...expressions: n.Expression[]) => recast.types.namedTypes.TemplateLiteral;
|
|
291
|
+
/**
|
|
292
|
+
* Tagged template literal: tag`...${expr}...`
|
|
293
|
+
*
|
|
294
|
+
* @param tag - The tag identifier (string or expression)
|
|
295
|
+
* @param quasis - The string parts of the template
|
|
296
|
+
* @param expressions - The interpolated expressions
|
|
297
|
+
* @param typeParams - Optional type parameters for the tag: tag<T>`...`
|
|
298
|
+
*
|
|
299
|
+
* @example
|
|
300
|
+
* // sql`SELECT * FROM users WHERE id = ${id}`
|
|
301
|
+
* conjure.taggedTemplate("sql", ["SELECT * FROM users WHERE id = ", ""], [idExpr])
|
|
302
|
+
*
|
|
303
|
+
* // sql<User>`SELECT * FROM users`
|
|
304
|
+
* conjure.taggedTemplate("sql", ["SELECT * FROM users"], [], [conjure.ts.ref("User")])
|
|
305
|
+
*/
|
|
306
|
+
readonly taggedTemplate: (tag: string | n.Expression, quasis: readonly string[], expressions: readonly n.Expression[], typeParams?: readonly n.TSType[]) => n.TaggedTemplateExpression;
|
|
285
307
|
readonly op: {
|
|
286
308
|
/** Generic binary expression */
|
|
287
309
|
readonly binary: (left: n.Expression, operator: BinaryOp, right: n.Expression) => recast.types.namedTypes.BinaryExpression;
|
|
@@ -330,6 +352,28 @@ export declare const conjure: {
|
|
|
330
352
|
/** Async function declaration */
|
|
331
353
|
readonly asyncFn: (name: string, params: (n.Identifier | n.ObjectPattern)[], body: n.Statement[]) => n.FunctionDeclaration;
|
|
332
354
|
};
|
|
355
|
+
readonly import: {
|
|
356
|
+
/**
|
|
357
|
+
* Named imports: `import { a, b, c } from "source"`
|
|
358
|
+
* Also supports renaming: `import { a as b } from "source"`
|
|
359
|
+
*/
|
|
360
|
+
readonly named: (source: string, ...names: (string | {
|
|
361
|
+
imported: string;
|
|
362
|
+
local: string;
|
|
363
|
+
})[]) => n.ImportDeclaration;
|
|
364
|
+
/**
|
|
365
|
+
* Default import: `import name from "source"`
|
|
366
|
+
*/
|
|
367
|
+
readonly default: (source: string, name: string) => n.ImportDeclaration;
|
|
368
|
+
/**
|
|
369
|
+
* Namespace import: `import * as name from "source"`
|
|
370
|
+
*/
|
|
371
|
+
readonly namespace: (source: string, name: string) => n.ImportDeclaration;
|
|
372
|
+
/**
|
|
373
|
+
* Side-effect import: `import "source"`
|
|
374
|
+
*/
|
|
375
|
+
readonly sideEffect: (source: string) => n.ImportDeclaration;
|
|
376
|
+
};
|
|
333
377
|
readonly export: {
|
|
334
378
|
/**
|
|
335
379
|
* Export const declaration: `export const name = init`
|
|
@@ -494,6 +538,19 @@ export declare const conjure: {
|
|
|
494
538
|
* // { limit = 50, offset = 0 }: { limit?: number; offset?: number }
|
|
495
539
|
*/
|
|
496
540
|
readonly destructured: (fields: readonly DestructuredField[]) => n.ObjectPattern;
|
|
541
|
+
/**
|
|
542
|
+
* Create a destructured parameter with a rest element and intersection type.
|
|
543
|
+
* Useful for functions like: `({ id, ...data }: { id: string } & Updateable<Comment>)`
|
|
544
|
+
*
|
|
545
|
+
* @example
|
|
546
|
+
* param.withRest(
|
|
547
|
+
* [{ name: "id", type: ts.string() }],
|
|
548
|
+
* "data",
|
|
549
|
+
* ts.ref("Updateable", [ts.ref("Comment")])
|
|
550
|
+
* )
|
|
551
|
+
* // { id, ...data }: { id: string } & Updateable<Comment>
|
|
552
|
+
*/
|
|
553
|
+
readonly withRest: (fields: readonly DestructuredField[], restName: string, restType: n.TSType) => n.ObjectPattern;
|
|
497
554
|
};
|
|
498
555
|
readonly exp: {
|
|
499
556
|
/**
|
|
@@ -526,6 +583,8 @@ export declare const conjure: {
|
|
|
526
583
|
};
|
|
527
584
|
/** Await expression */
|
|
528
585
|
readonly await: (expr: n.Expression) => recast.types.namedTypes.AwaitExpression;
|
|
586
|
+
/** Non-null assertion: `expr!` */
|
|
587
|
+
readonly nonNull: (expr: n.Expression) => recast.types.namedTypes.TSNonNullExpression;
|
|
529
588
|
/** Spread expression (for use in arrays/calls) */
|
|
530
589
|
readonly spread: (expr: n.Expression) => recast.types.namedTypes.SpreadElement;
|
|
531
590
|
/** Print AST node to code string */
|
|
@@ -542,4 +601,4 @@ export declare const conjure: {
|
|
|
542
601
|
readonly b: import("ast-types/lib/gen/builders").builders;
|
|
543
602
|
};
|
|
544
603
|
export default conjure;
|
|
545
|
-
//# sourceMappingURL=
|
|
604
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/conjure/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,KAAK,EAAE,UAAU,IAAI,CAAC,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,WAAW,EACX,UAAU,EAKV,iBAAiB,EACjB,eAAe,EAShB,MAAM,4BAA4B,CAAC;AAQpC;;;;;;;GAOG;AAEH,2EAA2E;AAC3E,iBAAS,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC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AAa;;;QAgNlB;;WAEG;mCAEK,MAAM,OACP,aAAa,cACN,mBAAmB,EAAE,KAChC,eAAe;QASlB;;WAEG;mCACe,MAAM,OAAO,aAAa,QAAQ,CAAC,CAAC,MAAM,KAAG,eAAe;QAM9E;;WAEG;+BAEK,MAAM,OACP,aAAa,QACZ,CAAC,CAAC,UAAU,mBACD,CAAC,CAAC,MAAM,KACxB,eAAe;QAUlB;;;WAGG;8BACU,MAAM,OAAO,aAAa,QAAQ,CAAC,CAAC,MAAM,KAAG,eAAe;QAQzE;;;;;;;;WAQG;gCACY,MAAM,OAAO,aAAa,UAAU,SAAS,MAAM,EAAE,KAAG,eAAe;;IA0NtF,uBAAuB;2BACT,CAAC,CAAC,UAAU;IAE1B,kCAAkC;6BAClB,CAAC,CAAC,UAAU;IAE5B,kDAAkD;4BACnC,CAAC,CAAC,UAAU;IAE3B,oCAAoC;2BACtB,CAAC,CAAC,IAAI;IAEpB,8DAA8D;sCACrC,CAAC,CAAC,SAAS,EAAE;IAEtC;;;;OAIG;;IAKH,iDAAiD;;CAEzC,CAAC;AAEX,eAAe,OAAO,CAAC"}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* ```typescript
|
|
9
|
-
* import { conjure, cast } from "
|
|
9
|
+
* import { conjure, cast } from "./index.js"
|
|
10
10
|
*
|
|
11
11
|
* // Method chains
|
|
12
12
|
* const schema = conjure.id("z")
|
|
@@ -123,6 +123,10 @@ function createObj(props = []) {
|
|
|
123
123
|
prop.shorthand = true;
|
|
124
124
|
return createObj([...props, prop]);
|
|
125
125
|
},
|
|
126
|
+
fromEntries(entries) {
|
|
127
|
+
const newProps = entries.map(([key, value]) => b.objectProperty(b.identifier(key), toExpr(value)));
|
|
128
|
+
return createObj([...props, ...newProps]);
|
|
129
|
+
},
|
|
126
130
|
build() {
|
|
127
131
|
return b.objectExpression(props);
|
|
128
132
|
},
|
|
@@ -144,6 +148,9 @@ function createArr(elems = []) {
|
|
|
144
148
|
},
|
|
145
149
|
};
|
|
146
150
|
}
|
|
151
|
+
function isFnRawParam(p) {
|
|
152
|
+
return "pattern" in p;
|
|
153
|
+
}
|
|
147
154
|
const defaultParam = (name, type) => ({
|
|
148
155
|
name,
|
|
149
156
|
type,
|
|
@@ -153,6 +160,10 @@ const defaultParam = (name, type) => ({
|
|
|
153
160
|
});
|
|
154
161
|
function createFn(config) {
|
|
155
162
|
const buildParams = () => config.params.map((p) => {
|
|
163
|
+
// Raw pattern params (e.g., destructured objects)
|
|
164
|
+
if (isFnRawParam(p)) {
|
|
165
|
+
return p.pattern;
|
|
166
|
+
}
|
|
156
167
|
if (p.rest) {
|
|
157
168
|
const restId = b.identifier(p.name);
|
|
158
169
|
if (p.type) {
|
|
@@ -204,6 +215,12 @@ function createFn(config) {
|
|
|
204
215
|
params: [...config.params, { ...defaultParam(name, type), defaultValue }],
|
|
205
216
|
});
|
|
206
217
|
},
|
|
218
|
+
rawParam(pattern) {
|
|
219
|
+
return createFn({
|
|
220
|
+
...config,
|
|
221
|
+
params: [...config.params, { pattern }],
|
|
222
|
+
});
|
|
223
|
+
},
|
|
207
224
|
returns(type) {
|
|
208
225
|
return createFn({ ...config, returnType: type });
|
|
209
226
|
},
|
|
@@ -605,10 +622,81 @@ const param = {
|
|
|
605
622
|
return prop;
|
|
606
623
|
}));
|
|
607
624
|
// Build the type annotation: { name: type; name?: type; }
|
|
608
|
-
const typeAnnotation = ts.objectType(fields.map(f => ({ name: f.name, type: f.type, optional: f.optional })));
|
|
625
|
+
const typeAnnotation = ts.objectType(fields.map(f => ({ name: f.name, type: toTSType(f.type), optional: f.optional })));
|
|
609
626
|
pattern.typeAnnotation = b.tsTypeAnnotation(toTSType(typeAnnotation));
|
|
610
627
|
return pattern;
|
|
611
628
|
},
|
|
629
|
+
/**
|
|
630
|
+
* Create a destructured parameter with a rest element and intersection type.
|
|
631
|
+
* Useful for functions like: `({ id, ...data }: { id: string } & Updateable<Comment>)`
|
|
632
|
+
*
|
|
633
|
+
* @example
|
|
634
|
+
* param.withRest(
|
|
635
|
+
* [{ name: "id", type: ts.string() }],
|
|
636
|
+
* "data",
|
|
637
|
+
* ts.ref("Updateable", [ts.ref("Comment")])
|
|
638
|
+
* )
|
|
639
|
+
* // { id, ...data }: { id: string } & Updateable<Comment>
|
|
640
|
+
*/
|
|
641
|
+
withRest: (fields, restName, restType) => {
|
|
642
|
+
const properties = fields.map(f => {
|
|
643
|
+
const id = b.identifier(f.name);
|
|
644
|
+
const value = f.defaultValue ? b.assignmentPattern(id, toExpr(f.defaultValue)) : id;
|
|
645
|
+
const prop = b.objectProperty(b.identifier(f.name), value);
|
|
646
|
+
prop.shorthand = true;
|
|
647
|
+
return prop;
|
|
648
|
+
});
|
|
649
|
+
// Add rest element: ...data
|
|
650
|
+
const restId = b.identifier(restName);
|
|
651
|
+
properties.push(b.restElement(restId));
|
|
652
|
+
const pattern = b.objectPattern(properties);
|
|
653
|
+
// Build intersection type: { id: string } & RestType
|
|
654
|
+
const objType = ts.objectType(fields.map(f => ({ name: f.name, type: toTSType(f.type), optional: f.optional })));
|
|
655
|
+
const intersectionType = b.tsIntersectionType([toTSType(objType), toTSType(restType)]);
|
|
656
|
+
pattern.typeAnnotation = b.tsTypeAnnotation(intersectionType);
|
|
657
|
+
return pattern;
|
|
658
|
+
},
|
|
659
|
+
};
|
|
660
|
+
// =============================================================================
|
|
661
|
+
// Import Statement Helpers (conjure.import.*)
|
|
662
|
+
// =============================================================================
|
|
663
|
+
/**
|
|
664
|
+
* Import statement builders for generating import declarations.
|
|
665
|
+
*/
|
|
666
|
+
const importHelpers = {
|
|
667
|
+
/**
|
|
668
|
+
* Named imports: `import { a, b, c } from "source"`
|
|
669
|
+
* Also supports renaming: `import { a as b } from "source"`
|
|
670
|
+
*/
|
|
671
|
+
named: (source, ...names) => {
|
|
672
|
+
const specifiers = names.map(n => {
|
|
673
|
+
if (typeof n === "string") {
|
|
674
|
+
return b.importSpecifier(b.identifier(n), b.identifier(n));
|
|
675
|
+
}
|
|
676
|
+
else {
|
|
677
|
+
return b.importSpecifier(b.identifier(n.imported), b.identifier(n.local));
|
|
678
|
+
}
|
|
679
|
+
});
|
|
680
|
+
return b.importDeclaration(specifiers, b.stringLiteral(source));
|
|
681
|
+
},
|
|
682
|
+
/**
|
|
683
|
+
* Default import: `import name from "source"`
|
|
684
|
+
*/
|
|
685
|
+
default: (source, name) => {
|
|
686
|
+
return b.importDeclaration([b.importDefaultSpecifier(b.identifier(name))], b.stringLiteral(source));
|
|
687
|
+
},
|
|
688
|
+
/**
|
|
689
|
+
* Namespace import: `import * as name from "source"`
|
|
690
|
+
*/
|
|
691
|
+
namespace: (source, name) => {
|
|
692
|
+
return b.importDeclaration([b.importNamespaceSpecifier(b.identifier(name))], b.stringLiteral(source));
|
|
693
|
+
},
|
|
694
|
+
/**
|
|
695
|
+
* Side-effect import: `import "source"`
|
|
696
|
+
*/
|
|
697
|
+
sideEffect: (source) => {
|
|
698
|
+
return b.importDeclaration([], b.stringLiteral(source));
|
|
699
|
+
},
|
|
612
700
|
};
|
|
613
701
|
// =============================================================================
|
|
614
702
|
// Export Statement Helpers (conjure.export.*)
|
|
@@ -846,6 +934,8 @@ export const conjure = {
|
|
|
846
934
|
obj: () => createObj(),
|
|
847
935
|
/** Start an array literal builder */
|
|
848
936
|
arr: (...elements) => createArr(elements.map(e => toExpr(e))),
|
|
937
|
+
/** Create an array expression directly (handles type casting) */
|
|
938
|
+
arrExpr: (...elements) => b.arrayExpression(elements.map(e => toExpr(e))),
|
|
849
939
|
/** Start a function builder */
|
|
850
940
|
fn: () => createFn({
|
|
851
941
|
params: [],
|
|
@@ -871,10 +961,39 @@ export const conjure = {
|
|
|
871
961
|
const templateElements = quasis.map((raw, i) => b.templateElement({ raw, cooked: raw }, i === quasis.length - 1));
|
|
872
962
|
return b.templateLiteral(templateElements, expressions.map(toExpr));
|
|
873
963
|
},
|
|
964
|
+
/**
|
|
965
|
+
* Tagged template literal: tag`...${expr}...`
|
|
966
|
+
*
|
|
967
|
+
* @param tag - The tag identifier (string or expression)
|
|
968
|
+
* @param quasis - The string parts of the template
|
|
969
|
+
* @param expressions - The interpolated expressions
|
|
970
|
+
* @param typeParams - Optional type parameters for the tag: tag<T>`...`
|
|
971
|
+
*
|
|
972
|
+
* @example
|
|
973
|
+
* // sql`SELECT * FROM users WHERE id = ${id}`
|
|
974
|
+
* conjure.taggedTemplate("sql", ["SELECT * FROM users WHERE id = ", ""], [idExpr])
|
|
975
|
+
*
|
|
976
|
+
* // sql<User>`SELECT * FROM users`
|
|
977
|
+
* conjure.taggedTemplate("sql", ["SELECT * FROM users"], [], [conjure.ts.ref("User")])
|
|
978
|
+
*/
|
|
979
|
+
taggedTemplate: (tag, quasis, expressions, typeParams) => {
|
|
980
|
+
const templateElements = quasis.map((raw, i) => b.templateElement({ raw, cooked: raw }, i === quasis.length - 1));
|
|
981
|
+
const templateLiteral = b.templateLiteral(templateElements, expressions.map(toExpr));
|
|
982
|
+
const tagExpr = typeof tag === "string" ? b.identifier(tag) : toExpr(tag);
|
|
983
|
+
const tagged = b.taggedTemplateExpression(tagExpr, templateLiteral);
|
|
984
|
+
// Add type parameters if provided: sql<User>`...`
|
|
985
|
+
if (typeParams && typeParams.length > 0) {
|
|
986
|
+
tagged.typeParameters =
|
|
987
|
+
b.tsTypeParameterInstantiation(typeParams.map(toTSType));
|
|
988
|
+
}
|
|
989
|
+
return tagged;
|
|
990
|
+
},
|
|
874
991
|
// === Operators ===
|
|
875
992
|
op,
|
|
876
993
|
// === Statements ===
|
|
877
994
|
stmt,
|
|
995
|
+
// === Import statements ===
|
|
996
|
+
import: importHelpers,
|
|
878
997
|
// === Export statements ===
|
|
879
998
|
export: exportHelpers,
|
|
880
999
|
/** Async function declaration */
|
|
@@ -896,6 +1015,8 @@ export const conjure = {
|
|
|
896
1015
|
// === Helpers ===
|
|
897
1016
|
/** Await expression */
|
|
898
1017
|
await: (expr) => b.awaitExpression(toExpr(expr)),
|
|
1018
|
+
/** Non-null assertion: `expr!` */
|
|
1019
|
+
nonNull: (expr) => b.tsNonNullExpression(toExpr(expr)),
|
|
899
1020
|
/** Spread expression (for use in arrays/calls) */
|
|
900
1021
|
spread: (expr) => b.spreadElement(toExpr(expr)),
|
|
901
1022
|
/** Print AST node to code string */
|
|
@@ -913,4 +1034,4 @@ export const conjure = {
|
|
|
913
1034
|
b,
|
|
914
1035
|
};
|
|
915
1036
|
export default conjure;
|
|
916
|
-
//# sourceMappingURL=
|
|
1037
|
+
//# sourceMappingURL=index.js.map
|