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.
@@ -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) => options.generateHelpers[key]
174
- ? `export type ${options.generateHelpers[key] === true ? defaultName : options.generateHelpers[key]} = {${EOL}${prefixLines(getIndentation(options.indentation, 1), declarations
175
- .filter(filterFn)
176
- .sort((a, b) => a.name.localeCompare(b.name))
177
- .map(renderKeyFn ??
178
- (decl => `${decl.name}: ${decl.name}${decl.parameters.length > 0 ? "<" + decl.parameters.map(param => (param.constraint ? renderType(options, param.constraint)[1] : "unknown")).join(", ") + ">" : ""}`))
179
- .join(EOL))}${EOL}}${EOL + EOL}`
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
- isMarkdown?: boolean;
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
- isMarkdown?: boolean;
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(Object.fromEntries(Object.entries(value).map(([key, item]) => [
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 isObjectType(type.type.value)
42
- ? typeof value === "object" && value !== null && !Array.isArray(value)
43
- ? sortObjectKeys(Object.fromEntries(Object.entries(value).map(([key, item]) => [
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
- isMarkdown?: boolean;
8
+ markdown?: MarkdownStringOption;
8
9
  }
9
10
  export declare const resolveTypeArgumentsInSerializedStringType: SerializedTypeArgumentsResolver<SerializedStringType>;
10
11
  export declare const getReferencesForSerializedStringType: GetReferencesSerialized<SerializedStringType>;
@@ -23,7 +23,7 @@ export const isSinglularInputFieldType = (getDeclFromDeclName, type) => {
23
23
  : false;
24
24
  }
25
25
  case "StringType":
26
- return !(type.isMarkdown ?? false);
26
+ return !(type.markdown ?? false);
27
27
  default:
28
28
  return assertExhaustive(type);
29
29
  }
@@ -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 isEmpty = (arr)=>0 === arr.length;
3416
- const nonEmpty_isNotEmpty = (arr)=>!isEmpty(arr);
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 (!nonEmpty_isNotEmpty(results)) throw new Error("Failed to parse");
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 (!nonEmpty_isNotEmpty(results)) throw new Error("Failed to parse");
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 && nonEmpty_isNotEmpty(node.caption) && /*#__PURE__*/ jsxRuntime_module_u("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 blocks = parseBlockMarkdown(string);
4128
- const blockElements = blocks.map((block, i)=>/*#__PURE__*/ jsxRuntime_module_u(BlockMarkdown, {
4129
- node: block,
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: blockElements
4148
+ children: elements
4136
4149
  });
4137
4150
  return /*#__PURE__*/ jsxRuntime_module_u(preact_module_k, {
4138
- children: blockElements
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.isMarkdown ?? false);
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, isMarkdown } = type;
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
- }) : isMarkdown ? /*#__PURE__*/ jsxRuntime_module_u(preact_module_k, {
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("textarea", {
5545
- rows: 1,
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 textarea supports",
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: void 0 === pattern ? void 0 : pattern.startsWith("^(?:") && pattern.endsWith(")$") ? pattern.slice(4, -2) : `.*${pattern}.*`,
5619
+ pattern: preparedPattern,
5598
5620
  onInput: (event)=>{
5599
5621
  onChange(event.currentTarget.value);
5600
5622
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsondb",
3
- "version": "0.19.17",
3
+ "version": "0.20.0",
4
4
  "description": "",
5
5
  "license": "ISC",
6
6
  "author": "Lukas Obermann",