skir-simple-data-objects-generator 0.1.0 → 0.2.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
@@ -122,10 +122,13 @@ Every Skir struct generates a final class extending `StdOut\SimpleDataObjects\Ba
122
122
  | --- | --- |
123
123
  | `skirType()` | Return the runtime `Type` descriptor. |
124
124
  | `makeFromSkirPayload(array $data)` | Validate raw named Skir data, recursively hydrate nested values, and return the DTO. |
125
- | `fromSkir(string $json)` | Decode dense Skir JSON and delegate to `makeFromSkirPayload()`. |
125
+ | `fromSkir(string $json)` | Decode dense or readable Skir JSON and delegate to `makeFromSkirPayload()`. There is no separate `fromReadableJson()`. |
126
126
  | `toSkirArray()` | Convert DTO values to the named array representation expected by the runtime. |
127
127
  | `toSkir()` | Encode the DTO as the dense PHP array representation. |
128
128
  | `toSkirJson()` | Encode the DTO as dense Skir JSON. |
129
+ | `toReadableJson()` | Encode the DTO as readable Skir JSON. |
130
+ | `toBytes()` | Encode the DTO in the Skir binary format. |
131
+ | `fromBytes(string $bytes)` | Decode the Skir binary format and delegate to `makeFromSkirPayload()`, so validation applies. |
129
132
 
130
133
  Generated classes inherit the current `BaseData` APIs, including `from()`, `fromValidated()`, `validate()`, `toArray()`, `toJson()`, `with()`, `equals()`, `diff()`, `only()`, `except()`, `collection()`, and `lazyCollection()`.
131
134
 
@@ -176,7 +179,7 @@ Nested arrays and arrays whose item is optional remain normal PHP arrays, althou
176
179
 
177
180
  ### Wrapper enums
178
181
 
179
- Skir enums generate readonly wrapper classes with a `Data` suffix. Constant variants have parameterless named constructors; payload variants have typed named constructors. Generated enum classes expose `name()`, `payload()`, `skirType()`, `toSkirValue()`, `fromSkirValue()`, `toDenseValue()`, `fromDenseValue()`, `toDenseJson()`, and `fromDenseJson()`.
182
+ Skir enums generate readonly wrapper classes with a `Data` suffix. Constant variants have parameterless named constructors; payload variants have typed named constructors. Generated enum classes expose `name()`, `payload()`, `skirType()`, `toSkirValue()`, `fromSkirValue()`, `toDenseValue()`, `fromDenseValue()`, `toDenseJson()`, `fromDenseJson()`, `toReadableJson()`, `toBytes()`, and `fromBytes()`. `fromDenseJson()` accepts both dense and readable JSON.
180
183
 
181
184
  Structs, typed struct collections, nested arrays, optionals, and nested enum wrappers are converted to wire values when stored in a wrapper and converted back to target DTO values when `payload()` is read.
182
185
 
@@ -357,14 +360,3 @@ npm install --no-save --package-lock=false ../generator-core
357
360
  ```
358
361
 
359
362
  Once the compatible core package has been published and this repository has committed its normal `package-lock.json`, use `npm ci` instead of the local-path bootstrap.
360
-
361
- ## Releasing
362
-
363
- Release the shared packages in dependency order:
364
-
365
- 1. Merge and publish `@php-skir/generator-core` with the required adapter APIs.
366
- 2. Replace the local link with the published compatible core version and commit the resulting `package-lock.json` update.
367
- 3. Run `npm ci`, typecheck, build, package validation, the full test suite, and `git diff --check` again.
368
- 4. Create the Simple Data Objects generator release only after those checks pass.
369
-
370
- The release workflow uses Node 24 and npm trusted publishing with provenance. Configure this GitHub repository as an npm trusted publisher before publishing; no release or publish action is performed by the test workflow.
package/dist/target.d.ts CHANGED
@@ -25,5 +25,8 @@ export declare class SimpleDataObjectsTarget implements PhpTargetAdapter {
25
25
  private renderToSkirArray;
26
26
  private renderToSkir;
27
27
  private renderToSkirJson;
28
+ private renderToReadableJson;
29
+ private renderToBytes;
30
+ private renderFromBytes;
28
31
  private toSkirValueExpression;
29
32
  }
package/dist/target.js CHANGED
@@ -1,15 +1,24 @@
1
1
  import { importClass, importClassAs, indent, renderPhpFile, renderUseStatements, resolveValidationRules, toClassName, toPhpNamespaceSegment, toPropertyName, } from "@php-skir/generator-core";
2
2
  import { GENERATOR_MODULE } from "./config.js";
3
3
  import { structuralRules } from "./structural-rules.js";
4
+ const BINARY_FORMAT = "Skir\\Runtime\\BinaryFormat";
4
5
  const DENSE_JSON = "Skir\\Runtime\\DenseJson";
5
6
  const FIELD = "Skir\\Runtime\\Field";
7
+ const READABLE_JSON = "Skir\\Runtime\\ReadableJson";
6
8
  const TYPE = "Skir\\Runtime\\Type";
7
9
  const DATA_COLLECTION = "StdOut\\SimpleDataObjects\\Attributes\\DataCollection";
8
10
  const MAP_PROPERTY_NAME = "StdOut\\SimpleDataObjects\\Attributes\\MapPropertyName";
9
11
  const RULES = "StdOut\\SimpleDataObjects\\Attributes\\Rules";
10
12
  const BASE_DATA = "StdOut\\SimpleDataObjects\\BaseData";
11
13
  const TYPED_DATA_COLLECTION = "StdOut\\SimpleDataObjects\\TypedDataCollection";
12
- const BASE_STRUCT_IMPORTS = [DENSE_JSON, FIELD, TYPE, BASE_DATA];
14
+ const BASE_STRUCT_IMPORTS = [
15
+ BINARY_FORMAT,
16
+ DENSE_JSON,
17
+ FIELD,
18
+ READABLE_JSON,
19
+ TYPE,
20
+ BASE_DATA,
21
+ ];
13
22
  export class SimpleDataObjectsTarget {
14
23
  validation;
15
24
  id = GENERATOR_MODULE;
@@ -62,8 +71,10 @@ export class SimpleDataObjectsTarget {
62
71
  }
63
72
  const className = classNameForRecord(record, context);
64
73
  const imports = this.structImports(record);
74
+ const binaryFormat = importClass(context.imports, BINARY_FORMAT);
65
75
  const denseJson = importClass(context.imports, DENSE_JSON);
66
76
  const fieldClass = importClass(context.imports, FIELD);
77
+ const readableJson = importClass(context.imports, READABLE_JSON);
67
78
  const typeClass = importClass(context.imports, TYPE);
68
79
  const baseData = importClass(context.imports, BASE_DATA);
69
80
  const fields = record.fields.filter(isStructField);
@@ -76,6 +87,9 @@ export class SimpleDataObjectsTarget {
76
87
  this.renderToSkirArray(fields, context),
77
88
  this.renderToSkir(denseJson),
78
89
  this.renderToSkirJson(denseJson),
90
+ this.renderToReadableJson(readableJson),
91
+ this.renderToBytes(binaryFormat),
92
+ this.renderFromBytes(className, binaryFormat),
79
93
  ].filter((member) => member !== null);
80
94
  const body = [
81
95
  `final class ${className} extends ${baseData}`,
@@ -262,6 +276,32 @@ export class SimpleDataObjectsTarget {
262
276
  "}",
263
277
  ].join("\n");
264
278
  }
279
+ renderToReadableJson(readableJson) {
280
+ return [
281
+ "public function toReadableJson(): string",
282
+ "{",
283
+ ` return ${readableJson}::toJson(self::skirType(), $this->toSkirArray());`,
284
+ "}",
285
+ ].join("\n");
286
+ }
287
+ renderToBytes(binaryFormat) {
288
+ return [
289
+ "public function toBytes(): string",
290
+ "{",
291
+ ` return ${binaryFormat}::encode(self::skirType(), $this->toSkirArray());`,
292
+ "}",
293
+ ].join("\n");
294
+ }
295
+ renderFromBytes(className, binaryFormat) {
296
+ return [
297
+ `public static function fromBytes(string $bytes): ${className}`,
298
+ "{",
299
+ ` $data = ${binaryFormat}::decode(self::skirType(), $bytes);`,
300
+ "",
301
+ " return self::makeFromSkirPayload($data);",
302
+ "}",
303
+ ].join("\n");
304
+ }
265
305
  toSkirValueExpression(type, expression, context, allowTypedCollection) {
266
306
  if (type.kind === "record") {
267
307
  return type.recordType === "enum"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skir-simple-data-objects-generator",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Skir code generator for std-out/simple-data-objects.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -43,11 +43,11 @@
43
43
  "pretest": "npm run build",
44
44
  "pack:dry-run": "npm pack --dry-run --cache .npm-cache",
45
45
  "test": "vitest run",
46
- "test:coverage": "vitest run --coverage --coverage.reporter=json-summary --coverage.include=src/**/*.ts",
46
+ "test:coverage": "vitest run --coverage --coverage.reporter=json-summary --coverage.include=src/**/*.ts --coverage.thresholds.lines=80 --coverage.thresholds.statements=80 --coverage.thresholds.branches=75 --coverage.thresholds.functions=75",
47
47
  "typecheck": "tsc -p tsconfig.json --noEmit"
48
48
  },
49
49
  "dependencies": {
50
- "@php-skir/generator-core": "^0.1.0",
50
+ "@php-skir/generator-core": "^0.2.0",
51
51
  "skir-internal": "^0.2.21",
52
52
  "zod": "^4.0.0"
53
53
  },
@@ -56,6 +56,7 @@
56
56
  "@vitest/coverage-v8": "^4.1.10",
57
57
  "skir": "^1.2.19",
58
58
  "typescript": "^5.9.0",
59
- "vitest": "^4.0.0"
59
+ "vitest": "^4.0.0",
60
+ "yaml": "^2.9.0"
60
61
  }
61
62
  }