@effect-atom/atom-livestore 0.1.9 → 0.1.10

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.
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.make = void 0;
6
+ exports.Tag = void 0;
7
7
  var Atom = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("@effect-atom/atom/Atom"));
8
8
  var Result = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("@effect-atom/atom/Result"));
9
9
  var _livestore = /*#__PURE__*/require("@livestore/livestore");
@@ -40,20 +40,20 @@ function _interopRequireWildcard(e, t) {
40
40
  * @since 1.0.0
41
41
  * @category Constructors
42
42
  */
43
- const make = options => {
44
- const StoreService = Context.GenericTag("@effect-atom/atom-livestore/StoreService");
45
- const layer = Layer.scoped(StoreService, (0, _livestore.createStore)(options).pipe((0, _livestore.provideOtel)({
43
+ const Tag = () => (id, options) => {
44
+ const self = Context.Tag(id)();
45
+ self.layer = Layer.scoped(self, (0, _livestore.createStore)(options).pipe((0, _livestore.provideOtel)({
46
46
  parentSpanContext: options?.otelOptions?.rootSpanContext,
47
47
  otelTracer: options?.otelOptions?.tracer
48
48
  }), Effect.orDie));
49
- const runtimeAtom = Atom.runtime(layer);
50
- const storeAtom = runtimeAtom.atom(StoreService);
51
- const storeAtomUnsafe = Atom.readable(get => {
52
- const result = get(storeAtom);
49
+ self.runtime = Atom.runtime(self.layer);
50
+ self.store = self.runtime.atom(self);
51
+ self.storeUnsafe = Atom.readable(get => {
52
+ const result = get(self.store);
53
53
  return Result.getOrElse(result, _Function.constUndefined);
54
54
  });
55
- const makeQueryAtom = query => Atom.readable(get => {
56
- const store = get(storeAtom);
55
+ self.makeQuery = query => Atom.readable(get => {
56
+ const store = get(self.store);
57
57
  return Result.map(store, store => {
58
58
  const result = store.query(query);
59
59
  get.addFinalizer(store.subscribe(query, {
@@ -64,8 +64,8 @@ const make = options => {
64
64
  return result;
65
65
  });
66
66
  });
67
- const makeQueryAtomUnsafe = query => Atom.readable(get => {
68
- const store = get(storeAtomUnsafe);
67
+ self.makeQueryUnsafe = query => Atom.readable(get => {
68
+ const store = get(self.storeUnsafe);
69
69
  if (store === undefined) {
70
70
  return undefined;
71
71
  }
@@ -76,21 +76,12 @@ const make = options => {
76
76
  }));
77
77
  return store.query(query);
78
78
  });
79
- const commitAtom = Atom.writable(get => {
80
- get(storeAtomUnsafe);
79
+ self.commit = Atom.writable(get => {
80
+ get(self.storeUnsafe);
81
81
  }, (ctx, value) => {
82
- ctx.get(storeAtomUnsafe)?.commit(value);
82
+ ctx.get(self.storeUnsafe)?.commit(value);
83
83
  });
84
- return {
85
- StoreService,
86
- layer,
87
- runtimeAtom,
88
- storeAtom,
89
- storeAtomUnsafe,
90
- makeQueryAtom,
91
- makeQueryAtomUnsafe,
92
- commitAtom
93
- };
84
+ return self;
94
85
  };
95
- exports.make = make;
86
+ exports.Tag = Tag;
96
87
  //# sourceMappingURL=AtomLivestore.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AtomLivestore.js","names":["Atom","_interopRequireWildcard","require","Result","_livestore","Context","Effect","_Function","Layer","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","make","options","StoreService","GenericTag","layer","scoped","createStore","pipe","provideOtel","parentSpanContext","otelOptions","rootSpanContext","otelTracer","tracer","orDie","runtimeAtom","runtime","storeAtom","atom","storeAtomUnsafe","readable","result","getOrElse","constUndefined","makeQueryAtom","query","store","map","addFinalizer","subscribe","onUpdate","value","setSelf","success","makeQueryAtomUnsafe","undefined","commitAtom","writable","ctx","commit","exports"],"sources":["../../src/AtomLivestore.ts"],"sourcesContent":[null],"mappings":";;;;;;AAIA,IAAAA,IAAA,gBAAAC,uBAAA,cAAAC,OAAA;AACA,IAAAC,MAAA,gBAAAF,uBAAA,cAAAC,OAAA;AA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,CAAC;QACpC;OACD,CAAC,CACH;MACD,OAAOV,MAAM;IACf,CAAC,CAAC;EACJ,CAAC,CAAC;EACJ,MAAMa,mBAAmB,GAAOT,KAAsB,IACpDrD,IAAI,CAACgD,QAAQ,CAAE3B,GAAG,IAAI;IACpB,MAAMiC,KAAK,GAAGjC,GAAG,CAAC0B,eAAe,CAAC;IAClC,IAAIO,KAAK,KAAKS,SAAS,EAAE;MACvB,OAAOA,SAAS;IAClB;IACA1C,GAAG,CAACmC,YAAY,CACdF,KAAK,CAACG,SAAS,CAACJ,KAAK,EAAE;MACrBK,QAAQA,CAACC,KAAK;QACZtC,GAAG,CAACuC,OAAO,CAACzD,MAAM,CAAC0D,OAAO,CAACF,KAAK,CAAC,CAAC;MACpC;KACD,CAAC,CACH;IACD,OAAOL,KAAK,CAACD,KAAK,CAACA,KAAK,CAAC;EAC3B,CAAC,CAAC;EACJ,MAAMW,UAAU,GAAGhE,IAAI,CAACiE,QAAQ,CAAE5C,GAAG,IAAI;IACvCA,GAAG,CAAC0B,eAAe,CAAC;EACtB,CAAC,EAAE,CAACmB,GAAG,EAAEP,KAAS,KAAI;IACpBO,GAAG,CAAC7C,GAAG,CAAC0B,eAAe,CAAC,EAAEoB,MAAM,CAACR,KAAK,CAAC;EACzC,CAAC,CAAC;EACF,OAAO;IACL7B,YAAY;IACZE,KAAK;IACLW,WAAW;IACXE,SAAS;IACTE,eAAe;IACfK,aAAa;IACbU,mBAAmB;IACnBE;GACQ;AACZ,CAAC;AAAAI,OAAA,CAAAxC,IAAA,GAAAA,IAAA","ignoreList":[]}
1
+ {"version":3,"file":"AtomLivestore.js","names":["Atom","_interopRequireWildcard","require","Result","_livestore","Context","Effect","_Function","Layer","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","Tag","id","options","self","layer","scoped","createStore","pipe","provideOtel","parentSpanContext","otelOptions","rootSpanContext","otelTracer","tracer","orDie","runtime","store","atom","storeUnsafe","readable","result","getOrElse","constUndefined","makeQuery","query","map","addFinalizer","subscribe","onUpdate","value","setSelf","success","makeQueryUnsafe","undefined","commit","writable","ctx","exports"],"sources":["../../src/AtomLivestore.ts"],"sourcesContent":[null],"mappings":";;;;;;AAIA,IAAAA,IAAA,gBAAAC,uBAAA,cAAAC,OAAA;AACA,IAAAC,MAAA,gBAAAF,uBAAA,cAAAC,OAAA;AAEA,IAAAE,UAAA,gBAAAF,OAAA;AACA,IAAAG,OAAA,gBAAAJ,uBAAA,cAAAC,OAAA;AACA,IAAAI,MAAA,gBAAAL,uBAAA,cAAAC,OAAA;AACA,IAAAK,SAAA,gBAAAL,OAAA;AACA,IAAAM,KAAA,gBAAAP,uBAAA,cAAAC,OAAA;AAAqC,SAAAD,wBAAAQ,CAAA,EAAAC,CAAA;EAAA,yBAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA;IAAAE,CAAA,OAAAF,OAAA;EAAA,QAAAV,uBAAA,YAAAA,CAAAQ,CAAA,EAAAC,CAAA;IAAA,KAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA;IAAA,IAAAM,CAAA;MAAAC,CAAA;MAAAC,CAAA;QAAAC,SAAA;QAAAC,OAAA,EAAAV;MAAA;IAAA,aAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA;IAAA,IAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA;MAAA,IAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA;MAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA;IAAA;IAAA,WAAAP,CAAA,IAAAD,CAAA,gBAAAC,CAAA,OAAAa,cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAC,CAAA,OAAAM,CAAA,IAAAD,CAAA,GAAAU,MAAA,CAAAC,cAAA,KAAAD,MAAA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C;EACF,OAAO1B,IAA2C;AACpD,CAAC;AAAAkC,OAAA,CAAArC,GAAA,GAAAA,GAAA","ignoreList":[]}
@@ -8,53 +8,47 @@ import * as Context from "effect/Context";
8
8
  import * as Layer from "effect/Layer";
9
9
  /**
10
10
  * @since 1.0.0
11
- * @category Store
11
+ * @category Models
12
12
  */
13
- export interface StoreService {
14
- readonly _: unique symbol;
15
- }
16
- /**
17
- * @since 1.0.0
18
- * @category Constructors
19
- */
20
- export declare const make: <S extends LiveStoreSchema, Context = {}>(options: CreateStoreOptions<S, Context> & {
21
- readonly otelOptions?: Partial<OtelOptions> | undefined;
22
- }) => {
23
- /**
24
- * A context tag for the Store.
25
- */
26
- readonly StoreService: Context.Tag<StoreService, Store<S, Context>>;
27
- /**
28
- * The Layer that builds the Store
29
- */
30
- readonly layer: Layer.Layer<StoreService>;
31
- /**
32
- * A Atom.runtime that contains the Store.
33
- */
34
- readonly runtimeAtom: Atom.AtomRuntime<StoreService, never>;
13
+ export interface AtomLiveStore<Self, Id extends string, S extends LiveStoreSchema, Context = {}> extends Context.Tag<Self, Store<S, Context>> {
14
+ new (_: never): Context.TagClassShape<Id, Store<S, Context>>;
15
+ readonly layer: Layer.Layer<Self>;
16
+ readonly runtime: Atom.AtomRuntime<Self>;
35
17
  /**
36
18
  * A Atom that allows you to access the Store. It will emit a `Result` that
37
19
  * contains the Store or an error if it could not be created.
38
20
  */
39
- readonly storeAtom: Atom.Atom<Result.Result<Store<S, Context>>>;
21
+ readonly store: Atom.Atom<Result.Result<Store<S, Context>>>;
40
22
  /**
41
23
  * A Atom that allows you to access the Store. It will emit the Store or
42
24
  * `undefined` if has not been created yet.
43
25
  */
44
- readonly storeAtomUnsafe: Atom.Atom<Store<S, Context> | undefined>;
26
+ readonly storeUnsafe: Atom.Atom<Store<S, Context> | undefined>;
45
27
  /**
46
28
  * Creates a Atom that allows you to resolve a LiveQueryDef. It embeds the loading
47
29
  * of the Store and will emit a `Result` that contains the result of the query
48
30
  */
49
- readonly makeQueryAtom: <A>(query: LiveQueryDef<A>) => Atom.Atom<Result.Result<A>>;
31
+ readonly makeQuery: <A>(query: LiveQueryDef<A>) => Atom.Atom<Result.Result<A>>;
50
32
  /**
51
33
  * Creates a Atom that allows you to resolve a LiveQueryDef. If the Store has
52
34
  * not been created yet, it will return `undefined`.
53
35
  */
54
- readonly makeQueryAtomUnsafe: <A>(query: LiveQueryDef<A>) => Atom.Atom<A | undefined>;
36
+ readonly makeQueryUnsafe: <A>(query: LiveQueryDef<A>) => Atom.Atom<A | undefined>;
55
37
  /**
56
38
  * A Atom.Writable that allows you to commit an event to the Store.
57
39
  */
58
- readonly commitAtom: Atom.Writable<void, {}>;
59
- };
40
+ readonly commit: Atom.Writable<void, {}>;
41
+ }
42
+ declare global {
43
+ interface ErrorConstructor {
44
+ stackTraceLimit: number;
45
+ }
46
+ }
47
+ /**
48
+ * @since 1.0.0
49
+ * @category Constructors
50
+ */
51
+ export declare const Tag: <Self>() => <const Id extends string, S extends LiveStoreSchema, Context = {}>(id: Id, options: CreateStoreOptions<S, Context> & {
52
+ readonly otelOptions?: Partial<OtelOptions> | undefined;
53
+ }) => AtomLiveStore<Self, Id, S, Context>;
60
54
  //# sourceMappingURL=AtomLivestore.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AtomLivestore.d.ts","sourceRoot":"","sources":["../../src/AtomLivestore.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAA;AAC9C,OAAO,KAAK,MAAM,MAAM,0BAA0B,CAAA;AAClD,OAAO,KAAK,EAAE,kBAAkB,EAAE,YAAY,EAAE,eAAe,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAEjH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AAGzC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,CAAC,E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AAQ,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;IAC9E;;;OAGG;IACH,QAAQ,CAAC,eAAe,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,CAAC,CAAA;IACjF;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;CACzC;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,gBAAgB;QACxB,eAAe,EAAE,MAAM,CAAA;KACxB;CACF;AAED;;;GAGG;AACH,eAAO,MAAM,GAAG,GAAI,IAAI,QACvB,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC,SAAS,eAAe,EAAE,OAAO,GAAG,EAAE,EAC/D,IAAI,EAAE,EACN,SAAS,kBAAkB,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG;IACxC,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,SAAS,CAAA;CACxD,KACA,aAAa,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC,EAAE,OAAO,CAuDpC,CAAA"}
@@ -13,20 +13,20 @@ import * as Layer from "effect/Layer";
13
13
  * @since 1.0.0
14
14
  * @category Constructors
15
15
  */
16
- export const make = options => {
17
- const StoreService = Context.GenericTag("@effect-atom/atom-livestore/StoreService");
18
- const layer = Layer.scoped(StoreService, createStore(options).pipe(provideOtel({
16
+ export const Tag = () => (id, options) => {
17
+ const self = Context.Tag(id)();
18
+ self.layer = Layer.scoped(self, createStore(options).pipe(provideOtel({
19
19
  parentSpanContext: options?.otelOptions?.rootSpanContext,
20
20
  otelTracer: options?.otelOptions?.tracer
21
21
  }), Effect.orDie));
22
- const runtimeAtom = Atom.runtime(layer);
23
- const storeAtom = runtimeAtom.atom(StoreService);
24
- const storeAtomUnsafe = Atom.readable(get => {
25
- const result = get(storeAtom);
22
+ self.runtime = Atom.runtime(self.layer);
23
+ self.store = self.runtime.atom(self);
24
+ self.storeUnsafe = Atom.readable(get => {
25
+ const result = get(self.store);
26
26
  return Result.getOrElse(result, constUndefined);
27
27
  });
28
- const makeQueryAtom = query => Atom.readable(get => {
29
- const store = get(storeAtom);
28
+ self.makeQuery = query => Atom.readable(get => {
29
+ const store = get(self.store);
30
30
  return Result.map(store, store => {
31
31
  const result = store.query(query);
32
32
  get.addFinalizer(store.subscribe(query, {
@@ -37,8 +37,8 @@ export const make = options => {
37
37
  return result;
38
38
  });
39
39
  });
40
- const makeQueryAtomUnsafe = query => Atom.readable(get => {
41
- const store = get(storeAtomUnsafe);
40
+ self.makeQueryUnsafe = query => Atom.readable(get => {
41
+ const store = get(self.storeUnsafe);
42
42
  if (store === undefined) {
43
43
  return undefined;
44
44
  }
@@ -49,20 +49,11 @@ export const make = options => {
49
49
  }));
50
50
  return store.query(query);
51
51
  });
52
- const commitAtom = Atom.writable(get => {
53
- get(storeAtomUnsafe);
52
+ self.commit = Atom.writable(get => {
53
+ get(self.storeUnsafe);
54
54
  }, (ctx, value) => {
55
- ctx.get(storeAtomUnsafe)?.commit(value);
55
+ ctx.get(self.storeUnsafe)?.commit(value);
56
56
  });
57
- return {
58
- StoreService,
59
- layer,
60
- runtimeAtom,
61
- storeAtom,
62
- storeAtomUnsafe,
63
- makeQueryAtom,
64
- makeQueryAtomUnsafe,
65
- commitAtom
66
- };
57
+ return self;
67
58
  };
68
59
  //# sourceMappingURL=AtomLivestore.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AtomLivestore.js","names":["Atom","Result","createStore","provideOtel","Context","Effect","constUndefined","Layer","make","options","StoreService","GenericTag","layer","scoped","pipe","parentSpanContext","otelOptions","rootSpanContext","otelTracer","tracer","orDie","runtimeAtom","runtime","storeAtom","atom","storeAtomUnsafe","readable","get","result","getOrElse","makeQueryAtom","query","store","map","addFinalizer","subscribe","onUpdate","value","setSelf","success","makeQueryAtomUnsafe","undefined","commitAtom","writable","ctx","commit"],"sources":["../../src/AtomLivestore.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA;AACA,OAAO,KAAKA,IAAI,MAAM,wBAAwB;AAC9C,OAAO,KAAKC,MAAM,MAAM,0BAA0B;AAElD,SAASC,WAAW,EAAEC,WAAW,QAAQ,sBAAsB;AAC/D,OAAO,KAAKC,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,SAASC,cAAc,QAAQ,iBAAiB;AAChD,OAAO,KAAKC,KAAK,MAAM,cAAc;AAUrC;;;;AAIA,OAAO,MAAMC,IAAI,GACfC,OAEC,IAsCC;EACF,MAAMC,YAAY,GAAGN,OAAO,CAACO,UAAU,CAAkC,0CAA0C,CAAC;EACpH,MAAMC,KAAK,GAAGL,KAAK,CAACM,MAAM,CACxBH,YAAY,EACZR,WAAW,CAACO,OAAO,CAAC,CAACK,IAAI,CACvBX,WAAW,CAAC;IACVY,iBAAiB,EAAEN,OAAO,EAAEO,WAAW,EAAEC,eAAe;IACxDC,UAAU,EAAET,OAAO,EAAEO,WAAW,EAAEG;GACnC,CAAC,EACFd,MAAM,CAACe,KAAK,CACb,CACF;EACD,MAAMC,WAAW,GAAGrB,IAAI,CAACsB,OAAO,CAACV,KAAK,CAAC;EACvC,MAAMW,SAAS,GAAGF,WAAW,CAACG,IAAI,CAACd,YAAY,CAAC;EAChD,MAAMe,eAAe,GAAGzB,IAAI,CAAC0B,QAAQ,CAAEC,GAAG,IAAI;IAC5C,MAAMC,MAAM,GAAGD,GAAG,CAACJ,SAAS,CAAC;IAC7B,OAAOtB,MAAM,CAAC4B,SAAS,CAACD,MAAM,EAAEtB,cAAc,CAAC;EACjD,CAAC,CAAC;EACF,MAAMwB,aAAa,GAAOC,KAAsB,IAC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SAAS;IACTE,eAAe;IACfK,aAAa;IACbU,mBAAmB;IACnBE;GACQ;AACZ,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"AtomLivestore.js","names":["Atom","Result","createStore","provideOtel","Context","Effect","constUndefined","Layer","Tag","id","options","self","layer","scoped","pipe","parentSpanContext","otelOptions","rootSpanContext","otelTracer","tracer","orDie","runtime","store","atom","storeUnsafe","readable","get","result","getOrElse","makeQuery","query","map","addFinalizer","subscribe","onUpdate","value","setSelf","success","makeQueryUnsafe","undefined","commit","writable","ctx"],"sources":["../../src/AtomLivestore.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA;AACA,OAAO,KAAKA,IAAI,MAAM,wBAAwB;AAC9C,OAAO,KAAKC,MAAM,MAAM,0BAA0B;AAElD,SAASC,WAAW,EAAEC,WAAW,QAAQ,sBAAsB;AAC/D,OAAO,KAAKC,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,SAASC,cAAc,QAAQ,iBAAiB;AAChD,OAAO,KAAKC,KAAK,MAAM,cAAc;AAiDrC;;;;AAIA,OAAO,MAAMC,GAAG,GAAGA,CAAA,KACnB,CACEC,EAAM,EACNC,OAEC,KACsC;EACvC,MAAMC,IAAI,GAAiDP,OAAO,CAACI,GAAG,CAACC,EAAE,CAAC,EAAkC;EAE5GE,IAAI,CAACC,KAAK,GAAGL,KAAK,CAACM,MAAM,CACvBF,IAAI,EACJT,WAAW,CAACQ,OAAO,CAAC,CAACI,IAAI,CACvBX,WAAW,CAAC;IACVY,iBAAiB,EAAEL,OAAO,EAAEM,WAAW,EAAEC,eAAe;IACxDC,UAAU,EAAER,OAAO,EAAEM,WAAW,EAAEG;GACnC,CAAC,EACFd,MAAM,CAACe,KAAK,CACb,CACF;EACDT,IAAI,CAACU,OAAO,GAAGrB,IAAI,CAACqB,OAAO,CAACV,IAAI,CAACC,KAAK,CAAC;EACvCD,IAAI,CAACW,KAAK,GAAGX,IAAI,CAACU,OAA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K,CAAC;EAC3B,CAAC,CAAC;EACJnB,IAAI,CAAC6B,MAAM,GAAGxC,IAAI,CAACyC,QAAQ,CAAEf,GAAG,IAAI;IAClCA,GAAG,CAACf,IAAI,CAACa,WAAW,CAAC;EACvB,CAAC,EAAE,CAACkB,GAAG,EAAEP,KAAS,KAAI;IACpBO,GAAG,CAAChB,GAAG,CAACf,IAAI,CAACa,WAAW,CAAC,EAAEgB,MAAM,CAACL,KAAK,CAAC;EAC1C,CAAC,CAAC;EACF,OAAOxB,IAA2C;AACpD,CAAC","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect-atom/atom-livestore",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "description": "effect-atom bindings to livestore",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -11,7 +11,7 @@
11
11
  "author": "Effect contributors",
12
12
  "homepage": "https://github.com/tim-smart/effect-atom",
13
13
  "dependencies": {
14
- "@effect-atom/atom": "^0.1.11"
14
+ "@effect-atom/atom": "^0.1.12"
15
15
  },
16
16
  "peerDependencies": {
17
17
  "@livestore/livestore": "*",
@@ -10,64 +10,69 @@ import * as Context from "effect/Context"
10
10
  import * as Effect from "effect/Effect"
11
11
  import { constUndefined } from "effect/Function"
12
12
  import * as Layer from "effect/Layer"
13
+ import type { Mutable } from "effect/Types"
13
14
 
14
15
  /**
15
16
  * @since 1.0.0
16
- * @category Store
17
+ * @category Models
17
18
  */
18
- export interface StoreService {
19
- readonly _: unique symbol
20
- }
19
+ export interface AtomLiveStore<Self, Id extends string, S extends LiveStoreSchema, Context = {}>
20
+ extends Context.Tag<Self, Store<S, Context>>
21
+ {
22
+ new(
23
+ _: never
24
+ ): Context.TagClassShape<Id, Store<S, Context>>
25
+
26
+ readonly layer: Layer.Layer<Self>
27
+ readonly runtime: Atom.AtomRuntime<Self>
21
28
 
22
- /**
23
- * @since 1.0.0
24
- * @category Constructors
25
- */
26
- export const make = <S extends LiveStoreSchema, Context = {}>(
27
- options: CreateStoreOptions<S, Context> & {
28
- readonly otelOptions?: Partial<OtelOptions> | undefined
29
- }
30
- ): {
31
- /**
32
- * A context tag for the Store.
33
- */
34
- readonly StoreService: Context.Tag<StoreService, Store<S, Context>>
35
- /**
36
- * The Layer that builds the Store
37
- */
38
- readonly layer: Layer.Layer<StoreService>
39
- /**
40
- * A Atom.runtime that contains the Store.
41
- */
42
- readonly runtimeAtom: Atom.AtomRuntime<StoreService, never>
43
29
  /**
44
30
  * A Atom that allows you to access the Store. It will emit a `Result` that
45
31
  * contains the Store or an error if it could not be created.
46
32
  */
47
- readonly storeAtom: Atom.Atom<Result.Result<Store<S, Context>>>
33
+ readonly store: Atom.Atom<Result.Result<Store<S, Context>>>
48
34
  /**
49
35
  * A Atom that allows you to access the Store. It will emit the Store or
50
36
  * `undefined` if has not been created yet.
51
37
  */
52
- readonly storeAtomUnsafe: Atom.Atom<Store<S, Context> | undefined>
38
+ readonly storeUnsafe: Atom.Atom<Store<S, Context> | undefined>
53
39
  /**
54
40
  * Creates a Atom that allows you to resolve a LiveQueryDef. It embeds the loading
55
41
  * of the Store and will emit a `Result` that contains the result of the query
56
42
  */
57
- readonly makeQueryAtom: <A>(query: LiveQueryDef<A>) => Atom.Atom<Result.Result<A>>
43
+ readonly makeQuery: <A>(query: LiveQueryDef<A>) => Atom.Atom<Result.Result<A>>
58
44
  /**
59
45
  * Creates a Atom that allows you to resolve a LiveQueryDef. If the Store has
60
46
  * not been created yet, it will return `undefined`.
61
47
  */
62
- readonly makeQueryAtomUnsafe: <A>(query: LiveQueryDef<A>) => Atom.Atom<A | undefined>
48
+ readonly makeQueryUnsafe: <A>(query: LiveQueryDef<A>) => Atom.Atom<A | undefined>
63
49
  /**
64
50
  * A Atom.Writable that allows you to commit an event to the Store.
65
51
  */
66
- readonly commitAtom: Atom.Writable<void, {}>
67
- } => {
68
- const StoreService = Context.GenericTag<StoreService, Store<S, Context>>("@effect-atom/atom-livestore/StoreService")
69
- const layer = Layer.scoped(
70
- StoreService,
52
+ readonly commit: Atom.Writable<void, {}>
53
+ }
54
+
55
+ declare global {
56
+ interface ErrorConstructor {
57
+ stackTraceLimit: number
58
+ }
59
+ }
60
+
61
+ /**
62
+ * @since 1.0.0
63
+ * @category Constructors
64
+ */
65
+ export const Tag = <Self>() =>
66
+ <const Id extends string, S extends LiveStoreSchema, Context = {}>(
67
+ id: Id,
68
+ options: CreateStoreOptions<S, Context> & {
69
+ readonly otelOptions?: Partial<OtelOptions> | undefined
70
+ }
71
+ ): AtomLiveStore<Self, Id, S, Context> => {
72
+ const self: Mutable<AtomLiveStore<Self, Id, S, Context>> = Context.Tag(id)<Self, Store<S, Context>>() as any
73
+
74
+ self.layer = Layer.scoped(
75
+ self,
71
76
  createStore(options).pipe(
72
77
  provideOtel({
73
78
  parentSpanContext: options?.otelOptions?.rootSpanContext,
@@ -76,15 +81,15 @@ export const make = <S extends LiveStoreSchema, Context = {}>(
76
81
  Effect.orDie
77
82
  )
78
83
  )
79
- const runtimeAtom = Atom.runtime(layer)
80
- const storeAtom = runtimeAtom.atom(StoreService)
81
- const storeAtomUnsafe = Atom.readable((get) => {
82
- const result = get(storeAtom)
84
+ self.runtime = Atom.runtime(self.layer)
85
+ self.store = self.runtime.atom(self)
86
+ self.storeUnsafe = Atom.readable((get) => {
87
+ const result = get(self.store)
83
88
  return Result.getOrElse(result, constUndefined)
84
89
  })
85
- const makeQueryAtom = <A>(query: LiveQueryDef<A>) =>
90
+ self.makeQuery = <A>(query: LiveQueryDef<A>) =>
86
91
  Atom.readable((get) => {
87
- const store = get(storeAtom)
92
+ const store = get(self.store)
88
93
  return Result.map(store, (store) => {
89
94
  const result = store.query(query)
90
95
  get.addFinalizer(
@@ -97,9 +102,9 @@ export const make = <S extends LiveStoreSchema, Context = {}>(
97
102
  return result
98
103
  })
99
104
  })
100
- const makeQueryAtomUnsafe = <A>(query: LiveQueryDef<A>) =>
105
+ self.makeQueryUnsafe = <A>(query: LiveQueryDef<A>) =>
101
106
  Atom.readable((get) => {
102
- const store = get(storeAtomUnsafe)
107
+ const store = get(self.storeUnsafe)
103
108
  if (store === undefined) {
104
109
  return undefined
105
110
  }
@@ -112,19 +117,10 @@ export const make = <S extends LiveStoreSchema, Context = {}>(
112
117
  )
113
118
  return store.query(query)
114
119
  })
115
- const commitAtom = Atom.writable((get) => {
116
- get(storeAtomUnsafe)
120
+ self.commit = Atom.writable((get) => {
121
+ get(self.storeUnsafe)
117
122
  }, (ctx, value: {}) => {
118
- ctx.get(storeAtomUnsafe)?.commit(value)
123
+ ctx.get(self.storeUnsafe)?.commit(value)
119
124
  })
120
- return {
121
- StoreService,
122
- layer,
123
- runtimeAtom,
124
- storeAtom,
125
- storeAtomUnsafe,
126
- makeQueryAtom,
127
- makeQueryAtomUnsafe,
128
- commitAtom
129
- } as const
125
+ return self as AtomLiveStore<Self, Id, S, Context>
130
126
  }