tsondb 0.5.17 → 0.5.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.
@@ -1,9 +1,11 @@
1
+ import Debug from "debug";
1
2
  import { getNestedDeclarations, getParameterNames, walkNodeTree, } from "./declarations/Declaration.js";
2
3
  import { isEntityDecl } from "./declarations/EntityDecl.js";
3
4
  import { isStringType } from "./types/primitives/StringType.js";
4
5
  import { isIncludeIdentifierType } from "./types/references/IncludeIdentifierType.js";
5
6
  import { isNestedEntityMapType } from "./types/references/NestedEntityMapType.js";
6
7
  import { findTypeAtPath } from "./types/Type.js";
8
+ const debug = Debug("tsondb:schema");
7
9
  const checkDuplicateIdentifier = (existingDecls, decl) => {
8
10
  const existingDeclWithSameName = existingDecls
9
11
  .values()
@@ -66,9 +68,14 @@ const addDeclarations = (existingDecls, declsToAdd, nested) => declsToAdd.reduce
66
68
  return accDecls;
67
69
  }, existingDecls);
68
70
  export const Schema = (declarations, localeEntity) => {
71
+ debug("creating schema from %d declarations", declarations.length);
72
+ debug("collecting nested declarations ...");
69
73
  const allDecls = addDeclarations([], localeEntity ? declarations.concat(localeEntity) : declarations, true);
74
+ debug("checking name shadowing ...");
70
75
  checkParameterNamesShadowing(allDecls);
76
+ debug("checking entity display name paths ...");
71
77
  checkEntityDisplayNamePaths(allDecls, localeEntity);
78
+ debug("created schema, no integrity violations found");
72
79
  return {
73
80
  declarations: allDecls,
74
81
  localeEntity,
@@ -8,6 +8,10 @@ export type InlineMarkdownNode = {
8
8
  } | {
9
9
  kind: "code";
10
10
  content: string;
11
+ } | {
12
+ kind: "link";
13
+ href: string;
14
+ content: InlineMarkdownNode[];
11
15
  } | TextNode;
12
16
  export type BlockMarkdownNode = {
13
17
  kind: "paragraph";
@@ -19,10 +23,17 @@ export type BlockMarkdownNode = {
19
23
  kind: "listitem";
20
24
  content: InlineMarkdownNode[];
21
25
  }[];
26
+ } | {
27
+ kind: "table";
28
+ header: InlineMarkdownNode[][];
29
+ rows: InlineMarkdownNode[][][];
22
30
  };
23
31
  export type BlockSyntaxMarkdownNode = InlineMarkdownNode | {
24
32
  kind: "listitemmarker";
25
33
  content: string;
34
+ } | {
35
+ kind: "tablemarker";
36
+ content: string;
26
37
  };
27
38
  export declare const parseBlockMarkdown: (text: string) => BlockMarkdownNode[];
28
39
  export declare const parseBlockMarkdownForSyntaxHighlighting: (text: string) => BlockSyntaxMarkdownNode[];
@@ -1,77 +1,101 @@
1
1
  const codeRule = {
2
2
  pattern: /`(.*?)`/,
3
- map: (result, _parseInside, forSyntaxHighlighting) => ({
3
+ map: result => ({
4
+ kind: "code",
5
+ content: result[1] ?? "",
6
+ }),
7
+ mapHighlighting: result => ({
4
8
  kind: "code",
5
- content: forSyntaxHighlighting ? `\`${result[1] ?? ""}\`` : (result[1] ?? ""),
9
+ content: `\`${result[1] ?? ""}\``,
6
10
  }),
7
11
  };
8
12
  const boldWithItalicRule = {
9
- pattern: /\*\*(.*?\*.+?\*.*?)\*\*/,
10
- map: (result, parseInside, forSyntaxHighlighting) => ({
13
+ pattern: /(?<!\\)\*\*((.*?[^\\*])?\*(?!\*).*?[^\\*]\*.*?)(?<!\\)\*\*/,
14
+ map: (result, parseInside) => ({
15
+ kind: "bold",
16
+ content: parseInside(result[1] ?? ""),
17
+ }),
18
+ mapHighlighting: (result, parseInside) => ({
11
19
  kind: "bold",
12
- content: forSyntaxHighlighting
13
- ? [
14
- { kind: "text", content: "**" },
15
- ...parseInside(result[1] ?? ""),
16
- { kind: "text", content: "**" },
17
- ]
18
- : parseInside(result[1] ?? ""),
20
+ content: [textNode("**"), ...parseInside(result[1] ?? ""), textNode("**")],
19
21
  }),
20
22
  };
21
23
  const italicWithBoldRule = {
22
- pattern: /\*(.*?\*\*.+?\*\*.*?)\*/,
23
- map: (result, parseInside, forSyntaxHighlighting) => ({
24
+ pattern: /(?<![\\*])\*(?=\*\*|[^*])(.*?\*\*.*?\*\*.*?)(?<=[^\\*]|[^\\]\*\*)\*(?!\*)/,
25
+ map: (result, parseInside) => ({
24
26
  kind: "italic",
25
- content: forSyntaxHighlighting
26
- ? [
27
- { kind: "text", content: "*" },
28
- ...parseInside(result[1] ?? ""),
29
- { kind: "text", content: "*" },
30
- ]
31
- : parseInside(result[1] ?? ""),
27
+ content: parseInside(result[1] ?? ""),
28
+ }),
29
+ mapHighlighting: (result, parseInside) => ({
30
+ kind: "italic",
31
+ content: [textNode("*"), ...parseInside(result[1] ?? ""), textNode("*")],
32
32
  }),
33
33
  };
34
34
  const boldRule = {
35
- pattern: /\*\*(.+?)\*\*/,
36
- map: (result, parseInside, forSyntaxHighlighting) => ({
35
+ pattern: /(?<!\\)\*\*(.*?[^\\*])\*\*/,
36
+ map: (result, parseInside) => ({
37
+ kind: "bold",
38
+ content: parseInside(result[1] ?? ""),
39
+ }),
40
+ mapHighlighting: (result, parseInside) => ({
37
41
  kind: "bold",
38
- content: forSyntaxHighlighting
39
- ? [
40
- { kind: "text", content: "**" },
41
- ...parseInside(result[1] ?? ""),
42
- { kind: "text", content: "**" },
43
- ]
44
- : parseInside(result[1] ?? ""),
42
+ content: [textNode("**"), ...parseInside(result[1] ?? ""), textNode("**")],
45
43
  }),
46
44
  };
47
45
  const italicRule = {
48
- pattern: /\*(.+?)\*/,
49
- map: (result, parseInside, forSyntaxHighlighting) => ({
46
+ pattern: /(?<!\\)\*(.*?[^\\*])\*/,
47
+ map: (result, parseInside) => ({
50
48
  kind: "italic",
51
- content: forSyntaxHighlighting
52
- ? [
53
- { kind: "text", content: "*" },
54
- ...parseInside(result[1] ?? ""),
55
- { kind: "text", content: "*" },
56
- ]
57
- : parseInside(result[1] ?? ""),
49
+ content: parseInside(result[1] ?? ""),
50
+ }),
51
+ mapHighlighting: (result, parseInside) => ({
52
+ kind: "italic",
53
+ content: [textNode("*"), ...parseInside(result[1] ?? ""), textNode("*")],
54
+ }),
55
+ };
56
+ const linkRule = {
57
+ pattern: /(?<!\\)\[(.*?[^\\])\]\((.*?[^\\])\)/,
58
+ map: (result, parseInside) => ({
59
+ kind: "link",
60
+ href: result[2] ?? "",
61
+ content: parseInside(result[1] ?? ""),
62
+ }),
63
+ mapHighlighting: (result, parseInside) => ({
64
+ kind: "link",
65
+ href: result[2] ?? "",
66
+ content: [textNode("["), ...parseInside(result[1] ?? ""), textNode(`](${result[2] ?? ""})`)],
67
+ }),
68
+ };
69
+ const textNode = (content) => ({
70
+ kind: "text",
71
+ content: content,
72
+ });
73
+ const parseEscapedCharacters = (text) => text.replace(/\\([*_`[\]()\\])/g, "$1");
74
+ const textRule = {
75
+ pattern: /.+/,
76
+ map: result => ({
77
+ kind: "text",
78
+ content: parseEscapedCharacters(result[0]),
79
+ }),
80
+ mapHighlighting: result => ({
81
+ kind: "text",
82
+ content: result[0],
58
83
  }),
59
84
  };
60
85
  const inlineRules = [
61
86
  codeRule,
87
+ linkRule,
62
88
  boldWithItalicRule,
63
89
  italicWithBoldRule,
64
90
  boldRule,
65
91
  italicRule,
92
+ textRule,
66
93
  ];
67
94
  const parseForInlineRules = (rules, text, forSyntaxHighlighting) => {
68
- if (text.length === 0) {
95
+ if (text.length === 0 || rules[0] === undefined) {
69
96
  return [];
70
97
  }
71
98
  const activeRule = rules[0];
72
- if (activeRule === undefined) {
73
- return [{ kind: "text", content: text }];
74
- }
75
99
  const res = activeRule.pattern.exec(text);
76
100
  if (res && (activeRule.predicate?.(res) ?? true)) {
77
101
  const { index } = res;
@@ -81,7 +105,7 @@ const parseForInlineRules = (rules, text, forSyntaxHighlighting) => {
81
105
  ...(before.length > 0
82
106
  ? parseForInlineRules(rules.slice(1), before, forSyntaxHighlighting)
83
107
  : []),
84
- activeRule.map(res, text => parseForInlineRules(rules.slice(1), text, forSyntaxHighlighting), forSyntaxHighlighting),
108
+ (forSyntaxHighlighting ? activeRule.mapHighlighting : activeRule.map)(res, text => parseForInlineRules(rules.slice(1), text, forSyntaxHighlighting)),
85
109
  ...(after.length > 0 ? parseForInlineRules(rules, after, forSyntaxHighlighting) : []),
86
110
  ];
87
111
  }
@@ -107,9 +131,9 @@ const listRule = {
107
131
  content: /^(\d+\. |[-*] )/.exec(item)?.[1] ?? "",
108
132
  },
109
133
  ...parseInlineMarkdown(item.replace(/^\d+\. |[-*] /, ""), true),
110
- ...(index < array.length - 1 ? [{ kind: "text", content: "\n" }] : []),
134
+ ...(index < array.length - 1 ? [textNode("\n")] : []),
111
135
  ]),
112
- { kind: "text", content: result[2] ?? "" },
136
+ textNode(result[2] ?? ""),
113
137
  ],
114
138
  };
115
139
  const paragraphRule = {
@@ -120,48 +144,70 @@ const paragraphRule = {
120
144
  }),
121
145
  mapHighlighting: result => [
122
146
  ...parseInlineMarkdown(result[1] ?? "", true),
123
- { kind: "text", content: result[2] ?? "" },
147
+ textNode(result[2] ?? ""),
124
148
  ],
125
149
  };
126
- const blockRules = [listRule, paragraphRule];
127
- const parseForBlockRules = (rules, text, remainingRules = rules) => {
128
- if (text.length === 0) {
129
- return [];
130
- }
131
- const activeRule = remainingRules[0];
132
- if (activeRule === undefined) {
133
- return [{ kind: "paragraph", content: [{ kind: "text", content: text }] }];
134
- }
135
- const res = activeRule.pattern.exec(text);
136
- if (res && (activeRule.predicate?.(res) ?? true)) {
137
- const { index } = res;
138
- const after = text.slice(index + res[0].length);
139
- return [activeRule.map(res), ...(after.length > 0 ? parseForBlockRules(rules, after) : [])];
140
- }
141
- else {
142
- return parseForBlockRules(rules, text, remainingRules.slice(1));
143
- }
150
+ const removeSurroundingPipes = (text) => text.replace(/^\|/, "").replace(/\|$/, "");
151
+ const tableMarker = (text) => ({
152
+ kind: "tablemarker",
153
+ content: text,
154
+ });
155
+ const tableRule = {
156
+ pattern: /^(\| *)?(.+?(?: *(?<!\\)\| *.+?)+)( *\|)?\n((?:\| *)?(?:-{3,}|:-{2,}|-{2,}:|:-+:)(?: *\| *(?:-{3,}|:-{2,}|-{2,}:|:-+:))*(?: *\|)?)((?:\n\|? *.+?(?: *(?<!\\)\| *.+?)* *(?<!\\)\|?)+)(\n{2,}|$)/,
157
+ map: result => ({
158
+ kind: "table",
159
+ header: result[2]?.split("|").map(th => parseInlineMarkdown(th.trim(), false)) ?? [],
160
+ rows: result[5]
161
+ ?.split("\n")
162
+ .slice(1)
163
+ .map(tr => removeSurroundingPipes(tr)
164
+ .split("|")
165
+ .map(tc => parseInlineMarkdown(tc.trim(), false))) ?? [],
166
+ }),
167
+ mapHighlighting: result => [
168
+ tableMarker(result[1] ?? ""),
169
+ ...(result[2]
170
+ ?.split("|")
171
+ .flatMap((th, i) => i === 0
172
+ ? parseInlineMarkdown(th, true)
173
+ : [tableMarker("|"), ...parseInlineMarkdown(th, true)]) ?? []),
174
+ tableMarker((result[3] ?? "") + "\n" + (result[4] ?? "")),
175
+ ...(result[5]
176
+ ?.split("\n")
177
+ .slice(1)
178
+ .flatMap((tr) => [
179
+ textNode("\n"),
180
+ ...tr
181
+ .split("|")
182
+ .flatMap((tc, i) => i === 0
183
+ ? parseInlineMarkdown(tc, true)
184
+ : [tableMarker("|"), ...parseInlineMarkdown(tc, true)]),
185
+ ]) ?? []),
186
+ textNode(result[6] ?? ""),
187
+ ],
144
188
  };
145
- const parseForBlockRulesSyntaxHighlighting = (rules, text, remainingRules = rules) => {
146
- if (text.length === 0) {
189
+ const blockRules = [tableRule, listRule, paragraphRule];
190
+ const parseActiveBlockRule = (rule, res) => [
191
+ rule.map(res),
192
+ ];
193
+ const parseActiveBlockSyntaxRule = (rule, res) => rule.mapHighlighting(res);
194
+ const parseForBlockRules = (rules, text, ruleParser, remainingRules = rules) => {
195
+ if (text.length === 0 || remainingRules[0] === undefined) {
147
196
  return [];
148
197
  }
149
198
  const activeRule = remainingRules[0];
150
- if (activeRule === undefined) {
151
- return [{ kind: "text", content: text }];
152
- }
153
199
  const res = activeRule.pattern.exec(text);
154
200
  if (res && (activeRule.predicate?.(res) ?? true)) {
155
201
  const { index } = res;
156
202
  const after = text.slice(index + res[0].length);
157
203
  return [
158
- ...activeRule.mapHighlighting(res),
159
- ...(after.length > 0 ? parseForBlockRulesSyntaxHighlighting(rules, after) : []),
204
+ ...ruleParser(activeRule, res),
205
+ ...(after.length > 0 ? parseForBlockRules(rules, after, ruleParser) : []),
160
206
  ];
161
207
  }
162
208
  else {
163
- return parseForBlockRulesSyntaxHighlighting(rules, text, remainingRules.slice(1));
209
+ return parseForBlockRules(rules, text, ruleParser, remainingRules.slice(1));
164
210
  }
165
211
  };
166
- export const parseBlockMarkdown = (text) => parseForBlockRules(blockRules, text);
167
- export const parseBlockMarkdownForSyntaxHighlighting = (text) => parseForBlockRulesSyntaxHighlighting(blockRules, text);
212
+ export const parseBlockMarkdown = (text) => parseForBlockRules(blockRules, text, parseActiveBlockRule);
213
+ export const parseBlockMarkdownForSyntaxHighlighting = (text) => parseForBlockRules(blockRules, text, parseActiveBlockSyntaxRule);
@@ -1,4 +1,4 @@
1
- import { jsx as _jsx } from "preact/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
2
2
  import { InlineMarkdown } from "./InlineMarkdown.js";
3
3
  export const BlockMarkdown = ({ node }) => {
4
4
  switch (node.kind) {
@@ -11,6 +11,8 @@ export const BlockMarkdown = ({ node }) => {
11
11
  else {
12
12
  return (_jsx("ul", { children: node.content.map((item, ii) => (_jsx("li", { children: item.content.map((inline, iii) => (_jsx(InlineMarkdown, { node: inline }, iii))) }, ii))) }));
13
13
  }
14
+ case "table":
15
+ return (_jsxs("table", { children: [_jsx("thead", { children: _jsx("tr", { children: node.header.map((th, hi) => (_jsx("th", { children: th.map((inline, hii) => (_jsx(InlineMarkdown, { node: inline }, hii))) }, hi))) }) }), _jsx("tbody", { children: node.rows.map((tr, ri) => (_jsx("tr", { children: tr.map((tc, ci) => (_jsx("td", { children: tc.map((inline, cii) => (_jsx(InlineMarkdown, { node: inline }, cii))) }, ci))) }, ri))) })] }));
14
16
  default:
15
17
  return null;
16
18
  }
@@ -4,6 +4,8 @@ export const BlockMarkdownHighlighting = ({ node }) => {
4
4
  switch (node.kind) {
5
5
  case "listitemmarker":
6
6
  return _jsx("span", { class: "list-item-marker", children: node.content });
7
+ case "tablemarker":
8
+ return _jsx("span", { class: "table-marker", children: node.content });
7
9
  default:
8
10
  return _jsx(InlineMarkdown, { node: node });
9
11
  }
@@ -7,6 +7,8 @@ export const InlineMarkdown = ({ node }) => {
7
7
  return (_jsx("strong", { children: node.content.map((inline, i) => (_jsx(InlineMarkdown, { node: inline }, i))) }));
8
8
  case "italic":
9
9
  return (_jsx("em", { children: node.content.map((inline, i) => (_jsx(InlineMarkdown, { node: inline }, i))) }));
10
+ case "link":
11
+ return (_jsx("a", { href: node.href, children: node.content.map((inline, i) => (_jsx(InlineMarkdown, { node: inline }, i))) }));
10
12
  case "text":
11
13
  return node.content;
12
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsondb",
3
- "version": "0.5.17",
3
+ "version": "0.5.19",
4
4
  "description": "",
5
5
  "license": "ISC",
6
6
  "author": "Lukas Obermann",
@@ -23,7 +23,7 @@
23
23
  "scripts": {
24
24
  "build": "tsc -b",
25
25
  "watch": "tsc -b -w",
26
- "test": "node --test",
26
+ "test": "node --import tsx --test",
27
27
  "lint": "eslint",
28
28
  "format": "prettier \"{src,test}/**/*.{ts,tsx}\" --write",
29
29
  "format:check": "prettier \"{src,test}/**/*.{ts,tsx}\" --check",
@@ -41,6 +41,7 @@
41
41
  "eslint-plugin-react-hooks": "^5.2.0",
42
42
  "globals": "^16.3.0",
43
43
  "prettier": "^3.6.2",
44
+ "tsx": "^4.20.5",
44
45
  "typescript": "^5.9.2",
45
46
  "typescript-eslint": "^8.43.0"
46
47
  },
@@ -51,6 +51,7 @@
51
51
  --highlight-color-bold: rgb(205, 123, 43);
52
52
  --highlight-color-italic: rgb(41, 155, 96);
53
53
  --highlight-color-list-item-marker: rgb(195, 58, 237);
54
+ --highlight-color-table-marker: rgb(237, 58, 118);
54
55
  }
55
56
 
56
57
  @media (prefers-color-scheme: dark) {
@@ -82,6 +83,7 @@
82
83
  --highlight-color-bold: rgb(236, 170, 105);
83
84
  --highlight-color-italic: rgb(130, 230, 178);
84
85
  --highlight-color-list-item-marker: rgb(220, 133, 245);
86
+ --highlight-color-table-marker: rgb(244, 135, 171);
85
87
  }
86
88
  }
87
89
 
@@ -584,6 +586,10 @@ form > .field--container {
584
586
  color: var(--highlight-color-list-item-marker);
585
587
  }
586
588
 
589
+ .editor-highlighting .table-marker {
590
+ color: var(--highlight-color-table-marker);
591
+ }
592
+
587
593
  .help {
588
594
  font-size: 0.8rem;
589
595
  color: var(--secondary-color);
@@ -608,6 +614,28 @@ form > .field--container {
608
614
  margin-bottom: 0;
609
615
  }
610
616
 
617
+ .field--string .preview table {
618
+ border-collapse: collapse;
619
+ margin: 0.5rem 0;
620
+ }
621
+
622
+ .field--string .preview table :is(th, td) {
623
+ vertical-align: top;
624
+ padding: 0.25rem 0.5rem;
625
+ }
626
+
627
+ .field--string .preview table :is(th, td):first-child {
628
+ padding-left: 0;
629
+ }
630
+
631
+ .field--string .preview table :is(th, td):last-child {
632
+ padding-right: 0;
633
+ }
634
+
635
+ .field--string .preview table tbody tr {
636
+ border-top: 1px solid var(--tertiary-color);
637
+ }
638
+
611
639
  .container-item {
612
640
  container-type: inline-size;
613
641
  }