@wp-typia/project-tools 0.16.0 → 0.16.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.
Files changed (24) hide show
  1. package/README.md +6 -0
  2. package/dist/runtime/cli-help.js +1 -1
  3. package/dist/runtime/package-versions.js +7 -2
  4. package/dist/runtime/scaffold.js +21 -13
  5. package/dist/runtime/schema-core.d.ts +5 -266
  6. package/dist/runtime/schema-core.js +5 -775
  7. package/package.json +56 -3
  8. package/templates/_shared/compound/core/scripts/add-compound-child.ts.mustache +42 -28
  9. package/templates/_shared/compound/persistence/src/blocks/{{slugKebabCase}}/interactivity.ts.mustache +8 -0
  10. package/templates/_shared/compound/persistence-auth/{{slugKebabCase}}.php.mustache +5 -5
  11. package/templates/_shared/compound/persistence-public/{{slugKebabCase}}.php.mustache +5 -5
  12. package/templates/_shared/persistence/auth/{{slugKebabCase}}.php.mustache +5 -5
  13. package/templates/_shared/persistence/core/src/interactivity.ts.mustache +5 -0
  14. package/templates/_shared/persistence/core/{{slugKebabCase}}.php.mustache +5 -5
  15. package/templates/_shared/persistence/public/{{slugKebabCase}}.php.mustache +5 -5
  16. package/templates/_shared/workspace/persistence-auth/server.php.mustache +7 -5
  17. package/templates/_shared/workspace/persistence-public/server.php.mustache +7 -5
  18. package/templates/compound/src/blocks/{{slugKebabCase}}/types.ts.mustache +5 -0
  19. package/templates/compound/src/blocks/{{slugKebabCase}}/validators.ts.mustache +10 -3
  20. package/templates/compound/src/blocks/{{slugKebabCase}}-item/types.ts.mustache +5 -0
  21. package/templates/compound/src/blocks/{{slugKebabCase}}-item/validators.ts.mustache +10 -3
  22. package/templates/interactivity/src/edit.tsx.mustache +1 -1
  23. package/templates/interactivity/src/save.tsx.mustache +1 -1
  24. package/templates/persistence/src/edit.tsx.mustache +2 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wp-typia/project-tools",
3
- "version": "0.16.0",
3
+ "version": "0.16.2",
4
4
  "description": "Project orchestration and programmatic tooling for wp-typia",
5
5
  "packageManager": "bun@1.3.11",
6
6
  "type": "module",
@@ -12,11 +12,56 @@
12
12
  "import": "./dist/runtime/index.js",
13
13
  "default": "./dist/runtime/index.js"
14
14
  },
15
+ "./cli-add": {
16
+ "types": "./dist/runtime/cli-add.d.ts",
17
+ "import": "./dist/runtime/cli-add.js",
18
+ "default": "./dist/runtime/cli-add.js"
19
+ },
20
+ "./cli-doctor": {
21
+ "types": "./dist/runtime/cli-doctor.d.ts",
22
+ "import": "./dist/runtime/cli-doctor.js",
23
+ "default": "./dist/runtime/cli-doctor.js"
24
+ },
25
+ "./cli-prompt": {
26
+ "types": "./dist/runtime/cli-prompt.d.ts",
27
+ "import": "./dist/runtime/cli-prompt.js",
28
+ "default": "./dist/runtime/cli-prompt.js"
29
+ },
30
+ "./cli-scaffold": {
31
+ "types": "./dist/runtime/cli-scaffold.d.ts",
32
+ "import": "./dist/runtime/cli-scaffold.js",
33
+ "default": "./dist/runtime/cli-scaffold.js"
34
+ },
35
+ "./cli-templates": {
36
+ "types": "./dist/runtime/cli-templates.d.ts",
37
+ "import": "./dist/runtime/cli-templates.js",
38
+ "default": "./dist/runtime/cli-templates.js"
39
+ },
40
+ "./hooked-blocks": {
41
+ "types": "./dist/runtime/hooked-blocks.d.ts",
42
+ "import": "./dist/runtime/hooked-blocks.js",
43
+ "default": "./dist/runtime/hooked-blocks.js"
44
+ },
45
+ "./migrations": {
46
+ "types": "./dist/runtime/migrations.d.ts",
47
+ "import": "./dist/runtime/migrations.js",
48
+ "default": "./dist/runtime/migrations.js"
49
+ },
50
+ "./package-managers": {
51
+ "types": "./dist/runtime/package-managers.d.ts",
52
+ "import": "./dist/runtime/package-managers.js",
53
+ "default": "./dist/runtime/package-managers.js"
54
+ },
15
55
  "./schema-core": {
16
56
  "types": "./dist/runtime/schema-core.d.ts",
17
57
  "import": "./dist/runtime/schema-core.js",
18
58
  "default": "./dist/runtime/schema-core.js"
19
59
  },
60
+ "./workspace-project": {
61
+ "types": "./dist/runtime/workspace-project.d.ts",
62
+ "import": "./dist/runtime/workspace-project.js",
63
+ "default": "./dist/runtime/workspace-project.js"
64
+ },
20
65
  "./package.json": "./package.json"
21
66
  },
22
67
  "files": [
@@ -27,10 +72,18 @@
27
72
  ],
28
73
  "scripts": {
29
74
  "build": "bun run --filter @wp-typia/api-client build && bun run --filter @wp-typia/block-runtime build && rm -rf dist && tsc -p tsconfig.runtime.json",
75
+ "prepack": "bun run build && node ./scripts/publish-manifest.mjs prepare",
76
+ "postpack": "node ./scripts/publish-manifest.mjs restore",
30
77
  "test": "bun run build && bun test tests/*.test.ts",
78
+ "test:scaffold-core": "bun run build && bun test tests/scaffold-basic.test.ts tests/scaffold-persistence.test.ts tests/template-source.test.ts tests/cli-entry.test.ts tests/import-policy.test.ts",
79
+ "test:workspace": "bun run build && bun test tests/workspace-add.test.ts tests/workspace-doctor.test.ts",
80
+ "test:compound": "bun run build && bun test tests/scaffold-compound.test.ts",
81
+ "test:migration-planning": "bun run build && bun test tests/migration-init.test.ts tests/migration-config.test.ts tests/migration-plan-wizard.test.ts",
82
+ "test:migration-execution": "bun run build && bun test tests/migration-scaffold-diff.test.ts tests/migration-doctor.test.ts tests/migration-fixtures-fuzz.test.ts",
83
+ "test:project-tools": "bun run test:scaffold-core && bun run test:workspace && bun run test:compound && bun run test:migration-planning && bun run test:migration-execution",
31
84
  "test:coverage": "bun run build && bun test tests/*.test.ts --coverage --coverage-reporter=lcov --coverage-dir=coverage",
32
85
  "clean": "rm -rf dist",
33
- "prepack": "bun run build"
86
+ "prepublishOnly": "bun run build"
34
87
  },
35
88
  "keywords": [
36
89
  "wordpress",
@@ -62,7 +115,7 @@
62
115
  },
63
116
  "dependencies": {
64
117
  "@wp-typia/api-client": "^0.4.2",
65
- "@wp-typia/block-runtime": "^0.4.3",
118
+ "@wp-typia/block-runtime": "^0.4.5",
66
119
  "@wp-typia/rest": "^0.3.5",
67
120
  "@wp-typia/block-types": "^0.2.1",
68
121
  "mustache": "^4.2.0",
@@ -346,8 +346,15 @@ function renderBlockJson(
346
346
  ) }\n`;
347
347
  }
348
348
 
349
- function renderTypesFile( childTypeName: string, childTitle: string ): string {
350
- return `import { tags } from 'typia';
349
+ function renderTypesFile(
350
+ childTypeName: string,
351
+ childInterfaceName: string,
352
+ childTitle: string
353
+ ): string {
354
+ return `import type { ValidationResult } from '@wp-typia/block-runtime/validation';
355
+ import { tags } from 'typia';
356
+
357
+ export type { ValidationResult } from '@wp-typia/block-runtime/validation';
351
358
 
352
359
  export interface ${ childTypeName } {
353
360
  \ttitle: string &
@@ -359,6 +366,8 @@ export interface ${ childTypeName } {
359
366
  \t\ttags.MaxLength< 280 > &
360
367
  \t\ttags.Default< ${ JSON.stringify( CHILD_PLACEHOLDER ) } >;
361
368
  }
369
+
370
+ export type ${ childInterfaceName }ValidationResult = ValidationResult< ${ childTypeName } >;
362
371
  `;
363
372
  }
364
373
 
@@ -407,36 +416,37 @@ function renderValidatorsFile(
407
416
  ): string {
408
417
  return `import typia from 'typia';
409
418
  import currentManifest from './typia.manifest.json';
410
- import {
411
- \ttype ManifestDefaultsDocument,
412
- } from '@wp-typia/block-runtime/defaults';
413
- import {
414
- \tcreateScaffoldValidatorToolkit,
415
- } from '@wp-typia/block-runtime/validation';
416
-
417
- import type { ${ childTypeName } } from './types';
418
-
419
- const validate = typia.createValidate< ${ childTypeName } >();
420
- const assert = typia.createAssert< ${ childTypeName } >();
421
- const is = typia.createIs< ${ childTypeName } >();
422
- const random = typia.createRandom< ${ childTypeName } >();
423
- const clone = typia.misc.createClone< ${ childTypeName } >();
424
- const prune = typia.misc.createPrune< ${ childTypeName } >();
425
- const scaffoldValidators = createScaffoldValidatorToolkit< ${ childTypeName } >( {
426
- \tmanifest: currentManifest as ManifestDefaultsDocument,
427
- \tvalidate,
428
- \tassert,
429
- \tis,
430
- \trandom,
431
- \tclone,
432
- \tprune,
419
+ import type {
420
+ \t${ childTypeName },
421
+ \t${ childInterfaceName }ValidationResult,
422
+ } from './types';
423
+ import { createTemplateValidatorToolkit } from '../../validator-toolkit';
424
+
425
+ const scaffoldValidators = createTemplateValidatorToolkit< ${ childTypeName } >( {
426
+ \tassert: typia.createAssert< ${ childTypeName } >(),
427
+ \tclone: typia.misc.createClone< ${ childTypeName } >() as (
428
+ \t\tvalue: ${ childTypeName },
429
+ \t) => ${ childTypeName },
430
+ \tis: typia.createIs< ${ childTypeName } >(),
431
+ \tmanifest: currentManifest,
432
+ \tprune: typia.misc.createPrune< ${ childTypeName } >(),
433
+ \trandom: typia.createRandom< ${ childTypeName } >() as (
434
+ \t\t...args: unknown[]
435
+ \t) => ${ childTypeName },
436
+ \tvalidate: typia.createValidate< ${ childTypeName } >(),
433
437
  } );
434
438
 
435
- export const validate${ childInterfaceName } = scaffoldValidators.validateAttributes;
439
+ export const validate${ childInterfaceName } =
440
+ \tscaffoldValidators.validateAttributes as (
441
+ \t\tattributes: unknown
442
+ \t) => ${ childInterfaceName }ValidationResult;
436
443
 
437
444
  export const validators = scaffoldValidators.validators;
438
445
 
439
- export const sanitize${ childInterfaceName } = scaffoldValidators.sanitizeAttributes;
446
+ export const sanitize${ childInterfaceName } =
447
+ \tscaffoldValidators.sanitizeAttributes as (
448
+ \t\tattributes: Partial< ${ childTypeName } >
449
+ \t) => ${ childTypeName };
440
450
 
441
451
  export const createAttributeUpdater = scaffoldValidators.createAttributeUpdater;
442
452
  `;
@@ -605,7 +615,11 @@ function main() {
605
615
  renderBlockJson( childBlockName, childFolderSlug, childTitle ),
606
616
  'utf8'
607
617
  );
608
- fs.writeFileSync( path.join( childDir, 'types.ts' ), renderTypesFile( childTypeName, childTitle ), 'utf8' );
618
+ fs.writeFileSync(
619
+ path.join( childDir, 'types.ts' ),
620
+ renderTypesFile( childTypeName, childInterfaceName, childTitle ),
621
+ 'utf8'
622
+ );
609
623
  fs.writeFileSync(
610
624
  path.join( childDir, 'typia.manifest.json' ),
611
625
  renderStarterManifestFile( childTypeName, childTitle ),
@@ -123,6 +123,8 @@ const { actions, state } = store( '{{slugKebabCase}}', {
123
123
  let bootstrapSucceeded = false;
124
124
  let lastBootstrapError =
125
125
  'Unable to initialize write access';
126
+ const includePublicWriteCredentials = {{isPublicPersistencePolicy}};
127
+ const includeRestNonce = {{isAuthenticatedPersistencePolicy}};
126
128
 
127
129
  for ( let attempt = 1; attempt <= BOOTSTRAP_MAX_ATTEMPTS; attempt += 1 ) {
128
130
  try {
@@ -146,16 +148,22 @@ const { actions, state } = store( '{{slugKebabCase}}', {
146
148
  }
147
149
 
148
150
  clientState.writeExpiry =
151
+ includePublicWriteCredentials &&
152
+ 'publicWriteExpiresAt' in result.data &&
149
153
  typeof result.data.publicWriteExpiresAt === 'number' &&
150
154
  result.data.publicWriteExpiresAt > 0
151
155
  ? result.data.publicWriteExpiresAt
152
156
  : 0;
153
157
  clientState.writeToken =
158
+ includePublicWriteCredentials &&
159
+ 'publicWriteToken' in result.data &&
154
160
  typeof result.data.publicWriteToken === 'string' &&
155
161
  result.data.publicWriteToken.length > 0
156
162
  ? result.data.publicWriteToken
157
163
  : '';
158
164
  clientState.writeNonce =
165
+ includeRestNonce &&
166
+ 'restNonce' in result.data &&
159
167
  typeof result.data.restNonce === 'string' &&
160
168
  result.data.restNonce.length > 0
161
169
  ? result.data.restNonce
@@ -79,7 +79,7 @@ function {{phpPrefix}}_with_counter_lock( $post_id, $resource_key, $callback ) {
79
79
  }
80
80
 
81
81
  function {{phpPrefix}}_maybe_install_storage() {
82
- if ( 'custom-table' !== '{{dataStorageMode}}' ) {
82
+ if ( 'custom-table' !== {{phpPrefixUpper}}_DATA_STORAGE_MODE ) {
83
83
  return;
84
84
  }
85
85
 
@@ -110,7 +110,7 @@ function {{phpPrefix}}_maybe_install_storage() {
110
110
  }
111
111
 
112
112
  function {{phpPrefix}}_ensure_storage_installed() {
113
- if ( 'custom-table' === '{{dataStorageMode}}' && '1.0.0' !== get_option( '{{phpPrefix}}_storage_version', '' ) ) {
113
+ if ( 'custom-table' === {{phpPrefixUpper}}_DATA_STORAGE_MODE && '1.0.0' !== get_option( '{{phpPrefix}}_storage_version', '' ) ) {
114
114
  {{phpPrefix}}_maybe_install_storage();
115
115
  }
116
116
  }
@@ -122,7 +122,7 @@ function {{phpPrefix}}_get_rest_build_dir() {
122
122
  function {{phpPrefix}}_get_counter( $post_id, $resource_key ) {
123
123
  global $wpdb;
124
124
 
125
- if ( 'custom-table' === '{{dataStorageMode}}' ) {
125
+ if ( 'custom-table' === {{phpPrefixUpper}}_DATA_STORAGE_MODE ) {
126
126
  $table_name = {{phpPrefix}}_get_counter_table_name();
127
127
  $count = $wpdb->get_var(
128
128
  $wpdb->prepare(
@@ -144,7 +144,7 @@ function {{phpPrefix}}_get_counter( $post_id, $resource_key ) {
144
144
  function {{phpPrefix}}_increment_counter( $post_id, $resource_key, $delta ) {
145
145
  global $wpdb;
146
146
 
147
- if ( 'custom-table' === '{{dataStorageMode}}' ) {
147
+ if ( 'custom-table' === {{phpPrefixUpper}}_DATA_STORAGE_MODE ) {
148
148
  $table_name = {{phpPrefix}}_get_counter_table_name();
149
149
  $delta_value = (int) $delta;
150
150
  $initial_count = max( 0, $delta_value );
@@ -188,7 +188,7 @@ function {{phpPrefix}}_build_state_response( $post_id, $resource_key, $count ) {
188
188
  'postId' => (int) $post_id,
189
189
  'resourceKey' => (string) $resource_key,
190
190
  'count' => (int) $count,
191
- 'storage' => '{{dataStorageMode}}',
191
+ 'storage' => {{phpPrefixUpper}}_DATA_STORAGE_MODE,
192
192
  );
193
193
  }
194
194
 
@@ -82,7 +82,7 @@ function {{phpPrefix}}_with_counter_lock( $post_id, $resource_key, $callback ) {
82
82
  }
83
83
 
84
84
  function {{phpPrefix}}_maybe_install_storage() {
85
- if ( 'custom-table' !== '{{dataStorageMode}}' ) {
85
+ if ( 'custom-table' !== {{phpPrefixUpper}}_DATA_STORAGE_MODE ) {
86
86
  return;
87
87
  }
88
88
 
@@ -113,7 +113,7 @@ function {{phpPrefix}}_maybe_install_storage() {
113
113
  }
114
114
 
115
115
  function {{phpPrefix}}_ensure_storage_installed() {
116
- if ( 'custom-table' === '{{dataStorageMode}}' && '1.0.0' !== get_option( '{{phpPrefix}}_storage_version', '' ) ) {
116
+ if ( 'custom-table' === {{phpPrefixUpper}}_DATA_STORAGE_MODE && '1.0.0' !== get_option( '{{phpPrefix}}_storage_version', '' ) ) {
117
117
  {{phpPrefix}}_maybe_install_storage();
118
118
  }
119
119
  }
@@ -125,7 +125,7 @@ function {{phpPrefix}}_get_rest_build_dir() {
125
125
  function {{phpPrefix}}_get_counter( $post_id, $resource_key ) {
126
126
  global $wpdb;
127
127
 
128
- if ( 'custom-table' === '{{dataStorageMode}}' ) {
128
+ if ( 'custom-table' === {{phpPrefixUpper}}_DATA_STORAGE_MODE ) {
129
129
  $table_name = {{phpPrefix}}_get_counter_table_name();
130
130
  $count = $wpdb->get_var(
131
131
  $wpdb->prepare(
@@ -147,7 +147,7 @@ function {{phpPrefix}}_get_counter( $post_id, $resource_key ) {
147
147
  function {{phpPrefix}}_increment_counter( $post_id, $resource_key, $delta ) {
148
148
  global $wpdb;
149
149
 
150
- if ( 'custom-table' === '{{dataStorageMode}}' ) {
150
+ if ( 'custom-table' === {{phpPrefixUpper}}_DATA_STORAGE_MODE ) {
151
151
  $table_name = {{phpPrefix}}_get_counter_table_name();
152
152
  $delta_value = (int) $delta;
153
153
  $initial_count = max( 0, $delta_value );
@@ -191,7 +191,7 @@ function {{phpPrefix}}_build_state_response( $post_id, $resource_key, $count ) {
191
191
  'postId' => (int) $post_id,
192
192
  'resourceKey' => (string) $resource_key,
193
193
  'count' => (int) $count,
194
- 'storage' => '{{dataStorageMode}}',
194
+ 'storage' => {{phpPrefixUpper}}_DATA_STORAGE_MODE,
195
195
  );
196
196
  }
197
197
 
@@ -84,7 +84,7 @@ function {{phpPrefix}}_with_counter_lock( $post_id, $resource_key, $callback ) {
84
84
  }
85
85
 
86
86
  function {{phpPrefix}}_maybe_install_storage() {
87
- if ( 'custom-table' !== '{{dataStorageMode}}' ) {
87
+ if ( 'custom-table' !== {{phpPrefixUpper}}_DATA_STORAGE_MODE ) {
88
88
  return;
89
89
  }
90
90
 
@@ -115,7 +115,7 @@ function {{phpPrefix}}_maybe_install_storage() {
115
115
  }
116
116
 
117
117
  function {{phpPrefix}}_ensure_storage_installed() {
118
- if ( 'custom-table' === '{{dataStorageMode}}' && '1.0.0' !== get_option( '{{phpPrefix}}_storage_version', '' ) ) {
118
+ if ( 'custom-table' === {{phpPrefixUpper}}_DATA_STORAGE_MODE && '1.0.0' !== get_option( '{{phpPrefix}}_storage_version', '' ) ) {
119
119
  {{phpPrefix}}_maybe_install_storage();
120
120
  }
121
121
  }
@@ -127,7 +127,7 @@ function {{phpPrefix}}_get_rest_build_dir() {
127
127
  function {{phpPrefix}}_get_counter( $post_id, $resource_key ) {
128
128
  global $wpdb;
129
129
 
130
- if ( 'custom-table' === '{{dataStorageMode}}' ) {
130
+ if ( 'custom-table' === {{phpPrefixUpper}}_DATA_STORAGE_MODE ) {
131
131
  $table_name = {{phpPrefix}}_get_counter_table_name();
132
132
  $count = $wpdb->get_var(
133
133
  $wpdb->prepare(
@@ -149,7 +149,7 @@ function {{phpPrefix}}_get_counter( $post_id, $resource_key ) {
149
149
  function {{phpPrefix}}_increment_counter( $post_id, $resource_key, $delta ) {
150
150
  global $wpdb;
151
151
 
152
- if ( 'custom-table' === '{{dataStorageMode}}' ) {
152
+ if ( 'custom-table' === {{phpPrefixUpper}}_DATA_STORAGE_MODE ) {
153
153
  $table_name = {{phpPrefix}}_get_counter_table_name();
154
154
  $delta_value = (int) $delta;
155
155
  $initial_count = max( 0, $delta_value );
@@ -193,7 +193,7 @@ function {{phpPrefix}}_build_state_response( $post_id, $resource_key, $count ) {
193
193
  'postId' => (int) $post_id,
194
194
  'resourceKey' => (string) $resource_key,
195
195
  'count' => (int) $count,
196
- 'storage' => '{{dataStorageMode}}',
196
+ 'storage' => {{phpPrefixUpper}}_DATA_STORAGE_MODE,
197
197
  );
198
198
  }
199
199
 
@@ -126,6 +126,7 @@ const { actions, state } = store( '{{slugKebabCase}}', {
126
126
  let bootstrapSucceeded = false;
127
127
  let lastBootstrapError =
128
128
  'Unable to initialize write access';
129
+ const includePublicWriteCredentials = {{isPublicPersistencePolicy}};
129
130
  const includeRestNonce = {{isAuthenticatedPersistencePolicy}};
130
131
 
131
132
  for ( let attempt = 1; attempt <= BOOTSTRAP_MAX_ATTEMPTS; attempt += 1 ) {
@@ -150,11 +151,15 @@ const { actions, state } = store( '{{slugKebabCase}}', {
150
151
  }
151
152
 
152
153
  clientState.writeExpiry =
154
+ includePublicWriteCredentials &&
155
+ 'publicWriteExpiresAt' in result.data &&
153
156
  typeof result.data.publicWriteExpiresAt === 'number' &&
154
157
  result.data.publicWriteExpiresAt > 0
155
158
  ? result.data.publicWriteExpiresAt
156
159
  : 0;
157
160
  clientState.writeToken =
161
+ includePublicWriteCredentials &&
162
+ 'publicWriteToken' in result.data &&
158
163
  typeof result.data.publicWriteToken === 'string' &&
159
164
  result.data.publicWriteToken.length > 0
160
165
  ? result.data.publicWriteToken
@@ -81,7 +81,7 @@ function {{phpPrefix}}_with_counter_lock( $post_id, $resource_key, $callback ) {
81
81
  }
82
82
 
83
83
  function {{phpPrefix}}_maybe_install_storage() {
84
- if ( 'custom-table' !== '{{dataStorageMode}}' ) {
84
+ if ( 'custom-table' !== {{phpPrefixUpper}}_DATA_STORAGE_MODE ) {
85
85
  return;
86
86
  }
87
87
 
@@ -112,7 +112,7 @@ function {{phpPrefix}}_maybe_install_storage() {
112
112
  }
113
113
 
114
114
  function {{phpPrefix}}_ensure_storage_installed() {
115
- if ( 'custom-table' === '{{dataStorageMode}}' && '1.0.0' !== get_option( '{{phpPrefix}}_storage_version', '' ) ) {
115
+ if ( 'custom-table' === {{phpPrefixUpper}}_DATA_STORAGE_MODE && '1.0.0' !== get_option( '{{phpPrefix}}_storage_version', '' ) ) {
116
116
  {{phpPrefix}}_maybe_install_storage();
117
117
  }
118
118
  }
@@ -170,7 +170,7 @@ function {{phpPrefix}}_validate_and_sanitize_request( $value, $schema_name, $par
170
170
  function {{phpPrefix}}_get_counter( $post_id, $resource_key ) {
171
171
  global $wpdb;
172
172
 
173
- if ( 'custom-table' === '{{dataStorageMode}}' ) {
173
+ if ( 'custom-table' === {{phpPrefixUpper}}_DATA_STORAGE_MODE ) {
174
174
  $table_name = {{phpPrefix}}_get_counter_table_name();
175
175
  $count = $wpdb->get_var(
176
176
  $wpdb->prepare(
@@ -191,7 +191,7 @@ function {{phpPrefix}}_get_counter( $post_id, $resource_key ) {
191
191
  function {{phpPrefix}}_increment_counter( $post_id, $resource_key, $delta ) {
192
192
  global $wpdb;
193
193
 
194
- if ( 'custom-table' === '{{dataStorageMode}}' ) {
194
+ if ( 'custom-table' === {{phpPrefixUpper}}_DATA_STORAGE_MODE ) {
195
195
  $table_name = {{phpPrefix}}_get_counter_table_name();
196
196
  $delta_value = (int) $delta;
197
197
  $initial_count = max( 0, $delta_value );
@@ -235,7 +235,7 @@ function {{phpPrefix}}_build_state_response( $post_id, $resource_key, $count ) {
235
235
  'postId' => (int) $post_id,
236
236
  'resourceKey' => (string) $resource_key,
237
237
  'count' => (int) $count,
238
- 'storage' => '{{dataStorageMode}}',
238
+ 'storage' => {{phpPrefixUpper}}_DATA_STORAGE_MODE,
239
239
  );
240
240
  }
241
241
 
@@ -87,7 +87,7 @@ function {{phpPrefix}}_with_counter_lock( $post_id, $resource_key, $callback ) {
87
87
  }
88
88
 
89
89
  function {{phpPrefix}}_maybe_install_storage() {
90
- if ( 'custom-table' !== '{{dataStorageMode}}' ) {
90
+ if ( 'custom-table' !== {{phpPrefixUpper}}_DATA_STORAGE_MODE ) {
91
91
  return;
92
92
  }
93
93
 
@@ -118,7 +118,7 @@ function {{phpPrefix}}_maybe_install_storage() {
118
118
  }
119
119
 
120
120
  function {{phpPrefix}}_ensure_storage_installed() {
121
- if ( 'custom-table' === '{{dataStorageMode}}' && '1.0.0' !== get_option( '{{phpPrefix}}_storage_version', '' ) ) {
121
+ if ( 'custom-table' === {{phpPrefixUpper}}_DATA_STORAGE_MODE && '1.0.0' !== get_option( '{{phpPrefix}}_storage_version', '' ) ) {
122
122
  {{phpPrefix}}_maybe_install_storage();
123
123
  }
124
124
  }
@@ -130,7 +130,7 @@ function {{phpPrefix}}_get_rest_build_dir() {
130
130
  function {{phpPrefix}}_get_counter( $post_id, $resource_key ) {
131
131
  global $wpdb;
132
132
 
133
- if ( 'custom-table' === '{{dataStorageMode}}' ) {
133
+ if ( 'custom-table' === {{phpPrefixUpper}}_DATA_STORAGE_MODE ) {
134
134
  $table_name = {{phpPrefix}}_get_counter_table_name();
135
135
  $count = $wpdb->get_var(
136
136
  $wpdb->prepare(
@@ -152,7 +152,7 @@ function {{phpPrefix}}_get_counter( $post_id, $resource_key ) {
152
152
  function {{phpPrefix}}_increment_counter( $post_id, $resource_key, $delta ) {
153
153
  global $wpdb;
154
154
 
155
- if ( 'custom-table' === '{{dataStorageMode}}' ) {
155
+ if ( 'custom-table' === {{phpPrefixUpper}}_DATA_STORAGE_MODE ) {
156
156
  $table_name = {{phpPrefix}}_get_counter_table_name();
157
157
  $delta_value = (int) $delta;
158
158
  $initial_count = max( 0, $delta_value );
@@ -196,7 +196,7 @@ function {{phpPrefix}}_build_state_response( $post_id, $resource_key, $count ) {
196
196
  'postId' => (int) $post_id,
197
197
  'resourceKey' => (string) $resource_key,
198
198
  'count' => (int) $count,
199
- 'storage' => '{{dataStorageMode}}',
199
+ 'storage' => {{phpPrefixUpper}}_DATA_STORAGE_MODE,
200
200
  );
201
201
  }
202
202
 
@@ -7,6 +7,8 @@ if ( ! defined( 'ABSPATH' ) ) {
7
7
  require_once __DIR__ . '/inc/rest-shared.php';
8
8
  require_once __DIR__ . '/inc/rest-auth.php';
9
9
 
10
+ define( '{{phpPrefixUpper}}_DATA_STORAGE_MODE', '{{dataStorageMode}}' );
11
+
10
12
  function {{phpPrefix}}_get_rest_build_dir() {
11
13
  return dirname( __DIR__, 3 ) . '/build/blocks/{{slugKebabCase}}';
12
14
  }
@@ -50,7 +52,7 @@ function {{phpPrefix}}_with_counter_lock( $post_id, $resource_key, $callback ) {
50
52
  }
51
53
 
52
54
  function {{phpPrefix}}_maybe_install_storage() {
53
- if ( 'custom-table' !== '{{dataStorageMode}}' ) {
55
+ if ( 'custom-table' !== {{phpPrefixUpper}}_DATA_STORAGE_MODE ) {
54
56
  return;
55
57
  }
56
58
 
@@ -81,7 +83,7 @@ function {{phpPrefix}}_maybe_install_storage() {
81
83
  }
82
84
 
83
85
  function {{phpPrefix}}_ensure_storage_installed() {
84
- if ( 'custom-table' === '{{dataStorageMode}}' && '1.0.0' !== get_option( '{{phpPrefix}}_storage_version', '' ) ) {
86
+ if ( 'custom-table' === {{phpPrefixUpper}}_DATA_STORAGE_MODE && '1.0.0' !== get_option( '{{phpPrefix}}_storage_version', '' ) ) {
85
87
  {{phpPrefix}}_maybe_install_storage();
86
88
  }
87
89
  }
@@ -89,7 +91,7 @@ function {{phpPrefix}}_ensure_storage_installed() {
89
91
  function {{phpPrefix}}_get_counter( $post_id, $resource_key ) {
90
92
  global $wpdb;
91
93
 
92
- if ( 'custom-table' === '{{dataStorageMode}}' ) {
94
+ if ( 'custom-table' === {{phpPrefixUpper}}_DATA_STORAGE_MODE ) {
93
95
  $table_name = {{phpPrefix}}_get_counter_table_name();
94
96
  $count = $wpdb->get_var(
95
97
  $wpdb->prepare(
@@ -110,7 +112,7 @@ function {{phpPrefix}}_get_counter( $post_id, $resource_key ) {
110
112
  function {{phpPrefix}}_increment_counter( $post_id, $resource_key, $delta ) {
111
113
  global $wpdb;
112
114
 
113
- if ( 'custom-table' === '{{dataStorageMode}}' ) {
115
+ if ( 'custom-table' === {{phpPrefixUpper}}_DATA_STORAGE_MODE ) {
114
116
  $table_name = {{phpPrefix}}_get_counter_table_name();
115
117
  $delta_value = (int) $delta;
116
118
  $initial_count = max( 0, $delta_value );
@@ -154,7 +156,7 @@ function {{phpPrefix}}_build_state_response( $post_id, $resource_key, $count ) {
154
156
  'postId' => (int) $post_id,
155
157
  'resourceKey' => (string) $resource_key,
156
158
  'count' => (int) $count,
157
- 'storage' => '{{dataStorageMode}}',
159
+ 'storage' => {{phpPrefixUpper}}_DATA_STORAGE_MODE,
158
160
  );
159
161
  }
160
162
 
@@ -7,6 +7,8 @@ if ( ! defined( 'ABSPATH' ) ) {
7
7
  require_once __DIR__ . '/inc/rest-shared.php';
8
8
  require_once __DIR__ . '/inc/rest-public.php';
9
9
 
10
+ define( '{{phpPrefixUpper}}_DATA_STORAGE_MODE', '{{dataStorageMode}}' );
11
+
10
12
  function {{phpPrefix}}_get_rest_build_dir() {
11
13
  return dirname( __DIR__, 3 ) . '/build/blocks/{{slugKebabCase}}';
12
14
  }
@@ -50,7 +52,7 @@ function {{phpPrefix}}_with_counter_lock( $post_id, $resource_key, $callback ) {
50
52
  }
51
53
 
52
54
  function {{phpPrefix}}_maybe_install_storage() {
53
- if ( 'custom-table' !== '{{dataStorageMode}}' ) {
55
+ if ( 'custom-table' !== {{phpPrefixUpper}}_DATA_STORAGE_MODE ) {
54
56
  return;
55
57
  }
56
58
 
@@ -81,7 +83,7 @@ function {{phpPrefix}}_maybe_install_storage() {
81
83
  }
82
84
 
83
85
  function {{phpPrefix}}_ensure_storage_installed() {
84
- if ( 'custom-table' === '{{dataStorageMode}}' && '1.0.0' !== get_option( '{{phpPrefix}}_storage_version', '' ) ) {
86
+ if ( 'custom-table' === {{phpPrefixUpper}}_DATA_STORAGE_MODE && '1.0.0' !== get_option( '{{phpPrefix}}_storage_version', '' ) ) {
85
87
  {{phpPrefix}}_maybe_install_storage();
86
88
  }
87
89
  }
@@ -89,7 +91,7 @@ function {{phpPrefix}}_ensure_storage_installed() {
89
91
  function {{phpPrefix}}_get_counter( $post_id, $resource_key ) {
90
92
  global $wpdb;
91
93
 
92
- if ( 'custom-table' === '{{dataStorageMode}}' ) {
94
+ if ( 'custom-table' === {{phpPrefixUpper}}_DATA_STORAGE_MODE ) {
93
95
  $table_name = {{phpPrefix}}_get_counter_table_name();
94
96
  $count = $wpdb->get_var(
95
97
  $wpdb->prepare(
@@ -110,7 +112,7 @@ function {{phpPrefix}}_get_counter( $post_id, $resource_key ) {
110
112
  function {{phpPrefix}}_increment_counter( $post_id, $resource_key, $delta ) {
111
113
  global $wpdb;
112
114
 
113
- if ( 'custom-table' === '{{dataStorageMode}}' ) {
115
+ if ( 'custom-table' === {{phpPrefixUpper}}_DATA_STORAGE_MODE ) {
114
116
  $table_name = {{phpPrefix}}_get_counter_table_name();
115
117
  $delta_value = (int) $delta;
116
118
  $initial_count = max( 0, $delta_value );
@@ -154,7 +156,7 @@ function {{phpPrefix}}_build_state_response( $post_id, $resource_key, $count ) {
154
156
  'postId' => (int) $post_id,
155
157
  'resourceKey' => (string) $resource_key,
156
158
  'count' => (int) $count,
157
- 'storage' => '{{dataStorageMode}}',
159
+ 'storage' => {{phpPrefixUpper}}_DATA_STORAGE_MODE,
158
160
  );
159
161
  }
160
162
 
@@ -1,5 +1,8 @@
1
+ import type { ValidationResult } from '@wp-typia/block-runtime/validation';
1
2
  import { tags } from 'typia';
2
3
 
4
+ export type { ValidationResult } from '@wp-typia/block-runtime/validation';
5
+
3
6
  export interface {{pascalCase}}Attributes {
4
7
  heading: string &
5
8
  tags.MinLength< 1 > &
@@ -11,3 +14,5 @@ export interface {{pascalCase}}Attributes {
11
14
  tags.Default< 'Add and reorder internal items inside this compound block.' >;
12
15
  showDividers?: boolean & tags.Default< true >;
13
16
  }
17
+
18
+ export type {{pascalCase}}ValidationResult = ValidationResult< {{pascalCase}}Attributes >;
@@ -1,6 +1,9 @@
1
1
  import typia from 'typia';
2
2
  import currentManifest from './typia.manifest.json';
3
- import type { {{pascalCase}}Attributes } from './types';
3
+ import type {
4
+ {{pascalCase}}Attributes,
5
+ {{pascalCase}}ValidationResult,
6
+ } from './types';
4
7
  import { createTemplateValidatorToolkit } from '../../validator-toolkit';
5
8
 
6
9
  const scaffoldValidators = createTemplateValidatorToolkit< {{pascalCase}}Attributes >( {
@@ -18,11 +21,15 @@ const scaffoldValidators = createTemplateValidatorToolkit< {{pascalCase}}Attribu
18
21
  } );
19
22
 
20
23
  export const validate{{pascalCase}}Attributes =
21
- scaffoldValidators.validateAttributes;
24
+ scaffoldValidators.validateAttributes as (
25
+ attributes: unknown
26
+ ) => {{pascalCase}}ValidationResult;
22
27
 
23
28
  export const validators = scaffoldValidators.validators;
24
29
 
25
30
  export const sanitize{{pascalCase}}Attributes =
26
- scaffoldValidators.sanitizeAttributes;
31
+ scaffoldValidators.sanitizeAttributes as (
32
+ attributes: Partial< {{pascalCase}}Attributes >
33
+ ) => {{pascalCase}}Attributes;
27
34
 
28
35
  export const createAttributeUpdater = scaffoldValidators.createAttributeUpdater;
@@ -1,5 +1,8 @@
1
+ import type { ValidationResult } from '@wp-typia/block-runtime/validation';
1
2
  import { tags } from 'typia';
2
3
 
4
+ export type { ValidationResult } from '@wp-typia/block-runtime/validation';
5
+
3
6
  export interface {{pascalCase}}ItemAttributes {
4
7
  title: string &
5
8
  tags.MinLength< 1 > &
@@ -10,3 +13,5 @@ export interface {{pascalCase}}ItemAttributes {
10
13
  tags.MaxLength< 280 > &
11
14
  tags.Default< 'Add supporting details for this internal item.' >;
12
15
  }
16
+
17
+ export type {{pascalCase}}ItemValidationResult = ValidationResult< {{pascalCase}}ItemAttributes >;