@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,50 @@
|
|
|
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 function indentMultiline(source, prefix) {
|
|
9
|
+
return source
|
|
10
|
+
.split("\n")
|
|
11
|
+
.map((line) => `${prefix}${line}`)
|
|
12
|
+
.join("\n");
|
|
13
|
+
}
|
|
14
|
+
const RESOLVE_REST_NONCE_SOURCE = `function resolveRestNonce( fallback?: string ): string | undefined {
|
|
15
|
+
\tif ( typeof fallback === 'string' && fallback.length > 0 ) {
|
|
16
|
+
\t\treturn fallback;
|
|
17
|
+
\t}
|
|
18
|
+
|
|
19
|
+
\tif ( typeof window === 'undefined' ) {
|
|
20
|
+
\t\treturn undefined;
|
|
21
|
+
\t}
|
|
22
|
+
|
|
23
|
+
\tconst wpApiSettings = (
|
|
24
|
+
\t\twindow as typeof window & {
|
|
25
|
+
\t\t\twpApiSettings?: { nonce?: string };
|
|
26
|
+
\t\t}
|
|
27
|
+
\t).wpApiSettings;
|
|
28
|
+
|
|
29
|
+
\treturn typeof wpApiSettings?.nonce === 'string' &&
|
|
30
|
+
\t\twpApiSettings.nonce.length > 0
|
|
31
|
+
\t\t? wpApiSettings.nonce
|
|
32
|
+
\t\t: undefined;
|
|
33
|
+
}`;
|
|
34
|
+
/**
|
|
35
|
+
* Render the shared REST nonce helper in the formatting style expected by a
|
|
36
|
+
* generated source file.
|
|
37
|
+
*
|
|
38
|
+
* @param style Compact output is used by manual-contract shims; spaced output
|
|
39
|
+
* matches generated REST resource shims.
|
|
40
|
+
* @returns TypeScript source for the embedded `resolveRestNonce()` helper.
|
|
41
|
+
*/
|
|
42
|
+
export function formatResolveRestNonceSource(style) {
|
|
43
|
+
if (style === "spaced") {
|
|
44
|
+
return RESOLVE_REST_NONCE_SOURCE;
|
|
45
|
+
}
|
|
46
|
+
return RESOLVE_REST_NONCE_SOURCE
|
|
47
|
+
.replace("function resolveRestNonce( fallback?: string ): string | undefined {", "function resolveRestNonce(fallback?: string): string | undefined {")
|
|
48
|
+
.replace("\tif ( typeof fallback === 'string' && fallback.length > 0 ) {", "\tif (typeof fallback === 'string' && fallback.length > 0) {")
|
|
49
|
+
.replace("\tif ( typeof window === 'undefined' ) {", "\tif (typeof window === 'undefined') {");
|
|
50
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build the standard sync-rest patch failure message for missing anchors.
|
|
3
|
+
*
|
|
4
|
+
* @param functionName Name of the patcher that could not complete.
|
|
5
|
+
* @param syncRestScriptPath Path to the workspace sync-rest script.
|
|
6
|
+
* @param anchorDescription Human-readable description of the missing anchor.
|
|
7
|
+
* @param subject Configuration subject the patcher was trying to wire.
|
|
8
|
+
* @returns A formatted error message with manual recovery guidance.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getSyncRestPatchErrorMessage(functionName: string, syncRestScriptPath: string, anchorDescription: string, subject: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Add a required block-config value and type import to sync-rest source.
|
|
13
|
+
*
|
|
14
|
+
* @param options Import patching options.
|
|
15
|
+
* @param options.functionName Name of the calling patcher for error messages.
|
|
16
|
+
* @param options.nextSource Current sync-rest script source.
|
|
17
|
+
* @param options.subject Value and type names that must be imported.
|
|
18
|
+
* @param options.syncRestScriptPath Path to the target sync-rest script.
|
|
19
|
+
* @returns Source with the block-config import updated or left unchanged.
|
|
20
|
+
* @throws When the generated block-config import anchor cannot be found.
|
|
21
|
+
*/
|
|
22
|
+
export declare function replaceBlockConfigImport({ functionName, nextSource, subject, syncRestScriptPath, }: {
|
|
23
|
+
functionName: string;
|
|
24
|
+
nextSource: string;
|
|
25
|
+
subject: {
|
|
26
|
+
configTypeName: string;
|
|
27
|
+
constName: string;
|
|
28
|
+
};
|
|
29
|
+
syncRestScriptPath: string;
|
|
30
|
+
}): string;
|
|
31
|
+
/**
|
|
32
|
+
* Render a sync-rest guard for the selected empty resource collections.
|
|
33
|
+
*
|
|
34
|
+
* @param options Guard rendering options.
|
|
35
|
+
* @param options.subjects Candidate guard subjects and conditions.
|
|
36
|
+
* @returns TypeScript source for the no-resources guard block.
|
|
37
|
+
*/
|
|
38
|
+
export declare function buildNoResourcesGuard({ subjects, }: {
|
|
39
|
+
subjects: readonly {
|
|
40
|
+
condition: string;
|
|
41
|
+
include: boolean;
|
|
42
|
+
subject: string;
|
|
43
|
+
}[];
|
|
44
|
+
}): string;
|
|
45
|
+
/**
|
|
46
|
+
* Replace the generated no-resources guard in sync-rest source.
|
|
47
|
+
*
|
|
48
|
+
* @param nextSource Current sync-rest script source.
|
|
49
|
+
* @param replacement New no-resources guard source.
|
|
50
|
+
* @param functionName Name of the calling patcher for error messages.
|
|
51
|
+
* @param syncRestScriptPath Path to the target sync-rest script.
|
|
52
|
+
* @param subject Configuration subject the patcher was trying to wire.
|
|
53
|
+
* @returns Source with the no-resources guard replaced.
|
|
54
|
+
* @throws When the generated no-resources guard cannot be found.
|
|
55
|
+
*/
|
|
56
|
+
export declare function replaceNoResourcesGuard(nextSource: string, replacement: string, functionName: string, syncRestScriptPath: string, subject: string): string;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
/**
|
|
3
|
+
* Build the standard sync-rest patch failure message for missing anchors.
|
|
4
|
+
*
|
|
5
|
+
* @param functionName Name of the patcher that could not complete.
|
|
6
|
+
* @param syncRestScriptPath Path to the workspace sync-rest script.
|
|
7
|
+
* @param anchorDescription Human-readable description of the missing anchor.
|
|
8
|
+
* @param subject Configuration subject the patcher was trying to wire.
|
|
9
|
+
* @returns A formatted error message with manual recovery guidance.
|
|
10
|
+
*/
|
|
11
|
+
export function getSyncRestPatchErrorMessage(functionName, syncRestScriptPath, anchorDescription, subject) {
|
|
12
|
+
return [
|
|
13
|
+
`${functionName} could not patch ${path.basename(syncRestScriptPath)}.`,
|
|
14
|
+
`Missing expected ${anchorDescription} anchor in scripts/sync-rest-contracts.ts.`,
|
|
15
|
+
`Restore the generated template or add the ${subject} wiring manually before retrying.`,
|
|
16
|
+
].join(" ");
|
|
17
|
+
}
|
|
18
|
+
const BLOCK_CONFIG_IMPORT_PATTERNS = [
|
|
19
|
+
/^import\s*\{\n(?:\t[^\n]*\n)+\} from ["']\.\/block-config["'];?$/mu,
|
|
20
|
+
/^import\s*\{[^\n]*\}\s*from\s*["']\.\/block-config["'];?$/mu,
|
|
21
|
+
];
|
|
22
|
+
const BLOCK_CONFIG_VALUE_IMPORT_ORDER = [
|
|
23
|
+
"AI_FEATURES",
|
|
24
|
+
"BLOCKS",
|
|
25
|
+
"CONTRACTS",
|
|
26
|
+
"POST_META",
|
|
27
|
+
"REST_RESOURCES",
|
|
28
|
+
];
|
|
29
|
+
const BLOCK_CONFIG_TYPE_IMPORT_ORDER = [
|
|
30
|
+
"WorkspaceAiFeatureConfig",
|
|
31
|
+
"WorkspaceBlockConfig",
|
|
32
|
+
"WorkspaceContractConfig",
|
|
33
|
+
"WorkspacePostMetaConfig",
|
|
34
|
+
"WorkspaceRestResourceConfig",
|
|
35
|
+
];
|
|
36
|
+
/**
|
|
37
|
+
* Add a required block-config value and type import to sync-rest source.
|
|
38
|
+
*
|
|
39
|
+
* @param options Import patching options.
|
|
40
|
+
* @param options.functionName Name of the calling patcher for error messages.
|
|
41
|
+
* @param options.nextSource Current sync-rest script source.
|
|
42
|
+
* @param options.subject Value and type names that must be imported.
|
|
43
|
+
* @param options.syncRestScriptPath Path to the target sync-rest script.
|
|
44
|
+
* @returns Source with the block-config import updated or left unchanged.
|
|
45
|
+
* @throws When the generated block-config import anchor cannot be found.
|
|
46
|
+
*/
|
|
47
|
+
export function replaceBlockConfigImport({ functionName, nextSource, subject, syncRestScriptPath, }) {
|
|
48
|
+
const importMatch = BLOCK_CONFIG_IMPORT_PATTERNS.map((pattern) => pattern.exec(nextSource)).find(Boolean) ?? null;
|
|
49
|
+
if (!importMatch) {
|
|
50
|
+
throw new Error(getSyncRestPatchErrorMessage(functionName, syncRestScriptPath, "block-config import", subject.constName));
|
|
51
|
+
}
|
|
52
|
+
const importSource = importMatch[0];
|
|
53
|
+
if (importSource.includes(subject.constName) &&
|
|
54
|
+
importSource.includes(subject.configTypeName)) {
|
|
55
|
+
return nextSource;
|
|
56
|
+
}
|
|
57
|
+
if (!importSource.includes("BLOCKS") ||
|
|
58
|
+
!importSource.includes("WorkspaceBlockConfig")) {
|
|
59
|
+
throw new Error(getSyncRestPatchErrorMessage(functionName, syncRestScriptPath, "BLOCKS import", subject.constName));
|
|
60
|
+
}
|
|
61
|
+
const replacement = [
|
|
62
|
+
"import {",
|
|
63
|
+
...BLOCK_CONFIG_VALUE_IMPORT_ORDER.flatMap((constName) => constName === subject.constName || importSource.includes(constName)
|
|
64
|
+
? [`\t${constName},`]
|
|
65
|
+
: []),
|
|
66
|
+
...BLOCK_CONFIG_TYPE_IMPORT_ORDER.flatMap((configTypeName) => configTypeName === subject.configTypeName ||
|
|
67
|
+
importSource.includes(configTypeName)
|
|
68
|
+
? [`\ttype ${configTypeName},`]
|
|
69
|
+
: []),
|
|
70
|
+
"} from './block-config';",
|
|
71
|
+
].join("\n");
|
|
72
|
+
return nextSource.replace(importSource, replacement);
|
|
73
|
+
}
|
|
74
|
+
function formatNoResourcesSubject(subjects) {
|
|
75
|
+
if (subjects.length <= 2) {
|
|
76
|
+
return subjects.join(" or ");
|
|
77
|
+
}
|
|
78
|
+
const lastSubject = subjects[subjects.length - 1];
|
|
79
|
+
return `${subjects.slice(0, -1).join(", ")}, or ${lastSubject}`;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Render a sync-rest guard for the selected empty resource collections.
|
|
83
|
+
*
|
|
84
|
+
* @param options Guard rendering options.
|
|
85
|
+
* @param options.subjects Candidate guard subjects and conditions.
|
|
86
|
+
* @returns TypeScript source for the no-resources guard block.
|
|
87
|
+
*/
|
|
88
|
+
export function buildNoResourcesGuard({ subjects, }) {
|
|
89
|
+
const includedSubjects = subjects.filter((subject) => subject.include);
|
|
90
|
+
const condition = includedSubjects.map(({ condition }, index) => index === includedSubjects.length - 1 ? condition : `${condition} &&`);
|
|
91
|
+
const noResourcesSubject = formatNoResourcesSubject(includedSubjects.map(({ subject }) => subject));
|
|
92
|
+
return [
|
|
93
|
+
"if (",
|
|
94
|
+
...condition.map((line) => `\t\t${line}`),
|
|
95
|
+
"\t) {",
|
|
96
|
+
"\t\tconsole.log(",
|
|
97
|
+
"\t\t\toptions.check",
|
|
98
|
+
`\t\t\t\t? 'ℹ️ No ${noResourcesSubject} are registered yet. \`sync-rest --check\` is already clean.'`,
|
|
99
|
+
`\t\t\t\t: 'ℹ️ No ${noResourcesSubject} are registered yet.'`,
|
|
100
|
+
"\t\t);",
|
|
101
|
+
"\t\treturn;",
|
|
102
|
+
"\t}",
|
|
103
|
+
].join("\n");
|
|
104
|
+
}
|
|
105
|
+
const NO_RESOURCES_GUARD_PATTERN = /if \(\s*restBlocks\.length === 0(?:\s*&&\s*standaloneContracts\.length === 0)?(?:\s*&&\s*postMetaContracts\.length === 0)?(?:\s*&&\s*restResources\.length === 0)?(?:\s*&&\s*aiFeatures\.length === 0)?\s*\) \{[\s\S]*?\n\t\treturn;\n\t\}/u;
|
|
106
|
+
/**
|
|
107
|
+
* Replace the generated no-resources guard in sync-rest source.
|
|
108
|
+
*
|
|
109
|
+
* @param nextSource Current sync-rest script source.
|
|
110
|
+
* @param replacement New no-resources guard source.
|
|
111
|
+
* @param functionName Name of the calling patcher for error messages.
|
|
112
|
+
* @param syncRestScriptPath Path to the target sync-rest script.
|
|
113
|
+
* @param subject Configuration subject the patcher was trying to wire.
|
|
114
|
+
* @returns Source with the no-resources guard replaced.
|
|
115
|
+
* @throws When the generated no-resources guard cannot be found.
|
|
116
|
+
*/
|
|
117
|
+
export function replaceNoResourcesGuard(nextSource, replacement, functionName, syncRestScriptPath, subject) {
|
|
118
|
+
if (!NO_RESOURCES_GUARD_PATTERN.test(nextSource)) {
|
|
119
|
+
throw new Error(getSyncRestPatchErrorMessage(functionName, syncRestScriptPath, "no-resources guard", subject));
|
|
120
|
+
}
|
|
121
|
+
return nextSource.replace(NO_RESOURCES_GUARD_PATTERN, replacement);
|
|
122
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { ManualRestContractAuthId, ManualRestContractHttpMethodId, RestResourceMethodId } from "./cli-add-shared.js";
|
|
2
|
+
import type { WorkspaceProject } from "./workspace-project.js";
|
|
3
|
+
/**
|
|
4
|
+
* Normalized metadata returned after `wp-typia add rest-resource` completes.
|
|
5
|
+
*
|
|
6
|
+
* @property auth Manual-mode authentication policy when `mode` is `"manual"`.
|
|
7
|
+
* @property bodyTypeName Optional manual-mode request body type export.
|
|
8
|
+
* @property controllerClass Optional PHP controller class reference. Generated
|
|
9
|
+
* mode uses it for callbacks; manual mode records it as route-owner metadata.
|
|
10
|
+
* @property methods Generated-mode REST operation ids, or an empty array for
|
|
11
|
+
* manual contracts.
|
|
12
|
+
* @property mode Whether the scaffold wrote generated REST glue or a type-only
|
|
13
|
+
* manual contract.
|
|
14
|
+
* @property namespace REST namespace in `vendor/v1` format.
|
|
15
|
+
* @property projectDir Absolute workspace project directory.
|
|
16
|
+
* @property restResourceSlug Normalized kebab-case REST resource slug.
|
|
17
|
+
* @property secretPreserveOnEmpty Whether blank settings secret submissions
|
|
18
|
+
* should preserve the stored value when `secretFieldName` is set.
|
|
19
|
+
*/
|
|
20
|
+
export interface RunAddRestResourceCommandResult {
|
|
21
|
+
auth?: ManualRestContractAuthId;
|
|
22
|
+
bodyTypeName?: string;
|
|
23
|
+
controllerClass?: string;
|
|
24
|
+
controllerExtends?: string;
|
|
25
|
+
method?: ManualRestContractHttpMethodId;
|
|
26
|
+
methods: RestResourceMethodId[];
|
|
27
|
+
mode: "generated" | "manual";
|
|
28
|
+
namespace: string;
|
|
29
|
+
permissionCallback?: string;
|
|
30
|
+
pathPattern?: string;
|
|
31
|
+
projectDir: string;
|
|
32
|
+
queryTypeName?: string;
|
|
33
|
+
restResourceSlug: string;
|
|
34
|
+
responseTypeName?: string;
|
|
35
|
+
routePattern?: string;
|
|
36
|
+
secretFieldName?: string;
|
|
37
|
+
secretHasValueFieldName?: string;
|
|
38
|
+
secretMaskedResponseFieldName?: string;
|
|
39
|
+
secretPreserveOnEmpty?: boolean;
|
|
40
|
+
secretStateFieldName?: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Raw command options passed from the REST orchestrator into manual-mode
|
|
44
|
+
* contract scaffolding.
|
|
45
|
+
*
|
|
46
|
+
* @property auth Optional raw manual authentication id, validated before use.
|
|
47
|
+
* @property bodyTypeName Optional exported request body type name.
|
|
48
|
+
* @property method Optional raw HTTP method id, validated as a manual REST
|
|
49
|
+
* contract method.
|
|
50
|
+
* @property namespace Resolved REST namespace in `vendor/v1` format.
|
|
51
|
+
* @property pathPattern Optional manual route path pattern relative to the
|
|
52
|
+
* namespace.
|
|
53
|
+
* @property permissionCallback Optional manual route-owner permission callback
|
|
54
|
+
* metadata.
|
|
55
|
+
* @property restResourceSlug Normalized kebab-case REST resource slug.
|
|
56
|
+
* @property routePattern Optional manual route path alias for `pathPattern`.
|
|
57
|
+
* @property secretHasValueFieldName Optional alias for `secretStateFieldName`.
|
|
58
|
+
* @property secretMaskedResponseFieldName Optional alias for
|
|
59
|
+
* `secretStateFieldName`.
|
|
60
|
+
* @property secretFieldName Optional write-only request secret field.
|
|
61
|
+
* @property secretPreserveOnEmpty Optional normalized boolean for blank-secret
|
|
62
|
+
* preservation. Defaults to true when `secretFieldName` is set.
|
|
63
|
+
* @property workspace Resolved official workspace project.
|
|
64
|
+
*/
|
|
65
|
+
export interface ManualRestContractScaffoldOptions {
|
|
66
|
+
auth: string | undefined;
|
|
67
|
+
bodyTypeName: string | undefined;
|
|
68
|
+
controllerClass: string | undefined;
|
|
69
|
+
controllerExtends: string | undefined;
|
|
70
|
+
method: string | undefined;
|
|
71
|
+
namespace: string;
|
|
72
|
+
pathPattern: string | undefined;
|
|
73
|
+
permissionCallback: string | undefined;
|
|
74
|
+
queryTypeName: string | undefined;
|
|
75
|
+
responseTypeName: string | undefined;
|
|
76
|
+
restResourceSlug: string;
|
|
77
|
+
routePattern: string | undefined;
|
|
78
|
+
secretFieldName: string | undefined;
|
|
79
|
+
secretHasValueFieldName: string | undefined;
|
|
80
|
+
secretMaskedResponseFieldName: string | undefined;
|
|
81
|
+
secretPreserveOnEmpty: boolean | undefined;
|
|
82
|
+
secretStateFieldName: string | undefined;
|
|
83
|
+
workspace: WorkspaceProject;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Raw command options passed from the REST orchestrator into generated-mode
|
|
87
|
+
* resource scaffolding.
|
|
88
|
+
*
|
|
89
|
+
* @property controllerClass Optional PHP controller class reference.
|
|
90
|
+
* @property controllerExtends Optional PHP base class reference; requires
|
|
91
|
+
* `controllerClass`.
|
|
92
|
+
* @property methods Optional comma-separated REST method list validated into
|
|
93
|
+
* `RestResourceMethodId` values.
|
|
94
|
+
* @property namespace Resolved REST namespace in `vendor/v1` format.
|
|
95
|
+
* @property permissionCallback Optional PHP permission callback reference.
|
|
96
|
+
* @property restResourceSlug Normalized kebab-case REST resource slug.
|
|
97
|
+
* @property workspace Resolved official workspace project.
|
|
98
|
+
*/
|
|
99
|
+
export interface GeneratedRestResourceScaffoldOptions {
|
|
100
|
+
controllerClass: string | undefined;
|
|
101
|
+
controllerExtends: string | undefined;
|
|
102
|
+
methods: string | undefined;
|
|
103
|
+
namespace: string;
|
|
104
|
+
permissionCallback: string | undefined;
|
|
105
|
+
restResourceSlug: string;
|
|
106
|
+
routePattern: string | undefined;
|
|
107
|
+
workspace: WorkspaceProject;
|
|
108
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type RunAddRestResourceCommandOptions } from "./cli-add-shared.js";
|
|
2
|
+
import { type RunAddRestResourceCommandResult } from "./cli-add-workspace-rest-types.js";
|
|
2
3
|
/**
|
|
3
4
|
* Scaffold a workspace-level REST resource and synchronize its generated
|
|
4
5
|
* TypeScript and PHP artifacts.
|
|
@@ -6,22 +7,4 @@ import { type ManualRestContractAuthId, type ManualRestContractHttpMethodId, typ
|
|
|
6
7
|
* @param options Command options for the REST resource scaffold workflow.
|
|
7
8
|
* @returns Resolved scaffold metadata for the created REST resource.
|
|
8
9
|
*/
|
|
9
|
-
export declare function runAddRestResourceCommand({ auth, bodyTypeName, controllerClass, controllerExtends, cwd, manual, method, methods, namespace, permissionCallback, pathPattern, queryTypeName, restResourceName, responseTypeName, routePattern, secretFieldName, secretStateFieldName, }: RunAddRestResourceCommandOptions): Promise<
|
|
10
|
-
auth?: ManualRestContractAuthId;
|
|
11
|
-
bodyTypeName?: string;
|
|
12
|
-
controllerClass?: string;
|
|
13
|
-
controllerExtends?: string;
|
|
14
|
-
method?: ManualRestContractHttpMethodId;
|
|
15
|
-
methods: RestResourceMethodId[];
|
|
16
|
-
mode: "generated" | "manual";
|
|
17
|
-
namespace: string;
|
|
18
|
-
permissionCallback?: string;
|
|
19
|
-
pathPattern?: string;
|
|
20
|
-
projectDir: string;
|
|
21
|
-
queryTypeName?: string;
|
|
22
|
-
restResourceSlug: string;
|
|
23
|
-
responseTypeName?: string;
|
|
24
|
-
routePattern?: string;
|
|
25
|
-
secretFieldName?: string;
|
|
26
|
-
secretStateFieldName?: string;
|
|
27
|
-
}>;
|
|
10
|
+
export declare function runAddRestResourceCommand({ auth, bodyTypeName, controllerClass, controllerExtends, cwd, manual, method, methods, namespace, permissionCallback, pathPattern, queryTypeName, restResourceName, responseTypeName, routePattern, secretFieldName, secretHasValueFieldName, secretMaskedResponseFieldName, secretPreserveOnEmpty, secretStateFieldName, }: RunAddRestResourceCommandOptions): Promise<RunAddRestResourceCommandResult>;
|