@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.
- package/dist/runtime/ai-feature-artifacts.js +4 -1
- package/dist/runtime/block-generator-service-spec.js +2 -1
- package/dist/runtime/built-in-block-non-ts-basic-artifacts.d.ts +9 -0
- package/dist/runtime/built-in-block-non-ts-basic-artifacts.js +84 -0
- package/dist/runtime/built-in-block-non-ts-compound-artifacts.d.ts +9 -0
- package/dist/runtime/built-in-block-non-ts-compound-artifacts.js +36 -0
- package/dist/runtime/built-in-block-non-ts-compound-templates.d.ts +23 -0
- package/dist/runtime/built-in-block-non-ts-compound-templates.js +453 -0
- package/dist/runtime/built-in-block-non-ts-family-artifacts.d.ts +8 -26
- package/dist/runtime/built-in-block-non-ts-family-artifacts.js +8 -1034
- package/dist/runtime/built-in-block-non-ts-interactivity-artifacts.d.ts +9 -0
- package/dist/runtime/built-in-block-non-ts-interactivity-artifacts.js +83 -0
- package/dist/runtime/built-in-block-non-ts-persistence-artifacts.d.ts +9 -0
- package/dist/runtime/built-in-block-non-ts-persistence-artifacts.js +33 -0
- package/dist/runtime/built-in-block-non-ts-persistence-templates.d.ts +23 -0
- package/dist/runtime/built-in-block-non-ts-persistence-templates.js +395 -0
- package/dist/runtime/cli-add-block-json.js +5 -1
- package/dist/runtime/cli-add-collision.js +8 -0
- package/dist/runtime/cli-add-help.js +14 -10
- package/dist/runtime/cli-add-kind-ids.d.ts +1 -1
- package/dist/runtime/cli-add-kind-ids.js +1 -0
- package/dist/runtime/cli-add-types.d.ts +45 -6
- package/dist/runtime/cli-add-types.js +2 -0
- package/dist/runtime/cli-add-validation.d.ts +7 -0
- package/dist/runtime/cli-add-validation.js +9 -0
- package/dist/runtime/cli-add-workspace-ability-anchors.d.ts +24 -0
- package/dist/runtime/cli-add-workspace-ability-anchors.js +294 -0
- package/dist/runtime/cli-add-workspace-ability-registry.d.ts +10 -0
- package/dist/runtime/cli-add-workspace-ability-registry.js +51 -0
- package/dist/runtime/cli-add-workspace-ability-scaffold.d.ts +1 -1
- package/dist/runtime/cli-add-workspace-ability-scaffold.js +5 -308
- package/dist/runtime/cli-add-workspace-admin-view-scaffold.js +6 -2
- package/dist/runtime/cli-add-workspace-admin-view-templates-core-data.d.ts +34 -0
- package/dist/runtime/cli-add-workspace-admin-view-templates-core-data.js +483 -0
- package/dist/runtime/cli-add-workspace-admin-view-templates-default.d.ts +30 -0
- package/dist/runtime/cli-add-workspace-admin-view-templates-default.js +310 -0
- package/dist/runtime/cli-add-workspace-admin-view-templates-rest.d.ts +25 -0
- package/dist/runtime/cli-add-workspace-admin-view-templates-rest.js +124 -0
- package/dist/runtime/cli-add-workspace-admin-view-templates-settings.d.ts +34 -0
- package/dist/runtime/cli-add-workspace-admin-view-templates-settings.js +370 -0
- package/dist/runtime/cli-add-workspace-admin-view-templates-shared.d.ts +49 -0
- package/dist/runtime/cli-add-workspace-admin-view-templates-shared.js +259 -0
- package/dist/runtime/cli-add-workspace-admin-view-templates.d.ts +18 -27
- package/dist/runtime/cli-add-workspace-admin-view-templates.js +30 -1326
- package/dist/runtime/cli-add-workspace-ai-anchors.d.ts +4 -4
- package/dist/runtime/cli-add-workspace-ai-anchors.js +8 -233
- package/dist/runtime/cli-add-workspace-ai-scaffold.js +4 -2
- package/dist/runtime/cli-add-workspace-ai-source-emitters.d.ts +1 -4
- package/dist/runtime/cli-add-workspace-ai-source-emitters.js +1 -129
- package/dist/runtime/cli-add-workspace-ai-sync-rest-anchors.d.ts +5 -0
- package/dist/runtime/cli-add-workspace-ai-sync-rest-anchors.js +236 -0
- package/dist/runtime/cli-add-workspace-ai-sync-script-source.d.ts +4 -0
- package/dist/runtime/cli-add-workspace-ai-sync-script-source.js +145 -0
- package/dist/runtime/cli-add-workspace-assets.d.ts +6 -63
- package/dist/runtime/cli-add-workspace-assets.js +6 -950
- package/dist/runtime/cli-add-workspace-binding-source-anchors.d.ts +23 -0
- package/dist/runtime/cli-add-workspace-binding-source-anchors.js +112 -0
- package/dist/runtime/cli-add-workspace-binding-source-source-emitters.d.ts +33 -0
- package/dist/runtime/cli-add-workspace-binding-source-source-emitters.js +436 -0
- package/dist/runtime/cli-add-workspace-binding-source-types.d.ts +20 -0
- package/dist/runtime/cli-add-workspace-binding-source-types.js +1 -0
- package/dist/runtime/cli-add-workspace-binding-source.d.ts +40 -0
- package/dist/runtime/cli-add-workspace-binding-source.js +275 -0
- package/dist/runtime/cli-add-workspace-block-style.d.ts +22 -0
- package/dist/runtime/cli-add-workspace-block-style.js +148 -0
- package/dist/runtime/cli-add-workspace-block-transform.d.ts +32 -0
- package/dist/runtime/cli-add-workspace-block-transform.js +197 -0
- package/dist/runtime/cli-add-workspace-contract.js +1 -1
- package/dist/runtime/cli-add-workspace-core-variation.d.ts +20 -0
- package/dist/runtime/cli-add-workspace-core-variation.js +322 -0
- package/dist/runtime/cli-add-workspace-editor-plugin-anchors.d.ts +37 -0
- package/dist/runtime/cli-add-workspace-editor-plugin-anchors.js +206 -0
- package/dist/runtime/cli-add-workspace-editor-plugin-source-emitters.d.ts +47 -0
- package/dist/runtime/cli-add-workspace-editor-plugin-source-emitters.js +219 -0
- package/dist/runtime/cli-add-workspace-editor-plugin.d.ts +22 -0
- package/dist/runtime/cli-add-workspace-editor-plugin.js +78 -0
- package/dist/runtime/cli-add-workspace-hooked-block.d.ts +23 -0
- package/dist/runtime/cli-add-workspace-hooked-block.js +57 -0
- package/dist/runtime/cli-add-workspace-integration-env-files.d.ts +33 -0
- package/dist/runtime/cli-add-workspace-integration-env-files.js +65 -0
- package/dist/runtime/cli-add-workspace-integration-env-package-json.d.ts +38 -0
- package/dist/runtime/cli-add-workspace-integration-env-package-json.js +122 -0
- package/dist/runtime/cli-add-workspace-integration-env-source-emitters.d.ts +44 -0
- package/dist/runtime/cli-add-workspace-integration-env-source-emitters.js +262 -0
- package/dist/runtime/cli-add-workspace-integration-env.d.ts +3 -1
- package/dist/runtime/cli-add-workspace-integration-env.js +10 -313
- package/dist/runtime/cli-add-workspace-pattern-anchors.d.ts +10 -0
- package/dist/runtime/cli-add-workspace-pattern-anchors.js +95 -0
- package/dist/runtime/cli-add-workspace-pattern-options.d.ts +20 -0
- package/dist/runtime/cli-add-workspace-pattern-options.js +113 -0
- package/dist/runtime/cli-add-workspace-pattern-source-emitters.d.ts +20 -0
- package/dist/runtime/cli-add-workspace-pattern-source-emitters.js +57 -0
- package/dist/runtime/cli-add-workspace-pattern.d.ts +42 -0
- package/dist/runtime/cli-add-workspace-pattern.js +99 -0
- package/dist/runtime/cli-add-workspace-post-meta.js +1 -1
- package/dist/runtime/cli-add-workspace-registration-hooks.d.ts +50 -0
- package/dist/runtime/cli-add-workspace-registration-hooks.js +162 -0
- package/dist/runtime/cli-add-workspace-rest-anchors.d.ts +9 -4
- package/dist/runtime/cli-add-workspace-rest-anchors.js +9 -428
- package/dist/runtime/cli-add-workspace-rest-bootstrap-anchors.d.ts +17 -0
- package/dist/runtime/cli-add-workspace-rest-bootstrap-anchors.js +108 -0
- package/dist/runtime/cli-add-workspace-rest-contract-sync-anchors.d.ts +9 -0
- package/dist/runtime/cli-add-workspace-rest-contract-sync-anchors.js +142 -0
- package/dist/runtime/cli-add-workspace-rest-generated-source-emitters.d.ts +51 -0
- package/dist/runtime/cli-add-workspace-rest-generated-source-emitters.js +415 -0
- package/dist/runtime/cli-add-workspace-rest-generated.d.ts +9 -0
- package/dist/runtime/cli-add-workspace-rest-generated.js +160 -0
- package/dist/runtime/cli-add-workspace-rest-manual-source-emitters.d.ts +80 -0
- package/dist/runtime/cli-add-workspace-rest-manual-source-emitters.js +238 -0
- package/dist/runtime/cli-add-workspace-rest-manual.d.ts +8 -0
- package/dist/runtime/cli-add-workspace-rest-manual.js +266 -0
- package/dist/runtime/cli-add-workspace-rest-php-templates.d.ts +18 -0
- package/dist/runtime/cli-add-workspace-rest-php-templates.js +359 -0
- package/dist/runtime/cli-add-workspace-rest-resource-php-routing-template.d.ts +33 -0
- package/dist/runtime/cli-add-workspace-rest-resource-php-routing-template.js +145 -0
- package/dist/runtime/cli-add-workspace-rest-resource-sync-anchors.d.ts +9 -0
- package/dist/runtime/cli-add-workspace-rest-resource-sync-anchors.js +162 -0
- package/dist/runtime/cli-add-workspace-rest-schema-helper-php-template.d.ts +7 -0
- package/dist/runtime/cli-add-workspace-rest-schema-helper-php-template.js +193 -0
- package/dist/runtime/cli-add-workspace-rest-source-emitters.d.ts +5 -91
- package/dist/runtime/cli-add-workspace-rest-source-emitters.js +5 -642
- package/dist/runtime/cli-add-workspace-rest-source-utils.d.ts +17 -0
- package/dist/runtime/cli-add-workspace-rest-source-utils.js +50 -0
- package/dist/runtime/cli-add-workspace-rest-sync-script-shared.d.ts +56 -0
- package/dist/runtime/cli-add-workspace-rest-sync-script-shared.js +122 -0
- package/dist/runtime/cli-add-workspace-rest-types.d.ts +108 -0
- package/dist/runtime/cli-add-workspace-rest-types.js +1 -0
- package/dist/runtime/cli-add-workspace-rest.d.ts +3 -20
- package/dist/runtime/cli-add-workspace-rest.js +33 -788
- package/dist/runtime/cli-add-workspace-variation.d.ts +22 -0
- package/dist/runtime/cli-add-workspace-variation.js +162 -0
- package/dist/runtime/cli-add-workspace.d.ts +42 -107
- package/dist/runtime/cli-add-workspace.js +42 -674
- package/dist/runtime/cli-add.d.ts +3 -3
- package/dist/runtime/cli-add.js +2 -2
- package/dist/runtime/cli-core.d.ts +3 -2
- package/dist/runtime/cli-core.js +2 -2
- package/dist/runtime/cli-diagnostics.d.ts +3 -1
- package/dist/runtime/cli-diagnostics.js +17 -5
- package/dist/runtime/cli-doctor-workspace-bindings.js +63 -1
- package/dist/runtime/cli-doctor-workspace-block-addons.d.ts +12 -0
- package/dist/runtime/cli-doctor-workspace-block-addons.js +162 -0
- package/dist/runtime/cli-doctor-workspace-block-iframe.d.ts +9 -0
- package/dist/runtime/cli-doctor-workspace-block-iframe.js +228 -0
- package/dist/runtime/cli-doctor-workspace-block-metadata.d.ts +11 -0
- package/dist/runtime/cli-doctor-workspace-block-metadata.js +111 -0
- package/dist/runtime/cli-doctor-workspace-blocks.js +6 -424
- package/dist/runtime/cli-doctor-workspace-features-abilities.d.ts +11 -0
- package/dist/runtime/cli-doctor-workspace-features-abilities.js +112 -0
- package/dist/runtime/cli-doctor-workspace-features-admin-views.d.ts +11 -0
- package/dist/runtime/cli-doctor-workspace-features-admin-views.js +128 -0
- package/dist/runtime/cli-doctor-workspace-features-ai.d.ts +11 -0
- package/dist/runtime/cli-doctor-workspace-features-ai.js +57 -0
- package/dist/runtime/cli-doctor-workspace-features-editor-plugins.d.ts +11 -0
- package/dist/runtime/cli-doctor-workspace-features-editor-plugins.js +80 -0
- package/dist/runtime/cli-doctor-workspace-features-post-meta.d.ts +11 -0
- package/dist/runtime/cli-doctor-workspace-features-post-meta.js +77 -0
- package/dist/runtime/cli-doctor-workspace-features-rest.d.ts +11 -0
- package/dist/runtime/cli-doctor-workspace-features-rest.js +120 -0
- package/dist/runtime/cli-doctor-workspace-features.js +14 -487
- package/dist/runtime/cli-doctor.d.ts +54 -3
- package/dist/runtime/cli-doctor.js +92 -10
- package/dist/runtime/cli-help.js +12 -7
- package/dist/runtime/cli-init-package-json.js +4 -2
- package/dist/runtime/cli-prompt.d.ts +16 -2
- package/dist/runtime/cli-prompt.js +29 -12
- package/dist/runtime/cli-scaffold.d.ts +2 -1
- package/dist/runtime/cli-scaffold.js +19 -10
- package/dist/runtime/external-template-guards.js +4 -6
- package/dist/runtime/index.d.ts +6 -3
- package/dist/runtime/index.js +4 -2
- package/dist/runtime/json-utils.d.ts +62 -4
- package/dist/runtime/json-utils.js +78 -4
- package/dist/runtime/local-dev-presets.js +6 -2
- package/dist/runtime/migration-ui-capability.js +4 -1
- package/dist/runtime/migration-utils.js +4 -1
- package/dist/runtime/package-managers.js +6 -1
- package/dist/runtime/package-versions.d.ts +1 -0
- package/dist/runtime/package-versions.js +16 -3
- package/dist/runtime/pattern-catalog.d.ts +122 -0
- package/dist/runtime/pattern-catalog.js +471 -0
- package/dist/runtime/post-meta-binding-fields.d.ts +46 -0
- package/dist/runtime/post-meta-binding-fields.js +135 -0
- package/dist/runtime/scaffold-bootstrap.js +7 -2
- package/dist/runtime/scaffold-package-manager-files.js +5 -1
- package/dist/runtime/scaffold-repository-reference.js +4 -2
- package/dist/runtime/scaffold-template-variables.js +2 -1
- package/dist/runtime/scaffold.d.ts +18 -1
- package/dist/runtime/scaffold.js +55 -2
- package/dist/runtime/temp-roots.js +4 -1
- package/dist/runtime/template-layers.js +4 -1
- package/dist/runtime/template-registry.js +9 -3
- package/dist/runtime/template-source-contracts.d.ts +2 -0
- package/dist/runtime/template-source-normalization.js +2 -1
- package/dist/runtime/template-source-remote.js +18 -5
- package/dist/runtime/template-source-seeds.js +10 -3
- package/dist/runtime/typia-llm-json-schema.d.ts +24 -0
- package/dist/runtime/typia-llm-json-schema.js +33 -0
- package/dist/runtime/typia-llm-openapi-constraints.d.ts +20 -0
- package/dist/runtime/typia-llm-openapi-constraints.js +254 -0
- package/dist/runtime/typia-llm-projection.d.ts +25 -0
- package/dist/runtime/typia-llm-projection.js +58 -0
- package/dist/runtime/typia-llm-render.d.ts +21 -0
- package/dist/runtime/typia-llm-render.js +252 -0
- package/dist/runtime/typia-llm-sync.d.ts +10 -0
- package/dist/runtime/typia-llm-sync.js +63 -0
- package/dist/runtime/typia-llm-types.d.ts +197 -0
- package/dist/runtime/typia-llm-types.js +1 -0
- package/dist/runtime/typia-llm.d.ts +9 -255
- package/dist/runtime/typia-llm.js +5 -634
- package/dist/runtime/workspace-inventory-mutations.js +15 -1
- package/dist/runtime/workspace-inventory-parser-entries.d.ts +17 -0
- package/dist/runtime/workspace-inventory-parser-entries.js +157 -0
- package/dist/runtime/workspace-inventory-parser-validation.d.ts +104 -0
- package/dist/runtime/workspace-inventory-parser-validation.js +34 -0
- package/dist/runtime/workspace-inventory-parser.d.ts +3 -45
- package/dist/runtime/workspace-inventory-parser.js +3 -581
- package/dist/runtime/workspace-inventory-section-descriptors.d.ts +19 -0
- package/dist/runtime/workspace-inventory-section-descriptors.js +443 -0
- package/dist/runtime/workspace-inventory-templates.d.ts +3 -3
- package/dist/runtime/workspace-inventory-templates.js +10 -1
- package/dist/runtime/workspace-inventory-types.d.ts +10 -1
- package/dist/runtime/workspace-project.js +4 -6
- package/package.json +8 -3
- package/templates/_shared/compound/core/scripts/block-config.ts.mustache +22 -0
- package/templates/_shared/compound/core/scripts/sync-types-to-block-json.ts.mustache +103 -2
- package/templates/_shared/compound/core/src/inner-blocks-templates.ts.mustache +13 -0
- package/templates/_shared/compound/persistence/scripts/block-config.ts.mustache +22 -1
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { promises as fsp } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { ensureBlockConfigCanAddRestManifests } from "./cli-add-block-legacy-validator.js";
|
|
4
|
+
import { assertValidRestResourceMethods, getWorkspaceBootstrapPath, resolveGeneratedRestResourceRoutePattern, resolveOptionalPhpCallbackReference, resolveOptionalPhpClassReference, rollbackWorkspaceMutation, snapshotWorkspaceFiles, } from "./cli-add-shared.js";
|
|
5
|
+
import { ensureRestResourceBootstrapAnchors, ensureRestSchemaHelperBootstrapAnchors, } from "./cli-add-workspace-rest-bootstrap-anchors.js";
|
|
6
|
+
import { ensureRestResourceSyncScriptAnchors, } from "./cli-add-workspace-rest-resource-sync-anchors.js";
|
|
7
|
+
import { buildRestResourcePhpSource, } from "./cli-add-workspace-rest-php-templates.js";
|
|
8
|
+
import { buildWorkspaceRestSchemaHelperPhpSource, } from "./cli-add-workspace-rest-schema-helper-php-template.js";
|
|
9
|
+
import { buildRestResourceApiSource, buildRestResourceConfigEntry, buildRestResourceDataSource, buildRestResourceTypesSource, buildRestResourceValidatorsSource, } from "./cli-add-workspace-rest-generated-source-emitters.js";
|
|
10
|
+
import { hasPhpFunctionDefinition } from "./php-utils.js";
|
|
11
|
+
import { syncRestResourceArtifacts } from "./rest-resource-artifacts.js";
|
|
12
|
+
import { toPascalCase, toTitleCase } from "./string-case.js";
|
|
13
|
+
import { appendWorkspaceInventoryEntries } from "./workspace-inventory.js";
|
|
14
|
+
async function ensureWorkspaceRestSchemaHelperFile(helperFilePath, phpPrefix) {
|
|
15
|
+
let currentSource = null;
|
|
16
|
+
try {
|
|
17
|
+
currentSource = await fsp.readFile(helperFilePath, "utf8");
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
if (error.code !== "ENOENT") {
|
|
21
|
+
throw error;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (currentSource === null) {
|
|
25
|
+
await fsp.mkdir(path.dirname(helperFilePath), { recursive: true });
|
|
26
|
+
await fsp.writeFile(helperFilePath, buildWorkspaceRestSchemaHelperPhpSource(phpPrefix), "utf8");
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const requiredFunctions = [
|
|
30
|
+
`${phpPrefix}_load_rest_schema`,
|
|
31
|
+
`${phpPrefix}_prepare_rest_schema_for_wordpress`,
|
|
32
|
+
`${phpPrefix}_get_wordpress_rest_schema`,
|
|
33
|
+
`${phpPrefix}_validate_and_sanitize_rest_payload`,
|
|
34
|
+
];
|
|
35
|
+
const missingFunctions = requiredFunctions.filter((functionName) => !hasPhpFunctionDefinition(currentSource, functionName));
|
|
36
|
+
if (missingFunctions.length > 0) {
|
|
37
|
+
throw new Error([
|
|
38
|
+
`Existing ${path.relative(process.cwd(), helperFilePath)} is missing generated REST schema helper functions: ${missingFunctions.join(", ")}.`,
|
|
39
|
+
"Restore the generated inc/rest-schema.php helper or add these functions manually before retrying.",
|
|
40
|
+
].join(" "));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Scaffold generated TypeScript, PHP, schema, and inventory files for a
|
|
45
|
+
* workspace-owned REST resource.
|
|
46
|
+
*
|
|
47
|
+
* @param options Resolved workspace and raw generated-mode command options.
|
|
48
|
+
* @returns Resolved scaffold metadata for the generated REST resource.
|
|
49
|
+
*/
|
|
50
|
+
export async function scaffoldGeneratedRestResource({ controllerClass, controllerExtends, methods, namespace, permissionCallback, restResourceSlug, routePattern, workspace, }) {
|
|
51
|
+
const blockConfigPath = path.join(workspace.projectDir, "scripts", "block-config.ts");
|
|
52
|
+
const syncRestScriptPath = path.join(workspace.projectDir, "scripts", "sync-rest-contracts.ts");
|
|
53
|
+
const restResourceDir = path.join(workspace.projectDir, "src", "rest", restResourceSlug);
|
|
54
|
+
const typesFilePath = path.join(restResourceDir, "api-types.ts");
|
|
55
|
+
const validatorsFilePath = path.join(restResourceDir, "api-validators.ts");
|
|
56
|
+
const apiFilePath = path.join(restResourceDir, "api.ts");
|
|
57
|
+
const resolvedMethods = assertValidRestResourceMethods(methods);
|
|
58
|
+
const resolvedRoutePattern = resolveGeneratedRestResourceRoutePattern(restResourceSlug, routePattern);
|
|
59
|
+
const hasCustomRoutePattern = typeof routePattern === "string" && routePattern.trim().length > 0;
|
|
60
|
+
const resolvedPermissionCallback = resolveOptionalPhpCallbackReference("Generated REST resource permission callback", permissionCallback);
|
|
61
|
+
const resolvedControllerClass = resolveOptionalPhpClassReference("Generated REST resource controller class", controllerClass);
|
|
62
|
+
const resolvedControllerExtends = resolveOptionalPhpClassReference("Generated REST resource controller base class", controllerExtends);
|
|
63
|
+
if (resolvedControllerExtends && !resolvedControllerClass) {
|
|
64
|
+
throw new Error("Generated REST resource controller base class requires --controller-class.");
|
|
65
|
+
}
|
|
66
|
+
const bootstrapPath = getWorkspaceBootstrapPath(workspace);
|
|
67
|
+
const dataFilePath = path.join(restResourceDir, "data.ts");
|
|
68
|
+
const restSchemaHelperPath = path.join(workspace.projectDir, "inc", "rest-schema.php");
|
|
69
|
+
const phpFilePath = path.join(workspace.projectDir, "inc", "rest", `${restResourceSlug}.php`);
|
|
70
|
+
const mutationSnapshot = {
|
|
71
|
+
fileSources: await snapshotWorkspaceFiles([
|
|
72
|
+
blockConfigPath,
|
|
73
|
+
bootstrapPath,
|
|
74
|
+
restSchemaHelperPath,
|
|
75
|
+
syncRestScriptPath,
|
|
76
|
+
]),
|
|
77
|
+
snapshotDirs: [],
|
|
78
|
+
targetPaths: [restResourceDir, restSchemaHelperPath, phpFilePath],
|
|
79
|
+
};
|
|
80
|
+
try {
|
|
81
|
+
await fsp.mkdir(restResourceDir, { recursive: true });
|
|
82
|
+
await fsp.mkdir(path.dirname(phpFilePath), { recursive: true });
|
|
83
|
+
await ensureWorkspaceRestSchemaHelperFile(restSchemaHelperPath, workspace.workspace.phpPrefix);
|
|
84
|
+
await ensureRestSchemaHelperBootstrapAnchors(workspace);
|
|
85
|
+
await ensureRestResourceBootstrapAnchors(workspace);
|
|
86
|
+
await ensureRestResourceSyncScriptAnchors(workspace);
|
|
87
|
+
await fsp.writeFile(typesFilePath, buildRestResourceTypesSource(restResourceSlug, resolvedMethods), "utf8");
|
|
88
|
+
await fsp.writeFile(validatorsFilePath, buildRestResourceValidatorsSource(restResourceSlug, resolvedMethods), "utf8");
|
|
89
|
+
await fsp.writeFile(apiFilePath, buildRestResourceApiSource(restResourceSlug, resolvedMethods), "utf8");
|
|
90
|
+
await fsp.writeFile(dataFilePath, buildRestResourceDataSource(restResourceSlug, resolvedMethods), "utf8");
|
|
91
|
+
await fsp.writeFile(phpFilePath, buildRestResourcePhpSource(restResourceSlug, namespace, workspace.workspace.phpPrefix, resolvedMethods, {
|
|
92
|
+
...(resolvedControllerClass
|
|
93
|
+
? { controllerClass: resolvedControllerClass }
|
|
94
|
+
: {}),
|
|
95
|
+
...(resolvedControllerExtends
|
|
96
|
+
? { controllerExtends: resolvedControllerExtends }
|
|
97
|
+
: {}),
|
|
98
|
+
...(resolvedPermissionCallback
|
|
99
|
+
? { permissionCallback: resolvedPermissionCallback }
|
|
100
|
+
: {}),
|
|
101
|
+
routePattern: resolvedRoutePattern,
|
|
102
|
+
}), "utf8");
|
|
103
|
+
await syncRestResourceArtifacts({
|
|
104
|
+
clientFile: `src/rest/${restResourceSlug}/api-client.ts`,
|
|
105
|
+
methods: resolvedMethods,
|
|
106
|
+
outputDir: restResourceDir,
|
|
107
|
+
projectDir: workspace.projectDir,
|
|
108
|
+
typesFile: `src/rest/${restResourceSlug}/api-types.ts`,
|
|
109
|
+
validatorsFile: `src/rest/${restResourceSlug}/api-validators.ts`,
|
|
110
|
+
variables: {
|
|
111
|
+
namespace,
|
|
112
|
+
pascalCase: toPascalCase(restResourceSlug),
|
|
113
|
+
...(hasCustomRoutePattern ? { routePattern: resolvedRoutePattern } : {}),
|
|
114
|
+
slugKebabCase: restResourceSlug,
|
|
115
|
+
title: toTitleCase(restResourceSlug),
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
await appendWorkspaceInventoryEntries(workspace.projectDir, {
|
|
119
|
+
restResourceEntries: [
|
|
120
|
+
buildRestResourceConfigEntry({
|
|
121
|
+
...(resolvedControllerClass
|
|
122
|
+
? { controllerClass: resolvedControllerClass }
|
|
123
|
+
: {}),
|
|
124
|
+
...(resolvedControllerExtends
|
|
125
|
+
? { controllerExtends: resolvedControllerExtends }
|
|
126
|
+
: {}),
|
|
127
|
+
methods: resolvedMethods,
|
|
128
|
+
namespace,
|
|
129
|
+
...(resolvedPermissionCallback
|
|
130
|
+
? { permissionCallback: resolvedPermissionCallback }
|
|
131
|
+
: {}),
|
|
132
|
+
restResourceSlug,
|
|
133
|
+
...(hasCustomRoutePattern ? { routePattern: resolvedRoutePattern } : {}),
|
|
134
|
+
}),
|
|
135
|
+
],
|
|
136
|
+
transformSource: ensureBlockConfigCanAddRestManifests,
|
|
137
|
+
});
|
|
138
|
+
return {
|
|
139
|
+
...(resolvedControllerClass
|
|
140
|
+
? { controllerClass: resolvedControllerClass }
|
|
141
|
+
: {}),
|
|
142
|
+
...(resolvedControllerExtends
|
|
143
|
+
? { controllerExtends: resolvedControllerExtends }
|
|
144
|
+
: {}),
|
|
145
|
+
methods: resolvedMethods,
|
|
146
|
+
mode: "generated",
|
|
147
|
+
namespace,
|
|
148
|
+
...(resolvedPermissionCallback
|
|
149
|
+
? { permissionCallback: resolvedPermissionCallback }
|
|
150
|
+
: {}),
|
|
151
|
+
projectDir: workspace.projectDir,
|
|
152
|
+
restResourceSlug,
|
|
153
|
+
...(hasCustomRoutePattern ? { routePattern: resolvedRoutePattern } : {}),
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
await rollbackWorkspaceMutation(mutationSnapshot);
|
|
158
|
+
throw error;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { type ManualRestContractAuthId, type ManualRestContractHttpMethodId } from "./cli-add-shared.js";
|
|
2
|
+
/**
|
|
3
|
+
* Build the `REST_RESOURCES` config entry appended for a manual REST contract.
|
|
4
|
+
*
|
|
5
|
+
* @param options Manual contract file, route, type, and auth metadata.
|
|
6
|
+
* @param options.auth Auth intent stored in the endpoint manifest.
|
|
7
|
+
* @param options.bodyTypeName Optional exported body type name.
|
|
8
|
+
* @param options.method Uppercase HTTP method for the external route.
|
|
9
|
+
* @param options.namespace REST namespace such as `vendor/v1`.
|
|
10
|
+
* @param options.pathPattern Route pattern relative to the namespace.
|
|
11
|
+
* @param options.queryTypeName Exported query type name.
|
|
12
|
+
* @param options.responseTypeName Exported response type name.
|
|
13
|
+
* @param options.restResourceSlug Normalized workspace REST contract slug.
|
|
14
|
+
* @returns A TypeScript object literal string for `scripts/block-config.ts`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function buildManualRestContractConfigEntry(options: {
|
|
17
|
+
auth: ManualRestContractAuthId;
|
|
18
|
+
bodyTypeName?: string;
|
|
19
|
+
controllerClass?: string;
|
|
20
|
+
controllerExtends?: string;
|
|
21
|
+
method: ManualRestContractHttpMethodId;
|
|
22
|
+
namespace: string;
|
|
23
|
+
pathPattern: string;
|
|
24
|
+
permissionCallback?: string;
|
|
25
|
+
queryTypeName: string;
|
|
26
|
+
responseTypeName: string;
|
|
27
|
+
restResourceSlug: string;
|
|
28
|
+
secretFieldName?: string;
|
|
29
|
+
secretPreserveOnEmpty?: boolean;
|
|
30
|
+
secretStateFieldName?: string;
|
|
31
|
+
}): string;
|
|
32
|
+
/**
|
|
33
|
+
* Build the editable TypeScript type source for a manual REST contract.
|
|
34
|
+
*
|
|
35
|
+
* @param options Manual contract type naming metadata.
|
|
36
|
+
* @param options.bodyTypeName Optional exported body type name.
|
|
37
|
+
* @param options.pathParameterNames Route named captures that should be present
|
|
38
|
+
* in the starter query type so generated clients can fill provider paths.
|
|
39
|
+
* @param options.queryTypeName Exported query type name.
|
|
40
|
+
* @param options.responseTypeName Exported response type name.
|
|
41
|
+
* @param options.restResourceSlug Normalized workspace REST contract slug.
|
|
42
|
+
* @param options.secretFieldName Optional raw secret field included only in the request body.
|
|
43
|
+
* @param options.secretStateFieldName Optional masked response boolean field.
|
|
44
|
+
* @returns TypeScript source for `api-types.ts`.
|
|
45
|
+
*/
|
|
46
|
+
export declare function buildManualRestContractTypesSource(options: {
|
|
47
|
+
bodyTypeName?: string;
|
|
48
|
+
pathParameterNames?: string[];
|
|
49
|
+
queryTypeName: string;
|
|
50
|
+
responseTypeName: string;
|
|
51
|
+
restResourceSlug: string;
|
|
52
|
+
secretFieldName?: string;
|
|
53
|
+
secretPreserveOnEmpty?: boolean;
|
|
54
|
+
secretStateFieldName?: string;
|
|
55
|
+
}): string;
|
|
56
|
+
/**
|
|
57
|
+
* Build Typia validator source for a manual REST contract.
|
|
58
|
+
*
|
|
59
|
+
* @param options Manual contract type names to validate.
|
|
60
|
+
* @param options.bodyTypeName Optional exported body type name.
|
|
61
|
+
* @param options.queryTypeName Exported query type name.
|
|
62
|
+
* @param options.responseTypeName Exported response type name.
|
|
63
|
+
* @returns TypeScript source for `api-validators.ts`.
|
|
64
|
+
*/
|
|
65
|
+
export declare function buildManualRestContractValidatorsSource(options: {
|
|
66
|
+
bodyTypeName?: string;
|
|
67
|
+
queryTypeName: string;
|
|
68
|
+
responseTypeName: string;
|
|
69
|
+
}): string;
|
|
70
|
+
/**
|
|
71
|
+
* Build the public API shim for a manual REST contract.
|
|
72
|
+
*
|
|
73
|
+
* @param options Manual REST contract operation and request type metadata.
|
|
74
|
+
* @returns TypeScript source that re-exports the generated endpoint client.
|
|
75
|
+
*/
|
|
76
|
+
export declare function buildManualRestContractApiSource(options: {
|
|
77
|
+
bodyTypeName?: string;
|
|
78
|
+
queryTypeName: string;
|
|
79
|
+
restResourceSlug: string;
|
|
80
|
+
}): string;
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { quoteTsString, } from "./cli-add-shared.js";
|
|
2
|
+
import { formatResolveRestNonceSource, indentMultiline, } from "./cli-add-workspace-rest-source-utils.js";
|
|
3
|
+
import { buildManualRestContractEndpointManifest } from "./rest-resource-artifacts.js";
|
|
4
|
+
import { toPascalCase, toTitleCase } from "./string-case.js";
|
|
5
|
+
/**
|
|
6
|
+
* Build the `REST_RESOURCES` config entry appended for a manual REST contract.
|
|
7
|
+
*
|
|
8
|
+
* @param options Manual contract file, route, type, and auth metadata.
|
|
9
|
+
* @param options.auth Auth intent stored in the endpoint manifest.
|
|
10
|
+
* @param options.bodyTypeName Optional exported body type name.
|
|
11
|
+
* @param options.method Uppercase HTTP method for the external route.
|
|
12
|
+
* @param options.namespace REST namespace such as `vendor/v1`.
|
|
13
|
+
* @param options.pathPattern Route pattern relative to the namespace.
|
|
14
|
+
* @param options.queryTypeName Exported query type name.
|
|
15
|
+
* @param options.responseTypeName Exported response type name.
|
|
16
|
+
* @param options.restResourceSlug Normalized workspace REST contract slug.
|
|
17
|
+
* @returns A TypeScript object literal string for `scripts/block-config.ts`.
|
|
18
|
+
*/
|
|
19
|
+
export function buildManualRestContractConfigEntry(options) {
|
|
20
|
+
const pascalCase = toPascalCase(options.restResourceSlug);
|
|
21
|
+
const title = toTitleCase(options.restResourceSlug);
|
|
22
|
+
const manifest = buildManualRestContractEndpointManifest({
|
|
23
|
+
auth: options.auth,
|
|
24
|
+
...(options.bodyTypeName ? { bodyTypeName: options.bodyTypeName } : {}),
|
|
25
|
+
method: options.method,
|
|
26
|
+
namespace: options.namespace,
|
|
27
|
+
pascalCase,
|
|
28
|
+
pathPattern: options.pathPattern,
|
|
29
|
+
queryTypeName: options.queryTypeName,
|
|
30
|
+
responseTypeName: options.responseTypeName,
|
|
31
|
+
slugKebabCase: options.restResourceSlug,
|
|
32
|
+
title,
|
|
33
|
+
});
|
|
34
|
+
return [
|
|
35
|
+
"\t{",
|
|
36
|
+
`\t\tapiFile: ${quoteTsString(`src/rest/${options.restResourceSlug}/api.ts`)},`,
|
|
37
|
+
`\t\tauth: ${quoteTsString(options.auth)},`,
|
|
38
|
+
...(options.bodyTypeName
|
|
39
|
+
? [`\t\tbodyTypeName: ${quoteTsString(options.bodyTypeName)},`]
|
|
40
|
+
: []),
|
|
41
|
+
`\t\tclientFile: ${quoteTsString(`src/rest/${options.restResourceSlug}/api-client.ts`)},`,
|
|
42
|
+
...(options.controllerClass
|
|
43
|
+
? [`\t\tcontrollerClass: ${quoteTsString(options.controllerClass)},`]
|
|
44
|
+
: []),
|
|
45
|
+
...(options.controllerExtends
|
|
46
|
+
? [`\t\tcontrollerExtends: ${quoteTsString(options.controllerExtends)},`]
|
|
47
|
+
: []),
|
|
48
|
+
`\t\tmethod: ${quoteTsString(options.method)},`,
|
|
49
|
+
"\t\tmethods: [],",
|
|
50
|
+
"\t\tmode: 'manual',",
|
|
51
|
+
`\t\tnamespace: ${quoteTsString(options.namespace)},`,
|
|
52
|
+
`\t\topenApiFile: ${quoteTsString(`src/rest/${options.restResourceSlug}/api.openapi.json`)},`,
|
|
53
|
+
`\t\tpathPattern: ${quoteTsString(options.pathPattern)},`,
|
|
54
|
+
...(options.permissionCallback
|
|
55
|
+
? [`\t\tpermissionCallback: ${quoteTsString(options.permissionCallback)},`]
|
|
56
|
+
: []),
|
|
57
|
+
`\t\tqueryTypeName: ${quoteTsString(options.queryTypeName)},`,
|
|
58
|
+
"\t\trestManifest: defineEndpointManifest(",
|
|
59
|
+
indentMultiline(JSON.stringify(manifest, null, "\t"), "\t\t\t"),
|
|
60
|
+
"\t\t),",
|
|
61
|
+
`\t\tresponseTypeName: ${quoteTsString(options.responseTypeName)},`,
|
|
62
|
+
...(options.secretFieldName
|
|
63
|
+
? [`\t\tsecretFieldName: ${quoteTsString(options.secretFieldName)},`]
|
|
64
|
+
: []),
|
|
65
|
+
...(options.secretPreserveOnEmpty !== undefined
|
|
66
|
+
? [`\t\tsecretPreserveOnEmpty: ${options.secretPreserveOnEmpty},`]
|
|
67
|
+
: []),
|
|
68
|
+
...(options.secretStateFieldName
|
|
69
|
+
? [`\t\tsecretStateFieldName: ${quoteTsString(options.secretStateFieldName)},`]
|
|
70
|
+
: []),
|
|
71
|
+
`\t\tslug: ${quoteTsString(options.restResourceSlug)},`,
|
|
72
|
+
`\t\ttypesFile: ${quoteTsString(`src/rest/${options.restResourceSlug}/api-types.ts`)},`,
|
|
73
|
+
`\t\tvalidatorsFile: ${quoteTsString(`src/rest/${options.restResourceSlug}/api-validators.ts`)},`,
|
|
74
|
+
"\t},",
|
|
75
|
+
].join("\n");
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Build the editable TypeScript type source for a manual REST contract.
|
|
79
|
+
*
|
|
80
|
+
* @param options Manual contract type naming metadata.
|
|
81
|
+
* @param options.bodyTypeName Optional exported body type name.
|
|
82
|
+
* @param options.pathParameterNames Route named captures that should be present
|
|
83
|
+
* in the starter query type so generated clients can fill provider paths.
|
|
84
|
+
* @param options.queryTypeName Exported query type name.
|
|
85
|
+
* @param options.responseTypeName Exported response type name.
|
|
86
|
+
* @param options.restResourceSlug Normalized workspace REST contract slug.
|
|
87
|
+
* @param options.secretFieldName Optional raw secret field included only in the request body.
|
|
88
|
+
* @param options.secretStateFieldName Optional masked response boolean field.
|
|
89
|
+
* @returns TypeScript source for `api-types.ts`.
|
|
90
|
+
*/
|
|
91
|
+
export function buildManualRestContractTypesSource(options) {
|
|
92
|
+
const title = toTitleCase(options.restResourceSlug);
|
|
93
|
+
const pathParameterNames = Array.from(new Set(options.pathParameterNames ?? []));
|
|
94
|
+
const queryFields = pathParameterNames.length > 0
|
|
95
|
+
? pathParameterNames.map((parameterName) => `\t${parameterName}: string & tags.MinLength< 1 >;`)
|
|
96
|
+
: ["\tid?: string & tags.MinLength< 1 >;"];
|
|
97
|
+
const lines = [
|
|
98
|
+
"import type { tags } from '@wp-typia/block-runtime/typia-tags';",
|
|
99
|
+
"",
|
|
100
|
+
`export interface ${options.queryTypeName} {`,
|
|
101
|
+
...queryFields,
|
|
102
|
+
...(pathParameterNames.includes("preview") ? [] : ["\tpreview?: boolean;"]),
|
|
103
|
+
"}",
|
|
104
|
+
];
|
|
105
|
+
if (options.bodyTypeName) {
|
|
106
|
+
const secretPreserveOnEmpty = options.secretPreserveOnEmpty ?? true;
|
|
107
|
+
const secretLines = options.secretFieldName && options.secretStateFieldName
|
|
108
|
+
? [
|
|
109
|
+
`\t${options.secretFieldName}?: string${secretPreserveOnEmpty ? " & tags.MinLength< 1 >" : ""} & tags.MaxLength< 4096 > & tags.Secret< ${quoteTsString(options.secretStateFieldName)} >${secretPreserveOnEmpty ? " & tags.PreserveOnEmpty< true >" : ""};`,
|
|
110
|
+
secretPreserveOnEmpty
|
|
111
|
+
? `\t// ${options.secretFieldName} is write-only: omit or submit an empty value to preserve the stored secret, and expose ${options.secretStateFieldName} in responses instead of returning the raw value.`
|
|
112
|
+
: `\t// ${options.secretFieldName} is write-only: persist it server-side and expose ${options.secretStateFieldName} in responses instead of returning the raw value.`,
|
|
113
|
+
]
|
|
114
|
+
: [];
|
|
115
|
+
lines.push("", `export interface ${options.bodyTypeName} {`, ...secretLines, "\tpayload: string & tags.MinLength< 1 >;", "\tcomment?: string & tags.MaxLength< 500 >;", "}");
|
|
116
|
+
}
|
|
117
|
+
lines.push("", `export interface ${options.responseTypeName} {`, ...(options.secretStateFieldName
|
|
118
|
+
? [
|
|
119
|
+
`\t${options.secretStateFieldName}: boolean;`,
|
|
120
|
+
`\t// Raw secret fields such as ${options.secretFieldName ?? "the request secret"} must never be returned in this response.`,
|
|
121
|
+
]
|
|
122
|
+
: []), "\tid: string & tags.MinLength< 1 >;", "\tstatus: 'ok' | 'error';", "\tmessage?: string;", "\tupdatedAt?: string;", "}", "", `// ${title} is a manual REST contract: edit these types to match the external route owner.`);
|
|
123
|
+
return `${lines.join("\n")}\n`;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Build Typia validator source for a manual REST contract.
|
|
127
|
+
*
|
|
128
|
+
* @param options Manual contract type names to validate.
|
|
129
|
+
* @param options.bodyTypeName Optional exported body type name.
|
|
130
|
+
* @param options.queryTypeName Exported query type name.
|
|
131
|
+
* @param options.responseTypeName Exported response type name.
|
|
132
|
+
* @returns TypeScript source for `api-validators.ts`.
|
|
133
|
+
*/
|
|
134
|
+
export function buildManualRestContractValidatorsSource(options) {
|
|
135
|
+
const importedTypes = [
|
|
136
|
+
options.queryTypeName,
|
|
137
|
+
...(options.bodyTypeName ? [options.bodyTypeName] : []),
|
|
138
|
+
options.responseTypeName,
|
|
139
|
+
].sort();
|
|
140
|
+
const validatorDeclarations = [
|
|
141
|
+
`const validateQuery = typia.createValidate< ${options.queryTypeName} >();`,
|
|
142
|
+
...(options.bodyTypeName
|
|
143
|
+
? [`const validateRequest = typia.createValidate< ${options.bodyTypeName} >();`]
|
|
144
|
+
: []),
|
|
145
|
+
`const validateResponse = typia.createValidate< ${options.responseTypeName} >();`,
|
|
146
|
+
];
|
|
147
|
+
const validatorEntries = [
|
|
148
|
+
`\tquery: ( input: unknown ) => toValidationResult< ${options.queryTypeName} >( validateQuery( input ) ),`,
|
|
149
|
+
...(options.bodyTypeName
|
|
150
|
+
? [
|
|
151
|
+
`\trequest: ( input: unknown ) => toValidationResult< ${options.bodyTypeName} >( validateRequest( input ) ),`,
|
|
152
|
+
]
|
|
153
|
+
: []),
|
|
154
|
+
`\tresponse: ( input: unknown ) => toValidationResult< ${options.responseTypeName} >( validateResponse( input ) ),`,
|
|
155
|
+
];
|
|
156
|
+
return `import typia from 'typia';
|
|
157
|
+
|
|
158
|
+
import { toValidationResult } from '@wp-typia/rest';
|
|
159
|
+
import type {
|
|
160
|
+
\t${importedTypes.join(",\n\t")},
|
|
161
|
+
} from './api-types';
|
|
162
|
+
|
|
163
|
+
${validatorDeclarations.join("\n")}
|
|
164
|
+
|
|
165
|
+
export const apiValidators = {
|
|
166
|
+
${validatorEntries.join("\n")}
|
|
167
|
+
};
|
|
168
|
+
`;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Build the public API shim for a manual REST contract.
|
|
172
|
+
*
|
|
173
|
+
* @param options Manual REST contract operation and request type metadata.
|
|
174
|
+
* @returns TypeScript source that re-exports the generated endpoint client.
|
|
175
|
+
*/
|
|
176
|
+
export function buildManualRestContractApiSource(options) {
|
|
177
|
+
const pascalCase = toPascalCase(options.restResourceSlug);
|
|
178
|
+
const operationId = `call${pascalCase}ManualRestContract`;
|
|
179
|
+
const requestTypeName = options.bodyTypeName
|
|
180
|
+
? `${pascalCase}ManualRestContractRequest`
|
|
181
|
+
: options.queryTypeName;
|
|
182
|
+
const requestTypeSource = options.bodyTypeName
|
|
183
|
+
? `export interface ${requestTypeName} {
|
|
184
|
+
\tbody: ${options.bodyTypeName};
|
|
185
|
+
\tquery: ${options.queryTypeName};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
`
|
|
189
|
+
: "";
|
|
190
|
+
const typeImports = options.bodyTypeName
|
|
191
|
+
? [options.bodyTypeName, options.queryTypeName]
|
|
192
|
+
: [options.queryTypeName];
|
|
193
|
+
return `import {
|
|
194
|
+
\tcallEndpoint,
|
|
195
|
+
\tresolveRestRouteUrl,
|
|
196
|
+
} from '@wp-typia/rest';
|
|
197
|
+
|
|
198
|
+
import type {
|
|
199
|
+
\t${typeImports.sort().join(",\n\t")},
|
|
200
|
+
} from './api-types';
|
|
201
|
+
import { ${operationId}Endpoint } from './api-client';
|
|
202
|
+
|
|
203
|
+
export * from './api-client';
|
|
204
|
+
|
|
205
|
+
${requestTypeSource}${formatResolveRestNonceSource("compact")}
|
|
206
|
+
|
|
207
|
+
function resolveEndpointRouteOptions(request: ${requestTypeName}) {
|
|
208
|
+
\tconst requestOptions = ${operationId}Endpoint.buildRequestOptions?.(request) ?? {};
|
|
209
|
+
\tconst nonce = resolveRestNonce();
|
|
210
|
+
\tconst requestHeaders = (
|
|
211
|
+
\t\trequestOptions as { headers?: Record<string, string> }
|
|
212
|
+
\t).headers;
|
|
213
|
+
|
|
214
|
+
\treturn {
|
|
215
|
+
\t\t...requestOptions,
|
|
216
|
+
\t\theaders: nonce
|
|
217
|
+
\t\t\t? {
|
|
218
|
+
\t\t\t\t\t...(requestHeaders ?? {}),
|
|
219
|
+
\t\t\t\t\t'X-WP-Nonce': nonce,
|
|
220
|
+
\t\t\t\t}
|
|
221
|
+
\t\t\t: requestHeaders,
|
|
222
|
+
\t\tpath: undefined,
|
|
223
|
+
\t\turl:
|
|
224
|
+
\t\t\trequestOptions.url ??
|
|
225
|
+
\t\t\tresolveRestRouteUrl(requestOptions.path ?? ${operationId}Endpoint.path),
|
|
226
|
+
\t};
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export const manualRestContractEndpoint = {
|
|
230
|
+
\t...${operationId}Endpoint,
|
|
231
|
+
\tbuildRequestOptions: resolveEndpointRouteOptions,
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
export function callManualRestContract(request: ${requestTypeName}) {
|
|
235
|
+
\treturn callEndpoint(manualRestContractEndpoint, request);
|
|
236
|
+
}
|
|
237
|
+
`;
|
|
238
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type ManualRestContractScaffoldOptions, type RunAddRestResourceCommandResult } from "./cli-add-workspace-rest-types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Scaffold a type-only external REST contract for workspace consumers.
|
|
4
|
+
*
|
|
5
|
+
* @param options Resolved workspace and raw manual-mode command options.
|
|
6
|
+
* @returns Resolved scaffold metadata for the manual REST contract.
|
|
7
|
+
*/
|
|
8
|
+
export declare function scaffoldManualRestContract({ auth, bodyTypeName, controllerClass, controllerExtends, method, namespace, pathPattern, permissionCallback, queryTypeName, responseTypeName, restResourceSlug, routePattern, secretFieldName, secretHasValueFieldName, secretMaskedResponseFieldName, secretPreserveOnEmpty, secretStateFieldName, workspace, }: ManualRestContractScaffoldOptions): Promise<RunAddRestResourceCommandResult>;
|