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
import { User } from "../models/User"; | |
import { Action, RequestContext } from "@chiselstrike/api"; | |
export default { | |
read: (user: User, ctx: RequestContext) => { | |
if (ctx.token && user.userId && user.userId == ctx.token['userId']) { | |
return Action.Allow; | |
} else { | |
return Action.Skip; | |
} |
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
import { User } from "../models/User"; | |
import { Action, RequestContext } from "@chiselstrike/api"; | |
export default { | |
create: (user: User, ctx: RequestContext) => { | |
if (ctx.token && user.userId && user.userId == ctx.token['userId']) { | |
return Action.Allow; | |
} else { | |
return Action.Deny; | |
} |
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
{ | |
"userId": "xxxx", | |
"otherFields": "yyy" | |
} |
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
// in models/User.ts | |
import {ChiselEntity} from "@chiselstrike/api"; | |
export class User extends ChiselEntity { | |
// the external user_id (coming from JWT auth, not public data) | |
userId?: string; | |
// the user's username | |
username: string; | |
// the user's email (not public data!) | |
email?: string; |
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
import { TopOfBook } from "../models/TopOfBook"; | |
export default TopOfBook.crud(); |
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
import { ChiselEvent } from "@chiselstrike/api"; | |
import { TopOfBook } from "../models/TopOfBook"; | |
function toJSON(buffer: ArrayBuffer) { | |
return JSON.parse(String.fromCharCode.apply(null, new Uint8Array(buffer))); | |
} | |
export default async function (event: ChiselEvent) { | |
const bookUpdate = toJSON(event.value); | |
const symbol = bookUpdate.symbol; |
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
import { ChiselEntity } from "@chiselstrike/api" | |
export class TopOfBook extends ChiselEntity { | |
symbol: string; | |
bidPrice?: number; | |
bidVolume?: number; | |
askPrice?: number; | |
askVolume?: number; | |
} |
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
CHISEL_SERVER="https://chiselstrike-examples-glommer.chiselstrike.io" | |
CHISEL_VERSION="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
import type { Post } from "../../chiselstrike/Post"; | |
export type { Post } from "../../chiselstrike/Post"; | |
function chiselUrl(name: string): string { | |
// Use environment variables to figure out where we are. Feel free to add this | |
// to your .env, but to keep things simple we'll add a default | |
const chiselServer = process.env.CHISEL_SERVER ?? "http://localhost:8080"; | |
// Which version? Versions are isolated backends that can be used in the same | |
// chisel instance. You can do test databases, API versions, or what your heart | |
// desires. By (local) default this is "dev", but when deployed it is customary |
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
$ curl http://localhost:8080/dev/posts | |
{ | |
"next_page": "http://localhost:8080/dev/posts?cursor=eyJheGVzIjpbeyJrZXkiOnsiZmllbGROYW1lIjoiaWQiLCJhc2NlbmRpbmciOnRydWV9LCJ2YWx1ZSI6ImMyNzMwODA3LTVjZWYtNDQ0MC1hNzk2LWVjNjIxNjcxMjZkYyJ9XSwiZm9yd2FyZCI6dHJ1ZSwiaW5jbHVzaXZlIjpmYWxzZX0%3D", | |
"prev_page": "http://localhost:8080/dev/posts?cursor=eyJheGVzIjpbeyJrZXkiOnsiZmllbGROYW1lIjoiaWQiLCJhc2NlbmRpbmciOnRydWV9LCJ2YWx1ZSI6IjE5YTQzOTU3LWVmN2YtNGViZC04MDk2LTJkN2UzNzQ5NGUyYSJ9XSwiZm9yd2FyZCI6ZmFsc2UsImluY2x1c2l2ZSI6ZmFsc2V9", | |
"results": [ | |
{ | |
"id": "19a43957-ef7f-4ebd-8096-2d7e37494e2a", | |
"title": "my first post", | |
"markdown": "Here iss our first post" | |
}, |
NewerOlder