@atscript/core 0.1.17 → 0.1.19
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/index.cjs +228 -217
- package/dist/index.d.ts +52 -35
- package/dist/index.mjs +228 -218
- package/package.json +22 -22
package/dist/index.mjs
CHANGED
|
@@ -7,8 +7,8 @@ import { BasicNode } from "@prostojs/parser";
|
|
|
7
7
|
import path$1 from "path";
|
|
8
8
|
import { URL } from "url";
|
|
9
9
|
import { defu } from "defu";
|
|
10
|
-
import { glob } from "glob";
|
|
11
10
|
import { mkdir, writeFile } from "fs/promises";
|
|
11
|
+
import { glob } from "glob";
|
|
12
12
|
|
|
13
13
|
//#region packages/core/src/parser/nodes/semantic-node.ts
|
|
14
14
|
function _define_property$14(obj, key, value) {
|
|
@@ -346,7 +346,7 @@ var Token = class Token {
|
|
|
346
346
|
return this._data.children || [];
|
|
347
347
|
}
|
|
348
348
|
get hasChildren() {
|
|
349
|
-
return
|
|
349
|
+
return (this._data.children?.length ?? 0) > 0;
|
|
350
350
|
}
|
|
351
351
|
/**
|
|
352
352
|
* This is truth if the text token was ended with a newline character
|
|
@@ -424,7 +424,7 @@ var SemanticPrimitiveNode = class SemanticPrimitiveNode extends SemanticNode {
|
|
|
424
424
|
token: dummyToken,
|
|
425
425
|
args: []
|
|
426
426
|
});
|
|
427
|
-
if (
|
|
427
|
+
if (this.config.expect?.pattern !== undefined) {
|
|
428
428
|
const patterns = Array.isArray(this.config.expect.pattern) ? this.config.expect.pattern : [this.config.expect.pattern];
|
|
429
429
|
for (const p of patterns) {
|
|
430
430
|
const args = typeof p === "string" ? [text$1(p)] : [text$1(p.source), text$1(p.flags)];
|
|
@@ -1351,19 +1351,6 @@ const PunctuationToken = new BasicNode({
|
|
|
1351
1351
|
context.customData.type = "punctuation";
|
|
1352
1352
|
});
|
|
1353
1353
|
|
|
1354
|
-
//#endregion
|
|
1355
|
-
//#region packages/core/src/tokenizer/tokens/text.node.ts
|
|
1356
|
-
const TextToken = new BasicNode({
|
|
1357
|
-
icon: "T",
|
|
1358
|
-
tokens: [RegExp("(?<quote>[\"'])", "u"), (context) => new RegExp(`(?<end>${context.getCustomData().quote || ""}|\\n)`)],
|
|
1359
|
-
backSlash: "-ignore",
|
|
1360
|
-
tokenOE: "omit-omit"
|
|
1361
|
-
}).mapContent("text", "join-clear").onMatch((context) => {
|
|
1362
|
-
context.customData.type = "text";
|
|
1363
|
-
}).onPop((context) => {
|
|
1364
|
-
context.customData.multiline = context.customData.end === "\n";
|
|
1365
|
-
});
|
|
1366
|
-
|
|
1367
1354
|
//#endregion
|
|
1368
1355
|
//#region packages/core/src/tokenizer/tokens/regexp.token.ts
|
|
1369
1356
|
const REGEXP_LITERAL_RE = /\/(?![/*])(?:\\.|\[.*?]|[^/\\\n\r[])*\/[dgimsuy]*/;
|
|
@@ -1377,6 +1364,19 @@ const RegExpToken = new BasicNode({
|
|
|
1377
1364
|
ctx.customData.text = ctx.matched[0];
|
|
1378
1365
|
});
|
|
1379
1366
|
|
|
1367
|
+
//#endregion
|
|
1368
|
+
//#region packages/core/src/tokenizer/tokens/text.node.ts
|
|
1369
|
+
const TextToken = new BasicNode({
|
|
1370
|
+
icon: "T",
|
|
1371
|
+
tokens: [RegExp("(?<quote>[\"'])", "u"), (context) => new RegExp(`(?<end>${context.getCustomData().quote || ""}|\\n)`)],
|
|
1372
|
+
backSlash: "-ignore",
|
|
1373
|
+
tokenOE: "omit-omit"
|
|
1374
|
+
}).mapContent("text", "join-clear").onMatch((context) => {
|
|
1375
|
+
context.customData.type = "text";
|
|
1376
|
+
}).onPop((context) => {
|
|
1377
|
+
context.customData.multiline = context.customData.end === "\n";
|
|
1378
|
+
});
|
|
1379
|
+
|
|
1380
1380
|
//#endregion
|
|
1381
1381
|
//#region packages/core/src/tokenizer/tokens/index.ts
|
|
1382
1382
|
const tokens = {
|
|
@@ -1924,13 +1924,14 @@ function propName() {
|
|
|
1924
1924
|
return { handler(ni, target) {
|
|
1925
1925
|
switch (ni.$?.type) {
|
|
1926
1926
|
case "identifier":
|
|
1927
|
-
case "text":
|
|
1927
|
+
case "text": {
|
|
1928
1928
|
target.node.saveToken(new Token(ni.$), "identifier");
|
|
1929
1929
|
ni.accepted();
|
|
1930
1930
|
ni.move();
|
|
1931
1931
|
ni.skip(["\n"]);
|
|
1932
1932
|
return true;
|
|
1933
|
-
|
|
1933
|
+
}
|
|
1934
|
+
case "block": {
|
|
1934
1935
|
const childrenLength = ni.$.children?.length || 0;
|
|
1935
1936
|
const firstText = ni.$.children?.[0]?.text;
|
|
1936
1937
|
if (ni.$.text === "[" && ni.$.children?.[0]?.type === "unknown" && childrenLength === 1 && ni.$.children[0].text === "*" || ni.$.text === "[" && ni.$.children?.[0]?.type === "regexp" && childrenLength === 1) {
|
|
@@ -1940,8 +1941,8 @@ function propName() {
|
|
|
1940
1941
|
});
|
|
1941
1942
|
try {
|
|
1942
1943
|
t.pattern = firstText === "*" ? /./ : parseRegExpLiteral(firstText);
|
|
1943
|
-
} catch (
|
|
1944
|
-
ni.unexpected(false,
|
|
1944
|
+
} catch (error) {
|
|
1945
|
+
ni.unexpected(false, error.message);
|
|
1945
1946
|
return false;
|
|
1946
1947
|
}
|
|
1947
1948
|
target.node.saveToken(t, "identifier");
|
|
@@ -1954,9 +1955,11 @@ function propName() {
|
|
|
1954
1955
|
if (ni.$.text === "[" && childrenLength > 1) ni.unexpected(false, firstText?.startsWith("/") ? "Invalid Regular Expression" : "To many arguments in prop pattern []");
|
|
1955
1956
|
else ni.unexpected(false, "Unexpected identifier at property name");
|
|
1956
1957
|
return false;
|
|
1957
|
-
|
|
1958
|
+
}
|
|
1959
|
+
default: {
|
|
1958
1960
|
ni.unexpected(false, "Unexpected identifier at property name");
|
|
1959
1961
|
return false;
|
|
1962
|
+
}
|
|
1960
1963
|
}
|
|
1961
1964
|
} };
|
|
1962
1965
|
}
|
|
@@ -2329,12 +2332,14 @@ var AtscriptDoc = class {
|
|
|
2329
2332
|
} else {
|
|
2330
2333
|
let severity = 0;
|
|
2331
2334
|
switch (this.config.unknownAnnotation) {
|
|
2332
|
-
case "warn":
|
|
2335
|
+
case "warn": {
|
|
2333
2336
|
severity = 2;
|
|
2334
2337
|
break;
|
|
2335
|
-
|
|
2338
|
+
}
|
|
2339
|
+
case "error": {
|
|
2336
2340
|
severity = 1;
|
|
2337
2341
|
break;
|
|
2342
|
+
}
|
|
2338
2343
|
default:
|
|
2339
2344
|
}
|
|
2340
2345
|
if (severity > 0) this.registerMessage(mainToken, `Unknown annotation "${mainToken.text}"`, severity, "dim");
|
|
@@ -2659,22 +2664,26 @@ else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.pro
|
|
|
2659
2664
|
let sc = "";
|
|
2660
2665
|
let banner = "[atscript]";
|
|
2661
2666
|
switch (m.severity) {
|
|
2662
|
-
case TSeverity.Error:
|
|
2667
|
+
case TSeverity.Error: {
|
|
2663
2668
|
sc = c.red;
|
|
2664
2669
|
banner += "[Error]";
|
|
2665
2670
|
break;
|
|
2666
|
-
|
|
2671
|
+
}
|
|
2672
|
+
case TSeverity.Warning: {
|
|
2667
2673
|
sc = c.yellow;
|
|
2668
2674
|
banner += "[Warning]";
|
|
2669
2675
|
break;
|
|
2670
|
-
|
|
2676
|
+
}
|
|
2677
|
+
case TSeverity.Info: {
|
|
2671
2678
|
sc = "";
|
|
2672
2679
|
banner += "[Info]";
|
|
2673
2680
|
break;
|
|
2674
|
-
|
|
2681
|
+
}
|
|
2682
|
+
case TSeverity.Hint: {
|
|
2675
2683
|
sc = c.dim;
|
|
2676
2684
|
banner += "[Hint]";
|
|
2677
2685
|
break;
|
|
2686
|
+
}
|
|
2678
2687
|
default: sc = "";
|
|
2679
2688
|
}
|
|
2680
2689
|
const n = m.range.start.line + 1;
|
|
@@ -2697,12 +2706,12 @@ else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.pro
|
|
|
2697
2706
|
].filter(Boolean);
|
|
2698
2707
|
const nl = String(n).length + 1;
|
|
2699
2708
|
for (const { l, i } of renderLines) {
|
|
2700
|
-
const prefix = `${c.dim + c.cyan}${
|
|
2709
|
+
const prefix = `${c.dim + c.cyan}${`0${i}`.slice(-nl)} | ${c.reset}`;
|
|
2701
2710
|
out += `\n${prefix}${l}${c.reset}`;
|
|
2702
2711
|
}
|
|
2703
2712
|
out += `\n${" ".repeat(nl + 3 + m.range.start.character)}${c.red}${"^".repeat(m.range.end.character - m.range.start.character)}${c.reset}`;
|
|
2704
2713
|
}
|
|
2705
|
-
return out
|
|
2714
|
+
return `${out}\n`;
|
|
2706
2715
|
}
|
|
2707
2716
|
getDiagMessages() {
|
|
2708
2717
|
if (!this._allMessages) {
|
|
@@ -2762,7 +2771,7 @@ else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.pro
|
|
|
2762
2771
|
}
|
|
2763
2772
|
if (isPrimitive(def) && def.config.isContainer) this._allMessages.push({
|
|
2764
2773
|
severity: 1,
|
|
2765
|
-
message: `"${t.parentNode.id}${t.parentNode.hasChain ?
|
|
2774
|
+
message: `"${t.parentNode.id}${t.parentNode.hasChain ? `.${t.parentNode.chain.map((c) => c.text).join(".")}` : ""}" is a container type — use one of its extensions`,
|
|
2766
2775
|
range: t.range
|
|
2767
2776
|
});
|
|
2768
2777
|
if (t.parentNode.hasChain) {
|
|
@@ -2929,7 +2938,7 @@ else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.pro
|
|
|
2929
2938
|
}
|
|
2930
2939
|
for (const a of left || []) {
|
|
2931
2940
|
const spec = this.resolveAnnotation(a.name);
|
|
2932
|
-
|
|
2941
|
+
const append = spec && spec.config.multiple && spec.config.mergeStrategy === "append";
|
|
2933
2942
|
if (append || !savedAnnotations.has(a.name)) annotations$1.push(a);
|
|
2934
2943
|
}
|
|
2935
2944
|
return annotations$1;
|
|
@@ -3006,6 +3015,181 @@ const zeroRange = {
|
|
|
3006
3015
|
}
|
|
3007
3016
|
};
|
|
3008
3017
|
|
|
3018
|
+
//#endregion
|
|
3019
|
+
//#region packages/core/src/defaults/emit-annotations.ts
|
|
3020
|
+
const emitAnnotations = { jsonSchema: new AnnotationSpec({
|
|
3021
|
+
nodeType: ["interface"],
|
|
3022
|
+
description: "Pre-compute and embed JSON Schema at build time for this interface, regardless of the global jsonSchema plugin option."
|
|
3023
|
+
}) };
|
|
3024
|
+
|
|
3025
|
+
//#endregion
|
|
3026
|
+
//#region packages/core/src/defaults/expect-annotations.ts
|
|
3027
|
+
const expectAnnotations = {
|
|
3028
|
+
minLength: new AnnotationSpec({
|
|
3029
|
+
description: "Validates that a string or array has a minimum length.\n\n**Example:**```atscript@expect.minLength 5name: string```",
|
|
3030
|
+
defType: ["array", "string"],
|
|
3031
|
+
argument: [{
|
|
3032
|
+
name: "length",
|
|
3033
|
+
type: "number",
|
|
3034
|
+
description: "The minimum length of the string or array."
|
|
3035
|
+
}, {
|
|
3036
|
+
name: "message",
|
|
3037
|
+
optional: true,
|
|
3038
|
+
type: "string",
|
|
3039
|
+
description: "Optional error message to display if the validation fails."
|
|
3040
|
+
}]
|
|
3041
|
+
}),
|
|
3042
|
+
maxLength: new AnnotationSpec({
|
|
3043
|
+
description: "Validates that a string or array has a maximum length.\n\n**Example:**```atscript@expect.maxLength 5name: string```",
|
|
3044
|
+
defType: ["array", "string"],
|
|
3045
|
+
argument: [{
|
|
3046
|
+
name: "length",
|
|
3047
|
+
type: "number",
|
|
3048
|
+
description: "The maximum length of the string or array."
|
|
3049
|
+
}, {
|
|
3050
|
+
name: "message",
|
|
3051
|
+
optional: true,
|
|
3052
|
+
type: "string",
|
|
3053
|
+
description: "Optional error message to display if the validation fails."
|
|
3054
|
+
}]
|
|
3055
|
+
}),
|
|
3056
|
+
min: new AnnotationSpec({
|
|
3057
|
+
description: "Validates that a number is greater than or equal to a minimum value.\n\n**Example:**```atscript@expect.min 18age: number```",
|
|
3058
|
+
defType: ["number"],
|
|
3059
|
+
argument: [{
|
|
3060
|
+
name: "minValue",
|
|
3061
|
+
type: "number",
|
|
3062
|
+
description: "The minimum value."
|
|
3063
|
+
}, {
|
|
3064
|
+
name: "message",
|
|
3065
|
+
optional: true,
|
|
3066
|
+
type: "string",
|
|
3067
|
+
description: "Optional error message to display if the validation fails."
|
|
3068
|
+
}]
|
|
3069
|
+
}),
|
|
3070
|
+
max: new AnnotationSpec({
|
|
3071
|
+
description: "Validates that a number is less than or equal to a maximum value.\n\n**Example:**```atscript@expect.max 10count: number```",
|
|
3072
|
+
defType: ["number"],
|
|
3073
|
+
argument: [{
|
|
3074
|
+
name: "maxValue",
|
|
3075
|
+
type: "number",
|
|
3076
|
+
description: "The maximum value."
|
|
3077
|
+
}, {
|
|
3078
|
+
name: "message",
|
|
3079
|
+
optional: true,
|
|
3080
|
+
type: "string",
|
|
3081
|
+
description: "Optional error message to display if the validation fails."
|
|
3082
|
+
}]
|
|
3083
|
+
}),
|
|
3084
|
+
int: new AnnotationSpec({
|
|
3085
|
+
description: "Validates that a number is an integer (no decimal places).\n\n**Example:**```atscript@expect.intage: number```",
|
|
3086
|
+
defType: ["number"]
|
|
3087
|
+
}),
|
|
3088
|
+
pattern: new AnnotationSpec({
|
|
3089
|
+
description: "Validates that a string matches a specific pattern.\n\n**Example:**```atscript@expect.pattern \"[a-z]+\", \"u\"name: string```",
|
|
3090
|
+
defType: ["string"],
|
|
3091
|
+
multiple: true,
|
|
3092
|
+
mergeStrategy: "append",
|
|
3093
|
+
argument: [
|
|
3094
|
+
{
|
|
3095
|
+
name: "pattern",
|
|
3096
|
+
type: "string",
|
|
3097
|
+
description: "The regular expression pattern to match."
|
|
3098
|
+
},
|
|
3099
|
+
{
|
|
3100
|
+
name: "flags",
|
|
3101
|
+
optional: true,
|
|
3102
|
+
type: "string",
|
|
3103
|
+
values: [
|
|
3104
|
+
"g",
|
|
3105
|
+
"gi",
|
|
3106
|
+
"gim",
|
|
3107
|
+
"gims",
|
|
3108
|
+
"gimsu",
|
|
3109
|
+
"gimsuy",
|
|
3110
|
+
"gimsy",
|
|
3111
|
+
"gimu",
|
|
3112
|
+
"gimuy",
|
|
3113
|
+
"gimy",
|
|
3114
|
+
"gis",
|
|
3115
|
+
"gisu",
|
|
3116
|
+
"gisuy",
|
|
3117
|
+
"gisy",
|
|
3118
|
+
"giu",
|
|
3119
|
+
"giuy",
|
|
3120
|
+
"giy",
|
|
3121
|
+
"gm",
|
|
3122
|
+
"gms",
|
|
3123
|
+
"gmsu",
|
|
3124
|
+
"gmsuy",
|
|
3125
|
+
"gmsy",
|
|
3126
|
+
"gmu",
|
|
3127
|
+
"gmuy",
|
|
3128
|
+
"gmy",
|
|
3129
|
+
"gs",
|
|
3130
|
+
"gsu",
|
|
3131
|
+
"gsuy",
|
|
3132
|
+
"gsy",
|
|
3133
|
+
"gu",
|
|
3134
|
+
"guy",
|
|
3135
|
+
"gy",
|
|
3136
|
+
"i",
|
|
3137
|
+
"im",
|
|
3138
|
+
"ims",
|
|
3139
|
+
"imsu",
|
|
3140
|
+
"imsuy",
|
|
3141
|
+
"imsy",
|
|
3142
|
+
"imu",
|
|
3143
|
+
"imuy",
|
|
3144
|
+
"imy",
|
|
3145
|
+
"is",
|
|
3146
|
+
"isu",
|
|
3147
|
+
"isuy",
|
|
3148
|
+
"isy",
|
|
3149
|
+
"iu",
|
|
3150
|
+
"iuy",
|
|
3151
|
+
"iy",
|
|
3152
|
+
"m",
|
|
3153
|
+
"ms",
|
|
3154
|
+
"msu",
|
|
3155
|
+
"msuy",
|
|
3156
|
+
"msy",
|
|
3157
|
+
"mu",
|
|
3158
|
+
"muy",
|
|
3159
|
+
"my",
|
|
3160
|
+
"s",
|
|
3161
|
+
"su",
|
|
3162
|
+
"suy",
|
|
3163
|
+
"sy",
|
|
3164
|
+
"u",
|
|
3165
|
+
"uy",
|
|
3166
|
+
"y"
|
|
3167
|
+
],
|
|
3168
|
+
description: "Optional flags for the regular expression."
|
|
3169
|
+
},
|
|
3170
|
+
{
|
|
3171
|
+
name: "message",
|
|
3172
|
+
optional: true,
|
|
3173
|
+
type: "string",
|
|
3174
|
+
description: "Optional error message to display if the validation fails."
|
|
3175
|
+
}
|
|
3176
|
+
],
|
|
3177
|
+
validate(mainToken, args) {
|
|
3178
|
+
if (args[0]) try {
|
|
3179
|
+
new RegExp(args[0].text);
|
|
3180
|
+
return [];
|
|
3181
|
+
} catch (error) {
|
|
3182
|
+
return [{
|
|
3183
|
+
message: "Invalid regular expression",
|
|
3184
|
+
range: args[0].range,
|
|
3185
|
+
severity: 1
|
|
3186
|
+
}];
|
|
3187
|
+
}
|
|
3188
|
+
return [];
|
|
3189
|
+
}
|
|
3190
|
+
})
|
|
3191
|
+
};
|
|
3192
|
+
|
|
3009
3193
|
//#endregion
|
|
3010
3194
|
//#region packages/core/src/defaults/meta-annotations.ts
|
|
3011
3195
|
const metaAnnotations = {
|
|
@@ -3045,7 +3229,7 @@ const metaAnnotations = {
|
|
|
3045
3229
|
}),
|
|
3046
3230
|
placeholder: new AnnotationSpec({
|
|
3047
3231
|
description: "Defines a **default placeholder value** for UI input fields.\n\n**Example:**```atscript@meta.placeholder \"Enter your name\"name: string```",
|
|
3048
|
-
nodeType: ["prop"],
|
|
3232
|
+
nodeType: ["prop", "type"],
|
|
3049
3233
|
argument: {
|
|
3050
3234
|
name: "text",
|
|
3051
3235
|
type: "string",
|
|
@@ -3054,12 +3238,12 @@ const metaAnnotations = {
|
|
|
3054
3238
|
}),
|
|
3055
3239
|
sensitive: new AnnotationSpec({
|
|
3056
3240
|
description: "Marks a field as **sensitive** (e.g., passwords, API keys), ensuring it is hidden in logs and UI.\n\n**Example:**```atscript@meta.sensitivepassword: string```",
|
|
3057
|
-
nodeType: ["prop"],
|
|
3241
|
+
nodeType: ["prop", "type"],
|
|
3058
3242
|
multiple: false
|
|
3059
3243
|
}),
|
|
3060
3244
|
readonly: new AnnotationSpec({
|
|
3061
3245
|
description: "Marks a field as **read-only**.\n\n**Example:**```atscript@meta.readonlycreatedAt: string.date```",
|
|
3062
|
-
nodeType: ["prop"],
|
|
3246
|
+
nodeType: ["prop", "type"],
|
|
3063
3247
|
multiple: false
|
|
3064
3248
|
}),
|
|
3065
3249
|
required: new AnnotationSpec({
|
|
@@ -3074,7 +3258,7 @@ const metaAnnotations = {
|
|
|
3074
3258
|
}),
|
|
3075
3259
|
isKey: new AnnotationSpec({
|
|
3076
3260
|
description: "Marks a **key field** inside an array. This annotation is used to identify unique fields within an array that can be used as **lookup keys**.\n\n\n\n**Example:**\n```atscript\nexport interface User {\n id: string\n profiles: {\n @meta.isKey\n profileId: string\n name: string\n }[]\n}\n```\n",
|
|
3077
|
-
nodeType: ["prop"],
|
|
3261
|
+
nodeType: ["prop", "type"],
|
|
3078
3262
|
multiple: false,
|
|
3079
3263
|
validate(token, args, doc) {
|
|
3080
3264
|
const field = token.parentNode;
|
|
@@ -3222,181 +3406,6 @@ const primitives = {
|
|
|
3222
3406
|
}
|
|
3223
3407
|
};
|
|
3224
3408
|
|
|
3225
|
-
//#endregion
|
|
3226
|
-
//#region packages/core/src/defaults/expect-annotations.ts
|
|
3227
|
-
const expectAnnotations = {
|
|
3228
|
-
minLength: new AnnotationSpec({
|
|
3229
|
-
description: "Validates that a string or array has a minimum length.\n\n**Example:**```atscript@expect.minLength 5name: string```",
|
|
3230
|
-
defType: ["array", "string"],
|
|
3231
|
-
argument: [{
|
|
3232
|
-
name: "length",
|
|
3233
|
-
type: "number",
|
|
3234
|
-
description: "The minimum length of the string or array."
|
|
3235
|
-
}, {
|
|
3236
|
-
name: "message",
|
|
3237
|
-
optional: true,
|
|
3238
|
-
type: "string",
|
|
3239
|
-
description: "Optional error message to display if the validation fails."
|
|
3240
|
-
}]
|
|
3241
|
-
}),
|
|
3242
|
-
maxLength: new AnnotationSpec({
|
|
3243
|
-
description: "Validates that a string or array has a maximum length.\n\n**Example:**```atscript@expect.maxLength 5name: string```",
|
|
3244
|
-
defType: ["array", "string"],
|
|
3245
|
-
argument: [{
|
|
3246
|
-
name: "length",
|
|
3247
|
-
type: "number",
|
|
3248
|
-
description: "The maximum length of the string or array."
|
|
3249
|
-
}, {
|
|
3250
|
-
name: "message",
|
|
3251
|
-
optional: true,
|
|
3252
|
-
type: "string",
|
|
3253
|
-
description: "Optional error message to display if the validation fails."
|
|
3254
|
-
}]
|
|
3255
|
-
}),
|
|
3256
|
-
min: new AnnotationSpec({
|
|
3257
|
-
description: "Validates that a number is greater than or equal to a minimum value.\n\n**Example:**```atscript@expect.min 18age: number```",
|
|
3258
|
-
defType: ["number"],
|
|
3259
|
-
argument: [{
|
|
3260
|
-
name: "minValue",
|
|
3261
|
-
type: "number",
|
|
3262
|
-
description: "The minimum value."
|
|
3263
|
-
}, {
|
|
3264
|
-
name: "message",
|
|
3265
|
-
optional: true,
|
|
3266
|
-
type: "string",
|
|
3267
|
-
description: "Optional error message to display if the validation fails."
|
|
3268
|
-
}]
|
|
3269
|
-
}),
|
|
3270
|
-
max: new AnnotationSpec({
|
|
3271
|
-
description: "Validates that a number is less than or equal to a maximum value.\n\n**Example:**```atscript@expect.max 10count: number```",
|
|
3272
|
-
defType: ["number"],
|
|
3273
|
-
argument: [{
|
|
3274
|
-
name: "maxValue",
|
|
3275
|
-
type: "number",
|
|
3276
|
-
description: "The maximum value."
|
|
3277
|
-
}, {
|
|
3278
|
-
name: "message",
|
|
3279
|
-
optional: true,
|
|
3280
|
-
type: "string",
|
|
3281
|
-
description: "Optional error message to display if the validation fails."
|
|
3282
|
-
}]
|
|
3283
|
-
}),
|
|
3284
|
-
int: new AnnotationSpec({
|
|
3285
|
-
description: "Validates that a number is an integer (no decimal places).\n\n**Example:**```atscript@expect.intage: number```",
|
|
3286
|
-
defType: ["number"]
|
|
3287
|
-
}),
|
|
3288
|
-
pattern: new AnnotationSpec({
|
|
3289
|
-
description: "Validates that a string matches a specific pattern.\n\n**Example:**```atscript@expect.pattern \"[a-z]+\", \"u\"name: string```",
|
|
3290
|
-
defType: ["string"],
|
|
3291
|
-
multiple: true,
|
|
3292
|
-
mergeStrategy: "append",
|
|
3293
|
-
argument: [
|
|
3294
|
-
{
|
|
3295
|
-
name: "pattern",
|
|
3296
|
-
type: "string",
|
|
3297
|
-
description: "The regular expression pattern to match."
|
|
3298
|
-
},
|
|
3299
|
-
{
|
|
3300
|
-
name: "flags",
|
|
3301
|
-
optional: true,
|
|
3302
|
-
type: "string",
|
|
3303
|
-
values: [
|
|
3304
|
-
"g",
|
|
3305
|
-
"gi",
|
|
3306
|
-
"gim",
|
|
3307
|
-
"gims",
|
|
3308
|
-
"gimsu",
|
|
3309
|
-
"gimsuy",
|
|
3310
|
-
"gimsy",
|
|
3311
|
-
"gimu",
|
|
3312
|
-
"gimuy",
|
|
3313
|
-
"gimy",
|
|
3314
|
-
"gis",
|
|
3315
|
-
"gisu",
|
|
3316
|
-
"gisuy",
|
|
3317
|
-
"gisy",
|
|
3318
|
-
"giu",
|
|
3319
|
-
"giuy",
|
|
3320
|
-
"giy",
|
|
3321
|
-
"gm",
|
|
3322
|
-
"gms",
|
|
3323
|
-
"gmsu",
|
|
3324
|
-
"gmsuy",
|
|
3325
|
-
"gmsy",
|
|
3326
|
-
"gmu",
|
|
3327
|
-
"gmuy",
|
|
3328
|
-
"gmy",
|
|
3329
|
-
"gs",
|
|
3330
|
-
"gsu",
|
|
3331
|
-
"gsuy",
|
|
3332
|
-
"gsy",
|
|
3333
|
-
"gu",
|
|
3334
|
-
"guy",
|
|
3335
|
-
"gy",
|
|
3336
|
-
"i",
|
|
3337
|
-
"im",
|
|
3338
|
-
"ims",
|
|
3339
|
-
"imsu",
|
|
3340
|
-
"imsuy",
|
|
3341
|
-
"imsy",
|
|
3342
|
-
"imu",
|
|
3343
|
-
"imuy",
|
|
3344
|
-
"imy",
|
|
3345
|
-
"is",
|
|
3346
|
-
"isu",
|
|
3347
|
-
"isuy",
|
|
3348
|
-
"isy",
|
|
3349
|
-
"iu",
|
|
3350
|
-
"iuy",
|
|
3351
|
-
"iy",
|
|
3352
|
-
"m",
|
|
3353
|
-
"ms",
|
|
3354
|
-
"msu",
|
|
3355
|
-
"msuy",
|
|
3356
|
-
"msy",
|
|
3357
|
-
"mu",
|
|
3358
|
-
"muy",
|
|
3359
|
-
"my",
|
|
3360
|
-
"s",
|
|
3361
|
-
"su",
|
|
3362
|
-
"suy",
|
|
3363
|
-
"sy",
|
|
3364
|
-
"u",
|
|
3365
|
-
"uy",
|
|
3366
|
-
"y"
|
|
3367
|
-
],
|
|
3368
|
-
description: "Optional flags for the regular expression."
|
|
3369
|
-
},
|
|
3370
|
-
{
|
|
3371
|
-
name: "message",
|
|
3372
|
-
optional: true,
|
|
3373
|
-
type: "string",
|
|
3374
|
-
description: "Optional error message to display if the validation fails."
|
|
3375
|
-
}
|
|
3376
|
-
],
|
|
3377
|
-
validate(mainToken, args) {
|
|
3378
|
-
if (args[0]) try {
|
|
3379
|
-
new RegExp(args[0].text);
|
|
3380
|
-
return [];
|
|
3381
|
-
} catch (e) {
|
|
3382
|
-
return [{
|
|
3383
|
-
message: "Invalid regular expression",
|
|
3384
|
-
range: args[0].range,
|
|
3385
|
-
severity: 1
|
|
3386
|
-
}];
|
|
3387
|
-
}
|
|
3388
|
-
return [];
|
|
3389
|
-
}
|
|
3390
|
-
})
|
|
3391
|
-
};
|
|
3392
|
-
|
|
3393
|
-
//#endregion
|
|
3394
|
-
//#region packages/core/src/defaults/emit-annotations.ts
|
|
3395
|
-
const emitAnnotations = { jsonSchema: new AnnotationSpec({
|
|
3396
|
-
nodeType: ["interface"],
|
|
3397
|
-
description: "Pre-compute and embed JSON Schema at build time for this interface, regardless of the global jsonSchema plugin option."
|
|
3398
|
-
}) };
|
|
3399
|
-
|
|
3400
3409
|
//#endregion
|
|
3401
3410
|
//#region packages/core/src/default-atscript-config.ts
|
|
3402
3411
|
function getDefaultAtscriptConfig() {
|
|
@@ -3476,8 +3485,8 @@ var PluginManager = class {
|
|
|
3476
3485
|
const content = await readFile(filePath, "utf8");
|
|
3477
3486
|
return content.toString();
|
|
3478
3487
|
}
|
|
3479
|
-
async
|
|
3480
|
-
for (const plugin of this.plugins) if (plugin.
|
|
3488
|
+
async onDocument(doc) {
|
|
3489
|
+
for (const plugin of this.plugins) if (plugin.onDocument) await plugin.onDocument(doc);
|
|
3481
3490
|
}
|
|
3482
3491
|
async render(doc, format) {
|
|
3483
3492
|
const files = [];
|
|
@@ -3571,8 +3580,8 @@ else types.push({ type: "boolean" });
|
|
|
3571
3580
|
for (const { name, token, args } of awaited.annotations) {
|
|
3572
3581
|
if (annotations$1[name]?.fromSpec) continue;
|
|
3573
3582
|
if (!annotations$1[name]) {
|
|
3574
|
-
|
|
3575
|
-
|
|
3583
|
+
const types = [];
|
|
3584
|
+
const multiple = false;
|
|
3576
3585
|
annotations$1[name] = {
|
|
3577
3586
|
multiple,
|
|
3578
3587
|
fromSpec: false,
|
|
@@ -3674,10 +3683,10 @@ else types.push({ type: "boolean" });
|
|
|
3674
3683
|
const newId = await manager.resolve(id);
|
|
3675
3684
|
if (!newId) throw new Error(`Document not resolved: ${id}`);
|
|
3676
3685
|
const content = text$2 || await manager.load(newId);
|
|
3677
|
-
if (typeof content !== "string") throw new
|
|
3686
|
+
if (typeof content !== "string") throw new TypeError(`Document not found: ${newId}`);
|
|
3678
3687
|
const atscript = new AtscriptDoc(id, await manager.getDocConfig(), manager);
|
|
3679
3688
|
atscript.update(content);
|
|
3680
|
-
await manager.
|
|
3689
|
+
await manager.onDocument(atscript);
|
|
3681
3690
|
return atscript;
|
|
3682
3691
|
}
|
|
3683
3692
|
async checkDoc(atscript) {
|
|
@@ -3749,6 +3758,7 @@ else types.push({ type: "boolean" });
|
|
|
3749
3758
|
|
|
3750
3759
|
//#endregion
|
|
3751
3760
|
//#region packages/core/src/plugin/types.ts
|
|
3761
|
+
const DEFAULT_FORMAT = "__default__";
|
|
3752
3762
|
const createAtscriptPlugin = (plugin) => plugin;
|
|
3753
3763
|
|
|
3754
3764
|
//#endregion
|
|
@@ -3780,7 +3790,7 @@ else {
|
|
|
3780
3790
|
entries.push(...found);
|
|
3781
3791
|
}
|
|
3782
3792
|
const documents = [];
|
|
3783
|
-
for (const entry of entries) documents.push(await repo.openDocument(
|
|
3793
|
+
for (const entry of entries) documents.push(await repo.openDocument(`file://${entry}`));
|
|
3784
3794
|
return new BuildRepo(rootDir, repo, documents.filter(Boolean));
|
|
3785
3795
|
}
|
|
3786
3796
|
var BuildRepo = class {
|
|
@@ -3834,4 +3844,4 @@ var BuildRepo = class {
|
|
|
3834
3844
|
};
|
|
3835
3845
|
|
|
3836
3846
|
//#endregion
|
|
3837
|
-
export { $n, AnnotationSpec, AtscriptDoc, AtscriptRepo, BuildRepo, PluginManager, SemanticAnnotateNode, SemanticArrayNode, SemanticConstNode, SemanticGroup, SemanticImportNode, SemanticInterfaceNode, SemanticNode, SemanticPrimitiveNode, SemanticPropNode, SemanticRefNode, SemanticStructureNode, SemanticTupleNode, SemanticTypeNode, Token, build, createAtscriptPlugin, defineConfig, getRelPath, isAnnotate, isAnnotationSpec, isArray, isConst, isGroup, isImport, isInterface, isPrimitive, isProp, isRef, isStructure, isTuple, isType, loadConfig, loadTsConfig, resolveAnnotation, resolveAtscriptFromPath, resolveConfigFile };
|
|
3847
|
+
export { $n, AnnotationSpec, AtscriptDoc, AtscriptRepo, BuildRepo, DEFAULT_FORMAT, PluginManager, SemanticAnnotateNode, SemanticArrayNode, SemanticConstNode, SemanticGroup, SemanticImportNode, SemanticInterfaceNode, SemanticNode, SemanticPrimitiveNode, SemanticPropNode, SemanticRefNode, SemanticStructureNode, SemanticTupleNode, SemanticTypeNode, Token, build, createAtscriptPlugin, defineConfig, getRelPath, isAnnotate, isAnnotationSpec, isArray, isConst, isGroup, isImport, isInterface, isPrimitive, isProp, isRef, isStructure, isTuple, isType, loadConfig, loadTsConfig, resolveAnnotation, resolveAtscriptFromPath, resolveConfigFile };
|
package/package.json
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.19",
|
|
4
4
|
"description": "Core library for Atscript parsing and file generation.",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "dist/index.mjs",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
8
|
-
"exports": {
|
|
9
|
-
".": {
|
|
10
|
-
"types": "./dist/index.d.ts",
|
|
11
|
-
"import": "./dist/index.mjs",
|
|
12
|
-
"require": "./dist/index.cjs"
|
|
13
|
-
},
|
|
14
|
-
"./package.json": "./package.json"
|
|
15
|
-
},
|
|
16
|
-
"files": [
|
|
17
|
-
"dist"
|
|
18
|
-
],
|
|
19
5
|
"keywords": [
|
|
20
|
-
"atscript",
|
|
21
6
|
"annotations",
|
|
7
|
+
"atscript",
|
|
8
|
+
"code-generation",
|
|
22
9
|
"interfaces",
|
|
23
|
-
"runtime"
|
|
24
|
-
"code-generation"
|
|
10
|
+
"runtime"
|
|
25
11
|
],
|
|
12
|
+
"homepage": "https://github.com/moostjs/atscript/tree/main/packages/core#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/moostjs/atscript/issues"
|
|
15
|
+
},
|
|
16
|
+
"license": "ISC",
|
|
26
17
|
"author": "Artem Maltsev",
|
|
27
18
|
"repository": {
|
|
28
19
|
"type": "git",
|
|
29
20
|
"url": "git+https://github.com/moostjs/atscript.git",
|
|
30
21
|
"directory": "packages/core"
|
|
31
22
|
},
|
|
32
|
-
"
|
|
33
|
-
"
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"type": "module",
|
|
27
|
+
"main": "dist/index.mjs",
|
|
28
|
+
"types": "dist/index.d.ts",
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"import": "./dist/index.mjs",
|
|
33
|
+
"require": "./dist/index.cjs"
|
|
34
|
+
},
|
|
35
|
+
"./package.json": "./package.json"
|
|
34
36
|
},
|
|
35
|
-
"homepage": "https://github.com/moostjs/atscript/tree/main/packages/core#readme",
|
|
36
|
-
"license": "ISC",
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@prostojs/parser": "^0.5.11",
|
|
39
39
|
"defu": "^6.1.4",
|