@vite-hub/comments 0.0.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +291 -0
- package/dist/anchor.d.ts +43 -0
- package/dist/anchor.js +133 -0
- package/dist/client-diagnostics-CcFpkbAk.js +40 -0
- package/dist/client.d.ts +176 -0
- package/dist/client.js +738 -0
- package/dist/console-h4KlhIik.d.ts +332 -0
- package/dist/context-BqIsmYP1.js +61 -0
- package/dist/database/postgres.d.ts +1402 -0
- package/dist/database/postgres.js +81 -0
- package/dist/database-CA1aHKN7.d.ts +1495 -0
- package/dist/database.d.ts +12 -0
- package/dist/database.js +2 -0
- package/dist/define-43mMR39K.js +89 -0
- package/dist/define-B3TF9zzn.d.ts +204 -0
- package/dist/errors-4gelGVmK.js +57 -0
- package/dist/errors-C6qptPoG.js +135 -0
- package/dist/errors-CyQyKAvy.d.ts +185 -0
- package/dist/fold-name-B7Zb3-MF.js +7 -0
- package/dist/identity-CBOzgxSf.js +39 -0
- package/dist/index-DNhy69Wt.d.ts +83 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +196 -0
- package/dist/install-BcMPgPk_.js +1154 -0
- package/dist/install-W9ghhGoh.d.ts +36 -0
- package/dist/installed-B-PfERBU.js +30 -0
- package/dist/invariant-D8_xBqmZ.js +22 -0
- package/dist/migrate-B0k_0swk.d.ts +54 -0
- package/dist/migrate-BDQ8xqUs.js +289 -0
- package/dist/object-Da1zyPCR.js +11 -0
- package/dist/operations-D4A1Fcgf.d.ts +160 -0
- package/dist/operations-DMMIfYPW.js +1159 -0
- package/dist/operations-GLeOqgMt.d.ts +257 -0
- package/dist/operations.d.ts +3 -0
- package/dist/operations.js +3 -0
- package/dist/overlay/client-DmsSMOzi.js +4 -0
- package/dist/overlay/dist-BoHMOFax.js +14 -0
- package/dist/overlay/dist-yIZmvSaU.js +1 -0
- package/dist/overlay/overlay.js +201 -0
- package/dist/page/loader.js +142 -0
- package/dist/page-B41ozN63.js +40 -0
- package/dist/page-DtbMOEMd.d.ts +22 -0
- package/dist/page-tools-shared-NHUjKI8E.js +117 -0
- package/dist/path--zk6PEMz.js +18 -0
- package/dist/plugin-PS8PMYus.js +74 -0
- package/dist/realtime.d.ts +12 -0
- package/dist/realtime.js +47 -0
- package/dist/rpc-HBcWtg0T.d.ts +17 -0
- package/dist/rpc-RKPAusHp.js +153 -0
- package/dist/rpc.d.ts +2 -0
- package/dist/rpc.js +2 -0
- package/dist/runtime/auth.d.ts +8 -0
- package/dist/runtime/auth.js +18 -0
- package/dist/runtime/connect/node.d.ts +1 -0
- package/dist/runtime/connect/node.js +2 -0
- package/dist/runtime/connect.d.ts +1 -0
- package/dist/runtime/connect.js +2 -0
- package/dist/runtime/console.d.ts +5 -0
- package/dist/runtime/console.js +64 -0
- package/dist/runtime/index.d.ts +270 -0
- package/dist/runtime/index.js +1113 -0
- package/dist/server-D8k-0GXe.js +72 -0
- package/dist/server.d.ts +20 -0
- package/dist/server.js +7 -0
- package/dist/service-CFVm23k7.d.ts +158 -0
- package/dist/service-GHhhyQj4.js +609 -0
- package/dist/session-DVx-1Tym.d.ts +14 -0
- package/dist/session-EkudzUmm.js +503 -0
- package/dist/testing.d.ts +30 -0
- package/dist/testing.js +187 -0
- package/dist/tokens-DSbwkVSy.js +58 -0
- package/dist/types-BIS0hCEl.d.ts +124 -0
- package/dist/types-CZujrMFd.d.ts +322 -0
- package/dist/vite.d.ts +308 -0
- package/dist/vite.js +1660 -0
- package/package.json +153 -4
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { t as commentsErrorDiagnostics } from "./errors-C6qptPoG.js";
|
|
2
|
+
//#region src/operations-core/server.ts
|
|
3
|
+
const key = Symbol.for("vitehub.comments.runtime");
|
|
4
|
+
const scope = globalThis;
|
|
5
|
+
/**
|
|
6
|
+
* Install the runtime that the comment operations use. `installComments()` calls this; the generated Nitro plugin
|
|
7
|
+
* passes a function that builds the runtime on first use.
|
|
8
|
+
*/
|
|
9
|
+
function installCommentsRuntime(runtime) {
|
|
10
|
+
scope[key] = runtime;
|
|
11
|
+
}
|
|
12
|
+
/** The installed runtime, or `COMMENTS_R0010` with status 503. */
|
|
13
|
+
async function commentsRuntime() {
|
|
14
|
+
const installed = scope[key];
|
|
15
|
+
if (!installed) throw Object.assign(commentsErrorDiagnostics.COMMENTS_R0010(), { status: 503 });
|
|
16
|
+
if (installed instanceof Function) {
|
|
17
|
+
const built = await installed();
|
|
18
|
+
scope[key] = built;
|
|
19
|
+
return built;
|
|
20
|
+
}
|
|
21
|
+
return installed;
|
|
22
|
+
}
|
|
23
|
+
function hasCommentsRuntime() {
|
|
24
|
+
return scope[key] !== void 0;
|
|
25
|
+
}
|
|
26
|
+
function toUser(record) {
|
|
27
|
+
const id = typeof record.id === "string" ? record.id : void 0;
|
|
28
|
+
if (!id) return void 0;
|
|
29
|
+
const name = typeof record.name === "string" && record.name ? record.name : void 0;
|
|
30
|
+
const image = typeof record.image === "string" && record.image ? record.image : void 0;
|
|
31
|
+
return {
|
|
32
|
+
id,
|
|
33
|
+
...name ? { name } : {},
|
|
34
|
+
...image ? { image } : {}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/** People from a Better Auth instance, through its internal adapter. The generated Nitro plugin passes it when the app has Auth. */
|
|
38
|
+
function createAuthUsers(getAuth) {
|
|
39
|
+
const adapter = async () => (await (await getAuth()).$context).internalAdapter;
|
|
40
|
+
return {
|
|
41
|
+
async byIds(ids) {
|
|
42
|
+
if (!ids.length) return [];
|
|
43
|
+
return (await (await adapter()).listUsers(ids.length, 0, void 0, [{
|
|
44
|
+
field: "id",
|
|
45
|
+
operator: "in",
|
|
46
|
+
value: [...ids]
|
|
47
|
+
}])).flatMap((record) => {
|
|
48
|
+
const person = toUser(record);
|
|
49
|
+
return person ? [{
|
|
50
|
+
...record,
|
|
51
|
+
...person
|
|
52
|
+
}] : [];
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
async search(query, limit) {
|
|
56
|
+
return (await (await adapter()).listUsers(limit, 0, void 0, [{
|
|
57
|
+
field: "name",
|
|
58
|
+
operator: "contains",
|
|
59
|
+
value: query,
|
|
60
|
+
mode: "insensitive"
|
|
61
|
+
}])).flatMap((record) => {
|
|
62
|
+
const person = toUser(record);
|
|
63
|
+
return person ? [{
|
|
64
|
+
...record,
|
|
65
|
+
...person
|
|
66
|
+
}] : [];
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
export { installCommentsRuntime as i, createAuthUsers as n, hasCommentsRuntime as r, commentsRuntime as t };
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { d as CommentsPeople, x as validateCommentsDefinition } from "./define-B3TF9zzn.js";
|
|
2
|
+
import { a as maximumCommentBodyLength, c as CommentsTables, i as CommentsRuntime, l as createCommentsStore, n as CommentsAttachmentStore, o as CommentsDatabase, r as CommentsForgeHooks, s as CommentsStore } from "./service-CFVm23k7.js";
|
|
3
|
+
import { a as commentsOperations, i as commentInputSchemas, n as commentActions, r as commentAnchorSchema, t as CommentsCaller } from "./operations-GLeOqgMt.js";
|
|
4
|
+
import { n as createRpcTransport, t as RpcTransportOptions } from "./rpc-HBcWtg0T.js";
|
|
5
|
+
import { n as installComments, t as InstallCommentsOptions } from "./install-W9ghhGoh.js";
|
|
6
|
+
//#region src/operations-core/server.d.ts
|
|
7
|
+
/** Where mentions find people. The same shape as `defineComments({ people })`. */
|
|
8
|
+
export type CommentsUsers = CommentsPeople;
|
|
9
|
+
/**
|
|
10
|
+
* Install the runtime that the comment operations use. `installComments()` calls this; the generated Nitro plugin
|
|
11
|
+
* passes a function that builds the runtime on first use.
|
|
12
|
+
*/
|
|
13
|
+
export declare function installCommentsRuntime(runtime: CommentsRuntime | (() => CommentsRuntime | Promise<CommentsRuntime>)): void;
|
|
14
|
+
/** The installed runtime, or `COMMENTS_R0010` with status 503. */
|
|
15
|
+
export declare function commentsRuntime(): Promise<CommentsRuntime>;
|
|
16
|
+
export declare function hasCommentsRuntime(): boolean;
|
|
17
|
+
/** People from a Better Auth instance, through its internal adapter. The generated Nitro plugin passes it when the app has Auth. */
|
|
18
|
+
export declare function createAuthUsers(getAuth: () => object | Promise<object>): CommentsPeople;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { type CommentsAttachmentStore, CommentsCaller, type CommentsDatabase, type CommentsForgeHooks, type CommentsRuntime, type CommentsStore, type CommentsTables, type InstallCommentsOptions, RpcTransportOptions, commentActions, commentAnchorSchema, commentInputSchemas, commentsOperations, createCommentsStore, createRpcTransport, installComments, maximumCommentBodyLength, validateCommentsDefinition };
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { r as createCommentsStore, t as installComments } from "./install-BcMPgPk_.js";
|
|
2
|
+
import { i as commentsOperations, n as commentAnchorSchema, r as commentInputSchemas, t as commentActions } from "./operations-DMMIfYPW.js";
|
|
3
|
+
import { t as createRpcTransport } from "./rpc-RKPAusHp.js";
|
|
4
|
+
import { u as maximumCommentBodyLength } from "./service-GHhhyQj4.js";
|
|
5
|
+
import { c as validateCommentsDefinition } from "./define-43mMR39K.js";
|
|
6
|
+
import { i as installCommentsRuntime, n as createAuthUsers, r as hasCommentsRuntime, t as commentsRuntime } from "./server-D8k-0GXe.js";
|
|
7
|
+
export { commentActions, commentAnchorSchema, commentInputSchemas, commentsOperations, commentsRuntime, createAuthUsers, createCommentsStore, createRpcTransport, hasCommentsRuntime, installComments, installCommentsRuntime, maximumCommentBodyLength, validateCommentsDefinition };
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { S as CommentThread, _ as CommentMetadata, h as CommentListQuery, n as CommentActor, r as CommentAnchor, s as CommentContext, w as CommentUser, x as CommentSubject, y as CommentStatus } from "./types-CZujrMFd.js";
|
|
2
|
+
import { d as CommentsPeople, g as CommentsUser, l as CommentsDefinition } from "./define-B3TF9zzn.js";
|
|
3
|
+
import { i as commentThreads, r as commentMessages, t as commentCounters } from "./database-CA1aHKN7.js";
|
|
4
|
+
import "valibot";
|
|
5
|
+
import { LibSQLDatabase } from "drizzle-orm/libsql";
|
|
6
|
+
//#region ../internal/src/runtime/client-rate-limit.d.ts
|
|
7
|
+
/** The part of `checkRateLimit()` from `vite-hub/rate-limit` that a public write calls. */
|
|
8
|
+
type SharedRateLimit = (request: Request, name: string, options: {
|
|
9
|
+
key: string;
|
|
10
|
+
limit: number;
|
|
11
|
+
window: `${number}${"ms" | "s" | "m" | "h" | "d"}`;
|
|
12
|
+
}) => Promise<[unknown, {
|
|
13
|
+
allowed: boolean;
|
|
14
|
+
reason?: string;
|
|
15
|
+
retryAfter?: number;
|
|
16
|
+
cause?: unknown;
|
|
17
|
+
} | undefined]>;
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/operations-core/store.d.ts
|
|
20
|
+
/**
|
|
21
|
+
* The Drizzle database that the store uses. The store calls `select`, `insert`, `update`, and `delete` (with
|
|
22
|
+
* `onConflictDoNothing()` and `returning()`), which SQLite, libSQL, D1, and Postgres Drizzle databases all offer, and
|
|
23
|
+
* groups writes with `batch()` or `transaction()` when the driver has one. The Postgres tables have the same property
|
|
24
|
+
* names, so one set of queries serves every driver.
|
|
25
|
+
*/
|
|
26
|
+
type CommentsDatabase = LibSQLDatabase;
|
|
27
|
+
/** The tables to query: the ones of the Database schema, so Postgres uses its own. */
|
|
28
|
+
interface CommentsTables {
|
|
29
|
+
commentThreads: typeof commentThreads;
|
|
30
|
+
commentMessages: typeof commentMessages;
|
|
31
|
+
commentCounters: typeof commentCounters;
|
|
32
|
+
}
|
|
33
|
+
interface NewMessage {
|
|
34
|
+
actor?: CommentActor;
|
|
35
|
+
attachments: string[];
|
|
36
|
+
author: CommentUser;
|
|
37
|
+
body: string;
|
|
38
|
+
id: string;
|
|
39
|
+
mentions: string[];
|
|
40
|
+
now: number;
|
|
41
|
+
}
|
|
42
|
+
interface NewThread extends NewMessage {
|
|
43
|
+
anchor: CommentAnchor;
|
|
44
|
+
scope: string;
|
|
45
|
+
subject: CommentSubject;
|
|
46
|
+
threadId: string;
|
|
47
|
+
metadata?: CommentMetadata;
|
|
48
|
+
context?: CommentContext;
|
|
49
|
+
revision?: number;
|
|
50
|
+
/** The retry key. A second thread with the same key in the same scope is never inserted. */
|
|
51
|
+
requestId?: string;
|
|
52
|
+
}
|
|
53
|
+
/** What `list` filters by. `userId` is the signed-in user, for `mine` and `mentions`. */
|
|
54
|
+
type StoreListQuery = CommentListQuery & {
|
|
55
|
+
userId?: string;
|
|
56
|
+
scope?: string;
|
|
57
|
+
};
|
|
58
|
+
interface CommentsStore {
|
|
59
|
+
/** Newest first: by `updatedAt`, then `id`. `before` continues after the last thread of an earlier page. */
|
|
60
|
+
list: (query: StoreListQuery) => Promise<CommentThread[]>;
|
|
61
|
+
getById: (id: string) => Promise<CommentThread | null>;
|
|
62
|
+
getByNumber: (scope: string, n: number) => Promise<CommentThread | null>;
|
|
63
|
+
/** The thread that a `createThread` with this `requestId` stored in the scope. */
|
|
64
|
+
getByRequestId: (scope: string, requestId: string) => Promise<CommentThread | null>;
|
|
65
|
+
/** The thread that holds a message. */
|
|
66
|
+
getByMessage: (messageId: string) => Promise<CommentThread | null>;
|
|
67
|
+
/** Threads listing `key` in a page of matching messages. `cursor` continues after those candidates. */
|
|
68
|
+
getByAttachment: (key: string, cursor?: string) => Promise<{
|
|
69
|
+
threads: CommentThread[];
|
|
70
|
+
cursor?: string;
|
|
71
|
+
}>;
|
|
72
|
+
/**
|
|
73
|
+
* Inserts the thread and its first message together, with the next number of its scope. Several creators at once each
|
|
74
|
+
* get their own number, and a number is never handed out twice. With `requestId`, a thread of the scope that already
|
|
75
|
+
* has that key comes back instead, and nothing is inserted.
|
|
76
|
+
*/
|
|
77
|
+
createThread: (input: NewThread) => Promise<CommentThread>;
|
|
78
|
+
/**
|
|
79
|
+
* Adds a message. A resolved thread takes it only with `allowResolved`; otherwise it fails with `COMMENTS_R0016`,
|
|
80
|
+
* checked in the same statement as the insert.
|
|
81
|
+
*/
|
|
82
|
+
addMessage: (threadId: string, input: NewMessage, options?: {
|
|
83
|
+
allowResolved?: boolean;
|
|
84
|
+
}) => Promise<CommentThread>;
|
|
85
|
+
editMessage: (threadId: string, messageId: string, input: {
|
|
86
|
+
body: string;
|
|
87
|
+
mentions: string[];
|
|
88
|
+
now: number;
|
|
89
|
+
}) => Promise<CommentThread>;
|
|
90
|
+
deleteMessage: (threadId: string, messageId: string, now: number) => Promise<CommentThread>;
|
|
91
|
+
/** With `ownerId`, delete only if every message still belongs to that owner at mutation time. */
|
|
92
|
+
deleteThread: (threadId: string, ownerId?: string) => Promise<boolean>;
|
|
93
|
+
setStatus: (threadId: string, status: CommentStatus, by: CommentUser, now: number) => Promise<CommentThread>;
|
|
94
|
+
/** Deletes every thread of a scope with its messages, and returns their ids. Numbers of the scope are never reused. */
|
|
95
|
+
deleteScope: (scope: string) => Promise<string[]>;
|
|
96
|
+
/**
|
|
97
|
+
* The people that wrote in a thread, for a store without an Auth adapter. Only authors of threads that `canRead`
|
|
98
|
+
* accepts count, and a message without a thread never shows.
|
|
99
|
+
*/
|
|
100
|
+
knownUsers: (query: string, limit: number, canRead: (thread: CommentThread) => Promise<boolean>) => Promise<CommentUser[]>;
|
|
101
|
+
knownUsersByIds: (ids: readonly string[], canRead: (thread: CommentThread) => Promise<boolean>) => Promise<CommentUser[]>;
|
|
102
|
+
}
|
|
103
|
+
declare function createCommentsStore(database: CommentsDatabase, tables?: CommentsTables): CommentsStore;
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region src/operations-core/service.d.ts
|
|
106
|
+
/** Longest message, in characters. */
|
|
107
|
+
declare const maximumCommentBodyLength = 10000;
|
|
108
|
+
/** The parts of a Blob store that attachments use: `blob` of `@vite-hub/blob`. */
|
|
109
|
+
interface CommentsAttachmentStore {
|
|
110
|
+
put: (pathname: string, body: Uint8Array, options: {
|
|
111
|
+
contentType: string;
|
|
112
|
+
}) => Promise<readonly [unknown, unknown]>;
|
|
113
|
+
get?: (pathname: string) => Promise<readonly [unknown, Blob | null | undefined]>;
|
|
114
|
+
}
|
|
115
|
+
/** A file to answer, with the headers that keep a browser from running it. */
|
|
116
|
+
interface CommentsAttachmentBody {
|
|
117
|
+
key: string;
|
|
118
|
+
name: string;
|
|
119
|
+
/** The stored media type when Comments attaches that type, else `application/octet-stream`. */
|
|
120
|
+
type: string;
|
|
121
|
+
size: number;
|
|
122
|
+
/** Whether a browser may show it in the page: images other than SVG. */
|
|
123
|
+
inline: boolean;
|
|
124
|
+
data: Blob;
|
|
125
|
+
}
|
|
126
|
+
/** The pull request sync of `defineComments({ forge })`. */
|
|
127
|
+
interface CommentsForgeHooks {
|
|
128
|
+
/** Starts the sync of a thread after a change. */
|
|
129
|
+
changed: (threadId: string) => void;
|
|
130
|
+
/** The threads with their `forge` link. */
|
|
131
|
+
attach: (threads: CommentThread[]) => Promise<CommentThread[]>;
|
|
132
|
+
}
|
|
133
|
+
/** Everything that the comment operations, the server API, and the overlay API share. */
|
|
134
|
+
interface CommentsRuntime {
|
|
135
|
+
definition: CommentsDefinition;
|
|
136
|
+
/**
|
|
137
|
+
* The app's `identify`, given the server event of a call. With it, the comment operations ask it for the user, as
|
|
138
|
+
* the overlay API does, instead of taking the Console's user.
|
|
139
|
+
*/
|
|
140
|
+
identify?: (event: unknown) => Promise<CommentsUser | null>;
|
|
141
|
+
store: CommentsStore;
|
|
142
|
+
/** The Auth adapter. `people` wins over it. Without both, `@` finds the authors that the store knows. */
|
|
143
|
+
users?: CommentsPeople;
|
|
144
|
+
/** Vite's serve command, for the default guest policy. */
|
|
145
|
+
development?: boolean;
|
|
146
|
+
/** The Blob store for attachments, when the app has one and no `storeAttachment`. */
|
|
147
|
+
attachments?: CommentsAttachmentStore;
|
|
148
|
+
forge?: CommentsForgeHooks;
|
|
149
|
+
/**
|
|
150
|
+
* `checkRateLimit` of ViteHub Rate Limit, when it counts in a KV store that every server process shares. Guest writes
|
|
151
|
+
* then count under the Rate Limit name `comments`. Without it, they count in the memory of this process.
|
|
152
|
+
*/
|
|
153
|
+
rateLimit?: SharedRateLimit;
|
|
154
|
+
/** Work that runs after the answer, such as `onMention`. `flush()` of the server API waits for it. */
|
|
155
|
+
background?: (task: Promise<unknown>) => void;
|
|
156
|
+
}
|
|
157
|
+
//#endregion
|
|
158
|
+
export { maximumCommentBodyLength as a, CommentsTables as c, CommentsRuntime as i, createCommentsStore as l, CommentsAttachmentStore as n, CommentsDatabase as o, CommentsForgeHooks as r, CommentsStore as s, CommentsAttachmentBody as t, SharedRateLimit as u };
|