@cosmicdrift/kumiko-framework 0.336.1 → 0.338.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 (116) hide show
  1. package/dist/api/api-constants.d.ts +1 -0
  2. package/dist/api/api-constants.js +9 -0
  3. package/dist/api/auth-middleware.js +45 -21
  4. package/dist/api/auth-routes.d.ts +1 -0
  5. package/dist/api/auth-routes.js +20 -0
  6. package/dist/api/redis-sse-broker.d.ts +1 -0
  7. package/dist/api/redis-sse-broker.js +4 -5
  8. package/dist/api/server.js +14 -4
  9. package/dist/api/sse-route.js +14 -1
  10. package/dist/bun-db/query.js +6 -4
  11. package/dist/compliance/sub-processors.js +10 -1
  12. package/dist/crypto/kek-source.js +1 -0
  13. package/dist/db/blind-index-cleanup.d.ts +1 -0
  14. package/dist/db/blind-index-cleanup.js +12 -1
  15. package/dist/db/event-store-executor-read.js +30 -4
  16. package/dist/db/index.d.ts +1 -1
  17. package/dist/db/index.js +1 -1
  18. package/dist/db/queries/event-consumer.d.ts +2 -2
  19. package/dist/db/queries/event-consumer.js +5 -4
  20. package/dist/db/queries/event-store.js +6 -6
  21. package/dist/db/queries/projection-rebuild.js +4 -4
  22. package/dist/db/queries/seed-context.js +6 -6
  23. package/dist/db/tenant-db.js +16 -8
  24. package/dist/derivatives/derivatives-context.js +5 -2
  25. package/dist/engine/boot-validator/access-declarations.js +13 -7
  26. package/dist/engine/boot-validator/entity-handler.d.ts +1 -0
  27. package/dist/engine/boot-validator/entity-handler.js +26 -0
  28. package/dist/engine/boot-validator/index.js +2 -1
  29. package/dist/engine/boot-validator/pii-retention.js +11 -1
  30. package/dist/engine/boot-validator/projection-list-screens.d.ts +1 -1
  31. package/dist/engine/boot-validator/projection-list-screens.js +13 -0
  32. package/dist/engine/boot-validator/screens.js +12 -0
  33. package/dist/engine/build-config-feature-schema.js +4 -0
  34. package/dist/engine/config-helpers.d.ts +2 -1
  35. package/dist/engine/config-helpers.js +1 -0
  36. package/dist/engine/define-feature.js +1 -0
  37. package/dist/engine/extensions/escape-hatch-usage.js +3 -1
  38. package/dist/engine/feature-ast/extractors/hooks.js +7 -1
  39. package/dist/engine/feature-ast/extractors/index.d.ts +1 -1
  40. package/dist/engine/feature-ast/extractors/index.js +1 -1
  41. package/dist/engine/feature-ast/extractors/jobs-routes.js +6 -2
  42. package/dist/engine/feature-ast/extractors/round3.d.ts +2 -1
  43. package/dist/engine/feature-ast/extractors/round3.js +11 -0
  44. package/dist/engine/feature-ast/extractors/shared.js +1 -3
  45. package/dist/engine/feature-ast/index.d.ts +1 -1
  46. package/dist/engine/feature-ast/parse.js +3 -1
  47. package/dist/engine/feature-ast/patch.d.ts +3 -0
  48. package/dist/engine/feature-ast/patch.js +8 -11
  49. package/dist/engine/feature-ast/patcher.d.ts +6 -1
  50. package/dist/engine/feature-ast/patcher.js +3 -0
  51. package/dist/engine/feature-ast/pattern-change-schema.d.ts +630 -1
  52. package/dist/engine/feature-ast/pattern-change-schema.js +19 -2
  53. package/dist/engine/feature-ast/patterns.d.ts +8 -2
  54. package/dist/engine/feature-ast/patterns.js +1 -0
  55. package/dist/engine/feature-ast/render.js +9 -0
  56. package/dist/engine/feature-builder-state.d.ts +2 -1
  57. package/dist/engine/feature-builder-state.js +1 -0
  58. package/dist/engine/feature-config-events-jobs.d.ts +4 -1
  59. package/dist/engine/feature-config-events-jobs.js +25 -1
  60. package/dist/engine/feature-manifest.d.ts +1 -0
  61. package/dist/engine/feature-manifest.js +1 -0
  62. package/dist/engine/feature-ui-extensions.js +24 -21
  63. package/dist/engine/index.d.ts +1 -1
  64. package/dist/engine/pattern-library/library.js +2 -1
  65. package/dist/engine/pattern-library/static-schemas.d.ts +1 -0
  66. package/dist/engine/pattern-library/static-schemas.js +47 -4
  67. package/dist/engine/registry-facade.js +7 -0
  68. package/dist/engine/registry-ingest.js +7 -0
  69. package/dist/engine/registry-state.d.ts +2 -1
  70. package/dist/engine/registry-state.js +1 -0
  71. package/dist/engine/registry-validate.d.ts +1 -1
  72. package/dist/engine/registry-validate.js +39 -17
  73. package/dist/engine/registry.js +2 -2
  74. package/dist/engine/types/index.d.ts +3 -3
  75. package/dist/engine/types/index.js +1 -1
  76. package/dist/engine/types/screen.d.ts +1 -1
  77. package/dist/engine/types/screen.js +1 -1
  78. package/dist/errors/classes.d.ts +5 -0
  79. package/dist/errors/classes.js +15 -0
  80. package/dist/errors/index.d.ts +1 -1
  81. package/dist/errors/index.js +1 -1
  82. package/dist/i18n/required-surface-keys.js +3 -5
  83. package/dist/jobs/job-runner.js +2 -1
  84. package/dist/migrations/pending-rebuilds.d.ts +2 -0
  85. package/dist/migrations/pending-rebuilds.js +3 -0
  86. package/dist/pipeline/dispatch-query.js +3 -5
  87. package/dist/pipeline/dispatch-shared.js +32 -5
  88. package/dist/pipeline/dispatch-stream.js +2 -4
  89. package/dist/pipeline/dispatch-write.js +2 -4
  90. package/dist/pipeline/event-dispatcher-delivery.d.ts +0 -1
  91. package/dist/pipeline/event-dispatcher-delivery.js +1 -8
  92. package/dist/pipeline/event-dispatcher.js +16 -25
  93. package/dist/pipeline/handler-access-error.d.ts +3 -0
  94. package/dist/pipeline/handler-access-error.js +17 -0
  95. package/dist/pipeline/irreversible-operation-gate.js +9 -3
  96. package/dist/pipeline/member-read-only-transaction.js +8 -3
  97. package/dist/pipeline/system-hooks.js +7 -1
  98. package/dist/pipeline/system-identity-switch.js +11 -8
  99. package/dist/search/meilisearch-adapter.js +0 -2
  100. package/dist/stack/push-entity-projection-tables.js +5 -3
  101. package/dist/stack/redis.d.ts +1 -0
  102. package/dist/stack/redis.js +11 -2
  103. package/dist/stack/table-helpers.d.ts +3 -1
  104. package/dist/stack/table-helpers.js +9 -7
  105. package/dist/stack/test-stack.js +1 -7
  106. package/dist/testing/handler-context.js +3 -6
  107. package/dist/ui-types/index.d.ts +1 -1
  108. package/dist/ui-types/index.js +1 -1
  109. package/dist/upgrade-cli.js +29 -2
  110. package/package.json +4 -4
  111. package/src/changes.json +153 -0
  112. package/src/scripts/codemod/collect-source-files.ts +48 -0
  113. package/src/scripts/codemod/migrate-cross-tenant.ts +3 -23
  114. package/src/scripts/codemod/migrate-db-raw.ts +6 -23
  115. package/src/scripts/codemod/migrate-open-to-all.ts +4 -24
  116. package/src/scripts/codemod/unprocessable-error-details-reason.ts +47 -3
@@ -6,8 +6,7 @@
6
6
  // Usage:
7
7
  // bun scripts/codemod/migrate-open-to-all.ts [--dry-run] [--test-reason "<text>"] <path...>
8
8
 
9
- import { readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
10
- import { join, resolve } from "node:path";
9
+ import { readFileSync, writeFileSync } from "node:fs";
11
10
  import {
12
11
  Node,
13
12
  type ObjectLiteralExpression,
@@ -15,6 +14,7 @@ import {
15
14
  type PropertyAssignment,
16
15
  SyntaxKind,
17
16
  } from "ts-morph";
17
+ import { collectSourceFiles } from "./collect-source-files.js";
18
18
 
19
19
  const DEFAULT_TEST_REASON = "test handler callable by any signed-in test user";
20
20
 
@@ -164,28 +164,8 @@ function isMigratableFile(name: string): boolean {
164
164
  return /\.(ts|tsx)$/.test(name);
165
165
  }
166
166
 
167
- function walkDir(dir: string, out: string[]): void {
168
- for (const name of readdirSync(dir)) {
169
- if (name === "node_modules") continue;
170
- const full = join(dir, name);
171
- const stat = statSync(full);
172
- if (stat.isDirectory()) {
173
- walkDir(full, out);
174
- continue;
175
- }
176
- if (isMigratableFile(name)) out.push(full);
177
- }
178
- }
179
-
180
- function collectFiles(paths: string[]): string[] {
181
- const files: string[] = [];
182
- for (const p of paths) {
183
- const abs = resolve(p);
184
- const stat = statSync(abs);
185
- if (stat.isDirectory()) walkDir(abs, files);
186
- else if (isMigratableFile(abs)) files.push(abs);
187
- }
188
- return files;
167
+ export function collectFiles(paths: string[]): string[] {
168
+ return collectSourceFiles(paths, { isMigratableFile });
189
169
  }
190
170
 
191
171
  // Remaining manual sites still fail boot validation, so upgrade-cli must not
@@ -51,14 +51,20 @@ function findTargetFiles(rootDir: string): string[] {
51
51
  return files.sort();
52
52
  }
53
53
 
54
+ const NAMESPACE_IMPORT = "*";
55
+
54
56
  type ImportedBinding = { readonly importedName: string; readonly moduleSpecifier: string };
55
57
 
56
- /** Local-name -> where it's imported from, for every named value import in the file. */
58
+ /** Local-name -> where it's imported from, for every named or namespace value import in the file. */
57
59
  function collectImportedNames(sourceFile: SourceFile): Map<string, ImportedBinding> {
58
60
  const bindings = new Map<string, ImportedBinding>();
59
61
  for (const imp of sourceFile.getImportDeclarations()) {
60
62
  if (imp.isTypeOnly()) continue;
61
63
  const moduleSpecifier = imp.getModuleSpecifierValue();
64
+ const namespaceImport = imp.getNamespaceImport();
65
+ if (namespaceImport) {
66
+ bindings.set(namespaceImport.getText(), { importedName: NAMESPACE_IMPORT, moduleSpecifier });
67
+ }
62
68
  for (const spec of imp.getNamedImports()) {
63
69
  if (spec.isTypeOnly()) continue;
64
70
  const importedName = spec.getName();
@@ -264,6 +270,17 @@ const FAIL_UNPROCESSABLE_CALL: MigratableCall = {
264
270
  process: processFailUnprocessableCall,
265
271
  };
266
272
 
273
+ function isKumikoNamespaceReceiver(
274
+ receiver: Node,
275
+ importedNames: ReadonlyMap<string, ImportedBinding>,
276
+ ): boolean {
277
+ if (!Node.isIdentifier(receiver)) return false;
278
+ const binding = importedNames.get(receiver.getText());
279
+ return (
280
+ binding?.importedName === NAMESPACE_IMPORT && KUMIKO_MODULE_RE.test(binding.moduleSpecifier)
281
+ );
282
+ }
283
+
267
284
  function migrateCallSite(
268
285
  sourceFile: SourceFile,
269
286
  importedNames: ReadonlyMap<string, ImportedBinding>,
@@ -272,11 +289,28 @@ function migrateCallSite(
272
289
  skips: SkipEntry[],
273
290
  ): boolean {
274
291
  const callee = site.getExpression();
275
- if (!Node.isIdentifier(callee)) return false;
276
- const localName = callee.getText();
277
292
  const line = site.getStartLineNumber();
278
293
  const file = sourceFile.getFilePath();
279
294
 
295
+ if (!Node.isIdentifier(callee)) {
296
+ const unresolvedCallee = callee.getText();
297
+ const resolvedViaNamespace =
298
+ Node.isPropertyAccessExpression(callee) &&
299
+ callee.getName() === target.exportName &&
300
+ isKumikoNamespaceReceiver(callee.getExpression(), importedNames);
301
+ if (resolvedViaNamespace) return processCall(site, target, skips, file, line);
302
+ if (unresolvedCallee.endsWith(target.exportName)) {
303
+ skips.push({
304
+ file,
305
+ line,
306
+ note: `${target.exportName} is called through "${unresolvedCallee}", which is not a @cosmicdrift/kumiko-* namespace import this codemod can resolve`,
307
+ kind: "manual",
308
+ });
309
+ }
310
+ return false;
311
+ }
312
+ const localName = callee.getText();
313
+
280
314
  const binding = importedNames.get(localName);
281
315
  if (binding?.importedName !== target.exportName) {
282
316
  if (localName !== target.exportName) return false;
@@ -296,6 +330,16 @@ function migrateCallSite(
296
330
  return false;
297
331
  }
298
332
 
333
+ return processCall(site, target, skips, file, line);
334
+ }
335
+
336
+ function processCall(
337
+ site: Node & { getArguments(): Node[] },
338
+ target: MigratableCall,
339
+ skips: SkipEntry[],
340
+ file: string,
341
+ line: number,
342
+ ): boolean {
299
343
  const outcome = target.process(site.getArguments(), (note, kind) =>
300
344
  skips.push({ file, line, note, kind }),
301
345
  );