feat: add zero
This commit is contained in:
10
shared/package.json
Normal file
10
shared/package.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "@money/shared",
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
"exports": {
|
||||
".": "./src/index.ts",
|
||||
"./auth": "./src/auth.ts"
|
||||
}
|
||||
}
|
||||
25
shared/src/auth.ts
Normal file
25
shared/src/auth.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const sessionSchema = z.object({
|
||||
id: z.string(),
|
||||
userId: z.string(),
|
||||
expiresAt: z.date(),
|
||||
});
|
||||
|
||||
export const userSchema = z.object({
|
||||
id: z.string(),
|
||||
email: z.string(),
|
||||
emailVerified: z.boolean(),
|
||||
name: z.string(),
|
||||
createdAt: z.date(),
|
||||
updatedAt: z.date(),
|
||||
});
|
||||
|
||||
export const authDataSchema = z.object({
|
||||
session: sessionSchema,
|
||||
user: userSchema,
|
||||
});
|
||||
|
||||
export type Session = z.infer<typeof sessionSchema>;
|
||||
export type User = z.infer<typeof userSchema>;
|
||||
export type AuthData = z.infer<typeof authDataSchema>;
|
||||
2
shared/src/index.ts
Normal file
2
shared/src/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from "./schema";
|
||||
export * from "./queries";
|
||||
9
shared/src/queries.ts
Normal file
9
shared/src/queries.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { syncedQuery } from "@rocicorp/zero";
|
||||
import { z } from "zod";
|
||||
import { builder } from "@money/shared";
|
||||
|
||||
export const queries = {
|
||||
allTransactions: syncedQuery('allTransactions', z.tuple([]), () =>
|
||||
builder.transaction.limit(10)
|
||||
),
|
||||
};
|
||||
24
shared/src/schema.ts
Normal file
24
shared/src/schema.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { createSchema, table, string, number, createBuilder, definePermissions } from "@rocicorp/zero";
|
||||
|
||||
const transaction = table('transaction')
|
||||
.columns({
|
||||
id: string(),
|
||||
user_id: string(),
|
||||
name: string(),
|
||||
amount: number(),
|
||||
})
|
||||
.primaryKey('id');
|
||||
|
||||
export const schema = createSchema({
|
||||
tables: [transaction],
|
||||
enableLegacyMutators: false,
|
||||
enableLegacyQueries: false,
|
||||
});
|
||||
|
||||
export const builder = createBuilder(schema);
|
||||
|
||||
export const permissions = definePermissions(schema, () => ({}));
|
||||
|
||||
export type Schema = typeof schema;
|
||||
|
||||
|
||||
15
shared/tsconfig.json
Normal file
15
shared/tsconfig.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2022",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Bundler",
|
||||
"declaration": true,
|
||||
"outDir": "./dist",
|
||||
"strict": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"rootDir": "."
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
Reference in New Issue
Block a user