@trestleinc/replicate 0.1.0 → 1.1.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.
Files changed (94) hide show
  1. package/README.md +356 -420
  2. package/dist/client/collection.d.ts +78 -76
  3. package/dist/client/errors.d.ts +59 -0
  4. package/dist/client/index.d.ts +22 -18
  5. package/dist/client/logger.d.ts +0 -1
  6. package/dist/client/merge.d.ts +77 -0
  7. package/dist/client/persistence/adapters/index.d.ts +8 -0
  8. package/dist/client/persistence/adapters/opsqlite.d.ts +46 -0
  9. package/dist/client/persistence/adapters/sqljs.d.ts +83 -0
  10. package/dist/client/persistence/index.d.ts +49 -0
  11. package/dist/client/persistence/indexeddb.d.ts +17 -0
  12. package/dist/client/persistence/memory.d.ts +16 -0
  13. package/dist/client/persistence/sqlite-browser.d.ts +51 -0
  14. package/dist/client/persistence/sqlite-level.d.ts +63 -0
  15. package/dist/client/persistence/sqlite-rn.d.ts +36 -0
  16. package/dist/client/persistence/sqlite.d.ts +47 -0
  17. package/dist/client/persistence/types.d.ts +42 -0
  18. package/dist/client/prose.d.ts +56 -0
  19. package/dist/client/replicate.d.ts +40 -0
  20. package/dist/client/services/checkpoint.d.ts +18 -0
  21. package/dist/client/services/reconciliation.d.ts +24 -0
  22. package/dist/component/_generated/api.d.ts +35 -0
  23. package/dist/component/_generated/api.js +3 -3
  24. package/dist/component/_generated/component.d.ts +89 -0
  25. package/dist/component/_generated/component.js +0 -0
  26. package/dist/component/_generated/dataModel.d.ts +45 -0
  27. package/dist/component/_generated/dataModel.js +0 -0
  28. package/{src → dist}/component/_generated/server.d.ts +9 -38
  29. package/dist/component/convex.config.d.ts +2 -2
  30. package/dist/component/convex.config.js +2 -1
  31. package/dist/component/logger.d.ts +8 -0
  32. package/dist/component/logger.js +30 -0
  33. package/dist/component/public.d.ts +36 -61
  34. package/dist/component/public.js +232 -58
  35. package/dist/component/schema.d.ts +32 -8
  36. package/dist/component/schema.js +19 -6
  37. package/dist/index.js +1553 -308
  38. package/dist/server/builder.d.ts +94 -0
  39. package/dist/server/index.d.ts +14 -17
  40. package/dist/server/schema.d.ts +17 -63
  41. package/dist/server/storage.d.ts +80 -0
  42. package/dist/server.js +268 -83
  43. package/dist/shared/index.d.ts +5 -0
  44. package/dist/shared/index.js +2 -0
  45. package/dist/shared/types.d.ts +50 -0
  46. package/dist/shared/types.js +6 -0
  47. package/dist/shared.js +6 -0
  48. package/package.json +59 -49
  49. package/src/client/collection.ts +877 -450
  50. package/src/client/errors.ts +45 -0
  51. package/src/client/index.ts +52 -26
  52. package/src/client/logger.ts +2 -28
  53. package/src/client/merge.ts +374 -0
  54. package/src/client/persistence/adapters/index.ts +8 -0
  55. package/src/client/persistence/adapters/opsqlite.ts +54 -0
  56. package/src/client/persistence/adapters/sqljs.ts +128 -0
  57. package/src/client/persistence/index.ts +54 -0
  58. package/src/client/persistence/indexeddb.ts +110 -0
  59. package/src/client/persistence/memory.ts +61 -0
  60. package/src/client/persistence/sqlite-browser.ts +107 -0
  61. package/src/client/persistence/sqlite-level.ts +407 -0
  62. package/src/client/persistence/sqlite-rn.ts +44 -0
  63. package/src/client/persistence/sqlite.ts +161 -0
  64. package/src/client/persistence/types.ts +49 -0
  65. package/src/client/prose.ts +369 -0
  66. package/src/client/replicate.ts +80 -0
  67. package/src/client/services/checkpoint.ts +86 -0
  68. package/src/client/services/reconciliation.ts +108 -0
  69. package/src/component/_generated/api.ts +52 -0
  70. package/src/component/_generated/component.ts +103 -0
  71. package/src/component/_generated/{dataModel.d.ts → dataModel.ts} +1 -1
  72. package/src/component/_generated/server.ts +161 -0
  73. package/src/component/convex.config.ts +3 -1
  74. package/src/component/logger.ts +36 -0
  75. package/src/component/public.ts +364 -111
  76. package/src/component/schema.ts +18 -5
  77. package/src/env.d.ts +31 -0
  78. package/src/server/builder.ts +85 -0
  79. package/src/server/index.ts +9 -24
  80. package/src/server/schema.ts +20 -76
  81. package/src/server/storage.ts +313 -0
  82. package/src/shared/index.ts +5 -0
  83. package/src/shared/types.ts +52 -0
  84. package/LICENSE.package +0 -201
  85. package/dist/client/storage.d.ts +0 -143
  86. package/dist/server/replication.d.ts +0 -122
  87. package/dist/server/ssr.d.ts +0 -79
  88. package/dist/ssr.js +0 -19
  89. package/src/client/storage.ts +0 -206
  90. package/src/component/_generated/api.d.ts +0 -95
  91. package/src/component/_generated/api.js +0 -23
  92. package/src/component/_generated/server.js +0 -90
  93. package/src/server/replication.ts +0 -244
  94. package/src/server/ssr.ts +0 -106
@@ -0,0 +1,63 @@
1
+ /**
2
+ * SQLite-backed abstract-level implementation.
3
+ *
4
+ * Provides a LevelDB-compatible key-value store backed by SQLite,
5
+ * enabling y-leveldb to work with SQLite databases.
6
+ *
7
+ * Supports both browser (sql.js WASM) and React Native (op-sqlite).
8
+ */
9
+ import { AbstractLevel, AbstractIterator, AbstractKeyIterator, AbstractValueIterator } from 'abstract-level';
10
+ /**
11
+ * Interface for SQLite database operations.
12
+ * Abstracts over sql.js (browser) and op-sqlite (React Native).
13
+ */
14
+ export interface SqliteAdapter {
15
+ execute(sql: string, params?: unknown[]): Promise<{
16
+ rows: Record<string, unknown>[];
17
+ }>;
18
+ close(): void;
19
+ }
20
+ interface SqliteLevelOptions {
21
+ /** Custom SQLite adapter (for testing or alternative backends) */
22
+ adapter?: SqliteAdapter;
23
+ /** Value encoding (default: 'utf8') */
24
+ valueEncoding?: string;
25
+ keyEncoding?: string;
26
+ }
27
+ /**
28
+ * SQLite-backed implementation of abstract-level.
29
+ *
30
+ * Uses a simple key-value table with lexicographic ordering:
31
+ * CREATE TABLE entries (key BLOB PRIMARY KEY, value BLOB)
32
+ */
33
+ export declare class SqliteLevel<K = string, V = string> extends AbstractLevel<K, V> {
34
+ private adapter;
35
+ private adapterFactory;
36
+ constructor(_location: string, options?: SqliteLevelOptions);
37
+ /**
38
+ * Set the adapter factory for deferred initialization.
39
+ * Call this before open() to configure the SQLite backend.
40
+ */
41
+ setAdapterFactory(factory: () => Promise<SqliteAdapter>): void;
42
+ _open(): Promise<void>;
43
+ _close(): Promise<void>;
44
+ _get(key: K): Promise<V | undefined>;
45
+ _put(key: K, value: V): Promise<void>;
46
+ _del(key: K): Promise<void>;
47
+ _batch(operations: Array<{
48
+ type: 'put';
49
+ key: K;
50
+ value: V;
51
+ } | {
52
+ type: 'del';
53
+ key: K;
54
+ }>): Promise<void>;
55
+ _clear(): Promise<void>;
56
+ _iterator(options: Record<string, unknown>): AbstractIterator<typeof this, K, V>;
57
+ _keys(options: Record<string, unknown>): AbstractKeyIterator<typeof this, K>;
58
+ _values(options: Record<string, unknown>): AbstractValueIterator<typeof this, K, V>;
59
+ private encodeKey;
60
+ private encodeValue;
61
+ private decodeValue;
62
+ }
63
+ export {};
@@ -0,0 +1,36 @@
1
+ /**
2
+ * React Native SQLite persistence helper using op-sqlite.
3
+ *
4
+ * @example
5
+ * ```typescript
6
+ * import { createReactNativeSqlitePersistence } from '@trestleinc/replicate/client';
7
+ * import { open } from '@op-engineering/op-sqlite';
8
+ *
9
+ * const db = open({ name: 'myapp.db' });
10
+ * const persistence = await createReactNativeSqlitePersistence(db, 'myapp');
11
+ * ```
12
+ */
13
+ import { type OPSQLiteDatabase } from './adapters/opsqlite.js';
14
+ import type { Persistence } from './types.js';
15
+ /**
16
+ * Create React Native SQLite persistence using op-sqlite.
17
+ *
18
+ * @param db - The opened op-sqlite database instance
19
+ * @param dbName - Name for internal database identification
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * import { createReactNativeSqlitePersistence } from '@trestleinc/replicate/client';
24
+ * import { open } from '@op-engineering/op-sqlite';
25
+ *
26
+ * const db = open({ name: 'myapp.db' });
27
+ * const persistence = await createReactNativeSqlitePersistence(db, 'myapp');
28
+ *
29
+ * // Use in collection options
30
+ * convexCollectionOptions<Task>({
31
+ * // ...
32
+ * persistence,
33
+ * });
34
+ * ```
35
+ */
36
+ export declare function createReactNativeSqlitePersistence(db: OPSQLiteDatabase, dbName: string): Promise<Persistence>;
@@ -0,0 +1,47 @@
1
+ import { type SqliteAdapter } from './sqlite-level.js';
2
+ import type { Persistence } from './types.js';
3
+ /**
4
+ * Options for SQLite persistence.
5
+ */
6
+ export interface SqlitePersistenceOptions {
7
+ /**
8
+ * Pre-created SQLite adapter (required).
9
+ * Use SqlJsAdapter for browser or OPSqliteAdapter for React Native.
10
+ */
11
+ adapter: SqliteAdapter;
12
+ /**
13
+ * Database name for internal y-leveldb usage.
14
+ * @default 'replicate'
15
+ */
16
+ dbName?: string;
17
+ }
18
+ /**
19
+ * Create a universal SQLite persistence factory.
20
+ *
21
+ * Requires a pre-created SqliteAdapter - the replicate package does not
22
+ * import any SQLite packages directly, making it environment-agnostic.
23
+ *
24
+ * @param options - Configuration with required adapter
25
+ *
26
+ * @example Browser (sql.js)
27
+ * ```typescript
28
+ * import initSqlJs from 'sql.js';
29
+ * import { sqlitePersistence, SqlJsAdapter } from '@trestleinc/replicate/client';
30
+ *
31
+ * const SQL = await initSqlJs();
32
+ * const db = new SQL.Database();
33
+ * const adapter = new SqlJsAdapter(db);
34
+ * const persistence = await sqlitePersistence({ adapter });
35
+ * ```
36
+ *
37
+ * @example React Native (op-sqlite)
38
+ * ```typescript
39
+ * import { open } from '@op-engineering/op-sqlite';
40
+ * import { sqlitePersistence, OPSqliteAdapter } from '@trestleinc/replicate/client';
41
+ *
42
+ * const db = open({ name: 'myapp.db' });
43
+ * const adapter = new OPSqliteAdapter(db);
44
+ * const persistence = await sqlitePersistence({ adapter });
45
+ * ```
46
+ */
47
+ export declare function sqlitePersistence(options: SqlitePersistenceOptions): Promise<Persistence>;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Persistence layer types for swappable storage backends.
3
+ *
4
+ * Supports IndexedDB (browser), SQLite (React Native), and in-memory (testing).
5
+ */
6
+ import type * as Y from 'yjs';
7
+ /**
8
+ * Provider that persists Y.Doc state to storage.
9
+ *
10
+ * This wraps providers like y-indexeddb or y-op-sqlite, normalizing their APIs.
11
+ */
12
+ export interface PersistenceProvider {
13
+ /** Promise that resolves when initial sync from storage completes */
14
+ readonly whenSynced: Promise<void>;
15
+ /** Clean up resources (stop observing, close connections) */
16
+ destroy(): void;
17
+ }
18
+ /**
19
+ * Factory that creates persistence providers.
20
+ *
21
+ * Each persistence implementation (IndexedDB, SQLite, memory) exports a
22
+ * factory function that returns this interface.
23
+ */
24
+ export interface Persistence {
25
+ /** Create a Y.Doc persistence provider for a collection */
26
+ createDocPersistence(collection: string, ydoc: Y.Doc): PersistenceProvider;
27
+ /** Key-value store for metadata (checkpoints, clientID) */
28
+ readonly kv: KeyValueStore;
29
+ }
30
+ /**
31
+ * Simple key-value storage interface.
32
+ *
33
+ * Used for storing metadata like checkpoints and Yjs client IDs.
34
+ */
35
+ export interface KeyValueStore {
36
+ /** Get a value by key */
37
+ get<T>(key: string): Promise<T | undefined>;
38
+ /** Set a value by key */
39
+ set<T>(key: string, value: T): Promise<void>;
40
+ /** Delete a value by key */
41
+ del(key: string): Promise<void>;
42
+ }
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Prose Field Helpers - Document-level state management for rich text sync
3
+ *
4
+ * Manages Y.XmlFragment observation, debounced sync, and pending state.
5
+ * Uses document-level tracking to prevent race conditions.
6
+ */
7
+ import * as Y from 'yjs';
8
+ import type { Collection } from '@tanstack/db';
9
+ /**
10
+ * Check if a document is currently applying server data.
11
+ * Used to prevent echo loops in onUpdate handlers.
12
+ */
13
+ export declare function isApplyingFromServer(collection: string, documentId: string): boolean;
14
+ /**
15
+ * Set whether a document is currently applying server data.
16
+ */
17
+ export declare function setApplyingFromServer(collection: string, documentId: string, value: boolean): void;
18
+ /**
19
+ * Get current pending state for a document.
20
+ */
21
+ export declare function isPending(collection: string, documentId: string): boolean;
22
+ /**
23
+ * Subscribe to pending state changes for a document.
24
+ */
25
+ export declare function subscribePending(collection: string, documentId: string, callback: (pending: boolean) => void): () => void;
26
+ /**
27
+ * Cancel any pending debounced sync for a document.
28
+ * Called when receiving remote updates to avoid conflicts.
29
+ */
30
+ export declare function cancelPending(collection: string, documentId: string): void;
31
+ /**
32
+ * Cancel all pending syncs for a collection.
33
+ * Called when receiving a snapshot that replaces all state.
34
+ */
35
+ export declare function cancelAllPending(collection: string): void;
36
+ /** Configuration for fragment observation */
37
+ export interface ProseObserverConfig {
38
+ collection: string;
39
+ documentId: string;
40
+ field: string;
41
+ fragment: Y.XmlFragment;
42
+ ydoc: Y.Doc;
43
+ ymap: Y.Map<unknown>;
44
+ collectionRef: Collection<any>;
45
+ debounceMs?: number;
46
+ }
47
+ /**
48
+ * Set up observation for a prose field's Y.XmlFragment.
49
+ * Returns a cleanup function.
50
+ */
51
+ export declare function observeFragment(config: ProseObserverConfig): () => void;
52
+ /**
53
+ * Clean up all prose state for a collection.
54
+ * Called when collection is destroyed.
55
+ */
56
+ export declare function cleanup(collection: string): void;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Replicate Helpers - Collection-bound functions for TanStack DB optimistic updates
3
+ *
4
+ * Each collection gets its own set of bound functions that operate on that
5
+ * collection's TanStack DB instance. No global state - fully concurrent-safe.
6
+ */
7
+ export interface ReplicateParams {
8
+ readonly begin: () => void;
9
+ readonly write: (message: {
10
+ type: 'insert' | 'update' | 'delete';
11
+ value: unknown;
12
+ }) => void;
13
+ readonly commit: () => void;
14
+ readonly truncate: () => void;
15
+ }
16
+ /**
17
+ * Bound replicate operations for a specific collection.
18
+ * These functions are already tied to the collection's TanStack DB params.
19
+ */
20
+ export interface BoundReplicateOps<T> {
21
+ readonly insert: (items: T[]) => void;
22
+ readonly delete: (items: T[]) => void;
23
+ readonly upsert: (items: T[]) => void;
24
+ readonly replace: (items: T[]) => void;
25
+ }
26
+ /**
27
+ * Create bound replicate operations for a collection.
28
+ * Returns functions that are already tied to the collection's params.
29
+ * This is the proper way to handle multiple concurrent collections.
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * const ops = createReplicateOps<Task>(params);
34
+ * ops.replace(items); // Always targets THIS collection's TanStack DB
35
+ * ops.upsert([item]);
36
+ * ops.delete([item]);
37
+ * ```
38
+ */
39
+ export declare function createReplicateOps<T>(params: ReplicateParams): BoundReplicateOps<T>;
40
+ export declare function _resetReplicateParams(): void;
@@ -0,0 +1,18 @@
1
+ import { Effect, Context, Layer } from 'effect';
2
+ import { IDBError, IDBWriteError } from '$/client/errors.js';
3
+ import type { KeyValueStore } from '$/client/persistence/types.js';
4
+ export interface CheckpointData {
5
+ lastModified: number;
6
+ }
7
+ declare const Checkpoint_base: Context.TagClass<Checkpoint, "Checkpoint", {
8
+ readonly loadCheckpoint: (collection: string) => Effect.Effect<CheckpointData, IDBError>;
9
+ readonly saveCheckpoint: (collection: string, checkpoint: CheckpointData) => Effect.Effect<void, IDBWriteError>;
10
+ readonly clearCheckpoint: (collection: string) => Effect.Effect<void, IDBError>;
11
+ }>;
12
+ export declare class Checkpoint extends Checkpoint_base {
13
+ }
14
+ /**
15
+ * Create a Checkpoint service layer using the provided KeyValueStore.
16
+ */
17
+ export declare function createCheckpointLayer(kv: KeyValueStore): Layer.Layer<Checkpoint, never, never>;
18
+ export {};
@@ -0,0 +1,24 @@
1
+ import { Effect, Context, Layer } from 'effect';
2
+ import * as Y from 'yjs';
3
+ import { ReconciliationError as ReconciliationErrorImport } from '$/client/errors.js';
4
+ declare const Reconciliation_base: Context.TagClass<Reconciliation, "Reconciliation", {
5
+ /**
6
+ * Reconciles local Yjs state with server state by removing phantom documents.
7
+ * Uses an existing Yjs document and map instead of creating new ones.
8
+ *
9
+ * @param ydoc - Existing Yjs document
10
+ * @param ymap - Existing Yjs map within the document
11
+ * @param collection - Collection name for logging
12
+ * @param serverDocs - Documents from server
13
+ * @param getKey - Function to extract key from document
14
+ */
15
+ readonly reconcile: <T>(ydoc: Y.Doc, ymap: Y.Map<unknown>, collection: string, serverDocs: readonly T[], getKey: (doc: T) => string) => Effect.Effect<T[], ReconciliationErrorImport>;
16
+ }>;
17
+ /**
18
+ * Reconciliation handles removal of phantom documents -
19
+ * documents that exist locally but have been deleted on the server.
20
+ */
21
+ export declare class Reconciliation extends Reconciliation_base {
22
+ }
23
+ export declare const ReconciliationLive: Layer.Layer<Reconciliation, never, never>;
24
+ export {};
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Generated `api` utility.
3
+ *
4
+ * THIS CODE IS AUTOMATICALLY GENERATED.
5
+ *
6
+ * To regenerate, run `npx convex dev`.
7
+ * @module
8
+ */
9
+ import type * as logger from "../logger.js";
10
+ import type * as public_ from "../public.js";
11
+ import type { ApiFromModules, FilterApi, FunctionReference } from "convex/server";
12
+ declare const fullApi: ApiFromModules<{
13
+ logger: typeof logger;
14
+ public: typeof public_;
15
+ }>;
16
+ /**
17
+ * A utility for referencing Convex functions in your app's public API.
18
+ *
19
+ * Usage:
20
+ * ```js
21
+ * const myFunctionReference = api.myModule.myFunction;
22
+ * ```
23
+ */
24
+ export declare const api: FilterApi<typeof fullApi, FunctionReference<any, "public">>;
25
+ /**
26
+ * A utility for referencing Convex functions in your app's internal API.
27
+ *
28
+ * Usage:
29
+ * ```js
30
+ * const myFunctionReference = internal.myModule.myFunction;
31
+ * ```
32
+ */
33
+ export declare const internal: FilterApi<typeof fullApi, FunctionReference<any, "internal">>;
34
+ export declare const components: {};
35
+ export {};
@@ -1,5 +1,5 @@
1
- import { anyApi, componentsGeneric } from "convex/server";
2
- const api = anyApi;
3
- const internal = anyApi;
1
+ import { anyApi as server_anyApi, componentsGeneric } from "convex/server";
2
+ const api = server_anyApi;
3
+ const internal = server_anyApi;
4
4
  const components = componentsGeneric();
5
5
  export { api, components, internal };
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Generated `ComponentApi` utility.
3
+ *
4
+ * THIS CODE IS AUTOMATICALLY GENERATED.
5
+ *
6
+ * To regenerate, run `npx convex dev`.
7
+ * @module
8
+ */
9
+ import type { FunctionReference } from "convex/server";
10
+ /**
11
+ * A utility for referencing a Convex component's exposed API.
12
+ *
13
+ * Useful when expecting a parameter like `components.myComponent`.
14
+ * Usage:
15
+ * ```ts
16
+ * async function myFunction(ctx: QueryCtx, component: ComponentApi) {
17
+ * return ctx.runQuery(component.someFile.someQuery, { ...args });
18
+ * }
19
+ * ```
20
+ */
21
+ export type ComponentApi<Name extends string | undefined = string | undefined> = {
22
+ public: {
23
+ deleteDocument: FunctionReference<"mutation", "internal", {
24
+ collection: string;
25
+ crdtBytes: ArrayBuffer;
26
+ documentId: string;
27
+ threshold?: number;
28
+ version: number;
29
+ }, {
30
+ compacted?: boolean;
31
+ success: boolean;
32
+ }, Name>;
33
+ getInitialState: FunctionReference<"query", "internal", {
34
+ collection: string;
35
+ }, {
36
+ checkpoint: {
37
+ lastModified: number;
38
+ };
39
+ crdtBytes: ArrayBuffer;
40
+ } | null, Name>;
41
+ insertDocument: FunctionReference<"mutation", "internal", {
42
+ collection: string;
43
+ crdtBytes: ArrayBuffer;
44
+ documentId: string;
45
+ threshold?: number;
46
+ version: number;
47
+ }, {
48
+ compacted?: boolean;
49
+ success: boolean;
50
+ }, Name>;
51
+ recovery: FunctionReference<"query", "internal", {
52
+ clientStateVector: ArrayBuffer;
53
+ collection: string;
54
+ }, {
55
+ diff?: ArrayBuffer;
56
+ serverStateVector: ArrayBuffer;
57
+ }, Name>;
58
+ stream: FunctionReference<"query", "internal", {
59
+ checkpoint: {
60
+ lastModified: number;
61
+ };
62
+ collection: string;
63
+ limit?: number;
64
+ vector?: ArrayBuffer;
65
+ }, {
66
+ changes: Array<{
67
+ crdtBytes: ArrayBuffer;
68
+ documentId?: string;
69
+ operationType: string;
70
+ timestamp: number;
71
+ version: number;
72
+ }>;
73
+ checkpoint: {
74
+ lastModified: number;
75
+ };
76
+ hasMore: boolean;
77
+ }, Name>;
78
+ updateDocument: FunctionReference<"mutation", "internal", {
79
+ collection: string;
80
+ crdtBytes: ArrayBuffer;
81
+ documentId: string;
82
+ threshold?: number;
83
+ version: number;
84
+ }, {
85
+ compacted?: boolean;
86
+ success: boolean;
87
+ }, Name>;
88
+ };
89
+ };
File without changes
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Generated data model types.
3
+ *
4
+ * THIS CODE IS AUTOMATICALLY GENERATED.
5
+ *
6
+ * To regenerate, run `npx convex dev`.
7
+ * @module
8
+ */
9
+ import type { DataModelFromSchemaDefinition, DocumentByName, TableNamesInDataModel, SystemTableNames } from "convex/server";
10
+ import type { GenericId } from "convex/values";
11
+ import schema from "../schema.js";
12
+ /**
13
+ * The names of all of your Convex tables.
14
+ */
15
+ export type TableNames = TableNamesInDataModel<DataModel>;
16
+ /**
17
+ * The type of a document stored in Convex.
18
+ *
19
+ * @typeParam TableName - A string literal type of the table name (like "users").
20
+ */
21
+ export type Doc<TableName extends TableNames> = DocumentByName<DataModel, TableName>;
22
+ /**
23
+ * An identifier for a document in Convex.
24
+ *
25
+ * Convex documents are uniquely identified by their `Id`, which is accessible
26
+ * on the `_id` field. To learn more, see [Document IDs](https://docs.convex.dev/using/document-ids).
27
+ *
28
+ * Documents can be loaded using `db.get(tableName, id)` in query and mutation functions.
29
+ *
30
+ * IDs are just strings at runtime, but this type can be used to distinguish them from other
31
+ * strings when type checking.
32
+ *
33
+ * @typeParam TableName - A string literal type of the table name (like "users").
34
+ */
35
+ export type Id<TableName extends TableNames | SystemTableNames> = GenericId<TableName>;
36
+ /**
37
+ * A type describing your Convex data model.
38
+ *
39
+ * This type includes information about what tables you have, the type of
40
+ * documents stored in those tables, and the indexes defined on them.
41
+ *
42
+ * This type is used to parameterize methods like `queryGeneric` and
43
+ * `mutationGeneric` to make them type-safe.
44
+ */
45
+ export type DataModel = DataModelFromSchemaDefinition<typeof schema>;
File without changes
@@ -1,4 +1,3 @@
1
- /* eslint-disable */
2
1
  /**
3
2
  * Generated utilities for implementing server-side Convex query and mutation functions.
4
3
  *
@@ -7,27 +6,8 @@
7
6
  * To regenerate, run `npx convex dev`.
8
7
  * @module
9
8
  */
10
-
11
- import {
12
- ActionBuilder,
13
- AnyComponents,
14
- HttpActionBuilder,
15
- MutationBuilder,
16
- QueryBuilder,
17
- GenericActionCtx,
18
- GenericMutationCtx,
19
- GenericQueryCtx,
20
- GenericDatabaseReader,
21
- GenericDatabaseWriter,
22
- FunctionReference,
23
- } from "convex/server";
9
+ import type { ActionBuilder, HttpActionBuilder, MutationBuilder, QueryBuilder, GenericActionCtx, GenericMutationCtx, GenericQueryCtx, GenericDatabaseReader, GenericDatabaseWriter } from "convex/server";
24
10
  import type { DataModel } from "./dataModel.js";
25
-
26
- type GenericCtx =
27
- | GenericActionCtx<DataModel>
28
- | GenericMutationCtx<DataModel>
29
- | GenericQueryCtx<DataModel>;
30
-
31
11
  /**
32
12
  * Define a query in this Convex app's public API.
33
13
  *
@@ -37,7 +17,6 @@ type GenericCtx =
37
17
  * @returns The wrapped query. Include this as an `export` to name it and make it accessible.
38
18
  */
39
19
  export declare const query: QueryBuilder<DataModel, "public">;
40
-
41
20
  /**
42
21
  * Define a query that is only accessible from other Convex functions (but not from the client).
43
22
  *
@@ -47,7 +26,6 @@ export declare const query: QueryBuilder<DataModel, "public">;
47
26
  * @returns The wrapped query. Include this as an `export` to name it and make it accessible.
48
27
  */
49
28
  export declare const internalQuery: QueryBuilder<DataModel, "internal">;
50
-
51
29
  /**
52
30
  * Define a mutation in this Convex app's public API.
53
31
  *
@@ -57,7 +35,6 @@ export declare const internalQuery: QueryBuilder<DataModel, "internal">;
57
35
  * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
58
36
  */
59
37
  export declare const mutation: MutationBuilder<DataModel, "public">;
60
-
61
38
  /**
62
39
  * Define a mutation that is only accessible from other Convex functions (but not from the client).
63
40
  *
@@ -67,7 +44,6 @@ export declare const mutation: MutationBuilder<DataModel, "public">;
67
44
  * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
68
45
  */
69
46
  export declare const internalMutation: MutationBuilder<DataModel, "internal">;
70
-
71
47
  /**
72
48
  * Define an action in this Convex app's public API.
73
49
  *
@@ -80,7 +56,6 @@ export declare const internalMutation: MutationBuilder<DataModel, "internal">;
80
56
  * @returns The wrapped action. Include this as an `export` to name it and make it accessible.
81
57
  */
82
58
  export declare const action: ActionBuilder<DataModel, "public">;
83
-
84
59
  /**
85
60
  * Define an action that is only accessible from other Convex functions (but not from the client).
86
61
  *
@@ -88,38 +63,36 @@ export declare const action: ActionBuilder<DataModel, "public">;
88
63
  * @returns The wrapped function. Include this as an `export` to name it and make it accessible.
89
64
  */
90
65
  export declare const internalAction: ActionBuilder<DataModel, "internal">;
91
-
92
66
  /**
93
67
  * Define an HTTP action.
94
68
  *
95
- * This function will be used to respond to HTTP requests received by a Convex
96
- * deployment if the requests matches the path and method where this action
97
- * is routed. Be sure to route your action in `convex/http.js`.
69
+ * The wrapped function will be used to respond to HTTP requests received
70
+ * by a Convex deployment if the requests matches the path and method where
71
+ * this action is routed. Be sure to route your httpAction in `convex/http.js`.
98
72
  *
99
- * @param func - The function. It receives an {@link ActionCtx} as its first argument.
73
+ * @param func - The function. It receives an {@link ActionCtx} as its first argument
74
+ * and a Fetch API `Request` object as its second.
100
75
  * @returns The wrapped function. Import this function from `convex/http.js` and route it to hook it up.
101
76
  */
102
77
  export declare const httpAction: HttpActionBuilder;
103
-
104
78
  /**
105
79
  * A set of services for use within Convex query functions.
106
80
  *
107
81
  * The query context is passed as the first argument to any Convex query
108
82
  * function run on the server.
109
83
  *
110
- * This differs from the {@link MutationCtx} because all of the services are
111
- * read-only.
84
+ * If you're using code generation, use the `QueryCtx` type in `convex/_generated/server.d.ts` instead.
112
85
  */
113
86
  export type QueryCtx = GenericQueryCtx<DataModel>;
114
-
115
87
  /**
116
88
  * A set of services for use within Convex mutation functions.
117
89
  *
118
90
  * The mutation context is passed as the first argument to any Convex mutation
119
91
  * function run on the server.
92
+ *
93
+ * If you're using code generation, use the `MutationCtx` type in `convex/_generated/server.d.ts` instead.
120
94
  */
121
95
  export type MutationCtx = GenericMutationCtx<DataModel>;
122
-
123
96
  /**
124
97
  * A set of services for use within Convex action functions.
125
98
  *
@@ -127,7 +100,6 @@ export type MutationCtx = GenericMutationCtx<DataModel>;
127
100
  * function run on the server.
128
101
  */
129
102
  export type ActionCtx = GenericActionCtx<DataModel>;
130
-
131
103
  /**
132
104
  * An interface to read from the database within Convex query functions.
133
105
  *
@@ -136,7 +108,6 @@ export type ActionCtx = GenericActionCtx<DataModel>;
136
108
  * building a query.
137
109
  */
138
110
  export type DatabaseReader = GenericDatabaseReader<DataModel>;
139
-
140
111
  /**
141
112
  * An interface to read from and write to the database within Convex mutation
142
113
  * functions.
@@ -1,2 +1,2 @@
1
- declare const _default: import("convex/server").ComponentDefinition<any>;
2
- export default _default;
1
+ declare const component: import("convex/server").ComponentDefinition<any>;
2
+ export default component;
@@ -1,3 +1,4 @@
1
1
  import { defineComponent } from "convex/server";
2
- const convex_config = defineComponent('replicate');
2
+ const component = defineComponent('replicate');
3
+ const convex_config = component;
3
4
  export { convex_config as default };
@@ -0,0 +1,8 @@
1
+ interface Logger {
2
+ debug(message: string, context?: Record<string, any>): void;
3
+ info(message: string, context?: Record<string, any>): void;
4
+ warn(message: string, context?: Record<string, any>): void;
5
+ error(message: string, context?: Record<string, any>): void;
6
+ }
7
+ export declare function getLogger(category: string[]): Logger;
8
+ export {};