tsondb 0.19.17 → 0.20.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/dist/src/node/renderers/ts/render.d.ts +1 -1
- package/dist/src/node/renderers/ts/render.js +13 -8
- package/dist/src/node/schema/dsl/types/StringType.d.ts +3 -2
- package/dist/src/node/schema/treeOperations/format.js +13 -28
- package/dist/src/shared/schema/types/StringType.d.ts +2 -1
- package/dist/src/shared/schema/types/Type.js +1 -1
- package/dist/src/web/488.js +44 -22
- package/package.json +1 -1
|
@@ -20,7 +20,7 @@ export type TypeScriptRendererOptions = {
|
|
|
20
20
|
* If `true` or a string, generates an object type with all names of the type aliases as the key and their corresponding generated type as their respective value. Uses `TypeAliasMap` as a default name when using `true` or the string if set to a string.
|
|
21
21
|
*/
|
|
22
22
|
typeAliasMap: boolean | string;
|
|
23
|
-
}
|
|
23
|
+
}> | boolean;
|
|
24
24
|
addIdentifierToEntities: boolean;
|
|
25
25
|
/**
|
|
26
26
|
* Infer translation parameter types from the message strings in a {@link TranslationObjectType TranslationObject} as branded types.
|
|
@@ -170,14 +170,19 @@ const renderImports = (currentUrl, imports) => {
|
|
|
170
170
|
.join(EOL);
|
|
171
171
|
return importsSyntax.length > 0 ? importsSyntax + EOL + EOL : "";
|
|
172
172
|
};
|
|
173
|
-
const renderMapHelperType = (options, declarations, key, defaultName, filterFn, renderKeyFn) =>
|
|
174
|
-
|
|
175
|
-
.
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
173
|
+
const renderMapHelperType = (options, declarations, key, defaultName, filterFn, renderKeyFn) => {
|
|
174
|
+
const option = typeof options.generateHelpers === "boolean"
|
|
175
|
+
? options.generateHelpers
|
|
176
|
+
: options.generateHelpers[key];
|
|
177
|
+
return option
|
|
178
|
+
? `export type ${option === true ? defaultName : option} = {${EOL}${prefixLines(getIndentation(options.indentation, 1), declarations
|
|
179
|
+
.filter(filterFn)
|
|
180
|
+
.sort((a, b) => a.name.localeCompare(b.name))
|
|
181
|
+
.map(renderKeyFn ??
|
|
182
|
+
(decl => `${decl.name}: ${decl.name}${decl.parameters.length > 0 ? "<" + decl.parameters.map(param => (param.constraint ? renderType(options, param.constraint)[1] : "unknown")).join(", ") + ">" : ""}`))
|
|
183
|
+
.join(EOL))}${EOL}}${EOL + EOL}`
|
|
184
|
+
: "";
|
|
185
|
+
};
|
|
181
186
|
const renderEntityMapType = (options, declarations) => renderMapHelperType(options, declarations, "entityMap", "EntityMap", isEntityDecl);
|
|
182
187
|
const renderChildEntityMapType = (options, declarations) => renderMapHelperType(options, declarations, "childEntityMap", "ChildEntityMap", decl => isEntityDecl(decl) && isEntityDeclWithParentReference(decl), decl => `${decl.name}: [${decl.name}, "${decl.parentReferenceKey}", ${decl.name}["${decl.parentReferenceKey}"]]`);
|
|
183
188
|
const renderEnumMapType = (options, declarations) => renderMapHelperType(options, declarations, "enumMap", "EnumMap", isEnumDecl);
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { NodeKind } from "../../../../shared/schema/Node.js";
|
|
2
|
+
import type { MarkdownStringOption } from "../../../../shared/schema/types/StringType.ts";
|
|
2
3
|
import type { StringConstraints } from "../../../../shared/validation/string.ts";
|
|
3
4
|
import type { Node } from "../index.ts";
|
|
4
5
|
import type { BaseType } from "./Type.ts";
|
|
5
6
|
export interface StringType extends BaseType, StringConstraints {
|
|
6
7
|
kind: NodeKind["StringType"];
|
|
7
8
|
pattern?: RegExp;
|
|
8
|
-
|
|
9
|
+
markdown?: MarkdownStringOption;
|
|
9
10
|
}
|
|
10
11
|
export declare const StringType: (options?: {
|
|
11
12
|
minLength?: number;
|
|
12
13
|
maxLength?: number;
|
|
13
14
|
pattern?: RegExp;
|
|
14
|
-
|
|
15
|
+
markdown?: MarkdownStringOption;
|
|
15
16
|
}) => StringType;
|
|
16
17
|
export { StringType as String };
|
|
17
18
|
export declare const isStringType: (node: Node) => node is StringType;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { sortObjectKeys, sortObjectKeysByIndex } from "@elyukai/utils/object";
|
|
1
|
+
import { mapObject, sortObjectKeys, sortObjectKeysByIndex } from "@elyukai/utils/object";
|
|
2
2
|
import { assertExhaustive } from "@elyukai/utils/typeSafety";
|
|
3
3
|
import { ENUM_DISCRIMINATOR_KEY } from "../../../shared/schema/declarations/EnumDecl.js";
|
|
4
4
|
import { NodeKind } from "../../../shared/schema/Node.js";
|
|
5
|
-
import { isObjectType } from "../dsl/types/ObjectType.js";
|
|
6
5
|
const formatTranslationObjectValue = (type, value) => typeof value === "object" && value !== null && !Array.isArray(value)
|
|
7
6
|
? sortObjectKeysByIndex(Object.fromEntries(Object.entries(value).map(([key, item]) => [
|
|
8
7
|
key,
|
|
@@ -18,36 +17,14 @@ export const formatValue = (type, value) => {
|
|
|
18
17
|
return Array.isArray(value) ? value.map(item => formatValue(type.items, item)) : value;
|
|
19
18
|
case NodeKind.ObjectType:
|
|
20
19
|
return typeof value === "object" && value !== null && !Array.isArray(value)
|
|
21
|
-
? sortObjectKeysByIndex(
|
|
22
|
-
key,
|
|
23
|
-
type.properties[key] ? formatValue(type.properties[key].type, item) : item,
|
|
24
|
-
])), Object.keys(type.properties))
|
|
20
|
+
? sortObjectKeysByIndex(mapObject(value, (item, key) => type.properties[key] ? formatValue(type.properties[key].type, item) : item), Object.keys(type.properties))
|
|
25
21
|
: value;
|
|
26
|
-
case NodeKind.BooleanType:
|
|
27
|
-
return value;
|
|
28
|
-
case NodeKind.DateType:
|
|
29
|
-
return value;
|
|
30
|
-
case NodeKind.FloatType:
|
|
31
|
-
return value;
|
|
32
|
-
case NodeKind.IntegerType:
|
|
33
|
-
return value;
|
|
34
|
-
case NodeKind.StringType:
|
|
35
|
-
return value;
|
|
36
|
-
case NodeKind.TypeArgumentType:
|
|
37
|
-
return value;
|
|
38
22
|
case NodeKind.IncludeIdentifierType:
|
|
39
23
|
return formatValue(type.reference.type.value, value);
|
|
40
24
|
case NodeKind.NestedEntityMapType:
|
|
41
|
-
return
|
|
42
|
-
?
|
|
43
|
-
|
|
44
|
-
key,
|
|
45
|
-
formatValue(type.type.value, item),
|
|
46
|
-
])))
|
|
47
|
-
: value
|
|
48
|
-
: formatValue(type.type.value, value);
|
|
49
|
-
case NodeKind.ReferenceIdentifierType:
|
|
50
|
-
return value;
|
|
25
|
+
return typeof value === "object" && value !== null && !Array.isArray(value)
|
|
26
|
+
? sortObjectKeys(mapObject(value, item => formatValue(type.type.value, item)))
|
|
27
|
+
: value;
|
|
51
28
|
case NodeKind.EnumType: {
|
|
52
29
|
if (typeof value === "object" &&
|
|
53
30
|
value !== null &&
|
|
@@ -70,6 +47,14 @@ export const formatValue = (type, value) => {
|
|
|
70
47
|
return Array.isArray(value) ? value.toSorted() : value;
|
|
71
48
|
case NodeKind.TranslationObjectType:
|
|
72
49
|
return formatTranslationObjectValue(type.properties, value);
|
|
50
|
+
case NodeKind.BooleanType:
|
|
51
|
+
case NodeKind.DateType:
|
|
52
|
+
case NodeKind.FloatType:
|
|
53
|
+
case NodeKind.IntegerType:
|
|
54
|
+
case NodeKind.StringType:
|
|
55
|
+
case NodeKind.TypeArgumentType:
|
|
56
|
+
case NodeKind.ReferenceIdentifierType:
|
|
57
|
+
return value;
|
|
73
58
|
default:
|
|
74
59
|
return assertExhaustive(type);
|
|
75
60
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { StringConstraints } from "../../validation/string.ts";
|
|
2
2
|
import type { GetReferencesSerialized, NodeKind, SerializedTypeArgumentsResolver } from "../Node.ts";
|
|
3
3
|
import type { SerializedBaseType } from "./Type.ts";
|
|
4
|
+
export type MarkdownStringOption = "block" | "inline";
|
|
4
5
|
export interface SerializedStringType extends SerializedBaseType, StringConstraints {
|
|
5
6
|
kind: NodeKind["StringType"];
|
|
6
7
|
pattern?: string;
|
|
7
|
-
|
|
8
|
+
markdown?: MarkdownStringOption;
|
|
8
9
|
}
|
|
9
10
|
export declare const resolveTypeArgumentsInSerializedStringType: SerializedTypeArgumentsResolver<SerializedStringType>;
|
|
10
11
|
export declare const getReferencesForSerializedStringType: GetReferencesSerialized<SerializedStringType>;
|
package/dist/src/web/488.js
CHANGED
|
@@ -2867,6 +2867,8 @@ const Layout = ({ breadcrumbs, children })=>{
|
|
|
2867
2867
|
]
|
|
2868
2868
|
});
|
|
2869
2869
|
};
|
|
2870
|
+
const isEmpty = (arr)=>0 === arr.length;
|
|
2871
|
+
const isNotEmpty = (arr)=>!isEmpty(arr);
|
|
2870
2872
|
class Parser {
|
|
2871
2873
|
#fn;
|
|
2872
2874
|
constructor(fn){
|
|
@@ -3412,8 +3414,18 @@ const inlineNode = combineParsers([
|
|
|
3412
3414
|
leafParser(defaultInlineSyntaxStartSequences)
|
|
3413
3415
|
]);
|
|
3414
3416
|
const inlineMarkdown = inlineNode.many();
|
|
3415
|
-
const
|
|
3416
|
-
const
|
|
3417
|
+
const _parseInlineMarkdown = (syntax, keepSyntax = false)=>{
|
|
3418
|
+
const results = inlineMarkdown.evalT({
|
|
3419
|
+
indentation: 0,
|
|
3420
|
+
keepSyntax
|
|
3421
|
+
}).parse(syntax);
|
|
3422
|
+
if (!isNotEmpty(results)) throw new Error("Failed to parse");
|
|
3423
|
+
const [result, remaining] = results[0];
|
|
3424
|
+
if (remaining.length > 0) throw new Error(`Failed to parse the entire string. Remaining: "${remaining}"`);
|
|
3425
|
+
return result;
|
|
3426
|
+
};
|
|
3427
|
+
const parseInlineMarkdown = (syntax)=>_parseInlineMarkdown(syntax, false);
|
|
3428
|
+
const parseInlineMarkdownForSyntaxHighlighting = (syntax)=>_parseInlineMarkdown(syntax, true);
|
|
3417
3429
|
const isNullish = (value)=>null == value;
|
|
3418
3430
|
const isNotNullish = (value)=>!isNullish(value);
|
|
3419
3431
|
const sortObjectKeysByIndex = (obj, keys)=>Object.fromEntries([
|
|
@@ -3792,7 +3804,7 @@ const parseBlockMarkdown = (syntax)=>{
|
|
|
3792
3804
|
indentation: 0,
|
|
3793
3805
|
keepSyntax: false
|
|
3794
3806
|
}).parse(syntax);
|
|
3795
|
-
if (!
|
|
3807
|
+
if (!isNotEmpty(results)) throw new Error("Failed to parse");
|
|
3796
3808
|
const [result = [], remaining] = results[0];
|
|
3797
3809
|
if (remaining.length > 0) return [
|
|
3798
3810
|
...result,
|
|
@@ -3813,7 +3825,7 @@ const parseBlockMarkdownForSyntaxHighlighting = (syntax)=>{
|
|
|
3813
3825
|
indentation: 0,
|
|
3814
3826
|
keepSyntax: true
|
|
3815
3827
|
}).parse(syntax);
|
|
3816
|
-
if (!
|
|
3828
|
+
if (!isNotEmpty(results)) throw new Error("Failed to parse");
|
|
3817
3829
|
const [result, remaining] = results[0];
|
|
3818
3830
|
if (remaining.length > 0) return [
|
|
3819
3831
|
...result,
|
|
@@ -3986,7 +3998,7 @@ const BlockMarkdown = ({ node, outerHeadingLevel = 0, insertBefore, footnoteLabe
|
|
|
3986
3998
|
insertBefore,
|
|
3987
3999
|
/*#__PURE__*/ jsxRuntime_module_u("table", {
|
|
3988
4000
|
children: [
|
|
3989
|
-
void 0 !== node.caption &&
|
|
4001
|
+
void 0 !== node.caption && isNotEmpty(node.caption) && /*#__PURE__*/ jsxRuntime_module_u("caption", {
|
|
3990
4002
|
children: node.caption.length > 1 ? node.caption.map((captionLine, cli)=>/*#__PURE__*/ jsxRuntime_module_u("div", {
|
|
3991
4003
|
children: captionLine.map((inline, ci)=>/*#__PURE__*/ jsxRuntime_module_u(InlineMarkdown, {
|
|
3992
4004
|
node: inline
|
|
@@ -4123,19 +4135,20 @@ const TableRow = ({ columns, cells, cellType = "td" })=>{
|
|
|
4123
4135
|
])[0]
|
|
4124
4136
|
});
|
|
4125
4137
|
};
|
|
4126
|
-
const Markdown = ({ class: className, string, outerHeadingLevel, footnoteLabelSuffix })=>{
|
|
4127
|
-
const
|
|
4128
|
-
|
|
4129
|
-
|
|
4138
|
+
const Markdown = ({ class: className, string, outerHeadingLevel, footnoteLabelSuffix, inline })=>{
|
|
4139
|
+
const elements = inline ? parseInlineMarkdown(string).map((node, i)=>/*#__PURE__*/ jsxRuntime_module_u(InlineMarkdown, {
|
|
4140
|
+
node: node
|
|
4141
|
+
}, `md-inline-${i.toString()}`)) : parseBlockMarkdown(string).map((node, i)=>/*#__PURE__*/ jsxRuntime_module_u(BlockMarkdown, {
|
|
4142
|
+
node: node,
|
|
4130
4143
|
outerHeadingLevel: outerHeadingLevel,
|
|
4131
4144
|
footnoteLabelSuffix: footnoteLabelSuffix
|
|
4132
4145
|
}, `md-block-${i.toString()}`));
|
|
4133
4146
|
if (className) return /*#__PURE__*/ jsxRuntime_module_u("div", {
|
|
4134
4147
|
class: className,
|
|
4135
|
-
children:
|
|
4148
|
+
children: elements
|
|
4136
4149
|
});
|
|
4137
4150
|
return /*#__PURE__*/ jsxRuntime_module_u(preact_module_k, {
|
|
4138
|
-
children:
|
|
4151
|
+
children: elements
|
|
4139
4152
|
});
|
|
4140
4153
|
};
|
|
4141
4154
|
const homeTitle = "Entities";
|
|
@@ -4504,7 +4517,7 @@ const isSinglularInputFieldType = (getDeclFromDeclName, type)=>{
|
|
|
4504
4517
|
return secondaryDecl ? isSinglularInputFieldType(getDeclFromDeclName, secondaryDecl.type) : false;
|
|
4505
4518
|
}
|
|
4506
4519
|
case "StringType":
|
|
4507
|
-
return !(type.
|
|
4520
|
+
return !(type.markdown ?? false);
|
|
4508
4521
|
default:
|
|
4509
4522
|
return typeSafety_assertExhaustive(type);
|
|
4510
4523
|
}
|
|
@@ -5481,8 +5494,8 @@ const BlockMarkdownHighlighting = ({ node })=>{
|
|
|
5481
5494
|
return typeSafety_assertExhaustive(node.blockType);
|
|
5482
5495
|
}
|
|
5483
5496
|
};
|
|
5484
|
-
const MarkdownHighlighting = ({ class: className, string })=>{
|
|
5485
|
-
const blocks = parseBlockMarkdownForSyntaxHighlighting(string);
|
|
5497
|
+
const MarkdownHighlighting = ({ class: className, string, inline })=>{
|
|
5498
|
+
const blocks = inline ? parseInlineMarkdownForSyntaxHighlighting(string) : parseBlockMarkdownForSyntaxHighlighting(string);
|
|
5486
5499
|
const blockElements = blocks.map((block, i)=>/*#__PURE__*/ jsxRuntime_module_u(BlockMarkdownHighlighting, {
|
|
5487
5500
|
node: block
|
|
5488
5501
|
}, `md-block-${i.toString()}`));
|
|
@@ -5494,13 +5507,20 @@ const MarkdownHighlighting = ({ class: className, string })=>{
|
|
|
5494
5507
|
children: blockElements
|
|
5495
5508
|
});
|
|
5496
5509
|
};
|
|
5510
|
+
const TextInput = ({ type, ...props })=>"block" === type ? /*#__PURE__*/ jsxRuntime_module_u("textarea", {
|
|
5511
|
+
...props,
|
|
5512
|
+
rows: 1
|
|
5513
|
+
}) : /*#__PURE__*/ jsxRuntime_module_u("input", {
|
|
5514
|
+
type: "text"
|
|
5515
|
+
});
|
|
5497
5516
|
const StringTypeInput = ({ type, value, disabled, onChange, inTranslationObject })=>{
|
|
5498
5517
|
if ("string" != typeof value) return /*#__PURE__*/ jsxRuntime_module_u(MismatchingTypeError, {
|
|
5499
5518
|
expected: "string",
|
|
5500
5519
|
actual: value
|
|
5501
5520
|
});
|
|
5502
|
-
const { minLength, maxLength, pattern,
|
|
5521
|
+
const { minLength, maxLength, pattern, markdown } = type;
|
|
5503
5522
|
const errors = validateStringConstraints(type, value);
|
|
5523
|
+
const preparedPattern = void 0 === pattern ? void 0 : pattern.startsWith("^(?:") && pattern.endsWith(")$") ? pattern.slice(4, -2) : `.*${pattern}.*`;
|
|
5504
5524
|
return /*#__PURE__*/ jsxRuntime_module_u("div", {
|
|
5505
5525
|
class: "field field--string",
|
|
5506
5526
|
children: inTranslationObject ? /*#__PURE__*/ jsxRuntime_module_u(preact_module_k, {
|
|
@@ -5533,7 +5553,7 @@ const StringTypeInput = ({ type, value, disabled, onChange, inTranslationObject
|
|
|
5533
5553
|
})
|
|
5534
5554
|
]
|
|
5535
5555
|
})
|
|
5536
|
-
}) :
|
|
5556
|
+
}) : void 0 !== markdown ? /*#__PURE__*/ jsxRuntime_module_u(preact_module_k, {
|
|
5537
5557
|
children: [
|
|
5538
5558
|
/*#__PURE__*/ jsxRuntime_module_u("div", {
|
|
5539
5559
|
class: "editor editor--markdown",
|
|
@@ -5541,8 +5561,8 @@ const StringTypeInput = ({ type, value, disabled, onChange, inTranslationObject
|
|
|
5541
5561
|
/*#__PURE__*/ jsxRuntime_module_u("div", {
|
|
5542
5562
|
class: "textarea-grow-wrap",
|
|
5543
5563
|
children: [
|
|
5544
|
-
/*#__PURE__*/ jsxRuntime_module_u(
|
|
5545
|
-
|
|
5564
|
+
/*#__PURE__*/ jsxRuntime_module_u(TextInput, {
|
|
5565
|
+
type: markdown,
|
|
5546
5566
|
value: value,
|
|
5547
5567
|
minLength: minLength,
|
|
5548
5568
|
maxLength: maxLength,
|
|
@@ -5555,7 +5575,7 @@ const StringTypeInput = ({ type, value, disabled, onChange, inTranslationObject
|
|
|
5555
5575
|
/*#__PURE__*/ jsxRuntime_module_u("p", {
|
|
5556
5576
|
class: "help",
|
|
5557
5577
|
children: [
|
|
5558
|
-
"This
|
|
5578
|
+
"This text field supports",
|
|
5559
5579
|
" ",
|
|
5560
5580
|
/*#__PURE__*/ jsxRuntime_module_u("a", {
|
|
5561
5581
|
href: "https://www.markdownguide.org/getting-started/",
|
|
@@ -5568,7 +5588,8 @@ const StringTypeInput = ({ type, value, disabled, onChange, inTranslationObject
|
|
|
5568
5588
|
}),
|
|
5569
5589
|
/*#__PURE__*/ jsxRuntime_module_u(MarkdownHighlighting, {
|
|
5570
5590
|
class: "textarea-grow-wrap__mirror editor-highlighting",
|
|
5571
|
-
string: value + " "
|
|
5591
|
+
string: value + " ",
|
|
5592
|
+
inline: "inline" === markdown
|
|
5572
5593
|
})
|
|
5573
5594
|
]
|
|
5574
5595
|
}),
|
|
@@ -5582,7 +5603,8 @@ const StringTypeInput = ({ type, value, disabled, onChange, inTranslationObject
|
|
|
5582
5603
|
class: "preview",
|
|
5583
5604
|
children: /*#__PURE__*/ jsxRuntime_module_u(Markdown, {
|
|
5584
5605
|
string: value,
|
|
5585
|
-
outerHeadingLevel: 2
|
|
5606
|
+
outerHeadingLevel: 2,
|
|
5607
|
+
inline: "inline" === markdown
|
|
5586
5608
|
})
|
|
5587
5609
|
})
|
|
5588
5610
|
]
|
|
@@ -5594,7 +5616,7 @@ const StringTypeInput = ({ type, value, disabled, onChange, inTranslationObject
|
|
|
5594
5616
|
value: value,
|
|
5595
5617
|
minLength: minLength,
|
|
5596
5618
|
maxLength: maxLength,
|
|
5597
|
-
pattern:
|
|
5619
|
+
pattern: preparedPattern,
|
|
5598
5620
|
onInput: (event)=>{
|
|
5599
5621
|
onChange(event.currentTarget.value);
|
|
5600
5622
|
},
|