@atscript/typescript 0.1.36 → 0.1.38
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/cli.cjs +53 -6
- package/dist/index.cjs +40 -1
- package/dist/index.mjs +40 -1
- package/dist/{json-schema-S5-XAOrR.cjs → json-schema-B55uxKNQ.cjs} +13 -5
- package/dist/{json-schema-0UUPoHud.mjs → json-schema-DaFltW4t.mjs} +13 -5
- package/dist/utils.cjs +8 -7
- package/dist/utils.d.ts +3 -3
- package/dist/utils.mjs +8 -7
- package/package.json +4 -4
package/dist/cli.cjs
CHANGED
|
@@ -349,6 +349,7 @@ var TypeRenderer = class TypeRenderer extends BaseRenderer {
|
|
|
349
349
|
this.renderOwnProps(interfaceNode);
|
|
350
350
|
this.renderNavProps(interfaceNode);
|
|
351
351
|
this.renderPk(interfaceNode);
|
|
352
|
+
this.renderDimMeasure(interfaceNode);
|
|
352
353
|
}
|
|
353
354
|
}
|
|
354
355
|
renderInterface(node) {
|
|
@@ -607,6 +608,24 @@ else if (pkProps.length === 1) {
|
|
|
607
608
|
this.writeln(uniqueSuffix);
|
|
608
609
|
}
|
|
609
610
|
}
|
|
611
|
+
renderDimMeasure(node) {
|
|
612
|
+
let struct;
|
|
613
|
+
if (node.hasExtends) struct = this.doc.resolveInterfaceExtends(node);
|
|
614
|
+
if (!struct) struct = node.getDefinition();
|
|
615
|
+
if (!struct || !(0, __atscript_core.isStructure)(struct)) return;
|
|
616
|
+
const structNode = struct;
|
|
617
|
+
const dims = [];
|
|
618
|
+
const measures = [];
|
|
619
|
+
for (const [name, prop] of structNode.props) {
|
|
620
|
+
if (prop.token("identifier")?.pattern) continue;
|
|
621
|
+
if (prop.countAnnotations("db.column.dimension") > 0) dims.push(name);
|
|
622
|
+
if (prop.countAnnotations("db.column.measure") > 0) measures.push(name);
|
|
623
|
+
}
|
|
624
|
+
if (dims.length === 0 && measures.length === 0) return;
|
|
625
|
+
this.writeln();
|
|
626
|
+
if (dims.length > 0) this.writeln(`static __dim: ${dims.map((d) => `"${escapeQuotes(d)}"`).join(" | ")}`);
|
|
627
|
+
if (measures.length > 0) this.writeln(`static __measure: ${measures.map((m) => `"${escapeQuotes(m)}"`).join(" | ")}`);
|
|
628
|
+
}
|
|
610
629
|
phantomPropType(def) {
|
|
611
630
|
if (!def) return undefined;
|
|
612
631
|
if ((0, __atscript_core.isPrimitive)(def) && def.config.type === "phantom") return def.id;
|
|
@@ -656,7 +675,7 @@ function renderPrimitiveTypeDef(def) {
|
|
|
656
675
|
}
|
|
657
676
|
|
|
658
677
|
//#endregion
|
|
659
|
-
//#region packages/typescript/src/validator.ts
|
|
678
|
+
//#region packages/typescript/src/runtime/validator.ts
|
|
660
679
|
function _define_property$4(obj, key, value) {
|
|
661
680
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
662
681
|
value,
|
|
@@ -978,6 +997,13 @@ else {
|
|
|
978
997
|
}
|
|
979
998
|
return true;
|
|
980
999
|
}
|
|
1000
|
+
case "decimal": {
|
|
1001
|
+
if (typeOfValue !== "string") {
|
|
1002
|
+
this.error(`Expected string (decimal), got ${typeOfValue}`);
|
|
1003
|
+
return false;
|
|
1004
|
+
}
|
|
1005
|
+
return true;
|
|
1006
|
+
}
|
|
981
1007
|
default: throw new Error(`Unknown type "${def.type.designType}"`);
|
|
982
1008
|
}
|
|
983
1009
|
}
|
|
@@ -1091,7 +1117,7 @@ var ValidatorError = class extends Error {
|
|
|
1091
1117
|
};
|
|
1092
1118
|
|
|
1093
1119
|
//#endregion
|
|
1094
|
-
//#region packages/typescript/src/annotated-type.ts
|
|
1120
|
+
//#region packages/typescript/src/runtime/annotated-type.ts
|
|
1095
1121
|
const COMPLEX_KINDS = new Set([
|
|
1096
1122
|
"union",
|
|
1097
1123
|
"intersection",
|
|
@@ -1254,7 +1280,7 @@ function isPhantomType(def) {
|
|
|
1254
1280
|
}
|
|
1255
1281
|
|
|
1256
1282
|
//#endregion
|
|
1257
|
-
//#region packages/typescript/src/traverse.ts
|
|
1283
|
+
//#region packages/typescript/src/runtime/traverse.ts
|
|
1258
1284
|
function forAnnotatedType(def, handlers) {
|
|
1259
1285
|
switch (def.type.kind) {
|
|
1260
1286
|
case "": {
|
|
@@ -1272,7 +1298,7 @@ function forAnnotatedType(def, handlers) {
|
|
|
1272
1298
|
}
|
|
1273
1299
|
|
|
1274
1300
|
//#endregion
|
|
1275
|
-
//#region packages/typescript/src/json-schema.ts
|
|
1301
|
+
//#region packages/typescript/src/runtime/json-schema.ts
|
|
1276
1302
|
/**
|
|
1277
1303
|
* Detects a discriminator property across union items.
|
|
1278
1304
|
*
|
|
@@ -1395,7 +1421,8 @@ function buildJsonSchema(type) {
|
|
|
1395
1421
|
const schema$1 = {};
|
|
1396
1422
|
if (d.type.value !== undefined) schema$1.const = d.type.value;
|
|
1397
1423
|
if (d.type.designType && d.type.designType !== "any") {
|
|
1398
|
-
|
|
1424
|
+
const dt = d.type.designType;
|
|
1425
|
+
schema$1.type = dt === "undefined" ? "null" : dt === "decimal" ? "string" : dt;
|
|
1399
1426
|
if (schema$1.type === "number" && meta.get("expect.int")) schema$1.type = "integer";
|
|
1400
1427
|
}
|
|
1401
1428
|
if (schema$1.type === "string") {
|
|
@@ -1541,6 +1568,7 @@ else def = def.getDefinition() || def;
|
|
|
1541
1568
|
if (typeId) this.writeln(`static id = "${typeId}"`);
|
|
1542
1569
|
this.renderJsonSchemaMethod(node);
|
|
1543
1570
|
this.renderExampleDataMethod(node);
|
|
1571
|
+
this.renderDimMeasure(node);
|
|
1544
1572
|
}
|
|
1545
1573
|
renderInterface(node) {
|
|
1546
1574
|
this.renderDefinitionClass(node);
|
|
@@ -1592,6 +1620,25 @@ else def = def.getDefinition() || def;
|
|
|
1592
1620
|
this.writeln("}");
|
|
1593
1621
|
}
|
|
1594
1622
|
}
|
|
1623
|
+
renderDimMeasure(node) {
|
|
1624
|
+
if (!(0, __atscript_core.isInterface)(node)) return;
|
|
1625
|
+
const interfaceNode = node;
|
|
1626
|
+
if (!interfaceNode.annotations?.some((a) => a.name === "db.table" || a.name === "db.view" || a.name === "db.view.for")) return;
|
|
1627
|
+
let struct;
|
|
1628
|
+
if (interfaceNode.hasExtends) struct = this.doc.resolveInterfaceExtends(interfaceNode);
|
|
1629
|
+
if (!struct) struct = interfaceNode.getDefinition();
|
|
1630
|
+
if (!struct || !(0, __atscript_core.isStructure)(struct)) return;
|
|
1631
|
+
const structNode = struct;
|
|
1632
|
+
const dims = [];
|
|
1633
|
+
const measures = [];
|
|
1634
|
+
for (const [name, prop] of structNode.props) {
|
|
1635
|
+
if (prop.token("identifier")?.pattern) continue;
|
|
1636
|
+
if (prop.countAnnotations("db.column.dimension") > 0) dims.push(name);
|
|
1637
|
+
if (prop.countAnnotations("db.column.measure") > 0) measures.push(name);
|
|
1638
|
+
}
|
|
1639
|
+
if (dims.length > 0) this.writeln(`static dimensions = [${dims.map((d) => `'${escapeQuotes(d)}'`).join(", ")}]`);
|
|
1640
|
+
if (measures.length > 0) this.writeln(`static measures = [${measures.map((m) => `'${escapeQuotes(m)}'`).join(", ")}]`);
|
|
1641
|
+
}
|
|
1595
1642
|
toAnnotatedType(node) {
|
|
1596
1643
|
return this.toAnnotatedHandle(node).$type;
|
|
1597
1644
|
}
|
|
@@ -2468,7 +2515,7 @@ var DbSyncController = class {
|
|
|
2468
2515
|
}
|
|
2469
2516
|
this.printer.typeCount(dbTypes.length);
|
|
2470
2517
|
this.printer.banner();
|
|
2471
|
-
const { SchemaSync } = await this.importFromCwd("@atscript/
|
|
2518
|
+
const { SchemaSync } = await this.importFromCwd("@atscript/db/sync", true);
|
|
2472
2519
|
const sync = new SchemaSync(dbSpace);
|
|
2473
2520
|
const plan = await sync.plan(dbTypes, {
|
|
2474
2521
|
force,
|
package/dist/index.cjs
CHANGED
|
@@ -23,7 +23,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
}) : target, mod));
|
|
24
24
|
|
|
25
25
|
//#endregion
|
|
26
|
-
const require_json_schema = require('./json-schema-
|
|
26
|
+
const require_json_schema = require('./json-schema-B55uxKNQ.cjs');
|
|
27
27
|
const path = __toESM(require("path"));
|
|
28
28
|
const __atscript_core = __toESM(require("@atscript/core"));
|
|
29
29
|
|
|
@@ -345,6 +345,7 @@ var TypeRenderer = class TypeRenderer extends BaseRenderer {
|
|
|
345
345
|
this.renderOwnProps(interfaceNode);
|
|
346
346
|
this.renderNavProps(interfaceNode);
|
|
347
347
|
this.renderPk(interfaceNode);
|
|
348
|
+
this.renderDimMeasure(interfaceNode);
|
|
348
349
|
}
|
|
349
350
|
}
|
|
350
351
|
renderInterface(node) {
|
|
@@ -603,6 +604,24 @@ else if (pkProps.length === 1) {
|
|
|
603
604
|
this.writeln(uniqueSuffix);
|
|
604
605
|
}
|
|
605
606
|
}
|
|
607
|
+
renderDimMeasure(node) {
|
|
608
|
+
let struct;
|
|
609
|
+
if (node.hasExtends) struct = this.doc.resolveInterfaceExtends(node);
|
|
610
|
+
if (!struct) struct = node.getDefinition();
|
|
611
|
+
if (!struct || !(0, __atscript_core.isStructure)(struct)) return;
|
|
612
|
+
const structNode = struct;
|
|
613
|
+
const dims = [];
|
|
614
|
+
const measures = [];
|
|
615
|
+
for (const [name, prop] of structNode.props) {
|
|
616
|
+
if (prop.token("identifier")?.pattern) continue;
|
|
617
|
+
if (prop.countAnnotations("db.column.dimension") > 0) dims.push(name);
|
|
618
|
+
if (prop.countAnnotations("db.column.measure") > 0) measures.push(name);
|
|
619
|
+
}
|
|
620
|
+
if (dims.length === 0 && measures.length === 0) return;
|
|
621
|
+
this.writeln();
|
|
622
|
+
if (dims.length > 0) this.writeln(`static __dim: ${dims.map((d) => `"${escapeQuotes(d)}"`).join(" | ")}`);
|
|
623
|
+
if (measures.length > 0) this.writeln(`static __measure: ${measures.map((m) => `"${escapeQuotes(m)}"`).join(" | ")}`);
|
|
624
|
+
}
|
|
606
625
|
phantomPropType(def) {
|
|
607
626
|
if (!def) return undefined;
|
|
608
627
|
if ((0, __atscript_core.isPrimitive)(def) && def.config.type === "phantom") return def.id;
|
|
@@ -766,6 +785,7 @@ else def = def.getDefinition() || def;
|
|
|
766
785
|
if (typeId) this.writeln(`static id = "${typeId}"`);
|
|
767
786
|
this.renderJsonSchemaMethod(node);
|
|
768
787
|
this.renderExampleDataMethod(node);
|
|
788
|
+
this.renderDimMeasure(node);
|
|
769
789
|
}
|
|
770
790
|
renderInterface(node) {
|
|
771
791
|
this.renderDefinitionClass(node);
|
|
@@ -817,6 +837,25 @@ else def = def.getDefinition() || def;
|
|
|
817
837
|
this.writeln("}");
|
|
818
838
|
}
|
|
819
839
|
}
|
|
840
|
+
renderDimMeasure(node) {
|
|
841
|
+
if (!(0, __atscript_core.isInterface)(node)) return;
|
|
842
|
+
const interfaceNode = node;
|
|
843
|
+
if (!interfaceNode.annotations?.some((a) => a.name === "db.table" || a.name === "db.view" || a.name === "db.view.for")) return;
|
|
844
|
+
let struct;
|
|
845
|
+
if (interfaceNode.hasExtends) struct = this.doc.resolveInterfaceExtends(interfaceNode);
|
|
846
|
+
if (!struct) struct = interfaceNode.getDefinition();
|
|
847
|
+
if (!struct || !(0, __atscript_core.isStructure)(struct)) return;
|
|
848
|
+
const structNode = struct;
|
|
849
|
+
const dims = [];
|
|
850
|
+
const measures = [];
|
|
851
|
+
for (const [name, prop] of structNode.props) {
|
|
852
|
+
if (prop.token("identifier")?.pattern) continue;
|
|
853
|
+
if (prop.countAnnotations("db.column.dimension") > 0) dims.push(name);
|
|
854
|
+
if (prop.countAnnotations("db.column.measure") > 0) measures.push(name);
|
|
855
|
+
}
|
|
856
|
+
if (dims.length > 0) this.writeln(`static dimensions = [${dims.map((d) => `'${escapeQuotes(d)}'`).join(", ")}]`);
|
|
857
|
+
if (measures.length > 0) this.writeln(`static measures = [${measures.map((m) => `'${escapeQuotes(m)}'`).join(", ")}]`);
|
|
858
|
+
}
|
|
820
859
|
toAnnotatedType(node) {
|
|
821
860
|
return this.toAnnotatedHandle(node).$type;
|
|
822
861
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { buildJsonSchema, defineAnnotatedType } from "./json-schema-
|
|
1
|
+
import { buildJsonSchema, defineAnnotatedType } from "./json-schema-DaFltW4t.mjs";
|
|
2
2
|
import path from "path";
|
|
3
3
|
import { DEFAULT_FORMAT, flattenInterfaceNode, hasNavPropAnnotation, isArray, isConst, isGroup, isInterface, isPrimitive, isQueryLogical, isRef, isStructure } from "@atscript/core";
|
|
4
4
|
|
|
@@ -320,6 +320,7 @@ var TypeRenderer = class TypeRenderer extends BaseRenderer {
|
|
|
320
320
|
this.renderOwnProps(interfaceNode);
|
|
321
321
|
this.renderNavProps(interfaceNode);
|
|
322
322
|
this.renderPk(interfaceNode);
|
|
323
|
+
this.renderDimMeasure(interfaceNode);
|
|
323
324
|
}
|
|
324
325
|
}
|
|
325
326
|
renderInterface(node) {
|
|
@@ -578,6 +579,24 @@ else if (pkProps.length === 1) {
|
|
|
578
579
|
this.writeln(uniqueSuffix);
|
|
579
580
|
}
|
|
580
581
|
}
|
|
582
|
+
renderDimMeasure(node) {
|
|
583
|
+
let struct;
|
|
584
|
+
if (node.hasExtends) struct = this.doc.resolveInterfaceExtends(node);
|
|
585
|
+
if (!struct) struct = node.getDefinition();
|
|
586
|
+
if (!struct || !isStructure(struct)) return;
|
|
587
|
+
const structNode = struct;
|
|
588
|
+
const dims = [];
|
|
589
|
+
const measures = [];
|
|
590
|
+
for (const [name, prop] of structNode.props) {
|
|
591
|
+
if (prop.token("identifier")?.pattern) continue;
|
|
592
|
+
if (prop.countAnnotations("db.column.dimension") > 0) dims.push(name);
|
|
593
|
+
if (prop.countAnnotations("db.column.measure") > 0) measures.push(name);
|
|
594
|
+
}
|
|
595
|
+
if (dims.length === 0 && measures.length === 0) return;
|
|
596
|
+
this.writeln();
|
|
597
|
+
if (dims.length > 0) this.writeln(`static __dim: ${dims.map((d) => `"${escapeQuotes(d)}"`).join(" | ")}`);
|
|
598
|
+
if (measures.length > 0) this.writeln(`static __measure: ${measures.map((m) => `"${escapeQuotes(m)}"`).join(" | ")}`);
|
|
599
|
+
}
|
|
581
600
|
phantomPropType(def) {
|
|
582
601
|
if (!def) return undefined;
|
|
583
602
|
if (isPrimitive(def) && def.config.type === "phantom") return def.id;
|
|
@@ -741,6 +760,7 @@ else def = def.getDefinition() || def;
|
|
|
741
760
|
if (typeId) this.writeln(`static id = "${typeId}"`);
|
|
742
761
|
this.renderJsonSchemaMethod(node);
|
|
743
762
|
this.renderExampleDataMethod(node);
|
|
763
|
+
this.renderDimMeasure(node);
|
|
744
764
|
}
|
|
745
765
|
renderInterface(node) {
|
|
746
766
|
this.renderDefinitionClass(node);
|
|
@@ -792,6 +812,25 @@ else def = def.getDefinition() || def;
|
|
|
792
812
|
this.writeln("}");
|
|
793
813
|
}
|
|
794
814
|
}
|
|
815
|
+
renderDimMeasure(node) {
|
|
816
|
+
if (!isInterface(node)) return;
|
|
817
|
+
const interfaceNode = node;
|
|
818
|
+
if (!interfaceNode.annotations?.some((a) => a.name === "db.table" || a.name === "db.view" || a.name === "db.view.for")) return;
|
|
819
|
+
let struct;
|
|
820
|
+
if (interfaceNode.hasExtends) struct = this.doc.resolveInterfaceExtends(interfaceNode);
|
|
821
|
+
if (!struct) struct = interfaceNode.getDefinition();
|
|
822
|
+
if (!struct || !isStructure(struct)) return;
|
|
823
|
+
const structNode = struct;
|
|
824
|
+
const dims = [];
|
|
825
|
+
const measures = [];
|
|
826
|
+
for (const [name, prop] of structNode.props) {
|
|
827
|
+
if (prop.token("identifier")?.pattern) continue;
|
|
828
|
+
if (prop.countAnnotations("db.column.dimension") > 0) dims.push(name);
|
|
829
|
+
if (prop.countAnnotations("db.column.measure") > 0) measures.push(name);
|
|
830
|
+
}
|
|
831
|
+
if (dims.length > 0) this.writeln(`static dimensions = [${dims.map((d) => `'${escapeQuotes(d)}'`).join(", ")}]`);
|
|
832
|
+
if (measures.length > 0) this.writeln(`static measures = [${measures.map((m) => `'${escapeQuotes(m)}'`).join(", ")}]`);
|
|
833
|
+
}
|
|
795
834
|
toAnnotatedType(node) {
|
|
796
835
|
return this.toAnnotatedHandle(node).$type;
|
|
797
836
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
//#region packages/typescript/src/validator.ts
|
|
3
|
+
//#region packages/typescript/src/runtime/validator.ts
|
|
4
4
|
function _define_property(obj, key, value) {
|
|
5
5
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
6
6
|
value,
|
|
@@ -322,6 +322,13 @@ else {
|
|
|
322
322
|
}
|
|
323
323
|
return true;
|
|
324
324
|
}
|
|
325
|
+
case "decimal": {
|
|
326
|
+
if (typeOfValue !== "string") {
|
|
327
|
+
this.error(`Expected string (decimal), got ${typeOfValue}`);
|
|
328
|
+
return false;
|
|
329
|
+
}
|
|
330
|
+
return true;
|
|
331
|
+
}
|
|
325
332
|
default: throw new Error(`Unknown type "${def.type.designType}"`);
|
|
326
333
|
}
|
|
327
334
|
}
|
|
@@ -435,7 +442,7 @@ var ValidatorError = class extends Error {
|
|
|
435
442
|
};
|
|
436
443
|
|
|
437
444
|
//#endregion
|
|
438
|
-
//#region packages/typescript/src/annotated-type.ts
|
|
445
|
+
//#region packages/typescript/src/runtime/annotated-type.ts
|
|
439
446
|
const COMPLEX_KINDS = new Set([
|
|
440
447
|
"union",
|
|
441
448
|
"intersection",
|
|
@@ -655,7 +662,7 @@ function isAnnotatedTypeOfPrimitive(t) {
|
|
|
655
662
|
}
|
|
656
663
|
|
|
657
664
|
//#endregion
|
|
658
|
-
//#region packages/typescript/src/traverse.ts
|
|
665
|
+
//#region packages/typescript/src/runtime/traverse.ts
|
|
659
666
|
function forAnnotatedType(def, handlers) {
|
|
660
667
|
switch (def.type.kind) {
|
|
661
668
|
case "": {
|
|
@@ -673,7 +680,7 @@ function forAnnotatedType(def, handlers) {
|
|
|
673
680
|
}
|
|
674
681
|
|
|
675
682
|
//#endregion
|
|
676
|
-
//#region packages/typescript/src/json-schema.ts
|
|
683
|
+
//#region packages/typescript/src/runtime/json-schema.ts
|
|
677
684
|
/**
|
|
678
685
|
* Detects a discriminator property across union items.
|
|
679
686
|
*
|
|
@@ -796,7 +803,8 @@ function buildJsonSchema(type) {
|
|
|
796
803
|
const schema$1 = {};
|
|
797
804
|
if (d.type.value !== undefined) schema$1.const = d.type.value;
|
|
798
805
|
if (d.type.designType && d.type.designType !== "any") {
|
|
799
|
-
|
|
806
|
+
const dt = d.type.designType;
|
|
807
|
+
schema$1.type = dt === "undefined" ? "null" : dt === "decimal" ? "string" : dt;
|
|
800
808
|
if (schema$1.type === "number" && meta.get("expect.int")) schema$1.type = "integer";
|
|
801
809
|
}
|
|
802
810
|
if (schema$1.type === "string") {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
//#region packages/typescript/src/validator.ts
|
|
2
|
+
//#region packages/typescript/src/runtime/validator.ts
|
|
3
3
|
function _define_property(obj, key, value) {
|
|
4
4
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
5
5
|
value,
|
|
@@ -321,6 +321,13 @@ else {
|
|
|
321
321
|
}
|
|
322
322
|
return true;
|
|
323
323
|
}
|
|
324
|
+
case "decimal": {
|
|
325
|
+
if (typeOfValue !== "string") {
|
|
326
|
+
this.error(`Expected string (decimal), got ${typeOfValue}`);
|
|
327
|
+
return false;
|
|
328
|
+
}
|
|
329
|
+
return true;
|
|
330
|
+
}
|
|
324
331
|
default: throw new Error(`Unknown type "${def.type.designType}"`);
|
|
325
332
|
}
|
|
326
333
|
}
|
|
@@ -434,7 +441,7 @@ var ValidatorError = class extends Error {
|
|
|
434
441
|
};
|
|
435
442
|
|
|
436
443
|
//#endregion
|
|
437
|
-
//#region packages/typescript/src/annotated-type.ts
|
|
444
|
+
//#region packages/typescript/src/runtime/annotated-type.ts
|
|
438
445
|
const COMPLEX_KINDS = new Set([
|
|
439
446
|
"union",
|
|
440
447
|
"intersection",
|
|
@@ -654,7 +661,7 @@ function isAnnotatedTypeOfPrimitive(t) {
|
|
|
654
661
|
}
|
|
655
662
|
|
|
656
663
|
//#endregion
|
|
657
|
-
//#region packages/typescript/src/traverse.ts
|
|
664
|
+
//#region packages/typescript/src/runtime/traverse.ts
|
|
658
665
|
function forAnnotatedType(def, handlers) {
|
|
659
666
|
switch (def.type.kind) {
|
|
660
667
|
case "": {
|
|
@@ -672,7 +679,7 @@ function forAnnotatedType(def, handlers) {
|
|
|
672
679
|
}
|
|
673
680
|
|
|
674
681
|
//#endregion
|
|
675
|
-
//#region packages/typescript/src/json-schema.ts
|
|
682
|
+
//#region packages/typescript/src/runtime/json-schema.ts
|
|
676
683
|
/**
|
|
677
684
|
* Detects a discriminator property across union items.
|
|
678
685
|
*
|
|
@@ -795,7 +802,8 @@ function buildJsonSchema(type) {
|
|
|
795
802
|
const schema$1 = {};
|
|
796
803
|
if (d.type.value !== undefined) schema$1.const = d.type.value;
|
|
797
804
|
if (d.type.designType && d.type.designType !== "any") {
|
|
798
|
-
|
|
805
|
+
const dt = d.type.designType;
|
|
806
|
+
schema$1.type = dt === "undefined" ? "null" : dt === "decimal" ? "string" : dt;
|
|
799
807
|
if (schema$1.type === "number" && meta.get("expect.int")) schema$1.type = "integer";
|
|
800
808
|
}
|
|
801
809
|
if (schema$1.type === "string") {
|
package/dist/utils.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const require_json_schema = require('./json-schema-
|
|
2
|
+
const require_json_schema = require('./json-schema-B55uxKNQ.cjs');
|
|
3
3
|
|
|
4
|
-
//#region packages/typescript/src/default-value.ts
|
|
4
|
+
//#region packages/typescript/src/runtime/default-value.ts
|
|
5
5
|
/**
|
|
6
6
|
* Attempts to resolve a value from the mode for the given annotated type.
|
|
7
7
|
* Returns `undefined` when no value is available (or parse/validation fails).
|
|
@@ -21,8 +21,9 @@ const require_json_schema = require('./json-schema-S5-XAOrR.cjs');
|
|
|
21
21
|
if (parsed$1 !== undefined && prop.validator({ unknownProps: "ignore" }).validate(parsed$1, true)) return { value: parsed$1 };
|
|
22
22
|
return undefined;
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
if (
|
|
24
|
+
if (prop.metadata.has("db.default.increment")) return { value: "increment" };
|
|
25
|
+
if (prop.metadata.has("db.default.uuid")) return { value: "uuid" };
|
|
26
|
+
if (prop.metadata.has("db.default.now")) return { value: "now" };
|
|
26
27
|
return undefined;
|
|
27
28
|
}
|
|
28
29
|
const metaKey = mode === "default" ? "meta.default" : "meta.example";
|
|
@@ -101,13 +102,13 @@ else {
|
|
|
101
102
|
}
|
|
102
103
|
|
|
103
104
|
//#endregion
|
|
104
|
-
//#region packages/typescript/src/throw-disabled.ts
|
|
105
|
+
//#region packages/typescript/src/runtime/throw-disabled.ts
|
|
105
106
|
function throwFeatureDisabled(feature, option, annotation) {
|
|
106
107
|
throw new Error(`${feature} support is disabled. To enable, set \`${option}: 'lazy'\` or \`${option}: 'bundle'\` in tsPlugin options, or add @${annotation} annotation to individual interfaces.`);
|
|
107
108
|
}
|
|
108
109
|
|
|
109
110
|
//#endregion
|
|
110
|
-
//#region packages/typescript/src/flatten.ts
|
|
111
|
+
//#region packages/typescript/src/runtime/flatten.ts
|
|
111
112
|
function flattenAnnotatedType(type, options) {
|
|
112
113
|
const flatMap = new Map();
|
|
113
114
|
const skipPhantom = !!options?.excludePhantomTypes;
|
|
@@ -217,7 +218,7 @@ else flatUnion.item(existing);
|
|
|
217
218
|
}
|
|
218
219
|
|
|
219
220
|
//#endregion
|
|
220
|
-
//#region packages/typescript/src/serialize.ts
|
|
221
|
+
//#region packages/typescript/src/runtime/serialize.ts
|
|
221
222
|
const SERIALIZE_VERSION = 1;
|
|
222
223
|
function serializeAnnotatedType(type, options) {
|
|
223
224
|
const visited = new Set();
|
package/dist/utils.d.ts
CHANGED
|
@@ -142,7 +142,7 @@ interface TAtscriptTypeFinal<DataType = unknown> {
|
|
|
142
142
|
/**
|
|
143
143
|
* design type
|
|
144
144
|
*/
|
|
145
|
-
designType: 'string' | 'number' | 'boolean' | 'undefined' | 'null' | 'object' | 'any' | 'never' | 'phantom';
|
|
145
|
+
designType: 'string' | 'number' | 'boolean' | 'undefined' | 'null' | 'object' | 'any' | 'never' | 'phantom' | 'decimal';
|
|
146
146
|
/**
|
|
147
147
|
* value for literals
|
|
148
148
|
*/
|
|
@@ -375,7 +375,7 @@ interface TCreateDataOptions {
|
|
|
375
375
|
* - `'empty'` — structural defaults only (`''`, `0`, `false`, `[]`, `{}`); optional props skipped
|
|
376
376
|
* - `'default'` — use `@meta.default` annotations; optional props skipped unless annotated
|
|
377
377
|
* - `'example'` — use `@meta.example` annotations; optional props always included; arrays get one sample item
|
|
378
|
-
* - `'db'` — use `@db.default` (parsed) or `@db.default.
|
|
378
|
+
* - `'db'` — use `@db.default` (parsed) or `@db.default.increment/uuid/now` (returns fn name string); optional props skipped unless annotated
|
|
379
379
|
* - `function` — custom resolver per field; optional props skipped unless resolver returns a value
|
|
380
380
|
*
|
|
381
381
|
* @default 'empty'
|
|
@@ -389,7 +389,7 @@ interface TCreateDataOptions {
|
|
|
389
389
|
* - `'empty'` — structural defaults only; optional props omitted
|
|
390
390
|
* - `'default'` — uses `@meta.default` annotations; optional props omitted unless annotated
|
|
391
391
|
* - `'example'` — uses `@meta.example` annotations; optional props always included; arrays get one sample item
|
|
392
|
-
* - `'db'` — uses `@db.default` (parsed) or `@db.default.
|
|
392
|
+
* - `'db'` — uses `@db.default` (parsed) or `@db.default.increment/uuid/now` (fn name string); optional props omitted unless annotated
|
|
393
393
|
* - `function` — custom resolver; optional props omitted unless resolver returns a value
|
|
394
394
|
*
|
|
395
395
|
* When a `@meta.default` / `@meta.example` value is set on a complex type (object, array)
|
package/dist/utils.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Validator, ValidatorError, annotate, buildJsonSchema, cloneRefProp, createAnnotatedTypeNode, defineAnnotatedType, forAnnotatedType, fromJsonSchema, isAnnotatedType, isAnnotatedTypeOfPrimitive, isPhantomType, mergeJsonSchemas } from "./json-schema-
|
|
1
|
+
import { Validator, ValidatorError, annotate, buildJsonSchema, cloneRefProp, createAnnotatedTypeNode, defineAnnotatedType, forAnnotatedType, fromJsonSchema, isAnnotatedType, isAnnotatedTypeOfPrimitive, isPhantomType, mergeJsonSchemas } from "./json-schema-DaFltW4t.mjs";
|
|
2
2
|
|
|
3
|
-
//#region packages/typescript/src/default-value.ts
|
|
3
|
+
//#region packages/typescript/src/runtime/default-value.ts
|
|
4
4
|
/**
|
|
5
5
|
* Attempts to resolve a value from the mode for the given annotated type.
|
|
6
6
|
* Returns `undefined` when no value is available (or parse/validation fails).
|
|
@@ -20,8 +20,9 @@ import { Validator, ValidatorError, annotate, buildJsonSchema, cloneRefProp, cre
|
|
|
20
20
|
if (parsed$1 !== undefined && prop.validator({ unknownProps: "ignore" }).validate(parsed$1, true)) return { value: parsed$1 };
|
|
21
21
|
return undefined;
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
if (
|
|
23
|
+
if (prop.metadata.has("db.default.increment")) return { value: "increment" };
|
|
24
|
+
if (prop.metadata.has("db.default.uuid")) return { value: "uuid" };
|
|
25
|
+
if (prop.metadata.has("db.default.now")) return { value: "now" };
|
|
25
26
|
return undefined;
|
|
26
27
|
}
|
|
27
28
|
const metaKey = mode === "default" ? "meta.default" : "meta.example";
|
|
@@ -100,13 +101,13 @@ else {
|
|
|
100
101
|
}
|
|
101
102
|
|
|
102
103
|
//#endregion
|
|
103
|
-
//#region packages/typescript/src/throw-disabled.ts
|
|
104
|
+
//#region packages/typescript/src/runtime/throw-disabled.ts
|
|
104
105
|
function throwFeatureDisabled(feature, option, annotation) {
|
|
105
106
|
throw new Error(`${feature} support is disabled. To enable, set \`${option}: 'lazy'\` or \`${option}: 'bundle'\` in tsPlugin options, or add @${annotation} annotation to individual interfaces.`);
|
|
106
107
|
}
|
|
107
108
|
|
|
108
109
|
//#endregion
|
|
109
|
-
//#region packages/typescript/src/flatten.ts
|
|
110
|
+
//#region packages/typescript/src/runtime/flatten.ts
|
|
110
111
|
function flattenAnnotatedType(type, options) {
|
|
111
112
|
const flatMap = new Map();
|
|
112
113
|
const skipPhantom = !!options?.excludePhantomTypes;
|
|
@@ -216,7 +217,7 @@ else flatUnion.item(existing);
|
|
|
216
217
|
}
|
|
217
218
|
|
|
218
219
|
//#endregion
|
|
219
|
-
//#region packages/typescript/src/serialize.ts
|
|
220
|
+
//#region packages/typescript/src/runtime/serialize.ts
|
|
220
221
|
const SERIALIZE_VERSION = 1;
|
|
221
222
|
function serializeAnnotatedType(type, options) {
|
|
222
223
|
const visited = new Set();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/typescript",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.38",
|
|
4
4
|
"description": "Atscript: typescript-gen support.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"annotations",
|
|
@@ -64,11 +64,11 @@
|
|
|
64
64
|
"vitest": "3.2.4"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
|
-
"@atscript/core": "^0.1.
|
|
68
|
-
"@atscript/
|
|
67
|
+
"@atscript/core": "^0.1.38",
|
|
68
|
+
"@atscript/db": "^0.1.38"
|
|
69
69
|
},
|
|
70
70
|
"peerDependenciesMeta": {
|
|
71
|
-
"@atscript/
|
|
71
|
+
"@atscript/db": {
|
|
72
72
|
"optional": true
|
|
73
73
|
}
|
|
74
74
|
},
|