@lsync/server 0.0.2 → 0.0.3
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/README.md +46 -0
- package/dist/client.d.mts +1 -1
- package/dist/client.mjs +1 -1
- package/dist/index.d.mts +26 -4
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +214 -56
- package/dist/index.mjs.map +1 -1
- package/dist/{router-D_wddPdy.d.mts → router-B9emOwKj.d.mts} +13 -110
- package/dist/{router-D_wddPdy.d.mts.map → router-B9emOwKj.d.mts.map} +1 -1
- package/dist/router-CZnnFmXh.mjs +39 -0
- package/dist/router-CZnnFmXh.mjs.map +1 -0
- package/package.json +3 -4
- package/dist/router-C4eYfMV7.mjs +0 -39
- package/dist/router-C4eYfMV7.mjs.map +0 -1
|
@@ -97,115 +97,18 @@ interface Context {
|
|
|
97
97
|
changes: (query: SyncChangesQuery$1) => SyncChangesResult$1;
|
|
98
98
|
callApi: (call: ApiCall) => unknown;
|
|
99
99
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
type: "insert" | "update" | "delete";
|
|
113
|
-
createdAt: number;
|
|
114
|
-
path?: string | undefined;
|
|
115
|
-
value?: unknown;
|
|
116
|
-
previousValue?: unknown;
|
|
117
|
-
clientId?: string | undefined;
|
|
118
|
-
}[];
|
|
119
|
-
};
|
|
120
|
-
output: {
|
|
121
|
-
accepted: number;
|
|
122
|
-
watermark: number;
|
|
123
|
-
};
|
|
124
|
-
meta: object;
|
|
125
|
-
}>;
|
|
126
|
-
read: import("@trpc/server").TRPCQueryProcedure<{
|
|
127
|
-
input: {
|
|
128
|
-
collection: string;
|
|
129
|
-
filters?: {
|
|
130
|
-
field: string;
|
|
131
|
-
value: unknown;
|
|
132
|
-
op?: "in" | "eq" | "ne" | "gt" | "gte" | "lt" | "lte" | undefined;
|
|
133
|
-
}[] | undefined;
|
|
134
|
-
predicate?: unknown;
|
|
135
|
-
orderBy?: {
|
|
136
|
-
field: string;
|
|
137
|
-
direction?: "asc" | "desc" | undefined;
|
|
138
|
-
}[] | undefined;
|
|
139
|
-
cursor?: {
|
|
140
|
-
whereCurrent: unknown;
|
|
141
|
-
whereFrom: unknown;
|
|
142
|
-
lastKey?: string | number | undefined;
|
|
143
|
-
} | undefined;
|
|
144
|
-
limit?: number | undefined;
|
|
145
|
-
offset?: number | undefined;
|
|
146
|
-
};
|
|
147
|
-
output: ReadResult$1<unknown>;
|
|
148
|
-
meta: object;
|
|
149
|
-
}>;
|
|
150
|
-
subscribe: import("@trpc/server").TRPCMutationProcedure<{
|
|
151
|
-
input: {
|
|
152
|
-
collection: string;
|
|
153
|
-
};
|
|
154
|
-
output: {
|
|
155
|
-
collection: string;
|
|
156
|
-
subscriptions: string[];
|
|
157
|
-
};
|
|
158
|
-
meta: object;
|
|
159
|
-
}>;
|
|
160
|
-
unsubscribe: import("@trpc/server").TRPCMutationProcedure<{
|
|
161
|
-
input: {
|
|
162
|
-
collection: string;
|
|
163
|
-
};
|
|
164
|
-
output: {
|
|
165
|
-
collection: string;
|
|
166
|
-
subscriptions: string[];
|
|
167
|
-
};
|
|
168
|
-
meta: object;
|
|
169
|
-
}>;
|
|
170
|
-
changes: import("@trpc/server").TRPCQueryProcedure<{
|
|
171
|
-
input: {
|
|
172
|
-
collections: Record<string, number>;
|
|
173
|
-
limit?: number | undefined;
|
|
174
|
-
};
|
|
175
|
-
output: {
|
|
176
|
-
type: "changes";
|
|
177
|
-
updates: {
|
|
178
|
-
id: string;
|
|
179
|
-
collection: string;
|
|
180
|
-
key: string | number;
|
|
181
|
-
type: "insert" | "update" | "delete";
|
|
182
|
-
createdAt: number;
|
|
183
|
-
sequence: number;
|
|
184
|
-
serverCreatedAt: string;
|
|
185
|
-
path?: string | undefined;
|
|
186
|
-
value?: unknown;
|
|
187
|
-
previousValue?: unknown;
|
|
188
|
-
clientId?: string | undefined;
|
|
189
|
-
}[];
|
|
190
|
-
watermark: number;
|
|
191
|
-
hasMore: boolean;
|
|
192
|
-
} | {
|
|
193
|
-
type: "resyncRequired";
|
|
194
|
-
collections: string[];
|
|
195
|
-
watermark: number;
|
|
196
|
-
};
|
|
197
|
-
meta: object;
|
|
198
|
-
}>;
|
|
199
|
-
api: import("@trpc/server").TRPCMutationProcedure<{
|
|
200
|
-
input: {
|
|
201
|
-
path: string;
|
|
202
|
-
input?: unknown;
|
|
203
|
-
};
|
|
204
|
-
output: unknown;
|
|
205
|
-
meta: object;
|
|
206
|
-
}>;
|
|
207
|
-
}>>;
|
|
208
|
-
type Router = typeof router;
|
|
100
|
+
interface Caller {
|
|
101
|
+
push(input: Batch$1): Promise<PushResult$1>;
|
|
102
|
+
read(input: unknown): Promise<ReadResult$1>;
|
|
103
|
+
subscribe(input: CollectionSubscription$1): Promise<CollectionSubscriptionResult$1>;
|
|
104
|
+
unsubscribe(input: CollectionSubscription$1): Promise<CollectionSubscriptionResult$1>;
|
|
105
|
+
changes(input: SyncChangesQuery$1): Promise<SyncChangesResult$1>;
|
|
106
|
+
api(input: ApiCall): Promise<unknown>;
|
|
107
|
+
}
|
|
108
|
+
interface Router {
|
|
109
|
+
createCaller(context: Context): Caller;
|
|
110
|
+
}
|
|
111
|
+
declare const router: Router;
|
|
209
112
|
//#endregion
|
|
210
113
|
export { CollectionSubscriptionInput as A, ReadOrderBy as B, CollectionApiDefinition as C, CollectionInvalidation as D, CollectionConfigs as E, ReadAccessHandler as F, SQLiteJsonStorageConfig as G, ReadQuery$1 as H, ReadAccessResult as I, SyncChangesQuery$1 as J, SequencedBatch as K, ReadCursor as L, OperationType as M, PushResult$1 as N, CollectionStorageConfig as O, ReadAccessContext as P, WebSocketAttachment as Q, ReadFilter as R, CollectionAccessConfig as S, CollectionConfig as T, ReadResult$1 as U, ReadPredicate as V, SQLiteJsonIndexConfig as W, SyncChangesResult$1 as X, SyncChangesQueryInput as Y, Update as Z, ApiOutput as _, AccessReference as a, Batch$1 as b, ApiAccessHandler as c, ApiCallInput as d, ApiContract as f, ApiInput as g, ApiHandlerContext as h, AccessAuth as i, CollectionSubscriptionResult$1 as j, CollectionSubscription$1 as k, ApiCall as l, ApiHandlerArgs as m, Router as n, AccessReferenceResolver as o, ApiHandler as p, SequencedUpdate$1 as q, router as r, ApiAccessContext as s, Context as t, ApiCallArgs as u, ApiPath as v, CollectionApiHandlers as w, Broadcast as x, ApiRoute as y, ReadFilterOperator as z };
|
|
211
|
-
//# sourceMappingURL=router-
|
|
114
|
+
//# sourceMappingURL=router-B9emOwKj.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router-
|
|
1
|
+
{"version":3,"file":"router-B9emOwKj.d.mts","names":[],"sources":["../src/types.ts","../src/router.ts"],"mappings":";;;;KA2EY,UAAA,GAAa,MAAM;EAC7B,QAAQ;AAAA;AAAA,UAGO,iBAAA,oBAAqC,MAAA;EACpD,IAAA,EAAM,UAAA;EACN,UAAA;EACA,UAAA,EAAY,MAAA,SAAe,iBAAA,CAAkB,MAAA;EAC7C,MAAA,EAAQ,MAAA;EACR,OAAA;EACA,GAAA,EAAK,iBAAA,CAAkB,CAAA;AAAA;AAAA,KAGb,eAAA;EAGN,UAAA;EACA,GAAG;AAAA;AAAA,KAGG,uBAAA,IAA2B,OAAA;EACrC,IAAA,EAAM,UAAA;EACN,UAAA;EACA,MAAA,EAAQ,MAAA;EACR,OAAA;AAAA,MACI,eAAA;AAAA,KAEM,gBAAA,GAAmB,mBAAmB;AAAA,KAEtC,iBAAA,oBAAqC,MAAA,sBAC/C,OAAA,EAAS,iBAAA,CAAkB,CAAA,MACxB,gBAAA;AAAA,UAEY,gBAAA,yBAAyC,MAAA;EACxD,IAAA,EAAM,UAAA;EACN,KAAA,EAAO,iBAAA,CAAkB,MAAA;AAAA;AAAA,KAGf,gBAAA,yBAAyC,MA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,mBAAA;EAC1C,GAAA,CAAI,KAAA,EAAO,OAAA,GAAU,OAAA;AAAA;AAAA,UAGN,MAAA;EACf,YAAA,CAAa,OAAA,EAAS,OAAA,GAAU,MAAM;AAAA;AAAA,cAG3B,MAAA,EAAQ,MAuBpB"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { apiCallSchema, batchSchema, collectionSubscriptionSchema, readQuerySchema, syncChangesQuerySchema, webSocketAttachmentSchema } from "@lsync/transport";
|
|
2
|
+
//#region src/router.ts
|
|
3
|
+
const router = { createCaller(context) {
|
|
4
|
+
return {
|
|
5
|
+
async push(input) {
|
|
6
|
+
return context.mutate(batchSchema.parse(input));
|
|
7
|
+
},
|
|
8
|
+
async read(input) {
|
|
9
|
+
return context.read(normalizeReadQuery(readQuerySchema.parse(input)));
|
|
10
|
+
},
|
|
11
|
+
async subscribe(input) {
|
|
12
|
+
return context.subscribe(collectionSubscriptionSchema.parse(input));
|
|
13
|
+
},
|
|
14
|
+
async unsubscribe(input) {
|
|
15
|
+
return context.unsubscribe(collectionSubscriptionSchema.parse(input));
|
|
16
|
+
},
|
|
17
|
+
async changes(input) {
|
|
18
|
+
return context.changes(syncChangesQuerySchema.parse(input));
|
|
19
|
+
},
|
|
20
|
+
async api(input) {
|
|
21
|
+
return context.callApi(apiCallSchema.parse(input));
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
} };
|
|
25
|
+
function normalizeReadQuery(input) {
|
|
26
|
+
return {
|
|
27
|
+
collection: input.collection,
|
|
28
|
+
...input.filters !== void 0 ? { filters: input.filters } : {},
|
|
29
|
+
...input.predicate !== void 0 ? { predicate: input.predicate } : {},
|
|
30
|
+
...input.orderBy !== void 0 ? { orderBy: input.orderBy } : {},
|
|
31
|
+
...input.cursor !== void 0 ? { cursor: input.cursor } : {},
|
|
32
|
+
...input.limit !== void 0 ? { limit: input.limit } : {},
|
|
33
|
+
...input.offset !== void 0 ? { offset: input.offset } : {}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
export { webSocketAttachmentSchema as n, router as t };
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=router-CZnnFmXh.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router-CZnnFmXh.mjs","names":[],"sources":["../src/router.ts"],"sourcesContent":["import {\n apiCallSchema,\n batchSchema,\n collectionSubscriptionSchema,\n readQuerySchema,\n syncChangesQuerySchema,\n type ApiCall,\n type Batch,\n type CollectionSubscription,\n type CollectionSubscriptionResult,\n type PushResult,\n type ReadQuery,\n type ReadResult,\n type SequencedBatch,\n type SyncChangesQuery,\n type SyncChangesResult,\n} from \"./types\";\nimport type { z } from \"zod\";\n\nexport interface Context {\n shardId: string;\n validate: (batch: Batch) => void;\n persist: (batch: Batch) => SequencedBatch;\n publish: (batch: SequencedBatch) => void;\n mutate: (batch: Batch) => PushResult;\n subscribe: (input: CollectionSubscription) => CollectionSubscriptionResult;\n unsubscribe: (input: CollectionSubscription) => CollectionSubscriptionResult;\n read: (query: ReadQuery) => ReadResult;\n changes: (query: SyncChangesQuery) => SyncChangesResult;\n callApi: (call: ApiCall) => unknown;\n}\n\nexport interface Caller {\n push(input: Batch): Promise<PushResult>;\n read(input: unknown): Promise<ReadResult>;\n subscribe(input: CollectionSubscription): Promise<CollectionSubscriptionResult>;\n unsubscribe(input: CollectionSubscription): Promise<CollectionSubscriptionResult>;\n changes(input: SyncChangesQuery): Promise<SyncChangesResult>;\n api(input: ApiCall): Promise<unknown>;\n}\n\nexport interface Router {\n createCaller(context: Context): Caller;\n}\n\nexport const router: Router = {\n createCaller(context): Caller {\n return {\n async push(input) {\n return context.mutate(batchSchema.parse(input));\n },\n async read(input) {\n return context.read(normalizeReadQuery(readQuerySchema.parse(input)));\n },\n async subscribe(input) {\n return context.subscribe(collectionSubscriptionSchema.parse(input));\n },\n async unsubscribe(input) {\n return context.unsubscribe(collectionSubscriptionSchema.parse(input));\n },\n async changes(input) {\n return context.changes(syncChangesQuerySchema.parse(input));\n },\n async api(input) {\n return context.callApi(apiCallSchema.parse(input));\n },\n };\n },\n};\n\nfunction normalizeReadQuery(input: z.output<typeof readQuerySchema>): ReadQuery {\n return {\n collection: input.collection,\n ...(input.filters !== undefined ? { filters: input.filters } : {}),\n ...(input.predicate !== undefined ? { predicate: input.predicate } : {}),\n ...(input.orderBy !== undefined ? { orderBy: input.orderBy } : {}),\n ...(input.cursor !== undefined ? { cursor: input.cursor } : {}),\n ...(input.limit !== undefined ? { limit: input.limit } : {}),\n ...(input.offset !== undefined ? { offset: input.offset } : {}),\n };\n}\n"],"mappings":";;AA6CA,MAAa,SAAiB,EAC5B,aAAa,SAAiB;CAC5B,OAAO;EACL,MAAM,KAAK,OAAO;GAChB,OAAO,QAAQ,OAAO,YAAY,MAAM,KAAK,CAAC;EAChD;EACA,MAAM,KAAK,OAAO;GAChB,OAAO,QAAQ,KAAK,mBAAmB,gBAAgB,MAAM,KAAK,CAAC,CAAC;EACtE;EACA,MAAM,UAAU,OAAO;GACrB,OAAO,QAAQ,UAAU,6BAA6B,MAAM,KAAK,CAAC;EACpE;EACA,MAAM,YAAY,OAAO;GACvB,OAAO,QAAQ,YAAY,6BAA6B,MAAM,KAAK,CAAC;EACtE;EACA,MAAM,QAAQ,OAAO;GACnB,OAAO,QAAQ,QAAQ,uBAAuB,MAAM,KAAK,CAAC;EAC5D;EACA,MAAM,IAAI,OAAO;GACf,OAAO,QAAQ,QAAQ,cAAc,MAAM,KAAK,CAAC;EACnD;CACF;AACF,EACF;AAEA,SAAS,mBAAmB,OAAoD;CAC9E,OAAO;EACL,YAAY,MAAM;EAClB,GAAI,MAAM,YAAY,KAAA,IAAY,EAAE,SAAS,MAAM,QAAQ,IAAI,CAAC;EAChE,GAAI,MAAM,cAAc,KAAA,IAAY,EAAE,WAAW,MAAM,UAAU,IAAI,CAAC;EACtE,GAAI,MAAM,YAAY,KAAA,IAAY,EAAE,SAAS,MAAM,QAAQ,IAAI,CAAC;EAChE,GAAI,MAAM,WAAW,KAAA,IAAY,EAAE,QAAQ,MAAM,OAAO,IAAI,CAAC;EAC7D,GAAI,MAAM,UAAU,KAAA,IAAY,EAAE,OAAO,MAAM,MAAM,IAAI,CAAC;EAC1D,GAAI,MAAM,WAAW,KAAA,IAAY,EAAE,QAAQ,MAAM,OAAO,IAAI,CAAC;CAC/D;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lsync/server",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"homepage": "https://github.com/Myrannas/lsync#readme",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/Myrannas/lsync/issues"
|
|
@@ -31,11 +31,10 @@
|
|
|
31
31
|
"registry": "https://registry.npmjs.org/"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@trpc/server": "^11.4.4",
|
|
35
34
|
"sql-template-tag": "^5.2.1",
|
|
36
35
|
"zod": "^4.4.3",
|
|
37
|
-
"@lsync/definitions": "0.0.
|
|
38
|
-
"@lsync/transport": "0.0.
|
|
36
|
+
"@lsync/definitions": "0.0.3",
|
|
37
|
+
"@lsync/transport": "0.0.3"
|
|
39
38
|
},
|
|
40
39
|
"devDependencies": {
|
|
41
40
|
"@cloudflare/workers-types": "^5.20260705.1",
|
package/dist/router-C4eYfMV7.mjs
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { apiCallSchema, batchSchema, collectionSubscriptionResultSchema, collectionSubscriptionSchema, readQuerySchema, syncChangesQuerySchema, webSocketAttachmentSchema } from "@lsync/transport";
|
|
2
|
-
import { initTRPC } from "@trpc/server";
|
|
3
|
-
//#region src/router.ts
|
|
4
|
-
const t = initTRPC.context().create();
|
|
5
|
-
const router = t.router({
|
|
6
|
-
push: t.procedure.input(batchSchema).mutation(({ ctx, input }) => {
|
|
7
|
-
return ctx.mutate(input);
|
|
8
|
-
}),
|
|
9
|
-
read: t.procedure.input(readQuerySchema).query(({ ctx, input }) => {
|
|
10
|
-
return ctx.read(normalizeReadQuery(input));
|
|
11
|
-
}),
|
|
12
|
-
subscribe: t.procedure.input(collectionSubscriptionSchema).output(collectionSubscriptionResultSchema).mutation(({ ctx, input }) => {
|
|
13
|
-
return ctx.subscribe(input);
|
|
14
|
-
}),
|
|
15
|
-
unsubscribe: t.procedure.input(collectionSubscriptionSchema).output(collectionSubscriptionResultSchema).mutation(({ ctx, input }) => {
|
|
16
|
-
return ctx.unsubscribe(input);
|
|
17
|
-
}),
|
|
18
|
-
changes: t.procedure.input(syncChangesQuerySchema).query(({ ctx, input }) => {
|
|
19
|
-
return ctx.changes(input);
|
|
20
|
-
}),
|
|
21
|
-
api: t.procedure.input(apiCallSchema).mutation(({ ctx, input }) => {
|
|
22
|
-
return ctx.callApi(input);
|
|
23
|
-
})
|
|
24
|
-
});
|
|
25
|
-
function normalizeReadQuery(input) {
|
|
26
|
-
return {
|
|
27
|
-
collection: input.collection,
|
|
28
|
-
...input.filters ? { filters: input.filters } : {},
|
|
29
|
-
...input.predicate ? { predicate: input.predicate } : {},
|
|
30
|
-
...input.orderBy ? { orderBy: input.orderBy } : {},
|
|
31
|
-
...input.cursor ? { cursor: input.cursor } : {},
|
|
32
|
-
...input.limit !== void 0 ? { limit: input.limit } : {},
|
|
33
|
-
...input.offset !== void 0 ? { offset: input.offset } : {}
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
//#endregion
|
|
37
|
-
export { webSocketAttachmentSchema as n, router as t };
|
|
38
|
-
|
|
39
|
-
//# sourceMappingURL=router-C4eYfMV7.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"router-C4eYfMV7.mjs","names":[],"sources":["../src/router.ts"],"sourcesContent":["import { initTRPC } from \"@trpc/server\";\nimport {\n apiCallSchema,\n batchSchema,\n collectionSubscriptionResultSchema,\n collectionSubscriptionSchema,\n readQuerySchema,\n syncChangesQuerySchema,\n type ApiCall,\n type Batch,\n type CollectionSubscription,\n type CollectionSubscriptionResult,\n type PushResult,\n type ReadQuery,\n type ReadResult,\n type SequencedBatch,\n type SyncChangesQuery,\n type SyncChangesResult,\n} from \"./types\";\n\nexport interface Context {\n shardId: string;\n validate: (batch: Batch) => void;\n persist: (batch: Batch) => SequencedBatch;\n publish: (batch: SequencedBatch) => void;\n mutate: (batch: Batch) => PushResult;\n subscribe: (input: CollectionSubscription) => CollectionSubscriptionResult;\n unsubscribe: (input: CollectionSubscription) => CollectionSubscriptionResult;\n read: (query: ReadQuery) => ReadResult;\n changes: (query: SyncChangesQuery) => SyncChangesResult;\n callApi: (call: ApiCall) => unknown;\n}\n\nconst t = initTRPC.context<Context>().create();\n\nexport const router = t.router({\n push: t.procedure.input(batchSchema).mutation(({ ctx, input }): PushResult => {\n return ctx.mutate(input);\n }),\n read: t.procedure.input(readQuerySchema).query(({ ctx, input }): ReadResult => {\n return ctx.read(normalizeReadQuery(input));\n }),\n subscribe: t.procedure\n .input(collectionSubscriptionSchema)\n .output(collectionSubscriptionResultSchema)\n .mutation(({ ctx, input }) => {\n return ctx.subscribe(input);\n }),\n unsubscribe: t.procedure\n .input(collectionSubscriptionSchema)\n .output(collectionSubscriptionResultSchema)\n .mutation(({ ctx, input }) => {\n return ctx.unsubscribe(input);\n }),\n changes: t.procedure.input(syncChangesQuerySchema).query(({ ctx, input }): SyncChangesResult => {\n return ctx.changes(input);\n }),\n api: t.procedure.input(apiCallSchema).mutation(({ ctx, input }): unknown => {\n return ctx.callApi(input);\n }),\n});\n\nexport type Router = typeof router;\n\nfunction normalizeReadQuery(input: {\n collection: string;\n filters?: ReadQuery[\"filters\"] | undefined;\n predicate?: ReadQuery[\"predicate\"] | undefined;\n orderBy?: ReadQuery[\"orderBy\"] | undefined;\n cursor?: ReadQuery[\"cursor\"] | undefined;\n limit?: number | undefined;\n offset?: number | undefined;\n}): ReadQuery {\n return {\n collection: input.collection,\n ...(input.filters ? { filters: input.filters } : {}),\n ...(input.predicate ? { predicate: input.predicate } : {}),\n ...(input.orderBy ? { orderBy: input.orderBy } : {}),\n ...(input.cursor ? { cursor: input.cursor } : {}),\n ...(input.limit !== undefined ? { limit: input.limit } : {}),\n ...(input.offset !== undefined ? { offset: input.offset } : {}),\n };\n}\n"],"mappings":";;;AAiCA,MAAM,IAAI,SAAS,QAAiB,CAAC,CAAC,OAAO;AAE7C,MAAa,SAAS,EAAE,OAAO;CAC7B,MAAM,EAAE,UAAU,MAAM,WAAW,CAAC,CAAC,UAAU,EAAE,KAAK,YAAwB;EAC5E,OAAO,IAAI,OAAO,KAAK;CACzB,CAAC;CACD,MAAM,EAAE,UAAU,MAAM,eAAe,CAAC,CAAC,OAAO,EAAE,KAAK,YAAwB;EAC7E,OAAO,IAAI,KAAK,mBAAmB,KAAK,CAAC;CAC3C,CAAC;CACD,WAAW,EAAE,UACV,MAAM,4BAA4B,CAAC,CACnC,OAAO,kCAAkC,CAAC,CAC1C,UAAU,EAAE,KAAK,YAAY;EAC5B,OAAO,IAAI,UAAU,KAAK;CAC5B,CAAC;CACH,aAAa,EAAE,UACZ,MAAM,4BAA4B,CAAC,CACnC,OAAO,kCAAkC,CAAC,CAC1C,UAAU,EAAE,KAAK,YAAY;EAC5B,OAAO,IAAI,YAAY,KAAK;CAC9B,CAAC;CACH,SAAS,EAAE,UAAU,MAAM,sBAAsB,CAAC,CAAC,OAAO,EAAE,KAAK,YAA+B;EAC9F,OAAO,IAAI,QAAQ,KAAK;CAC1B,CAAC;CACD,KAAK,EAAE,UAAU,MAAM,aAAa,CAAC,CAAC,UAAU,EAAE,KAAK,YAAqB;EAC1E,OAAO,IAAI,QAAQ,KAAK;CAC1B,CAAC;AACH,CAAC;AAID,SAAS,mBAAmB,OAQd;CACZ,OAAO;EACL,YAAY,MAAM;EAClB,GAAI,MAAM,UAAU,EAAE,SAAS,MAAM,QAAQ,IAAI,CAAC;EAClD,GAAI,MAAM,YAAY,E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