chronolizer 0.1.0 → 0.2.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/README.md +70 -7
- package/dist/ast/constructors.d.mts +140 -0
- package/dist/ast/constructors.mjs +25 -0
- package/dist/ast/fold.d.mts +12 -0
- package/dist/ast/fold.mjs +51 -0
- package/dist/ast/normalize.d.mts +42 -0
- package/dist/ast/normalize.mjs +32 -0
- package/dist/ast/schemas.d.mts +87 -0
- package/dist/ast/schemas.mjs +74 -0
- package/dist/filter/codec.d.mts +92 -0
- package/dist/filter/codec.mjs +48 -0
- package/dist/filter/errors.d.mts +14 -0
- package/dist/filter/errors.mjs +10 -0
- package/dist/filter/expression.d.mts +8 -0
- package/dist/filter/expression.mjs +93 -0
- package/dist/filter/schema.d.mts +13 -0
- package/dist/filter/schema.mjs +11 -0
- package/dist/filter/transformation.d.mts +37 -0
- package/dist/filter/transformation.mjs +20 -0
- package/dist/index.d.mts +22 -969
- package/dist/index.mjs +22 -2305
- package/dist/language/errors.d.mts +38 -0
- package/dist/language/errors.mjs +30 -0
- package/dist/language/model.d.mts +239 -0
- package/dist/language/model.mjs +53 -0
- package/dist/language/registry.d.mts +17 -0
- package/dist/language/registry.mjs +134 -0
- package/dist/locales/cs.d.mts +10 -0
- package/dist/locales/cs.mjs +693 -0
- package/dist/locales/de.d.mts +10 -0
- package/dist/locales/de.mjs +828 -0
- package/dist/locales/en.d.mts +10 -0
- package/dist/locales/en.mjs +550 -0
- package/dist/locales/es.d.mts +10 -0
- package/dist/locales/es.mjs +660 -0
- package/dist/locales/fr.d.mts +10 -0
- package/dist/locales/fr.mjs +737 -0
- package/dist/locales/nl.d.mts +10 -0
- package/dist/locales/nl.mjs +652 -0
- package/dist/locales/pl.d.mts +10 -0
- package/dist/locales/pl.mjs +711 -0
- package/dist/locales/shared.mjs +289 -0
- package/dist/locales/tr.d.mts +10 -0
- package/dist/locales/tr.mjs +660 -0
- package/dist/natural/correction.d.mts +13 -0
- package/dist/natural/correction.mjs +73 -0
- package/dist/natural/format.d.mts +47 -0
- package/dist/natural/format.mjs +14 -0
- package/dist/natural/parse.d.mts +99 -0
- package/dist/natural/parse.mjs +66 -0
- package/dist/natural/policy.mjs +6 -0
- package/dist/natural/suggest.d.mts +53 -0
- package/dist/natural/suggest.mjs +24 -0
- package/dist/natural/suggestion.d.mts +4 -0
- package/dist/natural/suggestion.mjs +79 -0
- package/dist/natural/text.d.mts +5 -0
- package/dist/natural/text.mjs +5 -0
- package/dist/resolve/resolve.d.mts +79 -0
- package/dist/resolve/resolve.mjs +66 -0
- package/dist/resolve/schema.d.mts +59 -0
- package/dist/resolve/schema.mjs +28 -0
- package/package.json +15 -3
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
//#region src/language/errors.d.ts
|
|
3
|
+
declare const UnsupportedLocaleError_base: Schema.Class<UnsupportedLocaleError, Schema.TaggedStruct<"UnsupportedLocaleError", {
|
|
4
|
+
readonly locale: Schema.String;
|
|
5
|
+
}>, import("effect/Cause").YieldableError>;
|
|
6
|
+
declare class UnsupportedLocaleError extends UnsupportedLocaleError_base {}
|
|
7
|
+
declare const LanguageConflictError_base: Schema.Class<LanguageConflictError, Schema.TaggedStruct<"LanguageConflictError", {
|
|
8
|
+
readonly locale: Schema.String;
|
|
9
|
+
readonly firstPluginId: Schema.String;
|
|
10
|
+
readonly secondPluginId: Schema.String;
|
|
11
|
+
readonly message: Schema.String;
|
|
12
|
+
}>, import("effect/Cause").YieldableError>;
|
|
13
|
+
declare class LanguageConflictError extends LanguageConflictError_base {}
|
|
14
|
+
declare const LanguageRegistrationError_base: Schema.Class<LanguageRegistrationError, Schema.TaggedStruct<"LanguageRegistrationError", {
|
|
15
|
+
readonly pluginId: Schema.String;
|
|
16
|
+
readonly locale: Schema.String;
|
|
17
|
+
readonly message: Schema.String;
|
|
18
|
+
}>, import("effect/Cause").YieldableError>;
|
|
19
|
+
declare class LanguageRegistrationError extends LanguageRegistrationError_base {}
|
|
20
|
+
declare const NaturalLanguageParseError_base: Schema.Class<NaturalLanguageParseError, Schema.TaggedStruct<"NaturalLanguageParseError", {
|
|
21
|
+
readonly input: Schema.String;
|
|
22
|
+
readonly locale: Schema.String;
|
|
23
|
+
readonly message: Schema.String;
|
|
24
|
+
}>, import("effect/Cause").YieldableError>;
|
|
25
|
+
declare class NaturalLanguageParseError extends NaturalLanguageParseError_base {}
|
|
26
|
+
declare const AmbiguousNaturalLanguageError_base: Schema.Class<AmbiguousNaturalLanguageError, Schema.TaggedStruct<"AmbiguousNaturalLanguageError", {
|
|
27
|
+
readonly input: Schema.String;
|
|
28
|
+
readonly locale: Schema.String;
|
|
29
|
+
readonly alternatives: Schema.$Array<Schema.String>;
|
|
30
|
+
}>, import("effect/Cause").YieldableError>;
|
|
31
|
+
declare class AmbiguousNaturalLanguageError extends AmbiguousNaturalLanguageError_base {}
|
|
32
|
+
declare const NaturalLanguageRenderError_base: Schema.Class<NaturalLanguageRenderError, Schema.TaggedStruct<"NaturalLanguageRenderError", {
|
|
33
|
+
readonly locale: Schema.String;
|
|
34
|
+
readonly message: Schema.String;
|
|
35
|
+
}>, import("effect/Cause").YieldableError>;
|
|
36
|
+
declare class NaturalLanguageRenderError extends NaturalLanguageRenderError_base {}
|
|
37
|
+
//#endregion
|
|
38
|
+
export { AmbiguousNaturalLanguageError, LanguageConflictError, LanguageRegistrationError, NaturalLanguageParseError, NaturalLanguageRenderError, UnsupportedLocaleError };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
//#region src/language/errors.ts
|
|
3
|
+
var UnsupportedLocaleError = class extends Schema.TaggedError()("UnsupportedLocaleError", { locale: Schema.String }) {};
|
|
4
|
+
var LanguageConflictError = class extends Schema.TaggedError()("LanguageConflictError", {
|
|
5
|
+
locale: Schema.String,
|
|
6
|
+
firstPluginId: Schema.String,
|
|
7
|
+
secondPluginId: Schema.String,
|
|
8
|
+
message: Schema.String
|
|
9
|
+
}) {};
|
|
10
|
+
var LanguageRegistrationError = class extends Schema.TaggedError()("LanguageRegistrationError", {
|
|
11
|
+
pluginId: Schema.String,
|
|
12
|
+
locale: Schema.String,
|
|
13
|
+
message: Schema.String
|
|
14
|
+
}) {};
|
|
15
|
+
var NaturalLanguageParseError = class extends Schema.TaggedError()("NaturalLanguageParseError", {
|
|
16
|
+
input: Schema.String,
|
|
17
|
+
locale: Schema.String,
|
|
18
|
+
message: Schema.String
|
|
19
|
+
}) {};
|
|
20
|
+
var AmbiguousNaturalLanguageError = class extends Schema.TaggedError()("AmbiguousNaturalLanguageError", {
|
|
21
|
+
input: Schema.String,
|
|
22
|
+
locale: Schema.String,
|
|
23
|
+
alternatives: Schema.Array(Schema.String)
|
|
24
|
+
}) {};
|
|
25
|
+
var NaturalLanguageRenderError = class extends Schema.TaggedError()("NaturalLanguageRenderError", {
|
|
26
|
+
locale: Schema.String,
|
|
27
|
+
message: Schema.String
|
|
28
|
+
}) {};
|
|
29
|
+
//#endregion
|
|
30
|
+
export { AmbiguousNaturalLanguageError, LanguageConflictError, LanguageRegistrationError, NaturalLanguageParseError, NaturalLanguageRenderError, UnsupportedLocaleError };
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { DateRangeExpr, InstantExpr } from "../ast/schemas.mjs";
|
|
2
|
+
import { LanguageConflictError, LanguageRegistrationError } from "./errors.mjs";
|
|
3
|
+
import { Effect, Option, Schema, Scope } from "effect";
|
|
4
|
+
//#region src/language/model.d.ts
|
|
5
|
+
declare const ParseQuality: Schema.Literals<readonly ["exact", "corrected", "ambiguous"]>;
|
|
6
|
+
type ParseQuality = typeof ParseQuality.Type;
|
|
7
|
+
declare const Correction: Schema.Struct<{
|
|
8
|
+
readonly original: Schema.String;
|
|
9
|
+
readonly replacement: Schema.String;
|
|
10
|
+
readonly distance: Schema.Int;
|
|
11
|
+
readonly offset: Schema.Int;
|
|
12
|
+
}>;
|
|
13
|
+
type Correction = typeof Correction.Type;
|
|
14
|
+
declare const NaturalCorrectionCandidate: Schema.Struct<{
|
|
15
|
+
readonly text: Schema.String;
|
|
16
|
+
readonly corrections: Schema.$Array<Schema.Struct<{
|
|
17
|
+
readonly original: Schema.String;
|
|
18
|
+
readonly replacement: Schema.String;
|
|
19
|
+
readonly distance: Schema.Int;
|
|
20
|
+
readonly offset: Schema.Int;
|
|
21
|
+
}>>;
|
|
22
|
+
readonly cost: Schema.Int;
|
|
23
|
+
}>;
|
|
24
|
+
type NaturalCorrectionCandidate = typeof NaturalCorrectionCandidate.Type;
|
|
25
|
+
declare const NaturalAlternative: Schema.Struct<{
|
|
26
|
+
readonly canonical: Schema.String;
|
|
27
|
+
readonly range: Schema.Union<readonly [Schema.TaggedStruct<"DateRange", {
|
|
28
|
+
readonly lower: Schema.Union<readonly [Schema.TaggedStruct<"GreaterThan", {
|
|
29
|
+
readonly value: Schema.Codec<InstantExpr, InstantExpr, never, never>;
|
|
30
|
+
}>, Schema.TaggedStruct<"GreaterThanOrEqual", {
|
|
31
|
+
readonly value: Schema.Codec<InstantExpr, InstantExpr, never, never>;
|
|
32
|
+
}>]>;
|
|
33
|
+
readonly upper: Schema.Union<readonly [Schema.TaggedStruct<"LessThan", {
|
|
34
|
+
readonly value: Schema.Codec<InstantExpr, InstantExpr, never, never>;
|
|
35
|
+
}>, Schema.TaggedStruct<"LessThanOrEqual", {
|
|
36
|
+
readonly value: Schema.Codec<InstantExpr, InstantExpr, never, never>;
|
|
37
|
+
}>]>;
|
|
38
|
+
}>, Schema.TaggedStruct<"DateRange", {
|
|
39
|
+
readonly lower: Schema.Union<readonly [Schema.TaggedStruct<"GreaterThan", {
|
|
40
|
+
readonly value: Schema.Codec<InstantExpr, InstantExpr, never, never>;
|
|
41
|
+
}>, Schema.TaggedStruct<"GreaterThanOrEqual", {
|
|
42
|
+
readonly value: Schema.Codec<InstantExpr, InstantExpr, never, never>;
|
|
43
|
+
}>]>;
|
|
44
|
+
readonly upper: Schema.optionalKey<Schema.Never>;
|
|
45
|
+
}>, Schema.TaggedStruct<"DateRange", {
|
|
46
|
+
readonly lower: Schema.optionalKey<Schema.Never>;
|
|
47
|
+
readonly upper: Schema.Union<readonly [Schema.TaggedStruct<"LessThan", {
|
|
48
|
+
readonly value: Schema.Codec<InstantExpr, InstantExpr, never, never>;
|
|
49
|
+
}>, Schema.TaggedStruct<"LessThanOrEqual", {
|
|
50
|
+
readonly value: Schema.Codec<InstantExpr, InstantExpr, never, never>;
|
|
51
|
+
}>]>;
|
|
52
|
+
}>]>;
|
|
53
|
+
}>;
|
|
54
|
+
type NaturalAlternative = typeof NaturalAlternative.Type;
|
|
55
|
+
declare const NaturalParseResult: Schema.Struct<{
|
|
56
|
+
readonly range: Schema.Union<readonly [Schema.TaggedStruct<"DateRange", {
|
|
57
|
+
readonly lower: Schema.Union<readonly [Schema.TaggedStruct<"GreaterThan", {
|
|
58
|
+
readonly value: Schema.Codec<InstantExpr, InstantExpr, never, never>;
|
|
59
|
+
}>, Schema.TaggedStruct<"GreaterThanOrEqual", {
|
|
60
|
+
readonly value: Schema.Codec<InstantExpr, InstantExpr, never, never>;
|
|
61
|
+
}>]>;
|
|
62
|
+
readonly upper: Schema.Union<readonly [Schema.TaggedStruct<"LessThan", {
|
|
63
|
+
readonly value: Schema.Codec<InstantExpr, InstantExpr, never, never>;
|
|
64
|
+
}>, Schema.TaggedStruct<"LessThanOrEqual", {
|
|
65
|
+
readonly value: Schema.Codec<InstantExpr, InstantExpr, never, never>;
|
|
66
|
+
}>]>;
|
|
67
|
+
}>, Schema.TaggedStruct<"DateRange", {
|
|
68
|
+
readonly lower: Schema.Union<readonly [Schema.TaggedStruct<"GreaterThan", {
|
|
69
|
+
readonly value: Schema.Codec<InstantExpr, InstantExpr, never, never>;
|
|
70
|
+
}>, Schema.TaggedStruct<"GreaterThanOrEqual", {
|
|
71
|
+
readonly value: Schema.Codec<InstantExpr, InstantExpr, never, never>;
|
|
72
|
+
}>]>;
|
|
73
|
+
readonly upper: Schema.optionalKey<Schema.Never>;
|
|
74
|
+
}>, Schema.TaggedStruct<"DateRange", {
|
|
75
|
+
readonly lower: Schema.optionalKey<Schema.Never>;
|
|
76
|
+
readonly upper: Schema.Union<readonly [Schema.TaggedStruct<"LessThan", {
|
|
77
|
+
readonly value: Schema.Codec<InstantExpr, InstantExpr, never, never>;
|
|
78
|
+
}>, Schema.TaggedStruct<"LessThanOrEqual", {
|
|
79
|
+
readonly value: Schema.Codec<InstantExpr, InstantExpr, never, never>;
|
|
80
|
+
}>]>;
|
|
81
|
+
}>]>;
|
|
82
|
+
readonly quality: Schema.Literals<readonly ["exact", "corrected", "ambiguous"]>;
|
|
83
|
+
readonly corrections: Schema.$Array<Schema.Struct<{
|
|
84
|
+
readonly original: Schema.String;
|
|
85
|
+
readonly replacement: Schema.String;
|
|
86
|
+
readonly distance: Schema.Int;
|
|
87
|
+
readonly offset: Schema.Int;
|
|
88
|
+
}>>;
|
|
89
|
+
readonly alternatives: Schema.$Array<Schema.Struct<{
|
|
90
|
+
readonly canonical: Schema.String;
|
|
91
|
+
readonly range: Schema.Union<readonly [Schema.TaggedStruct<"DateRange", {
|
|
92
|
+
readonly lower: Schema.Union<readonly [Schema.TaggedStruct<"GreaterThan", {
|
|
93
|
+
readonly value: Schema.Codec<InstantExpr, InstantExpr, never, never>;
|
|
94
|
+
}>, Schema.TaggedStruct<"GreaterThanOrEqual", {
|
|
95
|
+
readonly value: Schema.Codec<InstantExpr, InstantExpr, never, never>;
|
|
96
|
+
}>]>;
|
|
97
|
+
readonly upper: Schema.Union<readonly [Schema.TaggedStruct<"LessThan", {
|
|
98
|
+
readonly value: Schema.Codec<InstantExpr, InstantExpr, never, never>;
|
|
99
|
+
}>, Schema.TaggedStruct<"LessThanOrEqual", {
|
|
100
|
+
readonly value: Schema.Codec<InstantExpr, InstantExpr, never, never>;
|
|
101
|
+
}>]>;
|
|
102
|
+
}>, Schema.TaggedStruct<"DateRange", {
|
|
103
|
+
readonly lower: Schema.Union<readonly [Schema.TaggedStruct<"GreaterThan", {
|
|
104
|
+
readonly value: Schema.Codec<InstantExpr, InstantExpr, never, never>;
|
|
105
|
+
}>, Schema.TaggedStruct<"GreaterThanOrEqual", {
|
|
106
|
+
readonly value: Schema.Codec<InstantExpr, InstantExpr, never, never>;
|
|
107
|
+
}>]>;
|
|
108
|
+
readonly upper: Schema.optionalKey<Schema.Never>;
|
|
109
|
+
}>, Schema.TaggedStruct<"DateRange", {
|
|
110
|
+
readonly lower: Schema.optionalKey<Schema.Never>;
|
|
111
|
+
readonly upper: Schema.Union<readonly [Schema.TaggedStruct<"LessThan", {
|
|
112
|
+
readonly value: Schema.Codec<InstantExpr, InstantExpr, never, never>;
|
|
113
|
+
}>, Schema.TaggedStruct<"LessThanOrEqual", {
|
|
114
|
+
readonly value: Schema.Codec<InstantExpr, InstantExpr, never, never>;
|
|
115
|
+
}>]>;
|
|
116
|
+
}>]>;
|
|
117
|
+
}>>;
|
|
118
|
+
}>;
|
|
119
|
+
type NaturalParseResult = typeof NaturalParseResult.Type;
|
|
120
|
+
declare const NaturalCandidate: Schema.Struct<{
|
|
121
|
+
readonly range: Schema.Union<readonly [Schema.TaggedStruct<"DateRange", {
|
|
122
|
+
readonly lower: Schema.Union<readonly [Schema.TaggedStruct<"GreaterThan", {
|
|
123
|
+
readonly value: Schema.Codec<InstantExpr, InstantExpr, never, never>;
|
|
124
|
+
}>, Schema.TaggedStruct<"GreaterThanOrEqual", {
|
|
125
|
+
readonly value: Schema.Codec<InstantExpr, InstantExpr, never, never>;
|
|
126
|
+
}>]>;
|
|
127
|
+
readonly upper: Schema.Union<readonly [Schema.TaggedStruct<"LessThan", {
|
|
128
|
+
readonly value: Schema.Codec<InstantExpr, InstantExpr, never, never>;
|
|
129
|
+
}>, Schema.TaggedStruct<"LessThanOrEqual", {
|
|
130
|
+
readonly value: Schema.Codec<InstantExpr, InstantExpr, never, never>;
|
|
131
|
+
}>]>;
|
|
132
|
+
}>, Schema.TaggedStruct<"DateRange", {
|
|
133
|
+
readonly lower: Schema.Union<readonly [Schema.TaggedStruct<"GreaterThan", {
|
|
134
|
+
readonly value: Schema.Codec<InstantExpr, InstantExpr, never, never>;
|
|
135
|
+
}>, Schema.TaggedStruct<"GreaterThanOrEqual", {
|
|
136
|
+
readonly value: Schema.Codec<InstantExpr, InstantExpr, never, never>;
|
|
137
|
+
}>]>;
|
|
138
|
+
readonly upper: Schema.optionalKey<Schema.Never>;
|
|
139
|
+
}>, Schema.TaggedStruct<"DateRange", {
|
|
140
|
+
readonly lower: Schema.optionalKey<Schema.Never>;
|
|
141
|
+
readonly upper: Schema.Union<readonly [Schema.TaggedStruct<"LessThan", {
|
|
142
|
+
readonly value: Schema.Codec<InstantExpr, InstantExpr, never, never>;
|
|
143
|
+
}>, Schema.TaggedStruct<"LessThanOrEqual", {
|
|
144
|
+
readonly value: Schema.Codec<InstantExpr, InstantExpr, never, never>;
|
|
145
|
+
}>]>;
|
|
146
|
+
}>]>;
|
|
147
|
+
readonly canonical: Schema.String;
|
|
148
|
+
}>;
|
|
149
|
+
type NaturalCandidate = typeof NaturalCandidate.Type;
|
|
150
|
+
declare const NaturalSuggestion: Schema.Struct<{
|
|
151
|
+
readonly text: Schema.String;
|
|
152
|
+
readonly range: Schema.Union<readonly [Schema.TaggedStruct<"DateRange", {
|
|
153
|
+
readonly lower: Schema.Union<readonly [Schema.TaggedStruct<"GreaterThan", {
|
|
154
|
+
readonly value: Schema.Codec<InstantExpr, InstantExpr, never, never>;
|
|
155
|
+
}>, Schema.TaggedStruct<"GreaterThanOrEqual", {
|
|
156
|
+
readonly value: Schema.Codec<InstantExpr, InstantExpr, never, never>;
|
|
157
|
+
}>]>;
|
|
158
|
+
readonly upper: Schema.Union<readonly [Schema.TaggedStruct<"LessThan", {
|
|
159
|
+
readonly value: Schema.Codec<InstantExpr, InstantExpr, never, never>;
|
|
160
|
+
}>, Schema.TaggedStruct<"LessThanOrEqual", {
|
|
161
|
+
readonly value: Schema.Codec<InstantExpr, InstantExpr, never, never>;
|
|
162
|
+
}>]>;
|
|
163
|
+
}>, Schema.TaggedStruct<"DateRange", {
|
|
164
|
+
readonly lower: Schema.Union<readonly [Schema.TaggedStruct<"GreaterThan", {
|
|
165
|
+
readonly value: Schema.Codec<InstantExpr, InstantExpr, never, never>;
|
|
166
|
+
}>, Schema.TaggedStruct<"GreaterThanOrEqual", {
|
|
167
|
+
readonly value: Schema.Codec<InstantExpr, InstantExpr, never, never>;
|
|
168
|
+
}>]>;
|
|
169
|
+
readonly upper: Schema.optionalKey<Schema.Never>;
|
|
170
|
+
}>, Schema.TaggedStruct<"DateRange", {
|
|
171
|
+
readonly lower: Schema.optionalKey<Schema.Never>;
|
|
172
|
+
readonly upper: Schema.Union<readonly [Schema.TaggedStruct<"LessThan", {
|
|
173
|
+
readonly value: Schema.Codec<InstantExpr, InstantExpr, never, never>;
|
|
174
|
+
}>, Schema.TaggedStruct<"LessThanOrEqual", {
|
|
175
|
+
readonly value: Schema.Codec<InstantExpr, InstantExpr, never, never>;
|
|
176
|
+
}>]>;
|
|
177
|
+
}>]>;
|
|
178
|
+
}>;
|
|
179
|
+
type NaturalSuggestion = typeof NaturalSuggestion.Type;
|
|
180
|
+
declare const BaseLanguageContribution_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => Readonly<A> & {
|
|
181
|
+
readonly _tag: "BaseLanguage";
|
|
182
|
+
} & import("effect/Pipeable").Pipeable;
|
|
183
|
+
declare class BaseLanguageContribution extends BaseLanguageContribution_base<{
|
|
184
|
+
readonly locale: string;
|
|
185
|
+
readonly vocabulary: ReadonlyArray<string>;
|
|
186
|
+
readonly normalize?: (input: string, locale: string) => string;
|
|
187
|
+
readonly correct?: (input: string, vocabulary: ReadonlyArray<string>) => ReadonlyArray<NaturalCorrectionCandidate>;
|
|
188
|
+
readonly parseExact: (input: string) => Option.Option<NaturalCandidate>;
|
|
189
|
+
readonly suggest?: (input: string, limit: number) => ReadonlyArray<string>;
|
|
190
|
+
readonly render: (range: DateRangeExpr) => Option.Option<string>;
|
|
191
|
+
}> {}
|
|
192
|
+
declare const LanguageExtensionContribution_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => Readonly<A> & {
|
|
193
|
+
readonly _tag: "LanguageExtension";
|
|
194
|
+
} & import("effect/Pipeable").Pipeable;
|
|
195
|
+
declare class LanguageExtensionContribution extends LanguageExtensionContribution_base<{
|
|
196
|
+
readonly locale: string;
|
|
197
|
+
readonly priority: number;
|
|
198
|
+
readonly vocabulary: ReadonlyArray<string>;
|
|
199
|
+
readonly parseExact: (input: string) => Option.Option<NaturalCandidate>;
|
|
200
|
+
readonly suggest?: (input: string, limit: number) => ReadonlyArray<string>;
|
|
201
|
+
}> {}
|
|
202
|
+
type LanguageContribution = BaseLanguageContribution | LanguageExtensionContribution;
|
|
203
|
+
declare const canonicalBaseLocale: (input: string) => Option.Option<string>;
|
|
204
|
+
declare const Locale: Schema.String;
|
|
205
|
+
declare const BaseLanguageMetadata: Schema.TaggedStruct<"BaseLanguage", {
|
|
206
|
+
readonly locale: Schema.String;
|
|
207
|
+
readonly vocabulary: Schema.$Array<Schema.String>;
|
|
208
|
+
}>;
|
|
209
|
+
declare const LanguageExtensionMetadata: Schema.TaggedStruct<"LanguageExtension", {
|
|
210
|
+
readonly locale: Schema.String;
|
|
211
|
+
readonly priority: Schema.Int;
|
|
212
|
+
readonly vocabulary: Schema.$Array<Schema.String>;
|
|
213
|
+
}>;
|
|
214
|
+
declare const LanguageContributionMetadata: Schema.Union<readonly [Schema.TaggedStruct<"BaseLanguage", {
|
|
215
|
+
readonly locale: Schema.String;
|
|
216
|
+
readonly vocabulary: Schema.$Array<Schema.String>;
|
|
217
|
+
}>, Schema.TaggedStruct<"LanguageExtension", {
|
|
218
|
+
readonly locale: Schema.String;
|
|
219
|
+
readonly priority: Schema.Int;
|
|
220
|
+
readonly vocabulary: Schema.$Array<Schema.String>;
|
|
221
|
+
}>]>;
|
|
222
|
+
interface LanguagePluginContext {
|
|
223
|
+
readonly register: (pluginId: string, contribution: LanguageContribution) => Effect.Effect<void, LanguageRegistrationError | LanguageConflictError, Scope.Scope>;
|
|
224
|
+
}
|
|
225
|
+
interface LanguagePlugin {
|
|
226
|
+
readonly id: string;
|
|
227
|
+
readonly effect: (context: LanguagePluginContext) => Effect.Effect<void, LanguageRegistrationError | LanguageConflictError, Scope.Scope>;
|
|
228
|
+
}
|
|
229
|
+
interface CompiledLanguage {
|
|
230
|
+
readonly locale: string;
|
|
231
|
+
readonly vocabulary: ReadonlyArray<string>;
|
|
232
|
+
readonly normalize: (input: string, locale: string) => string;
|
|
233
|
+
readonly correct: ((input: string, vocabulary: ReadonlyArray<string>) => ReadonlyArray<NaturalCorrectionCandidate>) | undefined;
|
|
234
|
+
readonly parseExact: (input: string) => ReadonlyArray<NaturalCandidate>;
|
|
235
|
+
readonly suggest: (input: string, limit: number) => ReadonlyArray<string>;
|
|
236
|
+
readonly render: (range: DateRangeExpr) => Option.Option<string>;
|
|
237
|
+
}
|
|
238
|
+
//#endregion
|
|
239
|
+
export { BaseLanguageContribution, BaseLanguageMetadata, CompiledLanguage, Correction, LanguageContribution, LanguageContributionMetadata, LanguageExtensionContribution, LanguageExtensionMetadata, LanguagePlugin, LanguagePluginContext, Locale, NaturalAlternative, NaturalCandidate, NaturalCorrectionCandidate, NaturalParseResult, NaturalSuggestion, ParseQuality, canonicalBaseLocale };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { DateRangeExpr } from "../ast/schemas.mjs";
|
|
2
|
+
import { Data, Option, Result, Schema } from "effect";
|
|
3
|
+
//#region src/language/model.ts
|
|
4
|
+
const ParseQuality = Schema.Literals([
|
|
5
|
+
"exact",
|
|
6
|
+
"corrected",
|
|
7
|
+
"ambiguous"
|
|
8
|
+
]);
|
|
9
|
+
const Correction = Schema.Struct({
|
|
10
|
+
original: Schema.String,
|
|
11
|
+
replacement: Schema.String,
|
|
12
|
+
distance: Schema.Int.check(Schema.isGreaterThanOrEqualTo(1)),
|
|
13
|
+
offset: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0))
|
|
14
|
+
});
|
|
15
|
+
const NaturalCorrectionCandidate = Schema.Struct({
|
|
16
|
+
text: Schema.String,
|
|
17
|
+
corrections: Schema.Array(Correction),
|
|
18
|
+
cost: Schema.Int.check(Schema.isGreaterThanOrEqualTo(1))
|
|
19
|
+
});
|
|
20
|
+
const NaturalAlternative = Schema.Struct({
|
|
21
|
+
canonical: Schema.String,
|
|
22
|
+
range: DateRangeExpr
|
|
23
|
+
});
|
|
24
|
+
const NaturalParseResult = Schema.Struct({
|
|
25
|
+
range: DateRangeExpr,
|
|
26
|
+
quality: ParseQuality,
|
|
27
|
+
corrections: Schema.Array(Correction),
|
|
28
|
+
alternatives: Schema.Array(NaturalAlternative)
|
|
29
|
+
});
|
|
30
|
+
const NaturalCandidate = Schema.Struct({
|
|
31
|
+
range: DateRangeExpr,
|
|
32
|
+
canonical: Schema.String
|
|
33
|
+
});
|
|
34
|
+
const NaturalSuggestion = Schema.Struct({
|
|
35
|
+
text: Schema.String,
|
|
36
|
+
range: DateRangeExpr
|
|
37
|
+
});
|
|
38
|
+
var BaseLanguageContribution = class extends Data.TaggedClass("BaseLanguage") {};
|
|
39
|
+
var LanguageExtensionContribution = class extends Data.TaggedClass("LanguageExtension") {};
|
|
40
|
+
const canonicalBaseLocale = (input) => Result.getSuccess(Result.try(() => new Intl.Locale(input).baseName));
|
|
41
|
+
const Locale = Schema.String.check(Schema.makeFilter((value) => Option.contains(canonicalBaseLocale(value), value), { expected: "a canonical BCP 47 base locale identifier" })).annotate({ identifier: "Locale" });
|
|
42
|
+
const BaseLanguageMetadata = Schema.TaggedStruct("BaseLanguage", {
|
|
43
|
+
locale: Locale,
|
|
44
|
+
vocabulary: Schema.Array(Schema.String)
|
|
45
|
+
});
|
|
46
|
+
const LanguageExtensionMetadata = Schema.TaggedStruct("LanguageExtension", {
|
|
47
|
+
locale: Locale,
|
|
48
|
+
priority: Schema.Int,
|
|
49
|
+
vocabulary: Schema.Array(Schema.String)
|
|
50
|
+
});
|
|
51
|
+
const LanguageContributionMetadata = Schema.Union([BaseLanguageMetadata, LanguageExtensionMetadata]);
|
|
52
|
+
//#endregion
|
|
53
|
+
export { BaseLanguageContribution, BaseLanguageMetadata, Correction, LanguageContributionMetadata, LanguageExtensionContribution, LanguageExtensionMetadata, Locale, NaturalAlternative, NaturalCandidate, NaturalCorrectionCandidate, NaturalParseResult, NaturalSuggestion, ParseQuality, canonicalBaseLocale };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { LanguageConflictError, LanguageRegistrationError, UnsupportedLocaleError } from "./errors.mjs";
|
|
2
|
+
import { CompiledLanguage, LanguageContribution, LanguagePlugin } from "./model.mjs";
|
|
3
|
+
import { Context, Effect, Layer, Scope } from "effect";
|
|
4
|
+
//#region src/language/registry.d.ts
|
|
5
|
+
declare namespace LanguageRegistry {
|
|
6
|
+
interface Service {
|
|
7
|
+
readonly register: (pluginId: string, contribution: LanguageContribution) => Effect.Effect<void, LanguageRegistrationError | LanguageConflictError, Scope.Scope>;
|
|
8
|
+
readonly resolve: (locale: string) => Effect.Effect<CompiledLanguage, UnsupportedLocaleError>;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
declare const LanguageRegistry_base: Context.ServiceClass<LanguageRegistry, "chronolizer/LanguageRegistry", LanguageRegistry.Service>;
|
|
12
|
+
declare class LanguageRegistry extends LanguageRegistry_base {}
|
|
13
|
+
declare const LanguageRegistryLayer: Layer.Layer<LanguageRegistry, never, never>;
|
|
14
|
+
declare const languagePluginsLayer: (plugins: ReadonlyArray<LanguagePlugin>) => Layer.Layer<LanguageRegistry, LanguageConflictError | LanguageRegistrationError, never>;
|
|
15
|
+
declare const defineLanguagePlugin: (plugin: LanguagePlugin) => LanguagePlugin;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { LanguageRegistry, LanguageRegistryLayer, defineLanguagePlugin, languagePluginsLayer };
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { LanguageConflictError, LanguageRegistrationError, UnsupportedLocaleError } from "./errors.mjs";
|
|
2
|
+
import { BaseLanguageMetadata, LanguageContributionMetadata, LanguageExtensionMetadata, canonicalBaseLocale } from "./model.mjs";
|
|
3
|
+
import { normalizeNaturalText } from "../natural/text.mjs";
|
|
4
|
+
import { Array, Context, Effect, Layer, Match, Option, Order, Ref, Result, Schema } from "effect";
|
|
5
|
+
//#region src/language/registry.ts
|
|
6
|
+
var LanguageRegistry = class extends Context.Service()("chronolizer/LanguageRegistry") {};
|
|
7
|
+
const metadataOf = (contribution) => Match.valueTags(contribution, {
|
|
8
|
+
BaseLanguage: (base) => BaseLanguageMetadata.make({
|
|
9
|
+
locale: base.locale,
|
|
10
|
+
vocabulary: base.vocabulary
|
|
11
|
+
}),
|
|
12
|
+
LanguageExtension: (extension) => LanguageExtensionMetadata.make({
|
|
13
|
+
locale: extension.locale,
|
|
14
|
+
priority: extension.priority,
|
|
15
|
+
vocabulary: extension.vocabulary
|
|
16
|
+
})
|
|
17
|
+
});
|
|
18
|
+
const localeCandidates = (locale) => {
|
|
19
|
+
const candidates = [locale];
|
|
20
|
+
let parent = locale;
|
|
21
|
+
while (parent.includes("-")) {
|
|
22
|
+
parent = parent.slice(0, parent.lastIndexOf("-"));
|
|
23
|
+
candidates.push(parent);
|
|
24
|
+
}
|
|
25
|
+
return candidates;
|
|
26
|
+
};
|
|
27
|
+
const compileLanguage = (locale, registered) => {
|
|
28
|
+
const locales = localeCandidates(locale);
|
|
29
|
+
const base = Array.sort(Array.filterMap(registered, (entry) => Match.valueTags(entry.contribution, {
|
|
30
|
+
BaseLanguage: (contribution) => locales.includes(contribution.locale) ? Result.succeed({
|
|
31
|
+
pluginId: entry.pluginId,
|
|
32
|
+
contribution
|
|
33
|
+
}) : Result.failVoid,
|
|
34
|
+
LanguageExtension: () => Result.failVoid
|
|
35
|
+
})), Order.mapInput(Order.Number, (entry) => locales.indexOf(entry.contribution.locale)))[0];
|
|
36
|
+
if (base === void 0) return Option.none();
|
|
37
|
+
const extensions = Array.sort(Array.filterMap(registered, (entry) => Match.valueTags(entry.contribution, {
|
|
38
|
+
BaseLanguage: () => Result.failVoid,
|
|
39
|
+
LanguageExtension: (contribution) => locales.includes(contribution.locale) ? Result.succeed({
|
|
40
|
+
pluginId: entry.pluginId,
|
|
41
|
+
contribution
|
|
42
|
+
}) : Result.failVoid
|
|
43
|
+
})), Order.combine(Order.mapInput(Order.flip(Order.Number), (entry) => entry.contribution.priority), Order.mapInput(Order.String, (entry) => entry.pluginId)));
|
|
44
|
+
const vocabulary = Object.freeze(Array.dedupe([...base.contribution.vocabulary, ...Array.flatMap(extensions, (entry) => entry.contribution.vocabulary)]));
|
|
45
|
+
const parsers = Object.freeze([...extensions.map((entry) => entry.contribution.parseExact), base.contribution.parseExact]);
|
|
46
|
+
const suggesters = Object.freeze([...extensions.map((entry) => entry.contribution.suggest), base.contribution.suggest].filter((suggest) => suggest !== void 0));
|
|
47
|
+
const parseExact = (input) => {
|
|
48
|
+
const candidates = [];
|
|
49
|
+
for (const parser of parsers) {
|
|
50
|
+
const candidate = parser(input);
|
|
51
|
+
if (Option.isSome(candidate)) candidates.push(candidate.value);
|
|
52
|
+
}
|
|
53
|
+
return candidates;
|
|
54
|
+
};
|
|
55
|
+
return Option.some(Object.freeze({
|
|
56
|
+
locale: base.contribution.locale,
|
|
57
|
+
vocabulary,
|
|
58
|
+
normalize: base.contribution.normalize ?? normalizeNaturalText,
|
|
59
|
+
correct: base.contribution.correct,
|
|
60
|
+
parseExact,
|
|
61
|
+
suggest: (input, limit) => Array.flatMap(suggesters, (suggest) => suggest(input, limit)),
|
|
62
|
+
render: base.contribution.render
|
|
63
|
+
}));
|
|
64
|
+
};
|
|
65
|
+
const createRegistry = Effect.fn(function* () {
|
|
66
|
+
const entries = yield* Ref.make([]);
|
|
67
|
+
const register = Effect.fn(function* (pluginId, contribution) {
|
|
68
|
+
if (pluginId.length === 0 || !Schema.is(LanguageContributionMetadata)(metadataOf(contribution))) return yield* new LanguageRegistrationError({
|
|
69
|
+
pluginId,
|
|
70
|
+
locale: contribution.locale,
|
|
71
|
+
message: "Invalid plugin identifier or contribution metadata"
|
|
72
|
+
});
|
|
73
|
+
const token = Symbol(pluginId);
|
|
74
|
+
yield* Effect.acquireRelease(Ref.modify(entries, (current) => {
|
|
75
|
+
const conflictingBase = Match.valueTags(contribution, {
|
|
76
|
+
BaseLanguage: (base) => Array.findFirst(current, (entry) => Match.valueTags(entry.contribution, {
|
|
77
|
+
BaseLanguage: (registeredBase) => registeredBase.locale === base.locale,
|
|
78
|
+
LanguageExtension: () => false
|
|
79
|
+
})),
|
|
80
|
+
LanguageExtension: () => Option.none()
|
|
81
|
+
});
|
|
82
|
+
return Option.match(conflictingBase, {
|
|
83
|
+
onNone: () => [Result.succeed(token), Array.append(current, {
|
|
84
|
+
token,
|
|
85
|
+
pluginId,
|
|
86
|
+
contribution
|
|
87
|
+
})],
|
|
88
|
+
onSome: (conflict) => [Result.fail(new LanguageConflictError({
|
|
89
|
+
locale: contribution.locale,
|
|
90
|
+
firstPluginId: conflict.pluginId,
|
|
91
|
+
secondPluginId: pluginId,
|
|
92
|
+
message: "Only one base language can be registered for a locale"
|
|
93
|
+
})), current]
|
|
94
|
+
});
|
|
95
|
+
}).pipe(Effect.flatMap((result) => Effect.fromResult(result))), (registeredToken) => Ref.update(entries, (items) => Array.filter(items, (entry) => entry.token !== registeredToken)));
|
|
96
|
+
});
|
|
97
|
+
const resolve = Effect.fn(function* (locale) {
|
|
98
|
+
const canonical = canonicalBaseLocale(locale);
|
|
99
|
+
if (Option.isSome(canonical)) {
|
|
100
|
+
const compiled = compileLanguage(canonical.value, yield* Ref.get(entries));
|
|
101
|
+
if (Option.isSome(compiled)) return compiled.value;
|
|
102
|
+
}
|
|
103
|
+
return yield* new UnsupportedLocaleError({ locale });
|
|
104
|
+
});
|
|
105
|
+
return LanguageRegistry.of({
|
|
106
|
+
register,
|
|
107
|
+
resolve
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
const LanguageRegistryLayer = Layer.effect(LanguageRegistry, createRegistry());
|
|
111
|
+
const duplicatePluginId = (plugins) => {
|
|
112
|
+
const ids = /* @__PURE__ */ new Set();
|
|
113
|
+
for (const plugin of plugins) {
|
|
114
|
+
if (ids.has(plugin.id)) return plugin.id;
|
|
115
|
+
ids.add(plugin.id);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
const createPluginRegistry = Effect.fn(function* (plugins) {
|
|
119
|
+
const duplicate = duplicatePluginId(plugins);
|
|
120
|
+
if (duplicate !== void 0) return yield* new LanguageRegistrationError({
|
|
121
|
+
pluginId: duplicate,
|
|
122
|
+
locale: "*",
|
|
123
|
+
message: "Plugin identifiers must be unique"
|
|
124
|
+
});
|
|
125
|
+
const registry = yield* createRegistry();
|
|
126
|
+
const context = { register: registry.register };
|
|
127
|
+
const ordered = Array.sortWith(plugins, (plugin) => plugin.id, Order.String);
|
|
128
|
+
for (const plugin of ordered) yield* plugin.effect(context);
|
|
129
|
+
return registry;
|
|
130
|
+
});
|
|
131
|
+
const languagePluginsLayer = (plugins) => Layer.effect(LanguageRegistry, createPluginRegistry(plugins));
|
|
132
|
+
const defineLanguagePlugin = (plugin) => plugin;
|
|
133
|
+
//#endregion
|
|
134
|
+
export { LanguageRegistry, LanguageRegistryLayer, defineLanguagePlugin, languagePluginsLayer };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LanguageConflictError, LanguageRegistrationError } from "../language/errors.mjs";
|
|
2
|
+
import { BaseLanguageContribution, LanguagePlugin } from "../language/model.mjs";
|
|
3
|
+
import { LanguageRegistry } from "../language/registry.mjs";
|
|
4
|
+
import "../index.mjs";
|
|
5
|
+
//#region src/locales/cs.d.ts
|
|
6
|
+
declare const CzechContribution: BaseLanguageContribution;
|
|
7
|
+
declare const CzechLanguage: LanguagePlugin;
|
|
8
|
+
declare const CzechLanguageLayer: import("effect/Layer").Layer<LanguageRegistry, LanguageConflictError | LanguageRegistrationError, never>;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { CzechContribution, CzechLanguage, CzechLanguageLayer };
|