obsidian-dev-utils 16.3.0 → 16.4.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/CHANGELOG.md +7 -0
- package/README.md +21 -2
- package/dist/bin/cli.cjs +1 -1
- package/dist/dprint.json +22 -0
- package/dist/lib/@types/debug.d.ts +1 -1
- package/dist/lib/Async.cjs +10 -5
- package/dist/lib/Debug.cjs +4 -2
- package/dist/lib/Library.cjs +1 -1
- package/dist/lib/Object.cjs +1 -1
- package/dist/lib/Object.d.ts +1 -1
- package/dist/lib/Path.cjs +1 -1
- package/dist/lib/Path.d.ts +5 -5
- package/dist/lib/obsidian/@types/Dataview/api/data-array.d.ts +116 -114
- package/dist/lib/obsidian/@types/Dataview/api/extensions.d.ts +8 -8
- package/dist/lib/obsidian/@types/Dataview/api/inline-api.d.ts +172 -151
- package/dist/lib/obsidian/@types/Dataview/api/plugin-api.d.ts +183 -166
- package/dist/lib/obsidian/@types/Dataview/api/result.d.ts +28 -28
- package/dist/lib/obsidian/@types/Dataview/data-import/csv.d.ts +1 -1
- package/dist/lib/obsidian/@types/Dataview/data-import/inline-field.d.ts +15 -15
- package/dist/lib/obsidian/@types/Dataview/data-import/markdown-file.d.ts +23 -7
- package/dist/lib/obsidian/@types/Dataview/data-import/persister.d.ts +25 -25
- package/dist/lib/obsidian/@types/Dataview/data-import/web-worker/import-impl.d.ts +5 -2
- package/dist/lib/obsidian/@types/Dataview/data-import/web-worker/import-manager.d.ts +30 -25
- package/dist/lib/obsidian/@types/Dataview/data-index/index.d.ts +156 -149
- package/dist/lib/obsidian/@types/Dataview/data-index/resolver.d.ts +9 -6
- package/dist/lib/obsidian/@types/Dataview/data-index/source.d.ts +43 -43
- package/dist/lib/obsidian/@types/Dataview/data-model/markdown.d.ts +105 -99
- package/dist/lib/obsidian/@types/Dataview/data-model/serialized/markdown.d.ts +92 -89
- package/dist/lib/obsidian/@types/Dataview/data-model/transferable.d.ts +4 -4
- package/dist/lib/obsidian/@types/Dataview/data-model/value.d.ts +139 -112
- package/dist/lib/obsidian/@types/Dataview/expression/binaryop.d.ts +31 -17
- package/dist/lib/obsidian/@types/Dataview/expression/context.d.ts +39 -33
- package/dist/lib/obsidian/@types/Dataview/expression/field.d.ts +46 -46
- package/dist/lib/obsidian/@types/Dataview/expression/functions.d.ts +120 -108
- package/dist/lib/obsidian/@types/Dataview/expression/parse.d.ts +135 -115
- package/dist/lib/obsidian/@types/Dataview/index.d.ts +48 -14
- package/dist/lib/obsidian/@types/Dataview/main.d.ts +50 -42
- package/dist/lib/obsidian/@types/Dataview/query/engine.d.ts +60 -44
- package/dist/lib/obsidian/@types/Dataview/query/parse.d.ts +31 -18
- package/dist/lib/obsidian/@types/Dataview/query/query.d.ts +45 -45
- package/dist/lib/obsidian/@types/Dataview/settings.d.ts +50 -50
- package/dist/lib/obsidian/@types/Dataview/typings/obsidian-ex.d.ts +16 -16
- package/dist/lib/obsidian/@types/Dataview/typings/workers.d.ts +3 -3
- package/dist/lib/obsidian/@types/Dataview/ui/export/markdown.d.ts +9 -3
- package/dist/lib/obsidian/@types/Dataview/ui/lp-render.d.ts +34 -21
- package/dist/lib/obsidian/@types/Dataview/ui/markdown.d.ts +49 -36
- package/dist/lib/obsidian/@types/Dataview/ui/refreshable-view.d.ts +15 -12
- package/dist/lib/obsidian/@types/Dataview/ui/render.d.ts +27 -6
- package/dist/lib/obsidian/@types/Dataview/ui/views/calendar-view.d.ts +15 -15
- package/dist/lib/obsidian/@types/Dataview/ui/views/inline-field-live-preview.d.ts +30 -17
- package/dist/lib/obsidian/@types/Dataview/ui/views/inline-view.d.ts +25 -16
- package/dist/lib/obsidian/@types/Dataview/ui/views/js-view.d.ts +18 -18
- package/dist/lib/obsidian/@types/Dataview/ui/views/list-view.d.ts +14 -14
- package/dist/lib/obsidian/@types/Dataview/ui/views/table-view.d.ts +17 -17
- package/dist/lib/obsidian/@types/Dataview/ui/views/task-view.d.ts +26 -14
- package/dist/lib/obsidian/@types/Dataview/util/media.d.ts +1 -1
- package/dist/lib/obsidian/@types/Dataview/util/normalize.d.ts +6 -3
- package/dist/lib/obsidian/App.cjs +1 -1
- package/dist/lib/obsidian/AttachmentPath.cjs +1 -1
- package/dist/lib/obsidian/Dataview.cjs +26 -17
- package/dist/lib/obsidian/FileChange.cjs +1 -1
- package/dist/lib/obsidian/FileChange.d.ts +4 -4
- package/dist/lib/obsidian/FileManager.cjs +2 -2
- package/dist/lib/obsidian/Link.cjs +1 -1
- package/dist/lib/obsidian/Link.d.ts +4 -4
- package/dist/lib/obsidian/Markdown.cjs +17 -1
- package/dist/lib/obsidian/Markdown.d.ts +11 -1
- package/dist/lib/obsidian/MarkdownCodeBlockProcessor.cjs +1 -1
- package/dist/lib/obsidian/MetadataCache.cjs +7 -3
- package/dist/lib/obsidian/Plugin/PluginSettingsTabBase.cjs +1 -1
- package/dist/lib/obsidian/Reference.cjs +1 -1
- package/dist/lib/obsidian/Reference.d.ts +6 -6
- package/dist/lib/obsidian/RenameDeleteHandler.cjs +7 -3
- package/dist/lib/obsidian/RenameDeleteHandler.d.ts +2 -2
- package/dist/lib/obsidian/Vault.cjs +1 -1
- package/dist/lib/obsidian/VaultEx.cjs +1 -1
- package/dist/lib/scripts/ESLint/ESLint.cjs +4 -2
- package/dist/lib/scripts/ESLint/eslint.config.cjs +5 -2
- package/dist/lib/scripts/Fs.cjs +1 -1
- package/dist/lib/scripts/JSON.cjs +1 -1
- package/dist/lib/scripts/Npm.cjs +1 -1
- package/dist/lib/scripts/ObsidianDevUtilsRepoPaths.cjs +2 -1
- package/dist/lib/scripts/ObsidianDevUtilsRepoPaths.d.ts +2 -0
- package/dist/lib/scripts/cli.cjs +23 -18
- package/dist/lib/scripts/esbuild/ObsidianPluginBuilder.cjs +5 -3
- package/dist/lib/scripts/esbuild/fixSourceMapsPlugin.cjs +1 -1
- package/dist/lib/scripts/esbuild/preprocessPlugin.cjs +1 -1
- package/dist/lib/scripts/format.cjs +56 -0
- package/dist/lib/scripts/format.d.ts +10 -0
- package/dist/lib/scripts/index.cjs +4 -1
- package/dist/lib/scripts/index.d.ts +1 -0
- package/dist/lib/scripts/version.cjs +18 -6
- package/package.json +13 -10
- package/dist/obsidian-dev-utils-16.3.0.tgz +0 -0
@@ -1,109 +1,136 @@
|
|
1
|
-
import type {
|
2
|
-
|
1
|
+
import type {
|
2
|
+
DateTime,
|
3
|
+
Duration
|
4
|
+
} from 'luxon';
|
5
|
+
import type { QuerySettings } from '../settings.d.ts';
|
3
6
|
/** Shorthand for a mapping from keys to values. */
|
4
7
|
export type DataObject = {
|
5
|
-
|
8
|
+
[key: string]: Literal;
|
6
9
|
};
|
7
10
|
/** The literal types supported by the query engine. */
|
8
|
-
export type LiteralType =
|
11
|
+
export type LiteralType = 'boolean' | 'number' | 'string' | 'date' | 'duration' | 'link' | 'array' | 'object' | 'function' | 'null' | 'html' | 'widget';
|
9
12
|
/** The raw values that a literal can take on. */
|
10
13
|
export type Literal = boolean | number | string | DateTime | Duration | Link | Array<Literal> | DataObject | Function | null | HTMLElement | Widget;
|
11
14
|
/** A grouping on a type which supports recursively-nested groups. */
|
12
15
|
export type GroupElement<T> = {
|
13
|
-
|
14
|
-
|
16
|
+
key: Literal;
|
17
|
+
rows: Grouping<T>;
|
15
18
|
};
|
16
19
|
export type Grouping<T> = T[] | GroupElement<T>[];
|
17
20
|
/** Maps the string type to it's external, API-facing representation. */
|
18
|
-
export type LiteralRepr<T extends LiteralType> = T extends
|
21
|
+
export type LiteralRepr<T extends LiteralType> = T extends 'boolean' ? boolean
|
22
|
+
: T extends 'number' ? number
|
23
|
+
: T extends 'string' ? string
|
24
|
+
: T extends 'duration' ? Duration
|
25
|
+
: T extends 'date' ? DateTime
|
26
|
+
: T extends 'null' ? null
|
27
|
+
: T extends 'link' ? Link
|
28
|
+
: T extends 'array' ? Array<Literal>
|
29
|
+
: T extends 'object' ? Record<string, Literal>
|
30
|
+
: T extends 'function' ? Function
|
31
|
+
: T extends 'html' ? HTMLElement
|
32
|
+
: T extends 'widget' ? Widget
|
33
|
+
: any;
|
19
34
|
/** A wrapped literal value which can be switched on. */
|
20
|
-
export type WrappedLiteral =
|
35
|
+
export type WrappedLiteral =
|
36
|
+
| LiteralWrapper<'string'>
|
37
|
+
| LiteralWrapper<'number'>
|
38
|
+
| LiteralWrapper<'boolean'>
|
39
|
+
| LiteralWrapper<'date'>
|
40
|
+
| LiteralWrapper<'duration'>
|
41
|
+
| LiteralWrapper<'link'>
|
42
|
+
| LiteralWrapper<'array'>
|
43
|
+
| LiteralWrapper<'object'>
|
44
|
+
| LiteralWrapper<'html'>
|
45
|
+
| LiteralWrapper<'widget'>
|
46
|
+
| LiteralWrapper<'function'>
|
47
|
+
| LiteralWrapper<'null'>;
|
21
48
|
export interface LiteralWrapper<T extends LiteralType> {
|
22
|
-
|
23
|
-
|
49
|
+
type: T;
|
50
|
+
value: LiteralRepr<T>;
|
24
51
|
}
|
25
52
|
export declare namespace Values {
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
+
/** Convert an arbitrary value into a reasonable, Markdown-friendly string if possible. */
|
54
|
+
function toString(field: any, setting?: QuerySettings, recursive?: boolean): string;
|
55
|
+
/** Wrap a literal value so you can switch on it easily. */
|
56
|
+
function wrapValue(val: Literal): WrappedLiteral | undefined;
|
57
|
+
/** Recursively map complex objects at the leaves. */
|
58
|
+
function mapLeaves(val: Literal, func: (t: Literal) => Literal): Literal;
|
59
|
+
/** Compare two arbitrary JavaScript values. Produces a total ordering over ANY possible dataview value. */
|
60
|
+
function compareValue(val1: Literal, val2: Literal, linkNormalizer?: (link: string) => string): number;
|
61
|
+
/** Find the corresponding Dataview type for an arbitrary value. */
|
62
|
+
function typeOf(val: any): LiteralType | undefined;
|
63
|
+
/** Determine if the given value is "truthy" (i.e., is non-null and has data in it). */
|
64
|
+
function isTruthy(field: Literal): boolean;
|
65
|
+
/** Deep copy a field. */
|
66
|
+
function deepCopy<T extends Literal>(field: T): T;
|
67
|
+
function isString(val: any): val is string;
|
68
|
+
function isNumber(val: any): val is number;
|
69
|
+
function isDate(val: any): val is DateTime;
|
70
|
+
function isDuration(val: any): val is Duration;
|
71
|
+
function isNull(val: any): val is null | undefined;
|
72
|
+
function isArray(val: any): val is any[];
|
73
|
+
function isBoolean(val: any): val is boolean;
|
74
|
+
function isLink(val: any): val is Link;
|
75
|
+
function isWidget(val: any): val is Widget;
|
76
|
+
function isHtml(val: any): val is HTMLElement;
|
77
|
+
/** Checks if the given value is an object (and not any other dataview-recognized object-like type). */
|
78
|
+
function isObject(val: any): val is Record<string, any>;
|
79
|
+
function isFunction(val: any): val is Function;
|
53
80
|
}
|
54
81
|
export declare namespace Groupings {
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
82
|
+
/** Determines if the given group entry is a standalone value, or a grouping of sub-entries. */
|
83
|
+
function isElementGroup<T>(entry: T | GroupElement<T>): entry is GroupElement<T>;
|
84
|
+
/** Determines if the given array is a grouping array. */
|
85
|
+
function isGrouping<T>(entry: Grouping<T>): entry is GroupElement<T>[];
|
86
|
+
/** Count the total number of elements in a recursive grouping. */
|
87
|
+
function count<T>(elements: Grouping<T>): number;
|
61
88
|
}
|
62
89
|
/** The Obsidian 'link', used for uniquely describing a file, header, or block. */
|
63
90
|
export declare class Link {
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
91
|
+
/** The file path this link points to. */
|
92
|
+
path: string;
|
93
|
+
/** The display name associated with the link. */
|
94
|
+
display?: string;
|
95
|
+
/** The block ID or header this link points to within a file, if relevant. */
|
96
|
+
subpath?: string;
|
97
|
+
/** Is this link an embedded link (!)? */
|
98
|
+
embed: boolean;
|
99
|
+
/** The type of this link, which determines what 'subpath' refers to, if anything. */
|
100
|
+
type: 'file' | 'header' | 'block';
|
101
|
+
/** Create a link to a specific file. */
|
102
|
+
static file(path: string, embed?: boolean, display?: string): Link;
|
103
|
+
static infer(linkpath: string, embed?: boolean, display?: string): Link;
|
104
|
+
/** Create a link to a specific file and header in that file. */
|
105
|
+
static header(path: string, header: string, embed?: boolean, display?: string): Link;
|
106
|
+
/** Create a link to a specific file and block in that file. */
|
107
|
+
static block(path: string, blockId: string, embed?: boolean, display?: string): Link;
|
108
|
+
static fromObject(object: Record<string, any>): Link;
|
109
|
+
private constructor();
|
110
|
+
/** Checks for link equality (i.e., that the links are pointing to the same exact location). */
|
111
|
+
equals(other: Link): boolean;
|
112
|
+
/** Convert this link to it's markdown representation. */
|
113
|
+
toString(): string;
|
114
|
+
/** Convert this link to a raw object which is serialization-friendly. */
|
115
|
+
toObject(): Record<string, any>;
|
116
|
+
/** Update this link with a new path. */
|
117
|
+
withPath(path: string): any;
|
118
|
+
/** Return a new link which points to the same location but with a new display value. */
|
119
|
+
withDisplay(display?: string): Link;
|
120
|
+
/** Convert a file link into a link to a specific header. */
|
121
|
+
withHeader(header: string): Link;
|
122
|
+
/** Convert any link into a link to its file. */
|
123
|
+
toFile(): Link;
|
124
|
+
/** Convert this link into an embedded link. */
|
125
|
+
toEmbed(): Link;
|
126
|
+
/** Convert this link into a non-embedded link. */
|
127
|
+
fromEmbed(): Link;
|
128
|
+
/** Convert this link to markdown so it can be rendered. */
|
129
|
+
markdown(): string;
|
130
|
+
/** Convert the inner part of the link to something that Obsidian can open / understand. */
|
131
|
+
obsidianLink(): string;
|
132
|
+
/** The stripped name of the file this link points to. */
|
133
|
+
fileName(): string;
|
107
134
|
}
|
108
135
|
/**
|
109
136
|
* A trivial base class which just defines the '$widget' identifier type. Subtypes of
|
@@ -111,38 +138,38 @@ export declare class Link {
|
|
111
138
|
* to have rendering functionality (which you probably do), you should extend `RenderWidget`.
|
112
139
|
*/
|
113
140
|
export declare abstract class Widget {
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
141
|
+
$widget: string;
|
142
|
+
constructor($widget: string);
|
143
|
+
/**
|
144
|
+
* Attempt to render this widget in markdown, if possible; if markdown is not possible,
|
145
|
+
* then this will attempt to render as HTML. Note that many widgets have interactive
|
146
|
+
* components or difficult functional components and the `markdown` function can simply
|
147
|
+
* return a placeholder in this case (such as `<function>` or `<task-list>`).
|
148
|
+
*/
|
149
|
+
abstract markdown(): string;
|
123
150
|
}
|
124
151
|
/** A trivial widget which renders a (key, value) pair, and allows accessing the key and value. */
|
125
152
|
export declare class ListPairWidget extends Widget {
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
153
|
+
key: Literal;
|
154
|
+
value: Literal;
|
155
|
+
constructor(key: Literal, value: Literal);
|
156
|
+
markdown(): string;
|
130
157
|
}
|
131
158
|
/** A simple widget which renders an external link. */
|
132
159
|
export declare class ExternalLinkWidget extends Widget {
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
160
|
+
url: string;
|
161
|
+
display?: string | undefined;
|
162
|
+
constructor(url: string, display?: string | undefined);
|
163
|
+
markdown(): string;
|
137
164
|
}
|
138
165
|
export declare namespace Widgets {
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
166
|
+
/** Create a list pair widget matching the given key and value. */
|
167
|
+
function listPair(key: Literal, value: Literal): ListPairWidget;
|
168
|
+
/** Create an external link widget which renders an external Obsidian link. */
|
169
|
+
function externalLink(url: string, display?: string): ExternalLinkWidget;
|
170
|
+
/** Checks if the given widget is a list pair widget. */
|
171
|
+
function isListPair(widget: Widget): widget is ListPairWidget;
|
172
|
+
function isExternalLink(widget: Widget): widget is ExternalLinkWidget;
|
173
|
+
/** Determines if the given widget is any kind of built-in widget with special rendering handling. */
|
174
|
+
function isBuiltin(widget: Widget): boolean;
|
148
175
|
}
|
@@ -1,29 +1,43 @@
|
|
1
1
|
/** Provides a global dispatch table for evaluating binary operators, including comparison. */
|
2
|
-
import type {
|
3
|
-
import type {
|
4
|
-
|
5
|
-
|
2
|
+
import type { Result } from '../api/result.d.ts';
|
3
|
+
import type {
|
4
|
+
Literal,
|
5
|
+
LiteralRepr,
|
6
|
+
LiteralType
|
7
|
+
} from '../data-model/value.d.ts';
|
8
|
+
import type { Context } from '../expression/context.d.ts';
|
9
|
+
import type { BinaryOp } from '../expression/field.d.ts';
|
6
10
|
/** A literal type or a catch-all '*'. */
|
7
|
-
export type LiteralTypeOrAll = LiteralType |
|
11
|
+
export type LiteralTypeOrAll = LiteralType | '*';
|
8
12
|
/** Maps a literal type or the catch-all '*'. */
|
9
|
-
export type LiteralReprAll<T extends LiteralTypeOrAll> = T extends
|
13
|
+
export type LiteralReprAll<T extends LiteralTypeOrAll> = T extends '*' ? Literal : T extends LiteralType ? LiteralRepr<T> : any;
|
10
14
|
/** An implementation for a binary operator. */
|
11
15
|
export type BinaryOpImpl<A extends Literal, B extends Literal> = (first: A, second: B, ctx: Context) => Literal;
|
12
16
|
/** An implementation of a comparator (returning a number) which then automatically defines all of the comparison operators. */
|
13
17
|
export type CompareImpl<T extends Literal> = (first: T, second: T, ctx: Context) => number;
|
14
18
|
/** Provides implementations for binary operators on two types using a registry. */
|
15
19
|
export declare class BinaryOpHandler {
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
private map;
|
21
|
+
static create(): BinaryOpHandler;
|
22
|
+
constructor();
|
23
|
+
register<T extends LiteralTypeOrAll, U extends LiteralTypeOrAll>(
|
24
|
+
left: T,
|
25
|
+
op: BinaryOp,
|
26
|
+
right: U,
|
27
|
+
func: BinaryOpImpl<LiteralReprAll<T>, LiteralReprAll<U>>
|
28
|
+
): BinaryOpHandler;
|
29
|
+
registerComm<T extends LiteralTypeOrAll, U extends LiteralTypeOrAll>(
|
30
|
+
left: T,
|
31
|
+
op: BinaryOp,
|
32
|
+
right: U,
|
33
|
+
func: BinaryOpImpl<LiteralReprAll<T>, LiteralReprAll<U>>
|
34
|
+
): BinaryOpHandler;
|
35
|
+
/** Implement a comparison function. */
|
36
|
+
compare<T extends LiteralTypeOrAll>(type: T, compare: CompareImpl<LiteralReprAll<T>>): BinaryOpHandler;
|
37
|
+
/** Attempt to evaluate the given binary operator on the two literal fields. */
|
38
|
+
evaluate(op: BinaryOp, left: Literal, right: Literal, ctx: Context): Result<Literal, string>;
|
39
|
+
/** Create a string representation of the given triplet for unique lookup in the map. */
|
40
|
+
static repr(op: BinaryOp, left: LiteralTypeOrAll, right: LiteralTypeOrAll): string;
|
27
41
|
}
|
28
42
|
/** Configure and create a binary OP handler with the given parameters. */
|
29
43
|
export declare function createBinaryOps(linkNormalizer: (x: string) => string): BinaryOpHandler;
|
@@ -1,43 +1,49 @@
|
|
1
1
|
/** Core implementation of the query language evaluation engine. */
|
2
|
-
import type {
|
3
|
-
import type {
|
4
|
-
import type {
|
5
|
-
import type {
|
6
|
-
import type {
|
7
|
-
import type {
|
2
|
+
import type { Result } from '../api/result.d.ts';
|
3
|
+
import type { Literal } from '../data-model/value.d.ts';
|
4
|
+
import type { QuerySettings } from '../settings.d.ts';
|
5
|
+
import type { BinaryOpHandler } from './binaryop.d.ts';
|
6
|
+
import type { Field } from './field.d.ts';
|
7
|
+
import type { FunctionImpl } from './functions.d.ts';
|
8
8
|
/** Handles link resolution and normalization inside of a context. */
|
9
9
|
export interface LinkHandler {
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
10
|
+
/** Resolve a link to the metadata it contains. */
|
11
|
+
resolve(path: string): Record<string, Literal> | null;
|
12
|
+
/**
|
13
|
+
* Normalize a link to it's fully-qualified path for comparison purposes.
|
14
|
+
* If the path does not exist, returns it unchanged.
|
15
|
+
*/
|
16
|
+
normalize(path: string): string;
|
17
|
+
/** Return true if the given path actually exists, false otherwise. */
|
18
|
+
exists(path: string): boolean;
|
19
19
|
}
|
20
20
|
/**
|
21
21
|
* Evaluation context that expressions can be evaluated in. Includes global state, as well as available functions and a handler
|
22
22
|
* for binary operators.
|
23
23
|
*/
|
24
24
|
export declare class Context {
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
25
|
+
linkHandler: LinkHandler;
|
26
|
+
settings: QuerySettings;
|
27
|
+
globals: Record<string, Literal>;
|
28
|
+
binaryOps: BinaryOpHandler;
|
29
|
+
functions: Record<string, FunctionImpl>;
|
30
|
+
/**
|
31
|
+
* Create a new context with the given namespace of globals, as well as optionally with custom binary operator, function,
|
32
|
+
* and link handlers.
|
33
|
+
*/
|
34
|
+
constructor(
|
35
|
+
linkHandler: LinkHandler,
|
36
|
+
settings: QuerySettings,
|
37
|
+
globals?: Record<string, Literal>,
|
38
|
+
binaryOps?: BinaryOpHandler,
|
39
|
+
functions?: Record<string, FunctionImpl>
|
40
|
+
);
|
41
|
+
/** Set a global value in this context. */
|
42
|
+
set(name: string, value: Literal): Context;
|
43
|
+
/** Get the value of a global variable by name. Returns null if not present. */
|
44
|
+
get(name: string): Literal;
|
45
|
+
/** Try to evaluate an arbitrary field in this context, raising an exception on failure. */
|
46
|
+
tryEvaluate(field: Field, data?: Record<string, Literal>): Literal;
|
47
|
+
/** Evaluate an arbitrary field in this context. */
|
48
|
+
evaluate(field: Field, data?: Record<string, Literal>): Result<Literal, string>;
|
43
49
|
}
|
@@ -1,82 +1,82 @@
|
|
1
1
|
/** Defines the AST for a field which can be evaluated. */
|
2
|
-
import type { Literal } from
|
2
|
+
import type { Literal } from '../data-model/value.d.ts';
|
3
3
|
/** Comparison operators which yield true/false. */
|
4
|
-
export type CompareOp =
|
4
|
+
export type CompareOp = '>' | '>=' | '<=' | '<' | '=' | '!=';
|
5
5
|
/** Arithmetic operators which yield numbers and other values. */
|
6
|
-
export type ArithmeticOp =
|
6
|
+
export type ArithmeticOp = '+' | '-' | '*' | '/' | '%' | '&' | '|';
|
7
7
|
/** All valid binary operators. */
|
8
8
|
export type BinaryOp = CompareOp | ArithmeticOp;
|
9
9
|
/** A (potentially computed) field to select or compare against. */
|
10
10
|
export type Field = BinaryOpField | VariableField | LiteralField | FunctionField | IndexField | NegatedField | LambdaField | ObjectField | ListField;
|
11
11
|
/** Literal representation of some field type. */
|
12
12
|
export interface LiteralField {
|
13
|
-
|
14
|
-
|
13
|
+
type: 'literal';
|
14
|
+
value: Literal;
|
15
15
|
}
|
16
16
|
/** A variable field for a variable with a given name. */
|
17
17
|
export interface VariableField {
|
18
|
-
|
19
|
-
|
18
|
+
type: 'variable';
|
19
|
+
name: string;
|
20
20
|
}
|
21
21
|
/** A list, which is an ordered collection of fields. */
|
22
22
|
export interface ListField {
|
23
|
-
|
24
|
-
|
23
|
+
type: 'list';
|
24
|
+
values: Field[];
|
25
25
|
}
|
26
26
|
/** An object, which is a mapping of name to field. */
|
27
27
|
export interface ObjectField {
|
28
|
-
|
29
|
-
|
28
|
+
type: 'object';
|
29
|
+
values: Record<string, Field>;
|
30
30
|
}
|
31
31
|
/** A binary operator field which combines two subnodes somehow. */
|
32
32
|
export interface BinaryOpField {
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
type: 'binaryop';
|
34
|
+
left: Field;
|
35
|
+
right: Field;
|
36
|
+
op: BinaryOp;
|
37
37
|
}
|
38
38
|
/** A function field which calls a function on 0 or more arguments. */
|
39
39
|
export interface FunctionField {
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
type: 'function';
|
41
|
+
/** Either the name of the function being called, or a Function object. */
|
42
|
+
func: Field;
|
43
|
+
/** The arguments being passed to the function. */
|
44
|
+
arguments: Field[];
|
45
45
|
}
|
46
46
|
export interface LambdaField {
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
47
|
+
type: 'lambda';
|
48
|
+
/** An ordered list of named arguments. */
|
49
|
+
arguments: string[];
|
50
|
+
/** The field which should be evaluated with the arguments in context. */
|
51
|
+
value: Field;
|
52
52
|
}
|
53
53
|
/** A field which indexes a variable into another variable. */
|
54
54
|
export interface IndexField {
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
55
|
+
type: 'index';
|
56
|
+
/** The field to index into. */
|
57
|
+
object: Field;
|
58
|
+
/** The index. */
|
59
|
+
index: Field;
|
60
60
|
}
|
61
61
|
/** A field which negates the value of the original field. */
|
62
62
|
export interface NegatedField {
|
63
|
-
|
64
|
-
|
65
|
-
|
63
|
+
type: 'negated';
|
64
|
+
/** The child field to negated. */
|
65
|
+
child: Field;
|
66
66
|
}
|
67
67
|
/** Utility methods for creating & comparing fields. */
|
68
68
|
export declare namespace Fields {
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
69
|
+
function variable(name: string): VariableField;
|
70
|
+
function literal(value: Literal): LiteralField;
|
71
|
+
function binaryOp(left: Field, op: BinaryOp, right: Field): Field;
|
72
|
+
function index(obj: Field, index: Field): IndexField;
|
73
|
+
/** Converts a string in dot-notation-format into a variable which indexes. */
|
74
|
+
function indexVariable(name: string): Field;
|
75
|
+
function lambda(args: string[], value: Field): LambdaField;
|
76
|
+
function func(func: Field, args: Field[]): FunctionField;
|
77
|
+
function list(values: Field[]): ListField;
|
78
|
+
function object(values: Record<string, Field>): ObjectField;
|
79
|
+
function negate(child: Field): NegatedField;
|
80
|
+
function isCompareOp(op: BinaryOp): op is CompareOp;
|
81
|
+
const NULL: LiteralField;
|
82
82
|
}
|