@volynets/reflex-store 0.0.0-stage → 0.0.2
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/LICENSE +21 -0
- package/README.md +237 -2
- package/SPECIFICATION.md +137 -0
- package/dist/advanced.d.ts +12 -0
- package/dist/advanced.js +10 -0
- package/dist/chunks/collections-yHy0wH0f.js +268 -0
- package/dist/chunks/compiler-Dsb3E2ck.js +2516 -0
- package/dist/chunks/createStore-DHj16Ehk.js +12 -0
- package/dist/chunks/hydrate-DMnHCI5q.js +138 -0
- package/dist/chunks/keyed-CQKtL8a7.js +383 -0
- package/dist/chunks/names-Cx4YcvsH.js +11 -0
- package/dist/chunks/values-DCB6zyMz.js +142 -0
- package/dist/compiled-store.d.ts +4 -0
- package/dist/compiled-store.js +4 -0
- package/dist/compiler/swc.wasm +0 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +8 -0
- package/dist/licenses/NOTICE.txt +1 -0
- package/dist/licenses/SWC-APACHE-2.0.txt +202 -0
- package/dist/runtime/core.d.ts +2 -0
- package/dist/runtime/core.js +1 -0
- package/dist/runtime/internal.d.ts +3 -0
- package/dist/runtime/internal.js +41 -0
- package/dist/runtime.d.ts +29 -0
- package/dist/runtime.js +88 -0
- package/dist/selectors/index.d.ts +13 -0
- package/dist/selectors/index.js +16 -0
- package/dist/selectors/shared.d.ts +3 -0
- package/dist/selectors/shared.js +64 -0
- package/dist/store.d.ts +9 -0
- package/dist/store.js +4 -0
- package/dist/types/contracts-BCsRPdQb.d.ts +78 -0
- package/dist/types/createStore-BJ66-pfq.d.ts +43 -0
- package/dist/types/internal-BIzJSPwN.d.ts +18 -0
- package/dist/types/keyed-CdSYzIOc.d.ts +18 -0
- package/dist/types/shared-CdTKzvLe.d.ts +114 -0
- package/dist/vite.d.ts +68 -0
- package/dist/vite.js +87 -0
- package/examples/task-board/README.md +15 -0
- package/examples/task-board/src/reactivity.ts +33 -0
- package/examples/task-board/src/task-board.ts +159 -0
- package/examples/task-board/vite.config.ts +6 -0
- package/package.json +119 -4
- package/src/store/README.md +59 -0
- package/src/store/TRANSFORM_SPEC.md +85 -0
|
Binary file
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/// <reference lib="esnext.disposable" />
|
|
2
|
+
import { b as StoreShape, C as CompiledStore, S as StoreData } from './types/createStore-BJ66-pfq.js';
|
|
3
|
+
export { c as createStore, l as leaf } from './types/createStore-BJ66-pfq.js';
|
|
4
|
+
import { S as StoreDisposable } from './types/keyed-CdSYzIOc.js';
|
|
5
|
+
export { b as selector } from './types/keyed-CdSYzIOc.js';
|
|
6
|
+
import { S as Snapshot } from './types/shared-CdTKzvLe.js';
|
|
7
|
+
export { o as opaque, e as reactiveMap, j as snapshot } from './types/shared-CdTKzvLe.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Creates a lazy, read-only structured projection from a pure-return callback.
|
|
11
|
+
* Return a plain object; use reactiveMap for state with dynamic keys.
|
|
12
|
+
*/
|
|
13
|
+
declare function derive<T extends object>(compute: () => T, options?: {
|
|
14
|
+
name?: string;
|
|
15
|
+
}): Readonly<T> & StoreDisposable;
|
|
16
|
+
|
|
17
|
+
/** Wrap one synchronous logical state change, preserving arguments and receiver. */
|
|
18
|
+
declare function action<F extends (...args: any[]) => any>(callback: F & (ReturnType<F> extends PromiseLike<unknown> ? never : unknown)): F;
|
|
19
|
+
|
|
20
|
+
/** Restore all compiled data fields after validating the complete static schema. */
|
|
21
|
+
declare function hydrate<T extends StoreShape>(store: CompiledStore<T>, data: Snapshot<StoreData<T>>): void;
|
|
22
|
+
|
|
23
|
+
export { action, derive, hydrate };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { c as createStore } from './chunks/createStore-DHj16Ehk.js';
|
|
2
|
+
export { a as action, d as derive, h as hydrate, l as leaf } from './chunks/hydrate-DMnHCI5q.js';
|
|
3
|
+
export { c as selector } from './chunks/keyed-CQKtL8a7.js';
|
|
4
|
+
export { c as reactiveMap } from './chunks/collections-yHy0wH0f.js';
|
|
5
|
+
export { o as opaque, s as snapshot } from './chunks/values-DCB6zyMz.js';
|
|
6
|
+
import '@volynets/reflex-runtime/internal';
|
|
7
|
+
import './chunks/names-Cx4YcvsH.js';
|
|
8
|
+
import './selectors/shared.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Includes SWC WebAssembly (Apache-2.0). Reflex host and runtime are shared peer dependencies.
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@volynets/reflex-runtime';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { currentConsumer, readProducer, createProducer, writeProducer, disposeNode } from '@volynets/reflex-runtime/internal';
|
|
2
|
+
export * from '@volynets/reflex-runtime/internal';
|
|
3
|
+
import { s as setStoreName } from '../chunks/names-Cx4YcvsH.js';
|
|
4
|
+
|
|
5
|
+
/** Compiler target: a direct leaf address, materialized only by a tracked read. */ function createStoreCell(initial, options) {
|
|
6
|
+
let value = initial;
|
|
7
|
+
let node;
|
|
8
|
+
let disposed = false;
|
|
9
|
+
const cell = ()=>{
|
|
10
|
+
if (disposed) throw new Error("Cannot use a disposed store cell");
|
|
11
|
+
if (currentConsumer === null) return value;
|
|
12
|
+
readProducer(node ??= createProducer(0));
|
|
13
|
+
return value;
|
|
14
|
+
};
|
|
15
|
+
cell.peek = ()=>{
|
|
16
|
+
if (disposed) throw new Error("Cannot use a disposed store cell");
|
|
17
|
+
return value;
|
|
18
|
+
};
|
|
19
|
+
cell.set = (next)=>{
|
|
20
|
+
if (disposed) throw new Error("Cannot use a disposed store cell");
|
|
21
|
+
if (Object.is(value, next)) return;
|
|
22
|
+
value = next;
|
|
23
|
+
if (node) writeProducer(node, node.payload + 1);
|
|
24
|
+
};
|
|
25
|
+
cell.collect = ()=>{
|
|
26
|
+
if (!node || node.firstOut !== null) return;
|
|
27
|
+
disposeNode(node);
|
|
28
|
+
node = undefined;
|
|
29
|
+
};
|
|
30
|
+
cell[Symbol.dispose] = ()=>cell.dispose();
|
|
31
|
+
cell.dispose = ()=>{
|
|
32
|
+
disposed = true;
|
|
33
|
+
if (node) disposeNode(node);
|
|
34
|
+
node = undefined;
|
|
35
|
+
value = undefined;
|
|
36
|
+
};
|
|
37
|
+
setStoreName(cell, options?.name);
|
|
38
|
+
return cell;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { createStoreCell };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/// <reference lib="esnext.disposable" />
|
|
2
|
+
import { S as StoreCell } from './types/internal-BIzJSPwN.js';
|
|
3
|
+
export { c as createStoreCell } from './types/internal-BIzJSPwN.js';
|
|
4
|
+
import { DisposableResource, Synchronous } from '@volynets/reflex-framework';
|
|
5
|
+
import '@volynets/reflex-runtime/internal';
|
|
6
|
+
|
|
7
|
+
interface DisposableComputed<T> {
|
|
8
|
+
readonly read: () => T;
|
|
9
|
+
dispose(): void;
|
|
10
|
+
}
|
|
11
|
+
/** Owned lazy getter used by the store compiler. */
|
|
12
|
+
declare function createDisposableComputed<T>(fn: () => T): DisposableComputed<T>;
|
|
13
|
+
|
|
14
|
+
type AnyFunction = (...args: never[]) => unknown;
|
|
15
|
+
interface StoreScope {
|
|
16
|
+
readonly disposed: boolean;
|
|
17
|
+
readonly signal: AbortSignal;
|
|
18
|
+
own<T extends DisposableResource>(resource: T): T;
|
|
19
|
+
action<F extends AnyFunction>(callback: Synchronous<F>): F;
|
|
20
|
+
writer<T>(cell: StoreCell<T>): (value: T) => T;
|
|
21
|
+
}
|
|
22
|
+
type StoreScopeValue<T extends object> = T & DisposableResource & {
|
|
23
|
+
dispose(): void;
|
|
24
|
+
};
|
|
25
|
+
/** Compiler lifetime and mutation boundary over the shared framework lifecycle. */
|
|
26
|
+
declare function createStoreScope<T extends object>(setup: (scope: StoreScope) => T): StoreScopeValue<T>;
|
|
27
|
+
|
|
28
|
+
export { createDisposableComputed, createStoreScope };
|
|
29
|
+
export type { DisposableComputed, StoreScope, StoreScopeValue };
|
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
export { createStoreCell } from './runtime/internal.js';
|
|
2
|
+
import { createConsumer, disposeNode, readConsumerLazy, untracked, setCurrentConsumer, currentConsumer } from '@volynets/reflex-runtime/internal';
|
|
3
|
+
import { LifecycleScope } from '@volynets/reflex-framework';
|
|
4
|
+
import { t as transaction } from './chunks/collections-yHy0wH0f.js';
|
|
5
|
+
import './chunks/names-Cx4YcvsH.js';
|
|
6
|
+
import './chunks/values-DCB6zyMz.js';
|
|
7
|
+
|
|
8
|
+
/** Owned lazy getter used by the store compiler. */ function createDisposableComputed(fn) {
|
|
9
|
+
const node = createConsumer(fn);
|
|
10
|
+
return {
|
|
11
|
+
read: readConsumerLazy.bind(node),
|
|
12
|
+
dispose () {
|
|
13
|
+
disposeNode(node);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Compiler lifetime and mutation boundary over the shared framework lifecycle. */ function createStoreScope(setup) {
|
|
19
|
+
const lifecycle = new LifecycleScope((fn)=>transaction(()=>untracked(fn)));
|
|
20
|
+
const assertOpen = ()=>{
|
|
21
|
+
if (lifecycle.disposed) throw new Error("Cannot use a disposed compiled store scope");
|
|
22
|
+
};
|
|
23
|
+
const scope = {
|
|
24
|
+
get disposed () {
|
|
25
|
+
return lifecycle.disposed;
|
|
26
|
+
},
|
|
27
|
+
get signal () {
|
|
28
|
+
return lifecycle.signal;
|
|
29
|
+
},
|
|
30
|
+
own (resource) {
|
|
31
|
+
assertOpen();
|
|
32
|
+
return lifecycle.use(resource);
|
|
33
|
+
},
|
|
34
|
+
writer (cell) {
|
|
35
|
+
assertOpen();
|
|
36
|
+
let pending;
|
|
37
|
+
const commit = ()=>{
|
|
38
|
+
const previous = currentConsumer;
|
|
39
|
+
setCurrentConsumer(null);
|
|
40
|
+
try {
|
|
41
|
+
cell.set(pending);
|
|
42
|
+
} finally{
|
|
43
|
+
setCurrentConsumer(previous);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
return (value)=>{
|
|
47
|
+
assertOpen();
|
|
48
|
+
if (Object.is(cell.peek(), value)) return value;
|
|
49
|
+
const previous = pending;
|
|
50
|
+
pending = value;
|
|
51
|
+
try {
|
|
52
|
+
transaction(commit);
|
|
53
|
+
return value;
|
|
54
|
+
} finally{
|
|
55
|
+
pending = previous;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
action (callback) {
|
|
60
|
+
assertOpen();
|
|
61
|
+
if (Object.prototype.toString.call(callback) === "[object AsyncFunction]") throw new TypeError("Store actions require a synchronous callback");
|
|
62
|
+
return function(...args) {
|
|
63
|
+
assertOpen();
|
|
64
|
+
return transaction(()=>untracked(()=>{
|
|
65
|
+
const result = Reflect.apply(callback, this, args);
|
|
66
|
+
if (result !== null && (typeof result === "object" || typeof result === "function") && typeof Reflect.get(result, "then") === "function") throw new TypeError("Store actions cannot return a promise");
|
|
67
|
+
return result;
|
|
68
|
+
}));
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
try {
|
|
73
|
+
const value = setup(scope);
|
|
74
|
+
const dispose = ()=>lifecycle.dispose();
|
|
75
|
+
return Object.defineProperties(value, {
|
|
76
|
+
dispose: {
|
|
77
|
+
value: dispose
|
|
78
|
+
},
|
|
79
|
+
[Symbol.dispose]: {
|
|
80
|
+
value: dispose
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
} catch (cause) {
|
|
84
|
+
return lifecycle.rollback(cause);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export { createDisposableComputed, createStoreScope };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference lib="esnext.disposable" />
|
|
2
|
+
import { c as StoreProjectionOptions, P as ProjectionOptions } from '../types/shared-CdTKzvLe.js';
|
|
3
|
+
export { K as KeyedOptions } from '../types/shared-CdTKzvLe.js';
|
|
4
|
+
import { S as StoreDisposable, A as Accessor, a as DisposableAccessor } from '../types/keyed-CdSYzIOc.js';
|
|
5
|
+
export { c as createKeyedProjection, b as createSelector } from '../types/keyed-CdSYzIOc.js';
|
|
6
|
+
import '../types/createStore-BJ66-pfq.js';
|
|
7
|
+
|
|
8
|
+
declare function createStoreProjection<T extends object>(fn: (draft: T) => void | T, seed: Partial<T>, options?: StoreProjectionOptions<T>): T & StoreDisposable;
|
|
9
|
+
|
|
10
|
+
declare function createProjection<T extends object>(fn: (draft: T) => void | T, seed: Partial<T>, options?: StoreProjectionOptions<T>): T & StoreDisposable;
|
|
11
|
+
declare function createProjection<T, K, R>(source: Accessor<T>, keyOf: (value: T) => K, project: (value: T) => R, options?: ProjectionOptions<K, R>): DisposableAccessor<K, R | undefined>;
|
|
12
|
+
|
|
13
|
+
export { ProjectionOptions, StoreProjectionOptions, createProjection, createStoreProjection };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { a as createKeyedProjection, b as createStoreProjection } from '../chunks/keyed-CQKtL8a7.js';
|
|
2
|
+
export { c as createSelector } from '../chunks/keyed-CQKtL8a7.js';
|
|
3
|
+
import '@volynets/reflex-runtime/internal';
|
|
4
|
+
import '../chunks/values-DCB6zyMz.js';
|
|
5
|
+
import '../chunks/names-Cx4YcvsH.js';
|
|
6
|
+
import './shared.js';
|
|
7
|
+
import '../chunks/collections-yHy0wH0f.js';
|
|
8
|
+
|
|
9
|
+
function createProjection(sourceOrProject, keyOrSeed, projectOrOptions, options) {
|
|
10
|
+
if (typeof keyOrSeed === "function" && typeof projectOrOptions === "function") {
|
|
11
|
+
return createKeyedProjection(sourceOrProject, keyOrSeed, projectOrOptions, options ?? {});
|
|
12
|
+
}
|
|
13
|
+
return createStoreProjection(sourceOrProject, keyOrSeed, projectOrOptions ?? {});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { createKeyedProjection, createProjection, createStoreProjection };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/// <reference lib="esnext.disposable" />
|
|
2
|
+
export { K as KeyedOptions, M as Missing, P as ProjectionOptions, c as StoreProjectionOptions, k as cloneProjectionValue, l as createStoreReaderProxy, m as getMissing, n as isObject, p as readProjectionPath, q as sameValue } from '../types/shared-CdTKzvLe.js';
|
|
3
|
+
import '../types/createStore-BJ66-pfq.js';
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export { f as cloneProjectionValue } from '../chunks/values-DCB6zyMz.js';
|
|
2
|
+
import '@volynets/reflex-runtime/internal';
|
|
3
|
+
|
|
4
|
+
const MISSING = Symbol("selector.missing");
|
|
5
|
+
function sameValue(prev, next) {
|
|
6
|
+
return Object.is(prev, next);
|
|
7
|
+
}
|
|
8
|
+
function getMissing() {
|
|
9
|
+
return MISSING;
|
|
10
|
+
}
|
|
11
|
+
function isObject(value) {
|
|
12
|
+
return typeof value === "object" && value !== null;
|
|
13
|
+
}
|
|
14
|
+
function readProjectionPath(value, path) {
|
|
15
|
+
let current = value;
|
|
16
|
+
for(let index = 0; index < path.length; ++index){
|
|
17
|
+
if (!isObject(current)) return undefined;
|
|
18
|
+
current = current[path[index]];
|
|
19
|
+
}
|
|
20
|
+
return current;
|
|
21
|
+
}
|
|
22
|
+
function createStoreReaderProxy(readState, path = []) {
|
|
23
|
+
return new Proxy(Object.create(null), {
|
|
24
|
+
get (_target, prop) {
|
|
25
|
+
if (prop === Symbol.toStringTag) return "ProjectionStore";
|
|
26
|
+
const value = readProjectionPath(readState(), [
|
|
27
|
+
...path,
|
|
28
|
+
prop
|
|
29
|
+
]);
|
|
30
|
+
return isObject(value) ? createStoreReaderProxy(readState, [
|
|
31
|
+
...path,
|
|
32
|
+
prop
|
|
33
|
+
]) : value;
|
|
34
|
+
},
|
|
35
|
+
has (_target, prop) {
|
|
36
|
+
const parent = readProjectionPath(readState(), path);
|
|
37
|
+
return isObject(parent) && prop in parent;
|
|
38
|
+
},
|
|
39
|
+
ownKeys () {
|
|
40
|
+
const value = readProjectionPath(readState(), path);
|
|
41
|
+
return isObject(value) ? Reflect.ownKeys(value) : [];
|
|
42
|
+
},
|
|
43
|
+
getOwnPropertyDescriptor (_target, prop) {
|
|
44
|
+
const parent = readProjectionPath(readState(), path);
|
|
45
|
+
if (!isObject(parent) || !(prop in parent)) {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
configurable: true,
|
|
50
|
+
enumerable: true,
|
|
51
|
+
value: parent[prop],
|
|
52
|
+
writable: false
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
set () {
|
|
56
|
+
return false;
|
|
57
|
+
},
|
|
58
|
+
deleteProperty () {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export { createStoreReaderProxy, getMissing, isObject, readProjectionPath, sameValue };
|
package/dist/store.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference lib="esnext.disposable" />
|
|
2
|
+
export { C as CompiledStore, b as StoreShape, c as createStore } from './types/createStore-BJ66-pfq.js';
|
|
3
|
+
import { C as CompiledStoreTransformOptions, a as CompiledStoreTransformResult } from './types/contracts-BCsRPdQb.js';
|
|
4
|
+
export { b as CompiledStoreDiagnostic, c as CompiledStoreLoweringTarget, d as CompiledStoreLoweringTargetOptions, e as CompiledStorePathContext, f as CompiledStoreTemporaryContext, g as CompiledStoreTransformError } from './types/contracts-BCsRPdQb.js';
|
|
5
|
+
|
|
6
|
+
declare function compileStore(code: string, id?: string, options?: CompiledStoreTransformOptions): CompiledStoreTransformResult;
|
|
7
|
+
declare function transformCompiledStore(code: string, id?: string, options?: CompiledStoreTransformOptions): CompiledStoreTransformResult;
|
|
8
|
+
|
|
9
|
+
export { CompiledStoreTransformOptions, CompiledStoreTransformResult, compileStore, transformCompiledStore };
|
package/dist/store.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/// <reference lib="esnext.disposable" />
|
|
2
|
+
interface CompiledStorePathContext {
|
|
3
|
+
path: readonly string[];
|
|
4
|
+
mangledPath: string;
|
|
5
|
+
}
|
|
6
|
+
interface CompiledStoreTemporaryContext {
|
|
7
|
+
index: number;
|
|
8
|
+
label: string;
|
|
9
|
+
}
|
|
10
|
+
interface CompiledStoreLoweringTarget {
|
|
11
|
+
runtimeModule: string;
|
|
12
|
+
scope: {
|
|
13
|
+
exportName: string;
|
|
14
|
+
localName: string;
|
|
15
|
+
actionMethod: string;
|
|
16
|
+
/** Legacy factory targets may return a zero-argument constructor. */
|
|
17
|
+
curried?: boolean;
|
|
18
|
+
};
|
|
19
|
+
signal: {
|
|
20
|
+
/** Defaults to runtimeModule for custom targets. */
|
|
21
|
+
runtimeModule?: string;
|
|
22
|
+
exportName: string;
|
|
23
|
+
localName: string;
|
|
24
|
+
};
|
|
25
|
+
identifiers: {
|
|
26
|
+
context: string;
|
|
27
|
+
value: string;
|
|
28
|
+
read: (context: CompiledStorePathContext) => string;
|
|
29
|
+
set: (context: CompiledStorePathContext) => string;
|
|
30
|
+
write: (context: CompiledStorePathContext) => string;
|
|
31
|
+
temporary: (context: CompiledStoreTemporaryContext) => string;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
type CompiledStoreLoweringTargetOptions = {
|
|
35
|
+
runtimeModule?: string;
|
|
36
|
+
scope?: Partial<CompiledStoreLoweringTarget["scope"]>;
|
|
37
|
+
/** @deprecated Use scope. Legacy model targets are invoked as factories. */
|
|
38
|
+
model?: Partial<CompiledStoreLoweringTarget["scope"]>;
|
|
39
|
+
signal?: Partial<CompiledStoreLoweringTarget["signal"]>;
|
|
40
|
+
identifiers?: Partial<CompiledStoreLoweringTarget["identifiers"]>;
|
|
41
|
+
};
|
|
42
|
+
type DiagnosticCode = "unsupported-shape" | "unsupported-binding" | "unsupported-write" | "dynamic-access" | "branch-alias" | "spread-reflection" | "delete" | "optional-chain";
|
|
43
|
+
interface CompiledStoreDiagnostic {
|
|
44
|
+
code: DiagnosticCode;
|
|
45
|
+
message: string;
|
|
46
|
+
}
|
|
47
|
+
interface CompiledStoreTransformOptions {
|
|
48
|
+
/**
|
|
49
|
+
* Emits the runtime import needed by generated code.
|
|
50
|
+
*
|
|
51
|
+
* Test harnesses can disable this and provide `__reflex_createStoreScope` and
|
|
52
|
+
* `__reflex_signal` in scope manually.
|
|
53
|
+
*/
|
|
54
|
+
importRuntime?: boolean;
|
|
55
|
+
/** Omit the facade when every store use lowers directly to a declared leaf. */
|
|
56
|
+
eraseFacade?: boolean;
|
|
57
|
+
/** Store scope module used by generated code. */
|
|
58
|
+
runtimeModule?: string;
|
|
59
|
+
/** Customize every runtime symbol emitted by the canonical lowering. */
|
|
60
|
+
loweringTarget?: CompiledStoreLoweringTargetOptions;
|
|
61
|
+
/**
|
|
62
|
+
* `throw` is the compiler default because unsupported store syntax should be
|
|
63
|
+
* found during development, not discovered as a runtime semantic mismatch.
|
|
64
|
+
*/
|
|
65
|
+
onDiagnostic?: "throw" | "collect";
|
|
66
|
+
}
|
|
67
|
+
interface CompiledStoreTransformResult {
|
|
68
|
+
code: string;
|
|
69
|
+
diagnostics: CompiledStoreDiagnostic[];
|
|
70
|
+
map: string | null;
|
|
71
|
+
}
|
|
72
|
+
declare class CompiledStoreTransformError extends Error {
|
|
73
|
+
readonly diagnostics: CompiledStoreDiagnostic[];
|
|
74
|
+
constructor(diagnostics: CompiledStoreDiagnostic[]);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export { CompiledStoreTransformError as g };
|
|
78
|
+
export type { CompiledStoreTransformOptions as C, CompiledStoreTransformResult as a, CompiledStoreDiagnostic as b, CompiledStoreLoweringTarget as c, CompiledStoreLoweringTargetOptions as d, CompiledStorePathContext as e, CompiledStoreTemporaryContext as f };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/// <reference lib="esnext.disposable" />
|
|
2
|
+
declare const storeBoundary: unique symbol;
|
|
3
|
+
type StoreBoundary<T> = T & {
|
|
4
|
+
readonly [storeBoundary]: T;
|
|
5
|
+
};
|
|
6
|
+
/** Marks one compiled store value as a replaceable leaf. */
|
|
7
|
+
declare function leaf<T>(value: T): StoreBoundary<T>;
|
|
8
|
+
|
|
9
|
+
type StoreLeaf = string | number | boolean | bigint | symbol | null | undefined | readonly unknown[] | ((...args: any[]) => unknown) | StoreBoundary<unknown>;
|
|
10
|
+
declare const compiledShape: unique symbol;
|
|
11
|
+
type Same<A, B> = (<T>() => T extends A ? 1 : 2) extends <T>() => T extends B ? 1 : 2 ? true : false;
|
|
12
|
+
type StoreData<T> = {
|
|
13
|
+
[K in keyof T as T[K] extends (...args: any[]) => unknown ? never : Same<Pick<T, K>, {
|
|
14
|
+
-readonly [P in K]: T[P];
|
|
15
|
+
}> extends true ? K : never]: T[K] extends StoreBoundary<infer V> ? V : T[K] extends StoreShape ? StoreData<T[K]> : T[K];
|
|
16
|
+
};
|
|
17
|
+
interface StoreOptions {
|
|
18
|
+
name?: string;
|
|
19
|
+
}
|
|
20
|
+
type StoreShape = {
|
|
21
|
+
[key: string]: StoreLeaf | StoreShape;
|
|
22
|
+
};
|
|
23
|
+
type CompiledValue<T> = T extends StoreBoundary<infer TLeaf> ? TLeaf : T extends StoreShape ? CompiledBranch<T> : T;
|
|
24
|
+
type CompiledBranch<TShape extends StoreShape> = {
|
|
25
|
+
-readonly [K in keyof TShape]: CompiledValue<TShape[K]>;
|
|
26
|
+
};
|
|
27
|
+
type CompiledStore<TShape extends StoreShape> = CompiledBranch<TShape> & {
|
|
28
|
+
readonly [compiledShape]: TShape;
|
|
29
|
+
dispose(): void;
|
|
30
|
+
[Symbol.dispose](): void;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Declares a compile-time store shape for the compiled-store transform.
|
|
34
|
+
*
|
|
35
|
+
* Data properties become leaf cells; methods become batched actions; getters
|
|
36
|
+
* become lazy computed values. leaf() and opaque() mark object values as
|
|
37
|
+
* replaceable leaves. If this function executes at runtime, the transform did
|
|
38
|
+
* not run.
|
|
39
|
+
*/
|
|
40
|
+
declare function createStore<TShape extends StoreShape>(_shape: TShape, _options?: StoreOptions): CompiledStore<TShape>;
|
|
41
|
+
|
|
42
|
+
export { createStore as c, leaf as l };
|
|
43
|
+
export type { CompiledStore as C, StoreData as S, StoreOptions as a, StoreShape as b, StoreBoundary as d };
|