@atscript/typescript 0.1.100 → 0.1.101
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 +12 -4
- package/dist/utils.d.ts +11 -0
- package/dist/utils.mjs +12 -4
- package/package.json +2 -2
package/dist/utils.cjs
CHANGED
|
@@ -527,7 +527,7 @@ function serializeRef(def, options, visited) {
|
|
|
527
527
|
}
|
|
528
528
|
function serializeNode(def, path, options, visited) {
|
|
529
529
|
const refDepth = options?.refDepth ?? 0;
|
|
530
|
-
const metadata = () => serializeMetadata(def
|
|
530
|
+
const metadata = () => serializeMetadata(def, {
|
|
531
531
|
path,
|
|
532
532
|
kind: def.type.kind
|
|
533
533
|
}, options, {
|
|
@@ -657,7 +657,7 @@ function serializeTypeDef(def, path, options, visited) {
|
|
|
657
657
|
*/ function shallowTarget(target, options, state, withMetadata) {
|
|
658
658
|
return {
|
|
659
659
|
id: target.id ?? "",
|
|
660
|
-
...withMetadata ? { metadata: serializeMetadata(target
|
|
660
|
+
...withMetadata ? { metadata: serializeMetadata(target, {
|
|
661
661
|
path: [],
|
|
662
662
|
kind: target.type.kind
|
|
663
663
|
}, options, state) } : {}
|
|
@@ -686,11 +686,19 @@ function serializeTypeDef(def, path, options, visited) {
|
|
|
686
686
|
ancestors.delete(value);
|
|
687
687
|
return out;
|
|
688
688
|
}
|
|
689
|
-
function serializeMetadata(
|
|
689
|
+
function serializeMetadata(owner, site, options, state) {
|
|
690
690
|
const { path, kind } = site;
|
|
691
691
|
const result = {};
|
|
692
692
|
const ignoreSet = options?.ignoreAnnotations ? new Set(options.ignoreAnnotations) : void 0;
|
|
693
|
-
|
|
693
|
+
const overrides = options?.annotationOverrides?.(owner);
|
|
694
|
+
let entries = owner.metadata.entries();
|
|
695
|
+
if (overrides) {
|
|
696
|
+
const merged = new Map(entries);
|
|
697
|
+
for (const [key, value] of Object.entries(overrides)) if (value === void 0) merged.delete(key);
|
|
698
|
+
else merged.set(key, value);
|
|
699
|
+
entries = merged;
|
|
700
|
+
}
|
|
701
|
+
for (const [key, value] of entries) {
|
|
694
702
|
if (ignoreSet?.has(key)) continue;
|
|
695
703
|
if (options?.processAnnotation) {
|
|
696
704
|
const processed = options.processAnnotation({
|
package/dist/utils.d.ts
CHANGED
|
@@ -629,6 +629,17 @@ interface TSerializeOptions {
|
|
|
629
629
|
* emits a shallow `{ id, metadata }` at the tail level instead of the full body.
|
|
630
630
|
*/
|
|
631
631
|
refDepth?: number;
|
|
632
|
+
/**
|
|
633
|
+
* Per-node annotation overrides, applied over the node's own metadata BEFORE
|
|
634
|
+
* `ignoreAnnotations` / `processAnnotation` (which still filter them). Called with the owning
|
|
635
|
+
* annotated type node for every serialized metadata block (type nodes and shallow ref /
|
|
636
|
+
* annotation-value targets; never for collapsed `$ref` uses). Keys absent from the node are
|
|
637
|
+
* added, existing keys are replaced, and a key whose value is `undefined` is removed. Must be a
|
|
638
|
+
* pure function of the node: the repeated-type detector compares the nodes' own metadata, and a
|
|
639
|
+
* collapsed use restores to the first node's (overridden) metadata. Runtime metadata is never
|
|
640
|
+
* mutated.
|
|
641
|
+
*/
|
|
642
|
+
annotationOverrides?: (type: TAtscriptAnnotatedType) => Readonly<Record<string, unknown>> | undefined;
|
|
632
643
|
}
|
|
633
644
|
/**
|
|
634
645
|
* Converts a runtime {@link TAtscriptAnnotatedType} into a plain JSON-safe object.
|
package/dist/utils.mjs
CHANGED
|
@@ -526,7 +526,7 @@ function serializeRef(def, options, visited) {
|
|
|
526
526
|
}
|
|
527
527
|
function serializeNode(def, path, options, visited) {
|
|
528
528
|
const refDepth = options?.refDepth ?? 0;
|
|
529
|
-
const metadata = () => serializeMetadata(def
|
|
529
|
+
const metadata = () => serializeMetadata(def, {
|
|
530
530
|
path,
|
|
531
531
|
kind: def.type.kind
|
|
532
532
|
}, options, {
|
|
@@ -656,7 +656,7 @@ function serializeTypeDef(def, path, options, visited) {
|
|
|
656
656
|
*/ function shallowTarget(target, options, state, withMetadata) {
|
|
657
657
|
return {
|
|
658
658
|
id: target.id ?? "",
|
|
659
|
-
...withMetadata ? { metadata: serializeMetadata(target
|
|
659
|
+
...withMetadata ? { metadata: serializeMetadata(target, {
|
|
660
660
|
path: [],
|
|
661
661
|
kind: target.type.kind
|
|
662
662
|
}, options, state) } : {}
|
|
@@ -685,11 +685,19 @@ function serializeTypeDef(def, path, options, visited) {
|
|
|
685
685
|
ancestors.delete(value);
|
|
686
686
|
return out;
|
|
687
687
|
}
|
|
688
|
-
function serializeMetadata(
|
|
688
|
+
function serializeMetadata(owner, site, options, state) {
|
|
689
689
|
const { path, kind } = site;
|
|
690
690
|
const result = {};
|
|
691
691
|
const ignoreSet = options?.ignoreAnnotations ? new Set(options.ignoreAnnotations) : void 0;
|
|
692
|
-
|
|
692
|
+
const overrides = options?.annotationOverrides?.(owner);
|
|
693
|
+
let entries = owner.metadata.entries();
|
|
694
|
+
if (overrides) {
|
|
695
|
+
const merged = new Map(entries);
|
|
696
|
+
for (const [key, value] of Object.entries(overrides)) if (value === void 0) merged.delete(key);
|
|
697
|
+
else merged.set(key, value);
|
|
698
|
+
entries = merged;
|
|
699
|
+
}
|
|
700
|
+
for (const [key, value] of entries) {
|
|
693
701
|
if (ignoreSet?.has(key)) continue;
|
|
694
702
|
if (options?.processAnnotation) {
|
|
695
703
|
const processed = options.processAnnotation({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/typescript",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.101",
|
|
4
4
|
"description": "Atscript: typescript-gen support.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"annotations",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
},
|
|
74
74
|
"peerDependencies": {
|
|
75
75
|
"@atscript/db": "^0.1.97",
|
|
76
|
-
"@atscript/core": "^0.1.
|
|
76
|
+
"@atscript/core": "^0.1.101"
|
|
77
77
|
},
|
|
78
78
|
"peerDependenciesMeta": {
|
|
79
79
|
"@atscript/db": {
|