Skip to content

Commit

Permalink
[ps] add notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
a-type committed Feb 23, 2025
1 parent ad55263 commit 3b8478a
Show file tree
Hide file tree
Showing 23 changed files with 806 additions and 158 deletions.
115 changes: 112 additions & 3 deletions apps/post/verdant/src/client/client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export class Client<Presence = any, Profile = any> {
/** Collection access for Post. Load queries, put and delete documents. */
readonly posts: CollectionQueries<Post, PostInit, PostFilter>;

/** Collection access for Notebook. Load queries, put and delete documents. */
readonly notebooks: CollectionQueries<Notebook, NotebookInit, NotebookFilter>;

/**
* Turn on and off sync, or adjust the sync protocol and other settings.
*/
Expand Down Expand Up @@ -163,12 +166,15 @@ export type PostBodyMarks = ListEntity<
PostBodyMarksSnapshot
>;
export type PostCoverImage = EntityFile;
/** The ID of the notebook this post belongs to, if any. If null, the post is not in a notebook. */
export type PostNotebookId = string;
export type PostInit = {
id?: string;
createdAt?: number;
title: string;
body?: PostBodyInit;
coverImage?: File | null;
notebookId?: string | null;
};

export type PostBodyAttrsInit = { [key: string]: PostBodyAttrsValueInit };
Expand All @@ -189,13 +195,14 @@ export type PostDestructured = {
title: string;
body: PostBody;
coverImage: EntityFile | null;
notebookId: string | null;
};

export type PostBodyAttrsDestructured = {
[key: string]: PostBodyAttrsValue | undefined;
};
export type PostBodyContentDestructured = PostBodyDestructured[];
export type PostBodyMarksDestructured = PostBodyDestructured[];
export type PostBodyContentDestructured = PostBody[];
export type PostBodyMarksDestructured = PostBody[];
export type PostBodyDestructured = {
type: string;
from: number | null;
Expand All @@ -211,6 +218,7 @@ export type PostSnapshot = {
title: string;
body: PostBodySnapshot;
coverImage: EntityFileSnapshot | null;
notebookId: string | null;
};

export type PostBodyAttrsSnapshot = {
Expand Down Expand Up @@ -247,7 +255,108 @@ export interface PostCreatedAtRangeFilter {
lt?: number;
order?: "asc" | "desc";
}
export interface PostNotebookIdSortFilter {
where: "notebookId";
order: "asc" | "desc";
}
export interface PostNotebookIdMatchFilter {
where: "notebookId";
equals: string;
order?: "asc" | "desc";
}
export interface PostNotebookIdRangeFilter {
where: "notebookId";
gte?: string;
gt?: string;
lte?: string;
lt?: string;
order?: "asc" | "desc";
}
export interface PostNotebookIdStartsWithFilter {
where: "notebookId";
startsWith: string;
order?: "asc" | "desc";
}
export interface PostNotebookIdCreatedAtCompoundFilter {
where: "notebookId_createdAt";
match: {
notebookId: string | null;
createdAt?: number;
};
order?: "asc" | "desc";
}
export type PostFilter =
| PostCreatedAtSortFilter
| PostCreatedAtMatchFilter
| PostCreatedAtRangeFilter;
| PostCreatedAtRangeFilter
| PostNotebookIdSortFilter
| PostNotebookIdMatchFilter
| PostNotebookIdRangeFilter
| PostNotebookIdStartsWithFilter
| PostNotebookIdCreatedAtCompoundFilter;

/** Generated types for Notebook */

export type Notebook = ObjectEntity<
NotebookInit,
NotebookDestructured,
NotebookSnapshot
>;
export type NotebookId = string;
export type NotebookCreatedAt = number;
export type NotebookName = string;
export type NotebookCoverImage = EntityFile;
export type NotebookIcon = EntityFile;
export type NotebookInit = {
id?: string;
createdAt?: number;
name: string;
coverImage?: File | null;
icon?: File | null;
};

export type NotebookDestructured = {
id: string;
createdAt: number;
name: string;
coverImage: EntityFile | null;
icon: EntityFile | null;
};

export type NotebookSnapshot = {
id: string;
createdAt: number;
name: string;
coverImage: EntityFileSnapshot | null;
icon: EntityFileSnapshot | null;
};

/** Index filters for Notebook **/

export interface NotebookNameSortFilter {
where: "name";
order: "asc" | "desc";
}
export interface NotebookNameMatchFilter {
where: "name";
equals: string;
order?: "asc" | "desc";
}
export interface NotebookNameRangeFilter {
where: "name";
gte?: string;
gt?: string;
lte?: string;
lt?: string;
order?: "asc" | "desc";
}
export interface NotebookNameStartsWithFilter {
where: "name";
startsWith: string;
order?: "asc" | "desc";
}
export type NotebookFilter =
| NotebookNameSortFilter
| NotebookNameMatchFilter
| NotebookNameRangeFilter
| NotebookNameStartsWithFilter;
49 changes: 49 additions & 0 deletions apps/post/verdant/src/client/react.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import type {
EntityFile,
Post,
PostFilter,
Notebook,
NotebookFilter,
} from "./index.js";

type HookConfig<F> = {
Expand Down Expand Up @@ -188,6 +190,53 @@ export interface GeneratedHooks<Presence, Profile> {
Post[],
{ loadMore: () => void; hasMore: boolean; status: QueryStatus },
];

useNotebook(id: string, config?: { skip?: boolean }): Notebook | null;
useNotebookUnsuspended(
id: string,
config?: { skip?: boolean },
): { data: Notebook | null; status: QueryStatus };
useOneNotebook: <Config extends HookConfig<NotebookFilter>>(
config?: Config,
) => Notebook | null;
useOneNotebooksUnsuspended: <Config extends HookConfig<NotebookFilter>>(
config?: Config,
) => { data: Notebook | null; status: QueryStatus };
useAllNotebooks: <Config extends HookConfig<NotebookFilter>>(
config?: Config,
) => Notebook[];
useAllNotebooksUnsuspended: <Config extends HookConfig<NotebookFilter>>(
config?: Config,
) => { data: Notebook[]; status: QueryStatus };
useAllNotebooksPaginated: <
Config extends HookConfig<NotebookFilter> & {
pageSize?: number;
suspend?: false;
},
>(
config?: Config,
) => [
Notebook[],
{
next: () => void;
previous: () => void;
setPage: (page: number) => void;
hasNext: boolean;
hasPrevious: boolean;
status: QueryStatus;
},
];
useAllNotebooksInfinite: <
Config extends HookConfig<NotebookFilter> & {
pageSize?: number;
suspend?: false;
},
>(
config?: Config,
) => [
Notebook[],
{ loadMore: () => void; hasMore: boolean; status: QueryStatus },
];
}

type HookName = `use${string}`;
Expand Down
4 changes: 2 additions & 2 deletions apps/post/verdant/src/client/schema.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from "./schemaVersions/v1.js";
export { default } from "./schemaVersions/v1.js";
export * from "./schemaVersions/v2.js";
export { default } from "./schemaVersions/v2.js";
2 changes: 1 addition & 1 deletion apps/post/verdant/src/client/schema.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import schema from './schemaVersions/v1.js';
import schema from './schemaVersions/v2.js';
const finalSchema = { wip: false, ...schema };
export default finalSchema;
3 changes: 2 additions & 1 deletion apps/post/verdant/src/client/schemaVersions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* @generated - do not modify this file.
*/
import v1 from './v1.js';
import v2 from './v2.js';

export default [v1]
export default [v1, v2]

68 changes: 68 additions & 0 deletions apps/post/verdant/src/client/schemaVersions/v2.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { StorageSchema } from "@verdant-web/common";
declare const schema: StorageSchema;
export default schema;

export type PostSnapshot = {
id: string;
createdAt: number;
title: string;
body: PostBodySnapshot;
coverImage: EntityFileSnapshot | null;
notebookId: string | null;
};

export type PostBodyAttrsSnapshot = {
[key: string]: PostBodyAttrsValueSnapshot;
};
export type PostBodyContentSnapshot = PostBodySnapshot[];
export type PostBodyMarksSnapshot = PostBodySnapshot[];
export type PostBodySnapshot = {
type: string;
from: number | null;
to: number | null;
attrs: PostBodyAttrsSnapshot;
content: PostBodyContentSnapshot;
text: string | null;
marks: PostBodyMarksSnapshot;
};
export type PostInit = {
id?: string;
createdAt?: number;
title: string;
body?: PostBodyInit;
coverImage?: File | null;
notebookId?: string | null;
};

export type PostBodyAttrsInit = { [key: string]: PostBodyAttrsValueInit };
export type PostBodyContentInit = PostBodyInit[];
export type PostBodyMarksInit = PostBodyInit[];
export type PostBodyInit = {
type: string;
from?: number | null;
to?: number | null;
attrs?: PostBodyAttrsInit;
content?: PostBodyContentInit;
text?: string | null;
marks?: PostBodyMarksInit;
};

export type NotebookSnapshot = {
id: string;
createdAt: number;
name: string;
coverImage: EntityFileSnapshot | null;
icon: EntityFileSnapshot | null;
};
export type NotebookInit = {
id?: string;
createdAt?: number;
name: string;
coverImage?: File | null;
icon?: File | null;
};

export type MigrationTypes = {
posts: { init: PostInit; snapshot: PostSnapshot };
notebooks: { init: NotebookInit; snapshot: NotebookSnapshot };
};
73 changes: 73 additions & 0 deletions apps/post/verdant/src/client/schemaVersions/v2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/** @generated - do not modify this file. */

// src/schema.ts
import { schema } from "@verdant-web/store";
import { createTipTapFieldSchema } from "@verdant-web/tiptap";
var posts = schema.collection({
name: "post",
primaryKey: "id",
fields: {
id: schema.fields.id(),
createdAt: schema.fields.number({
default: () => Date.now()
}),
title: schema.fields.string(),
body: createTipTapFieldSchema({
default: {
type: "doc"
}
}),
coverImage: schema.fields.file({
nullable: true
}),
notebookId: schema.fields.string({
nullable: true,
documentation: "The ID of the notebook this post belongs to, if any. If null, the post is not in a notebook."
})
},
indexes: {
createdAt: {
field: "createdAt"
},
notebookId: {
field: "notebookId"
}
},
compounds: {
notebookId_createdAt: {
of: ["notebookId", "createdAt"]
}
}
});
var notebooks = schema.collection({
name: "notebook",
primaryKey: "id",
fields: {
id: schema.fields.id(),
createdAt: schema.fields.number({
default: () => Date.now()
}),
name: schema.fields.string(),
coverImage: schema.fields.file({
nullable: true
}),
icon: schema.fields.file({
nullable: true
})
},
indexes: {
name: {
field: "name"
}
}
});
var schema_default = schema({
version: 2,
collections: {
posts,
notebooks
}
});
export {
schema_default as default
};
3 changes: 2 additions & 1 deletion apps/post/verdant/src/migrations/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import v1 from "./v1.js";
import v2 from "./v2.js";

export default [v1];
export default [v1, v2];
Loading

0 comments on commit 3b8478a

Please sign in to comment.