@wp-typia/project-tools 0.23.0 → 0.24.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 (228) hide show
  1. package/dist/runtime/ai-feature-artifacts.js +4 -1
  2. package/dist/runtime/block-generator-service-spec.js +2 -1
  3. package/dist/runtime/built-in-block-non-ts-basic-artifacts.d.ts +9 -0
  4. package/dist/runtime/built-in-block-non-ts-basic-artifacts.js +84 -0
  5. package/dist/runtime/built-in-block-non-ts-compound-artifacts.d.ts +9 -0
  6. package/dist/runtime/built-in-block-non-ts-compound-artifacts.js +36 -0
  7. package/dist/runtime/built-in-block-non-ts-compound-templates.d.ts +23 -0
  8. package/dist/runtime/built-in-block-non-ts-compound-templates.js +453 -0
  9. package/dist/runtime/built-in-block-non-ts-family-artifacts.d.ts +8 -26
  10. package/dist/runtime/built-in-block-non-ts-family-artifacts.js +8 -1034
  11. package/dist/runtime/built-in-block-non-ts-interactivity-artifacts.d.ts +9 -0
  12. package/dist/runtime/built-in-block-non-ts-interactivity-artifacts.js +83 -0
  13. package/dist/runtime/built-in-block-non-ts-persistence-artifacts.d.ts +9 -0
  14. package/dist/runtime/built-in-block-non-ts-persistence-artifacts.js +33 -0
  15. package/dist/runtime/built-in-block-non-ts-persistence-templates.d.ts +23 -0
  16. package/dist/runtime/built-in-block-non-ts-persistence-templates.js +395 -0
  17. package/dist/runtime/cli-add-block-json.js +5 -1
  18. package/dist/runtime/cli-add-collision.js +8 -0
  19. package/dist/runtime/cli-add-help.js +14 -10
  20. package/dist/runtime/cli-add-kind-ids.d.ts +1 -1
  21. package/dist/runtime/cli-add-kind-ids.js +1 -0
  22. package/dist/runtime/cli-add-types.d.ts +45 -6
  23. package/dist/runtime/cli-add-types.js +2 -0
  24. package/dist/runtime/cli-add-validation.d.ts +7 -0
  25. package/dist/runtime/cli-add-validation.js +9 -0
  26. package/dist/runtime/cli-add-workspace-ability-anchors.d.ts +24 -0
  27. package/dist/runtime/cli-add-workspace-ability-anchors.js +294 -0
  28. package/dist/runtime/cli-add-workspace-ability-registry.d.ts +10 -0
  29. package/dist/runtime/cli-add-workspace-ability-registry.js +51 -0
  30. package/dist/runtime/cli-add-workspace-ability-scaffold.d.ts +1 -1
  31. package/dist/runtime/cli-add-workspace-ability-scaffold.js +5 -308
  32. package/dist/runtime/cli-add-workspace-admin-view-scaffold.js +6 -2
  33. package/dist/runtime/cli-add-workspace-admin-view-templates-core-data.d.ts +34 -0
  34. package/dist/runtime/cli-add-workspace-admin-view-templates-core-data.js +483 -0
  35. package/dist/runtime/cli-add-workspace-admin-view-templates-default.d.ts +30 -0
  36. package/dist/runtime/cli-add-workspace-admin-view-templates-default.js +310 -0
  37. package/dist/runtime/cli-add-workspace-admin-view-templates-rest.d.ts +25 -0
  38. package/dist/runtime/cli-add-workspace-admin-view-templates-rest.js +124 -0
  39. package/dist/runtime/cli-add-workspace-admin-view-templates-settings.d.ts +34 -0
  40. package/dist/runtime/cli-add-workspace-admin-view-templates-settings.js +370 -0
  41. package/dist/runtime/cli-add-workspace-admin-view-templates-shared.d.ts +49 -0
  42. package/dist/runtime/cli-add-workspace-admin-view-templates-shared.js +259 -0
  43. package/dist/runtime/cli-add-workspace-admin-view-templates.d.ts +18 -27
  44. package/dist/runtime/cli-add-workspace-admin-view-templates.js +30 -1326
  45. package/dist/runtime/cli-add-workspace-ai-anchors.d.ts +4 -4
  46. package/dist/runtime/cli-add-workspace-ai-anchors.js +8 -233
  47. package/dist/runtime/cli-add-workspace-ai-scaffold.js +4 -2
  48. package/dist/runtime/cli-add-workspace-ai-source-emitters.d.ts +1 -4
  49. package/dist/runtime/cli-add-workspace-ai-source-emitters.js +1 -129
  50. package/dist/runtime/cli-add-workspace-ai-sync-rest-anchors.d.ts +5 -0
  51. package/dist/runtime/cli-add-workspace-ai-sync-rest-anchors.js +236 -0
  52. package/dist/runtime/cli-add-workspace-ai-sync-script-source.d.ts +4 -0
  53. package/dist/runtime/cli-add-workspace-ai-sync-script-source.js +145 -0
  54. package/dist/runtime/cli-add-workspace-assets.d.ts +6 -63
  55. package/dist/runtime/cli-add-workspace-assets.js +6 -950
  56. package/dist/runtime/cli-add-workspace-binding-source-anchors.d.ts +23 -0
  57. package/dist/runtime/cli-add-workspace-binding-source-anchors.js +112 -0
  58. package/dist/runtime/cli-add-workspace-binding-source-source-emitters.d.ts +33 -0
  59. package/dist/runtime/cli-add-workspace-binding-source-source-emitters.js +436 -0
  60. package/dist/runtime/cli-add-workspace-binding-source-types.d.ts +20 -0
  61. package/dist/runtime/cli-add-workspace-binding-source-types.js +1 -0
  62. package/dist/runtime/cli-add-workspace-binding-source.d.ts +40 -0
  63. package/dist/runtime/cli-add-workspace-binding-source.js +275 -0
  64. package/dist/runtime/cli-add-workspace-block-style.d.ts +22 -0
  65. package/dist/runtime/cli-add-workspace-block-style.js +148 -0
  66. package/dist/runtime/cli-add-workspace-block-transform.d.ts +32 -0
  67. package/dist/runtime/cli-add-workspace-block-transform.js +197 -0
  68. package/dist/runtime/cli-add-workspace-contract.js +1 -1
  69. package/dist/runtime/cli-add-workspace-core-variation.d.ts +20 -0
  70. package/dist/runtime/cli-add-workspace-core-variation.js +322 -0
  71. package/dist/runtime/cli-add-workspace-editor-plugin-anchors.d.ts +37 -0
  72. package/dist/runtime/cli-add-workspace-editor-plugin-anchors.js +206 -0
  73. package/dist/runtime/cli-add-workspace-editor-plugin-source-emitters.d.ts +47 -0
  74. package/dist/runtime/cli-add-workspace-editor-plugin-source-emitters.js +219 -0
  75. package/dist/runtime/cli-add-workspace-editor-plugin.d.ts +22 -0
  76. package/dist/runtime/cli-add-workspace-editor-plugin.js +78 -0
  77. package/dist/runtime/cli-add-workspace-hooked-block.d.ts +23 -0
  78. package/dist/runtime/cli-add-workspace-hooked-block.js +57 -0
  79. package/dist/runtime/cli-add-workspace-integration-env-files.d.ts +33 -0
  80. package/dist/runtime/cli-add-workspace-integration-env-files.js +65 -0
  81. package/dist/runtime/cli-add-workspace-integration-env-package-json.d.ts +38 -0
  82. package/dist/runtime/cli-add-workspace-integration-env-package-json.js +122 -0
  83. package/dist/runtime/cli-add-workspace-integration-env-source-emitters.d.ts +44 -0
  84. package/dist/runtime/cli-add-workspace-integration-env-source-emitters.js +262 -0
  85. package/dist/runtime/cli-add-workspace-integration-env.d.ts +3 -1
  86. package/dist/runtime/cli-add-workspace-integration-env.js +10 -313
  87. package/dist/runtime/cli-add-workspace-pattern-anchors.d.ts +10 -0
  88. package/dist/runtime/cli-add-workspace-pattern-anchors.js +95 -0
  89. package/dist/runtime/cli-add-workspace-pattern-options.d.ts +20 -0
  90. package/dist/runtime/cli-add-workspace-pattern-options.js +113 -0
  91. package/dist/runtime/cli-add-workspace-pattern-source-emitters.d.ts +20 -0
  92. package/dist/runtime/cli-add-workspace-pattern-source-emitters.js +57 -0
  93. package/dist/runtime/cli-add-workspace-pattern.d.ts +42 -0
  94. package/dist/runtime/cli-add-workspace-pattern.js +99 -0
  95. package/dist/runtime/cli-add-workspace-post-meta.js +1 -1
  96. package/dist/runtime/cli-add-workspace-registration-hooks.d.ts +50 -0
  97. package/dist/runtime/cli-add-workspace-registration-hooks.js +162 -0
  98. package/dist/runtime/cli-add-workspace-rest-anchors.d.ts +9 -4
  99. package/dist/runtime/cli-add-workspace-rest-anchors.js +9 -428
  100. package/dist/runtime/cli-add-workspace-rest-bootstrap-anchors.d.ts +17 -0
  101. package/dist/runtime/cli-add-workspace-rest-bootstrap-anchors.js +108 -0
  102. package/dist/runtime/cli-add-workspace-rest-contract-sync-anchors.d.ts +9 -0
  103. package/dist/runtime/cli-add-workspace-rest-contract-sync-anchors.js +142 -0
  104. package/dist/runtime/cli-add-workspace-rest-generated-source-emitters.d.ts +51 -0
  105. package/dist/runtime/cli-add-workspace-rest-generated-source-emitters.js +415 -0
  106. package/dist/runtime/cli-add-workspace-rest-generated.d.ts +9 -0
  107. package/dist/runtime/cli-add-workspace-rest-generated.js +160 -0
  108. package/dist/runtime/cli-add-workspace-rest-manual-source-emitters.d.ts +80 -0
  109. package/dist/runtime/cli-add-workspace-rest-manual-source-emitters.js +238 -0
  110. package/dist/runtime/cli-add-workspace-rest-manual.d.ts +8 -0
  111. package/dist/runtime/cli-add-workspace-rest-manual.js +266 -0
  112. package/dist/runtime/cli-add-workspace-rest-php-templates.d.ts +18 -0
  113. package/dist/runtime/cli-add-workspace-rest-php-templates.js +359 -0
  114. package/dist/runtime/cli-add-workspace-rest-resource-php-routing-template.d.ts +33 -0
  115. package/dist/runtime/cli-add-workspace-rest-resource-php-routing-template.js +145 -0
  116. package/dist/runtime/cli-add-workspace-rest-resource-sync-anchors.d.ts +9 -0
  117. package/dist/runtime/cli-add-workspace-rest-resource-sync-anchors.js +162 -0
  118. package/dist/runtime/cli-add-workspace-rest-schema-helper-php-template.d.ts +7 -0
  119. package/dist/runtime/cli-add-workspace-rest-schema-helper-php-template.js +193 -0
  120. package/dist/runtime/cli-add-workspace-rest-source-emitters.d.ts +5 -91
  121. package/dist/runtime/cli-add-workspace-rest-source-emitters.js +5 -642
  122. package/dist/runtime/cli-add-workspace-rest-source-utils.d.ts +17 -0
  123. package/dist/runtime/cli-add-workspace-rest-source-utils.js +50 -0
  124. package/dist/runtime/cli-add-workspace-rest-sync-script-shared.d.ts +56 -0
  125. package/dist/runtime/cli-add-workspace-rest-sync-script-shared.js +122 -0
  126. package/dist/runtime/cli-add-workspace-rest-types.d.ts +108 -0
  127. package/dist/runtime/cli-add-workspace-rest-types.js +1 -0
  128. package/dist/runtime/cli-add-workspace-rest.d.ts +3 -20
  129. package/dist/runtime/cli-add-workspace-rest.js +33 -788
  130. package/dist/runtime/cli-add-workspace-variation.d.ts +22 -0
  131. package/dist/runtime/cli-add-workspace-variation.js +162 -0
  132. package/dist/runtime/cli-add-workspace.d.ts +42 -107
  133. package/dist/runtime/cli-add-workspace.js +42 -674
  134. package/dist/runtime/cli-add.d.ts +3 -3
  135. package/dist/runtime/cli-add.js +2 -2
  136. package/dist/runtime/cli-core.d.ts +3 -2
  137. package/dist/runtime/cli-core.js +2 -2
  138. package/dist/runtime/cli-diagnostics.d.ts +3 -1
  139. package/dist/runtime/cli-diagnostics.js +17 -5
  140. package/dist/runtime/cli-doctor-workspace-bindings.js +63 -1
  141. package/dist/runtime/cli-doctor-workspace-block-addons.d.ts +12 -0
  142. package/dist/runtime/cli-doctor-workspace-block-addons.js +162 -0
  143. package/dist/runtime/cli-doctor-workspace-block-iframe.d.ts +9 -0
  144. package/dist/runtime/cli-doctor-workspace-block-iframe.js +228 -0
  145. package/dist/runtime/cli-doctor-workspace-block-metadata.d.ts +11 -0
  146. package/dist/runtime/cli-doctor-workspace-block-metadata.js +111 -0
  147. package/dist/runtime/cli-doctor-workspace-blocks.js +6 -424
  148. package/dist/runtime/cli-doctor-workspace-features-abilities.d.ts +11 -0
  149. package/dist/runtime/cli-doctor-workspace-features-abilities.js +112 -0
  150. package/dist/runtime/cli-doctor-workspace-features-admin-views.d.ts +11 -0
  151. package/dist/runtime/cli-doctor-workspace-features-admin-views.js +128 -0
  152. package/dist/runtime/cli-doctor-workspace-features-ai.d.ts +11 -0
  153. package/dist/runtime/cli-doctor-workspace-features-ai.js +57 -0
  154. package/dist/runtime/cli-doctor-workspace-features-editor-plugins.d.ts +11 -0
  155. package/dist/runtime/cli-doctor-workspace-features-editor-plugins.js +80 -0
  156. package/dist/runtime/cli-doctor-workspace-features-post-meta.d.ts +11 -0
  157. package/dist/runtime/cli-doctor-workspace-features-post-meta.js +77 -0
  158. package/dist/runtime/cli-doctor-workspace-features-rest.d.ts +11 -0
  159. package/dist/runtime/cli-doctor-workspace-features-rest.js +120 -0
  160. package/dist/runtime/cli-doctor-workspace-features.js +14 -487
  161. package/dist/runtime/cli-doctor.d.ts +54 -3
  162. package/dist/runtime/cli-doctor.js +92 -10
  163. package/dist/runtime/cli-help.js +12 -7
  164. package/dist/runtime/cli-init-package-json.js +4 -2
  165. package/dist/runtime/cli-prompt.d.ts +16 -2
  166. package/dist/runtime/cli-prompt.js +29 -12
  167. package/dist/runtime/cli-scaffold.d.ts +2 -1
  168. package/dist/runtime/cli-scaffold.js +19 -10
  169. package/dist/runtime/external-template-guards.js +4 -6
  170. package/dist/runtime/index.d.ts +6 -3
  171. package/dist/runtime/index.js +4 -2
  172. package/dist/runtime/json-utils.d.ts +62 -4
  173. package/dist/runtime/json-utils.js +78 -4
  174. package/dist/runtime/local-dev-presets.js +6 -2
  175. package/dist/runtime/migration-ui-capability.js +4 -1
  176. package/dist/runtime/migration-utils.js +4 -1
  177. package/dist/runtime/package-managers.js +6 -1
  178. package/dist/runtime/package-versions.d.ts +1 -0
  179. package/dist/runtime/package-versions.js +16 -3
  180. package/dist/runtime/pattern-catalog.d.ts +122 -0
  181. package/dist/runtime/pattern-catalog.js +471 -0
  182. package/dist/runtime/post-meta-binding-fields.d.ts +46 -0
  183. package/dist/runtime/post-meta-binding-fields.js +135 -0
  184. package/dist/runtime/scaffold-bootstrap.js +7 -2
  185. package/dist/runtime/scaffold-package-manager-files.js +5 -1
  186. package/dist/runtime/scaffold-repository-reference.js +4 -2
  187. package/dist/runtime/scaffold-template-variables.js +2 -1
  188. package/dist/runtime/scaffold.d.ts +18 -1
  189. package/dist/runtime/scaffold.js +55 -2
  190. package/dist/runtime/temp-roots.js +4 -1
  191. package/dist/runtime/template-layers.js +4 -1
  192. package/dist/runtime/template-registry.js +9 -3
  193. package/dist/runtime/template-source-contracts.d.ts +2 -0
  194. package/dist/runtime/template-source-normalization.js +2 -1
  195. package/dist/runtime/template-source-remote.js +18 -5
  196. package/dist/runtime/template-source-seeds.js +10 -3
  197. package/dist/runtime/typia-llm-json-schema.d.ts +24 -0
  198. package/dist/runtime/typia-llm-json-schema.js +33 -0
  199. package/dist/runtime/typia-llm-openapi-constraints.d.ts +20 -0
  200. package/dist/runtime/typia-llm-openapi-constraints.js +254 -0
  201. package/dist/runtime/typia-llm-projection.d.ts +25 -0
  202. package/dist/runtime/typia-llm-projection.js +58 -0
  203. package/dist/runtime/typia-llm-render.d.ts +21 -0
  204. package/dist/runtime/typia-llm-render.js +252 -0
  205. package/dist/runtime/typia-llm-sync.d.ts +10 -0
  206. package/dist/runtime/typia-llm-sync.js +63 -0
  207. package/dist/runtime/typia-llm-types.d.ts +197 -0
  208. package/dist/runtime/typia-llm-types.js +1 -0
  209. package/dist/runtime/typia-llm.d.ts +9 -255
  210. package/dist/runtime/typia-llm.js +5 -634
  211. package/dist/runtime/workspace-inventory-mutations.js +15 -1
  212. package/dist/runtime/workspace-inventory-parser-entries.d.ts +17 -0
  213. package/dist/runtime/workspace-inventory-parser-entries.js +157 -0
  214. package/dist/runtime/workspace-inventory-parser-validation.d.ts +104 -0
  215. package/dist/runtime/workspace-inventory-parser-validation.js +34 -0
  216. package/dist/runtime/workspace-inventory-parser.d.ts +3 -45
  217. package/dist/runtime/workspace-inventory-parser.js +3 -581
  218. package/dist/runtime/workspace-inventory-section-descriptors.d.ts +19 -0
  219. package/dist/runtime/workspace-inventory-section-descriptors.js +443 -0
  220. package/dist/runtime/workspace-inventory-templates.d.ts +3 -3
  221. package/dist/runtime/workspace-inventory-templates.js +10 -1
  222. package/dist/runtime/workspace-inventory-types.d.ts +10 -1
  223. package/dist/runtime/workspace-project.js +4 -6
  224. package/package.json +8 -3
  225. package/templates/_shared/compound/core/scripts/block-config.ts.mustache +22 -0
  226. package/templates/_shared/compound/core/scripts/sync-types-to-block-json.ts.mustache +103 -2
  227. package/templates/_shared/compound/core/src/inner-blocks-templates.ts.mustache +13 -0
  228. package/templates/_shared/compound/persistence/scripts/block-config.ts.mustache +22 -1
@@ -0,0 +1,142 @@
1
+ import path from "node:path";
2
+ import { patchFile } from "./cli-add-shared.js";
3
+ import { buildNoResourcesGuard, getSyncRestPatchErrorMessage, replaceBlockConfigImport, replaceNoResourcesGuard, } from "./cli-add-workspace-rest-sync-script-shared.js";
4
+ function replaceRequiredContractSyncRestSource(nextSource, target, anchor, replacement, anchorDescription, syncRestScriptPath) {
5
+ if (nextSource.includes(target)) {
6
+ return nextSource;
7
+ }
8
+ const hasAnchor = typeof anchor === "string" ? nextSource.includes(anchor) : anchor.test(nextSource);
9
+ if (!hasAnchor) {
10
+ throw new Error(getSyncRestPatchErrorMessage("ensureContractSyncScriptAnchors", syncRestScriptPath, anchorDescription, "CONTRACTS"));
11
+ }
12
+ return nextSource.replace(anchor, replacement);
13
+ }
14
+ function insertStandaloneContractFilter(nextSource, syncRestScriptPath) {
15
+ if (nextSource.includes("const standaloneContracts = CONTRACTS.filter")) {
16
+ return nextSource;
17
+ }
18
+ const restResourcesFilter = "const restResources = REST_RESOURCES.filter( isWorkspaceRestResource );";
19
+ if (nextSource.includes(restResourcesFilter)) {
20
+ return nextSource.replace(restResourcesFilter, [
21
+ "const standaloneContracts = CONTRACTS.filter( isWorkspaceStandaloneContract );",
22
+ restResourcesFilter,
23
+ ].join("\n\t"));
24
+ }
25
+ const restBlocksFilter = "const restBlocks = BLOCKS.filter( isRestEnabledBlock );";
26
+ return replaceRequiredContractSyncRestSource(nextSource, "const standaloneContracts = CONTRACTS.filter", restBlocksFilter, [
27
+ restBlocksFilter,
28
+ "const standaloneContracts = CONTRACTS.filter( isWorkspaceStandaloneContract );",
29
+ ].join("\n\t"), "restBlocks filter", syncRestScriptPath);
30
+ }
31
+ function insertStandaloneContractNoResourcesGuard(nextSource, syncRestScriptPath) {
32
+ const hasRestResources = nextSource.includes("const restResources = REST_RESOURCES.filter( isWorkspaceRestResource );");
33
+ const hasAiFeatures = nextSource.includes("const aiFeatures = AI_FEATURES.filter( isWorkspaceAiFeature );");
34
+ const hasPostMeta = nextSource.includes("const postMetaContracts = POST_META.filter( isWorkspacePostMetaContract );");
35
+ return replaceNoResourcesGuard(nextSource, buildNoResourcesGuard({
36
+ subjects: [
37
+ {
38
+ condition: "restBlocks.length === 0",
39
+ include: true,
40
+ subject: "REST-enabled workspace blocks",
41
+ },
42
+ {
43
+ condition: "standaloneContracts.length === 0",
44
+ include: true,
45
+ subject: "standalone contracts",
46
+ },
47
+ {
48
+ condition: "postMetaContracts.length === 0",
49
+ include: hasPostMeta,
50
+ subject: "post meta contracts",
51
+ },
52
+ {
53
+ condition: "restResources.length === 0",
54
+ include: hasRestResources,
55
+ subject: "plugin-level REST resources",
56
+ },
57
+ {
58
+ condition: "aiFeatures.length === 0",
59
+ include: hasAiFeatures,
60
+ subject: "AI features",
61
+ },
62
+ ],
63
+ }), "ensureContractSyncScriptAnchors", syncRestScriptPath, "CONTRACTS");
64
+ }
65
+ function insertStandaloneContractSyncLoop(nextSource, syncRestScriptPath) {
66
+ if (nextSource.includes("for ( const contract of standaloneContracts )")) {
67
+ return nextSource;
68
+ }
69
+ const loopSource = [
70
+ "\tfor ( const contract of standaloneContracts ) {",
71
+ "\t\tawait syncTypeSchemas(",
72
+ "\t\t\t{",
73
+ "\t\t\t\tjsonSchemaFile: contract.schemaFile,",
74
+ "\t\t\t\tsourceTypeName: contract.sourceTypeName,",
75
+ "\t\t\t\ttypesFile: contract.typesFile,",
76
+ "\t\t\t},",
77
+ "\t\t\t{",
78
+ "\t\t\t\tcheck: options.check,",
79
+ "\t\t\t}",
80
+ "\t\t);",
81
+ "\t}",
82
+ ].join("\n");
83
+ const resourceLoopAnchor = "\n\tfor ( const resource of restResources ) {";
84
+ if (nextSource.includes(resourceLoopAnchor)) {
85
+ return nextSource.replace(resourceLoopAnchor, `\n${loopSource}\n${resourceLoopAnchor}`);
86
+ }
87
+ const consoleLogPattern = /\n\tconsole\.log\(\n\t\toptions\.check/u;
88
+ return replaceRequiredContractSyncRestSource(nextSource, "for ( const contract of standaloneContracts )", consoleLogPattern, [
89
+ "",
90
+ loopSource,
91
+ "",
92
+ "\tconsole.log(",
93
+ "\t\toptions.check",
94
+ ].join("\n"), "success log insertion point", syncRestScriptPath);
95
+ }
96
+ /**
97
+ * Ensure sync-rest can repair and validate standalone workspace contracts.
98
+ *
99
+ * @param workspace Workspace project whose sync-rest script should be patched.
100
+ * @returns A promise that resolves after the sync-rest script is updated.
101
+ * @throws When the generated sync-rest anchors cannot be found.
102
+ */
103
+ export async function ensureContractSyncScriptAnchors(workspace) {
104
+ const syncRestScriptPath = path.join(workspace.projectDir, "scripts", "sync-rest-contracts.ts");
105
+ await patchFile(syncRestScriptPath, (source) => {
106
+ let nextSource = replaceBlockConfigImport({
107
+ functionName: "ensureContractSyncScriptAnchors",
108
+ nextSource: source,
109
+ subject: {
110
+ configTypeName: "WorkspaceContractConfig",
111
+ constName: "CONTRACTS",
112
+ },
113
+ syncRestScriptPath,
114
+ });
115
+ const helperInsertionAnchor = "async function assertTypeArtifactsCurrent";
116
+ nextSource = replaceRequiredContractSyncRestSource(nextSource, "function isWorkspaceStandaloneContract(", helperInsertionAnchor, [
117
+ "function isWorkspaceStandaloneContract(",
118
+ "\tcontract: WorkspaceContractConfig",
119
+ "): contract is WorkspaceContractConfig & {",
120
+ "\tschemaFile: string;",
121
+ "\tsourceTypeName: string;",
122
+ "\ttypesFile: string;",
123
+ "} {",
124
+ "\treturn (",
125
+ "\t\ttypeof contract.schemaFile === 'string' &&",
126
+ "\t\ttypeof contract.sourceTypeName === 'string' &&",
127
+ "\t\ttypeof contract.typesFile === 'string'",
128
+ "\t);",
129
+ "}",
130
+ "",
131
+ "async function assertTypeArtifactsCurrent",
132
+ ].join("\n"), "type artifact assertion helper", syncRestScriptPath);
133
+ nextSource = insertStandaloneContractFilter(nextSource, syncRestScriptPath);
134
+ nextSource = insertStandaloneContractNoResourcesGuard(nextSource, syncRestScriptPath);
135
+ nextSource = insertStandaloneContractSyncLoop(nextSource, syncRestScriptPath);
136
+ nextSource = nextSource.replace("✅ REST contract schemas, portable API clients, and endpoint-aware OpenAPI documents are already up to date for workspace blocks and plugin-level resources!", "✅ REST contract schemas, standalone schemas, portable API clients, and endpoint-aware OpenAPI documents are already up to date for workspace blocks, standalone contracts, and plugin-level resources!");
137
+ nextSource = nextSource.replace("✅ REST contract schemas, portable API clients, and endpoint-aware OpenAPI documents generated for workspace blocks and plugin-level resources!", "✅ REST contract schemas, standalone schemas, portable API clients, and endpoint-aware OpenAPI documents generated for workspace blocks, standalone contracts, and plugin-level resources!");
138
+ nextSource = nextSource.replace("✅ REST contract schemas, portable API clients, and endpoint-aware OpenAPI documents are already up to date with the TypeScript types!", "✅ REST contract schemas, standalone schemas, portable API clients, and endpoint-aware OpenAPI documents are already up to date with the TypeScript types!");
139
+ nextSource = nextSource.replace("✅ REST contract schemas, portable API clients, and endpoint-aware OpenAPI documents generated from TypeScript types!", "✅ REST contract schemas, standalone schemas, portable API clients, and endpoint-aware OpenAPI documents generated from TypeScript types!");
140
+ return nextSource;
141
+ });
142
+ }
@@ -0,0 +1,51 @@
1
+ import { type RestResourceMethodId } from "./cli-add-shared.js";
2
+ /**
3
+ * Build a generated REST resource config entry for `scripts/block-config.ts`.
4
+ *
5
+ * @param options REST resource metadata. `restResourceSlug`, `namespace`, and
6
+ * `methods` are required; `controllerClass`, `controllerExtends`,
7
+ * `permissionCallback`, and `routePattern` opt into generated controller,
8
+ * permission, and item-route escape hatches.
9
+ * @returns TypeScript object literal source for one generated REST resource entry.
10
+ */
11
+ export declare function buildRestResourceConfigEntry(options: {
12
+ controllerClass?: string;
13
+ controllerExtends?: string;
14
+ methods: RestResourceMethodId[];
15
+ namespace: string;
16
+ permissionCallback?: string;
17
+ restResourceSlug: string;
18
+ routePattern?: string;
19
+ }): string;
20
+ /**
21
+ * Build editable TypeScript type definitions for a generated REST resource.
22
+ *
23
+ * @param restResourceSlug Normalized REST resource slug.
24
+ * @param methods Enabled generated REST methods.
25
+ * @returns TypeScript source for `api-types.ts`.
26
+ */
27
+ export declare function buildRestResourceTypesSource(restResourceSlug: string, methods: RestResourceMethodId[]): string;
28
+ /**
29
+ * Build Typia validators for a generated REST resource.
30
+ *
31
+ * @param restResourceSlug Normalized REST resource slug.
32
+ * @param methods Enabled generated REST methods.
33
+ * @returns TypeScript source for `api-validators.ts`.
34
+ */
35
+ export declare function buildRestResourceValidatorsSource(restResourceSlug: string, methods: RestResourceMethodId[]): string;
36
+ /**
37
+ * Build the public API shim for a generated REST resource.
38
+ *
39
+ * @param restResourceSlug Normalized REST resource slug.
40
+ * @param methods Enabled generated REST methods.
41
+ * @returns TypeScript source for `api.ts`.
42
+ */
43
+ export declare function buildRestResourceApiSource(restResourceSlug: string, methods: RestResourceMethodId[]): string;
44
+ /**
45
+ * Build React query and mutation hooks for a generated REST resource.
46
+ *
47
+ * @param restResourceSlug Normalized REST resource slug.
48
+ * @param methods Enabled generated REST methods.
49
+ * @returns TypeScript source for `data.ts`.
50
+ */
51
+ export declare function buildRestResourceDataSource(restResourceSlug: string, methods: RestResourceMethodId[]): string;
@@ -0,0 +1,415 @@
1
+ import { quoteTsString, } from "./cli-add-shared.js";
2
+ import { formatResolveRestNonceSource, indentMultiline, } from "./cli-add-workspace-rest-source-utils.js";
3
+ import { buildRestResourceEndpointManifest } from "./rest-resource-artifacts.js";
4
+ import { toPascalCase, toTitleCase } from "./string-case.js";
5
+ /**
6
+ * Build a generated REST resource config entry for `scripts/block-config.ts`.
7
+ *
8
+ * @param options REST resource metadata. `restResourceSlug`, `namespace`, and
9
+ * `methods` are required; `controllerClass`, `controllerExtends`,
10
+ * `permissionCallback`, and `routePattern` opt into generated controller,
11
+ * permission, and item-route escape hatches.
12
+ * @returns TypeScript object literal source for one generated REST resource entry.
13
+ */
14
+ export function buildRestResourceConfigEntry(options) {
15
+ const pascalCase = toPascalCase(options.restResourceSlug);
16
+ const title = toTitleCase(options.restResourceSlug);
17
+ const manifest = buildRestResourceEndpointManifest({
18
+ namespace: options.namespace,
19
+ pascalCase,
20
+ ...(options.routePattern ? { routePattern: options.routePattern } : {}),
21
+ slugKebabCase: options.restResourceSlug,
22
+ title,
23
+ }, options.methods);
24
+ return [
25
+ "\t{",
26
+ `\t\tapiFile: ${quoteTsString(`src/rest/${options.restResourceSlug}/api.ts`)},`,
27
+ ...(options.controllerClass
28
+ ? [`\t\tcontrollerClass: ${quoteTsString(options.controllerClass)},`]
29
+ : []),
30
+ ...(options.controllerExtends
31
+ ? [`\t\tcontrollerExtends: ${quoteTsString(options.controllerExtends)},`]
32
+ : []),
33
+ `\t\tclientFile: ${quoteTsString(`src/rest/${options.restResourceSlug}/api-client.ts`)},`,
34
+ `\t\tdataFile: ${quoteTsString(`src/rest/${options.restResourceSlug}/data.ts`)},`,
35
+ `\t\tmethods: [ ${options.methods.map((method) => quoteTsString(method)).join(", ")} ],`,
36
+ `\t\tnamespace: ${quoteTsString(options.namespace)},`,
37
+ `\t\topenApiFile: ${quoteTsString(`src/rest/${options.restResourceSlug}/api.openapi.json`)},`,
38
+ ...(options.permissionCallback
39
+ ? [`\t\tpermissionCallback: ${quoteTsString(options.permissionCallback)},`]
40
+ : []),
41
+ `\t\tphpFile: ${quoteTsString(`inc/rest/${options.restResourceSlug}.php`)},`,
42
+ "\t\trestManifest: defineEndpointManifest(",
43
+ indentMultiline(JSON.stringify(manifest, null, "\t"), "\t\t\t"),
44
+ "\t\t),",
45
+ ...(options.routePattern
46
+ ? [`\t\troutePattern: ${quoteTsString(options.routePattern)},`]
47
+ : []),
48
+ `\t\tslug: ${quoteTsString(options.restResourceSlug)},`,
49
+ `\t\ttypesFile: ${quoteTsString(`src/rest/${options.restResourceSlug}/api-types.ts`)},`,
50
+ `\t\tvalidatorsFile: ${quoteTsString(`src/rest/${options.restResourceSlug}/api-validators.ts`)},`,
51
+ "\t},",
52
+ ].join("\n");
53
+ }
54
+ /**
55
+ * Build editable TypeScript type definitions for a generated REST resource.
56
+ *
57
+ * @param restResourceSlug Normalized REST resource slug.
58
+ * @param methods Enabled generated REST methods.
59
+ * @returns TypeScript source for `api-types.ts`.
60
+ */
61
+ export function buildRestResourceTypesSource(restResourceSlug, methods) {
62
+ const pascalCase = toPascalCase(restResourceSlug);
63
+ const lines = [
64
+ "import { tags } from 'typia';",
65
+ "",
66
+ `export type ${pascalCase}Status = 'draft' | 'published';`,
67
+ "",
68
+ `export interface ${pascalCase}Record {`,
69
+ "\tid: number & tags.Type< 'uint32' >;",
70
+ "\ttitle: string & tags.MinLength< 1 > & tags.MaxLength< 120 >;",
71
+ "\tcontent?: string & tags.MaxLength< 2000 >;",
72
+ `\tstatus: ${pascalCase}Status;`,
73
+ "\tupdatedAt: string;",
74
+ "}",
75
+ ];
76
+ if (methods.includes("list")) {
77
+ lines.push("", `export interface ${pascalCase}ListQuery {`, "\tpage?: number & tags.Type< 'uint32' > & tags.Minimum< 1 > & tags.Default< 1 >;", "\tperPage?: number & tags.Type< 'uint32' > & tags.Minimum< 1 > & tags.Maximum< 50 > & tags.Default< 10 >;", "\tsearch?: string & tags.MaxLength< 120 >;", "}", "", `export interface ${pascalCase}ListResponse {`, `\titems: ${pascalCase}Record[];`, "\tpage: number & tags.Type< 'uint32' >;", "\tperPage: number & tags.Type< 'uint32' >;", "\ttotal: number & tags.Type< 'uint32' >;", "}");
78
+ }
79
+ if (methods.includes("read")) {
80
+ lines.push("", `export interface ${pascalCase}ReadQuery {`, "\tid: number & tags.Type< 'uint32' >;", "}", "", `export type ${pascalCase}ReadResponse = ${pascalCase}Record;`);
81
+ }
82
+ if (methods.includes("create")) {
83
+ lines.push("", `export interface ${pascalCase}CreateRequest {`, "\ttitle: string & tags.MinLength< 1 > & tags.MaxLength< 120 >;", "\tcontent?: string & tags.MaxLength< 2000 >;", `\tstatus?: ${pascalCase}Status;`, "}", "", `export type ${pascalCase}CreateResponse = ${pascalCase}Record;`);
84
+ }
85
+ if (methods.includes("update")) {
86
+ lines.push("", `export interface ${pascalCase}UpdateQuery {`, "\tid: number & tags.Type< 'uint32' >;", "}", "", `export interface ${pascalCase}UpdateRequest {`, "\ttitle?: string & tags.MinLength< 1 > & tags.MaxLength< 120 >;", "\tcontent?: string & tags.MaxLength< 2000 >;", `\tstatus?: ${pascalCase}Status;`, "}", "", `export type ${pascalCase}UpdateResponse = ${pascalCase}Record;`);
87
+ }
88
+ if (methods.includes("delete")) {
89
+ lines.push("", `export interface ${pascalCase}DeleteQuery {`, "\tid: number & tags.Type< 'uint32' >;", "}", "", `export interface ${pascalCase}DeleteResponse {`, "\tdeleted: true;", "\tid: number & tags.Type< 'uint32' >;", "}");
90
+ }
91
+ return `${lines.join("\n")}\n`;
92
+ }
93
+ /**
94
+ * Build Typia validators for a generated REST resource.
95
+ *
96
+ * @param restResourceSlug Normalized REST resource slug.
97
+ * @param methods Enabled generated REST methods.
98
+ * @returns TypeScript source for `api-validators.ts`.
99
+ */
100
+ export function buildRestResourceValidatorsSource(restResourceSlug, methods) {
101
+ const pascalCase = toPascalCase(restResourceSlug);
102
+ const importedTypes = new Set();
103
+ const validatorDeclarations = [];
104
+ const validatorEntries = [];
105
+ const addValidator = (propertyName, typeName, validateIdentifier) => {
106
+ importedTypes.add(typeName);
107
+ validatorDeclarations.push(`const ${validateIdentifier} = typia.createValidate< ${typeName} >();`);
108
+ validatorEntries.push(`\t${propertyName}: ( input: unknown ) => toValidationResult< ${typeName} >( ${validateIdentifier}( input ) ),`);
109
+ };
110
+ if (methods.includes("list")) {
111
+ addValidator("listQuery", `${pascalCase}ListQuery`, "validateListQuery");
112
+ addValidator("listResponse", `${pascalCase}ListResponse`, "validateListResponse");
113
+ }
114
+ if (methods.includes("read")) {
115
+ addValidator("readQuery", `${pascalCase}ReadQuery`, "validateReadQuery");
116
+ addValidator("readResponse", `${pascalCase}ReadResponse`, "validateReadResponse");
117
+ }
118
+ if (methods.includes("create")) {
119
+ addValidator("createRequest", `${pascalCase}CreateRequest`, "validateCreateRequest");
120
+ addValidator("createResponse", `${pascalCase}CreateResponse`, "validateCreateResponse");
121
+ }
122
+ if (methods.includes("update")) {
123
+ addValidator("updateQuery", `${pascalCase}UpdateQuery`, "validateUpdateQuery");
124
+ addValidator("updateRequest", `${pascalCase}UpdateRequest`, "validateUpdateRequest");
125
+ addValidator("updateResponse", `${pascalCase}UpdateResponse`, "validateUpdateResponse");
126
+ }
127
+ if (methods.includes("delete")) {
128
+ addValidator("deleteQuery", `${pascalCase}DeleteQuery`, "validateDeleteQuery");
129
+ addValidator("deleteResponse", `${pascalCase}DeleteResponse`, "validateDeleteResponse");
130
+ }
131
+ return `import typia from 'typia';
132
+
133
+ import { toValidationResult } from '@wp-typia/rest';
134
+ import type {
135
+ \t${Array.from(importedTypes).sort().join(",\n\t")},
136
+ } from './api-types';
137
+
138
+ ${validatorDeclarations.join("\n")}
139
+
140
+ export const apiValidators = {
141
+ ${validatorEntries.join("\n")}
142
+ };
143
+ `;
144
+ }
145
+ /**
146
+ * Build the public API shim for a generated REST resource.
147
+ *
148
+ * @param restResourceSlug Normalized REST resource slug.
149
+ * @param methods Enabled generated REST methods.
150
+ * @returns TypeScript source for `api.ts`.
151
+ */
152
+ export function buildRestResourceApiSource(restResourceSlug, methods) {
153
+ const pascalCase = toPascalCase(restResourceSlug);
154
+ const typeImports = new Set();
155
+ const clientEndpointImports = [];
156
+ const exportedBindings = [];
157
+ const writeMethods = methods.filter((method) => ["create", "update", "delete"].includes(method));
158
+ if (methods.includes("list")) {
159
+ typeImports.add(`${pascalCase}ListQuery`);
160
+ clientEndpointImports.push(`list${pascalCase}ResourcesEndpoint`);
161
+ exportedBindings.push(`export const restResourceListEndpoint = {
162
+ \t...list${pascalCase}ResourcesEndpoint,
163
+ \tbuildRequestOptions: ( request: ${pascalCase}ListQuery ) =>
164
+ \t\tresolveEndpointRouteOptions( list${pascalCase}ResourcesEndpoint, request ),
165
+ };
166
+
167
+ export function listResource( request: ${pascalCase}ListQuery ) {
168
+ \treturn callEndpoint( restResourceListEndpoint, request );
169
+ }`);
170
+ }
171
+ if (methods.includes("read")) {
172
+ typeImports.add(`${pascalCase}ReadQuery`);
173
+ clientEndpointImports.push(`read${pascalCase}ResourceEndpoint`);
174
+ exportedBindings.push(`export const restResourceReadEndpoint = {
175
+ \t...read${pascalCase}ResourceEndpoint,
176
+ \tbuildRequestOptions: ( request: ${pascalCase}ReadQuery ) =>
177
+ \t\tresolveEndpointRouteOptions( read${pascalCase}ResourceEndpoint, request ),
178
+ };
179
+
180
+ export function readResource( request: ${pascalCase}ReadQuery ) {
181
+ \treturn callEndpoint( restResourceReadEndpoint, request );
182
+ }`);
183
+ }
184
+ if (methods.includes("create")) {
185
+ typeImports.add(`${pascalCase}CreateRequest`);
186
+ clientEndpointImports.push(`create${pascalCase}ResourceEndpoint`);
187
+ exportedBindings.push(`export const restResourceCreateEndpoint = {
188
+ \t...create${pascalCase}ResourceEndpoint,
189
+ \tbuildRequestOptions: ( request: ${pascalCase}CreateRequest ) => {
190
+ \t\tconst nonce = resolveRestNonce();
191
+ \t\treturn {
192
+ \t\t\t...resolveEndpointRouteOptions( create${pascalCase}ResourceEndpoint, request ),
193
+ \t\t\theaders: nonce
194
+ \t\t\t\t? {
195
+ \t\t\t\t\t'X-WP-Nonce': nonce,
196
+ \t\t\t\t}
197
+ \t\t\t\t: undefined,
198
+ \t\t};
199
+ \t},
200
+ };
201
+
202
+ export function createResource( request: ${pascalCase}CreateRequest ) {
203
+ \treturn callEndpoint( restResourceCreateEndpoint, request );
204
+ }`);
205
+ }
206
+ if (methods.includes("update")) {
207
+ typeImports.add(`${pascalCase}UpdateQuery`);
208
+ typeImports.add(`${pascalCase}UpdateRequest`);
209
+ clientEndpointImports.push(`update${pascalCase}ResourceEndpoint`);
210
+ exportedBindings.push(`export const restResourceUpdateEndpoint = {
211
+ \t...update${pascalCase}ResourceEndpoint,
212
+ \tbuildRequestOptions: ( request: {
213
+ \t\tbody: ${pascalCase}UpdateRequest;
214
+ \t\tquery: ${pascalCase}UpdateQuery;
215
+ \t} ) => {
216
+ \t\tconst nonce = resolveRestNonce();
217
+ \t\treturn {
218
+ \t\t\t...resolveEndpointRouteOptions( update${pascalCase}ResourceEndpoint, request ),
219
+ \t\t\theaders: nonce
220
+ \t\t\t\t? {
221
+ \t\t\t\t\t'X-WP-Nonce': nonce,
222
+ \t\t\t\t}
223
+ \t\t\t\t: undefined,
224
+ \t\t};
225
+ \t},
226
+ };
227
+
228
+ export function updateResource( request: {
229
+ \tbody: ${pascalCase}UpdateRequest;
230
+ \tquery: ${pascalCase}UpdateQuery;
231
+ } ) {
232
+ \treturn callEndpoint( restResourceUpdateEndpoint, request );
233
+ }`);
234
+ }
235
+ if (methods.includes("delete")) {
236
+ typeImports.add(`${pascalCase}DeleteQuery`);
237
+ clientEndpointImports.push(`delete${pascalCase}ResourceEndpoint`);
238
+ exportedBindings.push(`export const restResourceDeleteEndpoint = {
239
+ \t...delete${pascalCase}ResourceEndpoint,
240
+ \tbuildRequestOptions: ( request: ${pascalCase}DeleteQuery ) => {
241
+ \t\tconst nonce = resolveRestNonce();
242
+ \t\treturn {
243
+ \t\t\t...resolveEndpointRouteOptions( delete${pascalCase}ResourceEndpoint, request ),
244
+ \t\t\theaders: nonce
245
+ \t\t\t\t? {
246
+ \t\t\t\t\t'X-WP-Nonce': nonce,
247
+ \t\t\t\t}
248
+ \t\t\t\t: undefined,
249
+ \t\t};
250
+ \t},
251
+ };
252
+
253
+ export function deleteResource( request: ${pascalCase}DeleteQuery ) {
254
+ \treturn callEndpoint( restResourceDeleteEndpoint, request );
255
+ }`);
256
+ }
257
+ const resolveRestNonceSource = writeMethods.length > 0
258
+ ? `${formatResolveRestNonceSource("spaced")}\n\n`
259
+ : "";
260
+ return `import {
261
+ \tcallEndpoint,
262
+ \tresolveRestRouteUrl,
263
+ } from '@wp-typia/rest';
264
+
265
+ import type {
266
+ \t${Array.from(typeImports).sort().join(",\n\t")},
267
+ } from './api-types';
268
+ import {
269
+ \t${clientEndpointImports.sort().join(",\n\t")},
270
+ } from './api-client';
271
+ ${resolveRestNonceSource}
272
+ function resolveEndpointRouteOptions<TRequest>(
273
+ \tendpoint: {
274
+ \t\tbuildRequestOptions?: ( request: TRequest ) => {
275
+ \t\t\tpath?: string;
276
+ \t\t\turl?: string;
277
+ \t\t};
278
+ \t\tpath: string;
279
+ \t},
280
+ \trequest: TRequest
281
+ ) {
282
+ \tconst requestOptions = endpoint.buildRequestOptions?.( request ) ?? {};
283
+ \treturn {
284
+ \t\t...requestOptions,
285
+ \t\tpath: undefined,
286
+ \t\turl: requestOptions.url ?? resolveRestRouteUrl( requestOptions.path ?? endpoint.path ),
287
+ \t};
288
+ }
289
+
290
+ ${exportedBindings.join("\n\n")}
291
+ `;
292
+ }
293
+ /**
294
+ * Build React query and mutation hooks for a generated REST resource.
295
+ *
296
+ * @param restResourceSlug Normalized REST resource slug.
297
+ * @param methods Enabled generated REST methods.
298
+ * @returns TypeScript source for `data.ts`.
299
+ */
300
+ export function buildRestResourceDataSource(restResourceSlug, methods) {
301
+ const pascalCase = toPascalCase(restResourceSlug);
302
+ const typeImports = new Set();
303
+ const endpointImports = [];
304
+ const exportedBindings = [];
305
+ if (methods.includes("list")) {
306
+ typeImports.add(`${pascalCase}ListQuery`);
307
+ typeImports.add(`${pascalCase}ListResponse`);
308
+ endpointImports.push("restResourceListEndpoint");
309
+ exportedBindings.push(`export type Use${pascalCase}ListQueryOptions<
310
+ \tSelected = ${pascalCase}ListResponse,
311
+ > = UseEndpointQueryOptions<
312
+ \t${pascalCase}ListQuery,
313
+ \t${pascalCase}ListResponse,
314
+ \tSelected
315
+ >;
316
+
317
+ export function use${pascalCase}ListQuery<
318
+ \tSelected = ${pascalCase}ListResponse,
319
+ >(
320
+ \trequest: ${pascalCase}ListQuery,
321
+ \toptions: Use${pascalCase}ListQueryOptions< Selected > = {}
322
+ ) {
323
+ \treturn useEndpointQuery( restResourceListEndpoint, request, options );
324
+ }`);
325
+ }
326
+ if (methods.includes("read")) {
327
+ typeImports.add(`${pascalCase}ReadQuery`);
328
+ typeImports.add(`${pascalCase}ReadResponse`);
329
+ endpointImports.push("restResourceReadEndpoint");
330
+ exportedBindings.push(`export type Use${pascalCase}ReadQueryOptions<
331
+ \tSelected = ${pascalCase}ReadResponse,
332
+ > = UseEndpointQueryOptions<
333
+ \t${pascalCase}ReadQuery,
334
+ \t${pascalCase}ReadResponse,
335
+ \tSelected
336
+ >;
337
+
338
+ export function use${pascalCase}ReadQuery<
339
+ \tSelected = ${pascalCase}ReadResponse,
340
+ >(
341
+ \trequest: ${pascalCase}ReadQuery,
342
+ \toptions: Use${pascalCase}ReadQueryOptions< Selected > = {}
343
+ ) {
344
+ \treturn useEndpointQuery( restResourceReadEndpoint, request, options );
345
+ }`);
346
+ }
347
+ if (methods.includes("create")) {
348
+ typeImports.add(`${pascalCase}CreateRequest`);
349
+ typeImports.add(`${pascalCase}CreateResponse`);
350
+ endpointImports.push("restResourceCreateEndpoint");
351
+ exportedBindings.push(`export type UseCreate${pascalCase}ResourceMutationOptions = UseEndpointMutationOptions<
352
+ \t${pascalCase}CreateRequest,
353
+ \t${pascalCase}CreateResponse,
354
+ \tunknown
355
+ >;
356
+
357
+ export function useCreate${pascalCase}ResourceMutation(
358
+ \toptions: UseCreate${pascalCase}ResourceMutationOptions = {}
359
+ ) {
360
+ \treturn useEndpointMutation( restResourceCreateEndpoint, options );
361
+ }`);
362
+ }
363
+ if (methods.includes("update")) {
364
+ typeImports.add(`${pascalCase}UpdateQuery`);
365
+ typeImports.add(`${pascalCase}UpdateRequest`);
366
+ typeImports.add(`${pascalCase}UpdateResponse`);
367
+ endpointImports.push("restResourceUpdateEndpoint");
368
+ exportedBindings.push(`export type UseUpdate${pascalCase}ResourceMutationOptions = UseEndpointMutationOptions<
369
+ \t{
370
+ \t\tbody: ${pascalCase}UpdateRequest;
371
+ \t\tquery: ${pascalCase}UpdateQuery;
372
+ \t},
373
+ \t${pascalCase}UpdateResponse,
374
+ \tunknown
375
+ >;
376
+
377
+ export function useUpdate${pascalCase}ResourceMutation(
378
+ \toptions: UseUpdate${pascalCase}ResourceMutationOptions = {}
379
+ ) {
380
+ \treturn useEndpointMutation( restResourceUpdateEndpoint, options );
381
+ }`);
382
+ }
383
+ if (methods.includes("delete")) {
384
+ typeImports.add(`${pascalCase}DeleteQuery`);
385
+ typeImports.add(`${pascalCase}DeleteResponse`);
386
+ endpointImports.push("restResourceDeleteEndpoint");
387
+ exportedBindings.push(`export type UseDelete${pascalCase}ResourceMutationOptions = UseEndpointMutationOptions<
388
+ \t${pascalCase}DeleteQuery,
389
+ \t${pascalCase}DeleteResponse,
390
+ \tunknown
391
+ >;
392
+
393
+ export function useDelete${pascalCase}ResourceMutation(
394
+ \toptions: UseDelete${pascalCase}ResourceMutationOptions = {}
395
+ ) {
396
+ \treturn useEndpointMutation( restResourceDeleteEndpoint, options );
397
+ }`);
398
+ }
399
+ return `import {
400
+ \tuseEndpointMutation,
401
+ \tuseEndpointQuery,
402
+ \ttype UseEndpointMutationOptions,
403
+ \ttype UseEndpointQueryOptions,
404
+ } from '@wp-typia/rest/react';
405
+
406
+ import type {
407
+ \t${Array.from(typeImports).sort().join(",\n\t")},
408
+ } from './api-types';
409
+ import {
410
+ \t${endpointImports.sort().join(",\n\t")},
411
+ } from './api';
412
+
413
+ ${exportedBindings.join("\n\n")}
414
+ `;
415
+ }
@@ -0,0 +1,9 @@
1
+ import { type GeneratedRestResourceScaffoldOptions, type RunAddRestResourceCommandResult } from "./cli-add-workspace-rest-types.js";
2
+ /**
3
+ * Scaffold generated TypeScript, PHP, schema, and inventory files for a
4
+ * workspace-owned REST resource.
5
+ *
6
+ * @param options Resolved workspace and raw generated-mode command options.
7
+ * @returns Resolved scaffold metadata for the generated REST resource.
8
+ */
9
+ export declare function scaffoldGeneratedRestResource({ controllerClass, controllerExtends, methods, namespace, permissionCallback, restResourceSlug, routePattern, workspace, }: GeneratedRestResourceScaffoldOptions): Promise<RunAddRestResourceCommandResult>;