@trestleinc/replicate 1.1.2 → 1.2.0-preview.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 (51) hide show
  1. package/README.md +40 -41
  2. package/package.json +3 -1
  3. package/src/client/collection.ts +334 -523
  4. package/src/client/errors.ts +1 -1
  5. package/src/client/index.ts +4 -7
  6. package/src/client/merge.ts +2 -2
  7. package/src/client/persistence/indexeddb.ts +10 -14
  8. package/src/client/prose.ts +147 -203
  9. package/src/client/services/awareness.ts +373 -0
  10. package/src/client/services/context.ts +114 -0
  11. package/src/client/services/seq.ts +78 -0
  12. package/src/client/services/session.ts +20 -0
  13. package/src/client/services/sync.ts +122 -0
  14. package/src/client/subdocs.ts +263 -0
  15. package/src/component/_generated/api.ts +2 -2
  16. package/src/component/_generated/component.ts +73 -28
  17. package/src/component/mutations.ts +734 -0
  18. package/src/component/schema.ts +31 -14
  19. package/src/server/collection.ts +98 -0
  20. package/src/server/index.ts +2 -2
  21. package/src/server/{storage.ts → replicate.ts} +214 -75
  22. package/dist/client/index.d.ts +0 -314
  23. package/dist/client/index.js +0 -4027
  24. package/dist/component/_generated/api.d.ts +0 -31
  25. package/dist/component/_generated/api.js +0 -25
  26. package/dist/component/_generated/component.d.ts +0 -91
  27. package/dist/component/_generated/component.js +0 -1
  28. package/dist/component/_generated/dataModel.d.ts +0 -42
  29. package/dist/component/_generated/dataModel.js +0 -1
  30. package/dist/component/_generated/server.d.ts +0 -117
  31. package/dist/component/_generated/server.js +0 -73
  32. package/dist/component/_virtual/rolldown_runtime.js +0 -18
  33. package/dist/component/convex.config.d.ts +0 -6
  34. package/dist/component/convex.config.js +0 -8
  35. package/dist/component/logger.d.ts +0 -12
  36. package/dist/component/logger.js +0 -27
  37. package/dist/component/public.d.ts +0 -83
  38. package/dist/component/public.js +0 -325
  39. package/dist/component/schema.d.ts +0 -54
  40. package/dist/component/schema.js +0 -29
  41. package/dist/component/shared/types.d.ts +0 -9
  42. package/dist/component/shared/types.js +0 -15
  43. package/dist/server/index.d.ts +0 -135
  44. package/dist/server/index.js +0 -368
  45. package/dist/shared/index.d.ts +0 -29
  46. package/dist/shared/index.js +0 -1
  47. package/src/client/prose-schema.ts +0 -55
  48. package/src/client/services/cursor.ts +0 -109
  49. package/src/component/public.ts +0 -453
  50. package/src/server/builder.ts +0 -98
  51. /package/src/client/{replicate.ts → ops.ts} +0 -0
@@ -1,31 +0,0 @@
1
- import { logger_d_exports } from "../logger.js";
2
- import { public_d_exports } from "../public.js";
3
- import { ApiFromModules, FilterApi, FunctionReference } from "convex/server";
4
-
5
- //#region src/component/_generated/api.d.ts
6
-
7
- declare const fullApi: ApiFromModules<{
8
- logger: typeof logger_d_exports;
9
- public: typeof public_d_exports;
10
- }>;
11
- /**
12
- * A utility for referencing Convex functions in your app's public API.
13
- *
14
- * Usage:
15
- * ```js
16
- * const myFunctionReference = api.myModule.myFunction;
17
- * ```
18
- */
19
- declare const api: FilterApi<typeof fullApi, FunctionReference<any, "public">>;
20
- /**
21
- * A utility for referencing Convex functions in your app's internal API.
22
- *
23
- * Usage:
24
- * ```js
25
- * const myFunctionReference = internal.myModule.myFunction;
26
- * ```
27
- */
28
- declare const internal: FilterApi<typeof fullApi, FunctionReference<any, "internal">>;
29
- declare const components: {};
30
- //#endregion
31
- export { api, components, internal };
@@ -1,25 +0,0 @@
1
- import { anyApi, componentsGeneric } from "convex/server";
2
-
3
- //#region src/component/_generated/api.ts
4
- /**
5
- * A utility for referencing Convex functions in your app's public API.
6
- *
7
- * Usage:
8
- * ```js
9
- * const myFunctionReference = api.myModule.myFunction;
10
- * ```
11
- */
12
- const api = anyApi;
13
- /**
14
- * A utility for referencing Convex functions in your app's internal API.
15
- *
16
- * Usage:
17
- * ```js
18
- * const myFunctionReference = internal.myModule.myFunction;
19
- * ```
20
- */
21
- const internal = anyApi;
22
- const components = componentsGeneric();
23
-
24
- //#endregion
25
- export { api, components, internal };
@@ -1,91 +0,0 @@
1
- import { FunctionReference } from "convex/server";
2
-
3
- //#region src/component/_generated/component.d.ts
4
-
5
- /**
6
- * A utility for referencing a Convex component's exposed API.
7
- *
8
- * Useful when expecting a parameter like `components.myComponent`.
9
- * Usage:
10
- * ```ts
11
- * async function myFunction(ctx: QueryCtx, component: ComponentApi) {
12
- * return ctx.runQuery(component.someFile.someQuery, { ...args });
13
- * }
14
- * ```
15
- */
16
- type ComponentApi<Name extends string | undefined = string | undefined> = {
17
- public: {
18
- compact: FunctionReference<"mutation", "internal", {
19
- collection: string;
20
- documentId: string;
21
- peerTimeout?: number;
22
- snapshotBytes: ArrayBuffer;
23
- stateVector: ArrayBuffer;
24
- }, {
25
- removed: number;
26
- retained: number;
27
- success: boolean;
28
- }, Name>;
29
- deleteDocument: FunctionReference<"mutation", "internal", {
30
- collection: string;
31
- crdtBytes: ArrayBuffer;
32
- documentId: string;
33
- }, {
34
- seq: number;
35
- success: boolean;
36
- }, Name>;
37
- getInitialState: FunctionReference<"query", "internal", {
38
- collection: string;
39
- }, {
40
- crdtBytes: ArrayBuffer;
41
- cursor: number;
42
- } | null, Name>;
43
- insertDocument: FunctionReference<"mutation", "internal", {
44
- collection: string;
45
- crdtBytes: ArrayBuffer;
46
- documentId: string;
47
- }, {
48
- seq: number;
49
- success: boolean;
50
- }, Name>;
51
- mark: FunctionReference<"mutation", "internal", {
52
- collection: string;
53
- peerId: string;
54
- syncedSeq: number;
55
- }, null, Name>;
56
- recovery: FunctionReference<"query", "internal", {
57
- clientStateVector: ArrayBuffer;
58
- collection: string;
59
- }, {
60
- cursor: number;
61
- diff?: ArrayBuffer;
62
- serverStateVector: ArrayBuffer;
63
- }, Name>;
64
- stream: FunctionReference<"query", "internal", {
65
- collection: string;
66
- cursor: number;
67
- limit?: number;
68
- sizeThreshold?: number;
69
- }, {
70
- changes: Array<{
71
- crdtBytes: ArrayBuffer;
72
- documentId: string;
73
- operationType: string;
74
- seq: number;
75
- }>;
76
- compact?: string;
77
- cursor: number;
78
- hasMore: boolean;
79
- }, Name>;
80
- updateDocument: FunctionReference<"mutation", "internal", {
81
- collection: string;
82
- crdtBytes: ArrayBuffer;
83
- documentId: string;
84
- }, {
85
- seq: number;
86
- success: boolean;
87
- }, Name>;
88
- };
89
- };
90
- //#endregion
91
- export { ComponentApi };
@@ -1 +0,0 @@
1
- export { };
@@ -1,42 +0,0 @@
1
- import _default from "../schema.js";
2
- import { DataModelFromSchemaDefinition, DocumentByName, SystemTableNames, TableNamesInDataModel } from "convex/server";
3
- import { GenericId } from "convex/values";
4
-
5
- //#region src/component/_generated/dataModel.d.ts
6
-
7
- /**
8
- * The names of all of your Convex tables.
9
- */
10
- type TableNames = TableNamesInDataModel<DataModel>;
11
- /**
12
- * The type of a document stored in Convex.
13
- *
14
- * @typeParam TableName - A string literal type of the table name (like "users").
15
- */
16
- type Doc<TableName extends TableNames> = DocumentByName<DataModel, TableName>;
17
- /**
18
- * An identifier for a document in Convex.
19
- *
20
- * Convex documents are uniquely identified by their `Id`, which is accessible
21
- * on the `_id` field. To learn more, see [Document IDs](https://docs.convex.dev/using/document-ids).
22
- *
23
- * Documents can be loaded using `db.get(tableName, id)` in query and mutation functions.
24
- *
25
- * IDs are just strings at runtime, but this type can be used to distinguish them from other
26
- * strings when type checking.
27
- *
28
- * @typeParam TableName - A string literal type of the table name (like "users").
29
- */
30
- type Id<TableName extends TableNames | SystemTableNames> = GenericId<TableName>;
31
- /**
32
- * A type describing your Convex data model.
33
- *
34
- * This type includes information about what tables you have, the type of
35
- * documents stored in those tables, and the indexes defined on them.
36
- *
37
- * This type is used to parameterize methods like `queryGeneric` and
38
- * `mutationGeneric` to make them type-safe.
39
- */
40
- type DataModel = DataModelFromSchemaDefinition<typeof _default>;
41
- //#endregion
42
- export { DataModel, Doc, Id, TableNames };
@@ -1 +0,0 @@
1
- export { };
@@ -1,117 +0,0 @@
1
- import { DataModel } from "./dataModel.js";
2
- import { ActionBuilder, GenericActionCtx, GenericDatabaseReader, GenericDatabaseWriter, GenericMutationCtx, GenericQueryCtx, HttpActionBuilder, MutationBuilder, QueryBuilder } from "convex/server";
3
-
4
- //#region src/component/_generated/server.d.ts
5
-
6
- /**
7
- * Define a query in this Convex app's public API.
8
- *
9
- * This function will be allowed to read your Convex database and will be accessible from the client.
10
- *
11
- * @param func - The query function. It receives a {@link QueryCtx} as its first argument.
12
- * @returns The wrapped query. Include this as an `export` to name it and make it accessible.
13
- */
14
- declare const query: QueryBuilder<DataModel, "public">;
15
- /**
16
- * Define a query that is only accessible from other Convex functions (but not from the client).
17
- *
18
- * This function will be allowed to read from your Convex database. It will not be accessible from the client.
19
- *
20
- * @param func - The query function. It receives a {@link QueryCtx} as its first argument.
21
- * @returns The wrapped query. Include this as an `export` to name it and make it accessible.
22
- */
23
- declare const internalQuery: QueryBuilder<DataModel, "internal">;
24
- /**
25
- * Define a mutation in this Convex app's public API.
26
- *
27
- * This function will be allowed to modify your Convex database and will be accessible from the client.
28
- *
29
- * @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
30
- * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
31
- */
32
- declare const mutation: MutationBuilder<DataModel, "public">;
33
- /**
34
- * Define a mutation that is only accessible from other Convex functions (but not from the client).
35
- *
36
- * This function will be allowed to modify your Convex database. It will not be accessible from the client.
37
- *
38
- * @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
39
- * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
40
- */
41
- declare const internalMutation: MutationBuilder<DataModel, "internal">;
42
- /**
43
- * Define an action in this Convex app's public API.
44
- *
45
- * An action is a function which can execute any JavaScript code, including non-deterministic
46
- * code and code with side-effects, like calling third-party services.
47
- * They can be run in Convex's JavaScript environment or in Node.js using the "use node" directive.
48
- * They can interact with the database indirectly by calling queries and mutations using the {@link ActionCtx}.
49
- *
50
- * @param func - The action. It receives an {@link ActionCtx} as its first argument.
51
- * @returns The wrapped action. Include this as an `export` to name it and make it accessible.
52
- */
53
- declare const action: ActionBuilder<DataModel, "public">;
54
- /**
55
- * Define an action that is only accessible from other Convex functions (but not from the client).
56
- *
57
- * @param func - The function. It receives an {@link ActionCtx} as its first argument.
58
- * @returns The wrapped function. Include this as an `export` to name it and make it accessible.
59
- */
60
- declare const internalAction: ActionBuilder<DataModel, "internal">;
61
- /**
62
- * Define an HTTP action.
63
- *
64
- * The wrapped function will be used to respond to HTTP requests received
65
- * by a Convex deployment if the requests matches the path and method where
66
- * this action is routed. Be sure to route your httpAction in `convex/http.js`.
67
- *
68
- * @param func - The function. It receives an {@link ActionCtx} as its first argument
69
- * and a Fetch API `Request` object as its second.
70
- * @returns The wrapped function. Import this function from `convex/http.js` and route it to hook it up.
71
- */
72
- declare const httpAction: HttpActionBuilder;
73
- /**
74
- * A set of services for use within Convex query functions.
75
- *
76
- * The query context is passed as the first argument to any Convex query
77
- * function run on the server.
78
- *
79
- * If you're using code generation, use the `QueryCtx` type in `convex/_generated/server.d.ts` instead.
80
- */
81
- type QueryCtx = GenericQueryCtx<DataModel>;
82
- /**
83
- * A set of services for use within Convex mutation functions.
84
- *
85
- * The mutation context is passed as the first argument to any Convex mutation
86
- * function run on the server.
87
- *
88
- * If you're using code generation, use the `MutationCtx` type in `convex/_generated/server.d.ts` instead.
89
- */
90
- type MutationCtx = GenericMutationCtx<DataModel>;
91
- /**
92
- * A set of services for use within Convex action functions.
93
- *
94
- * The action context is passed as the first argument to any Convex action
95
- * function run on the server.
96
- */
97
- type ActionCtx = GenericActionCtx<DataModel>;
98
- /**
99
- * An interface to read from the database within Convex query functions.
100
- *
101
- * The two entry points are {@link DatabaseReader.get}, which fetches a single
102
- * document by its {@link Id}, or {@link DatabaseReader.query}, which starts
103
- * building a query.
104
- */
105
- type DatabaseReader = GenericDatabaseReader<DataModel>;
106
- /**
107
- * An interface to read from and write to the database within Convex mutation
108
- * functions.
109
- *
110
- * Convex guarantees that all writes within a single mutation are
111
- * executed atomically, so you never have to worry about partial writes leaving
112
- * your data in an inconsistent state. See [the Convex Guide](https://docs.convex.dev/understanding/convex-fundamentals/functions#atomicity-and-optimistic-concurrency-control)
113
- * for the guarantees Convex provides your functions.
114
- */
115
- type DatabaseWriter = GenericDatabaseWriter<DataModel>;
116
- //#endregion
117
- export { ActionCtx, DatabaseReader, DatabaseWriter, MutationCtx, QueryCtx, action, httpAction, internalAction, internalMutation, internalQuery, mutation, query };
@@ -1,73 +0,0 @@
1
- import { actionGeneric, httpActionGeneric, internalActionGeneric, internalMutationGeneric, internalQueryGeneric, mutationGeneric, queryGeneric } from "convex/server";
2
-
3
- //#region src/component/_generated/server.ts
4
- /**
5
- * Define a query in this Convex app's public API.
6
- *
7
- * This function will be allowed to read your Convex database and will be accessible from the client.
8
- *
9
- * @param func - The query function. It receives a {@link QueryCtx} as its first argument.
10
- * @returns The wrapped query. Include this as an `export` to name it and make it accessible.
11
- */
12
- const query = queryGeneric;
13
- /**
14
- * Define a query that is only accessible from other Convex functions (but not from the client).
15
- *
16
- * This function will be allowed to read from your Convex database. It will not be accessible from the client.
17
- *
18
- * @param func - The query function. It receives a {@link QueryCtx} as its first argument.
19
- * @returns The wrapped query. Include this as an `export` to name it and make it accessible.
20
- */
21
- const internalQuery = internalQueryGeneric;
22
- /**
23
- * Define a mutation in this Convex app's public API.
24
- *
25
- * This function will be allowed to modify your Convex database and will be accessible from the client.
26
- *
27
- * @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
28
- * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
29
- */
30
- const mutation = mutationGeneric;
31
- /**
32
- * Define a mutation that is only accessible from other Convex functions (but not from the client).
33
- *
34
- * This function will be allowed to modify your Convex database. It will not be accessible from the client.
35
- *
36
- * @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
37
- * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
38
- */
39
- const internalMutation = internalMutationGeneric;
40
- /**
41
- * Define an action in this Convex app's public API.
42
- *
43
- * An action is a function which can execute any JavaScript code, including non-deterministic
44
- * code and code with side-effects, like calling third-party services.
45
- * They can be run in Convex's JavaScript environment or in Node.js using the "use node" directive.
46
- * They can interact with the database indirectly by calling queries and mutations using the {@link ActionCtx}.
47
- *
48
- * @param func - The action. It receives an {@link ActionCtx} as its first argument.
49
- * @returns The wrapped action. Include this as an `export` to name it and make it accessible.
50
- */
51
- const action = actionGeneric;
52
- /**
53
- * Define an action that is only accessible from other Convex functions (but not from the client).
54
- *
55
- * @param func - The function. It receives an {@link ActionCtx} as its first argument.
56
- * @returns The wrapped function. Include this as an `export` to name it and make it accessible.
57
- */
58
- const internalAction = internalActionGeneric;
59
- /**
60
- * Define an HTTP action.
61
- *
62
- * The wrapped function will be used to respond to HTTP requests received
63
- * by a Convex deployment if the requests matches the path and method where
64
- * this action is routed. Be sure to route your httpAction in `convex/http.js`.
65
- *
66
- * @param func - The function. It receives an {@link ActionCtx} as its first argument
67
- * and a Fetch API `Request` object as its second.
68
- * @returns The wrapped function. Import this function from `convex/http.js` and route it to hook it up.
69
- */
70
- const httpAction = httpActionGeneric;
71
-
72
- //#endregion
73
- export { action, httpAction, internalAction, internalMutation, internalQuery, mutation, query };
@@ -1,18 +0,0 @@
1
- //#region rolldown:runtime
2
- var __defProp = Object.defineProperty;
3
- var __export = (all, symbols) => {
4
- let target = {};
5
- for (var name in all) {
6
- __defProp(target, name, {
7
- get: all[name],
8
- enumerable: true
9
- });
10
- }
11
- if (symbols) {
12
- __defProp(target, Symbol.toStringTag, { value: "Module" });
13
- }
14
- return target;
15
- };
16
-
17
- //#endregion
18
- export { __export };
@@ -1,6 +0,0 @@
1
- import * as convex_server11 from "convex/server";
2
-
3
- //#region src/component/convex.config.d.ts
4
- declare const component: convex_server11.ComponentDefinition<any>;
5
- //#endregion
6
- export { component as default };
@@ -1,8 +0,0 @@
1
- import { defineComponent } from "convex/server";
2
-
3
- //#region src/component/convex.config.ts
4
- const component = defineComponent("replicate");
5
- var convex_config_default = component;
6
-
7
- //#endregion
8
- export { convex_config_default as default };
@@ -1,12 +0,0 @@
1
- declare namespace logger_d_exports {
2
- export { getLogger };
3
- }
4
- interface Logger {
5
- debug(message: string, context?: Record<string, any>): void;
6
- info(message: string, context?: Record<string, any>): void;
7
- warn(message: string, context?: Record<string, any>): void;
8
- error(message: string, context?: Record<string, any>): void;
9
- }
10
- declare function getLogger(category: string[]): Logger;
11
- //#endregion
12
- export { getLogger, logger_d_exports };
@@ -1,27 +0,0 @@
1
- //#region src/component/logger.ts
2
- var ComponentLogger = class {
3
- constructor(category) {
4
- this.category = category;
5
- }
6
- format(level, message, context) {
7
- return `${`[${this.category.join(":")}]`} ${level}: ${message}${context ? ` ${JSON.stringify(context)}` : ""}`;
8
- }
9
- debug(message, context) {
10
- console.log(this.format("DEBUG", message, context));
11
- }
12
- info(message, context) {
13
- console.log(this.format("INFO", message, context));
14
- }
15
- warn(message, context) {
16
- console.warn(this.format("WARN", message, context));
17
- }
18
- error(message, context) {
19
- console.error(this.format("ERROR", message, context));
20
- }
21
- };
22
- function getLogger(category) {
23
- return new ComponentLogger(["component", ...category]);
24
- }
25
-
26
- //#endregion
27
- export { getLogger };
@@ -1,83 +0,0 @@
1
- import { OperationType } from "./shared/types.js";
2
- import * as convex_server0 from "convex/server";
3
-
4
- //#region src/component/public.d.ts
5
- declare namespace public_d_exports {
6
- export { OperationType, compact, deleteDocument, getInitialState, insertDocument, mark, recovery, stream, updateDocument };
7
- }
8
- declare const insertDocument: convex_server0.RegisteredMutation<"public", {
9
- collection: string;
10
- documentId: string;
11
- crdtBytes: ArrayBuffer;
12
- }, Promise<{
13
- success: boolean;
14
- seq: number;
15
- }>>;
16
- declare const updateDocument: convex_server0.RegisteredMutation<"public", {
17
- collection: string;
18
- documentId: string;
19
- crdtBytes: ArrayBuffer;
20
- }, Promise<{
21
- success: boolean;
22
- seq: number;
23
- }>>;
24
- declare const deleteDocument: convex_server0.RegisteredMutation<"public", {
25
- collection: string;
26
- documentId: string;
27
- crdtBytes: ArrayBuffer;
28
- }, Promise<{
29
- success: boolean;
30
- seq: number;
31
- }>>;
32
- declare const mark: convex_server0.RegisteredMutation<"public", {
33
- collection: string;
34
- peerId: string;
35
- syncedSeq: number;
36
- }, Promise<null>>;
37
- declare const compact: convex_server0.RegisteredMutation<"public", {
38
- peerTimeout?: number | undefined;
39
- collection: string;
40
- documentId: string;
41
- snapshotBytes: ArrayBuffer;
42
- stateVector: ArrayBuffer;
43
- }, Promise<{
44
- success: boolean;
45
- removed: number;
46
- retained: number;
47
- }>>;
48
- declare const stream: convex_server0.RegisteredQuery<"public", {
49
- limit?: number | undefined;
50
- sizeThreshold?: number | undefined;
51
- collection: string;
52
- cursor: number;
53
- }, Promise<{
54
- changes: {
55
- documentId: any;
56
- crdtBytes: any;
57
- seq: any;
58
- operationType: OperationType;
59
- }[];
60
- cursor: number;
61
- hasMore: boolean;
62
- compact: string | undefined;
63
- }>>;
64
- declare const getInitialState: convex_server0.RegisteredQuery<"public", {
65
- collection: string;
66
- }, Promise<{
67
- crdtBytes: ArrayBuffer;
68
- cursor: number;
69
- } | null>>;
70
- declare const recovery: convex_server0.RegisteredQuery<"public", {
71
- collection: string;
72
- clientStateVector: ArrayBuffer;
73
- }, Promise<{
74
- serverStateVector: ArrayBuffer;
75
- cursor: number;
76
- diff?: undefined;
77
- } | {
78
- diff: ArrayBuffer | undefined;
79
- serverStateVector: ArrayBuffer;
80
- cursor: number;
81
- }>>;
82
- //#endregion
83
- export { OperationType, compact, deleteDocument, getInitialState, insertDocument, mark, public_d_exports, recovery, stream, updateDocument };