@wp-typia/project-tools 0.23.1 → 0.24.0

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