convex-ents 0.9.5 → 0.10.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/dist/actions.d.ts +6 -0
- package/dist/actions.js +662 -0
- package/dist/actions.js.map +1 -0
- package/dist/deletion.d.ts +1 -1
- package/dist/deletion.js +24 -31
- package/dist/deletion.js.map +1 -1
- package/dist/functions.d.ts +3 -2
- package/dist/functions.js +505 -21
- package/dist/functions.js.map +1 -1
- package/dist/{index-nOBiMg01.d.ts → index-olos0Rx-.d.ts} +387 -23
- package/dist/index.d.ts +2 -1
- package/dist/index.js +676 -21
- package/dist/index.js.map +1 -1
- package/dist/shared.d.ts +17 -0
- package/dist/shared.js +33 -0
- package/dist/shared.js.map +1 -0
- package/dist/writer.d.ts +2 -1
- package/dist/writer.js +24 -8
- package/dist/writer.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import 'convex/server';
|
|
2
|
+
import 'convex/values';
|
|
3
|
+
export { a7 as ActionReadFuncRef, a8 as ActionWriteFuncRef, a6 as EntActionCtx, ab as EntsTableAction, aj as PromiseEdgeAction, al as PromiseEdgeActionOrNull, ak as PromiseEdgeActionOrThrow, ap as PromiseEdgeEntsAction, an as PromiseEdgeEntsActionOrNull, ao as PromiseEdgeOrderedEntsAction, am as PromiseEdgeOrderedEntsActionOrNull, af as PromiseEntAction, ae as PromiseEntActionOrNull, ad as PromiseEntIdAction, ai as PromiseEntsAction, ah as PromiseEntsActionOrNull, ag as PromiseEntsActionOrNulls, aq as PromiseOrderedQueryAction, au as PromiseOrderedQueryActionOrNull, at as PromisePaginationResultAction, as as PromisePaginationResultActionOrNull, ar as PromiseQueryAction, av as PromiseQueryActionOrNull, ac as PromiseTableAction, aw as PromiseTableActionImpl, ay as SerializedSearchFilter, a9 as entsActionReadFactory, aa as entsActionWriteFactory, ax as serializeExpression } from './index-olos0Rx-.js';
|
|
4
|
+
import './schema.js';
|
|
5
|
+
import './shared.js';
|
|
6
|
+
import './deletion.js';
|
package/dist/actions.js
ADDED
|
@@ -0,0 +1,662 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/actions.ts
|
|
21
|
+
var actions_exports = {};
|
|
22
|
+
__export(actions_exports, {
|
|
23
|
+
PromiseTableActionImpl: () => PromiseTableActionImpl,
|
|
24
|
+
entsActionReadFactory: () => entsActionReadFactory,
|
|
25
|
+
entsActionWriteFactory: () => entsActionWriteFactory,
|
|
26
|
+
serializeExpression: () => serializeExpression
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(actions_exports);
|
|
29
|
+
var import_server = require("convex/server");
|
|
30
|
+
|
|
31
|
+
// src/shared.ts
|
|
32
|
+
function getEdgeDefinitions(entDefinitions, table) {
|
|
33
|
+
return entDefinitions[table].edges;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// src/actions.ts
|
|
37
|
+
async function entsActionReadFactory(ctx, args_) {
|
|
38
|
+
const { read } = args_;
|
|
39
|
+
let result;
|
|
40
|
+
for (const call of read) {
|
|
41
|
+
result = addMethodCall(ctx, call, result);
|
|
42
|
+
}
|
|
43
|
+
return await result;
|
|
44
|
+
}
|
|
45
|
+
async function entsActionWriteFactory(ctx, args_) {
|
|
46
|
+
const { write } = args_;
|
|
47
|
+
let result;
|
|
48
|
+
for (const call of write) {
|
|
49
|
+
result = addMethodCall(ctx, call, result);
|
|
50
|
+
}
|
|
51
|
+
return await result;
|
|
52
|
+
}
|
|
53
|
+
function addMethodCall(ctx, call, result) {
|
|
54
|
+
if ("table" in call) {
|
|
55
|
+
const [table, indexName, indexRange] = call.table;
|
|
56
|
+
return ctx.table(table, indexName, deserializeIndexRange(indexRange));
|
|
57
|
+
} else if ("search" in call) {
|
|
58
|
+
const [indexName, filters] = call.search;
|
|
59
|
+
return result.search(indexName, deserializeSearchFilter(filters));
|
|
60
|
+
} else if ("normalizeId" in call) {
|
|
61
|
+
return result.normalizeId(call.normalizeId);
|
|
62
|
+
} else if ("normalizeIdX" in call) {
|
|
63
|
+
return result.normalizeIdX(call.normalizeIdX);
|
|
64
|
+
} else if ("get" in call) {
|
|
65
|
+
return result.get(...call.get);
|
|
66
|
+
} else if ("getX" in call) {
|
|
67
|
+
return result.getX(...call.getX);
|
|
68
|
+
} else if ("getMany" in call) {
|
|
69
|
+
return result.getMany(...call.getMany);
|
|
70
|
+
} else if ("getManyX" in call) {
|
|
71
|
+
return result.getManyX(...call.getManyX);
|
|
72
|
+
} else if ("filter" in call) {
|
|
73
|
+
return result.filter(deserializeFilterPredicate(call.filter));
|
|
74
|
+
} else if ("order" in call) {
|
|
75
|
+
return result.order(...call.order);
|
|
76
|
+
} else if ("take" in call) {
|
|
77
|
+
return result.take(call.take);
|
|
78
|
+
} else if ("paginate" in call) {
|
|
79
|
+
return result.paginate(call.paginate);
|
|
80
|
+
} else if ("first" in call) {
|
|
81
|
+
return result.first();
|
|
82
|
+
} else if ("firstX" in call) {
|
|
83
|
+
return result.firstX();
|
|
84
|
+
} else if ("unique" in call) {
|
|
85
|
+
return result.unique();
|
|
86
|
+
} else if ("uniqueX" in call) {
|
|
87
|
+
return result.uniqueX();
|
|
88
|
+
} else if ("edge" in call) {
|
|
89
|
+
return result.edge(call.edge);
|
|
90
|
+
} else if ("edgeX" in call) {
|
|
91
|
+
return result.edge(call.edgeX);
|
|
92
|
+
} else if ("has" in call) {
|
|
93
|
+
return result.has(call.has);
|
|
94
|
+
} else if ("insert" in call) {
|
|
95
|
+
return result.insert(call.insert);
|
|
96
|
+
} else if ("insertMany" in call) {
|
|
97
|
+
return result.insertMany(call.insertMany);
|
|
98
|
+
} else if ("patch" in call) {
|
|
99
|
+
return result.patch(call.patch);
|
|
100
|
+
} else if ("replace" in call) {
|
|
101
|
+
return result.replace(call.replace);
|
|
102
|
+
} else if ("delete" in call) {
|
|
103
|
+
return result.delete();
|
|
104
|
+
} else {
|
|
105
|
+
call;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
var PromiseQueryActionOrNullImpl = class _PromiseQueryActionOrNullImpl extends Promise {
|
|
109
|
+
constructor(ctx, entDefinitions, table, read) {
|
|
110
|
+
super(() => {
|
|
111
|
+
});
|
|
112
|
+
this.ctx = ctx;
|
|
113
|
+
this.entDefinitions = entDefinitions;
|
|
114
|
+
this.table = table;
|
|
115
|
+
this.read = read;
|
|
116
|
+
}
|
|
117
|
+
filter(predicate) {
|
|
118
|
+
return new _PromiseQueryActionOrNullImpl(
|
|
119
|
+
this.ctx,
|
|
120
|
+
this.entDefinitions,
|
|
121
|
+
this.table,
|
|
122
|
+
this.read.concat({ filter: serializeFilterPredicate(predicate) })
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
order(order, indexName) {
|
|
126
|
+
return new _PromiseQueryActionOrNullImpl(
|
|
127
|
+
this.ctx,
|
|
128
|
+
this.entDefinitions,
|
|
129
|
+
this.table,
|
|
130
|
+
this.read.concat({
|
|
131
|
+
order: [
|
|
132
|
+
order,
|
|
133
|
+
...indexName === void 0 ? [] : [indexName]
|
|
134
|
+
]
|
|
135
|
+
})
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
paginate(paginationOpts) {
|
|
139
|
+
return new PromisePaginationResultActionOrNullImpl(
|
|
140
|
+
this.ctx,
|
|
141
|
+
this.entDefinitions,
|
|
142
|
+
this.table,
|
|
143
|
+
this.read.concat({ paginate: paginationOpts })
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
async take(n) {
|
|
147
|
+
return await runRead(this.ctx, this.read.concat({ take: n }));
|
|
148
|
+
}
|
|
149
|
+
first() {
|
|
150
|
+
return new PromiseEntActionImpl(
|
|
151
|
+
this.ctx,
|
|
152
|
+
this.entDefinitions,
|
|
153
|
+
this.table,
|
|
154
|
+
this.read.concat({ first: true })
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
firstX() {
|
|
158
|
+
return new PromiseEntActionImpl(
|
|
159
|
+
this.ctx,
|
|
160
|
+
this.entDefinitions,
|
|
161
|
+
this.table,
|
|
162
|
+
this.read.concat({ firstX: true })
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
unique() {
|
|
166
|
+
return new PromiseEntActionImpl(
|
|
167
|
+
this.ctx,
|
|
168
|
+
this.entDefinitions,
|
|
169
|
+
this.table,
|
|
170
|
+
this.read.concat({ unique: true })
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
uniqueX() {
|
|
174
|
+
return new PromiseEntActionImpl(
|
|
175
|
+
this.ctx,
|
|
176
|
+
this.entDefinitions,
|
|
177
|
+
this.table,
|
|
178
|
+
this.read.concat({ uniqueX: true })
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
then(onfulfilled, onrejected) {
|
|
182
|
+
const docs = runRead(this.ctx, this.read);
|
|
183
|
+
return docs.then(onfulfilled, onrejected);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
var PromiseEdgeActionOrNullImpl = class extends PromiseQueryActionOrNullImpl {
|
|
187
|
+
async has(targetId) {
|
|
188
|
+
return runRead(this.ctx, this.read.concat({ has: targetId }));
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
var PromiseTableActionImpl = class extends PromiseQueryActionOrNullImpl {
|
|
192
|
+
constructor(ctx, entDefinitions, table) {
|
|
193
|
+
super(ctx, entDefinitions, table, [{ table: [table] }]);
|
|
194
|
+
}
|
|
195
|
+
get(...args) {
|
|
196
|
+
return new PromiseEntActionImpl(
|
|
197
|
+
this.ctx,
|
|
198
|
+
this.entDefinitions,
|
|
199
|
+
this.table,
|
|
200
|
+
this.read.concat({ get: args })
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
getX(...args) {
|
|
204
|
+
return new PromiseEntActionImpl(
|
|
205
|
+
this.ctx,
|
|
206
|
+
this.entDefinitions,
|
|
207
|
+
this.table,
|
|
208
|
+
this.read.concat({ getX: args })
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
async getMany(...args) {
|
|
212
|
+
return await runRead(this.ctx, this.read.concat({ getMany: args }));
|
|
213
|
+
}
|
|
214
|
+
async getManyX(...args) {
|
|
215
|
+
return await runRead(this.ctx, this.read.concat({ getManyX: args }));
|
|
216
|
+
}
|
|
217
|
+
async normalizeId(id) {
|
|
218
|
+
return await runRead(this.ctx, this.read.concat({ normalizeId: id }));
|
|
219
|
+
}
|
|
220
|
+
async normalizeIdX(id) {
|
|
221
|
+
return await runRead(this.ctx, this.read.concat({ normalizeIdX: id }));
|
|
222
|
+
}
|
|
223
|
+
withIndex(indexName, indexRange) {
|
|
224
|
+
return new PromiseQueryActionOrNullImpl(
|
|
225
|
+
this.ctx,
|
|
226
|
+
this.entDefinitions,
|
|
227
|
+
this.table,
|
|
228
|
+
[
|
|
229
|
+
{
|
|
230
|
+
table: [
|
|
231
|
+
this.table,
|
|
232
|
+
indexName,
|
|
233
|
+
serializeIndexRange(indexRange)
|
|
234
|
+
]
|
|
235
|
+
}
|
|
236
|
+
]
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
search(indexName, searchFilter) {
|
|
240
|
+
return new PromiseQueryActionOrNullImpl(
|
|
241
|
+
this.ctx,
|
|
242
|
+
this.entDefinitions,
|
|
243
|
+
this.table,
|
|
244
|
+
this.read.concat({
|
|
245
|
+
search: [indexName, serializeSearchFilter(searchFilter)]
|
|
246
|
+
})
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
insert(value) {
|
|
250
|
+
return new PromiseEntIdActionImpl(
|
|
251
|
+
this.ctx,
|
|
252
|
+
this.entDefinitions,
|
|
253
|
+
this.table,
|
|
254
|
+
this.read.concat({ insert: value })
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
// TODO: fluent API
|
|
258
|
+
async insertMany(values) {
|
|
259
|
+
return await runWrite(
|
|
260
|
+
this.ctx,
|
|
261
|
+
this.read.concat({ insertMany: values })
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
var PromisePaginationResultActionOrNullImpl = class extends Promise {
|
|
266
|
+
constructor(ctx, entDefinitions, table, read) {
|
|
267
|
+
super(() => {
|
|
268
|
+
});
|
|
269
|
+
this.ctx = ctx;
|
|
270
|
+
this.entDefinitions = entDefinitions;
|
|
271
|
+
this.table = table;
|
|
272
|
+
this.read = read;
|
|
273
|
+
}
|
|
274
|
+
then(onfulfilled, onrejected) {
|
|
275
|
+
return runRead(this.ctx, this.read).then(onfulfilled, onrejected);
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
var PromiseEntActionImpl = class _PromiseEntActionImpl extends Promise {
|
|
279
|
+
constructor(ctx, entDefinitions, table, read) {
|
|
280
|
+
super(() => {
|
|
281
|
+
});
|
|
282
|
+
this.ctx = ctx;
|
|
283
|
+
this.entDefinitions = entDefinitions;
|
|
284
|
+
this.table = table;
|
|
285
|
+
this.read = read;
|
|
286
|
+
}
|
|
287
|
+
then(onfulfilled, onrejected) {
|
|
288
|
+
return runRead(this.ctx, this.read).then(onfulfilled, onrejected);
|
|
289
|
+
}
|
|
290
|
+
edge(edge) {
|
|
291
|
+
return this.edgeImpl(edge);
|
|
292
|
+
}
|
|
293
|
+
edgeX(edge) {
|
|
294
|
+
return this.edgeImpl(edge, true);
|
|
295
|
+
}
|
|
296
|
+
edgeImpl(edge, throwIfNull = false) {
|
|
297
|
+
const edgeDefinition = getEdgeDefinitions(this.entDefinitions, this.table)[edge];
|
|
298
|
+
const read = throwIfNull ? { edgeX: edge } : { edge };
|
|
299
|
+
if (edgeDefinition.cardinality === "multiple") {
|
|
300
|
+
if (edgeDefinition.type === "ref") {
|
|
301
|
+
return new PromiseEdgeActionOrNullImpl(
|
|
302
|
+
this.ctx,
|
|
303
|
+
this.entDefinitions,
|
|
304
|
+
edgeDefinition.to,
|
|
305
|
+
this.read.concat(read)
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
return new PromiseQueryActionOrNullImpl(
|
|
309
|
+
this.ctx,
|
|
310
|
+
this.entDefinitions,
|
|
311
|
+
edgeDefinition.to,
|
|
312
|
+
this.read.concat(read)
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
return new _PromiseEntActionImpl(
|
|
316
|
+
this.ctx,
|
|
317
|
+
this.entDefinitions,
|
|
318
|
+
edgeDefinition.to,
|
|
319
|
+
this.read.concat(read)
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
patch(value) {
|
|
323
|
+
return new PromiseEntIdActionImpl(
|
|
324
|
+
this.ctx,
|
|
325
|
+
this.entDefinitions,
|
|
326
|
+
this.table,
|
|
327
|
+
this.read.concat({ patch: value })
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
replace(value) {
|
|
331
|
+
return new PromiseEntIdActionImpl(
|
|
332
|
+
this.ctx,
|
|
333
|
+
this.entDefinitions,
|
|
334
|
+
this.table,
|
|
335
|
+
this.read.concat({ replace: value })
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
async delete() {
|
|
339
|
+
return await runWrite(
|
|
340
|
+
this.ctx,
|
|
341
|
+
this.read.concat({ delete: true })
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
var PromiseEntIdActionImpl = class extends Promise {
|
|
346
|
+
constructor(ctx, entDefinitions, table, write) {
|
|
347
|
+
super(() => {
|
|
348
|
+
});
|
|
349
|
+
this.ctx = ctx;
|
|
350
|
+
this.entDefinitions = entDefinitions;
|
|
351
|
+
this.table = table;
|
|
352
|
+
this.write = write;
|
|
353
|
+
}
|
|
354
|
+
async get() {
|
|
355
|
+
return await runWrite(this.ctx, this.write.concat({ get: [] }));
|
|
356
|
+
}
|
|
357
|
+
then(onfulfilled, onrejected) {
|
|
358
|
+
return runWrite(this.ctx, this.write).then(onfulfilled, onrejected);
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
async function runRead(ctx, read) {
|
|
362
|
+
const readRef = ctx?.actionRead ?? (0, import_server.makeFunctionReference)("functions:read");
|
|
363
|
+
return await ctx.runQuery(readRef, { read });
|
|
364
|
+
}
|
|
365
|
+
async function runWrite(ctx, write) {
|
|
366
|
+
const writeRef = ctx?.actionRead ?? (0, import_server.makeFunctionReference)("functions:write");
|
|
367
|
+
return await ctx.runMutation(writeRef, { write });
|
|
368
|
+
}
|
|
369
|
+
var IndexRangeBuilderImpl = class _IndexRangeBuilderImpl {
|
|
370
|
+
constructor(rangeExpressions) {
|
|
371
|
+
this.rangeExpressions = rangeExpressions;
|
|
372
|
+
}
|
|
373
|
+
static new() {
|
|
374
|
+
return new _IndexRangeBuilderImpl([]);
|
|
375
|
+
}
|
|
376
|
+
eq(fieldName, value) {
|
|
377
|
+
return new _IndexRangeBuilderImpl(
|
|
378
|
+
this.rangeExpressions.concat({
|
|
379
|
+
type: "Eq",
|
|
380
|
+
fieldPath: fieldName,
|
|
381
|
+
value: value === void 0 ? "$undefined" : value
|
|
382
|
+
})
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
gt(fieldName, value) {
|
|
386
|
+
return new _IndexRangeBuilderImpl(
|
|
387
|
+
this.rangeExpressions.concat({
|
|
388
|
+
type: "Gt",
|
|
389
|
+
fieldPath: fieldName,
|
|
390
|
+
value
|
|
391
|
+
})
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
gte(fieldName, value) {
|
|
395
|
+
return new _IndexRangeBuilderImpl(
|
|
396
|
+
this.rangeExpressions.concat({
|
|
397
|
+
type: "Gte",
|
|
398
|
+
fieldPath: fieldName,
|
|
399
|
+
value
|
|
400
|
+
})
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
lt(fieldName, value) {
|
|
404
|
+
return new _IndexRangeBuilderImpl(
|
|
405
|
+
this.rangeExpressions.concat({
|
|
406
|
+
type: "Lt",
|
|
407
|
+
fieldPath: fieldName,
|
|
408
|
+
value
|
|
409
|
+
})
|
|
410
|
+
);
|
|
411
|
+
}
|
|
412
|
+
lte(fieldName, value) {
|
|
413
|
+
return new _IndexRangeBuilderImpl(
|
|
414
|
+
this.rangeExpressions.concat({
|
|
415
|
+
type: "Lte",
|
|
416
|
+
fieldPath: fieldName,
|
|
417
|
+
value
|
|
418
|
+
})
|
|
419
|
+
);
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
function serializeIndexRange(indexRange) {
|
|
423
|
+
if (indexRange === void 0) {
|
|
424
|
+
return void 0;
|
|
425
|
+
}
|
|
426
|
+
return (indexRange?.(
|
|
427
|
+
IndexRangeBuilderImpl.new()
|
|
428
|
+
)).rangeExpressions;
|
|
429
|
+
}
|
|
430
|
+
function deserializeIndexRange(rangeExpressions) {
|
|
431
|
+
if (rangeExpressions === void 0) {
|
|
432
|
+
return void 0;
|
|
433
|
+
}
|
|
434
|
+
return (q) => {
|
|
435
|
+
for (const range of rangeExpressions) {
|
|
436
|
+
switch (range.type) {
|
|
437
|
+
case "Eq":
|
|
438
|
+
q = q.eq(
|
|
439
|
+
range.fieldPath,
|
|
440
|
+
range.value === "$undefined" ? void 0 : range.value
|
|
441
|
+
);
|
|
442
|
+
break;
|
|
443
|
+
case "Gt":
|
|
444
|
+
q = q.gt(range.fieldPath, range.value);
|
|
445
|
+
break;
|
|
446
|
+
case "Gte":
|
|
447
|
+
q = q.gte(range.fieldPath, range.value);
|
|
448
|
+
break;
|
|
449
|
+
case "Lt":
|
|
450
|
+
q = q.lt(range.fieldPath, range.value);
|
|
451
|
+
break;
|
|
452
|
+
case "Lte":
|
|
453
|
+
q = q.lte(range.fieldPath, range.value);
|
|
454
|
+
break;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
return q;
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
function serializeFilterPredicate(predicate) {
|
|
461
|
+
return serializeExpression(predicate(filterBuilderImpl));
|
|
462
|
+
}
|
|
463
|
+
function deserializeFilterPredicate(predicate) {
|
|
464
|
+
return (q) => deserializeFilterExpression(q, predicate);
|
|
465
|
+
}
|
|
466
|
+
var binaryOps = [
|
|
467
|
+
"eq",
|
|
468
|
+
"neq",
|
|
469
|
+
"lt",
|
|
470
|
+
"lte",
|
|
471
|
+
"gt",
|
|
472
|
+
"gte",
|
|
473
|
+
"add",
|
|
474
|
+
"sub",
|
|
475
|
+
"mul",
|
|
476
|
+
"div",
|
|
477
|
+
"mod",
|
|
478
|
+
"and",
|
|
479
|
+
"or"
|
|
480
|
+
];
|
|
481
|
+
function deserializeFilterExpression(q, expression) {
|
|
482
|
+
if ("field" in expression) {
|
|
483
|
+
const fieldPath = expression["field"];
|
|
484
|
+
return q.field(fieldPath);
|
|
485
|
+
}
|
|
486
|
+
if ("literal" in expression) {
|
|
487
|
+
const literal = expression["literal"];
|
|
488
|
+
return literal === "$undefined" ? void 0 : literal;
|
|
489
|
+
}
|
|
490
|
+
if ("neg" in expression) {
|
|
491
|
+
return q.neg(deserializeFilterExpression(q, expression["neg"]));
|
|
492
|
+
}
|
|
493
|
+
if ("not" in expression) {
|
|
494
|
+
return q.not(deserializeFilterExpression(q, expression["not"]));
|
|
495
|
+
}
|
|
496
|
+
for (const op of binaryOps) {
|
|
497
|
+
if (op in expression) {
|
|
498
|
+
const [l, r] = expression[op];
|
|
499
|
+
return q[op](
|
|
500
|
+
deserializeFilterExpression(q, l),
|
|
501
|
+
deserializeFilterExpression(q, r)
|
|
502
|
+
);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
throw new Error(
|
|
506
|
+
"Expected a valid filter expression, got " + JSON.stringify(expression)
|
|
507
|
+
);
|
|
508
|
+
}
|
|
509
|
+
var filterBuilderImpl = {
|
|
510
|
+
// Comparisons /////////////////////////////////////////////////////////////
|
|
511
|
+
eq(l, r) {
|
|
512
|
+
return new FilterExpression({
|
|
513
|
+
eq: [serializeExpression(l), serializeExpression(r)]
|
|
514
|
+
});
|
|
515
|
+
},
|
|
516
|
+
neq(l, r) {
|
|
517
|
+
return new FilterExpression({
|
|
518
|
+
neq: [serializeExpression(l), serializeExpression(r)]
|
|
519
|
+
});
|
|
520
|
+
},
|
|
521
|
+
lt(l, r) {
|
|
522
|
+
return new FilterExpression({
|
|
523
|
+
lt: [serializeExpression(l), serializeExpression(r)]
|
|
524
|
+
});
|
|
525
|
+
},
|
|
526
|
+
lte(l, r) {
|
|
527
|
+
return new FilterExpression({
|
|
528
|
+
lte: [serializeExpression(l), serializeExpression(r)]
|
|
529
|
+
});
|
|
530
|
+
},
|
|
531
|
+
gt(l, r) {
|
|
532
|
+
return new FilterExpression({
|
|
533
|
+
gt: [serializeExpression(l), serializeExpression(r)]
|
|
534
|
+
});
|
|
535
|
+
},
|
|
536
|
+
gte(l, r) {
|
|
537
|
+
return new FilterExpression({
|
|
538
|
+
gte: [serializeExpression(l), serializeExpression(r)]
|
|
539
|
+
});
|
|
540
|
+
},
|
|
541
|
+
// Arithmetic //////////////////////////////////////////////////////////////
|
|
542
|
+
add(l, r) {
|
|
543
|
+
return new FilterExpression({
|
|
544
|
+
add: [serializeExpression(l), serializeExpression(r)]
|
|
545
|
+
});
|
|
546
|
+
},
|
|
547
|
+
sub(l, r) {
|
|
548
|
+
return new FilterExpression({
|
|
549
|
+
sub: [serializeExpression(l), serializeExpression(r)]
|
|
550
|
+
});
|
|
551
|
+
},
|
|
552
|
+
mul(l, r) {
|
|
553
|
+
return new FilterExpression({
|
|
554
|
+
mul: [serializeExpression(l), serializeExpression(r)]
|
|
555
|
+
});
|
|
556
|
+
},
|
|
557
|
+
div(l, r) {
|
|
558
|
+
return new FilterExpression({
|
|
559
|
+
div: [serializeExpression(l), serializeExpression(r)]
|
|
560
|
+
});
|
|
561
|
+
},
|
|
562
|
+
mod(l, r) {
|
|
563
|
+
return new FilterExpression({
|
|
564
|
+
mod: [serializeExpression(l), serializeExpression(r)]
|
|
565
|
+
});
|
|
566
|
+
},
|
|
567
|
+
neg(x) {
|
|
568
|
+
return new FilterExpression({ neg: serializeExpression(x) });
|
|
569
|
+
},
|
|
570
|
+
// Logic ///////////////////////////////////////////////////////////////////
|
|
571
|
+
and(...exprs) {
|
|
572
|
+
return new FilterExpression({ and: exprs.map(serializeExpression) });
|
|
573
|
+
},
|
|
574
|
+
or(...exprs) {
|
|
575
|
+
return new FilterExpression({ or: exprs.map(serializeExpression) });
|
|
576
|
+
},
|
|
577
|
+
not(x) {
|
|
578
|
+
return new FilterExpression({ not: serializeExpression(x) });
|
|
579
|
+
},
|
|
580
|
+
// Other ///////////////////////////////////////////////////////////////////
|
|
581
|
+
field(fieldPath) {
|
|
582
|
+
return new FilterExpression({ field: fieldPath });
|
|
583
|
+
}
|
|
584
|
+
};
|
|
585
|
+
function serializeExpression(expr) {
|
|
586
|
+
if (expr instanceof FilterExpression) {
|
|
587
|
+
return expr.serialize();
|
|
588
|
+
} else {
|
|
589
|
+
return {
|
|
590
|
+
literal: expr === void 0 ? "$undefined" : expr
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
var FilterExpression = class {
|
|
595
|
+
inner;
|
|
596
|
+
constructor(inner) {
|
|
597
|
+
this.inner = inner;
|
|
598
|
+
}
|
|
599
|
+
serialize() {
|
|
600
|
+
return this.inner;
|
|
601
|
+
}
|
|
602
|
+
};
|
|
603
|
+
function serializeSearchFilter(searchFilter) {
|
|
604
|
+
return searchFilter(
|
|
605
|
+
SearchFilterBuilderImpl.new()
|
|
606
|
+
).export();
|
|
607
|
+
}
|
|
608
|
+
function deserializeSearchFilter(filters) {
|
|
609
|
+
return (q) => {
|
|
610
|
+
for (const filter of filters) {
|
|
611
|
+
switch (filter.type) {
|
|
612
|
+
case "Search":
|
|
613
|
+
q = q.search(filter.fieldPath, filter.value);
|
|
614
|
+
break;
|
|
615
|
+
case "Eq":
|
|
616
|
+
q = q.eq(
|
|
617
|
+
filter.fieldPath,
|
|
618
|
+
filter.value === "$undefined" ? void 0 : filter.value
|
|
619
|
+
);
|
|
620
|
+
break;
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
return q;
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
var SearchFilterBuilderImpl = class _SearchFilterBuilderImpl {
|
|
627
|
+
constructor(filters) {
|
|
628
|
+
this.filters = filters;
|
|
629
|
+
}
|
|
630
|
+
static new() {
|
|
631
|
+
return new _SearchFilterBuilderImpl([]);
|
|
632
|
+
}
|
|
633
|
+
search(fieldName, query) {
|
|
634
|
+
return new _SearchFilterBuilderImpl(
|
|
635
|
+
this.filters.concat({
|
|
636
|
+
type: "Search",
|
|
637
|
+
fieldPath: fieldName,
|
|
638
|
+
value: query
|
|
639
|
+
})
|
|
640
|
+
);
|
|
641
|
+
}
|
|
642
|
+
eq(fieldName, value) {
|
|
643
|
+
return new _SearchFilterBuilderImpl(
|
|
644
|
+
this.filters.concat({
|
|
645
|
+
type: "Eq",
|
|
646
|
+
fieldPath: fieldName,
|
|
647
|
+
value: value === void 0 ? "$undefiend" : value
|
|
648
|
+
})
|
|
649
|
+
);
|
|
650
|
+
}
|
|
651
|
+
export() {
|
|
652
|
+
return this.filters;
|
|
653
|
+
}
|
|
654
|
+
};
|
|
655
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
656
|
+
0 && (module.exports = {
|
|
657
|
+
PromiseTableActionImpl,
|
|
658
|
+
entsActionReadFactory,
|
|
659
|
+
entsActionWriteFactory,
|
|
660
|
+
serializeExpression
|
|
661
|
+
});
|
|
662
|
+
//# sourceMappingURL=actions.js.map
|