@atscript/typescript 0.1.23 → 0.1.24
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/dist/utils.cjs
CHANGED
|
@@ -778,15 +778,24 @@ function build(def, path, mode) {
|
|
|
778
778
|
if (isPhantomType(prop)) continue;
|
|
779
779
|
const childPath = path ? `${path}.${key}` : key;
|
|
780
780
|
if (prop.optional) {
|
|
781
|
-
|
|
782
|
-
|
|
781
|
+
if (mode === "example") data[key] = build(prop, childPath, mode);
|
|
782
|
+
else {
|
|
783
|
+
const childResolved = resolveValue(prop, childPath, mode);
|
|
784
|
+
if (childResolved !== undefined) data[key] = childResolved.value;
|
|
785
|
+
}
|
|
783
786
|
continue;
|
|
784
787
|
}
|
|
785
788
|
data[key] = build(prop, childPath, mode);
|
|
786
789
|
}
|
|
787
790
|
return data;
|
|
788
791
|
},
|
|
789
|
-
array: () =>
|
|
792
|
+
array: (d) => {
|
|
793
|
+
if (mode === "example") {
|
|
794
|
+
const item = build(d.type.of, `${path}.0`, mode);
|
|
795
|
+
return item !== undefined ? [item] : [];
|
|
796
|
+
}
|
|
797
|
+
return [];
|
|
798
|
+
},
|
|
790
799
|
tuple: (d) => d.type.items.map((item, i) => build(item, `${path}.${i}`, mode)),
|
|
791
800
|
union: (d) => {
|
|
792
801
|
const first = d.type.items[0];
|
package/dist/utils.d.ts
CHANGED
|
@@ -332,7 +332,7 @@ interface TCreateDataOptions {
|
|
|
332
332
|
* How to resolve values:
|
|
333
333
|
* - `'empty'` — structural defaults only (`''`, `0`, `false`, `[]`, `{}`); optional props skipped
|
|
334
334
|
* - `'default'` — use `@meta.default` annotations; optional props skipped unless annotated
|
|
335
|
-
* - `'example'` — use `@meta.example` annotations; optional props
|
|
335
|
+
* - `'example'` — use `@meta.example` annotations; optional props always included; arrays get one sample item
|
|
336
336
|
* - `function` — custom resolver per field; optional props skipped unless resolver returns a value
|
|
337
337
|
*
|
|
338
338
|
* @default 'empty'
|
|
@@ -345,7 +345,7 @@ interface TCreateDataOptions {
|
|
|
345
345
|
* Supports four modes:
|
|
346
346
|
* - `'empty'` — structural defaults only; optional props omitted
|
|
347
347
|
* - `'default'` — uses `@meta.default` annotations; optional props omitted unless annotated
|
|
348
|
-
* - `'example'` — uses `@meta.example` annotations; optional props
|
|
348
|
+
* - `'example'` — uses `@meta.example` annotations; optional props always included; arrays get one sample item
|
|
349
349
|
* - `function` — custom resolver; optional props omitted unless resolver returns a value
|
|
350
350
|
*
|
|
351
351
|
* When a `@meta.default` / `@meta.example` value is set on a complex type (object, array)
|
package/dist/utils.mjs
CHANGED
|
@@ -777,15 +777,24 @@ function build(def, path, mode) {
|
|
|
777
777
|
if (isPhantomType(prop)) continue;
|
|
778
778
|
const childPath = path ? `${path}.${key}` : key;
|
|
779
779
|
if (prop.optional) {
|
|
780
|
-
|
|
781
|
-
|
|
780
|
+
if (mode === "example") data[key] = build(prop, childPath, mode);
|
|
781
|
+
else {
|
|
782
|
+
const childResolved = resolveValue(prop, childPath, mode);
|
|
783
|
+
if (childResolved !== undefined) data[key] = childResolved.value;
|
|
784
|
+
}
|
|
782
785
|
continue;
|
|
783
786
|
}
|
|
784
787
|
data[key] = build(prop, childPath, mode);
|
|
785
788
|
}
|
|
786
789
|
return data;
|
|
787
790
|
},
|
|
788
|
-
array: () =>
|
|
791
|
+
array: (d) => {
|
|
792
|
+
if (mode === "example") {
|
|
793
|
+
const item = build(d.type.of, `${path}.0`, mode);
|
|
794
|
+
return item !== undefined ? [item] : [];
|
|
795
|
+
}
|
|
796
|
+
return [];
|
|
797
|
+
},
|
|
789
798
|
tuple: (d) => d.type.items.map((item, i) => build(item, `${path}.${i}`, mode)),
|
|
790
799
|
union: (d) => {
|
|
791
800
|
const first = d.type.items[0];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/typescript",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.24",
|
|
4
4
|
"description": "Atscript: typescript-gen support.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"annotations",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"vitest": "3.2.4"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
|
-
"@atscript/core": "^0.1.
|
|
67
|
+
"@atscript/core": "^0.1.24"
|
|
68
68
|
},
|
|
69
69
|
"build": [
|
|
70
70
|
{},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: atscript-typescript
|
|
3
|
-
description: Atscript TypeScript
|
|
3
|
+
description: Use when working with Atscript (.as files) in TypeScript projects — writing or editing .as interfaces/types/annotations, configuring atscript.config.ts or tsPlugin, understanding generated .d.ts/.js output, using runtime APIs (TAtscriptAnnotatedType, metadata, validators), generating JSON Schema or example data from types, serializing/deserializing annotated types, or running the asc CLI.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# @atscript/typescript
|
|
@@ -257,12 +257,13 @@ const custom = createDataFromAnnotatedType(User, {
|
|
|
257
257
|
|------|----------|
|
|
258
258
|
| `'empty'` (default) | Structural defaults: `''`, `0`, `false`, `[]`, `{}`. Optional props omitted |
|
|
259
259
|
| `'default'` | Uses `@meta.default` annotations. Optional props only included if annotated |
|
|
260
|
-
| `'example'` | Uses `@meta.example` annotations. Optional props
|
|
260
|
+
| `'example'` | Uses `@meta.example` annotations. Optional props always included. Arrays get one sample item |
|
|
261
261
|
| `function` | Custom resolver per field. Return `undefined` to fall through |
|
|
262
262
|
|
|
263
263
|
### Behavior Notes
|
|
264
264
|
|
|
265
|
-
- **Optional properties** are omitted unless the mode provides a value for them
|
|
265
|
+
- **Optional properties** are omitted unless the mode provides a value for them (exception: `'example'` mode always includes all optional props)
|
|
266
|
+
- **Arrays** in `'example'` mode generate one sample item from the element type instead of an empty array
|
|
266
267
|
- **Complex types** (object, array): if a `@meta.default`/`@meta.example` annotation is set and passes validation, the entire subtree is replaced (no recursion into inner props)
|
|
267
268
|
- **Annotation values**: strings are used as-is for string types; everything else is parsed via `JSON.parse`
|
|
268
269
|
- **Unions/Intersections**: defaults to first item's value
|