@omegup/msync 0.0.99 → 0.1.1
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 +2 -2
- package/index.esm.js +17 -8
- package/index.js +17 -8
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -526,7 +526,7 @@ interface SnapshotStreamHKT extends HKT<O2> {
|
|
|
526
526
|
interface DeltaHKT extends HKT<O3> {
|
|
527
527
|
readonly out: DeltaStages<I<O3, this>[0], I<O3, this>[1], I<O3, this>[2]>;
|
|
528
528
|
}
|
|
529
|
-
declare const staging: <V extends Model, KK extends StrKey<V>>(view: View<V, Allowed$1<KK>>, streamName: string, skip?: boolean, after?: () => Promise<void
|
|
529
|
+
declare const staging: <V extends Model, KK extends StrKey<V>>(view: View<V, Allowed$1<KK>>, streamName: string, skip?: boolean, after?: () => Promise<void>, allowEmtpies?: readonly KK[]) => DeltaPipe<AllowedPick$1<V, KK>, AllowedPick$1<V, KK>, SnapshotStreamHKT, DeltaHKT>;
|
|
530
530
|
|
|
531
531
|
type Allowed<K> = Exclude<K, 'deletedAt' | '_id'>;
|
|
532
532
|
type AllowedPick<V extends Model, K extends StrKey<V>> = OPickD<V, Allowed<K>>;
|
|
@@ -536,7 +536,7 @@ interface StreamRunnerHKT extends HKT<O2> {
|
|
|
536
536
|
interface StagesHKT extends HKT<O3> {
|
|
537
537
|
readonly out: RORec<'lin', RawStages<I<O3, this>[0], I<O3, this>[1], I<O3, this>[2], unknown, 1>>;
|
|
538
538
|
}
|
|
539
|
-
declare const from: <V extends Model, KK extends StrKey<V>>(view: View<V, Allowed<KK>>, streamName: string) => DeltaPipe<AllowedPick<V, KK>, AllowedPick<V, KK>, StreamRunnerHKT, StagesHKT>;
|
|
539
|
+
declare const from: <V extends Model, KK extends StrKey<V>>(view: View<V, Allowed<KK>>, streamName: string, allowEmtpies?: readonly KK[]) => DeltaPipe<AllowedPick<V, KK>, AllowedPick<V, KK>, StreamRunnerHKT, StagesHKT>;
|
|
540
540
|
|
|
541
541
|
type SingleResult<out Result> = <Result2>(finalInput: RawStages<unknown, Result, Result2>) => Stages<unknown, Result2, unknown>;
|
|
542
542
|
interface SnapshotStreamHKT2 extends HKT<O2> {
|
package/index.esm.js
CHANGED
|
@@ -1367,10 +1367,11 @@ const $replaceWith = (expr) => ({
|
|
|
1367
1367
|
const $mergeX = (out, keys, f, map, whenNotMatched = 'fail', ext) => {
|
|
1368
1368
|
const patch = mapExact(keys, v => sub(v, f));
|
|
1369
1369
|
const filter = mapExactToObject(ext, v => ({ $eq: v }));
|
|
1370
|
+
const setDeleted = whenNotMatched === 'discard';
|
|
1370
1371
|
const replacer = map(field(omitPick().backward(spread(patch, {
|
|
1371
1372
|
_id: ['_id', f.of('_id').expr()],
|
|
1372
1373
|
touchedAt: ['touchedAt', current],
|
|
1373
|
-
deletedAt: ['deletedAt', current],
|
|
1374
|
+
deletedAt: [setDeleted ? 'deletedAt' : 'touchedAt', current],
|
|
1374
1375
|
}))));
|
|
1375
1376
|
return {
|
|
1376
1377
|
raw: (first) => link()
|
|
@@ -1383,8 +1384,16 @@ const $mergeX = (out, keys, f, map, whenNotMatched = 'fail', ext) => {
|
|
|
1383
1384
|
whenMatched: asStages([
|
|
1384
1385
|
{
|
|
1385
1386
|
$replaceWith: {
|
|
1386
|
-
old:
|
|
1387
|
-
|
|
1387
|
+
old: setDeleted
|
|
1388
|
+
? { $mergeObjects: ['$$ROOT', { deletedAt: '$deletedAt' }] }
|
|
1389
|
+
: '$$ROOT',
|
|
1390
|
+
merged: {
|
|
1391
|
+
$mergeObjects: [
|
|
1392
|
+
'$$ROOT',
|
|
1393
|
+
'$$new',
|
|
1394
|
+
...(setDeleted ? [{ deletedAt: '$deletedAt' }] : []),
|
|
1395
|
+
],
|
|
1396
|
+
},
|
|
1388
1397
|
},
|
|
1389
1398
|
},
|
|
1390
1399
|
{
|
|
@@ -1621,7 +1630,7 @@ const getFirstStages = (view) => {
|
|
|
1621
1630
|
};
|
|
1622
1631
|
|
|
1623
1632
|
const streamNames = {};
|
|
1624
|
-
const executes$2 = (view, input, streamName, skip = false, after) => {
|
|
1633
|
+
const executes$2 = (view, input, streamName, skip = false, after, allowEmtpies) => {
|
|
1625
1634
|
const { collection, projection, match } = view;
|
|
1626
1635
|
const { firstStages, hardMatch } = getFirstStages(view);
|
|
1627
1636
|
const db = collection.s.db, coll = collection.collectionName;
|
|
@@ -1810,9 +1819,9 @@ const executes$2 = (view, input, streamName, skip = false, after) => {
|
|
|
1810
1819
|
out: run,
|
|
1811
1820
|
};
|
|
1812
1821
|
};
|
|
1813
|
-
const staging = (view, streamName, skip = false, after) => pipe(input => executes$2(view, input, streamName, skip, after), emptyDelta(), concatDelta, emptyDelta);
|
|
1822
|
+
const staging = (view, streamName, skip = false, after, allowEmtpies) => pipe(input => executes$2(view, input, streamName, skip, after), emptyDelta(), concatDelta, emptyDelta);
|
|
1814
1823
|
|
|
1815
|
-
const executes$1 = (view, input, streamName) => {
|
|
1824
|
+
const executes$1 = (view, input, streamName, allowEmtpies) => {
|
|
1816
1825
|
const hash = crypto$1
|
|
1817
1826
|
.createHash('md5')
|
|
1818
1827
|
.update(new Error().stack + '')
|
|
@@ -1822,7 +1831,7 @@ const executes$1 = (view, input, streamName) => {
|
|
|
1822
1831
|
else if (streamNames[streamName] != hash)
|
|
1823
1832
|
throw new Error('streamName already used');
|
|
1824
1833
|
const { collection, projection, hardMatch: pre, match } = view;
|
|
1825
|
-
const removeNotYetSynchronizedFields = projection && Object.values(mapExactToObject(projection, (_, k) => k.startsWith('_') ? root().of(k).has($exists(true)) : null));
|
|
1834
|
+
const removeNotYetSynchronizedFields = projection && Object.values(mapExactToObject(projection, (_, k) => k.startsWith('_') && !allowEmtpies?.includes(k) ? root().of(k).has($exists(true)) : null));
|
|
1826
1835
|
const hardMatch = removeNotYetSynchronizedFields ? $and(pre, ...removeNotYetSynchronizedFields) : pre;
|
|
1827
1836
|
const job = {};
|
|
1828
1837
|
const db = collection.s.db, coll = collection.collectionName;
|
|
@@ -1933,7 +1942,7 @@ const executes$1 = (view, input, streamName) => {
|
|
|
1933
1942
|
};
|
|
1934
1943
|
};
|
|
1935
1944
|
const emptyLin = () => ({ lin: link().stages });
|
|
1936
|
-
const from = (view, streamName) => pipe(input => executes$1(view, input.lin, streamName), { lin: link().stages }, ({ lin: a }, { lin: b }) => ({ lin: concatStages(a, b) }), emptyLin);
|
|
1945
|
+
const from = (view, streamName, allowEmtpies) => pipe(input => executes$1(view, input.lin, streamName, allowEmtpies), { lin: link().stages }, ({ lin: a }, { lin: b }) => ({ lin: concatStages(a, b) }), emptyLin);
|
|
1937
1946
|
|
|
1938
1947
|
const executes = (view, input) => {
|
|
1939
1948
|
const { firstStages } = getFirstStages(view);
|
package/index.js
CHANGED
|
@@ -1369,10 +1369,11 @@ const $replaceWith = (expr) => ({
|
|
|
1369
1369
|
const $mergeX = (out, keys, f, map, whenNotMatched = 'fail', ext) => {
|
|
1370
1370
|
const patch = mapExact(keys, v => sub(v, f));
|
|
1371
1371
|
const filter = mapExactToObject(ext, v => ({ $eq: v }));
|
|
1372
|
+
const setDeleted = whenNotMatched === 'discard';
|
|
1372
1373
|
const replacer = map(field(omitPick().backward(spread(patch, {
|
|
1373
1374
|
_id: ['_id', f.of('_id').expr()],
|
|
1374
1375
|
touchedAt: ['touchedAt', current],
|
|
1375
|
-
deletedAt: ['deletedAt', current],
|
|
1376
|
+
deletedAt: [setDeleted ? 'deletedAt' : 'touchedAt', current],
|
|
1376
1377
|
}))));
|
|
1377
1378
|
return {
|
|
1378
1379
|
raw: (first) => link()
|
|
@@ -1385,8 +1386,16 @@ const $mergeX = (out, keys, f, map, whenNotMatched = 'fail', ext) => {
|
|
|
1385
1386
|
whenMatched: asStages([
|
|
1386
1387
|
{
|
|
1387
1388
|
$replaceWith: {
|
|
1388
|
-
old:
|
|
1389
|
-
|
|
1389
|
+
old: setDeleted
|
|
1390
|
+
? { $mergeObjects: ['$$ROOT', { deletedAt: '$deletedAt' }] }
|
|
1391
|
+
: '$$ROOT',
|
|
1392
|
+
merged: {
|
|
1393
|
+
$mergeObjects: [
|
|
1394
|
+
'$$ROOT',
|
|
1395
|
+
'$$new',
|
|
1396
|
+
...(setDeleted ? [{ deletedAt: '$deletedAt' }] : []),
|
|
1397
|
+
],
|
|
1398
|
+
},
|
|
1390
1399
|
},
|
|
1391
1400
|
},
|
|
1392
1401
|
{
|
|
@@ -1623,7 +1632,7 @@ const getFirstStages = (view) => {
|
|
|
1623
1632
|
};
|
|
1624
1633
|
|
|
1625
1634
|
const streamNames = {};
|
|
1626
|
-
const executes$2 = (view, input, streamName, skip = false, after) => {
|
|
1635
|
+
const executes$2 = (view, input, streamName, skip = false, after, allowEmtpies) => {
|
|
1627
1636
|
const { collection, projection, match } = view;
|
|
1628
1637
|
const { firstStages, hardMatch } = getFirstStages(view);
|
|
1629
1638
|
const db = collection.s.db, coll = collection.collectionName;
|
|
@@ -1812,9 +1821,9 @@ const executes$2 = (view, input, streamName, skip = false, after) => {
|
|
|
1812
1821
|
out: run,
|
|
1813
1822
|
};
|
|
1814
1823
|
};
|
|
1815
|
-
const staging = (view, streamName, skip = false, after) => pipe(input => executes$2(view, input, streamName, skip, after), emptyDelta(), concatDelta, emptyDelta);
|
|
1824
|
+
const staging = (view, streamName, skip = false, after, allowEmtpies) => pipe(input => executes$2(view, input, streamName, skip, after), emptyDelta(), concatDelta, emptyDelta);
|
|
1816
1825
|
|
|
1817
|
-
const executes$1 = (view, input, streamName) => {
|
|
1826
|
+
const executes$1 = (view, input, streamName, allowEmtpies) => {
|
|
1818
1827
|
const hash = crypto$1
|
|
1819
1828
|
.createHash('md5')
|
|
1820
1829
|
.update(new Error().stack + '')
|
|
@@ -1824,7 +1833,7 @@ const executes$1 = (view, input, streamName) => {
|
|
|
1824
1833
|
else if (streamNames[streamName] != hash)
|
|
1825
1834
|
throw new Error('streamName already used');
|
|
1826
1835
|
const { collection, projection, hardMatch: pre, match } = view;
|
|
1827
|
-
const removeNotYetSynchronizedFields = projection && Object.values(mapExactToObject(projection, (_, k) => k.startsWith('_') ? root().of(k).has($exists(true)) : null));
|
|
1836
|
+
const removeNotYetSynchronizedFields = projection && Object.values(mapExactToObject(projection, (_, k) => k.startsWith('_') && !allowEmtpies?.includes(k) ? root().of(k).has($exists(true)) : null));
|
|
1828
1837
|
const hardMatch = removeNotYetSynchronizedFields ? $and(pre, ...removeNotYetSynchronizedFields) : pre;
|
|
1829
1838
|
const job = {};
|
|
1830
1839
|
const db = collection.s.db, coll = collection.collectionName;
|
|
@@ -1935,7 +1944,7 @@ const executes$1 = (view, input, streamName) => {
|
|
|
1935
1944
|
};
|
|
1936
1945
|
};
|
|
1937
1946
|
const emptyLin = () => ({ lin: link().stages });
|
|
1938
|
-
const from = (view, streamName) => pipe(input => executes$1(view, input.lin, streamName), { lin: link().stages }, ({ lin: a }, { lin: b }) => ({ lin: concatStages(a, b) }), emptyLin);
|
|
1947
|
+
const from = (view, streamName, allowEmtpies) => pipe(input => executes$1(view, input.lin, streamName, allowEmtpies), { lin: link().stages }, ({ lin: a }, { lin: b }) => ({ lin: concatStages(a, b) }), emptyLin);
|
|
1939
1948
|
|
|
1940
1949
|
const executes = (view, input) => {
|
|
1941
1950
|
const { firstStages } = getFirstStages(view);
|