@wp-typia/block-runtime 0.3.0 → 0.4.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/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
- `@wp-typia/create` remains the CLI/scaffolding package.
28
+ `wp-typia` remains the CLI package.
29
29
 
30
- `@wp-typia/create/metadata-core` and `@wp-typia/create/runtime/*` remain
31
- available as backward-compatible facades, but newly generated projects should
32
- prefer `@wp-typia/block-runtime/*` and
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.js").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.js").JSX.Element;
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wp-typia/block-runtime",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Generated-project runtime and metadata sync helpers for wp-typia",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -31,6 +31,11 @@
31
31
  "import": "./dist/editor.js",
32
32
  "default": "./dist/editor.js"
33
33
  },
34
+ "./identifiers": {
35
+ "types": "./dist/identifiers.d.ts",
36
+ "import": "./dist/identifiers.js",
37
+ "default": "./dist/identifiers.js"
38
+ },
34
39
  "./inspector": {
35
40
  "types": "./dist/inspector.d.ts",
36
41
  "import": "./dist/inspector.js",