@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
|
@@ -1,645 +1,8 @@
|
|
|
1
|
-
import { quoteTsString, } from "./cli-add-shared.js";
|
|
2
|
-
import { buildManualRestContractEndpointManifest, buildRestResourceEndpointManifest, } from "./rest-resource-artifacts.js";
|
|
3
|
-
import { toPascalCase, toTitleCase } from "./string-case.js";
|
|
4
|
-
function indentMultiline(source, prefix) {
|
|
5
|
-
return source
|
|
6
|
-
.split("\n")
|
|
7
|
-
.map((line) => `${prefix}${line}`)
|
|
8
|
-
.join("\n");
|
|
9
|
-
}
|
|
10
1
|
/**
|
|
11
|
-
*
|
|
2
|
+
* Compatibility facade for REST workspace source emitters.
|
|
12
3
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* `permissionCallback`, and `routePattern` opt into generated controller,
|
|
16
|
-
* permission, and item-route escape hatches.
|
|
17
|
-
* @returns TypeScript object literal source for one generated REST resource entry.
|
|
4
|
+
* Keep the public runtime import path stable while generated-resource and
|
|
5
|
+
* manual-contract emitters live in focused modules.
|
|
18
6
|
*/
|
|
19
|
-
export
|
|
20
|
-
|
|
21
|
-
const title = toTitleCase(options.restResourceSlug);
|
|
22
|
-
const manifest = buildRestResourceEndpointManifest({
|
|
23
|
-
namespace: options.namespace,
|
|
24
|
-
pascalCase,
|
|
25
|
-
...(options.routePattern ? { routePattern: options.routePattern } : {}),
|
|
26
|
-
slugKebabCase: options.restResourceSlug,
|
|
27
|
-
title,
|
|
28
|
-
}, options.methods);
|
|
29
|
-
return [
|
|
30
|
-
"\t{",
|
|
31
|
-
`\t\tapiFile: ${quoteTsString(`src/rest/${options.restResourceSlug}/api.ts`)},`,
|
|
32
|
-
...(options.controllerClass
|
|
33
|
-
? [`\t\tcontrollerClass: ${quoteTsString(options.controllerClass)},`]
|
|
34
|
-
: []),
|
|
35
|
-
...(options.controllerExtends
|
|
36
|
-
? [`\t\tcontrollerExtends: ${quoteTsString(options.controllerExtends)},`]
|
|
37
|
-
: []),
|
|
38
|
-
`\t\tclientFile: ${quoteTsString(`src/rest/${options.restResourceSlug}/api-client.ts`)},`,
|
|
39
|
-
`\t\tdataFile: ${quoteTsString(`src/rest/${options.restResourceSlug}/data.ts`)},`,
|
|
40
|
-
`\t\tmethods: [ ${options.methods.map((method) => quoteTsString(method)).join(", ")} ],`,
|
|
41
|
-
`\t\tnamespace: ${quoteTsString(options.namespace)},`,
|
|
42
|
-
`\t\topenApiFile: ${quoteTsString(`src/rest/${options.restResourceSlug}/api.openapi.json`)},`,
|
|
43
|
-
...(options.permissionCallback
|
|
44
|
-
? [`\t\tpermissionCallback: ${quoteTsString(options.permissionCallback)},`]
|
|
45
|
-
: []),
|
|
46
|
-
`\t\tphpFile: ${quoteTsString(`inc/rest/${options.restResourceSlug}.php`)},`,
|
|
47
|
-
"\t\trestManifest: defineEndpointManifest(",
|
|
48
|
-
indentMultiline(JSON.stringify(manifest, null, "\t"), "\t\t\t"),
|
|
49
|
-
"\t\t),",
|
|
50
|
-
...(options.routePattern
|
|
51
|
-
? [`\t\troutePattern: ${quoteTsString(options.routePattern)},`]
|
|
52
|
-
: []),
|
|
53
|
-
`\t\tslug: ${quoteTsString(options.restResourceSlug)},`,
|
|
54
|
-
`\t\ttypesFile: ${quoteTsString(`src/rest/${options.restResourceSlug}/api-types.ts`)},`,
|
|
55
|
-
`\t\tvalidatorsFile: ${quoteTsString(`src/rest/${options.restResourceSlug}/api-validators.ts`)},`,
|
|
56
|
-
"\t},",
|
|
57
|
-
].join("\n");
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Build the `REST_RESOURCES` config entry appended for a manual REST contract.
|
|
61
|
-
*
|
|
62
|
-
* @param options Manual contract file, route, type, and auth metadata.
|
|
63
|
-
* @param options.auth Auth intent stored in the endpoint manifest.
|
|
64
|
-
* @param options.bodyTypeName Optional exported body type name.
|
|
65
|
-
* @param options.method Uppercase HTTP method for the external route.
|
|
66
|
-
* @param options.namespace REST namespace such as `vendor/v1`.
|
|
67
|
-
* @param options.pathPattern Route pattern relative to the namespace.
|
|
68
|
-
* @param options.queryTypeName Exported query type name.
|
|
69
|
-
* @param options.responseTypeName Exported response type name.
|
|
70
|
-
* @param options.restResourceSlug Normalized workspace REST contract slug.
|
|
71
|
-
* @returns A TypeScript object literal string for `scripts/block-config.ts`.
|
|
72
|
-
*/
|
|
73
|
-
export function buildManualRestContractConfigEntry(options) {
|
|
74
|
-
const pascalCase = toPascalCase(options.restResourceSlug);
|
|
75
|
-
const title = toTitleCase(options.restResourceSlug);
|
|
76
|
-
const manifest = buildManualRestContractEndpointManifest({
|
|
77
|
-
auth: options.auth,
|
|
78
|
-
...(options.bodyTypeName ? { bodyTypeName: options.bodyTypeName } : {}),
|
|
79
|
-
method: options.method,
|
|
80
|
-
namespace: options.namespace,
|
|
81
|
-
pascalCase,
|
|
82
|
-
pathPattern: options.pathPattern,
|
|
83
|
-
queryTypeName: options.queryTypeName,
|
|
84
|
-
responseTypeName: options.responseTypeName,
|
|
85
|
-
slugKebabCase: options.restResourceSlug,
|
|
86
|
-
title,
|
|
87
|
-
});
|
|
88
|
-
return [
|
|
89
|
-
"\t{",
|
|
90
|
-
`\t\tapiFile: ${quoteTsString(`src/rest/${options.restResourceSlug}/api.ts`)},`,
|
|
91
|
-
`\t\tauth: ${quoteTsString(options.auth)},`,
|
|
92
|
-
...(options.bodyTypeName
|
|
93
|
-
? [`\t\tbodyTypeName: ${quoteTsString(options.bodyTypeName)},`]
|
|
94
|
-
: []),
|
|
95
|
-
`\t\tclientFile: ${quoteTsString(`src/rest/${options.restResourceSlug}/api-client.ts`)},`,
|
|
96
|
-
`\t\tmethod: ${quoteTsString(options.method)},`,
|
|
97
|
-
"\t\tmethods: [],",
|
|
98
|
-
"\t\tmode: 'manual',",
|
|
99
|
-
`\t\tnamespace: ${quoteTsString(options.namespace)},`,
|
|
100
|
-
`\t\topenApiFile: ${quoteTsString(`src/rest/${options.restResourceSlug}/api.openapi.json`)},`,
|
|
101
|
-
`\t\tpathPattern: ${quoteTsString(options.pathPattern)},`,
|
|
102
|
-
`\t\tqueryTypeName: ${quoteTsString(options.queryTypeName)},`,
|
|
103
|
-
"\t\trestManifest: defineEndpointManifest(",
|
|
104
|
-
indentMultiline(JSON.stringify(manifest, null, "\t"), "\t\t\t"),
|
|
105
|
-
"\t\t),",
|
|
106
|
-
`\t\tresponseTypeName: ${quoteTsString(options.responseTypeName)},`,
|
|
107
|
-
...(options.secretFieldName
|
|
108
|
-
? [`\t\tsecretFieldName: ${quoteTsString(options.secretFieldName)},`]
|
|
109
|
-
: []),
|
|
110
|
-
...(options.secretStateFieldName
|
|
111
|
-
? [`\t\tsecretStateFieldName: ${quoteTsString(options.secretStateFieldName)},`]
|
|
112
|
-
: []),
|
|
113
|
-
`\t\tslug: ${quoteTsString(options.restResourceSlug)},`,
|
|
114
|
-
`\t\ttypesFile: ${quoteTsString(`src/rest/${options.restResourceSlug}/api-types.ts`)},`,
|
|
115
|
-
`\t\tvalidatorsFile: ${quoteTsString(`src/rest/${options.restResourceSlug}/api-validators.ts`)},`,
|
|
116
|
-
"\t},",
|
|
117
|
-
].join("\n");
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Build the editable TypeScript type source for a manual REST contract.
|
|
121
|
-
*
|
|
122
|
-
* @param options Manual contract type naming metadata.
|
|
123
|
-
* @param options.bodyTypeName Optional exported body type name.
|
|
124
|
-
* @param options.queryTypeName Exported query type name.
|
|
125
|
-
* @param options.responseTypeName Exported response type name.
|
|
126
|
-
* @param options.restResourceSlug Normalized workspace REST contract slug.
|
|
127
|
-
* @param options.secretFieldName Optional raw secret field included only in the request body.
|
|
128
|
-
* @param options.secretStateFieldName Optional masked response boolean field.
|
|
129
|
-
* @returns TypeScript source for `api-types.ts`.
|
|
130
|
-
*/
|
|
131
|
-
export function buildManualRestContractTypesSource(options) {
|
|
132
|
-
const title = toTitleCase(options.restResourceSlug);
|
|
133
|
-
const lines = [
|
|
134
|
-
"import type { tags } from '@wp-typia/block-runtime/typia-tags';",
|
|
135
|
-
"",
|
|
136
|
-
`export interface ${options.queryTypeName} {`,
|
|
137
|
-
"\tid?: string & tags.MinLength< 1 >;",
|
|
138
|
-
"\tpreview?: boolean;",
|
|
139
|
-
"}",
|
|
140
|
-
];
|
|
141
|
-
if (options.bodyTypeName) {
|
|
142
|
-
const secretLines = options.secretFieldName && options.secretStateFieldName
|
|
143
|
-
? [
|
|
144
|
-
`\t${options.secretFieldName}?: string & tags.MinLength< 1 > & tags.MaxLength< 4096 > & tags.Secret< ${quoteTsString(options.secretStateFieldName)} >;`,
|
|
145
|
-
`\t// ${options.secretFieldName} is write-only: persist it server-side and expose ${options.secretStateFieldName} in responses instead of returning the raw value.`,
|
|
146
|
-
]
|
|
147
|
-
: [];
|
|
148
|
-
lines.push("", `export interface ${options.bodyTypeName} {`, ...secretLines, "\tpayload: string & tags.MinLength< 1 >;", "\tcomment?: string & tags.MaxLength< 500 >;", "}");
|
|
149
|
-
}
|
|
150
|
-
lines.push("", `export interface ${options.responseTypeName} {`, ...(options.secretStateFieldName
|
|
151
|
-
? [
|
|
152
|
-
`\t${options.secretStateFieldName}: boolean;`,
|
|
153
|
-
`\t// Raw secret fields such as ${options.secretFieldName ?? "the request secret"} must never be returned in this response.`,
|
|
154
|
-
]
|
|
155
|
-
: []), "\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.`);
|
|
156
|
-
return `${lines.join("\n")}\n`;
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Build Typia validator source for a manual REST contract.
|
|
160
|
-
*
|
|
161
|
-
* @param options Manual contract type names to validate.
|
|
162
|
-
* @param options.bodyTypeName Optional exported body type name.
|
|
163
|
-
* @param options.queryTypeName Exported query type name.
|
|
164
|
-
* @param options.responseTypeName Exported response type name.
|
|
165
|
-
* @returns TypeScript source for `api-validators.ts`.
|
|
166
|
-
*/
|
|
167
|
-
export function buildManualRestContractValidatorsSource(options) {
|
|
168
|
-
const importedTypes = [
|
|
169
|
-
options.queryTypeName,
|
|
170
|
-
...(options.bodyTypeName ? [options.bodyTypeName] : []),
|
|
171
|
-
options.responseTypeName,
|
|
172
|
-
].sort();
|
|
173
|
-
const validatorDeclarations = [
|
|
174
|
-
`const validateQuery = typia.createValidate< ${options.queryTypeName} >();`,
|
|
175
|
-
...(options.bodyTypeName
|
|
176
|
-
? [`const validateRequest = typia.createValidate< ${options.bodyTypeName} >();`]
|
|
177
|
-
: []),
|
|
178
|
-
`const validateResponse = typia.createValidate< ${options.responseTypeName} >();`,
|
|
179
|
-
];
|
|
180
|
-
const validatorEntries = [
|
|
181
|
-
`\tquery: ( input: unknown ) => toValidationResult< ${options.queryTypeName} >( validateQuery( input ) ),`,
|
|
182
|
-
...(options.bodyTypeName
|
|
183
|
-
? [
|
|
184
|
-
`\trequest: ( input: unknown ) => toValidationResult< ${options.bodyTypeName} >( validateRequest( input ) ),`,
|
|
185
|
-
]
|
|
186
|
-
: []),
|
|
187
|
-
`\tresponse: ( input: unknown ) => toValidationResult< ${options.responseTypeName} >( validateResponse( input ) ),`,
|
|
188
|
-
];
|
|
189
|
-
return `import typia from 'typia';
|
|
190
|
-
|
|
191
|
-
import { toValidationResult } from '@wp-typia/rest';
|
|
192
|
-
import type {
|
|
193
|
-
\t${importedTypes.join(",\n\t")},
|
|
194
|
-
} from './api-types';
|
|
195
|
-
|
|
196
|
-
${validatorDeclarations.join("\n")}
|
|
197
|
-
|
|
198
|
-
export const apiValidators = {
|
|
199
|
-
${validatorEntries.join("\n")}
|
|
200
|
-
};
|
|
201
|
-
`;
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Build the public API shim for a manual REST contract.
|
|
205
|
-
*
|
|
206
|
-
* @param options Manual REST contract operation and request type metadata.
|
|
207
|
-
* @returns TypeScript source that re-exports the generated endpoint client.
|
|
208
|
-
*/
|
|
209
|
-
export function buildManualRestContractApiSource(options) {
|
|
210
|
-
const pascalCase = toPascalCase(options.restResourceSlug);
|
|
211
|
-
const operationId = `call${pascalCase}ManualRestContract`;
|
|
212
|
-
const requestTypeName = options.bodyTypeName
|
|
213
|
-
? `${pascalCase}ManualRestContractRequest`
|
|
214
|
-
: options.queryTypeName;
|
|
215
|
-
const requestTypeSource = options.bodyTypeName
|
|
216
|
-
? `export interface ${requestTypeName} {
|
|
217
|
-
\tbody: ${options.bodyTypeName};
|
|
218
|
-
\tquery: ${options.queryTypeName};
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
`
|
|
222
|
-
: "";
|
|
223
|
-
const typeImports = options.bodyTypeName
|
|
224
|
-
? [options.bodyTypeName, options.queryTypeName]
|
|
225
|
-
: [options.queryTypeName];
|
|
226
|
-
return `import {
|
|
227
|
-
\tcallEndpoint,
|
|
228
|
-
\tresolveRestRouteUrl,
|
|
229
|
-
} from '@wp-typia/rest';
|
|
230
|
-
|
|
231
|
-
import type {
|
|
232
|
-
\t${typeImports.sort().join(",\n\t")},
|
|
233
|
-
} from './api-types';
|
|
234
|
-
import { ${operationId}Endpoint } from './api-client';
|
|
235
|
-
|
|
236
|
-
export * from './api-client';
|
|
237
|
-
|
|
238
|
-
${requestTypeSource}function resolveRestNonce(fallback?: string): string | undefined {
|
|
239
|
-
\tif (typeof fallback === 'string' && fallback.length > 0) {
|
|
240
|
-
\t\treturn fallback;
|
|
241
|
-
\t}
|
|
242
|
-
|
|
243
|
-
\tif (typeof window === 'undefined') {
|
|
244
|
-
\t\treturn undefined;
|
|
245
|
-
\t}
|
|
246
|
-
|
|
247
|
-
\tconst wpApiSettings = (
|
|
248
|
-
\t\twindow as typeof window & {
|
|
249
|
-
\t\t\twpApiSettings?: { nonce?: string };
|
|
250
|
-
\t\t}
|
|
251
|
-
\t).wpApiSettings;
|
|
252
|
-
|
|
253
|
-
\treturn typeof wpApiSettings?.nonce === 'string' &&
|
|
254
|
-
\t\twpApiSettings.nonce.length > 0
|
|
255
|
-
\t\t? wpApiSettings.nonce
|
|
256
|
-
\t\t: undefined;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
function resolveEndpointRouteOptions(request: ${requestTypeName}) {
|
|
260
|
-
\tconst requestOptions = ${operationId}Endpoint.buildRequestOptions?.(request) ?? {};
|
|
261
|
-
\tconst nonce = resolveRestNonce();
|
|
262
|
-
\tconst requestHeaders = (
|
|
263
|
-
\t\trequestOptions as { headers?: Record<string, string> }
|
|
264
|
-
\t).headers;
|
|
265
|
-
|
|
266
|
-
\treturn {
|
|
267
|
-
\t\t...requestOptions,
|
|
268
|
-
\t\theaders: nonce
|
|
269
|
-
\t\t\t? {
|
|
270
|
-
\t\t\t\t\t...(requestHeaders ?? {}),
|
|
271
|
-
\t\t\t\t\t'X-WP-Nonce': nonce,
|
|
272
|
-
\t\t\t\t}
|
|
273
|
-
\t\t\t: requestHeaders,
|
|
274
|
-
\t\tpath: undefined,
|
|
275
|
-
\t\turl:
|
|
276
|
-
\t\t\trequestOptions.url ??
|
|
277
|
-
\t\t\tresolveRestRouteUrl(requestOptions.path ?? ${operationId}Endpoint.path),
|
|
278
|
-
\t};
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
export const manualRestContractEndpoint = {
|
|
282
|
-
\t...${operationId}Endpoint,
|
|
283
|
-
\tbuildRequestOptions: resolveEndpointRouteOptions,
|
|
284
|
-
};
|
|
285
|
-
|
|
286
|
-
export function callManualRestContract(request: ${requestTypeName}) {
|
|
287
|
-
\treturn callEndpoint(manualRestContractEndpoint, request);
|
|
288
|
-
}
|
|
289
|
-
`;
|
|
290
|
-
}
|
|
291
|
-
export function buildRestResourceTypesSource(restResourceSlug, methods) {
|
|
292
|
-
const pascalCase = toPascalCase(restResourceSlug);
|
|
293
|
-
const lines = [
|
|
294
|
-
"import { tags } from 'typia';",
|
|
295
|
-
"",
|
|
296
|
-
`export type ${pascalCase}Status = 'draft' | 'published';`,
|
|
297
|
-
"",
|
|
298
|
-
`export interface ${pascalCase}Record {`,
|
|
299
|
-
"\tid: number & tags.Type< 'uint32' >;",
|
|
300
|
-
"\ttitle: string & tags.MinLength< 1 > & tags.MaxLength< 120 >;",
|
|
301
|
-
"\tcontent?: string & tags.MaxLength< 2000 >;",
|
|
302
|
-
`\tstatus: ${pascalCase}Status;`,
|
|
303
|
-
"\tupdatedAt: string;",
|
|
304
|
-
"}",
|
|
305
|
-
];
|
|
306
|
-
if (methods.includes("list")) {
|
|
307
|
-
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' >;", "}");
|
|
308
|
-
}
|
|
309
|
-
if (methods.includes("read")) {
|
|
310
|
-
lines.push("", `export interface ${pascalCase}ReadQuery {`, "\tid: number & tags.Type< 'uint32' >;", "}", "", `export type ${pascalCase}ReadResponse = ${pascalCase}Record;`);
|
|
311
|
-
}
|
|
312
|
-
if (methods.includes("create")) {
|
|
313
|
-
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;`);
|
|
314
|
-
}
|
|
315
|
-
if (methods.includes("update")) {
|
|
316
|
-
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;`);
|
|
317
|
-
}
|
|
318
|
-
if (methods.includes("delete")) {
|
|
319
|
-
lines.push("", `export interface ${pascalCase}DeleteQuery {`, "\tid: number & tags.Type< 'uint32' >;", "}", "", `export interface ${pascalCase}DeleteResponse {`, "\tdeleted: true;", "\tid: number & tags.Type< 'uint32' >;", "}");
|
|
320
|
-
}
|
|
321
|
-
return `${lines.join("\n")}\n`;
|
|
322
|
-
}
|
|
323
|
-
export function buildRestResourceValidatorsSource(restResourceSlug, methods) {
|
|
324
|
-
const pascalCase = toPascalCase(restResourceSlug);
|
|
325
|
-
const importedTypes = new Set();
|
|
326
|
-
const validatorDeclarations = [];
|
|
327
|
-
const validatorEntries = [];
|
|
328
|
-
const addValidator = (propertyName, typeName, validateIdentifier) => {
|
|
329
|
-
importedTypes.add(typeName);
|
|
330
|
-
validatorDeclarations.push(`const ${validateIdentifier} = typia.createValidate< ${typeName} >();`);
|
|
331
|
-
validatorEntries.push(`\t${propertyName}: ( input: unknown ) => toValidationResult< ${typeName} >( ${validateIdentifier}( input ) ),`);
|
|
332
|
-
};
|
|
333
|
-
if (methods.includes("list")) {
|
|
334
|
-
addValidator("listQuery", `${pascalCase}ListQuery`, "validateListQuery");
|
|
335
|
-
addValidator("listResponse", `${pascalCase}ListResponse`, "validateListResponse");
|
|
336
|
-
}
|
|
337
|
-
if (methods.includes("read")) {
|
|
338
|
-
addValidator("readQuery", `${pascalCase}ReadQuery`, "validateReadQuery");
|
|
339
|
-
addValidator("readResponse", `${pascalCase}ReadResponse`, "validateReadResponse");
|
|
340
|
-
}
|
|
341
|
-
if (methods.includes("create")) {
|
|
342
|
-
addValidator("createRequest", `${pascalCase}CreateRequest`, "validateCreateRequest");
|
|
343
|
-
addValidator("createResponse", `${pascalCase}CreateResponse`, "validateCreateResponse");
|
|
344
|
-
}
|
|
345
|
-
if (methods.includes("update")) {
|
|
346
|
-
addValidator("updateQuery", `${pascalCase}UpdateQuery`, "validateUpdateQuery");
|
|
347
|
-
addValidator("updateRequest", `${pascalCase}UpdateRequest`, "validateUpdateRequest");
|
|
348
|
-
addValidator("updateResponse", `${pascalCase}UpdateResponse`, "validateUpdateResponse");
|
|
349
|
-
}
|
|
350
|
-
if (methods.includes("delete")) {
|
|
351
|
-
addValidator("deleteQuery", `${pascalCase}DeleteQuery`, "validateDeleteQuery");
|
|
352
|
-
addValidator("deleteResponse", `${pascalCase}DeleteResponse`, "validateDeleteResponse");
|
|
353
|
-
}
|
|
354
|
-
return `import typia from 'typia';
|
|
355
|
-
|
|
356
|
-
import { toValidationResult } from '@wp-typia/rest';
|
|
357
|
-
import type {
|
|
358
|
-
\t${Array.from(importedTypes).sort().join(",\n\t")},
|
|
359
|
-
} from './api-types';
|
|
360
|
-
|
|
361
|
-
${validatorDeclarations.join("\n")}
|
|
362
|
-
|
|
363
|
-
export const apiValidators = {
|
|
364
|
-
${validatorEntries.join("\n")}
|
|
365
|
-
};
|
|
366
|
-
`;
|
|
367
|
-
}
|
|
368
|
-
export function buildRestResourceApiSource(restResourceSlug, methods) {
|
|
369
|
-
const pascalCase = toPascalCase(restResourceSlug);
|
|
370
|
-
const typeImports = new Set();
|
|
371
|
-
const clientEndpointImports = [];
|
|
372
|
-
const exportedBindings = [];
|
|
373
|
-
const writeMethods = methods.filter((method) => ["create", "update", "delete"].includes(method));
|
|
374
|
-
if (methods.includes("list")) {
|
|
375
|
-
typeImports.add(`${pascalCase}ListQuery`);
|
|
376
|
-
clientEndpointImports.push(`list${pascalCase}ResourcesEndpoint`);
|
|
377
|
-
exportedBindings.push(`export const restResourceListEndpoint = {
|
|
378
|
-
\t...list${pascalCase}ResourcesEndpoint,
|
|
379
|
-
\tbuildRequestOptions: ( request: ${pascalCase}ListQuery ) =>
|
|
380
|
-
\t\tresolveEndpointRouteOptions( list${pascalCase}ResourcesEndpoint, request ),
|
|
381
|
-
};
|
|
382
|
-
|
|
383
|
-
export function listResource( request: ${pascalCase}ListQuery ) {
|
|
384
|
-
\treturn callEndpoint( restResourceListEndpoint, request );
|
|
385
|
-
}`);
|
|
386
|
-
}
|
|
387
|
-
if (methods.includes("read")) {
|
|
388
|
-
typeImports.add(`${pascalCase}ReadQuery`);
|
|
389
|
-
clientEndpointImports.push(`read${pascalCase}ResourceEndpoint`);
|
|
390
|
-
exportedBindings.push(`export const restResourceReadEndpoint = {
|
|
391
|
-
\t...read${pascalCase}ResourceEndpoint,
|
|
392
|
-
\tbuildRequestOptions: ( request: ${pascalCase}ReadQuery ) =>
|
|
393
|
-
\t\tresolveEndpointRouteOptions( read${pascalCase}ResourceEndpoint, request ),
|
|
394
|
-
};
|
|
395
|
-
|
|
396
|
-
export function readResource( request: ${pascalCase}ReadQuery ) {
|
|
397
|
-
\treturn callEndpoint( restResourceReadEndpoint, request );
|
|
398
|
-
}`);
|
|
399
|
-
}
|
|
400
|
-
if (methods.includes("create")) {
|
|
401
|
-
typeImports.add(`${pascalCase}CreateRequest`);
|
|
402
|
-
clientEndpointImports.push(`create${pascalCase}ResourceEndpoint`);
|
|
403
|
-
exportedBindings.push(`export const restResourceCreateEndpoint = {
|
|
404
|
-
\t...create${pascalCase}ResourceEndpoint,
|
|
405
|
-
\tbuildRequestOptions: ( request: ${pascalCase}CreateRequest ) => {
|
|
406
|
-
\t\tconst nonce = resolveRestNonce();
|
|
407
|
-
\t\treturn {
|
|
408
|
-
\t\t\t...resolveEndpointRouteOptions( create${pascalCase}ResourceEndpoint, request ),
|
|
409
|
-
\t\t\theaders: nonce
|
|
410
|
-
\t\t\t\t? {
|
|
411
|
-
\t\t\t\t\t'X-WP-Nonce': nonce,
|
|
412
|
-
\t\t\t\t}
|
|
413
|
-
\t\t\t\t: undefined,
|
|
414
|
-
\t\t};
|
|
415
|
-
\t},
|
|
416
|
-
};
|
|
417
|
-
|
|
418
|
-
export function createResource( request: ${pascalCase}CreateRequest ) {
|
|
419
|
-
\treturn callEndpoint( restResourceCreateEndpoint, request );
|
|
420
|
-
}`);
|
|
421
|
-
}
|
|
422
|
-
if (methods.includes("update")) {
|
|
423
|
-
typeImports.add(`${pascalCase}UpdateQuery`);
|
|
424
|
-
typeImports.add(`${pascalCase}UpdateRequest`);
|
|
425
|
-
clientEndpointImports.push(`update${pascalCase}ResourceEndpoint`);
|
|
426
|
-
exportedBindings.push(`export const restResourceUpdateEndpoint = {
|
|
427
|
-
\t...update${pascalCase}ResourceEndpoint,
|
|
428
|
-
\tbuildRequestOptions: ( request: {
|
|
429
|
-
\t\tbody: ${pascalCase}UpdateRequest;
|
|
430
|
-
\t\tquery: ${pascalCase}UpdateQuery;
|
|
431
|
-
\t} ) => {
|
|
432
|
-
\t\tconst nonce = resolveRestNonce();
|
|
433
|
-
\t\treturn {
|
|
434
|
-
\t\t\t...resolveEndpointRouteOptions( update${pascalCase}ResourceEndpoint, request ),
|
|
435
|
-
\t\t\theaders: nonce
|
|
436
|
-
\t\t\t\t? {
|
|
437
|
-
\t\t\t\t\t'X-WP-Nonce': nonce,
|
|
438
|
-
\t\t\t\t}
|
|
439
|
-
\t\t\t\t: undefined,
|
|
440
|
-
\t\t};
|
|
441
|
-
\t},
|
|
442
|
-
};
|
|
443
|
-
|
|
444
|
-
export function updateResource( request: {
|
|
445
|
-
\tbody: ${pascalCase}UpdateRequest;
|
|
446
|
-
\tquery: ${pascalCase}UpdateQuery;
|
|
447
|
-
} ) {
|
|
448
|
-
\treturn callEndpoint( restResourceUpdateEndpoint, request );
|
|
449
|
-
}`);
|
|
450
|
-
}
|
|
451
|
-
if (methods.includes("delete")) {
|
|
452
|
-
typeImports.add(`${pascalCase}DeleteQuery`);
|
|
453
|
-
clientEndpointImports.push(`delete${pascalCase}ResourceEndpoint`);
|
|
454
|
-
exportedBindings.push(`export const restResourceDeleteEndpoint = {
|
|
455
|
-
\t...delete${pascalCase}ResourceEndpoint,
|
|
456
|
-
\tbuildRequestOptions: ( request: ${pascalCase}DeleteQuery ) => {
|
|
457
|
-
\t\tconst nonce = resolveRestNonce();
|
|
458
|
-
\t\treturn {
|
|
459
|
-
\t\t\t...resolveEndpointRouteOptions( delete${pascalCase}ResourceEndpoint, request ),
|
|
460
|
-
\t\t\theaders: nonce
|
|
461
|
-
\t\t\t\t? {
|
|
462
|
-
\t\t\t\t\t'X-WP-Nonce': nonce,
|
|
463
|
-
\t\t\t\t}
|
|
464
|
-
\t\t\t\t: undefined,
|
|
465
|
-
\t\t};
|
|
466
|
-
\t},
|
|
467
|
-
};
|
|
468
|
-
|
|
469
|
-
export function deleteResource( request: ${pascalCase}DeleteQuery ) {
|
|
470
|
-
\treturn callEndpoint( restResourceDeleteEndpoint, request );
|
|
471
|
-
}`);
|
|
472
|
-
}
|
|
473
|
-
const resolveRestNonceSource = writeMethods.length > 0
|
|
474
|
-
? `function resolveRestNonce( fallback?: string ): string | undefined {
|
|
475
|
-
\tif ( typeof fallback === 'string' && fallback.length > 0 ) {
|
|
476
|
-
\t\treturn fallback;
|
|
477
|
-
\t}
|
|
478
|
-
|
|
479
|
-
\tif ( typeof window === 'undefined' ) {
|
|
480
|
-
\t\treturn undefined;
|
|
481
|
-
\t}
|
|
482
|
-
|
|
483
|
-
\tconst wpApiSettings = (
|
|
484
|
-
\t\twindow as typeof window & {
|
|
485
|
-
\t\t\twpApiSettings?: { nonce?: string };
|
|
486
|
-
\t\t}
|
|
487
|
-
\t).wpApiSettings;
|
|
488
|
-
|
|
489
|
-
\treturn typeof wpApiSettings?.nonce === 'string' &&
|
|
490
|
-
\t\twpApiSettings.nonce.length > 0
|
|
491
|
-
\t\t? wpApiSettings.nonce
|
|
492
|
-
\t\t: undefined;
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
`
|
|
496
|
-
: "";
|
|
497
|
-
return `import {
|
|
498
|
-
\tcallEndpoint,
|
|
499
|
-
\tresolveRestRouteUrl,
|
|
500
|
-
} from '@wp-typia/rest';
|
|
501
|
-
|
|
502
|
-
import type {
|
|
503
|
-
\t${Array.from(typeImports).sort().join(",\n\t")},
|
|
504
|
-
} from './api-types';
|
|
505
|
-
import {
|
|
506
|
-
\t${clientEndpointImports.sort().join(",\n\t")},
|
|
507
|
-
} from './api-client';
|
|
508
|
-
${resolveRestNonceSource}
|
|
509
|
-
function resolveEndpointRouteOptions<TRequest>(
|
|
510
|
-
\tendpoint: {
|
|
511
|
-
\t\tbuildRequestOptions?: ( request: TRequest ) => {
|
|
512
|
-
\t\t\tpath?: string;
|
|
513
|
-
\t\t\turl?: string;
|
|
514
|
-
\t\t};
|
|
515
|
-
\t\tpath: string;
|
|
516
|
-
\t},
|
|
517
|
-
\trequest: TRequest
|
|
518
|
-
) {
|
|
519
|
-
\tconst requestOptions = endpoint.buildRequestOptions?.( request ) ?? {};
|
|
520
|
-
\treturn {
|
|
521
|
-
\t\t...requestOptions,
|
|
522
|
-
\t\tpath: undefined,
|
|
523
|
-
\t\turl: requestOptions.url ?? resolveRestRouteUrl( requestOptions.path ?? endpoint.path ),
|
|
524
|
-
\t};
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
${exportedBindings.join("\n\n")}
|
|
528
|
-
`;
|
|
529
|
-
}
|
|
530
|
-
export function buildRestResourceDataSource(restResourceSlug, methods) {
|
|
531
|
-
const pascalCase = toPascalCase(restResourceSlug);
|
|
532
|
-
const typeImports = new Set();
|
|
533
|
-
const endpointImports = [];
|
|
534
|
-
const exportedBindings = [];
|
|
535
|
-
if (methods.includes("list")) {
|
|
536
|
-
typeImports.add(`${pascalCase}ListQuery`);
|
|
537
|
-
typeImports.add(`${pascalCase}ListResponse`);
|
|
538
|
-
endpointImports.push("restResourceListEndpoint");
|
|
539
|
-
exportedBindings.push(`export type Use${pascalCase}ListQueryOptions<
|
|
540
|
-
\tSelected = ${pascalCase}ListResponse,
|
|
541
|
-
> = UseEndpointQueryOptions<
|
|
542
|
-
\t${pascalCase}ListQuery,
|
|
543
|
-
\t${pascalCase}ListResponse,
|
|
544
|
-
\tSelected
|
|
545
|
-
>;
|
|
546
|
-
|
|
547
|
-
export function use${pascalCase}ListQuery<
|
|
548
|
-
\tSelected = ${pascalCase}ListResponse,
|
|
549
|
-
>(
|
|
550
|
-
\trequest: ${pascalCase}ListQuery,
|
|
551
|
-
\toptions: Use${pascalCase}ListQueryOptions< Selected > = {}
|
|
552
|
-
) {
|
|
553
|
-
\treturn useEndpointQuery( restResourceListEndpoint, request, options );
|
|
554
|
-
}`);
|
|
555
|
-
}
|
|
556
|
-
if (methods.includes("read")) {
|
|
557
|
-
typeImports.add(`${pascalCase}ReadQuery`);
|
|
558
|
-
typeImports.add(`${pascalCase}ReadResponse`);
|
|
559
|
-
endpointImports.push("restResourceReadEndpoint");
|
|
560
|
-
exportedBindings.push(`export type Use${pascalCase}ReadQueryOptions<
|
|
561
|
-
\tSelected = ${pascalCase}ReadResponse,
|
|
562
|
-
> = UseEndpointQueryOptions<
|
|
563
|
-
\t${pascalCase}ReadQuery,
|
|
564
|
-
\t${pascalCase}ReadResponse,
|
|
565
|
-
\tSelected
|
|
566
|
-
>;
|
|
567
|
-
|
|
568
|
-
export function use${pascalCase}ReadQuery<
|
|
569
|
-
\tSelected = ${pascalCase}ReadResponse,
|
|
570
|
-
>(
|
|
571
|
-
\trequest: ${pascalCase}ReadQuery,
|
|
572
|
-
\toptions: Use${pascalCase}ReadQueryOptions< Selected > = {}
|
|
573
|
-
) {
|
|
574
|
-
\treturn useEndpointQuery( restResourceReadEndpoint, request, options );
|
|
575
|
-
}`);
|
|
576
|
-
}
|
|
577
|
-
if (methods.includes("create")) {
|
|
578
|
-
typeImports.add(`${pascalCase}CreateRequest`);
|
|
579
|
-
typeImports.add(`${pascalCase}CreateResponse`);
|
|
580
|
-
endpointImports.push("restResourceCreateEndpoint");
|
|
581
|
-
exportedBindings.push(`export type UseCreate${pascalCase}ResourceMutationOptions = UseEndpointMutationOptions<
|
|
582
|
-
\t${pascalCase}CreateRequest,
|
|
583
|
-
\t${pascalCase}CreateResponse,
|
|
584
|
-
\tunknown
|
|
585
|
-
>;
|
|
586
|
-
|
|
587
|
-
export function useCreate${pascalCase}ResourceMutation(
|
|
588
|
-
\toptions: UseCreate${pascalCase}ResourceMutationOptions = {}
|
|
589
|
-
) {
|
|
590
|
-
\treturn useEndpointMutation( restResourceCreateEndpoint, options );
|
|
591
|
-
}`);
|
|
592
|
-
}
|
|
593
|
-
if (methods.includes("update")) {
|
|
594
|
-
typeImports.add(`${pascalCase}UpdateQuery`);
|
|
595
|
-
typeImports.add(`${pascalCase}UpdateRequest`);
|
|
596
|
-
typeImports.add(`${pascalCase}UpdateResponse`);
|
|
597
|
-
endpointImports.push("restResourceUpdateEndpoint");
|
|
598
|
-
exportedBindings.push(`export type UseUpdate${pascalCase}ResourceMutationOptions = UseEndpointMutationOptions<
|
|
599
|
-
\t{
|
|
600
|
-
\t\tbody: ${pascalCase}UpdateRequest;
|
|
601
|
-
\t\tquery: ${pascalCase}UpdateQuery;
|
|
602
|
-
\t},
|
|
603
|
-
\t${pascalCase}UpdateResponse,
|
|
604
|
-
\tunknown
|
|
605
|
-
>;
|
|
606
|
-
|
|
607
|
-
export function useUpdate${pascalCase}ResourceMutation(
|
|
608
|
-
\toptions: UseUpdate${pascalCase}ResourceMutationOptions = {}
|
|
609
|
-
) {
|
|
610
|
-
\treturn useEndpointMutation( restResourceUpdateEndpoint, options );
|
|
611
|
-
}`);
|
|
612
|
-
}
|
|
613
|
-
if (methods.includes("delete")) {
|
|
614
|
-
typeImports.add(`${pascalCase}DeleteQuery`);
|
|
615
|
-
typeImports.add(`${pascalCase}DeleteResponse`);
|
|
616
|
-
endpointImports.push("restResourceDeleteEndpoint");
|
|
617
|
-
exportedBindings.push(`export type UseDelete${pascalCase}ResourceMutationOptions = UseEndpointMutationOptions<
|
|
618
|
-
\t${pascalCase}DeleteQuery,
|
|
619
|
-
\t${pascalCase}DeleteResponse,
|
|
620
|
-
\tunknown
|
|
621
|
-
>;
|
|
622
|
-
|
|
623
|
-
export function useDelete${pascalCase}ResourceMutation(
|
|
624
|
-
\toptions: UseDelete${pascalCase}ResourceMutationOptions = {}
|
|
625
|
-
) {
|
|
626
|
-
\treturn useEndpointMutation( restResourceDeleteEndpoint, options );
|
|
627
|
-
}`);
|
|
628
|
-
}
|
|
629
|
-
return `import {
|
|
630
|
-
\tuseEndpointMutation,
|
|
631
|
-
\tuseEndpointQuery,
|
|
632
|
-
\ttype UseEndpointMutationOptions,
|
|
633
|
-
\ttype UseEndpointQueryOptions,
|
|
634
|
-
} from '@wp-typia/rest/react';
|
|
635
|
-
|
|
636
|
-
import type {
|
|
637
|
-
\t${Array.from(typeImports).sort().join(",\n\t")},
|
|
638
|
-
} from './api-types';
|
|
639
|
-
import {
|
|
640
|
-
\t${endpointImports.sort().join(",\n\t")},
|
|
641
|
-
} from './api';
|
|
642
|
-
|
|
643
|
-
${exportedBindings.join("\n\n")}
|
|
644
|
-
`;
|
|
645
|
-
}
|
|
7
|
+
export { buildRestResourceApiSource, buildRestResourceConfigEntry, buildRestResourceDataSource, buildRestResourceTypesSource, buildRestResourceValidatorsSource, } from "./cli-add-workspace-rest-generated-source-emitters.js";
|
|
8
|
+
export { buildManualRestContractApiSource, buildManualRestContractConfigEntry, buildManualRestContractTypesSource, buildManualRestContractValidatorsSource, } from "./cli-add-workspace-rest-manual-source-emitters.js";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prefix every line in a multi-line source fragment.
|
|
3
|
+
*
|
|
4
|
+
* @param source Source fragment to indent.
|
|
5
|
+
* @param prefix Prefix to prepend to every line.
|
|
6
|
+
* @returns The source fragment with each line prefixed.
|
|
7
|
+
*/
|
|
8
|
+
export declare function indentMultiline(source: string, prefix: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Render the shared REST nonce helper in the formatting style expected by a
|
|
11
|
+
* generated source file.
|
|
12
|
+
*
|
|
13
|
+
* @param style Compact output is used by manual-contract shims; spaced output
|
|
14
|
+
* matches generated REST resource shims.
|
|
15
|
+
* @returns TypeScript source for the embedded `resolveRestNonce()` helper.
|
|
16
|
+
*/
|
|
17
|
+
export declare function formatResolveRestNonceSource(style: "compact" | "spaced"): string;
|