Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ jobs:
run: yarn install --immutable --mode=skip-build

- name: Build in docker
uses: addnab/docker-run-action@v3
uses: stefan-gorules/docker-run-action@v1
if: ${{ matrix.settings.docker }}
with:
image: ${{ matrix.settings.docker }}
Expand Down Expand Up @@ -315,7 +315,7 @@ jobs:
shell: bash

- name: Test bindings
uses: addnab/docker-run-action@v3
uses: stefan-gorules/docker-run-action@v1
with:
image: node:${{ matrix.node }}-slim
options: -v ${{ github.workspace }}:/workspace
Expand Down Expand Up @@ -370,7 +370,7 @@ jobs:
shell: bash

- name: Test bindings
uses: addnab/docker-run-action@v3
uses: stefan-gorules/docker-run-action@v1
with:
image: node:${{ matrix.node }}-alpine
options: -v ${{ github.workspace }}:/workspace
Expand Down Expand Up @@ -432,7 +432,7 @@ jobs:
shell: bash

- name: Test bindings
uses: addnab/docker-run-action@v3
uses: stefan-gorules/docker-run-action@v1
with:
options: --platform linux/arm64 -v ${{ github.workspace }}:/workspace
image: node:${{ matrix.node }}-alpine
Expand Down Expand Up @@ -482,7 +482,7 @@ jobs:
# shell: bash
#
# - name: Setup and run tests
# uses: addnab/docker-run-action@v3
# uses: stefan-gorules/docker-run-action@v1
# with:
# image: ghcr.io/napi-rs/napi-rs/nodejs:aarch64-${{ matrix.node }}
# options: -v ${{ github.workspace }}:/workspace -w /workspace
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/rust.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ jobs:
run: rustup install 1.80
- run: cargo test --workspace --all-features --exclude zen-ffi --exclude zen-nodejs --exclude zen-python
- run: cargo test --workspace --all-features --exclude zen-ffi --exclude zen-nodejs --exclude zen-python --release
- name: Test without arbitrary_precision
run: cargo test --workspace --exclude zen-ffi --exclude zen-nodejs --exclude zen-python
- name: Test without arbitrary_precision (release)
run: cargo test --workspace --exclude zen-ffi --exclude zen-nodejs --exclude zen-python --release

build:
name: cargo +${{ matrix.rust }} build
Expand Down
11 changes: 3 additions & 8 deletions actions/cargo-version-action/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34066,17 +34066,12 @@ var toml = __nccwpck_require__(2132);
;// CONCATENATED MODULE: ./src/cargo.ts

const versionRegex = /version = "[0-9]+\.[0-9]+\.[0-9]+"$/im;
const expressionDep = /zen-expression =.*$/im;
const templateDep = /zen-tmpl =.*$/im;
const macroDep = /zen-macros =.*$/im;
const typesDep = /zen-types =.*$/im;
const zenDepLine = /^.*zen-(?:expression|tmpl|macros|types)\s*=\s*\{.*}.*$/gim;
const depVersionRegex = /version\s*=\s*"[0-9]+\.[0-9]+\.[0-9]+"/;
const updateCargoContents = (contents, { version }) => {
return contents
.replace(versionRegex, `version = "${version}"`)
.replace(expressionDep, `zen-expression = { path = "../expression", version = "${version}" }`)
.replace(macroDep, `zen-macros = { path = "../macros", version = "${version}" }`)
.replace(typesDep, `zen-types = { path = "../types", version = "${version}" }`)
.replace(templateDep, `zen-tmpl = { path = "../template", version = "${version}" }`);
.replace(zenDepLine, (line) => line.replace(depVersionRegex, `version = "${version}"`));
};
const getCargoVersion = (contents) => {
var _a;
Expand Down
11 changes: 3 additions & 8 deletions actions/cargo-version-action/src/cargo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,13 @@ type UpdateCargoOptions = {
};

const versionRegex = /version = "[0-9]+\.[0-9]+\.[0-9]+"$/im;
const expressionDep = /zen-expression =.*$/im;
const templateDep = /zen-tmpl =.*$/im;
const macroDep = /zen-macros =.*$/im;
const typesDep = /zen-types =.*$/im;
const zenDepLine = /^.*zen-(?:expression|tmpl|macros|types)\s*=\s*\{.*}.*$/gim;
const depVersionRegex = /version\s*=\s*"[0-9]+\.[0-9]+\.[0-9]+"/;

export const updateCargoContents = (contents: string, { version }: UpdateCargoOptions): string => {
return contents
.replace(versionRegex, `version = "${version}"`)
.replace(expressionDep, `zen-expression = { path = "../expression", version = "${version}" }`)
.replace(macroDep, `zen-macros = { path = "../macros", version = "${version}" }`)
.replace(typesDep, `zen-types = { path = "../types", version = "${version}" }`)
.replace(templateDep, `zen-tmpl = { path = "../template", version = "${version}" }`);
.replace(zenDepLine, (line) => line.replace(depVersionRegex, `version = "${version}"`));
};

export const getCargoVersion = (contents: string): string => {
Expand Down
28 changes: 28 additions & 0 deletions actions/cargo-version-action/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,34 @@ describe('GitHub Action', () => {
}
});

test('Preserves default-features and features flags', () => {
const tomlWithFlags = `
[package]
name = "zen-engine"
version = "0.53.0"

[dependencies]
zen-types = { path = "../types", version = "0.53.0", default-features = false }
zen-expression = { path = "../expression", version = "0.53.0", default-features = false }
zen-tmpl = { path = "../template", version = "0.53.0", default-features = false }
zen-macros = { path = "../macros", version = "0.53.0" }
`;

const expected = `
[package]
name = "zen-engine"
version = "1.0.0"

[dependencies]
zen-types = { path = "../types", version = "1.0.0", default-features = false }
zen-expression = { path = "../expression", version = "1.0.0", default-features = false }
zen-tmpl = { path = "../template", version = "1.0.0", default-features = false }
zen-macros = { path = "../macros", version = "1.0.0" }
`;

expect(updateCargoContents(tomlWithFlags, { version: '1.0.0' })).toEqual(expected);
});

test('Points to right directory', async () => {
const escapeDir = (count: number) => '../'.repeat(count);
const coreDirectory = path.join(__dirname, escapeDir(3), 'core');
Expand Down
4 changes: 2 additions & 2 deletions bindings/c/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ serde = { workspace = true }
serde_json = { workspace = true }
strum = { workspace = true, features = ["derive"] }
tokio = { workspace = true, features = ["rt"] }
zen-engine = { path = "../../core/engine" }
zen-expression = { path = "../../core/expression" }
zen-engine = { path = "../../core/engine", features = ["arbitrary_precision"] }
zen-expression = { path = "../../core/expression", features = ["arbitrary_precision"] }
zen-tmpl = { path = "../../core/template" }

[lib]
Expand Down
4 changes: 2 additions & 2 deletions bindings/nodejs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ napi-sys = "3"
napi-derive = "3"
tokio-util = { workspace = true, features = ["rt"] }
serde_json = { workspace = true }
zen-engine = { path = "../../core/engine" }
zen-expression = { path = "../../core/expression" }
zen-engine = { path = "../../core/engine", features = ["arbitrary_precision"] }
zen-expression = { path = "../../core/expression", features = ["arbitrary_precision"] }
zen-tmpl = { path = "../../core/template" }
serde = { workspace = true, features = ["derive"] }
json_dotpath = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions bindings/python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ serde = { workspace = true }
serde_json = { workspace = true }
rust_decimal = { workspace = true, features = ["maths-nopanic"] }
tokio-util = { version = "0.7", features = ["rt"] }
zen-engine = { path = "../../core/engine" }
zen-expression = { path = "../../core/expression" }
zen-engine = { path = "../../core/engine", features = ["arbitrary_precision"] }
zen-expression = { path = "../../core/expression", features = ["arbitrary_precision"] }
zen-tmpl = { path = "../../core/template" }
4 changes: 2 additions & 2 deletions bindings/uniffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ path = "uniffi-bindgen.rs"
[dependencies]
uniffi = { version = "0.29", features = ["tokio", "cli"] }
serde_json = { workspace = true }
zen-engine = { path = "../../core/engine" }
zen-expression = { path = "../../core/expression" }
zen-engine = { path = "../../core/engine", features = ["arbitrary_precision"] }
zen-expression = { path = "../../core/expression", features = ["arbitrary_precision"] }
serde = { workspace = true, features = ["derive"] }
async-trait = "0.1"
tokio = "1.46"
Expand Down
6 changes: 4 additions & 2 deletions core/engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ahash = { workspace = true }
anyhow = { workspace = true }
thiserror = { workspace = true }
petgraph = { workspace = true }
serde_json = { workspace = true, features = ["arbitrary_precision"] }
serde_json = { workspace = true, features = [] }
serde = { workspace = true, features = ["derive", "rc"] }
strum = { workspace = true, features = ["derive"] }
once_cell = { workspace = true }
Expand Down Expand Up @@ -52,4 +52,6 @@ harness = false
name = "engine"

[features]
bindgen = ["rquickjs/bindgen"]
default = []
bindgen = ["rquickjs/bindgen"]
arbitrary_precision = ["serde_json/arbitrary_precision", "zen-expression/arbitrary_precision", "zen-types/arbitrary_precision", "zen-tmpl/arbitrary_precision"]
3 changes: 2 additions & 1 deletion core/expression/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ once_cell = { workspace = true }
regex = { workspace = true, optional = true }
regex-lite = { workspace = true, optional = true }
serde = { workspace = true, features = ["rc", "derive"] }
serde_json = { workspace = true, features = ["arbitrary_precision"] }
serde_json = { workspace = true, features = [] }
strum = { workspace = true }
strum_macros = { workspace = true }
thiserror = { workspace = true }
Expand All @@ -44,6 +44,7 @@ recursive = { workspace = true }
default = ["regex-deprecated"]
regex-lite = ["dep:regex-lite"]
regex-deprecated = ["dep:regex"]
arbitrary_precision = ["serde_json/arbitrary_precision", "zen-types/arbitrary_precision"]

[[bench]]
harness = false
Expand Down
3 changes: 2 additions & 1 deletion core/template/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ serde_json = { workspace = true }
default = ["regex-deprecated"]

regex-lite = ["zen-expression/regex-lite"]
regex-deprecated = ["zen-expression/regex-deprecated"]
regex-deprecated = ["zen-expression/regex-deprecated"]
arbitrary_precision = ["zen-expression/arbitrary_precision"]
6 changes: 5 additions & 1 deletion core/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ license = "MIT"
[dependencies]
ahash = { workspace = true }
serde = { workspace = true, features = ["rc", "derive"] }
serde_json = { workspace = true, features = ["arbitrary_precision"] }
serde_json = { workspace = true, features = [] }
rust_decimal = { workspace = true, features = ["maths-nopanic"] }
rust_decimal_macros = { workspace = true }
thiserror = { workspace = true }
nohash-hasher = { workspace = true }

[features]
default = []
arbitrary_precision = ["serde_json/arbitrary_precision"]
1 change: 1 addition & 0 deletions core/types/src/constant.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#[cfg(feature = "arbitrary_precision")]
pub(crate) const NUMBER_TOKEN: &str = "$serde_json::private::Number";
36 changes: 31 additions & 5 deletions core/types/src/rcvalue/conv.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::rcvalue::RcValue;
use crate::variable::{ToVariable, Variable};
use rust_decimal::Decimal;
#[cfg(not(feature = "arbitrary_precision"))]
use rust_decimal::prelude::FromPrimitive;
use serde_json::Value;
use std::rc::Rc;

Expand Down Expand Up @@ -58,11 +60,35 @@ impl From<&Value> for RcValue {
match value {
Value::Null => RcValue::Null,
Value::Bool(b) => RcValue::Bool(*b),
Value::Number(n) => RcValue::Number(
Decimal::from_str_exact(n.as_str())
.or_else(|_| Decimal::from_scientific(n.as_str()))
.expect("Allowed number"),
),
Value::Number(n) => {
#[cfg(feature = "arbitrary_precision")]
{
RcValue::Number(
Decimal::from_str_exact(n.as_str())
.or_else(|_| Decimal::from_scientific(n.as_str()))
.expect("Allowed number"),
)
}

#[cfg(not(feature = "arbitrary_precision"))]
{
if let Some(u) = n.as_u64() {
return RcValue::Number(Decimal::from(u));
}

if let Some(i) = n.as_i64() {
return RcValue::Number(Decimal::from(i));
}

if let Some(f) = n.as_f64() {
return RcValue::Number(Decimal::from_f64(f).expect("Allowed number"));
}

unreachable!(
"serde_json::Number is always u64, i64, or f64 without arbitrary_precision"
);
}
}
Value::String(s) => RcValue::String(Rc::from(s.as_str())),
Value::Array(arr) => RcValue::Array(arr.iter().map(RcValue::from).collect()),
Value::Object(obj) => RcValue::Object(
Expand Down
9 changes: 8 additions & 1 deletion core/types/src/rcvalue/de.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(feature = "arbitrary_precision")]
use crate::constant::NUMBER_TOKEN;
use crate::rcvalue::RcValue;
use ahash::{HashMap, HashMapExt};
Expand All @@ -7,6 +8,7 @@ use serde::de::{DeserializeSeed, Error, MapAccess, SeqAccess, Unexpected, Visito
use serde::{Deserialize, Deserializer};
use std::fmt::Formatter;
use std::marker::PhantomData;
#[cfg(feature = "arbitrary_precision")]
use std::ops::Deref;
use std::rc::Rc;

Expand Down Expand Up @@ -84,11 +86,13 @@ impl<'de> Visitor<'de> for RcValueVisitor {
A: MapAccess<'de>,
{
let mut m = HashMap::with_capacity(map.size_hint().unwrap_or_default());
#[cfg(feature = "arbitrary_precision")]
let mut first = true;

while let Some((key, value)) =
map.next_entry_seed(PhantomData::<Rc<str>>, RcValueDeserializer)?
{
#[cfg(feature = "arbitrary_precision")]
if first && key.deref() == NUMBER_TOKEN {
let str = match &value {
RcValue::String(s) => s.as_ref(),
Expand All @@ -103,7 +107,10 @@ impl<'de> Visitor<'de> for RcValueVisitor {
}

m.insert(key, value);
first = false;
#[cfg(feature = "arbitrary_precision")]
{
first = false;
}
}

Ok(RcValue::Object(m))
Expand Down
26 changes: 24 additions & 2 deletions core/types/src/rcvalue/ser.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
use crate::constant::NUMBER_TOKEN;
use crate::rcvalue::RcValue;
use serde::ser::SerializeStruct;
#[cfg(not(feature = "arbitrary_precision"))]
use rust_decimal::prelude::ToPrimitive;
use serde::{Serialize, Serializer};

#[cfg(feature = "arbitrary_precision")]
use crate::constant::NUMBER_TOKEN;
#[cfg(feature = "arbitrary_precision")]
use serde::ser::SerializeStruct;

impl Serialize for RcValue {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
Expand All @@ -11,13 +16,30 @@ impl Serialize for RcValue {
match self {
RcValue::Null => serializer.serialize_unit(),
RcValue::Bool(v) => serializer.serialize_bool(*v),
#[cfg(feature = "arbitrary_precision")]
RcValue::Number(v) => {
let str = v.normalize().to_string();

let mut s = serializer.serialize_struct(NUMBER_TOKEN, 1)?;
s.serialize_field(NUMBER_TOKEN, &str)?;
s.end()
}
#[cfg(not(feature = "arbitrary_precision"))]
RcValue::Number(v) => {
if let Some(u) = v.to_u64() {
return serializer.serialize_u64(u);
}

if let Some(i) = v.to_i64() {
return serializer.serialize_i64(i);
}

if let Some(f) = v.to_f64() {
return serializer.serialize_f64(f);
}

Err(serde::ser::Error::custom("cannot convert to f64"))
}
RcValue::String(v) => serializer.serialize_str(v),
RcValue::Array(v) => serializer.collect_seq(v.iter()),
RcValue::Object(v) => serializer.collect_map(v.iter()),
Expand Down
Loading
Loading