@wp-typia/project-tools 0.11.1

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 (187) hide show
  1. package/README.md +32 -0
  2. package/dist/runtime/cli-add.d.ts +38 -0
  3. package/dist/runtime/cli-add.js +561 -0
  4. package/dist/runtime/cli-core.d.ts +25 -0
  5. package/dist/runtime/cli-core.js +25 -0
  6. package/dist/runtime/cli-doctor.d.ts +34 -0
  7. package/dist/runtime/cli-doctor.js +131 -0
  8. package/dist/runtime/cli-help.d.ts +9 -0
  9. package/dist/runtime/cli-help.js +37 -0
  10. package/dist/runtime/cli-prompt.d.ts +21 -0
  11. package/dist/runtime/cli-prompt.js +53 -0
  12. package/dist/runtime/cli-scaffold.d.ts +79 -0
  13. package/dist/runtime/cli-scaffold.js +206 -0
  14. package/dist/runtime/cli-templates.d.ts +30 -0
  15. package/dist/runtime/cli-templates.js +61 -0
  16. package/dist/runtime/index.d.ts +9 -0
  17. package/dist/runtime/index.js +7 -0
  18. package/dist/runtime/json-utils.d.ts +10 -0
  19. package/dist/runtime/json-utils.js +12 -0
  20. package/dist/runtime/local-dev-presets.d.ts +26 -0
  21. package/dist/runtime/local-dev-presets.js +132 -0
  22. package/dist/runtime/metadata-analysis.d.ts +11 -0
  23. package/dist/runtime/metadata-analysis.js +285 -0
  24. package/dist/runtime/metadata-model.d.ts +84 -0
  25. package/dist/runtime/metadata-model.js +59 -0
  26. package/dist/runtime/metadata-parser.d.ts +53 -0
  27. package/dist/runtime/metadata-parser.js +794 -0
  28. package/dist/runtime/metadata-php-render.d.ts +29 -0
  29. package/dist/runtime/metadata-php-render.js +549 -0
  30. package/dist/runtime/metadata-projection.d.ts +7 -0
  31. package/dist/runtime/metadata-projection.js +233 -0
  32. package/dist/runtime/migration-constants.d.ts +15 -0
  33. package/dist/runtime/migration-constants.js +16 -0
  34. package/dist/runtime/migration-diff.d.ts +2 -0
  35. package/dist/runtime/migration-diff.js +537 -0
  36. package/dist/runtime/migration-fixtures.d.ts +8 -0
  37. package/dist/runtime/migration-fixtures.js +94 -0
  38. package/dist/runtime/migration-fuzz-plan.d.ts +2 -0
  39. package/dist/runtime/migration-fuzz-plan.js +50 -0
  40. package/dist/runtime/migration-manifest.d.ts +19 -0
  41. package/dist/runtime/migration-manifest.js +129 -0
  42. package/dist/runtime/migration-project.d.ts +94 -0
  43. package/dist/runtime/migration-project.js +1101 -0
  44. package/dist/runtime/migration-render.d.ts +11 -0
  45. package/dist/runtime/migration-render.js +741 -0
  46. package/dist/runtime/migration-risk.d.ts +4 -0
  47. package/dist/runtime/migration-risk.js +52 -0
  48. package/dist/runtime/migration-types.d.ts +249 -0
  49. package/dist/runtime/migration-types.js +1 -0
  50. package/dist/runtime/migration-ui-capability.d.ts +17 -0
  51. package/dist/runtime/migration-ui-capability.js +190 -0
  52. package/dist/runtime/migration-utils.d.ts +69 -0
  53. package/dist/runtime/migration-utils.js +246 -0
  54. package/dist/runtime/migrations.d.ts +249 -0
  55. package/dist/runtime/migrations.js +1061 -0
  56. package/dist/runtime/object-utils.d.ts +12 -0
  57. package/dist/runtime/object-utils.js +14 -0
  58. package/dist/runtime/package-managers.d.ts +28 -0
  59. package/dist/runtime/package-managers.js +156 -0
  60. package/dist/runtime/package-versions.d.ts +10 -0
  61. package/dist/runtime/package-versions.js +68 -0
  62. package/dist/runtime/scaffold-onboarding.d.ts +32 -0
  63. package/dist/runtime/scaffold-onboarding.js +99 -0
  64. package/dist/runtime/scaffold.d.ts +146 -0
  65. package/dist/runtime/scaffold.js +612 -0
  66. package/dist/runtime/schema-core.d.ts +267 -0
  67. package/dist/runtime/schema-core.js +597 -0
  68. package/dist/runtime/starter-manifests.d.ts +25 -0
  69. package/dist/runtime/starter-manifests.js +383 -0
  70. package/dist/runtime/string-case.d.ts +36 -0
  71. package/dist/runtime/string-case.js +69 -0
  72. package/dist/runtime/template-builtins.d.ts +38 -0
  73. package/dist/runtime/template-builtins.js +72 -0
  74. package/dist/runtime/template-defaults.d.ts +75 -0
  75. package/dist/runtime/template-defaults.js +65 -0
  76. package/dist/runtime/template-registry.d.ts +36 -0
  77. package/dist/runtime/template-registry.js +94 -0
  78. package/dist/runtime/template-render.d.ts +24 -0
  79. package/dist/runtime/template-render.js +113 -0
  80. package/dist/runtime/template-source.d.ts +71 -0
  81. package/dist/runtime/template-source.js +821 -0
  82. package/dist/runtime/typia-tags.d.ts +1 -0
  83. package/dist/runtime/typia-tags.js +1 -0
  84. package/package.json +79 -0
  85. package/templates/_shared/base/languages/.gitkeep +1 -0
  86. package/templates/_shared/base/package.json.mustache +41 -0
  87. package/templates/_shared/base/scripts/sync-types-to-block-json.ts.mustache +118 -0
  88. package/templates/_shared/base/src/hooks.ts.mustache +19 -0
  89. package/templates/_shared/base/src/validator-toolkit.ts.mustache +31 -0
  90. package/templates/_shared/base/tsconfig.json.mustache +21 -0
  91. package/templates/_shared/base/webpack.config.js.mustache +99 -0
  92. package/templates/_shared/base/{{slugKebabCase}}.php.mustache +53 -0
  93. package/templates/_shared/compound/core/package.json.mustache +45 -0
  94. package/templates/_shared/compound/core/scripts/add-compound-child.ts.mustache +559 -0
  95. package/templates/_shared/compound/core/scripts/block-config.ts.mustache +13 -0
  96. package/templates/_shared/compound/core/scripts/sync-types-to-block-json.ts.mustache +53 -0
  97. package/templates/_shared/compound/core/webpack.config.js.mustache +141 -0
  98. package/templates/_shared/compound/core/{{slugKebabCase}}.php.mustache +51 -0
  99. package/templates/_shared/compound/persistence/package.json.mustache +50 -0
  100. package/templates/_shared/compound/persistence/scripts/block-config.ts.mustache +59 -0
  101. package/templates/_shared/compound/persistence/scripts/sync-rest-contracts.ts.mustache +101 -0
  102. package/templates/_shared/compound/persistence/src/blocks/{{slugKebabCase}}/api-types.ts.mustache +21 -0
  103. package/templates/_shared/compound/persistence/src/blocks/{{slugKebabCase}}/api-validators.ts.mustache +32 -0
  104. package/templates/_shared/compound/persistence/src/blocks/{{slugKebabCase}}/api.ts.mustache +68 -0
  105. package/templates/_shared/compound/persistence/src/blocks/{{slugKebabCase}}/block.json.mustache +52 -0
  106. package/templates/_shared/compound/persistence/src/blocks/{{slugKebabCase}}/data.ts.mustache +192 -0
  107. package/templates/_shared/compound/persistence/src/blocks/{{slugKebabCase}}/edit.tsx.mustache +123 -0
  108. package/templates/_shared/compound/persistence/src/blocks/{{slugKebabCase}}/hooks.ts.mustache +11 -0
  109. package/templates/_shared/compound/persistence/src/blocks/{{slugKebabCase}}/interactivity.ts.mustache +132 -0
  110. package/templates/_shared/compound/persistence/src/blocks/{{slugKebabCase}}/render.php.mustache +158 -0
  111. package/templates/_shared/compound/persistence/src/blocks/{{slugKebabCase}}/save.tsx.mustache +3 -0
  112. package/templates/_shared/compound/persistence/src/blocks/{{slugKebabCase}}/types.ts.mustache +56 -0
  113. package/templates/_shared/compound/persistence/src/blocks/{{slugKebabCase}}/validators.ts.mustache +32 -0
  114. package/templates/_shared/compound/persistence-auth/{{slugKebabCase}}.php.mustache +294 -0
  115. package/templates/_shared/compound/persistence-public/{{slugKebabCase}}.php.mustache +312 -0
  116. package/templates/_shared/migration-ui/common/src/admin/migration-dashboard.tsx +394 -0
  117. package/templates/_shared/migration-ui/common/src/migration-detector.ts +9 -0
  118. package/templates/_shared/migration-ui/common/src/migrations/helpers.ts +490 -0
  119. package/templates/_shared/migration-ui/common/src/migrations/index.ts +886 -0
  120. package/templates/_shared/persistence/auth/{{slugKebabCase}}.php.mustache +290 -0
  121. package/templates/_shared/persistence/core/package.json.mustache +46 -0
  122. package/templates/_shared/persistence/core/scripts/sync-rest-contracts.ts.mustache +113 -0
  123. package/templates/_shared/persistence/core/scripts/sync-types-to-block-json.ts.mustache +125 -0
  124. package/templates/_shared/persistence/core/src/api-types.ts.mustache +21 -0
  125. package/templates/_shared/persistence/core/src/api-validators.ts.mustache +32 -0
  126. package/templates/_shared/persistence/core/src/api.ts.mustache +68 -0
  127. package/templates/_shared/persistence/core/src/data.ts.mustache +192 -0
  128. package/templates/_shared/persistence/core/src/index.tsx.mustache +25 -0
  129. package/templates/_shared/persistence/core/src/interactivity.ts.mustache +134 -0
  130. package/templates/_shared/persistence/core/src/save.tsx.mustache +5 -0
  131. package/templates/_shared/persistence/core/src/validators.ts.mustache +32 -0
  132. package/templates/_shared/persistence/core/{{slugKebabCase}}.php.mustache +336 -0
  133. package/templates/_shared/persistence/public/{{slugKebabCase}}.php.mustache +308 -0
  134. package/templates/_shared/presets/test-preset/.wp-env.test.json.mustache +16 -0
  135. package/templates/_shared/presets/test-preset/playwright.config.ts.mustache +22 -0
  136. package/templates/_shared/presets/test-preset/scripts/wait-for-wp-env.mjs.mustache +102 -0
  137. package/templates/_shared/presets/test-preset/scripts/wp-env-utils.cjs.mustache +32 -0
  138. package/templates/_shared/presets/test-preset/tests/e2e/smoke.spec.ts.mustache +34 -0
  139. package/templates/_shared/presets/wp-env/.wp-env.json.mustache +16 -0
  140. package/templates/_shared/rest-helpers/auth/inc/rest-auth.php.mustache +37 -0
  141. package/templates/_shared/rest-helpers/public/inc/rest-public.php.mustache +314 -0
  142. package/templates/_shared/rest-helpers/shared/inc/rest-shared.php.mustache +58 -0
  143. package/templates/_shared/workspace/persistence-auth/inc/rest-auth.php.mustache +36 -0
  144. package/templates/_shared/workspace/persistence-auth/inc/rest-shared.php.mustache +55 -0
  145. package/templates/_shared/workspace/persistence-auth/server.php.mustache +237 -0
  146. package/templates/_shared/workspace/persistence-public/inc/rest-public.php.mustache +273 -0
  147. package/templates/_shared/workspace/persistence-public/inc/rest-shared.php.mustache +55 -0
  148. package/templates/_shared/workspace/persistence-public/server.php.mustache +252 -0
  149. package/templates/basic/src/block.json.mustache +51 -0
  150. package/templates/basic/src/edit.tsx.mustache +128 -0
  151. package/templates/basic/src/editor.scss.mustache +8 -0
  152. package/templates/basic/src/hooks.ts.mustache +18 -0
  153. package/templates/basic/src/index.tsx.mustache +45 -0
  154. package/templates/basic/src/save.tsx.mustache +30 -0
  155. package/templates/basic/src/style.scss.mustache +40 -0
  156. package/templates/basic/src/types.ts.mustache +56 -0
  157. package/templates/basic/src/validators.ts.mustache +26 -0
  158. package/templates/compound/src/blocks/{{slugKebabCase}}/block.json.mustache +37 -0
  159. package/templates/compound/src/blocks/{{slugKebabCase}}/children.ts.mustache +25 -0
  160. package/templates/compound/src/blocks/{{slugKebabCase}}/edit.tsx.mustache +93 -0
  161. package/templates/compound/src/blocks/{{slugKebabCase}}/hooks.ts.mustache +11 -0
  162. package/templates/compound/src/blocks/{{slugKebabCase}}/index.tsx.mustache +25 -0
  163. package/templates/compound/src/blocks/{{slugKebabCase}}/save.tsx.mustache +32 -0
  164. package/templates/compound/src/blocks/{{slugKebabCase}}/style.scss.mustache +31 -0
  165. package/templates/compound/src/blocks/{{slugKebabCase}}/types.ts.mustache +13 -0
  166. package/templates/compound/src/blocks/{{slugKebabCase}}/validators.ts.mustache +17 -0
  167. package/templates/compound/src/blocks/{{slugKebabCase}}-item/block.json.mustache +35 -0
  168. package/templates/compound/src/blocks/{{slugKebabCase}}-item/edit.tsx.mustache +50 -0
  169. package/templates/compound/src/blocks/{{slugKebabCase}}-item/hooks.ts.mustache +11 -0
  170. package/templates/compound/src/blocks/{{slugKebabCase}}-item/index.tsx.mustache +25 -0
  171. package/templates/compound/src/blocks/{{slugKebabCase}}-item/save.tsx.mustache +24 -0
  172. package/templates/compound/src/blocks/{{slugKebabCase}}-item/types.ts.mustache +12 -0
  173. package/templates/compound/src/blocks/{{slugKebabCase}}-item/validators.ts.mustache +17 -0
  174. package/templates/interactivity/package.json.mustache +42 -0
  175. package/templates/interactivity/src/block.json.mustache +73 -0
  176. package/templates/interactivity/src/edit.tsx.mustache +270 -0
  177. package/templates/interactivity/src/index.tsx.mustache +32 -0
  178. package/templates/interactivity/src/interactivity.ts.mustache +152 -0
  179. package/templates/interactivity/src/save.tsx.mustache +101 -0
  180. package/templates/interactivity/src/style.scss.mustache +60 -0
  181. package/templates/interactivity/src/types.ts.mustache +32 -0
  182. package/templates/interactivity/src/validators.ts.mustache +36 -0
  183. package/templates/persistence/src/block.json.mustache +52 -0
  184. package/templates/persistence/src/edit.tsx.mustache +165 -0
  185. package/templates/persistence/src/render.php.mustache +126 -0
  186. package/templates/persistence/src/style.scss.mustache +46 -0
  187. package/templates/persistence/src/types.ts.mustache +55 -0
@@ -0,0 +1,50 @@
1
+ import { flattenManifestLeafAttributes } from "./migration-manifest.js";
2
+ function isBlockedPath(pathLabel, blockedPaths) {
3
+ return blockedPaths.some((blockedPath) => pathLabel === blockedPath || pathLabel.startsWith(`${blockedPath}.`));
4
+ }
5
+ function unique(items) {
6
+ return [...new Set(items)];
7
+ }
8
+ export function createMigrationFuzzPlan(legacyManifest, currentManifest, diff) {
9
+ const legacyLeafMap = new Map(flattenManifestLeafAttributes(legacyManifest.attributes ?? {}).map((descriptor) => [
10
+ descriptor.currentPath,
11
+ descriptor,
12
+ ]));
13
+ const currentLeafDescriptors = flattenManifestLeafAttributes(currentManifest.attributes ?? {});
14
+ const autoRenameMap = new Map(diff.summary.renameCandidates
15
+ .filter((candidate) => candidate.autoApply)
16
+ .map((candidate) => [candidate.currentPath, candidate.legacyPath]));
17
+ const blockedPaths = unique([
18
+ ...diff.summary.manualItems.map((item) => item.path),
19
+ ...diff.summary.transformSuggestions.map((item) => item.currentPath),
20
+ ...diff.summary.renameCandidates
21
+ .filter((candidate) => !candidate.autoApply)
22
+ .map((candidate) => candidate.currentPath),
23
+ ]);
24
+ const compatibleMappings = [];
25
+ for (const descriptor of currentLeafDescriptors) {
26
+ const currentPath = descriptor.currentPath;
27
+ if (isBlockedPath(currentPath, blockedPaths)) {
28
+ continue;
29
+ }
30
+ const legacyPath = autoRenameMap.get(currentPath) ?? currentPath;
31
+ const legacyDescriptor = legacyLeafMap.get(legacyPath);
32
+ if (!legacyDescriptor) {
33
+ continue;
34
+ }
35
+ if (legacyDescriptor.attribute.ts.kind !== descriptor.attribute.ts.kind) {
36
+ continue;
37
+ }
38
+ if (!["string", "number", "boolean"].includes(descriptor.attribute.ts.kind)) {
39
+ continue;
40
+ }
41
+ compatibleMappings.push({
42
+ currentPath,
43
+ legacyPath,
44
+ });
45
+ }
46
+ return {
47
+ blockedPaths,
48
+ compatibleMappings,
49
+ };
50
+ }
@@ -0,0 +1,19 @@
1
+ import type { FlattenedAttributeDescriptor, JsonValue, ManifestAttribute, ManifestDocument, ManifestSummary, UnionBranchSummary } from "./migration-types.js";
2
+ interface FlattenContext {
3
+ rootPath: string;
4
+ unionBranch: string | null;
5
+ unionDiscriminator: string | null;
6
+ unionRoot: string | null;
7
+ }
8
+ type ManifestDefaultValue = ManifestAttribute["typia"]["defaultValue"] | JsonValue[] | Record<string, JsonValue>;
9
+ export declare function flattenManifestLeafAttributes(attributes: Record<string, ManifestAttribute>): FlattenedAttributeDescriptor[];
10
+ export declare function flattenManifestAttribute(attribute: ManifestAttribute | undefined | null, currentPath: string, sourcePath: string, context: FlattenContext): FlattenedAttributeDescriptor[];
11
+ export declare function getAttributeByCurrentPath(attributes: Record<string, ManifestAttribute>, currentPath: string): ManifestAttribute | null;
12
+ export declare function hasManifestDefault(attribute: ManifestAttribute | undefined | null): boolean;
13
+ export declare function getManifestDefaultValue(attribute: ManifestAttribute | undefined | null): string | number | boolean | JsonValue[] | {
14
+ [key: string]: JsonValue;
15
+ } | null;
16
+ export declare function summarizeManifest(manifest: ManifestDocument): ManifestSummary;
17
+ export declare function summarizeUnionBranches(manifestSummary: ManifestSummary): UnionBranchSummary[];
18
+ export declare function defaultValueForManifestAttribute(attribute: ManifestAttribute): ManifestDefaultValue | null;
19
+ export {};
@@ -0,0 +1,129 @@
1
+ export function flattenManifestLeafAttributes(attributes) {
2
+ return Object.entries(attributes).flatMap(([key, attribute]) => flattenManifestAttribute(attribute, key, key, {
3
+ rootPath: key,
4
+ unionBranch: null,
5
+ unionDiscriminator: null,
6
+ unionRoot: null,
7
+ }));
8
+ }
9
+ export function flattenManifestAttribute(attribute, currentPath, sourcePath, context) {
10
+ if (!attribute) {
11
+ return [];
12
+ }
13
+ if (attribute.ts.kind === "object") {
14
+ const properties = Object.entries(attribute.ts.properties ?? {});
15
+ if (properties.length === 0) {
16
+ return [{ ...context, attribute, currentPath, sourcePath }];
17
+ }
18
+ return properties.flatMap(([key, property]) => flattenManifestAttribute(property, `${currentPath}.${key}`, `${sourcePath}.${key}`, {
19
+ ...context,
20
+ }));
21
+ }
22
+ if (attribute.ts.kind === "union" && attribute.ts.union) {
23
+ const unionMetadata = attribute.ts.union;
24
+ return Object.entries(attribute.ts.union.branches ?? {}).flatMap(([branchKey, branchAttribute]) => Object.entries(branchAttribute.ts.properties ?? {})
25
+ .filter(([key]) => key !== unionMetadata.discriminator)
26
+ .flatMap(([key, property]) => flattenManifestAttribute(property, `${currentPath}.${branchKey}.${key}`, `${sourcePath}.${key}`, {
27
+ rootPath: context.rootPath,
28
+ unionBranch: branchKey,
29
+ unionDiscriminator: unionMetadata.discriminator,
30
+ unionRoot: currentPath,
31
+ })));
32
+ }
33
+ return [{ ...context, attribute, currentPath, sourcePath }];
34
+ }
35
+ export function getAttributeByCurrentPath(attributes, currentPath) {
36
+ const segments = String(currentPath).split(".");
37
+ const rootKey = segments.shift();
38
+ if (!rootKey) {
39
+ return null;
40
+ }
41
+ let attribute = attributes[rootKey] ?? null;
42
+ while (attribute && segments.length > 0) {
43
+ if (attribute.ts.kind === "union" && attribute.ts.union) {
44
+ const branchKey = segments.shift();
45
+ if (!branchKey || !(branchKey in attribute.ts.union.branches)) {
46
+ return null;
47
+ }
48
+ attribute = attribute.ts.union.branches[branchKey];
49
+ continue;
50
+ }
51
+ if (attribute.ts.kind === "object" && attribute.ts.properties) {
52
+ const propertyKey = segments.shift();
53
+ if (!propertyKey || !(propertyKey in attribute.ts.properties)) {
54
+ return null;
55
+ }
56
+ attribute = attribute.ts.properties[propertyKey];
57
+ continue;
58
+ }
59
+ return null;
60
+ }
61
+ return attribute;
62
+ }
63
+ export function hasManifestDefault(attribute) {
64
+ return attribute?.typia?.hasDefault === true;
65
+ }
66
+ export function getManifestDefaultValue(attribute) {
67
+ return attribute?.typia?.defaultValue ?? null;
68
+ }
69
+ export function summarizeManifest(manifest) {
70
+ return {
71
+ attributes: Object.fromEntries(Object.entries(manifest.attributes ?? {}).map(([name, attribute]) => [
72
+ name,
73
+ {
74
+ constraints: attribute.typia?.constraints ?? {},
75
+ defaultValue: attribute.typia?.defaultValue ?? null,
76
+ hasDefault: attribute.typia?.hasDefault ?? false,
77
+ enum: attribute.wp?.enum ?? null,
78
+ kind: attribute.ts?.kind ?? null,
79
+ required: attribute.ts?.required ?? false,
80
+ union: attribute.ts?.union ?? null,
81
+ },
82
+ ])),
83
+ manifestVersion: manifest.manifestVersion ?? null,
84
+ sourceType: manifest.sourceType ?? null,
85
+ };
86
+ }
87
+ export function summarizeUnionBranches(manifestSummary) {
88
+ if (!manifestSummary?.attributes) {
89
+ return [];
90
+ }
91
+ return Object.entries(manifestSummary.attributes)
92
+ .filter(([, attribute]) => attribute.kind === "union" && attribute.union)
93
+ .map(([field, attribute]) => ({
94
+ branches: Object.keys(attribute.union?.branches ?? {}),
95
+ discriminator: attribute.union?.discriminator ?? null,
96
+ field,
97
+ }));
98
+ }
99
+ export function defaultValueForManifestAttribute(attribute) {
100
+ if (attribute.typia?.hasDefault) {
101
+ return attribute.typia.defaultValue;
102
+ }
103
+ if (attribute.wp?.enum && attribute.wp.enum.length > 0) {
104
+ return attribute.wp.enum[0] ?? null;
105
+ }
106
+ switch (attribute.ts.kind) {
107
+ case "string":
108
+ return "";
109
+ case "number":
110
+ return 0;
111
+ case "boolean":
112
+ return false;
113
+ case "array":
114
+ return [];
115
+ case "object": {
116
+ const result = {};
117
+ for (const [key, property] of Object.entries(attribute.ts.properties ?? {})) {
118
+ result[key] = defaultValueForManifestAttribute(property);
119
+ }
120
+ return result;
121
+ }
122
+ case "union": {
123
+ const firstBranch = Object.values(attribute.ts.union?.branches ?? {})[0];
124
+ return firstBranch ? defaultValueForManifestAttribute(firstBranch) : null;
125
+ }
126
+ default:
127
+ return null;
128
+ }
129
+ }
@@ -0,0 +1,94 @@
1
+ import type { MigrationBlockConfig, MigrationConfig, MigrationEntry, MigrationProjectPaths, MigrationProjectState, ResolvedMigrationBlockTarget, RuleMetadata } from "./migration-types.js";
2
+ /**
3
+ * Describes the migration retrofit layout discovered in a project directory.
4
+ *
5
+ * Multi-block discovery wins when block targets are discovered under
6
+ * `src/blocks/<slug>/block.json`.
7
+ * Otherwise the runtime falls back to a supported single-block layout.
8
+ */
9
+ export type DiscoveredMigrationLayout = {
10
+ block: MigrationBlockConfig;
11
+ mode: "single";
12
+ } | {
13
+ blocks: MigrationBlockConfig[];
14
+ mode: "multi";
15
+ };
16
+ export declare function ensureAdvancedMigrationProject(projectDir: string, blocks?: MigrationBlockConfig[]): void;
17
+ export declare function getProjectPaths(projectDir: string): MigrationProjectPaths;
18
+ /**
19
+ * Detects the supported migration retrofit layout for `migrate init`.
20
+ *
21
+ * Multi-block targets under `src/blocks/<slug>` take precedence over
22
+ * single-block layouts.
23
+ * Returns the detected layout on success and throws an actionable error when no
24
+ * supported first-party layout can be inferred.
25
+ */
26
+ export declare function discoverMigrationInitLayout(projectDir: string): DiscoveredMigrationLayout;
27
+ export declare function resolveMigrationBlocks(projectDir: string, config: MigrationConfig): ResolvedMigrationBlockTarget[];
28
+ export declare function getSnapshotRoot(projectDir: string, block: MigrationBlockConfig | ResolvedMigrationBlockTarget, version: string): string;
29
+ export declare function getSnapshotBlockJsonPath(projectDir: string, block: MigrationBlockConfig | ResolvedMigrationBlockTarget, version: string): string;
30
+ export declare function getSnapshotManifestPath(projectDir: string, block: MigrationBlockConfig | ResolvedMigrationBlockTarget, version: string): string;
31
+ /**
32
+ * Lists the snapshot versions currently present for a specific block target.
33
+ *
34
+ * Returns the sorted subset of supported migration versions that have a manifest on disk
35
+ * for the provided block, or an empty array when none exist.
36
+ */
37
+ export declare function getAvailableSnapshotVersionsForBlock(projectDir: string, supportedMigrationVersions: string[], block: MigrationBlockConfig | ResolvedMigrationBlockTarget): string[];
38
+ /**
39
+ * Formats the standard missing-snapshot guidance for a block target.
40
+ *
41
+ * Returns a user-facing message that either lists the available snapshot
42
+ * versions or explains that no snapshots exist yet for the block.
43
+ */
44
+ export declare function createMissingBlockSnapshotMessage(blockName: string, fromVersion: string, availableSnapshotVersions: string[]): string;
45
+ export declare function getSnapshotSavePath(projectDir: string, block: MigrationBlockConfig | ResolvedMigrationBlockTarget, version: string): string;
46
+ export declare function getGeneratedDirForBlock(paths: MigrationProjectPaths, block: MigrationBlockConfig | ResolvedMigrationBlockTarget): string;
47
+ export declare function getRuleFilePath(paths: MigrationProjectPaths, block: MigrationBlockConfig | ResolvedMigrationBlockTarget, fromVersion: string, toVersion: string): string;
48
+ export declare function getFixtureFilePath(paths: MigrationProjectPaths, block: MigrationBlockConfig | ResolvedMigrationBlockTarget, fromVersion: string, toVersion: string): string;
49
+ export declare function getValidatorsImportPath(projectDir: string, block: MigrationBlockConfig | ResolvedMigrationBlockTarget, fromDir: string): string;
50
+ export declare function ensureMigrationDirectories(projectDir: string, blocks?: MigrationBlockConfig[]): void;
51
+ export declare function writeInitialMigrationScaffold(projectDir: string, currentMigrationVersion: string, blocks?: MigrationBlockConfig[]): void;
52
+ /**
53
+ * Guards a project directory against legacy semver-based migration workspaces.
54
+ *
55
+ * @param projectDir Absolute or relative project directory containing the migration workspace.
56
+ * @returns Nothing.
57
+ * @throws Error When legacy config keys or semver-named migration artifacts are detected.
58
+ */
59
+ export declare function assertNoLegacySemverMigrationWorkspace(projectDir: string): void;
60
+ /**
61
+ * Loads the migration workspace state for a project directory.
62
+ *
63
+ * By default this loader may run the project's `sync-types` script when the
64
+ * current manifest files are missing, because later migration commands depend
65
+ * on those generated artifacts. Pass `allowSyncTypes: false` to keep the call
66
+ * read-only and fail instead of mutating the workspace.
67
+ *
68
+ * When `allowMissingConfig` is enabled and the migration config file does not
69
+ * exist yet, the loader synthesizes a minimal legacy-root config so bootstrap
70
+ * flows can continue before the first config write.
71
+ *
72
+ * @param projectDir Absolute or relative project directory containing the migration workspace.
73
+ * @param options Loader flags controlling config fallback and `sync-types` side effects.
74
+ * @returns The resolved migration project state, including config, block targets, and helper paths.
75
+ * @throws Error When the project is not migration-capable, required manifests remain missing, or generated files cannot be read.
76
+ */
77
+ export declare function loadMigrationProject(projectDir: string, { allowMissingConfig, allowSyncTypes, }?: {
78
+ allowMissingConfig?: boolean;
79
+ allowSyncTypes?: boolean;
80
+ }): MigrationProjectState;
81
+ export declare function discoverMigrationEntries(state: MigrationProjectState): MigrationEntry[];
82
+ export declare function parseMigrationConfig(source: string): MigrationConfig;
83
+ export declare function writeMigrationConfig(projectDir: string, config: MigrationConfig): void;
84
+ /**
85
+ * Returns the discovered block name for a supported single-block project.
86
+ *
87
+ * Uses `discoverSingleBlockTarget(projectDir)` internally and throws when the
88
+ * project directory does not resolve to a supported single-block migration
89
+ * layout.
90
+ */
91
+ export declare function readProjectBlockName(projectDir: string): string;
92
+ export declare function assertRuleHasNoTodos(projectDir: string, block: MigrationBlockConfig | ResolvedMigrationBlockTarget, fromMigrationVersion: string, toMigrationVersion: string): void;
93
+ export declare function readRuleMetadata(rulePath: string): RuleMetadata;
94
+ export declare function createMigrationBlockConfig(block: MigrationBlockConfig): MigrationBlockConfig;