rrule-rust 1.1.4 → 1.2.0-next.1
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/.releaserc +47 -0
- package/index.d.ts +3 -0
- package/package.json +25 -20
- package/src/lib.rs +92 -41
package/.releaserc
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"plugins": [
|
|
3
|
+
[
|
|
4
|
+
"@semantic-release/commit-analyzer",
|
|
5
|
+
{
|
|
6
|
+
"preset": "angular",
|
|
7
|
+
"releaseRules": [
|
|
8
|
+
{ "type": "docs", "release": "patch" },
|
|
9
|
+
{ "type": "perf", "release": "patch" },
|
|
10
|
+
{ "type": "revert", "release": "patch" }
|
|
11
|
+
]
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
[
|
|
15
|
+
"@semantic-release/release-notes-generator",
|
|
16
|
+
{
|
|
17
|
+
"parserOpts": {
|
|
18
|
+
"noteKeywords": ["BREAKING CHANGE", "BREAKING CHANGES", "BREAKING"]
|
|
19
|
+
},
|
|
20
|
+
"preset": "conventionalcommits",
|
|
21
|
+
"presetConfig": {
|
|
22
|
+
"types": [
|
|
23
|
+
{ "type": "build", "section": "Build System", "hidden": false },
|
|
24
|
+
{ "type": "chore", "section": "Build System", "hidden": false },
|
|
25
|
+
{ "type": "chore", "scope": "merge", "section": "Build System", "hidden": true },
|
|
26
|
+
{ "type": "ci", "section": "Continuous Integration", "hidden": false },
|
|
27
|
+
{ "type": "docs", "section": "Documentation", "hidden": false },
|
|
28
|
+
{ "type": "feat", "section": "Features", "hidden": false },
|
|
29
|
+
{ "type": "fix", "section": "Bug Fixes", "hidden": false },
|
|
30
|
+
{ "type": "perf", "section": "Performance Improvements", "hidden": false },
|
|
31
|
+
{ "type": "refactor", "section": "Code Refactoring", "hidden": false },
|
|
32
|
+
{ "type": "revert", "section": "Reverted Changes", "hidden": false },
|
|
33
|
+
{ "type": "style", "section": "Styles", "hidden": false },
|
|
34
|
+
{ "type": "test", "section": "Tests", "hidden": false }
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
"writerOpts": {
|
|
38
|
+
"commitsSort": ["subject", "scope"]
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
"@semantic-release/github",
|
|
43
|
+
"@semantic-release/npm",
|
|
44
|
+
"@semantic-release/git"
|
|
45
|
+
],
|
|
46
|
+
"branches": ["+([0-9])?(.{+([0-9]),x}).x", "master", {"name": "next", "prerelease": true}]
|
|
47
|
+
}
|
package/index.d.ts
CHANGED
|
@@ -77,6 +77,9 @@ export class RRuleSet {
|
|
|
77
77
|
addExdate(timestamp: number): this
|
|
78
78
|
get dtstart(): number
|
|
79
79
|
get tzid(): string
|
|
80
|
+
getRrules(): Array<RRule>
|
|
81
|
+
getExrules(): Array<RRule>
|
|
82
|
+
getExdates(): Array<number>
|
|
80
83
|
all(limit?: number | undefined | null): number[]
|
|
81
84
|
between(after: number, before: number, inclusive?: boolean | undefined | null): number[]
|
|
82
85
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rrule-rust",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.0-next.1",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
6
|
"keywords": [
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"license": "MIT",
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@napi-rs/cli": "^2.15.1",
|
|
43
|
+
"@semantic-release/git": "^10.0.1",
|
|
43
44
|
"@types/jest": "^29.5.0",
|
|
44
45
|
"@types/node": "^18.15.5",
|
|
45
46
|
"@typescript-eslint/eslint-plugin": "^5.50.0",
|
|
@@ -55,16 +56,17 @@
|
|
|
55
56
|
"pre-commit": "^1.2.2",
|
|
56
57
|
"prettier": "^2.8.3",
|
|
57
58
|
"rrule": "^2.7.2",
|
|
59
|
+
"semantic-release": "^22.0.12",
|
|
58
60
|
"ts-jest": "^29.0.5",
|
|
59
61
|
"ts-node": "^10.9.1",
|
|
60
62
|
"typescript": "^4.9.4"
|
|
61
63
|
},
|
|
62
64
|
"pre-commit": [
|
|
63
|
-
"lint:fix-staged"
|
|
64
|
-
"test"
|
|
65
|
+
"lint:fix-staged"
|
|
65
66
|
],
|
|
66
67
|
"lint-staged": {
|
|
67
|
-
"**/*.{js,ts,json}": "eslint --fix --max-warnings=0"
|
|
68
|
+
"**/*.{js,ts,json}": "eslint --fix --max-warnings=0",
|
|
69
|
+
"**/*.rs": "rustfmt"
|
|
68
70
|
},
|
|
69
71
|
"engines": {
|
|
70
72
|
"node": ">= 10"
|
|
@@ -78,24 +80,27 @@
|
|
|
78
80
|
"universal": "napi universal",
|
|
79
81
|
"version": "napi version",
|
|
80
82
|
"benchmark": "ts-node ./benchmark/index.ts",
|
|
81
|
-
"lint": "eslint \"**/*.{js,ts,json}\" --max-warnings=0",
|
|
82
|
-
"lint:fix": "yarn lint --fix",
|
|
83
|
+
"lint": "cargo fmt --all -- --check && eslint \"**/*.{js,ts,json}\" --max-warnings=0",
|
|
84
|
+
"lint:fix": "cargo fmt --all && yarn lint --fix",
|
|
83
85
|
"lint:fix-staged": "lint-staged"
|
|
84
86
|
},
|
|
87
|
+
"dependencies": {
|
|
88
|
+
"conventional-changelog-conventionalcommits": "^7.0.2"
|
|
89
|
+
},
|
|
85
90
|
"optionalDependencies": {
|
|
86
|
-
"@rrule-rust/lib-win32-x64-msvc": "1.1
|
|
87
|
-
"@rrule-rust/lib-darwin-x64": "1.1
|
|
88
|
-
"@rrule-rust/lib-linux-x64-gnu": "1.1
|
|
89
|
-
"@rrule-rust/lib-darwin-arm64": "1.1
|
|
90
|
-
"@rrule-rust/lib-android-arm64": "1.1
|
|
91
|
-
"@rrule-rust/lib-linux-arm64-gnu": "1.1
|
|
92
|
-
"@rrule-rust/lib-linux-arm64-musl": "1.1
|
|
93
|
-
"@rrule-rust/lib-win32-arm64-msvc": "1.1
|
|
94
|
-
"@rrule-rust/lib-linux-arm-gnueabihf": "1.1
|
|
95
|
-
"@rrule-rust/lib-linux-x64-musl": "1.1
|
|
96
|
-
"@rrule-rust/lib-freebsd-x64": "1.1
|
|
97
|
-
"@rrule-rust/lib-win32-ia32-msvc": "1.1
|
|
98
|
-
"@rrule-rust/lib-android-arm-eabi": "1.1
|
|
99
|
-
"@rrule-rust/lib-darwin-universal": "1.1
|
|
91
|
+
"@rrule-rust/lib-win32-x64-msvc": "1.2.0-next.1",
|
|
92
|
+
"@rrule-rust/lib-darwin-x64": "1.2.0-next.1",
|
|
93
|
+
"@rrule-rust/lib-linux-x64-gnu": "1.2.0-next.1",
|
|
94
|
+
"@rrule-rust/lib-darwin-arm64": "1.2.0-next.1",
|
|
95
|
+
"@rrule-rust/lib-android-arm64": "1.2.0-next.1",
|
|
96
|
+
"@rrule-rust/lib-linux-arm64-gnu": "1.2.0-next.1",
|
|
97
|
+
"@rrule-rust/lib-linux-arm64-musl": "1.2.0-next.1",
|
|
98
|
+
"@rrule-rust/lib-win32-arm64-msvc": "1.2.0-next.1",
|
|
99
|
+
"@rrule-rust/lib-linux-arm-gnueabihf": "1.2.0-next.1",
|
|
100
|
+
"@rrule-rust/lib-linux-x64-musl": "1.2.0-next.1",
|
|
101
|
+
"@rrule-rust/lib-freebsd-x64": "1.2.0-next.1",
|
|
102
|
+
"@rrule-rust/lib-win32-ia32-msvc": "1.2.0-next.1",
|
|
103
|
+
"@rrule-rust/lib-android-arm-eabi": "1.2.0-next.1",
|
|
104
|
+
"@rrule-rust/lib-darwin-universal": "1.2.0-next.1"
|
|
100
105
|
}
|
|
101
106
|
}
|
package/src/lib.rs
CHANGED
|
@@ -46,6 +46,36 @@ pub enum JsMonth {
|
|
|
46
46
|
December,
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
fn to_unvalidated(rrule: &RRule) -> RRule<Unvalidated> {
|
|
50
|
+
let by_month = rrule
|
|
51
|
+
.get_by_month()
|
|
52
|
+
.iter()
|
|
53
|
+
.map(|m| Month::try_from(*m).unwrap())
|
|
54
|
+
.collect::<Vec<_>>();
|
|
55
|
+
let mut unvalidated = RRule::new(rrule.get_freq())
|
|
56
|
+
.interval(rrule.get_interval())
|
|
57
|
+
.week_start(rrule.get_week_start())
|
|
58
|
+
.by_set_pos(rrule.get_by_set_pos().to_vec())
|
|
59
|
+
.by_month(&by_month)
|
|
60
|
+
.by_month_day(rrule.get_by_month_day().to_vec())
|
|
61
|
+
.by_year_day(rrule.get_by_year_day().to_vec())
|
|
62
|
+
.by_week_no(rrule.get_by_week_no().to_vec())
|
|
63
|
+
.by_weekday(rrule.get_by_weekday().to_vec())
|
|
64
|
+
.by_hour(rrule.get_by_hour().to_vec())
|
|
65
|
+
.by_minute(rrule.get_by_minute().to_vec())
|
|
66
|
+
.by_second(rrule.get_by_second().to_vec());
|
|
67
|
+
|
|
68
|
+
if let Some(count) = rrule.get_count() {
|
|
69
|
+
unvalidated = unvalidated.count(count);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if let Some(until) = rrule.get_until() {
|
|
73
|
+
unvalidated = unvalidated.until(*until);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
unvalidated
|
|
77
|
+
}
|
|
78
|
+
|
|
49
79
|
#[napi(js_name = "RRule")]
|
|
50
80
|
pub struct JsRRule {
|
|
51
81
|
rrule: RRule<Unvalidated>,
|
|
@@ -78,7 +108,7 @@ impl JsRRule {
|
|
|
78
108
|
#[napi(getter, ts_return_type = "Weekday[]")]
|
|
79
109
|
pub fn by_weekday(&self, env: Env) -> napi::Result<Array> {
|
|
80
110
|
let ndays = self.rrule.get_by_weekday();
|
|
81
|
-
let mut arr = env.create_array(0)
|
|
111
|
+
let mut arr = env.create_array(0)?;
|
|
82
112
|
|
|
83
113
|
for nday in ndays.iter() {
|
|
84
114
|
let day = match nday {
|
|
@@ -86,7 +116,7 @@ impl JsRRule {
|
|
|
86
116
|
_ => panic!("Unsupported"),
|
|
87
117
|
};
|
|
88
118
|
|
|
89
|
-
arr.insert(map_rust_weekday(day))
|
|
119
|
+
arr.insert(map_rust_weekday(day))?;
|
|
90
120
|
}
|
|
91
121
|
|
|
92
122
|
Ok(arr)
|
|
@@ -120,10 +150,10 @@ impl JsRRule {
|
|
|
120
150
|
#[napi(getter, ts_return_type = "Month[]")]
|
|
121
151
|
pub fn by_month(&self, env: Env) -> napi::Result<Array> {
|
|
122
152
|
let months = self.rrule.get_by_month();
|
|
123
|
-
let mut arr = env.create_array(0)
|
|
153
|
+
let mut arr = env.create_array(0)?;
|
|
124
154
|
|
|
125
155
|
for month in months.iter() {
|
|
126
|
-
arr.insert(map_rust_month(month))
|
|
156
|
+
arr.insert(map_rust_month(month))?;
|
|
127
157
|
}
|
|
128
158
|
|
|
129
159
|
Ok(arr)
|
|
@@ -296,8 +326,14 @@ impl JsRRule {
|
|
|
296
326
|
Ok(self)
|
|
297
327
|
}
|
|
298
328
|
|
|
299
|
-
pub fn validate(&self, dt_start: DateTime<Tz>) -> RRule {
|
|
300
|
-
|
|
329
|
+
pub fn validate(&self, dt_start: DateTime<Tz>) -> napi::Result<RRule> {
|
|
330
|
+
return Ok(
|
|
331
|
+
self
|
|
332
|
+
.rrule
|
|
333
|
+
.clone()
|
|
334
|
+
.validate(dt_start)
|
|
335
|
+
.map_err(|e| napi::Error::new(napi::Status::GenericFailure, e))?,
|
|
336
|
+
);
|
|
301
337
|
}
|
|
302
338
|
}
|
|
303
339
|
|
|
@@ -310,21 +346,23 @@ pub struct JsRRuleSet {
|
|
|
310
346
|
#[napi]
|
|
311
347
|
impl JsRRuleSet {
|
|
312
348
|
#[napi(constructor)]
|
|
313
|
-
pub fn new(dtstart: i64, tzid: String) -> Self {
|
|
314
|
-
let tz = map_js_tz(&tzid)
|
|
349
|
+
pub fn new(dtstart: i64, tzid: String) -> napi::Result<Self> {
|
|
350
|
+
let tz = map_js_tz(&tzid)?;
|
|
315
351
|
let date = timestamp_to_date_with_tz(dtstart, &tz);
|
|
316
352
|
let rrule_set = RRuleSet::new(date);
|
|
317
353
|
|
|
318
|
-
JsRRuleSet { rrule_set, tz }
|
|
354
|
+
Ok(JsRRuleSet { rrule_set, tz })
|
|
319
355
|
}
|
|
320
356
|
|
|
321
357
|
#[napi(factory, ts_return_type = "RRuleSet")]
|
|
322
|
-
pub fn parse(str: String) -> Self {
|
|
323
|
-
let rrule_set: RRuleSet = str
|
|
358
|
+
pub fn parse(str: String) -> napi::Result<Self> {
|
|
359
|
+
let rrule_set: RRuleSet = str
|
|
360
|
+
.parse()
|
|
361
|
+
.map_err(|e| napi::Error::new(napi::Status::GenericFailure, e))?;
|
|
324
362
|
let dtstart = rrule_set.get_dt_start();
|
|
325
363
|
let tz = dtstart.timezone();
|
|
326
364
|
|
|
327
|
-
JsRRuleSet { rrule_set, tz }
|
|
365
|
+
Ok(JsRRuleSet { rrule_set, tz })
|
|
328
366
|
}
|
|
329
367
|
|
|
330
368
|
#[napi]
|
|
@@ -335,7 +373,7 @@ impl JsRRuleSet {
|
|
|
335
373
|
#[napi]
|
|
336
374
|
pub fn add_rrule(&mut self, js_rrule: &JsRRule) -> napi::Result<&Self> {
|
|
337
375
|
let dt_start = self.rrule_set.get_dt_start().clone();
|
|
338
|
-
let rrule = js_rrule.validate(dt_start)
|
|
376
|
+
let rrule = js_rrule.validate(dt_start)?;
|
|
339
377
|
|
|
340
378
|
replace_with_or_abort(&mut self.rrule_set, |self_| self_.rrule(rrule));
|
|
341
379
|
|
|
@@ -344,7 +382,7 @@ impl JsRRuleSet {
|
|
|
344
382
|
|
|
345
383
|
#[napi]
|
|
346
384
|
pub fn add_exrule(&mut self, js_rrule: &JsRRule) -> napi::Result<&Self> {
|
|
347
|
-
let rrule = js_rrule.validate(*self.rrule_set.get_dt_start())
|
|
385
|
+
let rrule = js_rrule.validate(*self.rrule_set.get_dt_start())?;
|
|
348
386
|
|
|
349
387
|
replace_with_or_abort(&mut self.rrule_set, |self_| self_.exrule(rrule));
|
|
350
388
|
|
|
@@ -370,19 +408,39 @@ impl JsRRuleSet {
|
|
|
370
408
|
Ok(String::from(self.tz.name()))
|
|
371
409
|
}
|
|
372
410
|
|
|
373
|
-
|
|
374
|
-
pub fn get_rrules(&self
|
|
375
|
-
|
|
376
|
-
|
|
411
|
+
#[napi]
|
|
412
|
+
pub fn get_rrules(&self) -> Vec<JsRRule> {
|
|
413
|
+
return self
|
|
414
|
+
.rrule_set
|
|
415
|
+
.get_rrule()
|
|
416
|
+
.iter()
|
|
417
|
+
.map(|rrule| JsRRule {
|
|
418
|
+
rrule: to_unvalidated(rrule),
|
|
419
|
+
})
|
|
420
|
+
.collect();
|
|
421
|
+
}
|
|
377
422
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
423
|
+
#[napi]
|
|
424
|
+
pub fn get_exrules(&self) -> Vec<JsRRule> {
|
|
425
|
+
return self
|
|
426
|
+
.rrule_set
|
|
427
|
+
.get_exrule()
|
|
428
|
+
.iter()
|
|
429
|
+
.map(|rrule| JsRRule {
|
|
430
|
+
rrule: to_unvalidated(rrule),
|
|
431
|
+
})
|
|
432
|
+
.collect();
|
|
433
|
+
}
|
|
383
434
|
|
|
384
|
-
|
|
385
|
-
|
|
435
|
+
#[napi]
|
|
436
|
+
pub fn get_exdates(&self) -> Vec<i64> {
|
|
437
|
+
return self
|
|
438
|
+
.rrule_set
|
|
439
|
+
.get_exdate()
|
|
440
|
+
.iter()
|
|
441
|
+
.map(|date| date.timestamp_millis())
|
|
442
|
+
.collect();
|
|
443
|
+
}
|
|
386
444
|
|
|
387
445
|
fn is_after(&self, timestamp: i64, after_timestamp: i64, inclusive: Option<bool>) -> bool {
|
|
388
446
|
let inclusive = inclusive.unwrap_or(false);
|
|
@@ -410,7 +468,7 @@ impl JsRRuleSet {
|
|
|
410
468
|
|
|
411
469
|
#[napi(ts_return_type = "number[]")]
|
|
412
470
|
pub fn all(&self, env: Env, limit: Option<u32>) -> napi::Result<Array> {
|
|
413
|
-
let mut arr = env.create_array(0)
|
|
471
|
+
let mut arr = env.create_array(0)?;
|
|
414
472
|
let mut left = match limit {
|
|
415
473
|
Some(number) => number,
|
|
416
474
|
None => 0,
|
|
@@ -424,7 +482,7 @@ impl JsRRuleSet {
|
|
|
424
482
|
}
|
|
425
483
|
|
|
426
484
|
let timestamp = date.timestamp_millis();
|
|
427
|
-
arr.insert(timestamp)
|
|
485
|
+
arr.insert(timestamp)?;
|
|
428
486
|
}
|
|
429
487
|
|
|
430
488
|
Ok(arr)
|
|
@@ -438,7 +496,7 @@ impl JsRRuleSet {
|
|
|
438
496
|
before: i64,
|
|
439
497
|
inclusive: Option<bool>,
|
|
440
498
|
) -> napi::Result<Array> {
|
|
441
|
-
let mut arr = env.create_array(0)
|
|
499
|
+
let mut arr = env.create_array(0)?;
|
|
442
500
|
|
|
443
501
|
for date in self.rrule_set.into_iter() {
|
|
444
502
|
let timestamp = date.timestamp_millis();
|
|
@@ -446,7 +504,7 @@ impl JsRRuleSet {
|
|
|
446
504
|
let is_before = self.is_before(timestamp, before, inclusive);
|
|
447
505
|
|
|
448
506
|
if is_after && is_before {
|
|
449
|
-
arr.insert(timestamp)
|
|
507
|
+
arr.insert(timestamp)?;
|
|
450
508
|
} else if !is_before {
|
|
451
509
|
break;
|
|
452
510
|
}
|
|
@@ -480,15 +538,6 @@ fn map_js_frequency(freq: JsFrequency) -> Frequency {
|
|
|
480
538
|
}
|
|
481
539
|
}
|
|
482
540
|
|
|
483
|
-
/*fn map_rust_rrule (rrule: RRule) -> JsRRule {
|
|
484
|
-
JsRRule {
|
|
485
|
-
freq: map_rust_frequency(rrule.get_freq()),
|
|
486
|
-
interval: Some(rrule.get_interval()),
|
|
487
|
-
count: rrule.get_count(),
|
|
488
|
-
by_weekday:
|
|
489
|
-
}
|
|
490
|
-
}*/
|
|
491
|
-
|
|
492
541
|
fn map_js_weekday(weekday: JsWeekday) -> Weekday {
|
|
493
542
|
match weekday {
|
|
494
543
|
JsWeekday::Monday => Weekday::Mon,
|
|
@@ -548,9 +597,11 @@ fn map_rust_month(month: &u8) -> JsMonth {
|
|
|
548
597
|
}
|
|
549
598
|
}
|
|
550
599
|
|
|
551
|
-
fn map_js_tz(tz: &str) -> Tz {
|
|
552
|
-
let chrono_tz = tz
|
|
553
|
-
|
|
600
|
+
fn map_js_tz(tz: &str) -> napi::Result<Tz> {
|
|
601
|
+
let chrono_tz = tz
|
|
602
|
+
.parse()
|
|
603
|
+
.map_err(|e| napi::Error::new(napi::Status::GenericFailure, e))?;
|
|
604
|
+
Ok(Tz::Tz(chrono_tz))
|
|
554
605
|
}
|
|
555
606
|
|
|
556
607
|
fn timestamp_to_date_with_tz(timestamp: i64, tz: &Tz) -> DateTime<Tz> {
|