Skip to content

Commit

Permalink
feat: Parameter transformation (#587)
Browse files Browse the repository at this point in the history
Enable parameter transformation with the `.apply()` method.
It has more or less the same logic as `.reduce()` with the ability to
flatten the input type.


#### Motivation and context

This feature enables simpler APIs (input types) on top of runtimes
(e.g.: prisma).

#### Migration notes

_No changes needed_.

### Checklist

- [x] The change come with new or modified tests
- [x] Hard-to-understand functions have explanatory comments
- [ ] End-user documentation is updated to reflect the change
  • Loading branch information
Natoandro authored Feb 20, 2024
1 parent 4a6b256 commit 961fab5
Show file tree
Hide file tree
Showing 133 changed files with 18,811 additions and 15,358 deletions.
7 changes: 6 additions & 1 deletion .ghjk/lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,11 @@
},
"portRef": "[email protected]",
"packageName": "@bytecodealliance/jco"
},
"f4760b34b6c9f9f96207cfb380deb77007a212a60bd10bdb3dc9d20b94c2785c": {
"version": "v8.15.2",
"depConfigs": {},
"portRef": "[email protected]"
}
}
},
Expand Down Expand Up @@ -746,7 +751,7 @@
}
},
{
"version": "v8.8.0",
"version": "v8.15.2",
"port": {
"ty": "denoWorker@v1",
"name": "pnpm_ghrel",
Expand Down
11 changes: 7 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ jobs:
strategy:
matrix:
include:
- os: macos-latest
activate: "source .venv/bin/activate"
# TODO
# - os: macos-latest
# activate: "source .venv/bin/activate"
- os: macos-14
activate: "source .venv/bin/activate"
#- os: windows-latest
Expand Down Expand Up @@ -186,8 +187,10 @@ jobs:
runner: ubuntu-latest
# FIXME: try macos-14 runner once all actions support it
# docker buildx action broken as of 2024-02-09
- platform: linux/arm64
runner: custom-macos

# TODO
# - platform: linux/arm64
# runner: custom-macos
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
Expand Down
79 changes: 45 additions & 34 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dev/lock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ dev:
RUST_VERSION: 1.75.0
DENO_VERSION: 1.40.1
NODE_VERSION: 20.8.0
PNPM_VERSION: v8.8.0
PNPM_VERSION: v8.15.2
CARGO_INSTA_VERSION: 1.33.0
WASM_TOOLS_VERSION: 1.0.53
JCO_VERSION: 1.0.0
Expand Down
8 changes: 6 additions & 2 deletions examples/typegraphs/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def authentication(g: Graph):
deno = DenoRuntime()
public = Policy.public()

ctx = t.struct({"username": t.string().optional().from_context("username")})
ctx = t.struct({"username": t.string().optional()})

# highlight-start
# expects a secret in metatype.yml
Expand All @@ -26,6 +26,10 @@ def authentication(g: Graph):
# highlight-end

g.expose(
get_context=deno.identity(ctx),
get_context=deno.identity(ctx).apply(
{
"username": g.from_context("username"),
}
),
default_policy=[public],
)
6 changes: 4 additions & 2 deletions examples/typegraphs/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ typegraph({
const pub = Policy.public();

const ctx = t.struct({
"username": t.string().optional().fromContext("username"),
"username": t.string().optional(),
});

// highlight-start
Expand All @@ -25,6 +25,8 @@ typegraph({
// highlight-end

g.expose({
get_context: deno.identity(ctx).withPolicy(pub),
get_context: deno.identity(ctx).apply({
username: g.fromContext("username"),
}).withPolicy(pub),
});
});
8 changes: 6 additions & 2 deletions examples/typegraphs/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ def basic_authentication(g: Graph):
deno = DenoRuntime()
public = Policy.public()

ctx = t.struct({"username": t.string().optional().from_context("username")})
ctx = t.struct({"username": t.string().optional()})

# highlight-next-line
g.auth(Auth.basic(["admin"]))

g.expose(
public,
get_context=deno.identity(ctx),
get_context=deno.identity(ctx).apply(
{
"username": g.from_context("username"),
}
),
)
6 changes: 4 additions & 2 deletions examples/typegraphs/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ typegraph({
const pub = Policy.public();

const ctx = t.struct({
"username": t.string().optional().fromContext("username"),
"username": t.string().optional(),
});

// highlight-next-line
g.auth(Auth.basic(["admin"]));

g.expose({
get_context: deno.identity(ctx).withPolicy(pub),
get_context: deno.identity(ctx).apply({
username: g.fromContext("username"),
}).withPolicy(pub),
});
});
6 changes: 4 additions & 2 deletions examples/typegraphs/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ def roadmap(g: Graph):
),
EffectUpdate(True),
),
get_context=deno.identity(
t.struct({"username": t.string().optional().from_context("username")})
get_context=deno.identity(t.struct({"username": t.string().optional()})).apply(
{
"username": g.from_context("username"),
}
),
)
6 changes: 4 additions & 2 deletions examples/typegraphs/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ typegraph({
effects.update(),
),
get_context: deno.identity(
t.struct({ "username": t.string().optional().fromContext("username") }),
),
t.struct({ "username": t.string().optional() }),
).apply({
"username": g.fromContext("username"),
}),
}, pub);
});
Loading

0 comments on commit 961fab5

Please sign in to comment.