atom.io 0.4.0 → 0.5.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.
Files changed (59) hide show
  1. package/README.md +38 -10
  2. package/dist/index.d.mts +598 -0
  3. package/dist/index.d.ts +52 -14
  4. package/dist/index.js +143 -28
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +142 -28
  7. package/dist/index.mjs.map +1 -1
  8. package/json/dist/index.d.mts +18 -0
  9. package/json/dist/index.d.ts +18 -0
  10. package/json/dist/index.js +51 -0
  11. package/json/dist/index.js.map +1 -0
  12. package/json/dist/index.mjs +15 -0
  13. package/json/dist/index.mjs.map +1 -0
  14. package/json/package.json +15 -0
  15. package/package.json +35 -8
  16. package/react/dist/index.d.mts +17 -0
  17. package/react-devtools/dist/index.d.mts +15 -0
  18. package/react-devtools/dist/index.js +13 -10
  19. package/react-devtools/dist/index.js.map +1 -1
  20. package/react-devtools/dist/index.mjs +10 -7
  21. package/react-devtools/dist/index.mjs.map +1 -1
  22. package/realtime/dist/index.d.mts +25 -0
  23. package/realtime/dist/index.d.ts +25 -0
  24. package/realtime/dist/index.js +168 -0
  25. package/realtime/dist/index.js.map +1 -0
  26. package/realtime/dist/index.mjs +130 -0
  27. package/realtime/dist/index.mjs.map +1 -0
  28. package/realtime/package.json +15 -0
  29. package/src/index.ts +22 -0
  30. package/src/internal/atom-internal.ts +1 -1
  31. package/src/internal/families-internal.ts +3 -3
  32. package/src/internal/get.ts +22 -12
  33. package/src/internal/selector-internal.ts +10 -0
  34. package/src/internal/set.ts +1 -1
  35. package/src/internal/store.ts +1 -1
  36. package/src/internal/subscribe-internal.ts +5 -0
  37. package/src/internal/timeline-internal.ts +13 -1
  38. package/src/internal/transaction-internal.ts +24 -9
  39. package/src/json/index.ts +1 -0
  40. package/src/json/select-json.ts +18 -0
  41. package/src/react-devtools/TokenList.tsx +13 -5
  42. package/src/react-explorer/explorer-states.ts +5 -5
  43. package/src/react-explorer/index.ts +1 -1
  44. package/src/react-explorer/space-states.ts +6 -7
  45. package/src/realtime/hook-composition/expose-family.ts +101 -0
  46. package/src/realtime/hook-composition/expose-single.ts +38 -0
  47. package/src/realtime/hook-composition/index.ts +11 -0
  48. package/src/realtime/hook-composition/receive-transaction.ts +19 -0
  49. package/src/realtime/index.ts +1 -0
  50. package/src/realtime-client/hook-composition/compose-realtime-hooks.ts +62 -0
  51. package/src/realtime-client/hook-composition/realtime-client-family-member.ts +28 -0
  52. package/src/realtime-client/hook-composition/realtime-client-family.ts +26 -0
  53. package/src/realtime-client/hook-composition/realtime-client-single.ts +24 -0
  54. package/src/realtime-client/hook-composition/realtime-client-transaction.ts +35 -0
  55. package/src/realtime-client/index.ts +1 -0
  56. package/src/selector.ts +9 -6
  57. package/src/silo.ts +45 -0
  58. package/src/subscribe.ts +13 -1
  59. package/src/transaction.ts +13 -4
@@ -0,0 +1,18 @@
1
+ import * as AtomIO from 'atom.io';
2
+
3
+ type JsonInterface<T, J extends Json = Json> = {
4
+ toJson: (t: T) => J;
5
+ fromJson: (json: J) => T;
6
+ };
7
+
8
+ type Primitive = boolean | number | string | null;
9
+ type Serializable = Primitive | Readonly<{
10
+ [key: string]: Serializable;
11
+ }> | ReadonlyArray<Serializable>;
12
+ type JsonObj<Key extends string = string, Value extends Serializable = Serializable> = Record<Key, Value>;
13
+ type JsonArr<Element extends Serializable = Serializable> = ReadonlyArray<Element>;
14
+ type Json = JsonArr | JsonObj | Primitive;
15
+
16
+ declare const selectJson: <T, J extends Json>(atom: AtomIO.AtomToken<T>, transform: JsonInterface<T, J>, store?: AtomIO.Store) => AtomIO.SelectorToken<J>;
17
+
18
+ export { selectJson };
@@ -0,0 +1,18 @@
1
+ import * as AtomIO from 'atom.io';
2
+
3
+ type JsonInterface<T, J extends Json = Json> = {
4
+ toJson: (t: T) => J;
5
+ fromJson: (json: J) => T;
6
+ };
7
+
8
+ type Primitive = boolean | number | string | null;
9
+ type Serializable = Primitive | Readonly<{
10
+ [key: string]: Serializable;
11
+ }> | ReadonlyArray<Serializable>;
12
+ type JsonObj<Key extends string = string, Value extends Serializable = Serializable> = Record<Key, Value>;
13
+ type JsonArr<Element extends Serializable = Serializable> = ReadonlyArray<Element>;
14
+ type Json = JsonArr | JsonObj | Primitive;
15
+
16
+ declare const selectJson: <T, J extends Json>(atom: AtomIO.AtomToken<T>, transform: JsonInterface<T, J>, store?: AtomIO.Store) => AtomIO.SelectorToken<J>;
17
+
18
+ export { selectJson };
@@ -0,0 +1,51 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // ../src/json/index.ts
30
+ var json_exports = {};
31
+ __export(json_exports, {
32
+ selectJson: () => selectJson
33
+ });
34
+ module.exports = __toCommonJS(json_exports);
35
+
36
+ // ../src/json/select-json.ts
37
+ var AtomIO = __toESM(require("atom.io"));
38
+ var selectJson = (atom, transform, store = AtomIO.__INTERNAL__.IMPLICIT.STORE) => AtomIO.__INTERNAL__.selector__INTERNAL(
39
+ {
40
+ key: `${atom.key}JSON`,
41
+ get: ({ get }) => transform.toJson(get(atom)),
42
+ set: ({ set }, newValue) => set(atom, transform.fromJson(newValue))
43
+ },
44
+ void 0,
45
+ store
46
+ );
47
+ // Annotate the CommonJS export names for ESM import in node:
48
+ 0 && (module.exports = {
49
+ selectJson
50
+ });
51
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/json/index.ts","../../src/json/select-json.ts"],"sourcesContent":["export * from \"./select-json\"\n","import * as AtomIO from \"atom.io\"\n\nimport type { Json, JsonInterface } from \"~/packages/anvl/src/json\"\n\nexport const selectJson = <T, J extends Json>(\n atom: AtomIO.AtomToken<T>,\n transform: JsonInterface<T, J>,\n store: AtomIO.Store = AtomIO.__INTERNAL__.IMPLICIT.STORE\n): AtomIO.SelectorToken<J> =>\n AtomIO.__INTERNAL__.selector__INTERNAL(\n {\n key: `${atom.key}JSON`,\n get: ({ get }) => transform.toJson(get(atom)),\n set: ({ set }, newValue) => set(atom, transform.fromJson(newValue)),\n },\n undefined,\n store\n )\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,aAAwB;AAIjB,IAAM,aAAa,CACxB,MACA,WACA,QAA6B,oBAAa,SAAS,UAE5C,oBAAa;AAAA,EAClB;AAAA,IACE,KAAK,GAAG,KAAK;AAAA,IACb,KAAK,CAAC,EAAE,IAAI,MAAM,UAAU,OAAO,IAAI,IAAI,CAAC;AAAA,IAC5C,KAAK,CAAC,EAAE,IAAI,GAAG,aAAa,IAAI,MAAM,UAAU,SAAS,QAAQ,CAAC;AAAA,EACpE;AAAA,EACA;AAAA,EACA;AACF;","names":[]}
@@ -0,0 +1,15 @@
1
+ // ../src/json/select-json.ts
2
+ import * as AtomIO from "atom.io";
3
+ var selectJson = (atom, transform, store = AtomIO.__INTERNAL__.IMPLICIT.STORE) => AtomIO.__INTERNAL__.selector__INTERNAL(
4
+ {
5
+ key: `${atom.key}JSON`,
6
+ get: ({ get }) => transform.toJson(get(atom)),
7
+ set: ({ set }, newValue) => set(atom, transform.fromJson(newValue))
8
+ },
9
+ void 0,
10
+ store
11
+ );
12
+ export {
13
+ selectJson
14
+ };
15
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/json/select-json.ts"],"sourcesContent":["import * as AtomIO from \"atom.io\"\n\nimport type { Json, JsonInterface } from \"~/packages/anvl/src/json\"\n\nexport const selectJson = <T, J extends Json>(\n atom: AtomIO.AtomToken<T>,\n transform: JsonInterface<T, J>,\n store: AtomIO.Store = AtomIO.__INTERNAL__.IMPLICIT.STORE\n): AtomIO.SelectorToken<J> =>\n AtomIO.__INTERNAL__.selector__INTERNAL(\n {\n key: `${atom.key}JSON`,\n get: ({ get }) => transform.toJson(get(atom)),\n set: ({ set }, newValue) => set(atom, transform.fromJson(newValue)),\n },\n undefined,\n store\n )\n"],"mappings":";AAAA,YAAY,YAAY;AAIjB,IAAM,aAAa,CACxB,MACA,WACA,QAA6B,oBAAa,SAAS,UAE5C,oBAAa;AAAA,EAClB;AAAA,IACE,KAAK,GAAG,KAAK;AAAA,IACb,KAAK,CAAC,EAAE,IAAI,MAAM,UAAU,OAAO,IAAI,IAAI,CAAC;AAAA,IAC5C,KAAK,CAAC,EAAE,IAAI,GAAG,aAAa,IAAI,MAAM,UAAU,SAAS,QAAQ,CAAC;AAAA,EACpE;AAAA,EACA;AAAA,EACA;AACF;","names":[]}
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "atom.io-json",
3
+ "private": true,
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "module": "dist/index.mjs",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "browser": "./dist/index.mjs",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ }
14
+ }
15
+ }
package/package.json CHANGED
@@ -1,16 +1,20 @@
1
1
  {
2
2
  "name": "atom.io",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Reactive state graph for React, Preact, and vanilla",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "module": "dist/index.mjs",
8
8
  "files": [
9
9
  "dist",
10
+ "json/dist",
11
+ "json/package.json",
10
12
  "react/dist",
11
13
  "react/package.json",
12
14
  "react-devtools/dist",
13
15
  "react-devtools/package.json",
16
+ "realtime/dist",
17
+ "realtime/package.json",
14
18
  "src"
15
19
  ],
16
20
  "exports": {
@@ -21,6 +25,13 @@
21
25
  "import": "./dist/index.mjs",
22
26
  "require": "./dist/index.js"
23
27
  },
28
+ "./json/package.json": "./json/package.json",
29
+ "./json": {
30
+ "types": "./json/dist/index.d.ts",
31
+ "browser": "./json/dist/index.mjs",
32
+ "import": "./json/dist/index.mjs",
33
+ "require": "./json/dist/index.js"
34
+ },
24
35
  "./react/package.json": "./react/package.json",
25
36
  "./react": {
26
37
  "types": "./react/dist/index.d.ts",
@@ -34,17 +45,26 @@
34
45
  "browser": "./react-devtools/dist/index.mjs",
35
46
  "import": "./react-devtools/dist/index.mjs",
36
47
  "require": "./react-devtools/dist/index.js"
48
+ },
49
+ "./realtime/package.json": "./realtime/package.json",
50
+ "./realtime": {
51
+ "types": "./realtime/dist/index.d.ts",
52
+ "browser": "./realtime/dist/index.mjs",
53
+ "import": "./realtime/dist/index.mjs",
54
+ "require": "./realtime/dist/index.js"
37
55
  }
38
56
  },
39
57
  "scripts": {
40
- "build": "tsup && (cd react && tsup) && (cd react-devtools && tsup)",
41
- "lint": "eslint",
58
+ "build": "tsup & (cd json && tsup) & (cd react && tsup) & (cd react-devtools && tsup) & (cd realtime && tsup)",
59
+ "lint": "eslint ./**/*.ts{,x}",
42
60
  "test": "vitest",
43
61
  "test:once": "vitest run"
44
62
  },
45
63
  "peerDependencies": {
46
64
  "preact": ">=10.0.0",
47
- "react": ">=16.8.0"
65
+ "react": ">=16.8.0",
66
+ "socket.io": ">=4.0.0",
67
+ "socket.io-client": ">=4.0.0"
48
68
  },
49
69
  "peerDependenciesMeta": {
50
70
  "preact": {
@@ -52,6 +72,12 @@
52
72
  },
53
73
  "react": {
54
74
  "optional": true
75
+ },
76
+ "socket.io": {
77
+ "optional": true
78
+ },
79
+ "socket.io-client": {
80
+ "optional": true
55
81
  }
56
82
  },
57
83
  "dependencies": {
@@ -63,14 +89,15 @@
63
89
  "@testing-library/preact": "3.2.3",
64
90
  "@testing-library/react": "14.0.0",
65
91
  "@types/mock-fs": "4.13.1",
92
+ "eslint": "8.44.0",
66
93
  "mock-fs": "5.2.0",
67
- "preact": "10.15.0",
94
+ "preact": "10.15.1",
68
95
  "react": "18.2.0",
69
96
  "react-dom": "18.2.0",
70
- "react-router-dom": "6.11.2",
71
- "tsup": "6.7.0",
97
+ "react-router-dom": "6.14.1",
98
+ "tsup": "7.1.0",
72
99
  "vite-tsconfig-paths": "4.2.0",
73
- "vitest": "0.31.1"
100
+ "vitest": "0.32.4"
74
101
  },
75
102
  "repository": {
76
103
  "type": "git",
@@ -0,0 +1,17 @@
1
+ import { StateToken, ReadonlySelectorToken, __INTERNAL__ } from 'atom.io';
2
+
3
+ type Modifier<T> = (thing: T) => T;
4
+
5
+ type StoreHooks = {
6
+ useI: <T>(token: StateToken<T>) => (next: Modifier<T> | T) => void;
7
+ useO: <T>(token: ReadonlySelectorToken<T> | StateToken<T>) => T;
8
+ useIO: <T>(token: StateToken<T>) => [T, (next: Modifier<T> | T) => void];
9
+ };
10
+ declare const composeStoreHooks: (store?: __INTERNAL__.Store) => StoreHooks;
11
+ declare const useI: <T>(token: StateToken<T>) => (next: T | Modifier<T>) => void;
12
+ declare const useO: <T>(token: ReadonlySelectorToken<T> | StateToken<T>) => T;
13
+ declare const useIO: <T>(token: StateToken<T>) => [T, (next: T | Modifier<T>) => void];
14
+ declare function useStore<T>(token: StateToken<T>): [T, (next: Modifier<T> | T) => void];
15
+ declare function useStore<T>(token: ReadonlySelectorToken<T>): T;
16
+
17
+ export { StoreHooks, composeStoreHooks, useI, useIO, useO, useStore };
@@ -0,0 +1,15 @@
1
+ import { FC } from 'react';
2
+ import { StateToken, ReadonlySelectorToken } from 'atom.io';
3
+
4
+ type Modifier<T> = (thing: T) => T;
5
+
6
+ type StoreHooks = {
7
+ useI: <T>(token: StateToken<T>) => (next: Modifier<T> | T) => void;
8
+ useO: <T>(token: ReadonlySelectorToken<T> | StateToken<T>) => T;
9
+ useIO: <T>(token: StateToken<T>) => [T, (next: Modifier<T> | T) => void];
10
+ };
11
+
12
+ declare const composeDevtools: (storeHooks: StoreHooks) => FC;
13
+ declare const AtomIODevtools: FC;
14
+
15
+ export { AtomIODevtools, composeDevtools };
@@ -66,12 +66,13 @@ module.exports = __toCommonJS(react_devtools_exports);
66
66
 
67
67
  // ../src/react-devtools/AtomIODevtools.tsx
68
68
  var import_react7 = require("react");
69
- var import_atom = require("atom.io");
69
+ var import_atom2 = require("atom.io");
70
70
  var import_react8 = require("atom.io/react");
71
71
  var import_framer_motion = require("framer-motion");
72
72
 
73
73
  // ../src/react-devtools/TokenList.tsx
74
74
  var import_react6 = require("react");
75
+ var import_atom = require("atom.io");
75
76
 
76
77
  // ../../anvl/src/object/index.ts
77
78
  var import_function4 = require("fp-ts/function");
@@ -89,7 +90,7 @@ var recordToEntries = (obj) => Object.entries(obj);
89
90
  var entriesToRecord = (entries) => Object.fromEntries(entries);
90
91
 
91
92
  // ../../anvl/src/object/mapObject.ts
92
- var import_function = require("fp-ts/lib/function");
93
+ var import_function = require("fp-ts/function");
93
94
 
94
95
  // ../../anvl/src/array/index.ts
95
96
  var isArray = (isType) => (input) => Array.isArray(input) && input.every((item) => isType(item));
@@ -1456,15 +1457,17 @@ var StoreEditor = ({ storeHooks, token }) => {
1456
1457
  var import_jsx_runtime13 = require("@emotion/react/jsx-runtime");
1457
1458
  var TokenList = ({ storeHooks, tokenIndex }) => {
1458
1459
  const tokenIds = storeHooks.useO(tokenIndex);
1459
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_jsx_runtime13.Fragment, { children: Object.entries(tokenIds).map(([key, token]) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_react6.Fragment, { children: key.startsWith(`\u{1F441}\u200D\u{1F5E8}_`) ? null : /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "node", children: [
1460
- key,
1461
- ":",
1462
- `type` in token ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(StoreEditor, { storeHooks, token }) : recordToEntries(token.familyMembers).map(([key2, token2]) => /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "node", children: [
1460
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_jsx_runtime13.Fragment, { children: Object.entries(tokenIds).map(([key, token]) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_react6.Fragment, { children: key.startsWith(`\u{1F441}\u200D\u{1F5E8}_`) ? null : /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "node", children: `type` in token ? /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
1461
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("label", { onClick: () => console.log(token, (0, import_atom.getState)(token)), children: key }),
1462
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(StoreEditor, { storeHooks, token })
1463
+ ] }) : recordToEntries(token.familyMembers).map(([key2, token2]) => /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
1464
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("label", { children: key2 }),
1465
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "node", children: [
1463
1466
  key2,
1464
1467
  ":",
1465
1468
  /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(StoreEditor, { storeHooks, token: token2 })
1466
- ] }, key2))
1467
- ] }) }, key)) });
1469
+ ] }, key2)
1470
+ ] })) }) }, key)) });
1468
1471
  };
1469
1472
 
1470
1473
  // ../src/web-effects/storage.ts
@@ -1484,8 +1487,8 @@ var lazyLocalStorageEffect = persistAtom(localStorage)(JSON);
1484
1487
 
1485
1488
  // ../src/react-devtools/AtomIODevtools.tsx
1486
1489
  var import_jsx_runtime14 = require("@emotion/react/jsx-runtime");
1487
- var { atomTokenIndexState, selectorTokenIndexState } = import_atom.__INTERNAL__.META.attachMetaState();
1488
- var devtoolsAreOpenState = (0, import_atom.atom)({
1490
+ var { atomTokenIndexState, selectorTokenIndexState } = import_atom2.__INTERNAL__.META.attachMetaState();
1491
+ var devtoolsAreOpenState = (0, import_atom2.atom)({
1489
1492
  key: `\u{1F441}\u200D\u{1F5E8}_devtools_are_open`,
1490
1493
  default: true,
1491
1494
  effects: [lazyLocalStorageEffect(`\u{1F441}\u200D\u{1F5E8}_devtools_are_open`)]