@omegup/msync 0.1.67 → 0.1.69

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/index.js CHANGED
@@ -68,6 +68,45 @@ const map1 = (k, to) => {
68
68
  return { [k]: [k2, to] };
69
69
  };
70
70
  //#endregion
71
+ //#region .build/lib/field/field.js
72
+ var Field = class Field {
73
+ field;
74
+ raw;
75
+ concat;
76
+ has(p) {
77
+ return { raw: (f) => ({ [f.with(this).str()]: p.raw }) };
78
+ }
79
+ constructor(field, raw, concat) {
80
+ this.field = field;
81
+ this.raw = raw;
82
+ this.concat = concat;
83
+ }
84
+ static root = () => {
85
+ const concat = (f1, f2) => new Field([f1.field, f2.field].filter(id$1).join("."), f1.raw, f1.concat);
86
+ return new Field("", (s) => s ? `$${s}` : "$$ROOT", concat);
87
+ };
88
+ static ctx = () => (k) => {
89
+ const concat = (_, f2) => new Field(f2.field, f2.raw, f2.concat);
90
+ return new Field(k, (s) => `$$${s}`, concat);
91
+ };
92
+ of(k) {
93
+ return new Field([this.field, k].filter(id$1).join("."), this.raw, this.concat);
94
+ }
95
+ with(k) {
96
+ return k.concat(this, k);
97
+ }
98
+ str() {
99
+ return this.field;
100
+ }
101
+ exprRaw() {
102
+ return asExprRaw(this.raw(this.field));
103
+ }
104
+ expr() {
105
+ return asExpr({ raw: (f) => f.with(this).exprRaw() });
106
+ }
107
+ };
108
+ const { root, ctx } = Field;
109
+ //#endregion
71
110
  //#region .build/lib/utils/map-object.js
72
111
  const mapExactToObject0 = (x, f) => {
73
112
  const filter = (x) => x.filter((x) => x[0] === x[1][0]);
@@ -88,9 +127,116 @@ const spread0 = (a, b) => ({
88
127
  ...mapExact0(b, id$1)
89
128
  });
90
129
  //#endregion
130
+ //#region .build/lib/expression/concat.js
131
+ const concat = (...expr) => asExpr({ raw: (f) => asExprRaw({ $concat: expr.map((e) => e.raw(f).get()) }) });
132
+ const $substr = (expr, start, length) => asExpr({ raw: (f) => asExprRaw({ $substrCP: [
133
+ expr.raw(f).get(),
134
+ start.raw(f).get(),
135
+ length.raw(f).get()
136
+ ] }) });
137
+ const padLeft = (expr, pad) => asExpr({ raw: (f) => asExprRaw({ $let: {
138
+ vars: { x: { $concat: [{ $literal: pad }, expr.raw(f).get()] } },
139
+ in: { $substrCP: [
140
+ "$$x",
141
+ { $subtract: [{ $strLenCP: "$$x" }, pad.length] },
142
+ pad.length
143
+ ] }
144
+ } }) });
145
+ const regex = (expr, regex, options) => asExpr({ raw: (f) => asExprRaw({ $regexMatch: {
146
+ input: expr.raw(f).get(),
147
+ regex: regex.raw(f).get(),
148
+ options: options?.raw(f).get()
149
+ } }) });
150
+ const str = (expr) => asExpr({ raw: (f) => asExprRaw({ $toString: expr.raw(f).get() }) });
151
+ const toInt = (expr) => asExpr({ raw: (f) => asExprRaw({ $toInt: expr.raw(f).get() }) });
152
+ const fieldM = (expr, m) => asExpr({ raw: (f) => asExprRaw(Object.fromEntries(Object.entries(m).flatMap(([dom, ref]) => expr[ref] ? [[dom, expr[ref].raw(f).get()]] : []))) });
153
+ const mergeExact = (...[exprsExact1, exprsExact2]) => spread(exprsExact1, exprsExact2);
154
+ const mergeExact0 = (...[exprsExact1, exprsExact2]) => spread0(exprsExact1, exprsExact2);
155
+ const mergeExpr = (...exprs) => mergeExact(...exprs);
156
+ const fieldF = () => (exprs) => Object.keys(exprs).length ? asExpr({ raw: (f) => asExprRaw(mapExactToObject(exprs, (e) => e.raw(f).get())) }) : asExpr(val(safeNarrow()({})));
157
+ const field = fieldF();
158
+ //#endregion
159
+ //#region .build/lib/expression/array.js
160
+ const size = (expr) => asExpr({ raw: (f) => asExprRaw({ $size: expr.raw(f).get() }) });
161
+ const filterDefined = (expr) => filter({
162
+ expr,
163
+ as: "x",
164
+ cond: ctx()("x").expr()
165
+ });
166
+ const filter = ({ as, cond, expr, limit }) => asExpr({ raw: (f) => asExprRaw({ $filter: {
167
+ input: expr.raw(f).get(),
168
+ as,
169
+ cond: cond.raw(f).get(),
170
+ ...limit ? { limit: limit.raw(f).get() } : {}
171
+ } }) });
172
+ const sortArray = ({ sortBy, expr, order }) => asExpr({ raw: (f) => asExprRaw({ $sortArray: {
173
+ input: expr.raw(f).get(),
174
+ sortBy: { [sortBy]: order ?? -1 }
175
+ } }) });
176
+ const isArray = (expr) => asBoolExpr({ raw: (f) => asExprRaw({ $isArray: expr.raw(f).get() }) });
177
+ const inArray = (item, expr) => asExpr({ raw: (f) => asExprRaw({ $in: [item.raw(f).get(), expr.raw(f).get()] }) });
178
+ const array = (...exprs) => asExpr({ raw: (f) => asExprRaw(exprs.map((x) => x.raw(f).get())) });
179
+ const concatArray = (...exprs) => asExpr({ raw: (f) => asExprRaw({ $concatArrays: exprs.map((x) => x.raw(f).get()) }) });
180
+ const $setUnion = (...exprs) => asExpr({ raw: (f) => asExprRaw({ $setUnion: exprs.map((x) => x.raw(f).get()) }) });
181
+ const first = (expr) => asExpr({ raw: (f) => asExprRaw({ $first: expr.raw(f).get() }) });
182
+ const firstSure = first;
183
+ const last = (expr) => asExpr({ raw: (f) => asExprRaw({ $last: expr.raw(f).get() }) });
184
+ const mergeObjects = (...exprs) => asExpr({ raw: (f) => asExprRaw({ $mergeObjects: exprs.map((x) => x.raw(f).get()) }) });
185
+ const $objectToArray = (expr) => asExpr({ raw: (f) => asExprRaw({ $objectToArray: expr.raw(f).get() }) });
186
+ const $arrayToObject = (expr) => asExpr({ raw: (f) => asExprRaw({ $arrayToObject: expr.raw(f).get() }) });
187
+ const anyElementTrue = (expr) => asExpr({ raw: (f) => asExprRaw({ $anyElementTrue: expr.raw(f).get() }) });
188
+ const $reduce = (input, initialValue, inExpr) => asExpr({ raw: (f) => asExprRaw({ $reduce: {
189
+ input: input.raw(f).get(),
190
+ initialValue: initialValue.raw(f).get(),
191
+ in: inExpr.raw(f).get()
192
+ } }) });
193
+ const indexOfArray = (array, item) => asExpr({ raw: (f) => asExprRaw({ $indexOfArray: [array.raw(f).get(), item.raw(f).get()] }) });
194
+ const slice = (array, start, end) => asExpr({ raw: (f) => asExprRaw({ $slice: [
195
+ array.raw(f).get(),
196
+ start.raw(f).get(),
197
+ end.raw(f).get()
198
+ ] }) });
199
+ const except = (a, b) => {
200
+ const value = ctx()("value");
201
+ const out = value.of("out").expr();
202
+ const except = value.of("except").expr();
203
+ const curr = ctx()("this").expr();
204
+ const indexInExcept = ctx()("indexInExcept").expr();
205
+ return $let({ res: ["res", $reduce(a, field({
206
+ out: ["out", array()],
207
+ except: ["except", b]
208
+ }), $let({ indexInExcept: ["indexInExcept", indexOfArray(except, curr)] }, ite(gte(indexInExcept, val(0)), field({
209
+ out: ["out", out],
210
+ except: ["except", concatArray(ite(eq(indexInExcept)(val(0)), array(), slice(except, val(0), indexInExcept)), slice(except, add(indexInExcept, val(1)), size(except)))]
211
+ }), field({
212
+ out: ["out", concatArray(out, array(curr))],
213
+ except: ["except", except]
214
+ }))))] }, ctx()("res").of("out").expr());
215
+ };
216
+ //#endregion
217
+ //#region .build/lib/expression/range.js
218
+ const range = (start, end, step) => asExpr({ raw: (f) => asExprRaw({ $range: [
219
+ start.raw(f).get(),
220
+ end.raw(f).get(),
221
+ step?.raw(f).get() ?? 1
222
+ ] }) });
223
+ const $map0 = ({ as, expr, input }) => asExpr({ raw: (f) => asExprRaw({ $map: {
224
+ input: input.raw(f).get(),
225
+ as,
226
+ in: expr.raw(f).get()
227
+ } }) });
228
+ const $map1 = (ex, map) => $map0({
229
+ input: ex,
230
+ as: "item",
231
+ expr: map(ctx()("item"))
232
+ });
233
+ const $map = (ex, map) => $map1(ex, (i) => map(i.expr()));
234
+ //#endregion
91
235
  //#region .build/lib/expression/val.js
92
236
  const val = (val) => asExpr({ raw: () => asExprRaw(val && typeof val === "object" && !(val instanceof Date) || typeof val === "string" && val[0] === "$" ? { $literal: val } : val) });
93
237
  const current = asExpr({ raw: () => asExprRaw("$$CLUSTER_TIME") });
238
+ const $rand = asExpr({ raw: () => asExprRaw({ $rand: {} }) });
239
+ const rand = $reduce(range(val(0), val(17)), val(""), concat(ctx()("value").expr(), $substr(val("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), floor(multiply($rand, val(62))), val(1))));
94
240
  const $let = (vars, inExpr) => asExpr({ raw: (f) => asExprRaw({ $let: {
95
241
  vars: mapExactToObject(vars, (v) => v.raw(f).get()),
96
242
  in: inExpr.raw(f).get()
@@ -105,11 +251,6 @@ const func = (f, ...args) => asExpr({ raw: (field) => asExprRaw({ $function: {
105
251
  args: args.map((x) => x.raw(field).get()),
106
252
  lang: "js"
107
253
  } }) });
108
- const rand = function() {
109
- const s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
110
- return Array(17).fill(0).map(() => s[Math.floor(Math.random() * 62)]).join("");
111
- };
112
- const $rand = func(rand);
113
254
  //#endregion
114
255
  //#region .build/lib/expression/logic.js
115
256
  const ite = ((cond, then, orelse) => asExpr({ raw: (f) => asExprRaw({ $cond: {
@@ -140,45 +281,6 @@ const setField = ({ field, input, value }) => asExpr({ raw: (f) => asExprRaw({ $
140
281
  value: value.raw(f).get()
141
282
  } }) });
142
283
  //#endregion
143
- //#region .build/lib/field/field.js
144
- var Field = class Field {
145
- field;
146
- raw;
147
- concat;
148
- has(p) {
149
- return { raw: (f) => ({ [f.with(this).str()]: p.raw }) };
150
- }
151
- constructor(field, raw, concat) {
152
- this.field = field;
153
- this.raw = raw;
154
- this.concat = concat;
155
- }
156
- static root = () => {
157
- const concat = (f1, f2) => new Field([f1.field, f2.field].filter(id$1).join("."), f1.raw, f1.concat);
158
- return new Field("", (s) => s ? `$${s}` : "$$ROOT", concat);
159
- };
160
- static ctx = () => (k) => {
161
- const concat = (_, f2) => new Field(f2.field, f2.raw, f2.concat);
162
- return new Field(k, (s) => `$$${s}`, concat);
163
- };
164
- of(k) {
165
- return new Field([this.field, k].filter(id$1).join("."), this.raw, this.concat);
166
- }
167
- with(k) {
168
- return k.concat(this, k);
169
- }
170
- str() {
171
- return this.field;
172
- }
173
- exprRaw() {
174
- return asExprRaw(this.raw(this.field));
175
- }
176
- expr() {
177
- return asExpr({ raw: (f) => f.with(this).exprRaw() });
178
- }
179
- };
180
- const { root, ctx } = Field;
181
- //#endregion
182
284
  //#region .build/lib/accumulators/index.js
183
285
  const asAccumulator = (x) => x;
184
286
  const $sum_ = (expr) => ({ raw: (f) => asAccumulator({ $sum: expr.raw(f).get() }) });
@@ -320,90 +422,6 @@ const concatTStages = ({ coll, exec, input }, stages) => ({
320
422
  exec: concatStages(exec, stages)
321
423
  });
322
424
  //#endregion
323
- //#region .build/lib/expression/concat.js
324
- const concat = (...expr) => asExpr({ raw: (f) => asExprRaw({ $concat: expr.map((e) => e.raw(f).get()) }) });
325
- const $substr = (expr, start, length) => asExpr({ raw: (f) => asExprRaw({ $substrCP: [
326
- expr.raw(f).get(),
327
- start.raw(f).get(),
328
- length.raw(f).get()
329
- ] }) });
330
- const padLeft = (expr, pad) => asExpr({ raw: (f) => asExprRaw({ $let: {
331
- vars: { x: { $concat: [{ $literal: pad }, expr.raw(f).get()] } },
332
- in: { $substrCP: [
333
- "$$x",
334
- { $subtract: [{ $strLenCP: "$$x" }, pad.length] },
335
- pad.length
336
- ] }
337
- } }) });
338
- const regex = (expr, regex, options) => asExpr({ raw: (f) => asExprRaw({ $regexMatch: {
339
- input: expr.raw(f).get(),
340
- regex: regex.raw(f).get(),
341
- options: options?.raw(f).get()
342
- } }) });
343
- const str = (expr) => asExpr({ raw: (f) => asExprRaw({ $toString: expr.raw(f).get() }) });
344
- const toInt = (expr) => asExpr({ raw: (f) => asExprRaw({ $toInt: expr.raw(f).get() }) });
345
- const fieldM = (expr, m) => asExpr({ raw: (f) => asExprRaw(Object.fromEntries(Object.entries(m).flatMap(([dom, ref]) => expr[ref] ? [[dom, expr[ref].raw(f).get()]] : []))) });
346
- const mergeExact = (...[exprsExact1, exprsExact2]) => spread(exprsExact1, exprsExact2);
347
- const mergeExact0 = (...[exprsExact1, exprsExact2]) => spread0(exprsExact1, exprsExact2);
348
- const mergeExpr = (...exprs) => mergeExact(...exprs);
349
- const fieldF = () => (exprs) => Object.keys(exprs).length ? asExpr({ raw: (f) => asExprRaw(mapExactToObject(exprs, (e) => e.raw(f).get())) }) : asExpr(val(safeNarrow()({})));
350
- const field = fieldF();
351
- //#endregion
352
- //#region .build/lib/expression/array.js
353
- const size = (expr) => asExpr({ raw: (f) => asExprRaw({ $size: expr.raw(f).get() }) });
354
- const filterDefined = (expr) => filter({
355
- expr,
356
- as: "x",
357
- cond: ctx()("x").expr()
358
- });
359
- const filter = ({ as, cond, expr, limit }) => asExpr({ raw: (f) => asExprRaw({ $filter: {
360
- input: expr.raw(f).get(),
361
- as,
362
- cond: cond.raw(f).get(),
363
- ...limit ? { limit: limit.raw(f).get() } : {}
364
- } }) });
365
- const sortArray = ({ sortBy, expr, order }) => asExpr({ raw: (f) => asExprRaw({ $sortArray: {
366
- input: expr.raw(f).get(),
367
- sortBy: { [sortBy]: order ?? -1 }
368
- } }) });
369
- const isArray = (expr) => asBoolExpr({ raw: (f) => asExprRaw({ $isArray: expr.raw(f).get() }) });
370
- const inArray = (item, expr) => asExpr({ raw: (f) => asExprRaw({ $in: [item.raw(f).get(), expr.raw(f).get()] }) });
371
- const array = (...exprs) => asExpr({ raw: (f) => asExprRaw(exprs.map((x) => x.raw(f).get())) });
372
- const concatArray = (...exprs) => asExpr({ raw: (f) => asExprRaw({ $concatArrays: exprs.map((x) => x.raw(f).get()) }) });
373
- const first = (expr) => asExpr({ raw: (f) => asExprRaw({ $first: expr.raw(f).get() }) });
374
- const firstSure = first;
375
- const last = (expr) => asExpr({ raw: (f) => asExprRaw({ $last: expr.raw(f).get() }) });
376
- const mergeObjects = (...exprs) => asExpr({ raw: (f) => asExprRaw({ $mergeObjects: exprs.map((x) => x.raw(f).get()) }) });
377
- const anyElementTrue = (expr) => asExpr({ raw: (f) => asExprRaw({ $anyElementTrue: expr.raw(f).get() }) });
378
- const $reduce = (input, initialValue, inExpr) => asExpr({ raw: (f) => asExprRaw({ $reduce: {
379
- input: input.raw(f).get(),
380
- initialValue: initialValue.raw(f).get(),
381
- in: inExpr.raw(f).get()
382
- } }) });
383
- const indexOfArray = (array, item) => asExpr({ raw: (f) => asExprRaw({ $indexOfArray: [array.raw(f).get(), item.raw(f).get()] }) });
384
- const slice = (array, start, end) => asExpr({ raw: (f) => asExprRaw({ $slice: [
385
- array.raw(f).get(),
386
- start.raw(f).get(),
387
- end.raw(f).get()
388
- ] }) });
389
- const except = (a, b) => {
390
- const value = ctx()("value");
391
- const out = value.of("out").expr();
392
- const except = value.of("except").expr();
393
- const curr = ctx()("this").expr();
394
- const indexInExcept = ctx()("indexInExcept").expr();
395
- return $let({ res: ["res", $reduce(a, field({
396
- out: ["out", array()],
397
- except: ["except", b]
398
- }), $let({ indexInExcept: ["indexInExcept", indexOfArray(except, curr)] }, ite(gte(indexInExcept, val(0)), field({
399
- out: ["out", out],
400
- except: ["except", concatArray(ite(eq(indexInExcept)(val(0)), array(), slice(except, val(0), indexInExcept)), slice(except, add(indexInExcept, val(1)), size(except)))]
401
- }), field({
402
- out: ["out", concatArray(out, array(curr))],
403
- except: ["except", except]
404
- }))))] }, ctx()("res").of("out").expr());
405
- };
406
- //#endregion
407
425
  //#region .build/lib/aggregate/raws.js
408
426
  const $match1 = (query) => (f) => asStages(query ? [{ $match: query.raw(f()) }] : []);
409
427
  const $set1 = (updater) => (f) => asStages([{ $set: Object.fromEntries(updater.raw(f()).map(([k, v]) => [f().of(k.slice(1)).str(), v])) }]);
@@ -596,24 +614,6 @@ const mapToPlainDateTime = (date, timezone) => asExpr({ raw: (f) => asExprRaw({
596
614
  timezone: timezone.raw(f).get()
597
615
  } } }) });
598
616
  //#endregion
599
- //#region .build/lib/expression/range.js
600
- const range = (start, end, step) => asExpr({ raw: (f) => asExprRaw({ $range: [
601
- start.raw(f).get(),
602
- end.raw(f).get(),
603
- step?.raw(f).get() ?? 1
604
- ] }) });
605
- const $map0 = ({ as, expr, input }) => asExpr({ raw: (f) => asExprRaw({ $map: {
606
- input: input.raw(f).get(),
607
- as,
608
- in: expr.raw(f).get()
609
- } }) });
610
- const $map1 = (ex, map) => $map0({
611
- input: ex,
612
- as: "item",
613
- expr: map(ctx()("item"))
614
- });
615
- const $map = (ex, map) => $map1(ex, (i) => map(i.expr()));
616
- //#endregion
617
617
  //#region .build/lib/update/updater.js
618
618
  const subUpdater = (a, f) => ({ raw: (g) => a.raw(g.with(f)) });
619
619
  const rawSet = (fields) => (f) => {
@@ -735,7 +735,7 @@ const subMerge = (args, out, gid, extra, idPrefix, first) => {
735
735
  const gidPath = root().of(gid).expr();
736
736
  const mapId = (k, v) => map1(k, v);
737
737
  const F1 = {
738
- _id: ["_id", to(idPrefix ? concat(val(idPrefix), $rand) : $rand)],
738
+ _id: ["_id", to(idPrefix ? concat(val(idPrefix), rand) : rand)],
739
739
  touchedAt: ["touchedAt", to(current)]
740
740
  };
741
741
  const F2 = mapId(gid, to(gidPath));
@@ -2145,6 +2145,7 @@ const single = (view, needs = {}) => pipe((input) => executes(view, input, needs
2145
2145
  //#endregion
2146
2146
  exports.$accumulator = $accumulator;
2147
2147
  exports.$and = $and;
2148
+ exports.$arrayToObject = $arrayToObject;
2148
2149
  exports.$countDict = $countDict;
2149
2150
  exports.$countDictArray = $countDictArray;
2150
2151
  exports.$entries = $entries;
@@ -2183,6 +2184,7 @@ exports.$merge_ = $merge_;
2183
2184
  exports.$ne = $ne;
2184
2185
  exports.$nin = $nin;
2185
2186
  exports.$nor = $nor;
2187
+ exports.$objectToArray = $objectToArray;
2186
2188
  exports.$or = $or;
2187
2189
  exports.$outerLookup = $outerLookup;
2188
2190
  exports.$pushDict = $pushDict;
@@ -2190,6 +2192,7 @@ exports.$rand = $rand;
2190
2192
  exports.$reduce = $reduce;
2191
2193
  exports.$replaceWith = $replaceWith;
2192
2194
  exports.$set = $set;
2195
+ exports.$setUnion = $setUnion;
2193
2196
  exports.$simpleInsert = $simpleInsert;
2194
2197
  exports.$simpleMerge = $simpleMerge;
2195
2198
  exports.$simpleMergePart = $simpleMergePart;