├── src
├── vite-env.d.ts
├── rand.ts
├── date.ts
├── use-interval.ts
├── main.tsx
├── test-data.ts
├── index.css
├── workerd
│ └── index.ts
├── schema.ts
└── App.tsx
├── public
└── favicon.ico
├── .env
├── prettier.config.js
├── tsconfig.workerd.json
├── tsconfig.json
├── docker
├── wait-for-pg.sh
├── docker-compose.yml
└── seed.sql
├── index.html
├── .gitignore
├── tsconfig.node.json
├── tsconfig.app.json
├── vite.config.ts
├── eslint.config.js
├── wrangler.toml
├── api
└── index.ts
├── package.json
├── README.md
├── CODE_OF_CONDUCT.md
└── LICENSE
/src/vite-env.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rocicorp/hello-zero-do/HEAD/public/favicon.ico
--------------------------------------------------------------------------------
/.env:
--------------------------------------------------------------------------------
1 | ZERO_UPSTREAM_DB="postgresql://user:password@127.0.0.1/zstart_do"
2 | ZERO_REPLICA_FILE="/tmp/zstart_do_replica.db"
3 | ZERO_AUTH_SECRET="secretkey"
4 |
--------------------------------------------------------------------------------
/prettier.config.js:
--------------------------------------------------------------------------------
1 | export default {
2 | singleQuote: true,
3 | trailingComma: 'all',
4 | arrowParens: 'avoid',
5 | bracketSpacing: false,
6 | quoteProps: 'consistent',
7 | };
8 |
--------------------------------------------------------------------------------
/tsconfig.workerd.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./tsconfig.node.json",
3 | "compilerOptions": {
4 | "types": ["@cloudflare/workers-types"]
5 | },
6 | "include": ["src/workerd/**/*.ts"]
7 | }
8 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "files": [],
3 | "references": [
4 | {"path": "./tsconfig.app.json"},
5 | {"path": "./tsconfig.node.json"},
6 | {"path": "./tsconfig.workerd.json"}
7 | ]
8 | }
9 |
--------------------------------------------------------------------------------
/src/rand.ts:
--------------------------------------------------------------------------------
1 | export const randBetween = (min: number, max: number) =>
2 | Math.floor(Math.random() * (max - min) + min);
3 | export const randInt = (max: number) => randBetween(0, max);
4 | export const randID = () => Math.random().toString(36).slice(2);
5 |
--------------------------------------------------------------------------------
/docker/wait-for-pg.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | set -e
3 |
4 | # Loop over all passed connection strings
5 | for conn_str in "$@"; do
6 | >&2 echo "waiting for $conn_str"
7 |
8 | until psql "$conn_str" -q -c '\q'; do
9 | >&2 echo "Postgres is unavailable - sleeping"
10 | sleep 1
11 | done
12 |
13 | >&2 echo "Postgres is up - continuing"
14 | done
15 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | When??
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 | pnpm-debug.log*
8 | lerna-debug.log*
9 |
10 | node_modules
11 | dist
12 | dist-ssr
13 | *.localtsbuildinfo
14 | *.tsbuildinfo
15 |
16 | # Editor directories and files
17 | .vscode/*
18 | !.vscode/extensions.json
19 | .idea
20 | .DS_Store
21 | *.suo
22 | *.ntvs*
23 | *.njsproj
24 | *.sln
25 | *.sw?
26 | .wrangler
27 |
28 | # zero
29 | zero-schema.json
30 |
31 |
--------------------------------------------------------------------------------
/src/date.ts:
--------------------------------------------------------------------------------
1 | // The built-in date formatter is surprisingly slow in Chrome.
2 | export const formatDate = (timestamp: number) => {
3 | const date = new Date(timestamp);
4 | const year = date.getFullYear();
5 | const month = (date.getMonth() + 1).toString().padStart(2, "0");
6 | const day = date.getDate().toString().padStart(2, "0");
7 | const hours = date.getHours().toString().padStart(2, "0");
8 | const minutes = date.getMinutes().toString().padStart(2, "0");
9 | return `${year}-${month}-${day} ${hours}:${minutes}`;
10 | };
11 |
--------------------------------------------------------------------------------
/tsconfig.node.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "ES2022",
4 | "lib": ["ES2022"],
5 | "module": "ESNext",
6 | "skipLibCheck": true,
7 |
8 | /* Bundler mode */
9 | "moduleResolution": "bundler",
10 | "allowImportingTsExtensions": true,
11 | "isolatedModules": true,
12 | "moduleDetection": "force",
13 | "noEmit": true,
14 |
15 | /* Linting */
16 | "strict": true,
17 | "noUnusedLocals": true,
18 | "noUnusedParameters": true,
19 | "noFallthroughCasesInSwitch": true,
20 | "verbatimModuleSyntax": true
21 | },
22 | "include": ["vite.config.ts", "./api"]
23 | }
24 |
--------------------------------------------------------------------------------
/tsconfig.app.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "ES2020",
4 | "useDefineForClassFields": true,
5 | "lib": ["ES2020", "DOM", "DOM.Iterable"],
6 | "module": "ESNext",
7 | "skipLibCheck": true,
8 |
9 | /* Bundler mode */
10 | "moduleResolution": "bundler",
11 | "allowImportingTsExtensions": true,
12 | "isolatedModules": true,
13 | "moduleDetection": "force",
14 | "noEmit": true,
15 | "jsx": "react-jsx",
16 |
17 | /* Linting */
18 | "strict": true,
19 | "noUnusedLocals": true,
20 | "noUnusedParameters": true,
21 | "noFallthroughCasesInSwitch": true
22 | },
23 | "include": ["src"]
24 | }
25 |
--------------------------------------------------------------------------------
/src/use-interval.ts:
--------------------------------------------------------------------------------
1 | import {useEffect, useLayoutEffect, useRef} from 'react';
2 |
3 | export function useInterval(callback: () => void, delay: number | null) {
4 | const savedCallback = useRef(callback);
5 |
6 | // Remember the latest callback if it changes.
7 | useLayoutEffect(() => {
8 | savedCallback.current = callback;
9 | }, [callback]);
10 |
11 | // Set up the interval.
12 | useEffect(() => {
13 | // Don't schedule if no delay is specified.
14 | // Note: 0 is a valid value for delay.
15 | if (delay === null) {
16 | return;
17 | }
18 |
19 | const id = setInterval(() => {
20 | savedCallback.current();
21 | }, delay);
22 |
23 | return () => {
24 | clearInterval(id);
25 | };
26 | }, [delay]);
27 | }
28 |
--------------------------------------------------------------------------------
/vite.config.ts:
--------------------------------------------------------------------------------
1 | import {getRequestListener} from '@hono/node-server';
2 | import react from '@vitejs/plugin-react';
3 | import {defineConfig} from 'vite';
4 | import {app} from './api/index.js';
5 |
6 | export default defineConfig({
7 | optimizeDeps: {
8 | esbuildOptions: {
9 | target: 'es2022',
10 | },
11 | },
12 | plugins: [
13 | react(),
14 | {
15 | name: 'api-server',
16 | configureServer(server) {
17 | server.middlewares.use((req, res, next) => {
18 | if (!req.url?.startsWith('/api')) {
19 | return next();
20 | }
21 | getRequestListener(async request => {
22 | return await app.fetch(request, {});
23 | })(req, res);
24 | });
25 | },
26 | },
27 | ],
28 | });
29 |
--------------------------------------------------------------------------------
/docker/docker-compose.yml:
--------------------------------------------------------------------------------
1 | services:
2 | zstart_postgres:
3 | image: postgres:16.2-alpine
4 | shm_size: 1g
5 | user: postgres
6 | restart: always
7 | healthcheck:
8 | test: 'pg_isready -U user --dbname=postgres'
9 | interval: 10s
10 | timeout: 5s
11 | retries: 5
12 | ports:
13 | - 5432:5432
14 | environment:
15 | POSTGRES_USER: user
16 | POSTGRES_DB: postgres
17 | POSTGRES_PASSWORD: password
18 | command: |
19 | postgres
20 | -c wal_level=logical
21 | -c max_wal_senders=10
22 | -c max_replication_slots=5
23 | -c hot_standby=on
24 | -c hot_standby_feedback=on
25 | volumes:
26 | - zstart_pgdata:/var/lib/postgresql/data
27 | - ./:/docker-entrypoint-initdb.d
28 |
29 | volumes:
30 | zstart_pgdata:
31 | driver: local
32 |
--------------------------------------------------------------------------------
/eslint.config.js:
--------------------------------------------------------------------------------
1 | import js from '@eslint/js';
2 | import reactHooks from 'eslint-plugin-react-hooks';
3 | import reactRefresh from 'eslint-plugin-react-refresh';
4 | import globals from 'globals';
5 | import tseslint from 'typescript-eslint';
6 |
7 | export default tseslint.config(
8 | {ignores: ['dist']},
9 | {
10 | extends: [js.configs.recommended, ...tseslint.configs.recommended],
11 | files: ['**/*.{ts,tsx}'],
12 | languageOptions: {
13 | ecmaVersion: 2020,
14 | globals: globals.browser,
15 | },
16 | plugins: {
17 | 'react-hooks': reactHooks,
18 | 'react-refresh': reactRefresh,
19 | },
20 | rules: {
21 | ...reactHooks.configs.recommended.rules,
22 | 'react-refresh/only-export-components': [
23 | 'warn',
24 | {allowConstantExport: true},
25 | ],
26 | },
27 | },
28 | );
29 |
--------------------------------------------------------------------------------
/src/main.tsx:
--------------------------------------------------------------------------------
1 | import {Zero} from '@rocicorp/zero';
2 | import {ZeroProvider} from '@rocicorp/zero/react';
3 | import {decodeJwt} from 'jose';
4 | import Cookies from 'js-cookie';
5 | import {StrictMode} from 'react';
6 | import {createRoot} from 'react-dom/client';
7 | import App from './App.tsx';
8 | import './index.css';
9 | import {schema} from './schema.ts';
10 |
11 | const encodedJWT = Cookies.get('jwt');
12 | const decodedJWT = encodedJWT && decodeJwt(encodedJWT);
13 | const userID = decodedJWT?.sub ? (decodedJWT.sub as string) : 'anon';
14 |
15 | const z = new Zero({
16 | userID,
17 | auth: () => encodedJWT,
18 | server: import.meta.env.VITE_PUBLIC_SERVER,
19 | schema,
20 | // This is often easier to develop with if you're frequently changing
21 | // the schema. Switch to 'idb' for local-persistence.
22 | kvStore: 'mem',
23 | });
24 |
25 | createRoot(document.getElementById('root')!).render(
26 |
27 |
28 |
29 |
30 | ,
31 | );
32 |
--------------------------------------------------------------------------------
/wrangler.toml:
--------------------------------------------------------------------------------
1 | #:schema node_modules/wrangler/config-schema.json
2 | name = "hello-zero-do"
3 | main = "src/workerd/index.ts"
4 | compatibility_flags = [ "nodejs_compat" ]
5 | compatibility_date = "2024-11-07"
6 |
7 | # Workers Logs
8 | # Docs: https://developers.cloudflare.com/workers/observability/logs/workers-logs/
9 | # Configuration: https://developers.cloudflare.com/workers/observability/logs/workers-logs/#enable-workers-logs
10 | [observability]
11 | enabled = true
12 |
13 | # Bind a Durable Object. Durable objects are a scale-to-zero compute primitive based on the actor model.
14 | # Durable Objects can live for as long as needed. Use these when you need a long-running "server", such as in realtime apps.
15 | # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects
16 | [[durable_objects.bindings]]
17 | name = "MY_DURABLE_OBJECT"
18 | class_name = "MyDurableObject"
19 |
20 | # Durable Object migrations.
21 | # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#migrations
22 | [[migrations]]
23 | tag = "v1"
24 | new_classes = ["MyDurableObject"]
25 |
--------------------------------------------------------------------------------
/docker/seed.sql:
--------------------------------------------------------------------------------
1 | CREATE DATABASE zstart_do;
2 | CREATE DATABASE zstart_do_cvr;
3 | CREATE DATABASE zstart_do_cdb;
4 |
5 | \c zstart_do;
6 |
7 | CREATE TABLE "user" (
8 | "id" VARCHAR PRIMARY KEY,
9 | "name" VARCHAR NOT NULL,
10 | "partner" BOOLEAN NOT NULL
11 | );
12 |
13 | CREATE TABLE "message" (
14 | "id" VARCHAR PRIMARY KEY,
15 | "sender_id" VARCHAR REFERENCES "user"(id),
16 | "body" VARCHAR NOT NULL,
17 | "timestamp" TIMESTAMP not null
18 | );
19 |
20 | INSERT INTO "user" (id, name, partner) VALUES ('ycD76wW4R2', 'Aaron', true);
21 | INSERT INTO "user" (id, name, partner) VALUES ('IoQSaxeVO5', 'Matt', true);
22 | INSERT INTO "user" (id, name, partner) VALUES ('WndZWmGkO4', 'Cesar', true);
23 | INSERT INTO "user" (id, name, partner) VALUES ('ENzoNm7g4E', 'Erik', true);
24 | INSERT INTO "user" (id, name, partner) VALUES ('dLKecN3ntd', 'Greg', true);
25 | INSERT INTO "user" (id, name, partner) VALUES ('enVvyDlBul', 'Darick', true);
26 | INSERT INTO "user" (id, name, partner) VALUES ('9ogaDuDNFx', 'Alex', true);
27 | INSERT INTO "user" (id, name, partner) VALUES ('6z7dkeVLNm', 'Dax', false);
28 | INSERT INTO "user" (id, name, partner) VALUES ('7VoEoJWEwn', 'Nate', false);
29 |
30 |
--------------------------------------------------------------------------------
/src/test-data.ts:
--------------------------------------------------------------------------------
1 | import {randBetween, randID, randInt} from './rand';
2 | import {Message, User} from './schema';
3 |
4 | const requests = [
5 | 'Hey guys, is the zero package ready yet?',
6 | "I tried installing the package, but it's not there.",
7 | 'The package does not install...',
8 | 'Hey, can you ask Aaron when the npm package will be ready?',
9 | 'npm npm npm npm npm',
10 | 'n --- p --- m',
11 | 'npm wen',
12 | 'npm package?',
13 | ];
14 |
15 | const replies = [
16 | 'It will be ready next week',
17 | "We'll let you know",
18 | "It's not ready - next week",
19 | 'next week i think',
20 | "Didn't we say next week",
21 | "I could send you a tarball, but it won't work",
22 | ];
23 |
24 | export function randomMessage(users: readonly User[]): Message {
25 | const id = randID();
26 | const timestamp = randBetween(1727395200000, new Date().getTime());
27 | const isRequest = randInt(10) <= 6;
28 | const messages = isRequest ? requests : replies;
29 | const senders = users.filter(u => u.partner === !isRequest);
30 | const senderID = senders[randInt(senders.length)].id;
31 | return {
32 | id,
33 | senderID,
34 | body: messages[randInt(messages.length)],
35 | timestamp,
36 | };
37 | }
38 |
--------------------------------------------------------------------------------
/api/index.ts:
--------------------------------------------------------------------------------
1 | import {randomInt} from 'crypto';
2 | import {Hono} from 'hono';
3 | import {handle} from 'hono/vercel';
4 | import {SignJWT} from 'jose';
5 | import {setCookie} from 'hono/cookie';
6 | import dotenv from 'dotenv';
7 |
8 | dotenv.config();
9 |
10 | export const app = new Hono().basePath('/api');
11 |
12 | // See seed.sql
13 | // In real life you would of course authenticate the user however you like.
14 | const userIDs = [
15 | '6z7dkeVLNm',
16 | 'ycD76wW4R2',
17 | 'IoQSaxeVO5',
18 | 'WndZWmGkO4',
19 | 'ENzoNm7g4E',
20 | 'dLKecN3ntd',
21 | '7VoEoJWEwn',
22 | 'enVvyDlBul',
23 | '9ogaDuDNFx',
24 | ];
25 |
26 | app.get('/login', async c => {
27 | const jwtPayload = {
28 | sub: userIDs[randomInt(userIDs.length)],
29 | iat: Math.floor(Date.now() / 1000),
30 | };
31 |
32 | const jwt = await new SignJWT(jwtPayload)
33 | .setProtectedHeader({alg: 'HS256'})
34 | .setExpirationTime('30days')
35 | .sign(new TextEncoder().encode(must(process.env.ZERO_AUTH_SECRET)));
36 |
37 | setCookie(c, 'jwt', jwt, {
38 | expires: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000),
39 | });
40 |
41 | return c.text('ok');
42 | });
43 |
44 | export default handle(app);
45 |
46 | function must(val: T) {
47 | if (!val) {
48 | throw new Error('Expected value to be defined');
49 | }
50 | return val;
51 | }
52 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "zapp",
3 | "private": true,
4 | "version": "0.0.0",
5 | "type": "module",
6 | "scripts": {
7 | "dev:ui": "VITE_PUBLIC_SERVER='http://localhost:4848' vite",
8 | "dev:zero-cache": "zero-cache-dev -p src/schema.ts",
9 | "dev:db-up": "docker compose --env-file .env -f ./docker/docker-compose.yml up",
10 | "dev:db-down": "docker compose --env-file .env -f ./docker/docker-compose.yml down",
11 | "dev:clean": "source .env && docker volume rm -f docker_zstart_pgdata && rm -rf \"${ZERO_REPLICA_FILE}\"*",
12 | "build": "tsc -b && vite build",
13 | "lint": "eslint ."
14 | },
15 | "dependencies": {
16 | "@rocicorp/zero": "0.23.2025090100",
17 | "ansi-escapes": "^7.0.0",
18 | "jose": "^5.9.6",
19 | "js-cookie": "^3.0.5",
20 | "react": "^18.3.1",
21 | "react-dom": "^18.3.1"
22 | },
23 | "devDependencies": {
24 | "@cloudflare/workers-types": "^4.20241106.0",
25 | "@eslint/js": "^9.9.0",
26 | "@hono/node-server": "^1.13.2",
27 | "@types/js-cookie": "^3.0.6",
28 | "@types/node": "^22.7.9",
29 | "@types/react": "^18.3.3",
30 | "@types/react-dom": "^18.3.0",
31 | "@vitejs/plugin-react": "^4.3.1",
32 | "dotenv": "^16.4.5",
33 | "eslint": "^9.9.0",
34 | "eslint-plugin-react-hooks": "^5.1.0-rc.0",
35 | "eslint-plugin-react-refresh": "^0.4.9",
36 | "globals": "^15.9.0",
37 | "hono": "^4.6.6",
38 | "prettier": "^3.3.3",
39 | "typescript": "^5.5.3",
40 | "typescript-eslint": "^8.0.1",
41 | "vite": "^5.4.1",
42 | "wrangler": "^3.85.0"
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Zero in a Durable Object
2 |
3 | This runs Zero in a Cloudflare Durable Object. It's a simple example, but it
4 | proves that it's possible to run Zero in a Durable Object.
5 |
6 | # Why run Zero in DO?
7 |
8 | This sample was written for a Zero user who was running collaboration sessions in DOs. Sometimes they needed to force shut down these DOs. It would be unreliable to send every DO a message telling it to shut down. But if they wrote the state into a DB and instead synced that state, it would be perfectly reliable. The DO would just monitor what state it is supposed to be in and shut itself down when necessary.
9 |
10 | More generally any time a DO needs some subset of PG data, it could be useful to have a live-updated, consistent view of it rather than having to query.
11 |
12 | ## Running
13 |
14 | We need 4 different terminals to run this example!
15 |
16 | ### 1. Run Posgres
17 |
18 | Start a Postgres database using docker
19 |
20 | ```
21 | npm run dev:db-up
22 | ```
23 |
24 | ### 2. Run Zero Cache
25 |
26 | Start a Zero cache server
27 |
28 | ```
29 | npm run dev:zero-cache
30 | ```
31 |
32 | ### 3. Run Web App
33 |
34 | This is to add and remove messages to Postgres. This web app uses Zero too.
35 |
36 | ```
37 | npm run dev:ui
38 | ```
39 |
40 | Open a browser at http://localhost:5173 to add and remove messages.
41 |
42 | ### 4. Run Durable Object
43 |
44 | ```
45 | npx wrangler dev
46 | ```
47 |
48 | Open a browser at http://localhost:8787. This will create the Durable Object
49 | which creates the Zero client in the DO.
50 |
51 | Then make changes in the web UI and observe the console output from wrangler.
52 |
--------------------------------------------------------------------------------
/src/index.css:
--------------------------------------------------------------------------------
1 | :root {
2 | font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
3 | line-height: 1.5;
4 | font-weight: 400;
5 | font-size: 0.9em;
6 |
7 | color-scheme: light dark;
8 | color: rgba(255, 255, 255, 0.87);
9 | background-color: black;
10 |
11 | font-synthesis: none;
12 | text-rendering: optimizeLegibility;
13 | -webkit-font-smoothing: antialiased;
14 | -moz-osx-font-smoothing: grayscale;
15 | }
16 |
17 | body {
18 | margin: 0;
19 | display: flex;
20 | place-items: center;
21 | flex-direction: column;
22 | min-width: 320px;
23 | min-height: 100vh;
24 | }
25 |
26 | #root {
27 | margin: 0 auto;
28 | padding: 2rem;
29 | text-align: center;
30 | width: 90%;
31 | min-width: 600px;
32 | max-width: 1280px;
33 | }
34 |
35 | a {
36 | font-weight: 500;
37 | }
38 |
39 | a:hover {
40 | color: #535bf2;
41 | }
42 |
43 | button {
44 | border-radius: 8px;
45 | border: 1px solid transparent;
46 | padding: 0.6em 1.2em;
47 | font-weight: 500;
48 | font-family: inherit;
49 | background-color: #3a3a3a;
50 | cursor: pointer;
51 | transition: border-color 0.25s;
52 | }
53 | button:hover {
54 | border-color: #646cff;
55 | }
56 | button:focus,
57 | button:focus-visible {
58 | outline: 4px auto -webkit-focus-ring-color;
59 | }
60 |
61 | td {
62 | white-space: nowrap;
63 | overflow: none;
64 | text-overflow: ellipsis;
65 | }
66 |
67 | td:last-child {
68 | cursor: pointer;
69 | }
70 |
71 | .controls {
72 | display: flex;
73 | gap: 1rem;
74 | align-items: center;
75 | margin-bottom: 1rem;
76 | white-space: nowrap;
77 | }
78 |
79 | .controls > div {
80 | flex: 1;
81 | display: flex;
82 | flex-direction: row;
83 | justify-content: start;
84 | gap: 1rem;
85 | align-items: center;
86 | margin-bottom: 1rem;
87 | }
88 |
--------------------------------------------------------------------------------
/src/workerd/index.ts:
--------------------------------------------------------------------------------
1 | import {Zero} from '@rocicorp/zero';
2 | import {clearTerminal, cursorTo} from 'ansi-escapes';
3 | import {DurableObject} from 'cloudflare:workers';
4 | import {formatDate} from '../date.js';
5 | import {type Message, schema, type Schema, type User} from '../schema.js';
6 |
7 | interface Env {
8 | ['MY_DURABLE_OBJECT']: DurableObjectNamespace;
9 | }
10 |
11 | export class MyDurableObject extends DurableObject {
12 | #z: Zero;
13 |
14 | constructor(ctx: DurableObjectState, env: Env) {
15 | super(ctx, env);
16 | addEventListener('unhandledrejection', e => {
17 | console.log('unhandledrejection', e);
18 | });
19 |
20 | this.#z = new Zero({
21 | server: 'http://localhost:4848',
22 | userID: 'anon',
23 | schema,
24 | kvStore: 'mem',
25 | });
26 |
27 | const view = this.#z.query.message
28 | .related('sender', q => q.one())
29 | .orderBy('timestamp', 'desc')
30 | .materialize();
31 | view.addListener(render);
32 | }
33 |
34 | init() {
35 | const url = 'http://localhost:5173/';
36 | return `Add or remove messages from ${url} `;
37 | }
38 | }
39 |
40 | export default {
41 | async fetch(request, env): Promise {
42 | const url = new URL(request.url);
43 | if (url.pathname !== '/') {
44 | return new Response('Not found', {status: 404});
45 | }
46 | const id: DurableObjectId = env.MY_DURABLE_OBJECT.idFromName(
47 | new URL(request.url).pathname,
48 | );
49 | const stub = env.MY_DURABLE_OBJECT.get(id);
50 | // We only get the DO to trigger it to watch the issue
51 | return new Response(await stub.init(), {
52 | headers: {'Content-Type': 'text/html'},
53 | });
54 | },
55 | } satisfies ExportedHandler;
56 |
57 | type Messages = readonly (Message & {readonly sender: User | undefined})[];
58 |
59 | function render(messages: Messages) {
60 | let s = clearTerminal;
61 | s += cursorTo(0, 0);
62 |
63 | s += 'Sender'.padEnd(12) + 'Message'.padEnd(72) + 'Sent' + '\n';
64 | for (const message of messages) {
65 | s +=
66 | (message.sender?.name ?? 'Unknown').padEnd(12) +
67 | message.body.padEnd(72) +
68 | formatDate(message.timestamp) +
69 | '\n';
70 | }
71 |
72 | console.log(s);
73 | }
74 |
--------------------------------------------------------------------------------
/src/schema.ts:
--------------------------------------------------------------------------------
1 | // These data structures define your client-side schema.
2 | // They must be equal to or a subset of the server-side schema.
3 | // Note the "relationships" field, which defines first-class
4 | // relationships between tables.
5 | // See https://github.com/rocicorp/mono/blob/main/apps/zbugs/src/domain/schema.ts
6 | // for more complex examples, including many-to-many.
7 |
8 | import {
9 | createSchema,
10 | definePermissions,
11 | ExpressionBuilder,
12 | Row,
13 | ANYONE_CAN,
14 | table,
15 | string,
16 | boolean,
17 | number,
18 | relationships,
19 | PermissionsConfig,
20 | } from '@rocicorp/zero';
21 |
22 | const user = table('user')
23 | .columns({
24 | id: string(),
25 | name: string(),
26 | partner: boolean(),
27 | })
28 | .primaryKey('id');
29 |
30 | const message = table('message')
31 | .columns({
32 | id: string(),
33 | senderID: string().from('sender_id'),
34 | body: string(),
35 | timestamp: number(),
36 | })
37 | .primaryKey('id');
38 |
39 | const messageRelationships = relationships(message, ({one}) => ({
40 | sender: one({
41 | sourceField: ['senderID'],
42 | destSchema: user,
43 | destField: ['id'],
44 | }),
45 | }));
46 |
47 | export const schema = createSchema({
48 | tables: [user, message],
49 | relationships: [messageRelationships],
50 | });
51 |
52 | // The contents of your decoded JWT.
53 | type AuthData = {
54 | sub: string;
55 | };
56 |
57 | export type Schema = typeof schema;
58 | export type Message = Row;
59 | export type User = Row;
60 |
61 | export const permissions = definePermissions(schema, () => {
62 | const allowIfLoggedIn = (
63 | authData: AuthData,
64 | {cmpLit}: ExpressionBuilder,
65 | ) => cmpLit(authData.sub, 'IS NOT', null);
66 |
67 | const allowIfMessageSender = (
68 | authData: AuthData,
69 | {cmp}: ExpressionBuilder,
70 | ) => {
71 | return cmp('senderID', '=', authData.sub);
72 | };
73 |
74 | return {
75 | user: {
76 | row: {
77 | select: ANYONE_CAN,
78 | },
79 | },
80 | message: {
81 | row: {
82 | insert: ANYONE_CAN,
83 | update: {
84 | // only sender can edit their own messages
85 | preMutation: [allowIfMessageSender],
86 | // user can only set messages being from self
87 | postMutation: [allowIfMessageSender],
88 | },
89 | // must be logged in to delete
90 | delete: [allowIfLoggedIn],
91 | select: ANYONE_CAN,
92 | },
93 | },
94 | } satisfies PermissionsConfig;
95 | });
96 |
97 | export default {
98 | schema,
99 | permissions,
100 | };
101 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | We as members, contributors, and leaders pledge to make participation in our
6 | community a harassment-free experience for everyone, regardless of age, body
7 | size, visible or invisible disability, ethnicity, sex characteristics, gender
8 | identity and expression, level of experience, education, socio-economic status,
9 | nationality, personal appearance, race, religion, or sexual identity
10 | and orientation.
11 |
12 | We pledge to act and interact in ways that contribute to an open, welcoming,
13 | diverse, inclusive, and healthy community.
14 |
15 | ## Our Standards
16 |
17 | Examples of behavior that contributes to a positive environment for our
18 | community include:
19 |
20 | * Demonstrating empathy and kindness toward other people
21 | * Being respectful of differing opinions, viewpoints, and experiences
22 | * Giving and gracefully accepting constructive feedback
23 | * Accepting responsibility and apologizing to those affected by our mistakes,
24 | and learning from the experience
25 | * Focusing on what is best not just for us as individuals, but for the
26 | overall community
27 |
28 | Examples of unacceptable behavior include:
29 |
30 | * The use of sexualized language or imagery, and sexual attention or
31 | advances of any kind
32 | * Trolling, insulting or derogatory comments, and personal or political attacks
33 | * Public or private harassment
34 | * Publishing others' private information, such as a physical or email
35 | address, without their explicit permission
36 | * Other conduct which could reasonably be considered inappropriate in a
37 | professional setting
38 |
39 | ## Enforcement Responsibilities
40 |
41 | Community leaders are responsible for clarifying and enforcing our standards of
42 | acceptable behavior and will take appropriate and fair corrective action in
43 | response to any behavior that they deem inappropriate, threatening, offensive,
44 | or harmful.
45 |
46 | Community leaders have the right and responsibility to remove, edit, or reject
47 | comments, commits, code, wiki edits, issues, and other contributions that are
48 | not aligned to this Code of Conduct, and will communicate reasons for moderation
49 | decisions when appropriate.
50 |
51 | ## Scope
52 |
53 | This Code of Conduct applies within all community spaces, and also applies when
54 | an individual is officially representing the community in public spaces.
55 | Examples of representing our community include using an official e-mail address,
56 | posting via an official social media account, or acting as an appointed
57 | representative at an online or offline event.
58 |
59 | ## Enforcement
60 |
61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
62 | reported to the community leaders responsible for enforcement at
63 | hello@roci.dev.
64 | All complaints will be reviewed and investigated promptly and fairly.
65 |
66 | All community leaders are obligated to respect the privacy and security of the
67 | reporter of any incident.
68 |
69 | ## Enforcement Guidelines
70 |
71 | Community leaders will follow these Community Impact Guidelines in determining
72 | the consequences for any action they deem in violation of this Code of Conduct:
73 |
74 | ### 1. Correction
75 |
76 | **Community Impact**: Use of inappropriate language or other behavior deemed
77 | unprofessional or unwelcome in the community.
78 |
79 | **Consequence**: A private, written warning from community leaders, providing
80 | clarity around the nature of the violation and an explanation of why the
81 | behavior was inappropriate. A public apology may be requested.
82 |
83 | ### 2. Warning
84 |
85 | **Community Impact**: A violation through a single incident or series
86 | of actions.
87 |
88 | **Consequence**: A warning with consequences for continued behavior. No
89 | interaction with the people involved, including unsolicited interaction with
90 | those enforcing the Code of Conduct, for a specified period of time. This
91 | includes avoiding interactions in community spaces as well as external channels
92 | like social media. Violating these terms may lead to a temporary or
93 | permanent ban.
94 |
95 | ### 3. Temporary Ban
96 |
97 | **Community Impact**: A serious violation of community standards, including
98 | sustained inappropriate behavior.
99 |
100 | **Consequence**: A temporary ban from any sort of interaction or public
101 | communication with the community for a specified period of time. No public or
102 | private interaction with the people involved, including unsolicited interaction
103 | with those enforcing the Code of Conduct, is allowed during this period.
104 | Violating these terms may lead to a permanent ban.
105 |
106 | ### 4. Permanent Ban
107 |
108 | **Community Impact**: Demonstrating a pattern of violation of community
109 | standards, including sustained inappropriate behavior, harassment of an
110 | individual, or aggression toward or disparagement of classes of individuals.
111 |
112 | **Consequence**: A permanent ban from any sort of public interaction within
113 | the community.
114 |
115 | ## Attribution
116 |
117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118 | version 2.0, available at
119 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
120 |
121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct
122 | enforcement ladder](https://github.com/mozilla/diversity).
123 |
124 | [homepage]: https://www.contributor-covenant.org
125 |
126 | For answers to common questions about this code of conduct, see the FAQ at
127 | https://www.contributor-covenant.org/faq. Translations are available at
128 | https://www.contributor-covenant.org/translations.
129 |
--------------------------------------------------------------------------------
/src/App.tsx:
--------------------------------------------------------------------------------
1 | import {escapeLike} from '@rocicorp/zero';
2 | import {useQuery, useZero} from '@rocicorp/zero/react';
3 | import Cookies from 'js-cookie';
4 | import {MouseEvent, useState} from 'react';
5 | import {formatDate} from './date';
6 | import {randInt} from './rand';
7 | import {Schema} from './schema';
8 | import {randomMessage} from './test-data';
9 | import {useInterval} from './use-interval';
10 |
11 | function App() {
12 | const z = useZero();
13 | const [users] = useQuery(z.query.user);
14 |
15 | const [filterUser, setFilterUser] = useState('');
16 | const [filterText, setFilterText] = useState('');
17 |
18 | const all = z.query.message;
19 | const [allMessages] = useQuery(all);
20 |
21 | let filtered = all
22 | .related('sender', sender => sender.one())
23 | .orderBy('timestamp', 'desc');
24 |
25 | if (filterUser) {
26 | filtered = filtered.where('senderID', filterUser);
27 | }
28 |
29 | if (filterText) {
30 | filtered = filtered.where('body', 'LIKE', `%${escapeLike(filterText)}%`);
31 | }
32 |
33 | filtered = filtered.orderBy('timestamp', 'desc');
34 |
35 | const [filteredMessages] = useQuery(filtered);
36 |
37 | const hasFilters = filterUser || filterText;
38 | const [action, setAction] = useState<'add' | 'remove' | undefined>(undefined);
39 |
40 | useInterval(
41 | () => {
42 | if (!handleAction()) {
43 | setAction(undefined);
44 | }
45 | },
46 | action !== undefined ? 1000 / 60 : null,
47 | );
48 |
49 | const handleAction = () => {
50 | if (action === undefined) {
51 | return false;
52 | }
53 | if (action === 'add') {
54 | z.mutate.message.insert(randomMessage(users));
55 | return true;
56 | } else {
57 | if (allMessages.length === 0) {
58 | return false;
59 | }
60 | const index = randInt(allMessages.length);
61 | z.mutate.message.delete({id: allMessages[index].id});
62 | return true;
63 | }
64 | };
65 |
66 | const addMessages = () => setAction('add');
67 |
68 | const removeMessages = (e: MouseEvent) => {
69 | if (z.userID === 'anon' && !e.shiftKey) {
70 | alert(
71 | 'You must be logged in to delete. Hold the shift key to try anyway.',
72 | );
73 | return;
74 | }
75 | setAction('remove');
76 | };
77 |
78 | const stopAction = () => setAction(undefined);
79 |
80 | const editMessage = (
81 | e: MouseEvent,
82 | id: string,
83 | senderID: string,
84 | prev: string,
85 | ) => {
86 | if (senderID !== z.userID && !e.shiftKey) {
87 | alert(
88 | "You aren't logged in as the sender of this message. Editing won't be permitted. Hold the shift key to try anyway.",
89 | );
90 | return;
91 | }
92 | const body = prompt('Edit message', prev);
93 | z.mutate.message.update({
94 | id,
95 | body: body ?? prev,
96 | });
97 | };
98 |
99 | const toggleLogin = async () => {
100 | if (z.userID === 'anon') {
101 | await fetch('/api/login');
102 | } else {
103 | Cookies.remove('jwt');
104 | }
105 | location.reload();
106 | };
107 |
108 | // If initial sync hasn't completed, these can be empty.
109 | if (!users.length) {
110 | return null;
111 | }
112 |
113 | const user = users.find(user => user.id === z.userID)?.name ?? 'anon';
114 |
115 | return (
116 | <>
117 |
118 |
119 |
120 | Add Messages
121 |
122 |
123 | Remove Messages
124 |
125 | (hold buttons to repeat)
126 |
127 |
132 | {user === 'anon' ? '' : `Logged in as ${user}`}
133 | toggleLogin()}>
134 | {user === 'anon' ? 'Login' : 'Logout'}
135 |
136 |
137 |
138 |
139 |
140 | From:
141 | setFilterUser(e.target.value)}
143 | style={{flex: 1}}
144 | >
145 |
146 | Sender
147 |
148 | {users.map(user => (
149 |
150 | {user.name}
151 |
152 | ))}
153 |
154 |
155 |
156 | Contains:
157 | setFilterText(e.target.value)}
161 | style={{flex: 1}}
162 | />
163 |
164 |
165 |
166 |
167 | {!hasFilters ? (
168 | <>Showing all {filteredMessages.length} messages>
169 | ) : (
170 | <>
171 | Showing {filteredMessages.length} of {allMessages.length}{' '}
172 | messages. Try opening{' '}
173 |
174 | another tab
175 | {' '}
176 | to see them all!
177 | >
178 | )}
179 |
180 |
181 | {filteredMessages.length === 0 ? (
182 |
183 | No posts found 😢
184 |
185 | ) : (
186 |
187 |
188 |
189 | Sender
190 | Message
191 | Sent
192 | Edit
193 |
194 |
195 |
196 | {filteredMessages.map(message => (
197 |
198 | {message.sender?.name}
199 | {message.body}
200 | {formatDate(message.timestamp)}
201 |
203 | editMessage(e, message.id, message.senderID, message.body)
204 | }
205 | >
206 | ✏️
207 |
208 |
209 | ))}
210 |
211 |
212 | )}
213 | >
214 | );
215 | }
216 |
217 | export default App;
218 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------