Skip to content

Commit

Permalink
Merge pull request #208 from lsndr/next
Browse files Browse the repository at this point in the history
Release next
  • Loading branch information
lsndr authored Jun 21, 2024
2 parents f947d4c + 269bb84 commit 0aa37b8
Show file tree
Hide file tree
Showing 28 changed files with 680 additions and 850 deletions.
9 changes: 4 additions & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ module.exports = {
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
'plugin:import/recommended',
'plugin:import/typescript',
'plugin:eslint-comments/recommended',
'prettier',
],
plugins: ['@typescript-eslint'],
ignorePatterns: ['node_modules', '/target', '/dist/**/*', 'src/lib/**/*'],
Expand All @@ -19,20 +19,19 @@ module.exports = {
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
'plugin:import/recommended',
'plugin:import/typescript',
'prettier',
],
parserOptions: {
project: ['tsconfig.eslint.json'],
},
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/explicit-member-accessibility': 'error',
'@typescript-eslint/ban-ts-comment': 'off',
'import/no-cycle': 'error',
'@typescript-eslint/member-ordering': 'error',
'import/no-unresolved': 'error',
'@typescript-eslint/no-for-in-array': 'error',
'no-implied-eval': 'off',
Expand Down
16 changes: 8 additions & 8 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
version: 2
updates:
- package-ecosystem: "npm"
target-branch: "next"
directory: "/"
- package-ecosystem: 'npm'
target-branch: 'next'
directory: '/'
schedule:
interval: "daily"
- package-ecosystem: "cargo"
target-branch: "next"
directory: "/"
interval: 'daily'
- package-ecosystem: 'cargo'
target-branch: 'next'
directory: '/'
schedule:
interval: "daily"
interval: 'daily'
4 changes: 2 additions & 2 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "Build & Test"
name: 'Build & Test'
env:
DEBUG: napi:*
APP_NAME: rrule-rust
Expand Down Expand Up @@ -430,4 +430,4 @@ jobs:
with:
name: bindings-universal-apple-darwin
path: src/lib/${{ env.APP_NAME }}.*.node
if-no-files-found: error
if-no-files-found: error
24 changes: 12 additions & 12 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:
inputs:
version:
description: "Version (e.g.: v2.0.0-next.17)"
description: 'Version (e.g.: v2.0.0-next.17)'
required: true

run-name: E2E (${{ inputs.version }})
Expand All @@ -29,14 +29,14 @@ jobs:
- os: windows-latest
node: 20
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm run test:e2e
env:
E2E_LIBRARY_VERSION: ${{ inputs.version }}
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm run test:e2e
env:
E2E_LIBRARY_VERSION: ${{ inputs.version }}
24 changes: 21 additions & 3 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
name: "Build & Test"
name: 'Build & Test'
env:
HUSKY: 0
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
cancel-in-progress: true
on:
pull_request: null
jobs:
format:
name: Format
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: 'npm'
- name: Install
run: |
npm ci
- name: Format
run: |
npm run format
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -24,4 +42,4 @@ jobs:
run: |
npm run lint
build_and_test:
uses: ./.github/workflows/build-and-test.yml
uses: ./.github/workflows/build-and-test.yml
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
branches:
- master
- next
- "*.x"
- '*.x'
permissions:
contents: read
jobs:
Expand All @@ -35,8 +35,8 @@ jobs:
- name: Setup LTS Node.js
uses: actions/setup-node@v4
with:
node-version: "lts/*"
cache: "npm"
node-version: 'lts/*'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Download all artifacts
Expand All @@ -52,4 +52,4 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.CI_GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx semantic-release
run: npx semantic-release
3 changes: 2 additions & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
npm run lint:fix-staged
npm run lint
npm run format
9 changes: 9 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.prettierignore
.husky
.gitignore
.npmignore
node_modules
target
/coverage
/dist
/src/lib
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all"
}
}
3 changes: 1 addition & 2 deletions .releaserc
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"preset": "angular",
"releaseRules": [
{ "type": "docs", "release": "patch" },
{ "type": "perf", "release": "patch" },
{ "type": "revert", "release": "patch" }
{ "type": "perf", "release": "patch" }
]
}
],
Expand Down
2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nodeLinker: node-modules
nodeLinker: node-modules
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 changes: 8 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,30 @@
[![npm downloads](https://img.shields.io/npm/dt/rrule-rust.svg)](https://www.npmjs.com/package/rrule-rust)
[![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/lsndr/rrule-rust/blob/master/LICENSE.md)


`rrule-rust` is a library for working with recurrence rules based on Rust's [rrule](https://crates.io/crates/rrule) crate


1. [Quick Start](#quick-start)
2. [Perfomance](#perfomance)
2. [Performance](#performance)

## Quick Start

See [test folder](https://github.com/lsndr/rrule-rust/tree/master/tests) to find more use cases

```
npm i rrule-rust
npm i rrule-rust
```


```typescript
import { RRule, RRuleSet, Frequency, DateTime } from 'rrule-rust';

const rrule = new RRule({
frequency: Frequency.Daily,
count: 5
count: 5,
});
const set = new RRuleSet({
dtstart: DateTime.create(1997, 9, 2, 9, 0, 0, false),
tzid: 'US/Eastern',
rrules: [rrule]
rrules: [rrule],
});

const dates = set.all(); // [ DateTime, DateTime, DateTime, DateTime, DateTime ]
Expand All @@ -47,10 +44,10 @@ const asString = set.toString(); // DTSTART;TZID=US/Eastern:19970902T090000\nFRE
Memory: 36 GB LPDDR5
```

| | rrule | rrule-rust | |
| -------- | -------------- | ------------- | ------------ |
| UTC TZ | 15 904 ops/s | 108 538 ops/s | ~6x faster |
| Other TZ | 260 ops/s | 106 034 ops/s | ~400x faster |
| | rrule | rrule-rust | |
| -------- | ------------ | ------------- | ------------ |
| UTC TZ | 15 904 ops/s | 108 538 ops/s | ~6x faster |
| Other TZ | 260 ops/s | 106 034 ops/s | ~400x faster |

You can run benchmarks using `npm run benchmark`

Expand Down
8 changes: 4 additions & 4 deletions e2e/sandbox/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ export type SandboxOptions = {
export class Sandbox {
private readonly projectPath: string;
private readonly esm: boolean;
constructor(options: SandboxOptions) {
public constructor(options: SandboxOptions) {
this.projectPath = path.resolve(__dirname, 'app');
this.esm = options.esm;
}

install() {
public install() {
rimrafSync(path.resolve(this.projectPath));
mkdirSync(this.projectPath);
execSync(`npm init -y`, { cwd: this.projectPath });
Expand All @@ -29,11 +29,11 @@ export class Sandbox {
});
}

uninstall() {
public uninstall() {
rimrafSync(path.resolve(this.projectPath));
}

run<T>(code: () => T): T {
public run<T>(code: () => T): T {
writeFileSync(
path.resolve(this.projectPath, 'index.js'),
`
Expand Down
54 changes: 36 additions & 18 deletions lib/js/rrule_set.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use super::rrule::RRule;
use crate::rrule::datetime::DateTime;
use crate::rrule::dtstart::DtStart;
use crate::rrule::exdate::ExDate;
use crate::rrule::rdate::RDate;
use crate::rrule::{rrule, rrule_set};
use napi::bindgen_prelude::{Array, Reference, SharedReference};
use napi::iterator::Generator;
Expand Down Expand Up @@ -48,13 +50,13 @@ impl RRuleSet {
.map(|rrule| rrule.into())
.collect();

let exdates: Vec<DateTime> = exdates
let exdates: Vec<ExDate> = exdates
.unwrap_or_default()
.into_iter()
.map(Into::into)
.collect();

let rdates: Vec<DateTime> = rdates
let rdates: Vec<RDate> = rdates
.unwrap_or_default()
.into_iter()
.map(Into::into)
Expand Down Expand Up @@ -111,26 +113,42 @@ impl RRuleSet {

#[napi(getter, ts_return_type = "number[]")]
pub fn exdates(&self) -> napi::Result<Vec<i64>> {
Ok(
self
.rrule_set
.exdates()
.iter()
.map(|date| date.into())
.collect(),
)
let mut exdates = Vec::<i64>::new();

for exdate in self.rrule_set.exdates() {
let datetimes = exdate
.to_datetimes(&self.rrule_set.dtstart())
.map_err(|e| napi::Error::new(napi::Status::GenericFailure, e))?;

for datetime in datetimes.iter() {
let datetime = datetime.with_timezone(&self.rrule_set.dtstart().timezone());
let datetime = DateTime::from(&datetime);

exdates.push((&datetime).into());
}
}

Ok(exdates)
}

#[napi(getter, ts_return_type = "number[]")]
pub fn rdates(&self) -> napi::Result<Vec<i64>> {
Ok(
self
.rrule_set
.rdates()
.iter()
.map(|date| date.into())
.collect(),
)
let mut rdates = Vec::<i64>::new();

for rdate in self.rrule_set.rdates() {
let datetimes = rdate
.to_datetimes(&self.rrule_set.dtstart())
.map_err(|e| napi::Error::new(napi::Status::GenericFailure, e))?;

for datetime in datetimes.iter() {
let datetime = datetime.with_timezone(&self.rrule_set.dtstart().timezone());
let datetime = DateTime::from(&datetime);

rdates.push((&datetime).into());
}
}

Ok(rdates)
}

#[napi(factory, ts_return_type = "RRuleSet")]
Expand Down
2 changes: 2 additions & 0 deletions lib/rrule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ mod calendar;

pub mod datetime;
pub mod dtstart;
pub mod exdate;
pub mod frequency;
pub mod month;
pub mod n_weekday;
pub mod rdate;
pub mod rrule;
pub mod rrule_set;
pub mod weekday;
Loading

0 comments on commit 0aa37b8

Please sign in to comment.