Skip to content

Commit

Permalink
added convex
Browse files Browse the repository at this point in the history
  • Loading branch information
Edantuti committed Oct 11, 2024
1 parent bd7bfc6 commit 8ba4936
Show file tree
Hide file tree
Showing 10 changed files with 203 additions and 18 deletions.
11 changes: 10 additions & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ android {
keyAlias 'androiddebugkey'
keyPassword 'android'
}
release {
if(project.hasProperty('MYAPP_UPLOAD_STORE_FILE')){

storeFile file(MYAPP_UPLOAD_STORE_FILE)
storePassword MYAPP_UPLOAD_STORE_PASSWORD
keyAlias MYAPP_UPLOAD_KEY_ALIAS
keyPassword MYAPP_UPLOAD_KEY_PASSWORD
}
}
}
buildTypes {
debug {
Expand All @@ -100,7 +109,7 @@ android {
release {
// Caution! In production, you need to generate your own keystore file.
// see https://reactnative.dev/docs/signed-apk-android.
signingConfig signingConfigs.debug
signingConfig signingConfigs.release
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
Expand Down
6 changes: 6 additions & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@ newArchEnabled=false
# Use this property to enable or disable the Hermes JS engine.
# If set to false, you will be using JSC instead.
hermesEnabled=true


MYAPP_UPLOAD_STORE_FILE=my-upload-key.keystore
MYAPP_UPLOAD_KEY_ALIAS=my-key-alias
MYAPP_UPLOAD_STORE_PASSWORD=123456
MYAPP_UPLOAD_KEY_PASSWORD=123456
9 changes: 8 additions & 1 deletion convex/_generated/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import type {
FilterApi,
FunctionReference,
} from "convex/server";
import type * as functions from "../functions.js";
import type * as message from "../message.js";
import type * as types from "../types.js";

/**
* A utility for referencing Convex functions in your app's API.
Expand All @@ -24,7 +27,11 @@ import type {
* const myFunctionReference = api.myModule.myFunction;
* ```
*/
declare const fullApi: ApiFromModules<{}>;
declare const fullApi: ApiFromModules<{
functions: typeof functions;
message: typeof message;
types: typeof types;
}>;
export declare const api: FilterApi<
typeof fullApi,
FunctionReference<any, "public">
Expand Down
34 changes: 18 additions & 16 deletions convex/_generated/dataModel.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@
* @module
*/

import { AnyDataModel } from "convex/server";
import type {
DataModelFromSchemaDefinition,
DocumentByName,
TableNamesInDataModel,
SystemTableNames,
} from "convex/server";
import type { GenericId } from "convex/values";

/**
* No `schema.ts` file found!
*
* This generated code has permissive types like `Doc = any` because
* Convex doesn't know your schema. If you'd like more type safety, see
* https://docs.convex.dev/using/schemas for instructions on how to add a
* schema file.
*
* After you change a schema, rerun codegen with `npx convex dev`.
*/
import schema from "../schema.js";

/**
* The names of all of your Convex tables.
*/
export type TableNames = string;
export type TableNames = TableNamesInDataModel<DataModel>;

/**
* The type of a document stored in Convex.
*
* @typeParam TableName - A string literal type of the table name (like "users").
*/
export type Doc = any;
export type Doc<TableName extends TableNames> = DocumentByName<
DataModel,
TableName
>;

/**
* An identifier for a document in Convex.
Expand All @@ -44,8 +44,10 @@ export type Doc = any;
*
* IDs are just strings at runtime, but this type can be used to distinguish them from other
* strings when type checking.
*
* @typeParam TableName - A string literal type of the table name (like "users").
*/
export type Id<TableName extends TableNames = TableNames> =
export type Id<TableName extends TableNames | SystemTableNames> =
GenericId<TableName>;

/**
Expand All @@ -57,6 +59,6 @@ export type Id<TableName extends TableNames = TableNames> =
* This type is used to parameterize methods like `queryGeneric` and
* `mutationGeneric` to make them type-safe.
*/
export type DataModel = AnyDataModel;
export type DataModel = DataModelFromSchemaDefinition<typeof schema>;

/* prettier-ignore-end */
62 changes: 62 additions & 0 deletions convex/functions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { entsTableFactory } from "convex-ents";
import {
customAction,
customCtx,
customMutation,
customQuery,
} from "convex-helpers/server/customFunctions";
import { GenericDatabaseReader, GenericDatabaseWriter } from "convex/server";
import { DataModel } from "./_generated/dataModel";
import {
internalMutation as baseInternalMutation,
internalQuery as baseInternalQuery,
mutation as baseMutation,
query as baseQuery,
} from "./_generated/server";
import { entDefinitions } from "./schema";

type LegacyTables = "messages" | "users";

export const query = customQuery(
baseQuery,
customCtx(async (ctx) => {
return {
table: entsTableFactory(ctx, entDefinitions),
db: ctx.db as unknown as GenericDatabaseReader<
Pick<DataModel, LegacyTables>
>,
};
}),
);

export const internalQuery = customQuery(
baseInternalQuery,
customCtx(async (ctx) => {
return {
table: entsTableFactory(ctx, entDefinitions),
db: ctx.db as unknown as GenericDatabaseReader<
Pick<DataModel, LegacyTables>
>,
};
}),
);

export const mutation = customMutation(
baseMutation,
customCtx(async (ctx) => {
return {
table: entsTableFactory(ctx, entDefinitions),
db: ctx.db as GenericDatabaseWriter<Pick<DataModel, LegacyTables>>,
};
}),
);

export const internalMutation = customMutation(
baseInternalMutation,
customCtx(async (ctx) => {
return {
table: entsTableFactory(ctx, entDefinitions),
db: ctx.db as GenericDatabaseWriter<Pick<DataModel, LegacyTables>>,
};
}),
);
17 changes: 17 additions & 0 deletions convex/message.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { v } from "convex/values";
import { mutation, query } from "./functions";

export const getMessageByGroupId = query({
args:{id:v.id('groups')},
handler:async (ctx, args)=>{
return await ctx.table('messages').filter((q)=>q.eq(q.field('groupId'), args.id));
}
})


export const createMessage = mutation({
args:{content:v.string(), to:v.id('users'), from:v.id('users')},
handler:async (ctx, args) => {

}
})
31 changes: 31 additions & 0 deletions convex/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { defineEnt, defineEntSchema, getEntDefinitions } from "convex-ents";
import { v } from "convex/values";

const schema = defineEntSchema({
users:defineEnt({
name:v.string(),
description: v.string(),
email:v.string(),
publicKey:v.string(),
}).edge('session').edges('group', {to:'groups', table:"groupchat"}),

messages:defineEnt({
content:v.string()
}).edge('group'),

sessions:defineEnt({
deviceId:v.string(),
}).edge('user'),

groups: defineEnt({
name:v.string(),
description:v.string(),
isDm:v.boolean(),
owner:v.optional(v.id('users'))
}).edge('message').edges('user', {to:'users', table:"groupchat"})
})

export default schema;

export const entDefinitions = getEntDefinitions(schema);

17 changes: 17 additions & 0 deletions convex/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { GenericEnt, GenericEntWriter } from "convex-ents";
import { CustomCtx } from "convex-helpers/server/customFunctions";
import { TableNames } from "./_generated/dataModel";
import { mutation, query } from "./functions";
import { entDefinitions } from "./schema";

export type QueryCtx = CustomCtx<typeof query>;
export type MutationCtx = CustomCtx<typeof mutation>;

export type Ent<TableName extends TableNames> = GenericEnt<
typeof entDefinitions,
TableName
>;
export type EntWriter<TableName extends TableNames> = GenericEntWriter<
typeof entDefinitions,
TableName
>;
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
},
"dependencies": {
"convex": "^1.16.4",
"convex-ents": "^0.11.0",
"convex-helpers": "^0.1.60",
"react": "18.3.1",
"react-native": "0.75.4",
"react-native-get-random-values": "^1.11.0",
Expand Down
32 changes: 32 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3102,6 +3102,8 @@ __metadata:
"@types/react-test-renderer": ^18.0.0
babel-jest: ^29.6.3
convex: ^1.16.4
convex-ents: ^0.11.0
convex-helpers: ^0.1.60
eslint: ^8.19.0
jest: ^29.6.3
prettier: 2.8.8
Expand Down Expand Up @@ -4050,6 +4052,36 @@ __metadata:
languageName: node
linkType: hard

"convex-ents@npm:^0.11.0":
version: 0.11.0
resolution: "convex-ents@npm:0.11.0"
peerDependencies:
convex: ^1.13.0
checksum: a9e58dba551e543a50fa530fa83b373a4f726367d7b9a567fdf67cd8e73c5f6303eaaaaede4cda322f522509da11b334aa25a8ada1768f8ce8d587b354be331d
languageName: node
linkType: hard

"convex-helpers@npm:^0.1.60":
version: 0.1.60
resolution: "convex-helpers@npm:0.1.60"
peerDependencies:
convex: ^1.13.0
hono: ^4.0.5
react: ^17.0.2 || ^18.0.0
zod: ^3.22.4
peerDependenciesMeta:
hono:
optional: true
react:
optional: true
zod:
optional: true
bin:
convex-helpers: bin.cjs
checksum: 3345e8a8235840ee42011289966e1c0d44230812ba0f57a0870711c339d346dc86a9b92539a28d43f6304cf5dbe9b417c8c3cd8949d43d2fff6373908768c400
languageName: node
linkType: hard

"convex@npm:^1.16.4":
version: 1.16.4
resolution: "convex@npm:1.16.4"
Expand Down

0 comments on commit 8ba4936

Please sign in to comment.