-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from oscartbeaumont/separate-layer-result
Normi
- Loading branch information
Showing
158 changed files
with
7,199 additions
and
1,747 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github: [oscartbeaumont] | ||
custom: ["https://paypal.me/oscartbeaumont"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: "github-actions" | ||
directory: "/" | ||
schedule: | ||
interval: "weekly" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/** | ||
* Updates the package.json files with a version to release to npm under | ||
* the main tag. | ||
* | ||
* Based on https://github.com/facebook/relay/blob/main/gulpfile.js | ||
*/ | ||
|
||
const fs = require("fs/promises"); | ||
const path = require("path"); | ||
|
||
const RELEASE_COMMIT_SHA = process.env.RELEASE_COMMIT_SHA; | ||
|
||
if (RELEASE_COMMIT_SHA && RELEASE_COMMIT_SHA.length !== 40) { | ||
throw new Error( | ||
"If the RELEASE_COMMIT_SHA env variable is set, it should be set to the " + | ||
"40 character git commit hash." | ||
); | ||
} | ||
|
||
const VERSION = RELEASE_COMMIT_SHA | ||
? `0.0.0-main-${RELEASE_COMMIT_SHA.substring(0, 8)}` | ||
: process.env.npm_package_version; | ||
|
||
console.log(RELEASE_COMMIT_SHA); | ||
|
||
async function main() { | ||
const packages = await ( | ||
await fs.readdir(path.join(__dirname, "../../packages")) | ||
).filter((pkg) => pkg !== ".DS_Store" && pkg !== "tsconfig.json"); | ||
const pkgJsons = {}; | ||
const pkgJsonPaths = {}; | ||
|
||
for (pkg of packages) { | ||
const pkgJsonPath = path.join( | ||
__dirname, | ||
"../../packages", | ||
pkg, | ||
"package.json" | ||
); | ||
pkgJsonPaths[pkg] = pkgJsonPath; | ||
const packageJson = JSON.parse(await fs.readFile(pkgJsonPath, "utf8")); | ||
|
||
pkgJsons[pkg] = packageJson; | ||
} | ||
|
||
const packageNames = Object.values(pkgJsons).map((pkg) => pkg.name); | ||
|
||
for (const pkg of packages) { | ||
let packageJson = pkgJsons[pkg]; | ||
packageJson.version = VERSION; | ||
for (const depKind of [ | ||
"dependencies", | ||
"devDependencies", | ||
"peerDependencies", | ||
]) { | ||
const deps = packageJson[depKind]; | ||
for (const dep in deps) { | ||
if (packageNames.includes(dep)) { | ||
deps[dep] = VERSION; | ||
} | ||
} | ||
} | ||
await fs.writeFile( | ||
pkgJsonPaths[pkg], | ||
JSON.stringify(packageJson, null, 2) + "\n", | ||
"utf8" | ||
); | ||
} | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
paths: | ||
- 'packages/**' | ||
# tags: | ||
# - '[0-9]+.[0-9]+.[0-9]+*' | ||
pull_request: | ||
branches: [main] | ||
paths: | ||
- 'packages/**' | ||
|
||
jobs: | ||
build-publish: | ||
name: Build and Publish to NPM | ||
runs-on: ubuntu-latest | ||
if: github.event_name == 'push' && github.repository == 'oscartbeaumont/rspc' | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: pnpm/action-setup@v2.2.4 | ||
with: | ||
version: latest | ||
|
||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: '16' | ||
cache: 'pnpm' | ||
|
||
- name: Install dependencies | ||
run: pnpm i --frozen-lockfile | ||
|
||
- name: Build | ||
run: pnpm build | ||
|
||
- name: Configure main version | ||
if: github.ref == 'refs/heads/main' | ||
run: pnpm set-package-versions | ||
env: | ||
RELEASE_COMMIT_SHA: ${{ github.sha }} | ||
|
||
- name: Publish main to npm | ||
if: github.ref == 'refs/heads/main' | ||
run: pnpm publish -r ${TAG} --no-git-checks --filter "@rspc/*" --access public | ||
env: | ||
TAG: ${{ (github.ref == 'refs/heads/main' && '--tag=main') || '' }} | ||
NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
|
||
# - name: Configure release version | ||
# if: github.ref_type == 'tag' | ||
# run: pnpm set-package-versions | ||
|
||
# - name: Publish release to npm | ||
# if: github.ref_type == 'tag' | ||
# run: pnpm publish -r ${TAG} --no-git-checks --filter "@rspc/*" --access public | ||
# env: | ||
# TAG: ${{ (contains(github.ref_name, '-beta.') && '--tag=beta') || ''}} | ||
# NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,4 +23,7 @@ node_modules | |
/packages/*/dist | ||
|
||
# Compiled vscode extension | ||
*.vsix | ||
*.vsix | ||
|
||
# Trybuild | ||
crates/*/wip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[package] | ||
name = "normi" | ||
description = "A normalised caching layer for rspc." | ||
version = "0.0.1" | ||
edition = "2021" | ||
|
||
[features] | ||
default = ["rspc"] | ||
rspc = ["dep:rspc"] | ||
|
||
[dependencies] | ||
rspc = { path = "../../", optional = true } | ||
normi-macros = { path = "./macros" } | ||
serde = "1.0.145" | ||
serde_json = "1.0.85" | ||
specta = { version = "0.0.4", path = "../specta" } | ||
|
||
[dev-dependencies] | ||
rspc = { path = "../../", features = ["axum"] } | ||
axum = "0.5.16" | ||
tokio = { version = "1.21.2", features = ["macros", "rt-multi-thread"] } | ||
tower-http = { version = "0.3.4", default-features = false, features = [ | ||
"cors", | ||
] } | ||
trybuild = "1.0.65" | ||
assert-json-diff = "2.0.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
use std::path::PathBuf; | ||
|
||
use axum::routing::get; | ||
use normi::{typed, Object}; | ||
use rspc::{Config, Router, Type}; | ||
use serde::Serialize; | ||
use tower_http::cors::{Any, CorsLayer}; | ||
|
||
#[derive(Serialize, Type, Object)] | ||
#[normi(rename = "org")] | ||
pub struct Organisation { | ||
#[normi(id)] | ||
pub id: String, | ||
pub name: String, | ||
#[normi(refr)] | ||
pub users: Vec<User>, | ||
#[normi(refr)] | ||
pub owner: User, | ||
pub non_normalised_data: Vec<()>, | ||
} | ||
|
||
#[derive(Serialize, Type, Object)] | ||
pub struct User { | ||
#[normi(id)] | ||
pub id: String, | ||
pub name: String, | ||
} | ||
|
||
// TODO: Unit test this duplicate naming | ||
|
||
#[derive(Serialize, Type, Object)] | ||
pub struct CompositeId { | ||
#[normi(id)] | ||
pub org_id: String, | ||
#[normi(id)] | ||
pub user_id: String, | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let router = <Router>::new() | ||
.config(Config::new().export_ts_bindings( | ||
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../examples/bindings.ts"), | ||
)) | ||
.query("version", |t| t(|_, _: ()| "0.1.0")) | ||
.query("userSync", |t| { | ||
t.resolver(|_, _: ()| User { | ||
id: "1".to_string(), | ||
name: "Monty Beaumont".to_string(), | ||
}) | ||
.map(typed) | ||
}) | ||
.query("user", |t| { | ||
t.resolver(|_, _: ()| async move { | ||
Ok(User { | ||
id: "1".to_string(), | ||
name: "Monty Beaumont".to_string(), | ||
}) | ||
}) | ||
.map(typed) | ||
}) | ||
.query("org", |t| { | ||
t.resolver(|_, _: ()| async move { | ||
Ok(Organisation { | ||
id: "org-1".into(), | ||
name: "Org 1".into(), | ||
users: vec![ | ||
User { | ||
id: "user-1".into(), | ||
name: "Monty Beaumont".into(), | ||
}, | ||
User { | ||
id: "user-2".into(), | ||
name: "Millie Beaumont".into(), | ||
}, | ||
User { | ||
id: "user-3".into(), | ||
name: "Oscar Beaumont".into(), | ||
}, | ||
], | ||
owner: User { | ||
id: "user-1".into(), | ||
name: "Monty Beaumont".into(), | ||
}, | ||
non_normalised_data: vec![(), ()], | ||
}) | ||
}) | ||
.map(typed) | ||
}) | ||
.query("composite", |t| { | ||
t.resolver(|_, _: ()| async move { | ||
Ok(CompositeId { | ||
org_id: "org-1".into(), | ||
user_id: "user-1".into(), | ||
}) | ||
}) | ||
.map(typed) | ||
}) | ||
.build() | ||
.arced(); | ||
|
||
let app = axum::Router::new() | ||
.route("/", get(|| async { "Hello 'rspc'!" })) | ||
// Attach the rspc router to your axum router. The closure is used to generate the request context for each request. | ||
.route("/rspc/:id", router.endpoint(|| ()).axum()) | ||
// We disable CORS because this is just an example. DON'T DO THIS IN PRODUCTION! | ||
.layer( | ||
CorsLayer::new() | ||
.allow_methods(Any) | ||
.allow_headers(Any) | ||
.allow_origin(Any), | ||
); | ||
|
||
let addr = "[::]:4000".parse::<std::net::SocketAddr>().unwrap(); // This listens on IPv6 and IPv4 | ||
println!("listening on http://{}/rspc/version", addr); | ||
axum::Server::bind(&addr) | ||
.serve(app.into_make_service()) | ||
.await | ||
.unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "normi-macros" | ||
version = "0.0.1" | ||
edition = "2021" | ||
|
||
[lib] | ||
proc-macro = true | ||
|
||
[dependencies] | ||
proc-macro2 = "1.0.46" | ||
quote = "1.0.21" | ||
syn = "1.0.101" |
Oops, something went wrong.