@cosmicdrift/kumiko-dev-server 0.328.1 → 0.330.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.
Files changed (125) hide show
  1. package/README.md +17 -0
  2. package/bin/kumiko-build.ts +3 -2
  3. package/bin/kumiko-dev.ts +1 -1
  4. package/bin/kumiko-init-deploy.ts +1 -1
  5. package/bin/kumiko-schema-check.ts +4 -1
  6. package/dist/build-server-bundle.d.ts +31 -0
  7. package/dist/build-server-bundle.js +282 -0
  8. package/dist/build.d.ts +2 -0
  9. package/dist/build.js +5 -0
  10. package/dist/cli.d.ts +5 -0
  11. package/dist/cli.js +9 -0
  12. package/dist/codegen/index.d.ts +4 -0
  13. package/dist/codegen/index.js +4 -0
  14. package/dist/codegen/render.d.ts +55 -0
  15. package/dist/codegen/render.js +273 -0
  16. package/dist/codegen/run-codegen.d.ts +20 -0
  17. package/dist/codegen/run-codegen.js +219 -0
  18. package/dist/codegen/scan-events.d.ts +76 -0
  19. package/dist/codegen/scan-events.js +447 -0
  20. package/dist/codegen/watch.d.ts +33 -0
  21. package/dist/codegen/watch.js +112 -0
  22. package/dist/compose-stacks.d.ts +60 -0
  23. package/dist/compose-stacks.js +127 -0
  24. package/dist/crash-tracker.d.ts +17 -0
  25. package/dist/crash-tracker.js +37 -0
  26. package/dist/create-kumiko-server.d.ts +195 -0
  27. package/dist/create-kumiko-server.js +1040 -0
  28. package/dist/env-schema.d.ts +15 -0
  29. package/dist/env-schema.js +60 -0
  30. package/dist/few-shot-corpus.d.ts +72 -0
  31. package/dist/few-shot-corpus.js +262 -0
  32. package/dist/framework-version.d.ts +1 -0
  33. package/dist/framework-version.js +31 -0
  34. package/dist/index.d.ts +22 -0
  35. package/dist/index.js +33 -0
  36. package/dist/init-deploy-cli.d.ts +10 -0
  37. package/dist/init-deploy-cli.js +111 -0
  38. package/dist/kebab.d.ts +1 -0
  39. package/{src/kebab.ts → dist/kebab.js} +2 -3
  40. package/dist/run-dev-app.d.ts +174 -0
  41. package/dist/run-dev-app.js +403 -0
  42. package/dist/scaffold-app-feature.d.ts +16 -0
  43. package/dist/scaffold-app-feature.js +240 -0
  44. package/dist/scaffold-app.d.ts +45 -0
  45. package/dist/scaffold-app.js +852 -0
  46. package/dist/scaffold-demo-tasks.d.ts +8 -0
  47. package/{src/scaffold-demo-tasks.ts → dist/scaffold-demo-tasks.js} +69 -98
  48. package/dist/scaffold-deploy.d.ts +92 -0
  49. package/dist/scaffold-deploy.js +254 -0
  50. package/dist/scaffold-feature.d.ts +26 -0
  51. package/dist/scaffold-feature.js +163 -0
  52. package/dist/schema-apply.d.ts +11 -0
  53. package/dist/schema-apply.js +95 -0
  54. package/dist/schema-check-core.d.ts +2 -0
  55. package/{src/schema-check-core.ts → dist/schema-check-core.js} +8 -10
  56. package/dist/schema-tables-auth-mode.d.ts +2 -0
  57. package/{src/schema-tables-auth-mode.ts → dist/schema-tables-auth-mode.js} +2 -10
  58. package/dist/schema-tables-minimal.d.ts +2 -0
  59. package/{src/schema-tables-minimal.ts → dist/schema-tables-minimal.js} +2 -11
  60. package/dist/setup-test-stack-from-features.d.ts +11 -0
  61. package/dist/setup-test-stack-from-features.js +42 -0
  62. package/dist/welcome-banner.d.ts +15 -0
  63. package/dist/welcome-banner.js +27 -0
  64. package/package.json +71 -24
  65. package/src/changes.json +6 -0
  66. package/src/__tests__/build-prod-bundle.integration.test.ts +0 -282
  67. package/src/__tests__/build-server-bundle.test.ts +0 -228
  68. package/src/__tests__/classify-change.test.ts +0 -87
  69. package/src/__tests__/compose-stacks.test.ts +0 -273
  70. package/src/__tests__/config-resolver-default.integration.test.ts +0 -165
  71. package/src/__tests__/crash-tracker.test.ts +0 -89
  72. package/src/__tests__/create-kumiko-server-errors.test.ts +0 -54
  73. package/src/__tests__/create-kumiko-server-options.test.ts +0 -33
  74. package/src/__tests__/create-kumiko-server.integration.test.ts +0 -1007
  75. package/src/__tests__/discover-format.test.ts +0 -32
  76. package/src/__tests__/env-schema.integration.test.ts +0 -248
  77. package/src/__tests__/env-schema.test.ts +0 -132
  78. package/src/__tests__/few-shot-corpus.test.ts +0 -316
  79. package/src/__tests__/framework-version.test.ts +0 -45
  80. package/src/__tests__/init-deploy-cli.test.ts +0 -113
  81. package/src/__tests__/kumiko-schema-check.test.ts +0 -56
  82. package/src/__tests__/merge-extra-context.test.ts +0 -67
  83. package/src/__tests__/resolve-stylesheet.test.ts +0 -132
  84. package/src/__tests__/run-dev-app-boot-validation.test.ts +0 -38
  85. package/src/__tests__/run-dev-app.integration.test.ts +0 -290
  86. package/src/__tests__/runtime-classification.test.ts +0 -26
  87. package/src/__tests__/saas-identity-wire.integration.test.ts +0 -427
  88. package/src/__tests__/scaffold-app-feature.test.ts +0 -216
  89. package/src/__tests__/scaffold-app.test.ts +0 -630
  90. package/src/__tests__/scaffold-demo-tasks.test.ts +0 -47
  91. package/src/__tests__/scaffold-deploy.test.ts +0 -464
  92. package/src/__tests__/scaffold-dev-cycle.integration.test.ts +0 -109
  93. package/src/__tests__/scaffold-feature.test.ts +0 -143
  94. package/src/__tests__/schema-apply.integration.test.ts +0 -191
  95. package/src/__tests__/setup-test-stack-from-features.integration.test.ts +0 -30
  96. package/src/__tests__/setup-test-stack-job-run-logger.integration.test.ts +0 -72
  97. package/src/__tests__/walkthrough.integration.test.ts +0 -140
  98. package/src/__tests__/welcome-banner.test.ts +0 -42
  99. package/src/build-server-bundle.ts +0 -346
  100. package/src/build.ts +0 -28
  101. package/src/codegen/__tests__/render-codegen.test.ts +0 -100
  102. package/src/codegen/__tests__/run-codegen.test.ts +0 -665
  103. package/src/codegen/__tests__/strict-mode-diagnostics.test.ts +0 -347
  104. package/src/codegen/__tests__/watch.test.ts +0 -222
  105. package/src/codegen/index.ts +0 -19
  106. package/src/codegen/render.ts +0 -305
  107. package/src/codegen/run-codegen.ts +0 -278
  108. package/src/codegen/scan-events.ts +0 -565
  109. package/src/codegen/watch.ts +0 -140
  110. package/src/compose-stacks.ts +0 -193
  111. package/src/crash-tracker.ts +0 -56
  112. package/src/create-kumiko-server.ts +0 -1397
  113. package/src/env-schema.ts +0 -72
  114. package/src/few-shot-corpus.ts +0 -370
  115. package/src/framework-version.ts +0 -39
  116. package/src/index.ts +0 -105
  117. package/src/init-deploy-cli.ts +0 -148
  118. package/src/run-dev-app.ts +0 -694
  119. package/src/scaffold-app-feature.ts +0 -283
  120. package/src/scaffold-app.ts +0 -1033
  121. package/src/scaffold-deploy.ts +0 -393
  122. package/src/scaffold-feature.ts +0 -226
  123. package/src/schema-apply.ts +0 -123
  124. package/src/setup-test-stack-from-features.ts +0 -80
  125. package/src/welcome-banner.ts +0 -43
@@ -1,123 +0,0 @@
1
- // Standalone `kumiko schema apply` für Production-Bundles. Apps bündeln ein
2
- // dünnes bin/kumiko.ts das nur runStandaloneSchemaCli mit den App-Features
3
- // aufruft — die ganze Orchestrierung (Infra-Bootstrap, Migrations,
4
- // Projection-Rebuild) lebt hier statt als ~100-Zeilen-Boilerplate pro App.
5
- //
6
- // Der Pulumi-migrate-initContainer ruft `bun /app/kumiko.js schema apply`;
7
- // kumiko-build entdeckt das App-bin via findRepoRoot() und bündelt es.
8
-
9
- import { existsSync } from "node:fs";
10
- import { join } from "node:path";
11
- import { createDbConnection, runMigrationsFromDir } from "@cosmicdrift/kumiko-framework/db";
12
- import { createRegistry, type FeatureDefinition } from "@cosmicdrift/kumiko-framework/engine";
13
- import { createEventsTable } from "@cosmicdrift/kumiko-framework/event-store";
14
- import {
15
- queueRebuildsFromMarkers,
16
- runPendingRebuilds,
17
- } from "@cosmicdrift/kumiko-framework/migrations";
18
- import {
19
- createEventConsumerStateTable,
20
- createProjectionStateTable,
21
- } from "@cosmicdrift/kumiko-framework/pipeline";
22
- import {
23
- type ComposeFeaturesOptions,
24
- composeFeatures,
25
- } from "@cosmicdrift/kumiko-server-runtime/compose-features";
26
-
27
- export type SchemaApplyOptions = ComposeFeaturesOptions & {
28
- /** App-Features (z.B. APP_FEATURES aus run-config) — composed mit den
29
- * bundled-Features für den Projection-Rebuild-Registry. */
30
- readonly features: readonly FeatureDefinition[];
31
- /** Default INIT_CWD ?? process.cwd(); Migrations unter <appCwd>/kumiko/migrations. */
32
- readonly appCwd?: string;
33
- };
34
-
35
- export async function runSchemaApply(opts: SchemaApplyOptions): Promise<number> {
36
- const dbUrl = process.env["DATABASE_URL"];
37
- if (!dbUrl) {
38
- console.error("\n DATABASE_URL not set.\n");
39
- return 1;
40
- }
41
-
42
- const appCwd = opts.appCwd ?? process.env["INIT_CWD"] ?? process.cwd();
43
- const migrationsDir = join(appCwd, "kumiko/migrations");
44
- if (!existsSync(migrationsDir)) {
45
- console.error(`\n ${migrationsDir} fehlt — kumiko/migrations/ muss im Image liegen.\n`);
46
- return 1;
47
- }
48
-
49
- const { db, close } = createDbConnection(dbUrl);
50
- try {
51
- // Infra-Tabellen (event-store + pipeline-state) zuerst, alle
52
- // tableExists-gated idempotent: auf einer Bestands-DB no-op, auf einer
53
- // leeren Greenfield-DB legen sie kumiko_events/_consumers/_projections an
54
- // bevor die App-Migrations dagegen laufen. Ohne das bricht eine leere DB
55
- // (z.B. cashcolt auf frischem CNPG) an `relation "kumiko_events" does not exist`.
56
- console.log("\n Lege Framework-Infra-Tabellen an (idempotent)…");
57
- await createEventsTable(db);
58
- await createEventConsumerStateTable(db);
59
- await createProjectionStateTable(db);
60
-
61
- console.log(` Wende kumiko-Migrations an (${migrationsDir})…`);
62
- const result = await runMigrationsFromDir(db, migrationsDir);
63
- if (result.applied.length === 0) {
64
- console.log(`\n ✓ All ${result.skipped.length} migrations already applied.\n`);
65
- } else {
66
- console.log(`\n ✓ Applied ${result.applied.length}:`);
67
- for (const id of result.applied) console.log(` + ${id}`);
68
- if (result.skipped.length > 0) console.log(` (${result.skipped.length} already applied)`);
69
- console.log("");
70
- }
71
-
72
- // Projection rebuild: persistent queue instead of "only this run's
73
- // result.applied" — otherwise a failed rebuild stays silently stuck
74
- // forever, since the migration is already tracked applied and gets
75
- // skipped on the next apply (#2464). queueRebuildsFromMarkers persists
76
- // the marker tables BEFORE the rebuild; runPendingRebuilds unconditionally
77
- // also picks up open entries from earlier, failed runs — not just the
78
- // ones this run freshly applied.
79
- const thisRunTables = await queueRebuildsFromMarkers(db, {
80
- migrationsDir,
81
- appliedIds: result.applied,
82
- });
83
- const registry = createRegistry(composeFeatures([...opts.features], opts));
84
- const rebuildRun = await runPendingRebuilds(db, registry, { thisRunTables });
85
- if (rebuildRun.rebuilt.length > 0) {
86
- console.log(` Rebuild ${rebuildRun.rebuilt.length} Projection(s)…`);
87
- for (const r of rebuildRun.rebuilt) {
88
- console.log(` ↻ ${r.projection} (${r.eventsProcessed} events)`);
89
- }
90
- console.log("");
91
- }
92
- if (rebuildRun.failed.length > 0) {
93
- throw new Error(
94
- `Projection rebuild failed for: ${rebuildRun.failed
95
- .map((f) => `${f.projection} (${f.error})`)
96
- .join(
97
- "; ",
98
- )}. Table(s) stay queued in kumiko_pending_rebuilds — retried on the next apply.`,
99
- );
100
- }
101
-
102
- return 0;
103
- } catch (e) {
104
- console.error(`\n ✗ ${e instanceof Error ? (e.stack ?? e.message) : String(e)}\n`);
105
- return 1;
106
- } finally {
107
- await close();
108
- }
109
- }
110
-
111
- export async function runStandaloneSchemaCli(opts: SchemaApplyOptions): Promise<never> {
112
- const cmd = Bun.argv[2];
113
- const sub = Bun.argv[3];
114
-
115
- if (cmd === "schema" && sub === "apply") {
116
- process.exit(await runSchemaApply(opts));
117
- }
118
-
119
- console.error(
120
- `\n Unbekannt: kumiko ${cmd ?? ""} ${sub ?? ""}\n Nur 'kumiko schema apply' im Standalone-Bundle.\n`,
121
- );
122
- process.exit(1);
123
- }
@@ -1,80 +0,0 @@
1
- // Test helper: composeFeatures + setupTestStack in one call.
2
- // Apps pass the same feature list as run-config (APP_FEATURES / buildAppFeatures).
3
-
4
- import {
5
- type ConfigResolver,
6
- createConfigResolver,
7
- } from "@cosmicdrift/kumiko-bundled-features/config";
8
- import { createTemplateResolverApi } from "@cosmicdrift/kumiko-bundled-features/template-resolver";
9
- import type { FeatureDefinition } from "@cosmicdrift/kumiko-framework/engine";
10
- import {
11
- setupTestStack,
12
- type TestStack,
13
- type TestStackOptions,
14
- } from "@cosmicdrift/kumiko-framework/stack";
15
- import { jobRunLoggerCallbacks } from "@cosmicdrift/kumiko-server-runtime/boot/job-run-logger";
16
- import {
17
- type ComposeFeaturesOptions,
18
- composeFeatures,
19
- } from "@cosmicdrift/kumiko-server-runtime/compose-features";
20
- import { addConfigAccessorFactory } from "@cosmicdrift/kumiko-server-runtime/run-prod-app";
21
-
22
- export type TestStackPreset = "config" | "template-resolver";
23
-
24
- export type SetupTestStackFromFeaturesOptions = Omit<TestStackOptions, "features"> & {
25
- readonly includeBundled?: boolean;
26
- readonly authOptions?: ComposeFeaturesOptions["authOptions"];
27
- readonly presets?: readonly TestStackPreset[];
28
- };
29
-
30
- export function mergeExtraContext(
31
- base: TestStackOptions["extraContext"],
32
- presets: readonly TestStackPreset[],
33
- ): TestStackOptions["extraContext"] {
34
- if (presets.length === 0) return base;
35
-
36
- return (deps) => {
37
- const fromBase =
38
- typeof base === "function" ? base(deps) : base !== undefined ? { ...base } : {};
39
- const merged: Record<string, unknown> = { ...fromBase };
40
-
41
- if (presets.includes("config")) {
42
- // Same precedence as mergeConfigResolverDefault (run-dev-app.ts) — a base-supplied resolver wins, factory always derives from it (fw#3313).
43
- const configResolver =
44
- (fromBase["configResolver"] as ConfigResolver | undefined) ?? createConfigResolver();
45
- Object.assign(merged, addConfigAccessorFactory({ configResolver }, deps.registry));
46
- }
47
- if (presets.includes("template-resolver")) {
48
- merged["templateResolver"] = createTemplateResolverApi(deps.db);
49
- }
50
-
51
- return merged;
52
- };
53
- }
54
-
55
- export async function setupTestStackFromFeatures(
56
- appFeatures: readonly FeatureDefinition[],
57
- options: SetupTestStackFromFeaturesOptions = {},
58
- ): Promise<TestStack> {
59
- const { includeBundled = false, authOptions, presets = [], ...stackOptions } = options;
60
- const features = composeFeatures(appFeatures, { includeBundled, authOptions });
61
- const extraContext = mergeExtraContext(stackOptions.extraContext, presets);
62
-
63
- // Same run-logger wiring as prod, so jobs that declare tenantVisibleFailure
64
- // write their failure rows in tests too.
65
- const defaultRunLogger: NonNullable<NonNullable<TestStackOptions["jobs"]>["runLogger"]> = ({
66
- registry,
67
- db,
68
- }) => jobRunLoggerCallbacks(registry, db);
69
- const jobs =
70
- stackOptions.jobs === undefined
71
- ? undefined
72
- : { runLogger: defaultRunLogger, ...stackOptions.jobs };
73
-
74
- return setupTestStack({
75
- ...stackOptions,
76
- ...(jobs !== undefined && { jobs }),
77
- features,
78
- ...(extraContext !== undefined && { extraContext }),
79
- });
80
- }
@@ -1,43 +0,0 @@
1
- // First-run welcome banner for `runDevApp({ welcomeBanner: true })`.
2
- // Opt-in only — `bun dev` should not normalize this for apps that
3
- // already log their own startup. Scaffolded apps (create-kumiko-app)
4
- // flip it on so the first `bun dev` doesn't end on "Server läuft" with
5
- // the user wondering where to click.
6
-
7
- export type WelcomeBannerInput = {
8
- /** Resolved listen-URL (`http://localhost:3000`). */
9
- readonly url: string;
10
- /** Login the seeded admin uses (from runDevApp options.auth.admin). */
11
- readonly admin?: { readonly email: string; readonly password: string };
12
- /** Hot-reload hint shown in the "add a feature" line. Defaults to
13
- * `src/features/`. */
14
- readonly featuresDir?: string;
15
- /** Custom docs URL — defaults to the public docs site. */
16
- readonly docsUrl?: string;
17
- };
18
-
19
- export function renderWelcomeBanner(input: WelcomeBannerInput): string {
20
- const featuresDir = input.featuresDir ?? "src/features/";
21
- const docsUrl = input.docsUrl ?? "https://docs.kumiko.rocks/quickstart";
22
-
23
- const lines: string[] = [];
24
- lines.push(`✓ kumiko-app läuft`);
25
- lines.push(`→ Browser: ${input.url}`);
26
- if (input.admin) {
27
- lines.push(`→ Login als: ${input.admin.email} / ${input.admin.password}`);
28
- }
29
- lines.push(`→ Feature add: edit ${featuresDir}`);
30
- lines.push(`→ Docs: ${docsUrl}`);
31
-
32
- const innerWidth = Math.max(...lines.map((l) => stringWidth(l)));
33
- const border = "─".repeat(innerWidth + 2);
34
- const top = `┌${border}┐`;
35
- const bottom = `└${border}┘`;
36
- const padded = lines.map((l) => `│ ${l}${" ".repeat(innerWidth - stringWidth(l))} │`);
37
- return [top, ...padded, bottom].join("\n");
38
- }
39
-
40
- // ponytail: codepoint width; ok for ASCII + arrows, add a width-lib if CJK ever lands here.
41
- function stringWidth(s: string): number {
42
- return [...s].length;
43
- }