@volynets/reflex-store 0.0.0-stage → 0.0.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.
Files changed (45) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +239 -2
  3. package/SPECIFICATION.md +137 -0
  4. package/dist/advanced.d.ts +13 -0
  5. package/dist/advanced.js +9 -0
  6. package/dist/chunks/compiler-CW_P8WsZ.js +2526 -0
  7. package/dist/chunks/createStore-DHj16Ehk.js +12 -0
  8. package/dist/chunks/hydrate-Bdtl9XyA.js +137 -0
  9. package/dist/chunks/keyed-C-QvvUv4.js +647 -0
  10. package/dist/chunks/names-BF36AyM3.js +11 -0
  11. package/dist/chunks/shared-BHHficW8.js +202 -0
  12. package/dist/compiled-store.d.ts +4 -0
  13. package/dist/compiled-store.js +4 -0
  14. package/dist/compiler/swc.wasm +0 -0
  15. package/dist/index.d.ts +23 -0
  16. package/dist/index.js +7 -0
  17. package/dist/licenses/NOTICE.txt +1 -0
  18. package/dist/licenses/SWC-APACHE-2.0.txt +202 -0
  19. package/dist/runtime/core.d.ts +2 -0
  20. package/dist/runtime/core.js +1 -0
  21. package/dist/runtime/internal.d.ts +3 -0
  22. package/dist/runtime/internal.js +41 -0
  23. package/dist/runtime/types.d.ts +45 -0
  24. package/dist/runtime/types.js +1 -0
  25. package/dist/runtime.d.ts +25 -0
  26. package/dist/runtime.js +78 -0
  27. package/dist/selectors/index.d.ts +13 -0
  28. package/dist/selectors/index.js +15 -0
  29. package/dist/selectors/shared.d.ts +3 -0
  30. package/dist/selectors/shared.js +2 -0
  31. package/dist/store.d.ts +9 -0
  32. package/dist/store.js +4 -0
  33. package/dist/types/contracts-BCsRPdQb.d.ts +78 -0
  34. package/dist/types/createStore-BJ66-pfq.d.ts +43 -0
  35. package/dist/types/internal-BIzJSPwN.d.ts +18 -0
  36. package/dist/types/keyed-CdSYzIOc.d.ts +18 -0
  37. package/dist/types/shared-CdTKzvLe.d.ts +114 -0
  38. package/dist/vite.d.ts +68 -0
  39. package/dist/vite.js +87 -0
  40. package/examples/task-board/README.md +15 -0
  41. package/examples/task-board/src/task-board.ts +159 -0
  42. package/examples/task-board/vite.config.ts +6 -0
  43. package/package.json +125 -4
  44. package/src/store/README.md +59 -0
  45. package/src/store/TRANSFORM_SPEC.md +85 -0
package/package.json CHANGED
@@ -1,6 +1,127 @@
1
1
  {
2
2
  "name": "@volynets/reflex-store",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "description": "State management primitives for Reflex",
6
+ "license": "MIT",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "sideEffects": false,
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js"
14
+ },
15
+ "./advanced": {
16
+ "types": "./dist/advanced.d.ts",
17
+ "import": "./dist/advanced.js"
18
+ },
19
+ "./selectors": {
20
+ "types": "./dist/selectors/index.d.ts",
21
+ "import": "./dist/selectors/index.js"
22
+ },
23
+ "./selectors/shared": {
24
+ "types": "./dist/selectors/shared.d.ts",
25
+ "import": "./dist/selectors/shared.js"
26
+ },
27
+ "./store": {
28
+ "types": "./dist/store.d.ts",
29
+ "import": "./dist/store.js"
30
+ },
31
+ "./compiled-store": {
32
+ "types": "./dist/compiled-store.d.ts",
33
+ "import": "./dist/compiled-store.js"
34
+ },
35
+ "./vite": {
36
+ "types": "./dist/vite.d.ts",
37
+ "import": "./dist/vite.js"
38
+ },
39
+ "./runtime": {
40
+ "types": "./dist/runtime.d.ts",
41
+ "import": "./dist/runtime.js"
42
+ },
43
+ "./runtime/internal": {
44
+ "types": "./dist/runtime/internal.d.ts",
45
+ "import": "./dist/runtime/internal.js"
46
+ },
47
+ "./runtime/core": {
48
+ "types": "./dist/runtime/core.d.ts",
49
+ "import": "./dist/runtime/core.js"
50
+ },
51
+ "./runtime/types": {
52
+ "types": "./dist/runtime/types.d.ts",
53
+ "import": "./dist/runtime/types.js"
54
+ }
55
+ },
56
+ "files": [
57
+ "dist",
58
+ "examples/task-board",
59
+ "src/store/README.md",
60
+ "src/store/TRANSFORM_SPEC.md",
61
+ "SPECIFICATION.md"
62
+ ],
63
+ "publishConfig": {
64
+ "access": "public"
65
+ },
66
+ "scripts": {
67
+ "clean": "node ../../tooling/build/clean.mjs .",
68
+ "build": "node scripts/build.mjs",
69
+ "bench": "vitest bench --config vite.config.ts bench/semantic-workloads.bench.ts",
70
+ "bench:full": "vitest bench --mode full --config vite.config.ts bench/semantic-workloads.bench.ts",
71
+ "bench:hot-paths": "node --expose-gc bench/hot-paths.node.mjs",
72
+ "bench:metrics": "vitest run --config vite.metrics.config.ts tests/semantic-workloads.metrics.test.ts",
73
+ "lint": "eslint .",
74
+ "lint:fix": "eslint . --fix",
75
+ "test": "vitest run --config vite.config.ts",
76
+ "typecheck": "tsc --noEmit -p tsconfig.json && tsc -p tsconfig.example.json",
77
+ "prepublishOnly": "pnpm check:release",
78
+ "check:release": "pnpm build:all && pnpm lint && pnpm test && pnpm test:dev && pnpm typecheck && pnpm check:artifacts && node scripts/packed-runtime-identity.mjs",
79
+ "test:dev": "vitest run --config vite.dev.config.ts",
80
+ "test:differential": "vitest run --config vite.config.ts tests/compiler.differential.test.ts tests/runtime.differential.test.ts",
81
+ "test:integration": "vitest run --config vite.config.ts tests/store.integration.test.ts tests/vite-user-dx.test.ts tests/task-board",
82
+ "test:packed-runtime": "pnpm --filter @volynets/reflex build:all && pnpm --filter @volynets/reflex-framework build && pnpm build && node scripts/packed-runtime-identity.mjs",
83
+ "build:all": "node ../../tooling/build/run.mjs @volynets/reflex-store",
84
+ "check:artifacts": "node ../../tooling/build/verify-artifacts.mjs --directory .",
85
+ "prepack": "pnpm build && pnpm check:artifacts"
86
+ },
87
+ "devDependencies": {
88
+ "@rollup/plugin-commonjs": "^29.0.3",
89
+ "@rollup/plugin-node-resolve": "^16.0.3",
90
+ "@rollup/plugin-replace": "^6.0.3",
91
+ "@rollup/plugin-swc": "^0.4.0",
92
+ "@swc/core": "^1.15.18",
93
+ "@swc/wasm": "^1.16.13",
94
+ "@types/node": "^26.1.2",
95
+ "@volynets/reflex": "workspace:^",
96
+ "@volynets/reflex-runtime": "workspace:*",
97
+ "@volynets/reflex-scheduler": "workspace:^",
98
+ "rollup": "^4.54.0",
99
+ "rollup-plugin-dts": "^6.4.1",
100
+ "@volynets/reflex-framework": "workspace:*"
101
+ },
102
+ "keywords": [
103
+ "reflex",
104
+ "state",
105
+ "store",
106
+ "selector",
107
+ "reactivity"
108
+ ],
109
+ "repository": {
110
+ "type": "git",
111
+ "url": "git+https://github.com/volynetstyle/Reflex.git",
112
+ "directory": "packages/reflex-store"
113
+ },
114
+ "homepage": "https://github.com/volynetstyle/Reflex/tree/main/packages/reflex-store",
115
+ "bugs": {
116
+ "url": "https://github.com/volynetstyle/Reflex/issues"
117
+ },
118
+ "engines": {
119
+ "node": ">=20.19.0"
120
+ },
121
+ "peerDependencies": {
122
+ "@volynets/reflex": "^1.0.0",
123
+ "@volynets/reflex-runtime": "^1.0.0",
124
+ "@volynets/reflex-framework": "^0.1.3"
125
+ },
126
+ "private": false
127
+ }
@@ -0,0 +1,59 @@
1
+ # Compiled static stores
2
+
3
+ The root createStore API requires the compiler. Import the plugin from
4
+ @volynets/reflex-store/vite or use compileStore from /store.
5
+
6
+ ```ts
7
+ import {
8
+ createStore,
9
+ leaf,
10
+ opaque,
11
+ snapshot,
12
+ hydrate,
13
+ } from "@volynets/reflex-store";
14
+
15
+ export function createCounter() {
16
+ const state = createStore(
17
+ {
18
+ count: 0,
19
+ history: leaf<readonly number[]>([]),
20
+ engine: opaque(new Engine()),
21
+ get doubled() {
22
+ return this.count * 2;
23
+ },
24
+ increment() {
25
+ this.count++;
26
+ this.history = [...this.history, this.count];
27
+ },
28
+ },
29
+ { name: "Counter" },
30
+ );
31
+ return state;
32
+ }
33
+ ```
34
+
35
+ Factories allocate independent cells, computed getters and action methods.
36
+ Static data accesses lower to direct cell calls. Root methods are bound actions;
37
+ getters are owned lazy computeds. Snapshot extraction excludes methods/getters.
38
+ Hydration validates the complete data schema before batched restoration.
39
+
40
+ The compiler accepts data properties with unique static keys. Literal objects
41
+ form branches; leaf/opaque imports (including aliases) define single replaceable
42
+ locations. Arrays use replacement semantics.
43
+
44
+ Unsupported syntax is diagnosed: spreads, shorthand, **proto**, reserved lifecycle
45
+ names, setter properties, nested methods/getters, async/generator methods, dynamic
46
+ paths, branch aliases, delete, optional chaining, structural replacement and
47
+ arbitrary root reflection. Getters must not write store state.
48
+
49
+ Use eraseFacade to remove objects proven unnecessary for direct data-cell uses.
50
+ Returned stores, computed getters, action methods and lifecycle/data boundaries
51
+ retain their facade.
52
+
53
+ The default lowering imports createStoreScope from /runtime and cells from
54
+ /runtime/internal. The scope uses the shared Framework LifecycleScope for resource
55
+ ownership and rollback, and adds the Store action boundary. It has no model
56
+ shape validation or capability brands. Custom scope/signal lowering remains
57
+ available for data-only stores through loweringTarget; the legacy model option
58
+ is a compatibility alias for curried factory targets.
59
+ See [TRANSFORM_SPEC.md](./TRANSFORM_SPEC.md).
@@ -0,0 +1,85 @@
1
+ # Compiled store transform contract
2
+
3
+ ## Recognition and declarations
4
+
5
+ Recognize createStore imports from @volynets/reflex-store, /advanced, /store and
6
+ /compiled-store, including aliases. Match binding identity, not text alone.
7
+ The compiler API may recognize unresolved bare createStore calls; the Vite plugin
8
+ requires a matching import unless compileBareCreateStore is enabled.
9
+
10
+ Lexical module/function/block declarations are supported. Each execution of a
11
+ local declaration allocates independent store resources. Inline return
12
+ createStore(...) and loop-header declarations remain diagnosed.
13
+
14
+ ## Shape and boundaries
15
+
16
+ Accept unique static data keys, root method declarations and root getter
17
+ declarations. Literal data objects become branches. Imported leaf(value) and
18
+ opaque(value) calls define one replaceable location. Preserve opaque marking.
19
+ Optional options require a static name string.
20
+
21
+ Data initializers execute once in source order for each declaration execution.
22
+ Data leaf reads are direct address calls. Producers materialize on tracked reads.
23
+
24
+ ## Methods and getters
25
+
26
+ Root methods become bound ctx.action callbacks. Rewrite their store this
27
+ references to the declaration binding, preserving lexical-arrow this and leaving
28
+ nested ordinary function/class receivers intact. Lower static leaf reads/writes
29
+ inside the callbacks as usual. Multi-write methods close one outer host/runtime
30
+ batch.
31
+
32
+ Root getters become owned createDisposableComputed accessors. Their this
33
+ references lower to store locations. Clean reads cache; writes invalidate and
34
+ pull reads compute current data. Getters cannot write store state or suspend.
35
+ Async/generator methods, setters and nested methods/getters are unsupported.
36
+
37
+ ## Writes and JavaScript order
38
+
39
+ Support =, +=, -=, prefix/postfix ++ and -- on declared data leaves.
40
+ Evaluate the previous value before a compound RHS, evaluate the RHS once and
41
+ then commit the result. Update operators preserve JavaScript ToNumeric,
42
+ including strings, undefined, NaN, signed zero and BigInt. Exceptions before
43
+ commit preserve the previous value; action exceptions close batches.
44
+
45
+ ## Facade, ownership and extraction
46
+
47
+ The generated facade contains data accessors, getter accessors, bound actions,
48
+ dispose and Symbol.dispose. A Store scope owns cells and computed getter resources
49
+ through Framework's LifecycleScope. Cells are allocated and adopted inside the
50
+ scope setup callback, preserving initializer order. Setup failures roll back all
51
+ resources already owned and rethrow the original cause. Actions reject terminal
52
+ use in production and development; raw cells expose Symbol.dispose.
53
+ Static hidden control callbacks extract only data fields and restore values to
54
+ known cells. Returning a facade (also within a factory return object) is supported.
55
+
56
+ snapshot/hydrate imports are recognized intrinsic data boundaries. own(ctx, state)
57
+ and getStoreName(state) are recognized ownership/diagnostic boundaries. Runtime
58
+ snapshot invokes the generated extraction untracked, preserving structural graph
59
+ semantics. Hydration validates the exact compiled branch/leaf schema before one
60
+ batched write. Empty branches are represented explicitly.
61
+
62
+ eraseFacade is opt-in. Omit a facade only if every use can lower to declared data
63
+ cells and no method/getter/escape/lifecycle/data boundary needs the object.
64
+
65
+ ## Runtime and tooling
66
+
67
+ Default imports use createStoreScope from @volynets/reflex-store/runtime and
68
+ createStoreCell from /runtime/internal. The compiler does not call createModel
69
+ or defineModel. The target delegates lifecycle policy to the shared Framework
70
+ package, and keeps host/runtime imports external. The Vite plugin preserves
71
+ application package resolution.
72
+
73
+ Custom data-only lowering targets configure scope/signal names and generated
74
+ identifiers. Scope targets return the constructed value directly; curried: true
75
+ supports factories returning a zero-argument constructor. The deprecated model
76
+ option remains an alias with curried: true for existing custom targets.
77
+ Getter/method lowering requires the default Store scope target.
78
+ The compiler includes portable SWC WASM and validates its normalized function AST
79
+ before printing. Names are store metadata and never modify kernel hot paths.
80
+
81
+ ## Diagnostics
82
+
83
+ Diagnose unsupported shapes and mutations before erasure. Collect mode returns
84
+ the original code when diagnostics exist. No partial transform is published for
85
+ an unsupported source module.