@omegup/msync 0.0.1 → 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/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Timestamp, BSON, Db, Collection, MongoClient as MongoClient$1 } from 'mongodb';
1
+ import { Timestamp, BSON, Db, Collection, IndexSpecification, CreateIndexesOptions, MongoClient as MongoClient$1, OptionalUnlessRequiredId } from 'mongodb';
2
2
  export { Collection, Timestamp } from 'mongodb';
3
3
  import * as bson from 'bson';
4
4
 
@@ -135,6 +135,7 @@ type BoolExpr<in D1, in D2, in Ctx = unknown> = {
135
135
  };
136
136
  };
137
137
 
138
+ type ExactPart<T, F extends HKT<T[StrKey<T>]>> = MapOPart<T, MappedHKT<T, F>>;
138
139
  type ExactKeys<K extends string> = Exact<RORec<K, 1>, IdHKT>;
139
140
  type MapO<T, F extends HKT<StrKey<T>>> = MapOPart<T, F> & {
140
141
  readonly [P: string]: readonly [StrKey<T>, unknown];
@@ -146,6 +147,9 @@ type Exact<T, F extends HKT<T[StrKey<T>]>> = MapO<T, MappedHKT<T, F>>;
146
147
  interface MappedHKT<T, F extends HKT<T[StrKey<T>]>> extends HKT<StrKey<T>> {
147
148
  readonly out: App<F, T[I<StrKey<T>, this>]>;
148
149
  }
150
+ interface MergeHKT<T, V, F1 extends HKT<StrKey<Omit<T, No>>>, F2 extends HKT<StrKey<V>>, No extends keyof V = never> extends HKT<StrKey<V & Omit<T, No>>> {
151
+ readonly out: I<StrKey<V & Omit<T, No>>, this> extends StrKey<V> ? App<F2, I<StrKey<V>, this>> : App<F1, I<StrKey<Omit<T, No>>, this>>;
152
+ }
149
153
 
150
154
  declare const AccumulatorRaw: unique symbol;
151
155
  interface AccumulatorRaw<in Doc, out T, in C = unknown> extends RawObj {
@@ -172,10 +176,28 @@ type DeltaAccumulator<in out Doc, in out T, in out Ctx = unknown> = {
172
176
  merge: <D, C = Ctx>(a: Expr<T | N, D, C>, b: Expr<T, D, C>) => Expr<T, D, C>;
173
177
  };
174
178
 
179
+ declare const concat: <D, C>(...expr: Expr<string, D, C>[]) => Expr<string, D, C>;
180
+ declare const str: <D, C>(expr: Expr<unknown, D, C>) => Expr<string, D, C>;
181
+ declare const toInt: <D, C>(expr: Expr<unknown, D, C>) => Expr<number, D, C>;
182
+ declare const fieldM: <M extends RORec<Dom, Ref>, T extends RORec<Ref, unknown>, D, Dom extends string = StrKey<M>, Ref extends string = StrKey<T>, C = unknown>(expr: { readonly [K in Ref]: Expr<T[K], D, C>; }, m: Pick<M, Dom>) => Expr<O<{ readonly [K in Dom]: T[M[K]]; }>, D, C>;
183
+ type Exprs<out T, in D, in C = unknown> = {
184
+ readonly [K in StrKey<T>]: Expr<T[K], D, C>;
185
+ };
186
+ declare const mergeExact: <T1, T2, F extends HKT<T1[StrKey<T1>] | T2[StrKey<T2>]>, E = unknown>(exprsExact1: Exact<Omit<T1, keyof T2>, F>, exprsExact2: Exact<T2, F>) => Exact<T2 & Omit<T1, keyof T2> & Pick<E, symbol & keyof E>, F>;
187
+ type MergeMapOArgs<T1, T2, F1 extends HKT<StrKey<Omit<T1, StrKey<T2>>>>, F2 extends HKT<StrKey<T2>>> = readonly [MapO<Omit<T1, StrKey<T2>>, F1>, MapO<T2, F2>];
188
+ declare const mergeExact0: <T1, T2, F1 extends HKT<StrKey<Omit<T1, StrKey<T2>>>>, F2 extends HKT<StrKey<T2>>, E = unknown>(exprsExact1: MapO<Omit<T1, StrKey<T2>>, F1>, exprsExact2: MapO<T2, F2>) => MapO<T2 & Omit<T1, StrKey<T2>> & Pick<E, symbol & keyof E>, MergeHKT<T1, T2, F1, F2, StrKey<T2>>>;
189
+ declare const mergeExpr: <T1, T2, D, C = unknown, E = unknown>(exprs_0: Exact<Omit<T1, keyof T2>, ExprHKT<D, C, IdHKT<unknown>>>, exprs_1: Exact<T2, ExprHKT<D, C, IdHKT<unknown>>>) => ExprsExact<T2 & Omit<T1, keyof T2> & Pick<E, symbol & keyof E>, D, C>;
190
+ type ExprsPart<T, D, C> = ExactPart<T, ExprHKT<D, C>>;
175
191
  interface ExprHKT<D, C = unknown, F extends HKT = IdHKT> extends HKT<unknown> {
176
192
  readonly out: Expr<App<F, I<unknown, this>>, D, C>;
177
193
  }
178
194
  type ExprsExact<T, D, C = unknown, F extends HKT = IdHKT> = Exact<T, ExprHKT<D, C, F>>;
195
+ interface ExprsExactHKT<E, D, C = unknown, F extends HKT = IdHKT> extends HKT {
196
+ readonly out: ExprsExact<E & I<unknown, this>, D, C, F>;
197
+ }
198
+ declare const pair: <T, D, C, P extends StrKey<T>>(k: P, v: Expr<T[P], D, C>) => ExprsExact<T, D, C>[P];
199
+ declare const fieldF: <F extends HKT>() => <T extends object, D, C = unknown>(exprs: ExprsExact<T, D, C, F>) => Expr<O<{ [K in keyof T]: App<F, T[K]>; }>, D, C>;
200
+ declare const field: <T extends object, D, C = unknown>(exprs: ExprsExact<T, D, C>) => Expr<O<T>, D, C>;
179
201
 
180
202
  declare const Type: unique symbol;
181
203
 
@@ -432,6 +454,8 @@ interface UpdaterHKT<R, Old, V, C, K extends keyof Old = keyof Old, V2 extends V
432
454
  readonly out: Updater<R, Get<Old, I<StrKey<V>, this>, K>, V2[I<StrKey<V>, this>], C>;
433
455
  }
434
456
  type Get<T, P extends string, K extends keyof T = never> = P extends K ? T[P] : P extends keyof T ? T[P] : undefined;
457
+ declare const set: <V>() => <R, Old extends notArr, C = unknown, K extends keyof Old = never>(fields: MapO<V, UpdaterHKT<R, Old, V, C, K>>) => Updater<R, Old, O & Omit<Old, StrKey<V>> & V, C> & Updater<R, Arr<Old>, Arr<Omit<Old, StrKey<V>> & V>, C>;
458
+ declare const to: <R, V, C = unknown, T = unknown>(expr: Expr<V, R, C>) => Updater<R, T, V, C>;
435
459
 
436
460
  declare const $set: <V extends O>() => <R extends O, C = unknown>(fields: MapO<V, UpdaterHKT<R, R, V, C>>) => DeltaStages<O, R, Replace<R, V>, C> & LinStages<O, R, Replace<R, V>, C>;
437
461
  declare const $replaceWith: <T extends O, V extends O>(expr: Expr<V, T>) => DeltaStages<O, T, V> & LinStages<O, T, V>;
@@ -518,7 +542,7 @@ declare const sortArray: <T, D, C, K extends keyof T>({ sortBy, expr, order, }:
518
542
  }) => Expr<Arr<T>, D, C>;
519
543
  declare const isArray: <T extends notArr, D, C, F extends HKT<T | Arr<T>>>(expr: Expr<T | Arr<T>, D & (App<F, T> | App<F, Arr<T>>), C>) => BoolExpr<D & App<F, Arr<T>>, D & App<F, T>, C>;
520
544
  declare const array: <T, D, C = unknown>(...exprs: Expr<T, D, C>[]) => Expr<Arr<T>, D, C>;
521
- declare const concat: <T, D, C>(...exprs: Expr<Arr<T>, D, C>[]) => Expr<Arr<T>, D, C>;
545
+ declare const concatArray: <T, D, C>(...exprs: Expr<Arr<T>, D, C>[]) => Expr<Arr<T>, D, C>;
522
546
  declare const first: <T, D, C>(expr: Expr<Arr<T>, D, C>) => Expr<T | null, D, C>;
523
547
  declare const firstSure: <T, D, C>(expr: Expr<Arr<T>, D, C>) => Expr<T, D, C>;
524
548
  declare const last: <T, D, C>(expr: Expr<Arr<T>, D, C>) => Expr<T | null, D, C>;
@@ -599,7 +623,19 @@ declare const $and: Combiner;
599
623
  declare const $nor: Combiner;
600
624
  declare const $or: Combiner;
601
625
 
626
+ declare const log: (...args: unknown[]) => void;
627
+
628
+ declare const createIndex: (collection: {
629
+ readonly createIndex: Collection["createIndex"];
630
+ }, indexSpec: IndexSpecification, options?: CreateIndexesOptions) => Promise<void>;
631
+
632
+ declare const noop: () => void;
633
+ declare const map1: <K extends string, Im>(k: AsLiteral<K>, to: Im) => { readonly [P in K]: [P, Im]; } & {
634
+ readonly [_: string]: [K, Im];
635
+ };
636
+
602
637
  declare const enablePreAndPostImages: <T extends doc>(coll: Collection<T>) => Promise<bson.Document>;
603
638
  declare const prepare: (testName?: string) => Promise<MongoClient$1>;
639
+ declare const makeCol: <T extends ID>(docs: readonly OptionalUnlessRequiredId<T>[], database: Db, name?: string) => Promise<Collection<T>>;
604
640
 
605
- export { $accumulator, $and, $countDict, $entries, $eq, $expr, $getField, $group, $groupId, $groupMerge, $gt, $gtTs, $gte, $gteTs, $ifNull, $in, $keys, $let, $lookup, $lt, $lte, $map, $map1, $match, $matchDelta, $merge, $merge_, $ne, $nin, $nor, $or, $pushDict, $rand, $replaceWith, $set, $sum, $unwind, $unwindDelta, $upsert, type Accumulators, type Arr, type AsLiteral, type Delta, type DeltaAccumulator, type DeltaAccumulators, Expr, Field, type ID, type Loose, Machine, type Merge, type MergeArgs, type MergeInto, type Model, type N, type NoRaw, type O, type OPick, type RONoRaw, type RORec, type RawStages, type Rec, type Replace, type SnapshotStreamExecutionResult, type StrKey, type Strict, type TS, Type, type WriteonlyCollection, add, and, array, ceil, comp, concat, ctx, current, dateAdd, dateDiff, dateLt, datePart, dayAndMonthPart, divide, type doc, enablePreAndPostImages, eq, eqTyped, except, exprMapVal, filter, filterDefined, first, firstSure, floor, from, func, gt, gte, inArray, isArray, ite, last, lt, lte, mapVal, max, maxDate, mergeObjects, minDate, monthPart, multiply, ne, nil, type notArr, notNull, now, prepare, rand, range, root, setField, size, slice, sortArray, staging, startOf, sub, subtract, val, wrap };
641
+ export { $accumulator, $and, $countDict, $entries, $eq, $expr, $getField, $group, $groupId, $groupMerge, $gt, $gtTs, $gte, $gteTs, $ifNull, $in, $keys, $let, $lookup, $lt, $lte, $map, $map1, $match, $matchDelta, $merge, $merge_, $ne, $nin, $nor, $or, $pushDict, $rand, $replaceWith, $set, $sum, $unwind, $unwindDelta, $upsert, type Accumulators, type Arr, type AsLiteral, type Delta, type DeltaAccumulator, type DeltaAccumulators, Expr, type ExprHKT, type Exprs, type ExprsExact, type ExprsExactHKT, type ExprsPart, Field, type ID, type Loose, Machine, type Merge, type MergeArgs, type MergeInto, type MergeMapOArgs, type Model, type N, type NoRaw, type O, type OPick, type OPickD, type RONoRaw, type RORec, type RawStages, type Rec, type Replace, type SnapshotStreamExecutionResult, type StrKey, type Strict, type TS, Type, type WriteonlyCollection, add, and, array, ceil, comp, concat, concatArray, createIndex, ctx, current, dateAdd, dateDiff, dateLt, datePart, dayAndMonthPart, divide, type doc, enablePreAndPostImages, eq, eqTyped, except, exprMapVal, field, fieldF, fieldM, filter, filterDefined, first, firstSure, floor, from, func, gt, gte, inArray, isArray, ite, last, log, lt, lte, makeCol, map1, mapVal, max, maxDate, mergeExact, mergeExact0, mergeExpr, mergeObjects, minDate, monthPart, multiply, ne, nil, noop, type notArr, notNull, now, pair, prepare, rand, range, root, set, setField, size, slice, sortArray, staging, startOf, str, sub, subtract, to, toInt, val, wrap };
package/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { UUID, MongoClient } from 'mongodb';
2
- import crypto from 'crypto';
2
+ import crypto$1 from 'crypto';
3
3
  import { writeFile } from 'fs/promises';
4
4
 
5
5
  const asExprRaw = (raw) => ({ get: () => raw });
@@ -54,6 +54,7 @@ function ceil(expr) {
54
54
 
55
55
  const id$1 = (x) => x;
56
56
  const defined = (x) => x != null;
57
+ const noop = () => { };
57
58
  const map1 = (k, to) => {
58
59
  const k2 = k;
59
60
  return { [k]: [k2, to] };
@@ -71,6 +72,7 @@ const mapExact1 = (x, f) => mapExactToObject1(x, (v, k) => [k, f(v, k)]);
71
72
  const mapExactToObject = (x, f) => mapExactToObject0(x, f);
72
73
  const mapExact = (x, f) => mapExactToObject(x, (v, k) => [k, f(v, k)]);
73
74
  const spread = (a, b) => ({ ...a, ...mapExact(b, id$1) });
75
+ const spread0 = (a, b) => ({ ...a, ...mapExact0(b, id$1) });
74
76
 
75
77
  const val = (val) => asExpr({
76
78
  raw: () => asExprRaw((val && typeof val === 'object') || (typeof val === 'string' && val[0] === '$')
@@ -285,9 +287,15 @@ const $entries = (expr) => func(function (obj) {
285
287
  return Object.entries({ ...obj }).flatMap(([k, v]) => v[0].map(v => ({ k, v })));
286
288
  }, expr);
287
289
 
288
- const concat$2 = (...expr) => asExpr({
290
+ const concat$1 = (...expr) => asExpr({
289
291
  raw: f => asExprRaw({ $concat: expr.map(e => e.raw(f).get()) }),
290
292
  });
293
+ const str = (expr) => asExpr({
294
+ raw: f => asExprRaw({ $toString: expr.raw(f).get() }),
295
+ });
296
+ const toInt = (expr) => asExpr({
297
+ raw: f => asExprRaw({ $toInt: expr.raw(f).get() }),
298
+ });
291
299
  const fieldM = (expr, m) => asExpr({
292
300
  raw: (f) => asExprRaw(Object.fromEntries(Object.entries(m).map(([dom, ref]) => [
293
301
  dom,
@@ -295,7 +303,10 @@ const fieldM = (expr, m) => asExpr({
295
303
  ]))),
296
304
  });
297
305
  const mergeExact = (...[exprsExact1, exprsExact2]) => spread(exprsExact1, exprsExact2);
306
+ const mergeExact0 = (...[exprsExact1, exprsExact2]) => spread0(exprsExact1, exprsExact2);
298
307
  const mergeExpr = (...exprs) => mergeExact(...exprs);
308
+ const asIntersect = (x) => x;
309
+ const pair = (k, v) => asIntersect([k, v]);
299
310
  const fieldF = () => (exprs) => Object.keys(exprs).length
300
311
  ? asExpr({
301
312
  raw: f => asExprRaw(mapExactToObject(exprs, e => e.raw(f).get())),
@@ -327,12 +338,12 @@ const pipe = (stream, s, concat, empty) => {
327
338
  };
328
339
  return acc;
329
340
  };
330
- const concat$1 = (stages) => ({
331
- with: extra => concat$1(concatStages(stages, extra)),
341
+ const concat = (stages) => ({
342
+ with: extra => concat(concatStages(stages, extra)),
332
343
  stages,
333
344
  });
334
345
  const link = () => ({
335
- with: extra => concat$1(extra),
346
+ with: extra => concat(extra),
336
347
  stages: asStages([]),
337
348
  });
338
349
  const emptyDelta = () => ({
@@ -368,7 +379,7 @@ const isArray = (expr) => asBoolExpr({
368
379
  const array = (...exprs) => asExpr({
369
380
  raw: f => asExprRaw(exprs.map(x => x.raw(f).get())),
370
381
  });
371
- const concat = (...exprs) => asExpr({
382
+ const concatArray = (...exprs) => asExpr({
372
383
  raw: f => asExprRaw({ $concatArrays: exprs.map(x => x.raw(f).get()) }),
373
384
  });
374
385
  const first$1 = (expr) => asExpr({
@@ -418,10 +429,10 @@ const except = (a, b) => {
418
429
  out: ['out', out],
419
430
  except: [
420
431
  'except',
421
- concat(ite(eq(indexInExcept)(val(0)), array(), slice(except, val(0), indexInExcept)), slice(except, add(indexInExcept, val(1)), size(except))),
432
+ concatArray(ite(eq(indexInExcept)(val(0)), array(), slice(except, val(0), indexInExcept)), slice(except, add(indexInExcept, val(1)), size(except))),
422
433
  ],
423
434
  }), field({
424
- out: ['out', concat(out, array(curr))],
435
+ out: ['out', concatArray(out, array(curr))],
425
436
  except: ['except', except],
426
437
  })))),
427
438
  ],
@@ -541,7 +552,7 @@ const subMerge = (args, out, gid, extra, idPrefix) => {
541
552
  const gidPath = root().of(gid).expr();
542
553
  const mapId = (k, v) => map1(k, v);
543
554
  const F1 = {
544
- _id: ['_id', to(idPrefix ? concat$2(val(idPrefix), $rand) : $rand)],
555
+ _id: ['_id', to(idPrefix ? concat$1(val(idPrefix), $rand) : $rand)],
545
556
  touchedAt: ['touchedAt', to(current)],
546
557
  };
547
558
  const F2 = mapId(gid, to(gidPath));
@@ -1116,7 +1127,7 @@ const makeWatchStream = (db, { collection, projection: p, hardMatch: m }, startA
1116
1127
 
1117
1128
  const streamNames = {};
1118
1129
  const executes$1 = (view, input, streamName) => {
1119
- const hash = crypto
1130
+ const hash = crypto$1
1120
1131
  .createHash('md5')
1121
1132
  .update(new Error().stack + '')
1122
1133
  .digest('base64url');
@@ -1252,7 +1263,7 @@ const executes$1 = (view, input, streamName) => {
1252
1263
  const staging = (view, streamName) => pipe(input => executes$1(view, input, streamName), emptyDelta(), concatDelta, emptyDelta);
1253
1264
 
1254
1265
  const executes = (view, input, streamName) => {
1255
- const hash = crypto
1266
+ const hash = crypto$1
1256
1267
  .createHash('md5')
1257
1268
  .update(new Error().stack + '')
1258
1269
  .digest('base64url');
@@ -1579,5 +1590,21 @@ const prepare = async (testName) => {
1579
1590
  });
1580
1591
  return client;
1581
1592
  };
1593
+ const makeCol = async (docs, database, name) => {
1594
+ if (!name) {
1595
+ (name = crypto.randomUUID());
1596
+ }
1597
+ try {
1598
+ const col = await database.createCollection(name, {
1599
+ changeStreamPreAndPostImages: { enabled: true },
1600
+ });
1601
+ if (docs.length)
1602
+ await col.insertMany([...docs]);
1603
+ return col;
1604
+ }
1605
+ catch {
1606
+ return database.collection(name);
1607
+ }
1608
+ };
1582
1609
 
1583
- export { $accumulator, $and, $countDict, $entries, $eq, $expr, $getField, $group, $groupId, $groupMerge, $gt, $gtTs, $gte, $gteTs, $ifNull, $in, $keys, $let, $lookup, $lt, $lte, $map, $map1, $match, $matchDelta, $merge, $merge_, $ne, $nin, $nor, $or, $pushDict, $rand, $replaceWith, $set, $sum, $unwind, $unwindDelta, $upsert, Field, Machine, add, and, array, ceil, comp, concat, ctx, current, dateAdd, dateDiff, dateLt, datePart, dayAndMonthPart, divide, enablePreAndPostImages, eq, eqTyped, except, exprMapVal, filter, filterDefined, first$1 as first, firstSure, floor, from, func, gt, gte, inArray, isArray, ite, last, lt, lte, mapVal, max, maxDate, mergeObjects, minDate, monthPart, multiply, ne, nil, notNull, now, prepare, rand, range, root, setField, size, slice, sortArray, staging, startOf, sub, subtract, val, wrap };
1610
+ export { $accumulator, $and, $countDict, $entries, $eq, $expr, $getField, $group, $groupId, $groupMerge, $gt, $gtTs, $gte, $gteTs, $ifNull, $in, $keys, $let, $lookup, $lt, $lte, $map, $map1, $match, $matchDelta, $merge, $merge_, $ne, $nin, $nor, $or, $pushDict, $rand, $replaceWith, $set, $sum, $unwind, $unwindDelta, $upsert, Field, Machine, add, and, array, ceil, comp, concat$1 as concat, concatArray, createIndex, ctx, current, dateAdd, dateDiff, dateLt, datePart, dayAndMonthPart, divide, enablePreAndPostImages, eq, eqTyped, except, exprMapVal, field, fieldF, fieldM, filter, filterDefined, first$1 as first, firstSure, floor, from, func, gt, gte, inArray, isArray, ite, last, log, lt, lte, makeCol, map1, mapVal, max, maxDate, mergeExact, mergeExact0, mergeExpr, mergeObjects, minDate, monthPart, multiply, ne, nil, noop, notNull, now, pair, prepare, rand, range, root, set, setField, size, slice, sortArray, staging, startOf, str, sub, subtract, to, toInt, val, wrap };
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var mongodb = require('mongodb');
4
- var crypto = require('crypto');
4
+ var crypto$1 = require('crypto');
5
5
  var promises = require('fs/promises');
6
6
 
7
7
  const asExprRaw = (raw) => ({ get: () => raw });
@@ -56,6 +56,7 @@ function ceil(expr) {
56
56
 
57
57
  const id$1 = (x) => x;
58
58
  const defined = (x) => x != null;
59
+ const noop = () => { };
59
60
  const map1 = (k, to) => {
60
61
  const k2 = k;
61
62
  return { [k]: [k2, to] };
@@ -73,6 +74,7 @@ const mapExact1 = (x, f) => mapExactToObject1(x, (v, k) => [k, f(v, k)]);
73
74
  const mapExactToObject = (x, f) => mapExactToObject0(x, f);
74
75
  const mapExact = (x, f) => mapExactToObject(x, (v, k) => [k, f(v, k)]);
75
76
  const spread = (a, b) => ({ ...a, ...mapExact(b, id$1) });
77
+ const spread0 = (a, b) => ({ ...a, ...mapExact0(b, id$1) });
76
78
 
77
79
  const val = (val) => asExpr({
78
80
  raw: () => asExprRaw((val && typeof val === 'object') || (typeof val === 'string' && val[0] === '$')
@@ -287,9 +289,15 @@ const $entries = (expr) => func(function (obj) {
287
289
  return Object.entries({ ...obj }).flatMap(([k, v]) => v[0].map(v => ({ k, v })));
288
290
  }, expr);
289
291
 
290
- const concat$2 = (...expr) => asExpr({
292
+ const concat$1 = (...expr) => asExpr({
291
293
  raw: f => asExprRaw({ $concat: expr.map(e => e.raw(f).get()) }),
292
294
  });
295
+ const str = (expr) => asExpr({
296
+ raw: f => asExprRaw({ $toString: expr.raw(f).get() }),
297
+ });
298
+ const toInt = (expr) => asExpr({
299
+ raw: f => asExprRaw({ $toInt: expr.raw(f).get() }),
300
+ });
293
301
  const fieldM = (expr, m) => asExpr({
294
302
  raw: (f) => asExprRaw(Object.fromEntries(Object.entries(m).map(([dom, ref]) => [
295
303
  dom,
@@ -297,7 +305,10 @@ const fieldM = (expr, m) => asExpr({
297
305
  ]))),
298
306
  });
299
307
  const mergeExact = (...[exprsExact1, exprsExact2]) => spread(exprsExact1, exprsExact2);
308
+ const mergeExact0 = (...[exprsExact1, exprsExact2]) => spread0(exprsExact1, exprsExact2);
300
309
  const mergeExpr = (...exprs) => mergeExact(...exprs);
310
+ const asIntersect = (x) => x;
311
+ const pair = (k, v) => asIntersect([k, v]);
301
312
  const fieldF = () => (exprs) => Object.keys(exprs).length
302
313
  ? asExpr({
303
314
  raw: f => asExprRaw(mapExactToObject(exprs, e => e.raw(f).get())),
@@ -329,12 +340,12 @@ const pipe = (stream, s, concat, empty) => {
329
340
  };
330
341
  return acc;
331
342
  };
332
- const concat$1 = (stages) => ({
333
- with: extra => concat$1(concatStages(stages, extra)),
343
+ const concat = (stages) => ({
344
+ with: extra => concat(concatStages(stages, extra)),
334
345
  stages,
335
346
  });
336
347
  const link = () => ({
337
- with: extra => concat$1(extra),
348
+ with: extra => concat(extra),
338
349
  stages: asStages([]),
339
350
  });
340
351
  const emptyDelta = () => ({
@@ -370,7 +381,7 @@ const isArray = (expr) => asBoolExpr({
370
381
  const array = (...exprs) => asExpr({
371
382
  raw: f => asExprRaw(exprs.map(x => x.raw(f).get())),
372
383
  });
373
- const concat = (...exprs) => asExpr({
384
+ const concatArray = (...exprs) => asExpr({
374
385
  raw: f => asExprRaw({ $concatArrays: exprs.map(x => x.raw(f).get()) }),
375
386
  });
376
387
  const first$1 = (expr) => asExpr({
@@ -420,10 +431,10 @@ const except = (a, b) => {
420
431
  out: ['out', out],
421
432
  except: [
422
433
  'except',
423
- concat(ite(eq(indexInExcept)(val(0)), array(), slice(except, val(0), indexInExcept)), slice(except, add(indexInExcept, val(1)), size(except))),
434
+ concatArray(ite(eq(indexInExcept)(val(0)), array(), slice(except, val(0), indexInExcept)), slice(except, add(indexInExcept, val(1)), size(except))),
424
435
  ],
425
436
  }), field({
426
- out: ['out', concat(out, array(curr))],
437
+ out: ['out', concatArray(out, array(curr))],
427
438
  except: ['except', except],
428
439
  })))),
429
440
  ],
@@ -543,7 +554,7 @@ const subMerge = (args, out, gid, extra, idPrefix) => {
543
554
  const gidPath = root().of(gid).expr();
544
555
  const mapId = (k, v) => map1(k, v);
545
556
  const F1 = {
546
- _id: ['_id', to(idPrefix ? concat$2(val(idPrefix), $rand) : $rand)],
557
+ _id: ['_id', to(idPrefix ? concat$1(val(idPrefix), $rand) : $rand)],
547
558
  touchedAt: ['touchedAt', to(current)],
548
559
  };
549
560
  const F2 = mapId(gid, to(gidPath));
@@ -1118,7 +1129,7 @@ const makeWatchStream = (db, { collection, projection: p, hardMatch: m }, startA
1118
1129
 
1119
1130
  const streamNames = {};
1120
1131
  const executes$1 = (view, input, streamName) => {
1121
- const hash = crypto
1132
+ const hash = crypto$1
1122
1133
  .createHash('md5')
1123
1134
  .update(new Error().stack + '')
1124
1135
  .digest('base64url');
@@ -1254,7 +1265,7 @@ const executes$1 = (view, input, streamName) => {
1254
1265
  const staging = (view, streamName) => pipe(input => executes$1(view, input, streamName), emptyDelta(), concatDelta, emptyDelta);
1255
1266
 
1256
1267
  const executes = (view, input, streamName) => {
1257
- const hash = crypto
1268
+ const hash = crypto$1
1258
1269
  .createHash('md5')
1259
1270
  .update(new Error().stack + '')
1260
1271
  .digest('base64url');
@@ -1581,6 +1592,22 @@ const prepare = async (testName) => {
1581
1592
  });
1582
1593
  return client;
1583
1594
  };
1595
+ const makeCol = async (docs, database, name) => {
1596
+ if (!name) {
1597
+ (name = crypto.randomUUID());
1598
+ }
1599
+ try {
1600
+ const col = await database.createCollection(name, {
1601
+ changeStreamPreAndPostImages: { enabled: true },
1602
+ });
1603
+ if (docs.length)
1604
+ await col.insertMany([...docs]);
1605
+ return col;
1606
+ }
1607
+ catch {
1608
+ return database.collection(name);
1609
+ }
1610
+ };
1584
1611
 
1585
1612
  exports.$accumulator = $accumulator;
1586
1613
  exports.$and = $and;
@@ -1628,7 +1655,9 @@ exports.and = and;
1628
1655
  exports.array = array;
1629
1656
  exports.ceil = ceil;
1630
1657
  exports.comp = comp;
1631
- exports.concat = concat;
1658
+ exports.concat = concat$1;
1659
+ exports.concatArray = concatArray;
1660
+ exports.createIndex = createIndex;
1632
1661
  exports.ctx = ctx;
1633
1662
  exports.current = current;
1634
1663
  exports.dateAdd = dateAdd;
@@ -1642,6 +1671,9 @@ exports.eq = eq;
1642
1671
  exports.eqTyped = eqTyped;
1643
1672
  exports.except = except;
1644
1673
  exports.exprMapVal = exprMapVal;
1674
+ exports.field = field;
1675
+ exports.fieldF = fieldF;
1676
+ exports.fieldM = fieldM;
1645
1677
  exports.filter = filter;
1646
1678
  exports.filterDefined = filterDefined;
1647
1679
  exports.first = first$1;
@@ -1655,30 +1687,42 @@ exports.inArray = inArray;
1655
1687
  exports.isArray = isArray;
1656
1688
  exports.ite = ite;
1657
1689
  exports.last = last;
1690
+ exports.log = log;
1658
1691
  exports.lt = lt;
1659
1692
  exports.lte = lte;
1693
+ exports.makeCol = makeCol;
1694
+ exports.map1 = map1;
1660
1695
  exports.mapVal = mapVal;
1661
1696
  exports.max = max;
1662
1697
  exports.maxDate = maxDate;
1698
+ exports.mergeExact = mergeExact;
1699
+ exports.mergeExact0 = mergeExact0;
1700
+ exports.mergeExpr = mergeExpr;
1663
1701
  exports.mergeObjects = mergeObjects;
1664
1702
  exports.minDate = minDate;
1665
1703
  exports.monthPart = monthPart;
1666
1704
  exports.multiply = multiply;
1667
1705
  exports.ne = ne;
1668
1706
  exports.nil = nil;
1707
+ exports.noop = noop;
1669
1708
  exports.notNull = notNull;
1670
1709
  exports.now = now;
1710
+ exports.pair = pair;
1671
1711
  exports.prepare = prepare;
1672
1712
  exports.rand = rand;
1673
1713
  exports.range = range;
1674
1714
  exports.root = root;
1715
+ exports.set = set;
1675
1716
  exports.setField = setField;
1676
1717
  exports.size = size;
1677
1718
  exports.slice = slice;
1678
1719
  exports.sortArray = sortArray;
1679
1720
  exports.staging = staging;
1680
1721
  exports.startOf = startOf;
1722
+ exports.str = str;
1681
1723
  exports.sub = sub;
1682
1724
  exports.subtract = subtract;
1725
+ exports.to = to;
1726
+ exports.toInt = toInt;
1683
1727
  exports.val = val;
1684
1728
  exports.wrap = wrap;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "module": "index.esm.js",
4
4
  "typings": "index.d.ts",
5
5
  "name": "@omegup/msync",
6
- "version": "0.0.1",
6
+ "version": "0.0.3",
7
7
  "dependencies": {
8
8
  "dayjs": "^1.11.9",
9
9
  "dotenv": "^16.3.1",