@kensio/quando 0.1.0-beta.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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # Quando
2
+
3
+ Declarative temporal rules for schedules, deadlines, constraints, and exceptions.
4
+
5
+ ## Status
6
+
7
+ Early. The API is still being designed and nothing is published yet, so there is
8
+ nothing here to install or call. `src/index.ts` is a placeholder that exists to
9
+ keep the build and test pipeline honest until it has real code to run over.
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Quando: declarative temporal rules for schedules, deadlines, constraints and
3
+ * exceptions.
4
+ *
5
+ * What exists so far is the interval core — the algebra everything else is
6
+ * built from. Rules, cascades and queries are still to come.
7
+ *
8
+ * Requires a runtime with `Temporal`: Node 26 or later, or a browser that
9
+ * implements it.
10
+ * Quando reads the global rather than importing a polyfill, so anywhere without
11
+ * one natively can load `temporal-polyfill` first and everything here works
12
+ * untouched.
13
+ */
14
+ export type { Interval } from "./interval.js";
15
+ export { compareEnds, compareStarts, contains, duration, isEmpty, startsAtOrBeforeEnd, startsBeforeEnd, } from "./interval.js";
16
+ export type { IntervalStream } from "./interval-stream.js";
17
+ export { clip, complement, intersect, union } from "./interval-stream.js";
18
+ export { take } from "./stream.js";
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EACL,WAAW,EACX,aAAa,EACb,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,mBAAmB,EACnB,eAAe,GAChB,MAAM,eAAe,CAAC;AAEvB,YAAY,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAE1E,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Quando: declarative temporal rules for schedules, deadlines, constraints and
3
+ * exceptions.
4
+ *
5
+ * What exists so far is the interval core — the algebra everything else is
6
+ * built from. Rules, cascades and queries are still to come.
7
+ *
8
+ * Requires a runtime with `Temporal`: Node 26 or later, or a browser that
9
+ * implements it.
10
+ * Quando reads the global rather than importing a polyfill, so anywhere without
11
+ * one natively can load `temporal-polyfill` first and everything here works
12
+ * untouched.
13
+ */
14
+ export { compareEnds, compareStarts, contains, duration, isEmpty, startsAtOrBeforeEnd, startsBeforeEnd, } from "./interval.js";
15
+ export { clip, complement, intersect, union } from "./interval-stream.js";
16
+ export { take } from "./stream.js";
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EACL,WAAW,EACX,aAAa,EACb,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,mBAAmB,EACnB,eAAe,GAChB,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAE1E,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * The interval algebra: intersection, union and complement over lazy streams.
3
+ *
4
+ * Streams are `Iterable`, and may be infinite — a weekly recurrence genuinely
5
+ * has no end, and modelling it as though it did would put callers back to
6
+ * guessing a window large enough to hold an answer they cannot predict.
7
+ *
8
+ * Every operation here is a sweep: it pulls from its sources only as far as it
9
+ * needs to produce the next result, so `take(3)` from an infinite intersection
10
+ * pulls a handful of intervals rather than expanding a year.
11
+ */
12
+ import { type Interval } from "./interval.js";
13
+ /**
14
+ * A lazy sequence of intervals.
15
+ *
16
+ * **Contract, which every producer must uphold:** intervals arrive sorted by
17
+ * start, do not overlap, and are already coalesced — no two touching intervals
18
+ * where one would do. The sweeps below are single-pass and rely on it; a
19
+ * producer that breaks it produces wrong answers rather than errors.
20
+ */
21
+ export type IntervalStream = Iterable<Interval>;
22
+ /**
23
+ * The times both streams cover.
24
+ *
25
+ * Terminates when either source does. Note that it will *not* terminate on two
26
+ * infinite sources that never overlap — there is nothing it could inspect to
27
+ * discover that the answer is empty. See the note on unbounded queries in the
28
+ * documentation; that case is the caller's to bound.
29
+ */
30
+ export declare function intersect(left: IntervalStream, right: IntervalStream): IntervalStream;
31
+ /**
32
+ * The times either stream covers, coalesced.
33
+ *
34
+ * Touching intervals are merged as well as overlapping ones, so the output
35
+ * satisfies the stream contract rather than merely being correct as a set.
36
+ */
37
+ export declare function union(left: IntervalStream, right: IntervalStream): IntervalStream;
38
+ /**
39
+ * The times a stream does not cover — the gaps, plus the unbounded stretches
40
+ * before the first interval and after the last.
41
+ *
42
+ * On an infinite source the trailing stretch is never reached, which is correct:
43
+ * there is no "after the last" when there is no last.
44
+ */
45
+ export declare function complement(source: IntervalStream): IntervalStream;
46
+ /**
47
+ * A stream limited to a window.
48
+ *
49
+ * This is what makes a composition over infinite sources terminate: bounded
50
+ * inputs run out, so the sweep above them runs out too. It relies on the
51
+ * sorted-by-start contract to stop early rather than draining its source.
52
+ */
53
+ export declare function clip(source: IntervalStream, window: Interval): IntervalStream;
54
+ //# sourceMappingURL=interval-stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interval-stream.d.ts","sourceRoot":"","sources":["../src/interval-stream.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAIL,KAAK,QAAQ,EAMd,MAAM,eAAe,CAAC;AAGvB;;;;;;;GAOG;AACH,MAAM,MAAM,cAAc,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAEhD;;;;;;;GAOG;AACH,wBAAiB,SAAS,CACxB,IAAI,EAAE,cAAc,EACpB,KAAK,EAAE,cAAc,GACpB,cAAc,CAwBhB;AAED;;;;;GAKG;AACH,wBAAiB,KAAK,CACpB,IAAI,EAAE,cAAc,EACpB,KAAK,EAAE,cAAc,GACpB,cAAc,CAgChB;AA8BD;;;;;;GAMG;AACH,wBAAiB,UAAU,CAAC,MAAM,EAAE,cAAc,GAAG,cAAc,CAyClE;AAED;;;;;;GAMG;AACH,wBAAgB,IAAI,CAAC,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,QAAQ,GAAG,cAAc,CAM7E"}
@@ -0,0 +1,162 @@
1
+ /**
2
+ * The interval algebra: intersection, union and complement over lazy streams.
3
+ *
4
+ * Streams are `Iterable`, and may be infinite — a weekly recurrence genuinely
5
+ * has no end, and modelling it as though it did would put callers back to
6
+ * guessing a window large enough to hold an answer they cannot predict.
7
+ *
8
+ * Every operation here is a sweep: it pulls from its sources only as far as it
9
+ * needs to produce the next result, so `take(3)` from an infinite intersection
10
+ * pulls a handful of intervals rather than expanding a year.
11
+ */
12
+ import { compareEnds, compareStarts, earlierEnd, isEmpty, laterEnd, laterStart, startsAtOrBeforeEnd, startsBeforeEnd, } from "./interval.js";
13
+ import { peekable } from "./stream.js";
14
+ /**
15
+ * The times both streams cover.
16
+ *
17
+ * Terminates when either source does. Note that it will *not* terminate on two
18
+ * infinite sources that never overlap — there is nothing it could inspect to
19
+ * discover that the answer is empty. See the note on unbounded queries in the
20
+ * documentation; that case is the caller's to bound.
21
+ */
22
+ export function* intersect(left, right) {
23
+ const a = peekable(left);
24
+ const b = peekable(right);
25
+ for (;;) {
26
+ const x = a.peek();
27
+ const y = b.peek();
28
+ if (x === undefined || y === undefined) {
29
+ return;
30
+ }
31
+ const start = laterStart(x.start, y.start);
32
+ const end = earlierEnd(x.end, y.end);
33
+ if (startsBeforeEnd(start, end)) {
34
+ yield { start, end };
35
+ }
36
+ // Drop whichever ends first: the other may still overlap what follows it.
37
+ if (compareEnds(x.end, y.end) <= 0) {
38
+ a.drop();
39
+ }
40
+ else {
41
+ b.drop();
42
+ }
43
+ }
44
+ }
45
+ /**
46
+ * The times either stream covers, coalesced.
47
+ *
48
+ * Touching intervals are merged as well as overlapping ones, so the output
49
+ * satisfies the stream contract rather than merely being correct as a set.
50
+ */
51
+ export function* union(left, right) {
52
+ const a = peekable(left);
53
+ const b = peekable(right);
54
+ let open;
55
+ for (;;) {
56
+ const next = takeEarlier(a, b);
57
+ if (next === undefined) {
58
+ break;
59
+ }
60
+ if (open === undefined) {
61
+ open = next;
62
+ }
63
+ else if (startsAtOrBeforeEnd(next.start, open.end)) {
64
+ open = { start: open.start, end: laterEnd(open.end, next.end) };
65
+ }
66
+ else {
67
+ yield open;
68
+ open = next;
69
+ }
70
+ // Nothing can extend an interval that already runs to the unbounded
71
+ // future, so there is no reason to keep pulling — and every reason not to,
72
+ // since either source may be infinite and this would never yield at all.
73
+ if (open.end === undefined) {
74
+ yield open;
75
+ return;
76
+ }
77
+ }
78
+ if (open !== undefined) {
79
+ yield open;
80
+ }
81
+ }
82
+ /** Consume whichever stream's next interval starts earlier. */
83
+ function takeEarlier(a, b) {
84
+ const x = a.peek();
85
+ const y = b.peek();
86
+ if (x === undefined) {
87
+ if (y === undefined) {
88
+ return undefined;
89
+ }
90
+ b.drop();
91
+ return y;
92
+ }
93
+ if (y === undefined) {
94
+ a.drop();
95
+ return x;
96
+ }
97
+ if (compareStarts(x.start, y.start) <= 0) {
98
+ a.drop();
99
+ return x;
100
+ }
101
+ b.drop();
102
+ return y;
103
+ }
104
+ /**
105
+ * The times a stream does not cover — the gaps, plus the unbounded stretches
106
+ * before the first interval and after the last.
107
+ *
108
+ * On an infinite source the trailing stretch is never reached, which is correct:
109
+ * there is no "after the last" when there is no last.
110
+ */
111
+ export function* complement(source) {
112
+ /** Where the next gap begins: the end of the interval last seen. */
113
+ let cursor;
114
+ let seenAny = false;
115
+ for (const interval of source) {
116
+ // A zero-length interval covers nothing, so it neither opens a gap nor
117
+ // closes one. Letting it through would split the surrounding gap into two
118
+ // touching halves, and a stream of touching intervals is one this module's
119
+ // own sweeps would then read wrongly.
120
+ if (isEmpty(interval)) {
121
+ continue;
122
+ }
123
+ if (!seenAny) {
124
+ seenAny = true;
125
+ // The stretch before the first interval — unless the source itself begins
126
+ // at the unbounded past, in which case there is nothing before it. An
127
+ // absent `start` and an absent `end` mean opposite things, so this case
128
+ // has to be handled rather than falling out of a comparison.
129
+ if (interval.start !== undefined) {
130
+ yield { start: undefined, end: interval.start };
131
+ }
132
+ }
133
+ else if (cursor !== undefined &&
134
+ interval.start !== undefined &&
135
+ Temporal.ZonedDateTime.compare(cursor, interval.start) < 0) {
136
+ yield { start: cursor, end: interval.start };
137
+ }
138
+ if (interval.end === undefined) {
139
+ // The source runs to the unbounded future; nothing can follow it.
140
+ return;
141
+ }
142
+ cursor = interval.end;
143
+ }
144
+ // An exhausted source leaves everything after it uncovered. An empty one
145
+ // leaves everything uncovered, which is the same statement with no cursor.
146
+ yield { start: seenAny ? cursor : undefined, end: undefined };
147
+ }
148
+ /**
149
+ * A stream limited to a window.
150
+ *
151
+ * This is what makes a composition over infinite sources terminate: bounded
152
+ * inputs run out, so the sweep above them runs out too. It relies on the
153
+ * sorted-by-start contract to stop early rather than draining its source.
154
+ */
155
+ export function clip(source, window) {
156
+ // Intersection with a single-interval stream, which is what clipping is. The
157
+ // early stop falls out of it: once the window is consumed the sweep has
158
+ // nothing left to intersect against and returns, so an infinite source is
159
+ // never drained.
160
+ return intersect(source, [window]);
161
+ }
162
+ //# sourceMappingURL=interval-stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interval-stream.js","sourceRoot":"","sources":["../src/interval-stream.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EACL,WAAW,EACX,aAAa,EACb,UAAU,EAEV,OA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AAK,SAAS,EAAE,CAAC;YAC/B,kEAAkE;YAClE,OAAO;QACT,CAAC;QACD,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAC;IACxB,CAAC;IAED,yEAAyE;IACzE,2EAA2E;IAC3E,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC;AAChE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,IAAI,CAAC,MAAsB,EAAE,MAAgB;IAC3D,6EAA6E;IAC7E,wEAAwE;IACxE,0EAA0E;IAC1E,iBAAiB;IACjB,OAAO,SAAS,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;AACrC,CAAC"}
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Intervals, and the comparisons the interval algebra is built from.
3
+ *
4
+ * An interval is half open: it includes its start and excludes its end. That is
5
+ * the only choice that makes boundaries unambiguous — under a closed interval a
6
+ * day ending at 17:00 and one beginning at 17:00 both contain that instant, and
7
+ * every boundary query has to pick a side.
8
+ */
9
+ /**
10
+ * A span of time, half open: `[start, end)`.
11
+ *
12
+ * Either end may be `undefined`, which means unbounded. Position says which
13
+ * direction: an absent `start` is the unbounded past, an absent `end` the
14
+ * unbounded future. Both are real — "closed indefinitely from 2030" has no end,
15
+ * and the complement of any rule has no beginning.
16
+ */
17
+ export interface Interval {
18
+ readonly start: Temporal.ZonedDateTime | undefined;
19
+ readonly end: Temporal.ZonedDateTime | undefined;
20
+ }
21
+ /**
22
+ * Compare two interval starts, where `undefined` is the unbounded past and so
23
+ * sorts before everything.
24
+ */
25
+ export declare function compareStarts(a: Temporal.ZonedDateTime | undefined, b: Temporal.ZonedDateTime | undefined): number;
26
+ /**
27
+ * Compare two interval ends, where `undefined` is the unbounded future and so
28
+ * sorts after everything.
29
+ *
30
+ * Separate from {@link compareStarts} because `undefined` means the opposite
31
+ * thing in the two positions, and a single comparison that took both would need
32
+ * telling which it was looking at anyway.
33
+ */
34
+ export declare function compareEnds(a: Temporal.ZonedDateTime | undefined, b: Temporal.ZonedDateTime | undefined): number;
35
+ /** The earlier of two starts. */
36
+ export declare function earlierStart(a: Temporal.ZonedDateTime | undefined, b: Temporal.ZonedDateTime | undefined): Temporal.ZonedDateTime | undefined;
37
+ /** The later of two starts. */
38
+ export declare function laterStart(a: Temporal.ZonedDateTime | undefined, b: Temporal.ZonedDateTime | undefined): Temporal.ZonedDateTime | undefined;
39
+ /** The earlier of two ends. */
40
+ export declare function earlierEnd(a: Temporal.ZonedDateTime | undefined, b: Temporal.ZonedDateTime | undefined): Temporal.ZonedDateTime | undefined;
41
+ /** The later of two ends. */
42
+ export declare function laterEnd(a: Temporal.ZonedDateTime | undefined, b: Temporal.ZonedDateTime | undefined): Temporal.ZonedDateTime | undefined;
43
+ /**
44
+ * Whether a start falls strictly before an end, which is what makes an interval
45
+ * non-empty. Either being unbounded settles it: nothing precedes the unbounded
46
+ * past and nothing follows the unbounded future.
47
+ */
48
+ export declare function startsBeforeEnd(start: Temporal.ZonedDateTime | undefined, end: Temporal.ZonedDateTime | undefined): boolean;
49
+ /**
50
+ * Whether a start falls at or before an end.
51
+ *
52
+ * The difference from {@link startsBeforeEnd} is what separates *touching* from
53
+ * *overlapping*, which is the test a union needs: `[09:00,12:00)` and
54
+ * `[12:00,17:00)` do not overlap, but they should still coalesce into one.
55
+ */
56
+ export declare function startsAtOrBeforeEnd(start: Temporal.ZonedDateTime | undefined, end: Temporal.ZonedDateTime | undefined): boolean;
57
+ /** Whether an interval contains no time at all. */
58
+ export declare function isEmpty(interval: Interval): boolean;
59
+ /**
60
+ * Whether an instant falls inside an interval. Half open, so an instant exactly
61
+ * at `end` is outside.
62
+ */
63
+ export declare function contains(interval: Interval, at: Temporal.ZonedDateTime): boolean;
64
+ /**
65
+ * How long an interval lasts in exact time, or `undefined` if it is unbounded
66
+ * and so has no finite length.
67
+ *
68
+ * Exact rather than wall clock: this is elapsed time, and across a daylight
69
+ * saving transition the two disagree. A `ZonedDateTime` knows its own offset,
70
+ * so `until` measures the real elapsed duration — 09:00 to 17:00 is eight hours
71
+ * on a transition day only because the transition falls outside it.
72
+ */
73
+ export declare function duration(interval: Interval): Temporal.Duration | undefined;
74
+ //# sourceMappingURL=interval.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interval.d.ts","sourceRoot":"","sources":["../src/interval.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;;;GAOG;AACH,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,aAAa,GAAG,SAAS,CAAC;IACnD,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,aAAa,GAAG,SAAS,CAAC;CAClD;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,CAAC,EAAE,QAAQ,CAAC,aAAa,GAAG,SAAS,EACrC,CAAC,EAAE,QAAQ,CAAC,aAAa,GAAG,SAAS,GACpC,MAAM,CAQR;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CACzB,CAAC,EAAE,QAAQ,CAAC,aAAa,GAAG,SAAS,EACrC,CAAC,EAAE,QAAQ,CAAC,aAAa,GAAG,SAAS,GACpC,MAAM,CAQR;AAED,iCAAiC;AACjC,wBAAgB,YAAY,CAC1B,CAAC,EAAE,QAAQ,CAAC,aAAa,GAAG,SAAS,EACrC,CAAC,EAAE,QAAQ,CAAC,aAAa,GAAG,SAAS,GACpC,QAAQ,CAAC,aAAa,GAAG,SAAS,CAEpC;AAED,+BAA+B;AAC/B,wBAAgB,UAAU,CACxB,CAAC,EAAE,QAAQ,CAAC,aAAa,GAAG,SAAS,EACrC,CAAC,EAAE,QAAQ,CAAC,aAAa,GAAG,SAAS,GACpC,QAAQ,CAAC,aAAa,GAAG,SAAS,CAEpC;AAED,+BAA+B;AAC/B,wBAAgB,UAAU,CACxB,CAAC,EAAE,QAAQ,CAAC,aAAa,GAAG,SAAS,EACrC,CAAC,EAAE,QAAQ,CAAC,aAAa,GAAG,SAAS,GACpC,QAAQ,CAAC,aAAa,GAAG,SAAS,CAEpC;AAED,6BAA6B;AAC7B,wBAAgB,QAAQ,CACtB,CAAC,EAAE,QAAQ,CAAC,aAAa,GAAG,SAAS,EACrC,CAAC,EAAE,QAAQ,CAAC,aAAa,GAAG,SAAS,GACpC,QAAQ,CAAC,aAAa,GAAG,SAAS,CAEpC;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,QAAQ,CAAC,aAAa,GAAG,SAAS,EACzC,GAAG,EAAE,QAAQ,CAAC,aAAa,GAAG,SAAS,GACtC,OAAO,CAKT;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,QAAQ,CAAC,aAAa,GAAG,SAAS,EACzC,GAAG,EAAE,QAAQ,CAAC,aAAa,GAAG,SAAS,GACtC,OAAO,CAKT;AAED,mDAAmD;AACnD,wBAAgB,OAAO,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAEnD;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,QAAQ,EAClB,EAAE,EAAE,QAAQ,CAAC,aAAa,GACzB,OAAO,CAIT;AAED;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,GAAG,QAAQ,CAAC,QAAQ,GAAG,SAAS,CAM1E"}
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Intervals, and the comparisons the interval algebra is built from.
3
+ *
4
+ * An interval is half open: it includes its start and excludes its end. That is
5
+ * the only choice that makes boundaries unambiguous — under a closed interval a
6
+ * day ending at 17:00 and one beginning at 17:00 both contain that instant, and
7
+ * every boundary query has to pick a side.
8
+ */
9
+ /**
10
+ * Compare two interval starts, where `undefined` is the unbounded past and so
11
+ * sorts before everything.
12
+ */
13
+ export function compareStarts(a, b) {
14
+ if (a === undefined) {
15
+ return b === undefined ? 0 : -1;
16
+ }
17
+ if (b === undefined) {
18
+ return 1;
19
+ }
20
+ return Temporal.ZonedDateTime.compare(a, b);
21
+ }
22
+ /**
23
+ * Compare two interval ends, where `undefined` is the unbounded future and so
24
+ * sorts after everything.
25
+ *
26
+ * Separate from {@link compareStarts} because `undefined` means the opposite
27
+ * thing in the two positions, and a single comparison that took both would need
28
+ * telling which it was looking at anyway.
29
+ */
30
+ export function compareEnds(a, b) {
31
+ if (a === undefined) {
32
+ return b === undefined ? 0 : 1;
33
+ }
34
+ if (b === undefined) {
35
+ return -1;
36
+ }
37
+ return Temporal.ZonedDateTime.compare(a, b);
38
+ }
39
+ /** The earlier of two starts. */
40
+ export function earlierStart(a, b) {
41
+ return compareStarts(a, b) <= 0 ? a : b;
42
+ }
43
+ /** The later of two starts. */
44
+ export function laterStart(a, b) {
45
+ return compareStarts(a, b) >= 0 ? a : b;
46
+ }
47
+ /** The earlier of two ends. */
48
+ export function earlierEnd(a, b) {
49
+ return compareEnds(a, b) <= 0 ? a : b;
50
+ }
51
+ /** The later of two ends. */
52
+ export function laterEnd(a, b) {
53
+ return compareEnds(a, b) >= 0 ? a : b;
54
+ }
55
+ /**
56
+ * Whether a start falls strictly before an end, which is what makes an interval
57
+ * non-empty. Either being unbounded settles it: nothing precedes the unbounded
58
+ * past and nothing follows the unbounded future.
59
+ */
60
+ export function startsBeforeEnd(start, end) {
61
+ if (start === undefined || end === undefined) {
62
+ return true;
63
+ }
64
+ return Temporal.ZonedDateTime.compare(start, end) < 0;
65
+ }
66
+ /**
67
+ * Whether a start falls at or before an end.
68
+ *
69
+ * The difference from {@link startsBeforeEnd} is what separates *touching* from
70
+ * *overlapping*, which is the test a union needs: `[09:00,12:00)` and
71
+ * `[12:00,17:00)` do not overlap, but they should still coalesce into one.
72
+ */
73
+ export function startsAtOrBeforeEnd(start, end) {
74
+ if (start === undefined || end === undefined) {
75
+ return true;
76
+ }
77
+ return Temporal.ZonedDateTime.compare(start, end) <= 0;
78
+ }
79
+ /** Whether an interval contains no time at all. */
80
+ export function isEmpty(interval) {
81
+ return !startsBeforeEnd(interval.start, interval.end);
82
+ }
83
+ /**
84
+ * Whether an instant falls inside an interval. Half open, so an instant exactly
85
+ * at `end` is outside.
86
+ */
87
+ export function contains(interval, at) {
88
+ return (compareStarts(interval.start, at) <= 0 && compareEnds(at, interval.end) < 0);
89
+ }
90
+ /**
91
+ * How long an interval lasts in exact time, or `undefined` if it is unbounded
92
+ * and so has no finite length.
93
+ *
94
+ * Exact rather than wall clock: this is elapsed time, and across a daylight
95
+ * saving transition the two disagree. A `ZonedDateTime` knows its own offset,
96
+ * so `until` measures the real elapsed duration — 09:00 to 17:00 is eight hours
97
+ * on a transition day only because the transition falls outside it.
98
+ */
99
+ export function duration(interval) {
100
+ const { start, end } = interval;
101
+ if (start === undefined || end === undefined) {
102
+ return undefined;
103
+ }
104
+ return start.until(end, { largestUnit: "hour" });
105
+ }
106
+ //# sourceMappingURL=interval.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interval.js","sourceRoot":"","sources":["../src/interval.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAeH;;;GAGG;AACH,MAAM,UAAU,aAAa,CAC3B,CAAqC,EACrC,CAAqC;IAErC,IAAI,CAAC,KAAK,SAAS,EAAE,CAAC;QACpB,OAAO,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAClC,CAAC;IACD,IAAI,CAAC,KAAK,SAAS,EAAE,CAAC;QACpB,OAAO,CAAC,CAAC;IACX,CAAC;IACD,OAAO,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC9C,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CACzB,CAAqC,EACrC,CAAqC;IAErC,IAAI,CAAC,KAAK,SAAS,EAAE,CAAC;QACpB,OAAO,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,C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AAC;AACxD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CACjC,KAAyC,EACzC,GAAuC;IAEvC,IAAI,KAAK,KAAK,SAAS,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QAC7C,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;AACzD,CAAC;AAED,mDAAmD;AACnD,MAAM,UAAU,OAAO,CAAC,QAAkB;IACxC,OAAO,CAAC,eAAe,CAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC;AACxD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,QAAQ,CACtB,QAAkB,EAClB,EAA0B;IAE1B,OAAO,CACL,aAAa,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,WAAW,CAAC,EAAE,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAC5E,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,QAAQ,CAAC,QAAkB;IACzC,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,QAAQ,CAAC;IAChC,IAAI,KAAK,KAAK,SAAS,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QAC7C,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAAC;AACnD,CAAC"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Generic helpers for lazy sequences. Nothing here knows about intervals.
3
+ *
4
+ * They live apart from the interval algebra because they are not about time at
5
+ * all: one is a way to look at the front of a sequence without consuming it,
6
+ * the other a way to stop consuming one. Both read the same for any element
7
+ * type, and the sweeps next door need exactly one item of lookahead — a sweep
8
+ * that needed more would not be a sweep.
9
+ */
10
+ /**
11
+ * `T` excludes `null` and `undefined` deliberately: `peek` uses `undefined` to
12
+ * mean exhausted, so a sequence that could yield `undefined` as a value would
13
+ * be indistinguishable from one that had ended.
14
+ */
15
+ export interface Peekable<T extends NonNullable<unknown>> {
16
+ /** The next item without consuming it, or `undefined` once exhausted. */
17
+ readonly peek: () => T | undefined;
18
+ /** Consume the item last peeked, so the next `peek` moves on. */
19
+ readonly drop: () => void;
20
+ }
21
+ export declare function peekable<T extends NonNullable<unknown>>(source: Iterable<T>): Peekable<T>;
22
+ /**
23
+ * The first `count` items of a sequence, as an array.
24
+ *
25
+ * The point of it is the stopping: the source may be infinite, and this pulls
26
+ * exactly as far as it needs and no further.
27
+ */
28
+ export declare function take<T>(source: Iterable<T>, count: number): T[];
29
+ //# sourceMappingURL=stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;GAIG;AACH,MAAM,WAAW,QAAQ,CAAC,CAAC,SAAS,WAAW,CAAC,OAAO,CAAC;IACtD,yEAAyE;IACzE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;IACnC,iEAAiE;IACjE,QAAQ,CAAC,IAAI,EAAE,MAAM,IAAI,CAAC;CAC3B;AAED,wBAAgB,QAAQ,CAAC,CAAC,SAAS,WAAW,CAAC,OAAO,CAAC,EACrD,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,GAClB,QAAQ,CAAC,CAAC,CAAC,CAuBb;AAED;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,EAAE,CAoB/D"}
package/dist/stream.js ADDED
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Generic helpers for lazy sequences. Nothing here knows about intervals.
3
+ *
4
+ * They live apart from the interval algebra because they are not about time at
5
+ * all: one is a way to look at the front of a sequence without consuming it,
6
+ * the other a way to stop consuming one. Both read the same for any element
7
+ * type, and the sweeps next door need exactly one item of lookahead — a sweep
8
+ * that needed more would not be a sweep.
9
+ */
10
+ export function peekable(source) {
11
+ const iterator = source[Symbol.iterator]();
12
+ let buffered;
13
+ let buffering = false;
14
+ let exhausted = false;
15
+ return {
16
+ peek() {
17
+ if (!buffering && !exhausted) {
18
+ const step = iterator.next();
19
+ if (step.done === true) {
20
+ exhausted = true;
21
+ }
22
+ else {
23
+ buffered = step.value;
24
+ buffering = true;
25
+ }
26
+ }
27
+ return buffering ? buffered : undefined;
28
+ },
29
+ drop() {
30
+ buffering = false;
31
+ },
32
+ };
33
+ }
34
+ /**
35
+ * The first `count` items of a sequence, as an array.
36
+ *
37
+ * The point of it is the stopping: the source may be infinite, and this pulls
38
+ * exactly as far as it needs and no further.
39
+ */
40
+ export function take(source, count) {
41
+ // Rejected before anything is pulled. `NaN` and `Infinity` both fail every
42
+ // comparison that would end the loop, so on an infinite sequence either one
43
+ // hangs rather than returning something wrong — which is worse, and worth an
44
+ // error rather than a silent guess at what was meant.
45
+ if (!Number.isInteger(count)) {
46
+ throw new RangeError(`take() needs a whole number of items, not ${count}.`);
47
+ }
48
+ const taken = [];
49
+ if (count <= 0) {
50
+ return taken;
51
+ }
52
+ for (const item of source) {
53
+ taken.push(item);
54
+ if (taken.length >= count) {
55
+ break;
56
+ }
57
+ }
58
+ return taken;
59
+ }
60
+ //# sourceMappingURL=stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.js","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAcH,MAAM,UAAU,QAAQ,CACtB,MAAmB;IAEnB,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;IAC3C,IAAI,QAAuB,CAAC;IAC5B,IAAI,SAAS,GAAG,KAAK,CAAC;IAC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description": "Declarative temporal rules for schedules, deadlines, constraints, and exceptions",
5
+ "repository": "https://github.com/KensioSoftware/quando",
6
+ "homepage": "https://quandojs.dev",
7
+ "bugs": "https://github.com/KensioSoftware/quando/issues",
8
+ "main": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js"
14
+ },
15
+ "./package.json": "./package.json"
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "README.md",
20
+ "LICENSE"
21
+ ],
22
+ "sideEffects": false,
23
+ "imports": {
24
+ "#test/*": "./test/*"
25
+ },
26
+ "packageManager": "pnpm@11.21.0+sha512.521705bce689924eac72f5a3587122f362689ef6571e55ba80076fd637c11132ecffada26fad4ea79c485bfddbfd3d5a2a5b05805a77e893de71ec8a6cca3bb1",
27
+ "engines": {
28
+ "node": ">=26.0.0"
29
+ },
30
+ "scripts": {
31
+ "build": "rm -rf dist && tsc -p tsconfig.build.json",
32
+ "prepack": "pnpm build",
33
+ "build:check": "tsc -p tsconfig.json --noEmit",
34
+ "fmt": "oxlint --fix . && oxfmt .",
35
+ "lint": "oxlint . && oxfmt --check .",
36
+ "lint:ci": "oxlint --format=github . && oxfmt --check .",
37
+ "docs:check": "./scripts/sh/docs-check.sh",
38
+ "fta": "./scripts/sh/fta.sh",
39
+ "test": "vitest run",
40
+ "test:coverage": "vitest run --coverage",
41
+ "pack:check": "./scripts/sh/pack-check.sh",
42
+ "check": "pnpm fmt && pnpm docs:check && pnpm fta && pnpm build:check && pnpm pack:check && pnpm test:coverage"
43
+ },
44
+ "devDependencies": {
45
+ "@kensio/smartass": "^1.33.0",
46
+ "@semantic-release/exec": "7.1.0",
47
+ "@types/node": "^26.0.0",
48
+ "@typescript/native": "npm:typescript@^7.0.2",
49
+ "@vitest/coverage-v8": "^4.1.10",
50
+ "conventional-changelog-conventionalcommits": "9.3.1",
51
+ "fta-cli": "^3.0.0",
52
+ "oxfmt": "^0.62.0",
53
+ "oxlint": "^1.77.0",
54
+ "oxlint-tsgolint": "^7.0.2001",
55
+ "semantic-release": "25.0.9",
56
+ "typescript": "npm:@typescript/typescript6@^6.0.2",
57
+ "vitest": "^4.1.10"
58
+ },
59
+ "keywords": [
60
+ "time",
61
+ "schedule",
62
+ "deadline",
63
+ "constraint"
64
+ ],
65
+ "publishConfig": {
66
+ "access": "public"
67
+ },
68
+ "author": "Kensio Software",
69
+ "license": "Apache-2.0",
70
+ "type": "module"
71
+ }