@wp-typia/block-runtime 0.3.0 → 0.4.2
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/README.md +4 -5
- package/dist/identifiers.d.ts +18 -0
- package/dist/identifiers.js +84 -0
- package/dist/inspector-runtime.d.ts +2 -2
- package/dist/metadata-core.js +4 -2
- package/dist/object-utils.js +2 -5
- package/dist/schema-core.d.ts +1 -0
- package/dist/schema-core.js +188 -8
- package/dist/validation.d.ts +3 -11
- package/dist/validation.js +3 -26
- package/package.json +39 -3
package/README.md
CHANGED
|
@@ -25,9 +25,8 @@ import { createNestedAttributeUpdater } from "@wp-typia/block-runtime/validation
|
|
|
25
25
|
import { runSyncBlockMetadata } from "@wp-typia/block-runtime/metadata-core";
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
`wp-typia` remains the CLI package.
|
|
29
29
|
|
|
30
|
-
`@wp-typia/
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
`@wp-typia/block-runtime/metadata-core`.
|
|
30
|
+
`@wp-typia/project-tools` is the canonical programmatic project orchestration
|
|
31
|
+
package, while newly generated projects should prefer `@wp-typia/block-runtime/*`
|
|
32
|
+
and `@wp-typia/block-runtime/metadata-core`.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate a UUID v4-style id for block attributes.
|
|
3
|
+
*/
|
|
4
|
+
export declare function generateBlockId(): string;
|
|
5
|
+
/**
|
|
6
|
+
* Generate a prefixed runtime id for client-side attributes such as uniqueId.
|
|
7
|
+
* @param prefix Prefix chosen by the scaffold/template.
|
|
8
|
+
*/
|
|
9
|
+
export declare function generateScopedClientId(prefix: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Generate a prefixed persistence resource key.
|
|
12
|
+
* @param prefix Prefix chosen by the scaffold/template.
|
|
13
|
+
*/
|
|
14
|
+
export declare function generateResourceKey(prefix: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Generate an opaque id for one public write attempt.
|
|
17
|
+
*/
|
|
18
|
+
export declare function generatePublicWriteRequestId(): string;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
const UUID_HEX_RADIX = 16;
|
|
2
|
+
const SCOPED_SUFFIX_LENGTH = 9;
|
|
3
|
+
/**
|
|
4
|
+
* Generate a UUID v4-style id for block attributes.
|
|
5
|
+
*/
|
|
6
|
+
export function generateBlockId() {
|
|
7
|
+
return generateUuidV4();
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Generate a prefixed runtime id for client-side attributes such as uniqueId.
|
|
11
|
+
* @param prefix Prefix chosen by the scaffold/template.
|
|
12
|
+
*/
|
|
13
|
+
export function generateScopedClientId(prefix) {
|
|
14
|
+
return generatePrefixedScopedId(prefix);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Generate a prefixed persistence resource key.
|
|
18
|
+
* @param prefix Prefix chosen by the scaffold/template.
|
|
19
|
+
*/
|
|
20
|
+
export function generateResourceKey(prefix) {
|
|
21
|
+
return generatePrefixedScopedId(prefix);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Generate an opaque id for one public write attempt.
|
|
25
|
+
*/
|
|
26
|
+
export function generatePublicWriteRequestId() {
|
|
27
|
+
return generateUuidV4();
|
|
28
|
+
}
|
|
29
|
+
function generateUuidV4() {
|
|
30
|
+
const cryptoObject = getCryptoObject();
|
|
31
|
+
if (typeof cryptoObject?.randomUUID === 'function') {
|
|
32
|
+
return cryptoObject.randomUUID();
|
|
33
|
+
}
|
|
34
|
+
const bytes = fillRandomBytes(16);
|
|
35
|
+
if (bytes) {
|
|
36
|
+
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
37
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
38
|
+
return formatUuidBytes(bytes);
|
|
39
|
+
}
|
|
40
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (character) => {
|
|
41
|
+
const randomNibble = Math.floor(Math.random() * UUID_HEX_RADIX);
|
|
42
|
+
const value = character === 'x'
|
|
43
|
+
? randomNibble
|
|
44
|
+
: (randomNibble & 0x03) | 0x08;
|
|
45
|
+
return value.toString(UUID_HEX_RADIX);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function generatePrefixedScopedId(prefix) {
|
|
49
|
+
return `${prefix}-${generateScopedSuffix()}`;
|
|
50
|
+
}
|
|
51
|
+
function generateScopedSuffix() {
|
|
52
|
+
const bytes = fillRandomBytes(SCOPED_SUFFIX_LENGTH);
|
|
53
|
+
if (bytes) {
|
|
54
|
+
return Array.from(bytes, (byte) => (byte % 36).toString(36)).join('');
|
|
55
|
+
}
|
|
56
|
+
return Math.random()
|
|
57
|
+
.toString(36)
|
|
58
|
+
.slice(2, 2 + SCOPED_SUFFIX_LENGTH)
|
|
59
|
+
.padEnd(SCOPED_SUFFIX_LENGTH, '0');
|
|
60
|
+
}
|
|
61
|
+
function formatUuidBytes(bytes) {
|
|
62
|
+
const hex = Array.from(bytes, (byte) => byte.toString(UUID_HEX_RADIX).padStart(2, '0')).join('');
|
|
63
|
+
return [
|
|
64
|
+
hex.slice(0, 8),
|
|
65
|
+
hex.slice(8, 12),
|
|
66
|
+
hex.slice(12, 16),
|
|
67
|
+
hex.slice(16, 20),
|
|
68
|
+
hex.slice(20),
|
|
69
|
+
].join('-');
|
|
70
|
+
}
|
|
71
|
+
function fillRandomBytes(size) {
|
|
72
|
+
const cryptoObject = getCryptoObject();
|
|
73
|
+
if (typeof cryptoObject?.getRandomValues !== 'function') {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
const bytes = new Uint8Array(size);
|
|
77
|
+
cryptoObject.getRandomValues(bytes);
|
|
78
|
+
return bytes;
|
|
79
|
+
}
|
|
80
|
+
function getCryptoObject() {
|
|
81
|
+
return typeof globalThis.crypto === 'object' && globalThis.crypto
|
|
82
|
+
? globalThis.crypto
|
|
83
|
+
: undefined;
|
|
84
|
+
}
|
|
@@ -125,5 +125,5 @@ export interface InspectorFromManifestProps<T extends UnknownRecord> {
|
|
|
125
125
|
}
|
|
126
126
|
export declare function useEditorFields(manifest: ManifestDocument, options?: EditorModelOptions): UseEditorFieldsResult;
|
|
127
127
|
export declare function useTypedAttributeUpdater<T extends object>(attributes: T, setAttributes: (attrs: Partial<T>) => void, validate?: (value: T) => ValidationResult<T>): TypedAttributeUpdater<T>;
|
|
128
|
-
export declare function FieldControl({ components, field, help, label, max, min, onChange, options, render, renderUnsupported, step, value, }: FieldControlProps): import("react/jsx-runtime
|
|
129
|
-
export declare function InspectorFromManifest<T extends UnknownRecord>({ attributes, children, components, fieldLookup, fieldOverrides, initialOpen, onChange, paths, title, }: InspectorFromManifestProps<T>): import("react/jsx-runtime
|
|
128
|
+
export declare function FieldControl({ components, field, help, label, max, min, onChange, options, render, renderUnsupported, step, value, }: FieldControlProps): import("react/jsx-runtime").JSX.Element | null;
|
|
129
|
+
export declare function InspectorFromManifest<T extends UnknownRecord>({ attributes, children, components, fieldLookup, fieldOverrides, initialOpen, onChange, paths, title, }: InspectorFromManifestProps<T>): import("react/jsx-runtime").JSX.Element;
|
package/dist/metadata-core.js
CHANGED
|
@@ -4,7 +4,7 @@ import { getTaggedSyncBlockMetadataFailureCode } from './metadata-analysis.js';
|
|
|
4
4
|
import { renderPhpValidator } from './metadata-php-render.js';
|
|
5
5
|
import { analyzeSourceType, analyzeSourceTypes } from './metadata-parser.js';
|
|
6
6
|
import { createBlockJsonAttribute, createExampleValue, createManifestDocument, validateWordPressExtractionAttributes, } from './metadata-projection.js';
|
|
7
|
-
import { buildEndpointOpenApiDocument, manifestToJsonSchema, manifestToOpenApi, normalizeEndpointAuthDefinition, } from './schema-core.js';
|
|
7
|
+
import { buildEndpointOpenApiDocument, manifestToJsonSchema, manifestToOpenApi, normalizeEndpointAuthDefinition, projectJsonSchemaDocument, } from './schema-core.js';
|
|
8
8
|
/**
|
|
9
9
|
* Preserve literal TypeScript inference for backend-neutral endpoint manifests.
|
|
10
10
|
*
|
|
@@ -251,7 +251,9 @@ export async function syncTypeSchemas(options, executionOptions = {}) {
|
|
|
251
251
|
: undefined;
|
|
252
252
|
reconcileGeneratedArtifacts([
|
|
253
253
|
{
|
|
254
|
-
content: JSON.stringify(manifestToJsonSchema(manifest),
|
|
254
|
+
content: JSON.stringify(projectJsonSchemaDocument(manifestToJsonSchema(manifest), {
|
|
255
|
+
profile: 'rest',
|
|
256
|
+
}), null, '\t'),
|
|
255
257
|
path: jsonSchemaPath,
|
|
256
258
|
},
|
|
257
259
|
...(openApiPath
|
package/dist/object-utils.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
+
import { isPlainObject as isSharedPlainObject } from "@wp-typia/api-client/runtime-primitives";
|
|
1
2
|
export function isPlainObject(value) {
|
|
2
|
-
|
|
3
|
-
return false;
|
|
4
|
-
}
|
|
5
|
-
const prototype = Object.getPrototypeOf(value);
|
|
6
|
-
return prototype === Object.prototype || prototype === null;
|
|
3
|
+
return isSharedPlainObject(value);
|
|
7
4
|
}
|
package/dist/schema-core.d.ts
CHANGED
|
@@ -59,6 +59,7 @@ export interface OpenApiResponse extends JsonSchemaObject {
|
|
|
59
59
|
"application/json": OpenApiMediaType;
|
|
60
60
|
};
|
|
61
61
|
description: string;
|
|
62
|
+
headers?: Record<string, JsonSchemaObject>;
|
|
62
63
|
}
|
|
63
64
|
/**
|
|
64
65
|
* Header-based security scheme used by authenticated WordPress REST routes.
|
package/dist/schema-core.js
CHANGED
|
@@ -149,15 +149,35 @@ function applyProjectedTypeTag(schema, typeTag, path) {
|
|
|
149
149
|
throw new Error(`Unsupported wp-typia schema type tag "${typeTag}" at "${path}".`);
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
|
+
function canProjectTypeTag(typeTag) {
|
|
153
|
+
switch (typeTag) {
|
|
154
|
+
case "uint32":
|
|
155
|
+
case "int32":
|
|
156
|
+
case "float":
|
|
157
|
+
case "double":
|
|
158
|
+
return true;
|
|
159
|
+
default:
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
152
163
|
function projectSchemaArrayItemsForAiStructuredOutput(items, path) {
|
|
153
164
|
return items.map((item, index) => projectSchemaObjectForAiStructuredOutput(item, `${path}/${index}`));
|
|
154
165
|
}
|
|
166
|
+
function projectSchemaArrayItemsForRest(items, path) {
|
|
167
|
+
return items.map((item, index) => projectSchemaObjectForRest(item, `${path}/${index}`));
|
|
168
|
+
}
|
|
155
169
|
function projectSchemaPropertyMapForAiStructuredOutput(properties, path) {
|
|
156
170
|
return Object.fromEntries(Object.entries(properties).map(([key, value]) => [
|
|
157
171
|
key,
|
|
158
172
|
projectSchemaObjectForAiStructuredOutput(value, `${path}/${key}`),
|
|
159
173
|
]));
|
|
160
174
|
}
|
|
175
|
+
function projectSchemaPropertyMapForRest(properties, path) {
|
|
176
|
+
return Object.fromEntries(Object.entries(properties).map(([key, value]) => [
|
|
177
|
+
key,
|
|
178
|
+
projectSchemaObjectForRest(value, `${path}/${key}`),
|
|
179
|
+
]));
|
|
180
|
+
}
|
|
161
181
|
function projectSchemaObjectForAiStructuredOutput(node, path) {
|
|
162
182
|
const projectedNode = cloneJsonSchemaNode(node);
|
|
163
183
|
const rawTypeTag = projectedNode[WP_TYPIA_OPENAPI_EXTENSION_KEYS.TYPE_TAG];
|
|
@@ -188,6 +208,126 @@ function projectSchemaObjectForAiStructuredOutput(node, path) {
|
|
|
188
208
|
}
|
|
189
209
|
return projectedNode;
|
|
190
210
|
}
|
|
211
|
+
function projectSchemaObjectForRest(node, path) {
|
|
212
|
+
const projectedNode = cloneJsonSchemaNode(node);
|
|
213
|
+
const rawTypeTag = projectedNode[WP_TYPIA_OPENAPI_EXTENSION_KEYS.TYPE_TAG];
|
|
214
|
+
if (typeof rawTypeTag === "string" && canProjectTypeTag(rawTypeTag)) {
|
|
215
|
+
applyProjectedTypeTag(projectedNode, rawTypeTag, path);
|
|
216
|
+
}
|
|
217
|
+
for (const key of Object.keys(projectedNode)) {
|
|
218
|
+
const child = projectedNode[key];
|
|
219
|
+
if (Array.isArray(child)) {
|
|
220
|
+
projectedNode[key] = child.every(isJsonSchemaObject)
|
|
221
|
+
? projectSchemaArrayItemsForRest(child, `${path}/${key}`)
|
|
222
|
+
: child;
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
if (!isJsonSchemaObject(child)) {
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
if (key === "properties") {
|
|
229
|
+
projectedNode[key] = projectSchemaPropertyMapForRest(child, `${path}/${key}`);
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
projectedNode[key] = projectSchemaObjectForRest(child, `${path}/${key}`);
|
|
233
|
+
}
|
|
234
|
+
applyProjectedBootstrapContract(projectedNode);
|
|
235
|
+
return projectedNode;
|
|
236
|
+
}
|
|
237
|
+
function applyProjectedBootstrapContract(schema) {
|
|
238
|
+
if (schema.type !== "object" || !isJsonSchemaObject(schema.properties)) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
const properties = schema.properties;
|
|
242
|
+
if (properties.canWrite?.type !== "boolean") {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
const allOf = Array.isArray(schema.allOf)
|
|
246
|
+
? [...schema.allOf]
|
|
247
|
+
: [];
|
|
248
|
+
const canWriteIsTrue = {
|
|
249
|
+
properties: {
|
|
250
|
+
canWrite: {
|
|
251
|
+
const: true,
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
required: ["canWrite"],
|
|
255
|
+
};
|
|
256
|
+
const buildRequiredPropertyObject = (requiredKeys) => Object.fromEntries(requiredKeys.map((requiredKey) => [requiredKey, properties[requiredKey] ?? {}]));
|
|
257
|
+
const hasRestNonce = properties.restNonce?.type === "string";
|
|
258
|
+
const hasPublicWriteCredential = properties.publicWriteToken?.type === "string" &&
|
|
259
|
+
isJsonSchemaObject(properties.publicWriteExpiresAt);
|
|
260
|
+
if (hasRestNonce && hasPublicWriteCredential) {
|
|
261
|
+
allOf.push({
|
|
262
|
+
if: canWriteIsTrue,
|
|
263
|
+
then: {
|
|
264
|
+
anyOf: [
|
|
265
|
+
{
|
|
266
|
+
properties: buildRequiredPropertyObject(["restNonce"]),
|
|
267
|
+
required: ["restNonce"],
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
properties: buildRequiredPropertyObject([
|
|
271
|
+
"publicWriteExpiresAt",
|
|
272
|
+
"publicWriteToken",
|
|
273
|
+
]),
|
|
274
|
+
required: ["publicWriteExpiresAt", "publicWriteToken"],
|
|
275
|
+
},
|
|
276
|
+
],
|
|
277
|
+
},
|
|
278
|
+
else: {
|
|
279
|
+
not: {
|
|
280
|
+
anyOf: [
|
|
281
|
+
{
|
|
282
|
+
properties: buildRequiredPropertyObject(["restNonce"]),
|
|
283
|
+
required: ["restNonce"],
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
properties: buildRequiredPropertyObject(["publicWriteToken"]),
|
|
287
|
+
required: ["publicWriteToken"],
|
|
288
|
+
},
|
|
289
|
+
],
|
|
290
|
+
},
|
|
291
|
+
},
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
if (hasRestNonce && !hasPublicWriteCredential) {
|
|
295
|
+
allOf.push({
|
|
296
|
+
if: canWriteIsTrue,
|
|
297
|
+
then: {
|
|
298
|
+
properties: buildRequiredPropertyObject(["restNonce"]),
|
|
299
|
+
required: ["restNonce"],
|
|
300
|
+
},
|
|
301
|
+
else: {
|
|
302
|
+
not: {
|
|
303
|
+
properties: buildRequiredPropertyObject(["restNonce"]),
|
|
304
|
+
required: ["restNonce"],
|
|
305
|
+
},
|
|
306
|
+
},
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
if (hasPublicWriteCredential && !hasRestNonce) {
|
|
310
|
+
allOf.push({
|
|
311
|
+
if: canWriteIsTrue,
|
|
312
|
+
then: {
|
|
313
|
+
properties: buildRequiredPropertyObject([
|
|
314
|
+
"publicWriteExpiresAt",
|
|
315
|
+
"publicWriteToken",
|
|
316
|
+
]),
|
|
317
|
+
required: ["publicWriteExpiresAt", "publicWriteToken"],
|
|
318
|
+
},
|
|
319
|
+
else: {
|
|
320
|
+
not: {
|
|
321
|
+
properties: buildRequiredPropertyObject(["publicWriteToken"]),
|
|
322
|
+
required: ["publicWriteToken"],
|
|
323
|
+
},
|
|
324
|
+
},
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
if (allOf.length > 0) {
|
|
328
|
+
schema.allOf = allOf;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
191
331
|
function manifestUnionToJsonSchema(union) {
|
|
192
332
|
const oneOf = Object.entries(union.branches).map(([branchKey, branch]) => {
|
|
193
333
|
if (branch.ts.kind !== "object") {
|
|
@@ -305,7 +445,7 @@ export function manifestToJsonSchema(doc) {
|
|
|
305
445
|
*/
|
|
306
446
|
export function projectJsonSchemaDocument(schema, options) {
|
|
307
447
|
if (options.profile === "rest") {
|
|
308
|
-
return
|
|
448
|
+
return projectSchemaObjectForRest(schema, "#");
|
|
309
449
|
}
|
|
310
450
|
if (options.profile === "ai-structured-output") {
|
|
311
451
|
return projectSchemaObjectForAiStructuredOutput(schema, "#");
|
|
@@ -321,10 +461,14 @@ export function projectJsonSchemaDocument(schema, options) {
|
|
|
321
461
|
*/
|
|
322
462
|
export function manifestToOpenApi(doc, info = {}) {
|
|
323
463
|
const schemaName = doc.sourceType ?? "TypiaDocument";
|
|
464
|
+
const projectedSchema = projectJsonSchemaDocument(manifestToJsonSchema(doc), {
|
|
465
|
+
profile: "rest",
|
|
466
|
+
});
|
|
467
|
+
delete projectedSchema.$schema;
|
|
324
468
|
return {
|
|
325
469
|
components: {
|
|
326
470
|
schemas: {
|
|
327
|
-
[schemaName]:
|
|
471
|
+
[schemaName]: projectedSchema,
|
|
328
472
|
},
|
|
329
473
|
},
|
|
330
474
|
info: {
|
|
@@ -486,7 +630,36 @@ function buildQueryParameters(contract) {
|
|
|
486
630
|
schema: manifestAttributeToJsonSchema(attribute),
|
|
487
631
|
}));
|
|
488
632
|
}
|
|
489
|
-
function
|
|
633
|
+
function createBootstrapResponseHeaders(normalizedAuth) {
|
|
634
|
+
const headers = {
|
|
635
|
+
"Cache-Control": {
|
|
636
|
+
description: "Must be non-cacheable for fresh bootstrap write/session state.",
|
|
637
|
+
schema: {
|
|
638
|
+
type: "string",
|
|
639
|
+
example: "private, no-store, no-cache, must-revalidate",
|
|
640
|
+
},
|
|
641
|
+
},
|
|
642
|
+
Pragma: {
|
|
643
|
+
description: "Legacy non-cacheable bootstrap response directive.",
|
|
644
|
+
schema: {
|
|
645
|
+
type: "string",
|
|
646
|
+
example: "no-cache",
|
|
647
|
+
},
|
|
648
|
+
},
|
|
649
|
+
};
|
|
650
|
+
if (normalizedAuth.wordpressAuth?.mechanism ===
|
|
651
|
+
WP_TYPIA_OPENAPI_LITERALS.WORDPRESS_REST_NONCE_MECHANISM) {
|
|
652
|
+
headers.Vary = {
|
|
653
|
+
description: "Viewer-aware bootstrap responses should vary on cookie-backed auth state.",
|
|
654
|
+
schema: {
|
|
655
|
+
type: "string",
|
|
656
|
+
example: "Cookie",
|
|
657
|
+
},
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
return headers;
|
|
661
|
+
}
|
|
662
|
+
function createSuccessResponse(schemaName, headers) {
|
|
490
663
|
return {
|
|
491
664
|
content: {
|
|
492
665
|
[WP_TYPIA_OPENAPI_LITERALS.JSON_CONTENT_TYPE]: {
|
|
@@ -494,14 +667,18 @@ function createSuccessResponse(schemaName) {
|
|
|
494
667
|
},
|
|
495
668
|
},
|
|
496
669
|
description: WP_TYPIA_OPENAPI_LITERALS.SUCCESS_RESPONSE_DESCRIPTION,
|
|
670
|
+
...(headers ? { headers } : {}),
|
|
497
671
|
};
|
|
498
672
|
}
|
|
499
673
|
function buildEndpointOpenApiOperation(endpoint, contracts) {
|
|
500
674
|
const normalizedAuth = normalizeEndpointAuthDefinition(endpoint);
|
|
675
|
+
const isBootstrapEndpoint = endpoint.path.endsWith("/bootstrap");
|
|
501
676
|
const operation = {
|
|
502
677
|
operationId: endpoint.operationId,
|
|
503
678
|
responses: {
|
|
504
|
-
"200": createSuccessResponse(getContractSchemaName(endpoint.responseContract, contracts[endpoint.responseContract], endpoint, "response")
|
|
679
|
+
"200": createSuccessResponse(getContractSchemaName(endpoint.responseContract, contracts[endpoint.responseContract], endpoint, "response"), isBootstrapEndpoint
|
|
680
|
+
? createBootstrapResponseHeaders(normalizedAuth)
|
|
681
|
+
: undefined),
|
|
505
682
|
},
|
|
506
683
|
tags: [...endpoint.tags],
|
|
507
684
|
[WP_TYPIA_OPENAPI_EXTENSION_KEYS.AUTH_INTENT]: normalizedAuth.auth,
|
|
@@ -554,10 +731,13 @@ function buildEndpointOpenApiOperation(endpoint, contracts) {
|
|
|
554
731
|
*/
|
|
555
732
|
export function buildEndpointOpenApiDocument(options) {
|
|
556
733
|
const contractEntries = Object.entries(options.contracts);
|
|
557
|
-
const schemas = Object.fromEntries(contractEntries.map(([contractKey, contract]) =>
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
734
|
+
const schemas = Object.fromEntries(contractEntries.map(([contractKey, contract]) => {
|
|
735
|
+
const projectedSchema = projectJsonSchemaDocument(manifestToJsonSchema(contract.document), {
|
|
736
|
+
profile: "rest",
|
|
737
|
+
});
|
|
738
|
+
delete projectedSchema.$schema;
|
|
739
|
+
return [getContractSchemaName(contractKey, contract), projectedSchema];
|
|
740
|
+
}));
|
|
561
741
|
const paths = {};
|
|
562
742
|
const topLevelTags = [...new Set(options.endpoints.flatMap((endpoint) => endpoint.tags))]
|
|
563
743
|
.filter((tag) => typeof tag === "string" && tag.length > 0)
|
package/dist/validation.d.ts
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
import type { ManifestDefaultsDocument } from "./defaults.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
path: string;
|
|
6
|
-
value: unknown;
|
|
7
|
-
}
|
|
8
|
-
export interface ValidationResult<T> {
|
|
9
|
-
data?: T;
|
|
10
|
-
errors: TypiaValidationError[];
|
|
11
|
-
isValid: boolean;
|
|
12
|
-
}
|
|
2
|
+
import { type ValidationError as SharedValidationError, type ValidationResult as SharedValidationResult } from "@wp-typia/api-client/runtime-primitives";
|
|
3
|
+
export type TypiaValidationError = SharedValidationError;
|
|
4
|
+
export type ValidationResult<T> = SharedValidationResult<T>;
|
|
13
5
|
export interface ValidationState<T> extends ValidationResult<T> {
|
|
14
6
|
errorMessages: string[];
|
|
15
7
|
}
|
package/dist/validation.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { applyTemplateDefaultsFromManifest } from "./defaults.js";
|
|
2
|
-
import { isPlainObject as isRecord } from "
|
|
2
|
+
import { isPlainObject as isRecord, normalizeValidationError as normalizeSharedValidationError, toValidationResult as toSharedValidationResult, } from "@wp-typia/api-client/runtime-primitives";
|
|
3
3
|
const UNSAFE_PATH_SEGMENTS = new Set(["__proto__", "constructor", "prototype"]);
|
|
4
4
|
function getValueType(value) {
|
|
5
5
|
if (value === null) {
|
|
@@ -18,33 +18,10 @@ function redactValidationErrors(errors) {
|
|
|
18
18
|
}));
|
|
19
19
|
}
|
|
20
20
|
export function normalizeValidationError(error) {
|
|
21
|
-
|
|
22
|
-
? error
|
|
23
|
-
: {};
|
|
24
|
-
return {
|
|
25
|
-
description: typeof raw.description === "string" ? raw.description : undefined,
|
|
26
|
-
expected: typeof raw.expected === "string" ? raw.expected : "unknown",
|
|
27
|
-
path: typeof raw.path === "string" && raw.path.length > 0 ? raw.path : "(root)",
|
|
28
|
-
value: Object.prototype.hasOwnProperty.call(raw, "value") ? raw.value : undefined,
|
|
29
|
-
};
|
|
21
|
+
return normalizeSharedValidationError(error);
|
|
30
22
|
}
|
|
31
23
|
export function toValidationResult(result) {
|
|
32
|
-
|
|
33
|
-
? result
|
|
34
|
-
: undefined;
|
|
35
|
-
if (raw?.success === true) {
|
|
36
|
-
return {
|
|
37
|
-
data: raw.data,
|
|
38
|
-
errors: [],
|
|
39
|
-
isValid: true,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
const rawErrors = Array.isArray(raw?.errors) ? raw.errors : [];
|
|
43
|
-
return {
|
|
44
|
-
data: undefined,
|
|
45
|
-
errors: rawErrors.map(normalizeValidationError),
|
|
46
|
-
isValid: false,
|
|
47
|
-
};
|
|
24
|
+
return toSharedValidationResult(result);
|
|
48
25
|
}
|
|
49
26
|
export function formatValidationError(error) {
|
|
50
27
|
return `${error.path}: ${error.expected} expected, got ${getValueType(error.value)}`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wp-typia/block-runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "Generated-project runtime and metadata sync helpers for wp-typia",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -21,6 +21,31 @@
|
|
|
21
21
|
"import": "./dist/metadata-core.js",
|
|
22
22
|
"default": "./dist/metadata-core.js"
|
|
23
23
|
},
|
|
24
|
+
"./metadata-analysis": {
|
|
25
|
+
"types": "./dist/metadata-analysis.d.ts",
|
|
26
|
+
"import": "./dist/metadata-analysis.js",
|
|
27
|
+
"default": "./dist/metadata-analysis.js"
|
|
28
|
+
},
|
|
29
|
+
"./metadata-model": {
|
|
30
|
+
"types": "./dist/metadata-model.d.ts",
|
|
31
|
+
"import": "./dist/metadata-model.js",
|
|
32
|
+
"default": "./dist/metadata-model.js"
|
|
33
|
+
},
|
|
34
|
+
"./metadata-parser": {
|
|
35
|
+
"types": "./dist/metadata-parser.d.ts",
|
|
36
|
+
"import": "./dist/metadata-parser.js",
|
|
37
|
+
"default": "./dist/metadata-parser.js"
|
|
38
|
+
},
|
|
39
|
+
"./metadata-php-render": {
|
|
40
|
+
"types": "./dist/metadata-php-render.d.ts",
|
|
41
|
+
"import": "./dist/metadata-php-render.js",
|
|
42
|
+
"default": "./dist/metadata-php-render.js"
|
|
43
|
+
},
|
|
44
|
+
"./metadata-projection": {
|
|
45
|
+
"types": "./dist/metadata-projection.d.ts",
|
|
46
|
+
"import": "./dist/metadata-projection.js",
|
|
47
|
+
"default": "./dist/metadata-projection.js"
|
|
48
|
+
},
|
|
24
49
|
"./defaults": {
|
|
25
50
|
"types": "./dist/defaults.d.ts",
|
|
26
51
|
"import": "./dist/defaults.js",
|
|
@@ -31,6 +56,11 @@
|
|
|
31
56
|
"import": "./dist/editor.js",
|
|
32
57
|
"default": "./dist/editor.js"
|
|
33
58
|
},
|
|
59
|
+
"./identifiers": {
|
|
60
|
+
"types": "./dist/identifiers.d.ts",
|
|
61
|
+
"import": "./dist/identifiers.js",
|
|
62
|
+
"default": "./dist/identifiers.js"
|
|
63
|
+
},
|
|
34
64
|
"./inspector": {
|
|
35
65
|
"types": "./dist/inspector.d.ts",
|
|
36
66
|
"import": "./dist/inspector.js",
|
|
@@ -41,6 +71,11 @@
|
|
|
41
71
|
"import": "./dist/validation.js",
|
|
42
72
|
"default": "./dist/validation.js"
|
|
43
73
|
},
|
|
74
|
+
"./json-utils": {
|
|
75
|
+
"types": "./dist/json-utils.d.ts",
|
|
76
|
+
"import": "./dist/json-utils.js",
|
|
77
|
+
"default": "./dist/json-utils.js"
|
|
78
|
+
},
|
|
44
79
|
"./package.json": "./package.json"
|
|
45
80
|
},
|
|
46
81
|
"files": [
|
|
@@ -49,7 +84,7 @@
|
|
|
49
84
|
"package.json"
|
|
50
85
|
],
|
|
51
86
|
"scripts": {
|
|
52
|
-
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
87
|
+
"build": "bun run --filter @wp-typia/api-client build && rm -rf dist && tsc -p tsconfig.build.json",
|
|
53
88
|
"clean": "rm -rf dist",
|
|
54
89
|
"test:prepare": "bun run build",
|
|
55
90
|
"test": "bun run test:prepare && bun test tests",
|
|
@@ -73,7 +108,7 @@
|
|
|
73
108
|
"engines": {
|
|
74
109
|
"node": ">=20.0.0",
|
|
75
110
|
"npm": ">=10.0.0",
|
|
76
|
-
"bun": ">=1.3.
|
|
111
|
+
"bun": ">=1.3.11"
|
|
77
112
|
},
|
|
78
113
|
"peerDependencies": {
|
|
79
114
|
"react": "^18.0.0 || ^19.0.0"
|
|
@@ -84,6 +119,7 @@
|
|
|
84
119
|
}
|
|
85
120
|
},
|
|
86
121
|
"dependencies": {
|
|
122
|
+
"@wp-typia/api-client": "^0.4.2",
|
|
87
123
|
"typescript": "^5.9.2"
|
|
88
124
|
},
|
|
89
125
|
"devDependencies": {
|