@signaldb/core 2.0.0-beta.13 → 2.0.0-beta.14
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/.vite/manifest.json +72 -46
- package/dist/AsyncDataAdapter.d.ts +11 -2
- package/dist/Collection/Cursor.d.ts +11 -1
- package/dist/Collection/Observer.d.ts +31 -0
- package/dist/DataAdapter.d.ts +15 -2
- package/dist/WorkerDataAdapter.d.ts +25 -2
- package/dist/WorkerDataAdapterHost.d.ts +2 -0
- package/dist/index.cjs.js +15 -15
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +15 -15
- package/dist/index10.cjs.js +7 -19
- package/dist/index10.mjs +7 -19
- package/dist/index11.cjs.js +19 -41
- package/dist/index11.mjs +19 -41
- package/dist/index12.cjs.js +41 -18
- package/dist/index12.mjs +41 -18
- package/dist/index13.cjs.js +18 -41
- package/dist/index13.mjs +18 -41
- package/dist/index14.cjs.js +39 -80
- package/dist/index14.mjs +39 -80
- package/dist/index15.cjs.js +82 -11
- package/dist/index15.mjs +82 -11
- package/dist/index16.cjs.js +11 -132
- package/dist/index16.mjs +11 -132
- package/dist/index17.cjs.js +127 -38
- package/dist/index17.mjs +127 -38
- package/dist/index18.cjs.js +43 -11
- package/dist/index18.mjs +43 -11
- package/dist/index19.cjs.js +10 -18
- package/dist/index19.mjs +11 -19
- package/dist/index20.cjs.js +19 -33
- package/dist/index20.mjs +19 -33
- package/dist/index21.cjs.js +33 -31
- package/dist/index21.mjs +33 -31
- package/dist/index22.cjs.js +31 -21
- package/dist/index22.mjs +31 -21
- package/dist/index23.cjs.js +16 -14
- package/dist/index23.mjs +16 -14
- package/dist/index24.cjs.js +15 -338
- package/dist/index24.mjs +15 -338
- package/dist/index25.cjs.js +122 -554
- package/dist/index25.mjs +121 -554
- package/dist/index26.cjs.js +34 -7
- package/dist/index26.mjs +34 -7
- package/dist/index27.cjs.js +339 -7
- package/dist/index27.mjs +339 -7
- package/dist/index28.cjs.js +550 -83
- package/dist/index28.mjs +550 -82
- package/dist/index29.cjs.js +8 -422
- package/dist/index29.mjs +8 -422
- package/dist/index30.cjs.js +7 -68
- package/dist/index30.mjs +7 -68
- package/dist/index31.cjs.js +86 -28
- package/dist/index31.mjs +85 -28
- package/dist/index32.cjs.js +446 -278
- package/dist/index32.mjs +446 -278
- package/dist/index33.cjs.js +68 -17
- package/dist/index33.mjs +68 -17
- package/dist/index34.cjs.js +460 -304
- package/dist/index34.mjs +460 -304
- package/dist/index35.cjs.js +14 -532
- package/dist/index35.mjs +14 -532
- package/dist/index36.cjs.js +389 -0
- package/dist/index36.mjs +389 -0
- package/dist/index37.cjs.js +539 -0
- package/dist/index37.mjs +539 -0
- package/dist/index4.cjs.js +199 -140
- package/dist/index4.mjs +195 -140
- package/dist/index5.cjs.js +152 -253
- package/dist/index5.mjs +152 -253
- package/dist/index6.cjs.js +267 -89
- package/dist/index6.mjs +267 -89
- package/dist/index7.cjs.js +121 -29
- package/dist/index7.mjs +121 -29
- package/dist/index8.cjs.js +29 -8
- package/dist/index8.mjs +29 -8
- package/dist/index9.cjs.js +8 -7
- package/dist/index9.mjs +8 -7
- package/dist/utils/incrementalQueryUpdate.d.ts +60 -0
- package/dist/utils/projectItems.d.ts +12 -0
- package/dist/utils/queryDelta.d.ts +83 -0
- package/package.json +1 -1
package/dist/index31.cjs.js
CHANGED
|
@@ -1,32 +1,90 @@
|
|
|
1
|
-
|
|
2
|
-
const require_project = require("./index21.cjs.js");
|
|
3
|
-
const require_sortItems = require("./index23.cjs.js");
|
|
4
|
-
//#region src/utils/applyQueryOptions.ts
|
|
1
|
+
//#region src/utils/reactiveOrAsync.ts
|
|
5
2
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
3
|
+
* A generator helper that makes TypeScript infer the “synchronous value type” for maybe-async expressions.
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* const doc = yield* unwrap(Collection.findOne(...))
|
|
7
|
+
* const list = yield* unwrap(Collection.find(...).fetch())
|
|
8
|
+
*
|
|
9
|
+
* Runtime note:
|
|
10
|
+
* This does not “unwrap” Promises by itself. It yields the value/Promise to the runner and returns the
|
|
11
|
+
* value that the runner feeds back via `.next(...)`.
|
|
12
|
+
* @param value The value (or Promise of a value) to yield to the runner.
|
|
13
|
+
* @returns A generator that yields `value` and resolves to the runner-supplied unwrapped `T`.
|
|
15
14
|
*/
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
15
|
+
function unwrap(value) {
|
|
16
|
+
return (function* () {
|
|
17
|
+
return yield value;
|
|
18
|
+
})();
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Internal: checks for thenables (Promise-like).
|
|
22
|
+
* @param value The value to test.
|
|
23
|
+
* @returns `true` if `value` looks like a Promise/thenable.
|
|
24
|
+
*/
|
|
25
|
+
function isThenable(value) {
|
|
26
|
+
return typeof value === "object" && value !== null && typeof value.then === "function";
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Internal runner: executes a generator either synchronously (reactive) or asynchronously (imperative).
|
|
30
|
+
*
|
|
31
|
+
* - In sync mode, yielding a Promise is a programming error and throws.
|
|
32
|
+
* - In async mode, yielded Promises are awaited.
|
|
33
|
+
* @param thisArgument The `this` value to bind when invoking `gen`.
|
|
34
|
+
* @param mode Execution mode options.
|
|
35
|
+
* @param gen The generator workflow to run.
|
|
36
|
+
* @returns The workflow result (a plain value in sync mode, or a Promise in async mode).
|
|
37
|
+
*/
|
|
38
|
+
function runReactiveOrAsync(thisArgument, mode, gen) {
|
|
39
|
+
const a = !!mode?.async;
|
|
40
|
+
const it = gen.call(thisArgument, a);
|
|
41
|
+
if (!a) {
|
|
42
|
+
let step = it.next();
|
|
43
|
+
while (!step.done) {
|
|
44
|
+
const y = step.value;
|
|
45
|
+
if (isThenable(y)) throw new Error("Promise yielded in sync flow");
|
|
46
|
+
step = it.next(y);
|
|
47
|
+
}
|
|
48
|
+
return step.value;
|
|
49
|
+
}
|
|
50
|
+
return (async function() {
|
|
51
|
+
let step = it.next();
|
|
52
|
+
while (!step.done) {
|
|
53
|
+
const y = step.value;
|
|
54
|
+
const v = isThenable(y) ? await y : y;
|
|
55
|
+
step = it.next(v);
|
|
56
|
+
}
|
|
57
|
+
return step.value;
|
|
58
|
+
})();
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Factory that turns a generator workflow into a callable method that can run in sync (reactive) or async mode.
|
|
62
|
+
*
|
|
63
|
+
* Call style:
|
|
64
|
+
* fn(a, b) -> sync/reactive return
|
|
65
|
+
* await fn(a, b, { async: true }) -> async return
|
|
66
|
+
* @param gen Generator workflow. Receives `(a)` which indicates async mode and should `yield`/`yield* unwrap(...)`
|
|
67
|
+
* any values that may be Promises.
|
|
68
|
+
* @returns A callable method with overloads plus a `.generator` property for composition.
|
|
69
|
+
*/
|
|
70
|
+
function reactiveOrAsync(gen) {
|
|
71
|
+
/**
|
|
72
|
+
* The generated method wrapper.
|
|
73
|
+
* @param allArguments Method arguments, optionally ending with a `ModeOptions` object.
|
|
74
|
+
* @returns The workflow result (sync) or a Promise of the result (async).
|
|
75
|
+
*/
|
|
76
|
+
function method(...allArguments) {
|
|
77
|
+
const last = allArguments.length > 0 ? allArguments.at(-1) : void 0;
|
|
78
|
+
const hasMode = typeof last === "object" && last !== null && "async" in last;
|
|
79
|
+
const mode = hasMode ? last : void 0;
|
|
80
|
+
const parameters = hasMode ? allArguments.slice(0, -1) : allArguments;
|
|
81
|
+
return runReactiveOrAsync(this, mode, function* (a) {
|
|
82
|
+
return yield* gen.call(this, a, ...parameters);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
method.generator = gen;
|
|
86
|
+
return method;
|
|
30
87
|
}
|
|
31
88
|
//#endregion
|
|
32
|
-
exports.default =
|
|
89
|
+
exports.default = reactiveOrAsync;
|
|
90
|
+
exports.unwrap = unwrap;
|
package/dist/index31.mjs
CHANGED
|
@@ -1,32 +1,89 @@
|
|
|
1
|
-
|
|
2
|
-
import project from "./index21.mjs";
|
|
3
|
-
import sortItems from "./index23.mjs";
|
|
4
|
-
//#region src/utils/applyQueryOptions.ts
|
|
1
|
+
//#region src/utils/reactiveOrAsync.ts
|
|
5
2
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
3
|
+
* A generator helper that makes TypeScript infer the “synchronous value type” for maybe-async expressions.
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* const doc = yield* unwrap(Collection.findOne(...))
|
|
7
|
+
* const list = yield* unwrap(Collection.find(...).fetch())
|
|
8
|
+
*
|
|
9
|
+
* Runtime note:
|
|
10
|
+
* This does not “unwrap” Promises by itself. It yields the value/Promise to the runner and returns the
|
|
11
|
+
* value that the runner feeds back via `.next(...)`.
|
|
12
|
+
* @param value The value (or Promise of a value) to yield to the runner.
|
|
13
|
+
* @returns A generator that yields `value` and resolves to the runner-supplied unwrapped `T`.
|
|
15
14
|
*/
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
15
|
+
function unwrap(value) {
|
|
16
|
+
return (function* () {
|
|
17
|
+
return yield value;
|
|
18
|
+
})();
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Internal: checks for thenables (Promise-like).
|
|
22
|
+
* @param value The value to test.
|
|
23
|
+
* @returns `true` if `value` looks like a Promise/thenable.
|
|
24
|
+
*/
|
|
25
|
+
function isThenable(value) {
|
|
26
|
+
return typeof value === "object" && value !== null && typeof value.then === "function";
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Internal runner: executes a generator either synchronously (reactive) or asynchronously (imperative).
|
|
30
|
+
*
|
|
31
|
+
* - In sync mode, yielding a Promise is a programming error and throws.
|
|
32
|
+
* - In async mode, yielded Promises are awaited.
|
|
33
|
+
* @param thisArgument The `this` value to bind when invoking `gen`.
|
|
34
|
+
* @param mode Execution mode options.
|
|
35
|
+
* @param gen The generator workflow to run.
|
|
36
|
+
* @returns The workflow result (a plain value in sync mode, or a Promise in async mode).
|
|
37
|
+
*/
|
|
38
|
+
function runReactiveOrAsync(thisArgument, mode, gen) {
|
|
39
|
+
const a = !!mode?.async;
|
|
40
|
+
const it = gen.call(thisArgument, a);
|
|
41
|
+
if (!a) {
|
|
42
|
+
let step = it.next();
|
|
43
|
+
while (!step.done) {
|
|
44
|
+
const y = step.value;
|
|
45
|
+
if (isThenable(y)) throw new Error("Promise yielded in sync flow");
|
|
46
|
+
step = it.next(y);
|
|
47
|
+
}
|
|
48
|
+
return step.value;
|
|
49
|
+
}
|
|
50
|
+
return (async function() {
|
|
51
|
+
let step = it.next();
|
|
52
|
+
while (!step.done) {
|
|
53
|
+
const y = step.value;
|
|
54
|
+
const v = isThenable(y) ? await y : y;
|
|
55
|
+
step = it.next(v);
|
|
56
|
+
}
|
|
57
|
+
return step.value;
|
|
58
|
+
})();
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Factory that turns a generator workflow into a callable method that can run in sync (reactive) or async mode.
|
|
62
|
+
*
|
|
63
|
+
* Call style:
|
|
64
|
+
* fn(a, b) -> sync/reactive return
|
|
65
|
+
* await fn(a, b, { async: true }) -> async return
|
|
66
|
+
* @param gen Generator workflow. Receives `(a)` which indicates async mode and should `yield`/`yield* unwrap(...)`
|
|
67
|
+
* any values that may be Promises.
|
|
68
|
+
* @returns A callable method with overloads plus a `.generator` property for composition.
|
|
69
|
+
*/
|
|
70
|
+
function reactiveOrAsync(gen) {
|
|
71
|
+
/**
|
|
72
|
+
* The generated method wrapper.
|
|
73
|
+
* @param allArguments Method arguments, optionally ending with a `ModeOptions` object.
|
|
74
|
+
* @returns The workflow result (sync) or a Promise of the result (async).
|
|
75
|
+
*/
|
|
76
|
+
function method(...allArguments) {
|
|
77
|
+
const last = allArguments.length > 0 ? allArguments.at(-1) : void 0;
|
|
78
|
+
const hasMode = typeof last === "object" && last !== null && "async" in last;
|
|
79
|
+
const mode = hasMode ? last : void 0;
|
|
80
|
+
const parameters = hasMode ? allArguments.slice(0, -1) : allArguments;
|
|
81
|
+
return runReactiveOrAsync(this, mode, function* (a) {
|
|
82
|
+
return yield* gen.call(this, a, ...parameters);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
method.generator = gen;
|
|
86
|
+
return method;
|
|
30
87
|
}
|
|
31
88
|
//#endregion
|
|
32
|
-
export {
|
|
89
|
+
export { reactiveOrAsync as default, unwrap };
|