@getforma/core 1.0.10 → 1.2.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/{chunk-T33QUD2Y.cjs → chunk-E3FV2VSU.cjs} +43 -43
- package/dist/{chunk-T33QUD2Y.cjs.map → chunk-E3FV2VSU.cjs.map} +1 -1
- package/dist/chunk-ETPJTPYD.js +103 -0
- package/dist/chunk-ETPJTPYD.js.map +1 -0
- package/dist/chunk-H7MDUHS5.cjs +110 -0
- package/dist/chunk-H7MDUHS5.cjs.map +1 -0
- package/dist/{chunk-6FW5E54W.cjs → chunk-KUXNZ5MG.cjs} +127 -103
- package/dist/chunk-KUXNZ5MG.cjs.map +1 -0
- package/dist/{chunk-3G7ET4O5.js → chunk-Y3A2EVVS.js} +121 -94
- package/dist/chunk-Y3A2EVVS.js.map +1 -0
- package/dist/{chunk-AFRFF7XL.js → chunk-YRNYOZF3.js} +4 -4
- package/dist/{chunk-AFRFF7XL.js.map → chunk-YRNYOZF3.js.map} +1 -1
- package/dist/forma-runtime-csp.js +52 -4
- package/dist/forma-runtime.js +98 -10
- package/dist/formajs-runtime-hardened.global.js +52 -4
- package/dist/formajs-runtime-hardened.global.js.map +1 -1
- package/dist/formajs-runtime.global.js +98 -10
- package/dist/formajs-runtime.global.js.map +1 -1
- package/dist/formajs.global.js +368 -147
- package/dist/formajs.global.js.map +1 -1
- package/dist/http.cjs +11 -11
- package/dist/http.js +2 -2
- package/dist/index.cjs +262 -141
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +32 -27
- package/dist/index.d.ts +32 -27
- package/dist/index.js +204 -83
- package/dist/index.js.map +1 -1
- package/dist/{resource-DeEzxUz6.d.cts → resource-D6HfVgiA.d.cts} +7 -2
- package/dist/{resource-BHsgURy0.d.ts → resource-ljs2X5NM.d.ts} +7 -2
- package/dist/runtime-hardened.cjs +53 -3
- package/dist/runtime-hardened.cjs.map +1 -1
- package/dist/runtime-hardened.js +53 -3
- package/dist/runtime-hardened.js.map +1 -1
- package/dist/runtime.cjs +29 -29
- package/dist/runtime.js +3 -3
- package/dist/server.cjs +7 -7
- package/dist/server.d.cts +2 -2
- package/dist/server.d.ts +2 -2
- package/dist/server.js +2 -2
- package/dist/{signal-C9v4akyJ.d.cts → signal-CRBJYQ6B.d.cts} +0 -8
- package/dist/{signal-C9v4akyJ.d.ts → signal-CRBJYQ6B.d.ts} +0 -8
- package/dist/tc39-compat.cjs +3 -6
- package/dist/tc39-compat.cjs.map +1 -1
- package/dist/tc39-compat.d.cts +1 -1
- package/dist/tc39-compat.d.ts +1 -1
- package/dist/tc39-compat.js +1 -4
- package/dist/tc39-compat.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-3G7ET4O5.js.map +0 -1
- package/dist/chunk-6FW5E54W.cjs.map +0 -1
- package/dist/chunk-HLM5BZZQ.js +0 -35
- package/dist/chunk-HLM5BZZQ.js.map +0 -1
- package/dist/chunk-QLPCVK7C.cjs +0 -38
- package/dist/chunk-QLPCVK7C.cjs.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as SignalGetter } from './signal-
|
|
1
|
+
import { S as SignalGetter } from './signal-CRBJYQ6B.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Forma Reactive - Resource
|
|
@@ -10,6 +10,11 @@ import { S as SignalGetter } from './signal-C9v4akyJ.js';
|
|
|
10
10
|
* React equivalent: use() + Suspense (React 19), or useSWR/react-query
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
/** Info passed to a resource fetcher — carries the AbortSignal for this fetch. */
|
|
14
|
+
interface ResourceFetcherInfo {
|
|
15
|
+
/** Aborted when the source changes / the resource refetches or is disposed. */
|
|
16
|
+
signal: AbortSignal;
|
|
17
|
+
}
|
|
13
18
|
/** An async data resource with reactive loading and error state. */
|
|
14
19
|
interface Resource<T> {
|
|
15
20
|
/** The resolved data (or undefined while loading). */
|
|
@@ -59,6 +64,6 @@ interface ResourceOptions<T> {
|
|
|
59
64
|
* );
|
|
60
65
|
* ```
|
|
61
66
|
*/
|
|
62
|
-
declare function createResource<T, S = true>(source: SignalGetter<S>, fetcher: (source: S) => Promise<T>, options?: ResourceOptions<T>): Resource<T>;
|
|
67
|
+
declare function createResource<T, S = true>(source: SignalGetter<S>, fetcher: (source: S, info: ResourceFetcherInfo) => Promise<T>, options?: ResourceOptions<T>): Resource<T>;
|
|
63
68
|
|
|
64
69
|
export { type Resource as R, type ResourceOptions as a, createResource as c };
|
|
@@ -3,10 +3,33 @@
|
|
|
3
3
|
var alienSignals = require('alien-signals');
|
|
4
4
|
|
|
5
5
|
// src/reactive/signal.ts
|
|
6
|
+
|
|
7
|
+
// src/reactive/dev.ts
|
|
8
|
+
function isDev() {
|
|
9
|
+
if (typeof process !== "undefined") {
|
|
10
|
+
return process.env?.NODE_ENV !== "production";
|
|
11
|
+
}
|
|
12
|
+
return typeof __FORMA_DEV__ !== "undefined" ? !!__FORMA_DEV__ : false;
|
|
13
|
+
}
|
|
14
|
+
isDev();
|
|
15
|
+
var _errorHandlers = /* @__PURE__ */ new Set();
|
|
16
|
+
function reportError(error, source) {
|
|
17
|
+
for (const handler of _errorHandlers) {
|
|
18
|
+
try {
|
|
19
|
+
handler(error, source ? { source } : {});
|
|
20
|
+
} catch {
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (isDev()) {
|
|
24
|
+
console.error(`[forma] ${source} error:`, error);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
6
27
|
function applySignalSet(s, v, equals) {
|
|
7
28
|
if (typeof v !== "function") {
|
|
8
|
-
|
|
9
|
-
|
|
29
|
+
{
|
|
30
|
+
s(v);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
10
33
|
}
|
|
11
34
|
const prevSub = alienSignals.setActiveSub(void 0);
|
|
12
35
|
const prev = s();
|
|
@@ -24,8 +47,35 @@ function internalEffect(fn) {
|
|
|
24
47
|
const dispose = alienSignals.effect(fn);
|
|
25
48
|
return dispose;
|
|
26
49
|
}
|
|
50
|
+
var ERR = /* @__PURE__ */ Symbol("formaComputedError");
|
|
51
|
+
function isErrBox(v) {
|
|
52
|
+
return typeof v === "object" && v !== null && ERR in v;
|
|
53
|
+
}
|
|
27
54
|
function createComputed(fn) {
|
|
28
|
-
|
|
55
|
+
let errored = false;
|
|
56
|
+
let error;
|
|
57
|
+
let lastGood;
|
|
58
|
+
const raw = alienSignals.computed(() => {
|
|
59
|
+
try {
|
|
60
|
+
const v = fn(lastGood);
|
|
61
|
+
errored = false;
|
|
62
|
+
error = void 0;
|
|
63
|
+
lastGood = v;
|
|
64
|
+
return v;
|
|
65
|
+
} catch (e) {
|
|
66
|
+
errored = true;
|
|
67
|
+
error = e;
|
|
68
|
+
reportError(e, "computed");
|
|
69
|
+
return { [ERR]: e };
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
const reader = () => {
|
|
73
|
+
const v = raw();
|
|
74
|
+
if (errored || isErrBox(v)) throw error;
|
|
75
|
+
return v;
|
|
76
|
+
};
|
|
77
|
+
Object.defineProperty(reader, "name", { value: raw.name, configurable: true });
|
|
78
|
+
return reader;
|
|
29
79
|
}
|
|
30
80
|
function batch(fn) {
|
|
31
81
|
alienSignals.startBatch();
|