@livestore/utils 0.0.12 → 0.0.14

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 (88) hide show
  1. package/dist/.tsbuildinfo.json +1 -0
  2. package/dist/Deferred.d.ts +10 -0
  3. package/dist/Deferred.d.ts.map +1 -0
  4. package/dist/Deferred.js +18 -0
  5. package/dist/Deferred.js.map +1 -0
  6. package/dist/NoopTracer.d.ts +10 -0
  7. package/dist/NoopTracer.d.ts.map +1 -0
  8. package/dist/NoopTracer.js +54 -0
  9. package/dist/NoopTracer.js.map +1 -0
  10. package/dist/base64.d.ts +12 -0
  11. package/dist/base64.d.ts.map +1 -0
  12. package/dist/base64.js +114 -0
  13. package/dist/base64.js.map +1 -0
  14. package/dist/browser.d.ts +3 -0
  15. package/dist/browser.d.ts.map +1 -0
  16. package/dist/browser.js +28 -0
  17. package/dist/browser.js.map +1 -0
  18. package/dist/effect/Effect.d.ts +11 -0
  19. package/dist/effect/Effect.d.ts.map +1 -0
  20. package/dist/effect/Effect.js +23 -0
  21. package/dist/effect/Effect.js.map +1 -0
  22. package/dist/effect/Error.d.ts +13 -0
  23. package/dist/effect/Error.d.ts.map +1 -0
  24. package/dist/effect/Error.js +13 -0
  25. package/dist/effect/Error.js.map +1 -0
  26. package/dist/effect/Schedule.d.ts +4 -0
  27. package/dist/effect/Schedule.d.ts.map +1 -0
  28. package/dist/effect/Schedule.js +5 -0
  29. package/dist/effect/Schedule.js.map +1 -0
  30. package/dist/effect/ServiceContext.d.ts +37 -0
  31. package/dist/effect/ServiceContext.d.ts.map +1 -0
  32. package/dist/effect/ServiceContext.js +55 -0
  33. package/dist/effect/ServiceContext.js.map +1 -0
  34. package/dist/effect/index.d.ts +9 -0
  35. package/dist/effect/index.d.ts.map +1 -0
  36. package/dist/effect/index.js +9 -0
  37. package/dist/effect/index.js.map +1 -0
  38. package/dist/global.d.ts +5 -0
  39. package/dist/global.d.ts.map +1 -0
  40. package/dist/global.js +2 -0
  41. package/dist/global.js.map +1 -0
  42. package/dist/guards.d.ts +6 -0
  43. package/dist/guards.d.ts.map +1 -0
  44. package/dist/guards.js +6 -0
  45. package/dist/guards.js.map +1 -0
  46. package/dist/index.d.ts +69 -0
  47. package/dist/index.d.ts.map +1 -0
  48. package/dist/index.js +158 -0
  49. package/dist/index.js.map +1 -0
  50. package/dist/object/index.d.ts +10 -0
  51. package/dist/object/index.d.ts.map +1 -0
  52. package/dist/object/index.js +10 -0
  53. package/dist/object/index.js.map +1 -0
  54. package/dist/object/omit.d.ts +3 -0
  55. package/dist/object/omit.d.ts.map +1 -0
  56. package/dist/object/omit.js +14 -0
  57. package/dist/object/omit.js.map +1 -0
  58. package/dist/object/pick.d.ts +14 -0
  59. package/dist/object/pick.d.ts.map +1 -0
  60. package/dist/object/pick.js +17 -0
  61. package/dist/object/pick.js.map +1 -0
  62. package/dist/promise.d.ts +6 -0
  63. package/dist/promise.d.ts.map +1 -0
  64. package/dist/promise.js +27 -0
  65. package/dist/promise.js.map +1 -0
  66. package/dist/set.d.ts +2 -0
  67. package/dist/set.d.ts.map +1 -0
  68. package/dist/set.js +10 -0
  69. package/dist/set.js.map +1 -0
  70. package/dist/string.d.ts +3 -0
  71. package/dist/string.d.ts.map +1 -0
  72. package/dist/string.js +3 -0
  73. package/dist/string.js.map +1 -0
  74. package/dist/time.d.ts +12 -0
  75. package/dist/time.d.ts.map +1 -0
  76. package/dist/time.js +22 -0
  77. package/dist/time.js.map +1 -0
  78. package/package.json +16 -18
  79. package/src/effect/Effect.ts +3 -5
  80. package/src/effect/Error.ts +5 -2
  81. package/src/effect/Schedule.ts +2 -4
  82. package/src/effect/ServiceContext.ts +2 -8
  83. package/src/effect/index.ts +47 -58
  84. package/src/global.ts +1 -1
  85. package/src/index.ts +12 -14
  86. package/src/object/index.ts +1 -1
  87. package/tsconfig.json +2 -5
  88. package/src/effect/Layer.ts +0 -42
@@ -0,0 +1,3 @@
1
+ /** Returns a shallowly cloned object with the provided keys omitted */
2
+ export declare const omit: <Obj extends Record<string, any>, Keys extends keyof Obj>(obj: Obj, keys: Keys[]) => Omit<Obj, Keys>;
3
+ //# sourceMappingURL=omit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"omit.d.ts","sourceRoot":"","sources":["../../src/object/omit.ts"],"names":[],"mappings":"AAKA,uEAAuE;AACvE,eAAO,MAAM,IAAI,sGAUhB,CAAA"}
@@ -0,0 +1,14 @@
1
+ // type ConvertUndefined<T> = OrUndefined<{ [K in keyof T as undefined extends T[K] ? K : never]-?: T[K] }>
2
+ // type OrUndefined<T> = { [K in keyof T]: T[K] | undefined }
3
+ // type PickRequired<T> = { [K in keyof T as undefined extends T[K] ? never : K]: T[K] }
4
+ // type ConvertPick<T> = ConvertUndefined<T> & PickRequired<T>
5
+ /** Returns a shallowly cloned object with the provided keys omitted */
6
+ export const omit = (obj, keys) => {
7
+ return Object.keys(obj).reduce((acc, key) => {
8
+ if (!keys.includes(key)) {
9
+ acc[key] = obj[key];
10
+ }
11
+ return acc;
12
+ }, {});
13
+ };
14
+ //# sourceMappingURL=omit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"omit.js","sourceRoot":"","sources":["../../src/object/omit.ts"],"names":[],"mappings":"AAAA,2GAA2G;AAC3G,6DAA6D;AAC7D,wFAAwF;AACxF,8DAA8D;AAE9D,uEAAuE;AACvE,MAAM,CAAC,MAAM,IAAI,GAAG,CAClB,GAAQ,EACR,IAAY,EACK,EAAE;IACnB,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAQ,EAAE,EAAE;QAC/C,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;YACvB,GAAG,CAAC,GAAG,CAAC,GAAI,GAAW,CAAC,GAAG,CAAC,CAAA;SAC7B;QACD,OAAO,GAAG,CAAA;IACZ,CAAC,EAAE,EAAS,CAAC,CAAA;AACf,CAAC,CAAA"}
@@ -0,0 +1,14 @@
1
+ type ConvertUndefined<T> = OrUndefined<{
2
+ [K in keyof T as undefined extends T[K] ? K : never]-?: T[K];
3
+ }>;
4
+ type OrUndefined<T> = {
5
+ [K in keyof T]: T[K] | undefined;
6
+ };
7
+ type PickRequired<T> = {
8
+ [K in keyof T as undefined extends T[K] ? never : K]: T[K];
9
+ };
10
+ type ConvertPick<T> = ConvertUndefined<T> & PickRequired<T>;
11
+ export declare const pick: <Obj, Keys extends keyof Obj>(obj: Obj, keys: Keys[]) => ConvertPick<{ [K in Keys]: Obj[K]; }>;
12
+ export declare const pickAllOrElse: <Obj, Keys extends keyof Obj, TElse>(obj: Obj, keys: Keys[], elseValue: TElse) => TElse | ConvertPick<{ [K in Keys]: NonNullable<Obj[K]>; }>;
13
+ export {};
14
+ //# sourceMappingURL=pick.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pick.d.ts","sourceRoot":"","sources":["../../src/object/pick.ts"],"names":[],"mappings":"AAAA,KAAK,gBAAgB,CAAC,CAAC,IAAI,WAAW,CAAC;KAAG,CAAC,IAAI,MAAM,CAAC,IAAI,SAAS,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC,CAAA;AACxG,KAAK,WAAW,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS;CAAE,CAAA;AAC1D,KAAK,YAAY,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,IAAI,SAAS,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,CAAA;AACrF,KAAK,WAAW,CAAC,CAAC,IAAI,gBAAgB,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAA;AAE3D,eAAO,MAAM,IAAI,gGAKhB,CAAA;AAED,eAAO,MAAM,aAAa,8IAczB,CAAA"}
@@ -0,0 +1,17 @@
1
+ export const pick = (obj, keys) => {
2
+ return keys.reduce((acc, key) => {
3
+ acc[key] = obj[key];
4
+ return acc;
5
+ }, {});
6
+ };
7
+ export const pickAllOrElse = (obj, keys, elseValue) => {
8
+ const ret = {};
9
+ for (const key of keys) {
10
+ if (obj[key] === undefined) {
11
+ return elseValue;
12
+ }
13
+ ret[key] = obj[key];
14
+ }
15
+ return ret;
16
+ };
17
+ //# sourceMappingURL=pick.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pick.js","sourceRoot":"","sources":["../../src/object/pick.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,MAAM,IAAI,GAAG,CAA8B,GAAQ,EAAE,IAAY,EAAwC,EAAE;IAChH,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QAC9B,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAA;QACnB,OAAO,GAAG,CAAA;IACZ,CAAC,EAAE,EAAS,CAAC,CAAA;AACf,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,GAAQ,EACR,IAAY,EACZ,SAAgB,EAC2C,EAAE;IAC7D,MAAM,GAAG,GAAG,EAAS,CAAA;IACrB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE;QACtB,IAAI,GAAG,CAAC,GAAG,CAAC,KAAK,SAAS,EAAE;YAC1B,OAAO,SAAS,CAAA;SACjB;QACD,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAA;KACpB;IAED,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA"}
@@ -0,0 +1,6 @@
1
+ /** Promise.all + Array.map */
2
+ export declare const promiseMap: <T, Res>(arr: T[], map: (el: T, index?: number) => Res | Promise<Res>) => Promise<(Awaited<Res> | Awaited<Res>)[]>;
3
+ export declare const promiseMapDict: <T, Res>(dict: Record<string, T>, map: (el: T, index?: number) => Res | Promise<Res>) => Promise<Record<string, Res>>;
4
+ export declare const promiseMapToDict: <T, Res>(arr: T[], mapValue: (el: T, index?: number) => Res | Promise<Res>, mapKey: (el: T, index?: number) => string) => Promise<Record<string, Res>>;
5
+ export declare const promiseMapPool: <T, Res>(arr: T[], map: (el: T, index?: number) => Promise<Res>, poolLimit: number) => Promise<Res[]>;
6
+ //# sourceMappingURL=promise.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../src/promise.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,eAAO,MAAM,UAAU,0CAA2C,MAAM,oEAC7C,CAAA;AAE3B,eAAO,MAAM,cAAc,yDAEJ,MAAM,wDAI5B,CAAA;AAED,eAAO,MAAM,gBAAgB,+CAED,MAAM,iDACR,MAAM,KAAK,MAAM,iCAK1C,CAAA;AAED,eAAO,MAAM,cAAc,0CAEJ,MAAM,8BAChB,MAAM,mBAiBlB,CAAA"}
@@ -0,0 +1,27 @@
1
+ /** Promise.all + Array.map */
2
+ export const promiseMap = (arr, map) => Promise.all(arr.map(map));
3
+ export const promiseMapDict = async (dict, map) => {
4
+ const mappedEntries = await Promise.all(Object.entries(dict).map(async ([key, val]) => [key, await map(val)]));
5
+ return Object.fromEntries(mappedEntries);
6
+ };
7
+ export const promiseMapToDict = async (arr, mapValue, mapKey) => {
8
+ const mappedEntries = await Promise.all(arr.map(async (el, index) => [mapKey(el, index), await mapValue(el, index)]));
9
+ return Object.fromEntries(mappedEntries);
10
+ };
11
+ export const promiseMapPool = async (arr, map, poolLimit) => {
12
+ const ret = [];
13
+ const executing = [];
14
+ for (const [index, item] of arr.entries()) {
15
+ const p = Promise.resolve().then(() => map(item, index));
16
+ ret.push(p);
17
+ if (poolLimit <= arr.length) {
18
+ const e = p.then(() => executing.splice(executing.indexOf(e), 1));
19
+ executing.push(e);
20
+ if (executing.length >= poolLimit) {
21
+ await Promise.race(executing);
22
+ }
23
+ }
24
+ }
25
+ return Promise.all(ret);
26
+ };
27
+ //# sourceMappingURL=promise.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"promise.js","sourceRoot":"","sources":["../src/promise.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,MAAM,CAAC,MAAM,UAAU,GAAG,CAAS,GAAQ,EAAE,GAAkD,EAAE,EAAE,CACjG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;AAE3B,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,EACjC,IAAuB,EACvB,GAAkD,EACpB,EAAE;IAChC,MAAM,aAAa,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;IAC9G,OAAO,MAAM,CAAC,WAAW,CAAC,aAAa,CAAC,CAAA;AAC1C,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,EACnC,GAAQ,EACR,QAAuD,EACvD,MAAyC,EACX,EAAE;IAChC,MAAM,aAAa,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,KAAK,CAAC,EAAE,MAAM,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;IAErH,OAAO,MAAM,CAAC,WAAW,CAAC,aAAa,CAAC,CAAA;AAC1C,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,EACjC,GAAQ,EACR,GAA4C,EAC5C,SAAiB,EACD,EAAE;IAClB,MAAM,GAAG,GAAmB,EAAE,CAAA;IAC9B,MAAM,SAAS,GAAmB,EAAE,CAAA;IACpC,KAAK,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,GAAG,CAAC,OAAO,EAAE,EAAE;QACzC,MAAM,CAAC,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAA;QACxD,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QAEX,IAAI,SAAS,IAAI,GAAG,CAAC,MAAM,EAAE;YAC3B,MAAM,CAAC,GAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;YACtE,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;YACjB,IAAI,SAAS,CAAC,MAAM,IAAI,SAAS,EAAE;gBACjC,MAAM,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;aAC9B;SACF;KACF;IACD,OAAO,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AACzB,CAAC,CAAA"}
package/dist/set.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export declare const difference: <T>(a: Set<T>, b: Set<T>) => Set<T>;
2
+ //# sourceMappingURL=set.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"set.d.ts","sourceRoot":"","sources":["../src/set.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,qCAStB,CAAA"}
package/dist/set.js ADDED
@@ -0,0 +1,10 @@
1
+ export const difference = (a, b) => {
2
+ const diff = new Set();
3
+ for (const item of a) {
4
+ if (!b.has(item)) {
5
+ diff.add(item);
6
+ }
7
+ }
8
+ return diff;
9
+ };
10
+ //# sourceMappingURL=set.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"set.js","sourceRoot":"","sources":["../src/set.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,CAAI,CAAS,EAAE,CAAS,EAAE,EAAE;IACpD,MAAM,IAAI,GAAG,IAAI,GAAG,EAAK,CAAA;IACzB,KAAK,MAAM,IAAI,IAAI,CAAC,EAAE;QACpB,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;YAChB,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;SACf;KACF;IAED,OAAO,IAAI,CAAA;AACb,CAAC,CAAA"}
@@ -0,0 +1,3 @@
1
+ export declare const lowercaseFirstChar: (str: string) => string;
2
+ export declare const uppercaseFirstChar: (str: string) => string;
3
+ //# sourceMappingURL=string.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../src/string.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,QAAS,MAAM,WAA+C,CAAA;AAC7F,eAAO,MAAM,kBAAkB,QAAS,MAAM,WAA+C,CAAA"}
package/dist/string.js ADDED
@@ -0,0 +1,3 @@
1
+ export const lowercaseFirstChar = (str) => str.charAt(0).toLowerCase() + str.slice(1);
2
+ export const uppercaseFirstChar = (str) => str.charAt(0).toUpperCase() + str.slice(1);
3
+ //# sourceMappingURL=string.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.js","sourceRoot":"","sources":["../src/string.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AAC7F,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA"}
package/dist/time.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ export declare const minuteInMs: number;
2
+ export declare const time: {
3
+ ms: number;
4
+ sec: number;
5
+ min: number;
6
+ hour: number;
7
+ day: number;
8
+ week: number;
9
+ };
10
+ /** Returns a string of format `m:ss` / `mm:ss` / `h:mm:ss` / ... */
11
+ export declare const msAsTimeString: (ms: number) => string;
12
+ //# sourceMappingURL=time.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,QAAY,CAAA;AAEnC,eAAO,MAAM,IAAI;;;;;;;CAOhB,CAAA;AAED,oEAAoE;AACpE,eAAO,MAAM,cAAc,OAAQ,MAAM,WAYxC,CAAA"}
package/dist/time.js ADDED
@@ -0,0 +1,22 @@
1
+ export const minuteInMs = 1000 * 60;
2
+ export const time = {
3
+ ms: 1,
4
+ sec: 1000,
5
+ min: 60 * 1000,
6
+ hour: 60 * 60 * 1000,
7
+ day: 24 * 60 * 60 * 1000,
8
+ week: 7 * 24 * 60 * 60 * 1000,
9
+ };
10
+ /** Returns a string of format `m:ss` / `mm:ss` / `h:mm:ss` / ... */
11
+ export const msAsTimeString = (ms) => {
12
+ const seconds = Math.floor(ms / 1000);
13
+ const minutes = Math.floor(seconds / 60);
14
+ const hours = Math.floor(minutes / 60);
15
+ const remainingSeconds = (seconds % 60).toString().padStart(2, '0');
16
+ const remainingMinutes = hours > 0 ? (minutes % 60).toString().padStart(2, '0') : minutes % 60;
17
+ const timeString = [hours > 0 ? `${hours}:` : '', `${remainingMinutes}:`, `${remainingSeconds}`]
18
+ .filter((val) => val !== '')
19
+ .join('');
20
+ return timeString;
21
+ };
22
+ //# sourceMappingURL=time.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"time.js","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,GAAG,EAAE,CAAA;AAEnC,MAAM,CAAC,MAAM,IAAI,GAAG;IAClB,EAAE,EAAE,CAAC;IACL,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,EAAE,GAAG,IAAI;IACd,IAAI,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI;IACpB,GAAG,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;IACxB,IAAI,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;CAC9B,CAAA;AAED,oEAAoE;AACpE,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,EAAU,EAAE,EAAE;IAC3C,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,IAAI,CAAC,CAAA;IACrC,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC,CAAA;IACxC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC,CAAA;IACtC,MAAM,gBAAgB,GAAG,CAAC,OAAO,GAAG,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;IACnE,MAAM,gBAAgB,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,GAAG,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,GAAG,EAAE,CAAA;IAE9F,MAAM,UAAU,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,GAAG,gBAAgB,GAAG,EAAE,GAAG,gBAAgB,EAAE,CAAC;SAC7F,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC;SAC3B,IAAI,CAAC,EAAE,CAAC,CAAA;IAEX,OAAO,UAAU,CAAA;AACnB,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "@livestore/utils",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
+ "sideEffects": false,
4
5
  "type": "module",
5
- "publishConfig": {
6
- "access": "public"
7
- },
8
- "react-native": "./dist/index.js",
9
6
  "exports": {
10
7
  ".": {
11
- "import": "./dist/index.js"
8
+ "types": "./dist/index.d.ts",
9
+ "default": "./dist/index.js"
12
10
  },
13
11
  "./effect": {
14
- "import": "./dist/effect/index.js"
12
+ "types": "./dist/effect/index.d.ts",
13
+ "default": "./dist/effect/index.js"
15
14
  }
16
15
  },
16
+ "react-native": "./dist/index.js",
17
17
  "types": "./dist/index.d.ts",
18
18
  "typesVersions": {
19
19
  "*": {
@@ -22,26 +22,24 @@
22
22
  ]
23
23
  }
24
24
  },
25
- "sideEffects": false,
26
25
  "scripts": {
27
26
  "test": "echo No tests yet"
28
27
  },
29
28
  "dependencies": {
30
- "@effect/data": "0.18.7",
31
- "@effect/io": "0.41.2",
32
- "@effect/match": "0.35.2",
33
- "@effect/opentelemetry": "^0.12.0",
34
- "@effect/schema": "0.38.0",
35
- "@effect/stm": "0.25.0",
36
- "@effect/stream": "0.37.1",
29
+ "@effect/opentelemetry": "^0.18.0",
30
+ "@effect/schema": "0.43.2",
37
31
  "@opentelemetry/api": "^1.6.0",
38
32
  "date-fns": "^2.30.0",
39
- "otel-websocket-exporter": "^0.0.22",
33
+ "effect": "2.0.0-next.48",
34
+ "otel-websocket-exporter": "^0.0.24",
40
35
  "pretty-bytes": "^6.1.1",
41
36
  "uuid": "^9.0.1"
42
37
  },
43
38
  "devDependencies": {
44
- "@types/uuid": "^9.0.4",
45
- "@types/web": "^0.0.115"
39
+ "@types/uuid": "^9.0.5",
40
+ "@types/web": "^0.0.117"
41
+ },
42
+ "publishConfig": {
43
+ "access": "public"
46
44
  }
47
45
  }
@@ -1,9 +1,7 @@
1
- import type * as Context from '@effect/data/Context'
2
- import { pipe } from '@effect/data/Function'
3
- import * as Cause from '@effect/io/Cause'
4
- import * as Effect from '@effect/io/Effect'
1
+ import type { Context } from 'effect'
2
+ import { Cause, Effect, pipe } from 'effect'
5
3
 
6
- export * from '@effect/io/Effect'
4
+ export * from 'effect/Effect'
7
5
 
8
6
  export const log = <A>(message: A, ...rest: any[]): Effect.Effect<never, never, void> =>
9
7
  Effect.sync(() => {
@@ -1,8 +1,11 @@
1
- import { TaggedClass } from '@effect/data/Data'
1
+ import { Data } from 'effect'
2
2
 
3
3
  import { errorToString, objectToString } from '../index.js'
4
4
 
5
- export class UnknownError extends TaggedClass('UnknownError')<{ readonly error: any; readonly payload?: any }> {
5
+ export class UnknownError extends Data.TaggedError('UnknownError')<{
6
+ readonly error: any
7
+ readonly payload?: any
8
+ }> {
6
9
  toString = () => {
7
10
  const payloadStr = this.payload ? ` with payload ${objectToString(this.payload)}` : ''
8
11
  return `UnknownError: ${errorToString(this.error)}${payloadStr}`
@@ -1,8 +1,6 @@
1
- import * as Duration from '@effect/data/Duration'
2
- import { pipe } from '@effect/data/Function'
3
- import * as Schedule from '@effect/io/Schedule'
1
+ import { Duration, pipe, Schedule } from 'effect'
4
2
 
5
- export * from '@effect/io/Schedule'
3
+ export * from 'effect/Schedule'
6
4
 
7
5
  export const exponentialBackoff10Sec: Schedule.Schedule<never, unknown, Duration.DurationInput> = pipe(
8
6
  Schedule.exponential(Duration.millis(10), 4), // 10ms, 40ms, 160ms, 640ms, 2560ms, ...
@@ -1,11 +1,5 @@
1
- import { pipe } from '@effect/data/Function'
2
- import * as Cause from '@effect/io/Cause'
3
- import * as Effect from '@effect/io/Effect'
4
- import * as Exit from '@effect/io/Exit'
5
- import * as Fiber from '@effect/io/Fiber'
6
- import * as Layer from '@effect/io/Layer'
7
- import type * as Runtime from '@effect/io/Runtime'
8
- import * as Scope from '@effect/io/Scope'
1
+ import type { Runtime } from 'effect'
2
+ import { Cause, Effect, Exit, Fiber, Layer, pipe, Scope } from 'effect'
9
3
 
10
4
  export interface MainLayer<Ctx> {
11
5
  layer: Layer.Layer<never, never, Ctx>
@@ -1,65 +1,54 @@
1
1
  import '../global.js'
2
2
 
3
- // io
4
- export * as Effect from './Effect.js'
5
- export * as Scope from '@effect/io/Scope'
6
- export * as Schedule from './Schedule.js'
7
- export * as Layer from './Layer.js'
8
- export * as Ref from '@effect/io/Ref'
9
- export * as SynchronizedRef from '@effect/io/SynchronizedRef'
10
- export * as Queue from '@effect/io/Queue'
11
- export * as Fiber from '@effect/io/Fiber'
12
- export * as FiberId from '@effect/io/FiberId'
13
- export * as RuntimeFlags from '@effect/io/RuntimeFlags'
14
- export * as Hub from '@effect/io/Hub'
15
- export * as Exit from '@effect/io/Exit'
16
- export * as Cause from '@effect/io/Cause'
17
- export * as Runtime from '@effect/io/Runtime'
18
- export * as Scheduler from '@effect/io/Scheduler'
19
- export * as FiberRef from '@effect/io/FiberRef'
20
- export * as FiberRefs from '@effect/io/FiberRefs'
21
- export * as FiberRefsPatch from '@effect/io/FiberRefsPatch'
22
- export * as Deferred from '@effect/io/Deferred'
23
- export * as Metric from '@effect/io/Metric'
24
- export * as MetricState from '@effect/io/MetricState'
25
- export * as Request from '@effect/io/Request'
26
- export * as Tracer from '@effect/io/Tracer'
27
-
28
- // data
29
- export * as Context from '@effect/data/Context'
30
- export * as Data from '@effect/data/Data'
31
- export { TaggedClass as Tagged } from '@effect/data/Data'
32
- export * as Either from '@effect/data/Either'
33
- export * as Brand from '@effect/data/Brand'
34
- export * as Hash from '@effect/data/Hash'
35
- export * as Equal from '@effect/data/Equal'
36
- export * as Ord from '@effect/data/Order'
37
- export * as Chunk from '@effect/data/Chunk'
38
- export * as Duration from '@effect/data/Duration'
39
- export * as ReadonlyArray from '@effect/data/ReadonlyArray'
40
- export * as ReadonlyRecord from '@effect/data/ReadonlyRecord'
41
- export * as SortedMap from '@effect/data/SortedMap'
42
- export * as HashMap from '@effect/data/HashMap'
43
- export * as HashSet from '@effect/data/HashSet'
44
- export * as MutableHashSet from '@effect/data/MutableHashSet'
45
- export * as Option from '@effect/data/Option'
46
- export { pipe, identity } from '@effect/data/Function'
3
+ export {
4
+ Scope,
5
+ Ref,
6
+ SynchronizedRef,
7
+ Queue,
8
+ Fiber,
9
+ FiberId,
10
+ RuntimeFlags,
11
+ PubSub,
12
+ Exit,
13
+ Cause,
14
+ Runtime,
15
+ Scheduler,
16
+ FiberRef,
17
+ FiberRefs,
18
+ FiberRefsPatch,
19
+ Deferred,
20
+ Metric,
21
+ MetricState,
22
+ Request,
23
+ Tracer,
24
+ Context,
25
+ Data,
26
+ Either,
27
+ Brand,
28
+ Hash,
29
+ Equal,
30
+ Chunk,
31
+ Duration,
32
+ ReadonlyArray,
33
+ ReadonlyRecord,
34
+ SortedMap,
35
+ HashMap,
36
+ HashSet,
37
+ MutableHashSet,
38
+ Option,
39
+ Layer,
40
+ Stream,
41
+ Channel,
42
+ SubscriptionRef,
43
+ pipe,
44
+ identity,
45
+ Match,
46
+ } from 'effect'
47
47
 
48
- // stream
49
- export * as Stream from '@effect/stream/Stream'
50
- export * as Channel from '@effect/stream/Channel'
51
- export * as SubscriptionRef from '@effect/stream/SubscriptionRef'
52
-
53
- // schema
54
48
  export * as Schema from '@effect/schema/Schema'
49
+ export * as OtelTracer from '@effect/opentelemetry/Tracer'
55
50
 
56
- // match
57
- export * as Match from '@effect/match'
58
-
59
- // error
51
+ export * as Effect from './Effect.js'
52
+ export * as Schedule from './Schedule.js'
60
53
  export * from './Error.js'
61
-
62
- // ServiceContext
63
54
  export * as ServiceContext from './ServiceContext.js'
64
-
65
- export * as OtelTracer from '@effect/opentelemetry/Tracer'
package/src/global.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  declare global {
2
- export type TODO = any
2
+ export type TODO<_Reason extends string = 'unknown'> = any
3
3
  }
4
4
 
5
5
  export {}
package/src/index.ts CHANGED
@@ -71,7 +71,7 @@ export const prop =
71
71
  obj[key]
72
72
 
73
73
  export const objectToString = (error: any): string => {
74
- const stack = typeof process !== 'undefined' && process.env.CL_DEBUG ? error.stack : undefined
74
+ const stack = error.stack
75
75
  const str = error.toString()
76
76
  const stackStr = stack ? `\n${stack}` : ''
77
77
  if (str !== '[object Object]') return str + stackStr
@@ -199,19 +199,17 @@ export const assertTag = <TObj extends { _tag: string }, TTag extends TObj['_tag
199
199
  return obj as any
200
200
  }
201
201
 
202
- export const getEnv = (varName: string) => {
203
- let value: string | undefined
202
+ export const memoize = <T extends (...args: any[]) => any>(fn: T): T => {
203
+ const cache = new Map<string, ReturnType<T>>()
204
204
 
205
- // @ts-expect-error `import.meta.env` might not be defined
206
- if (import.meta.env !== undefined) {
207
- // @ts-expect-error `import.meta.env` might not be defined
208
- value = import.meta.env[varName]
209
- // eslint-disable-next-line unicorn/no-negated-condition
210
- } else if (globalThis.process?.env !== undefined) {
211
- value = globalThis.process.env[varName]
212
- } else {
213
- throw new Error(`No environment variables found (neither import.meta.env nor process.env)`)
214
- }
205
+ return ((...args: any[]) => {
206
+ const key = JSON.stringify(args)
207
+ if (cache.has(key)) {
208
+ return cache.get(key)
209
+ }
215
210
 
216
- return value
211
+ const result = fn(...args)
212
+ cache.set(key, result)
213
+ return result
214
+ }) as any
217
215
  }
@@ -1,4 +1,4 @@
1
- import { pipe } from '@effect/data/Function'
1
+ import { pipe } from 'effect'
2
2
 
3
3
  export * from './pick.js'
4
4
  export * from './omit.js'
package/tsconfig.json CHANGED
@@ -1,13 +1,10 @@
1
1
  {
2
2
  "extends": "../../../tsconfig.base.json",
3
3
  "compilerOptions": {
4
- "module": "ES2020",
5
4
  "rootDir": "./src",
6
5
  "outDir": "./dist",
7
6
  "tsBuildInfoFile": "./dist/.tsbuildinfo.json"
8
7
  },
9
- "include": [
10
- "./src"
11
- ],
8
+ "include": ["./src"],
12
9
  "references": []
13
- }
10
+ }
@@ -1,42 +0,0 @@
1
- export * from '@effect/io/Layer'
2
- import type * as Context from '@effect/data/Context'
3
- import { pipe } from '@effect/data/Function'
4
- import * as Effect from '@effect/io/Effect'
5
- import * as Layer from '@effect/io/Layer'
6
- import type * as Tracer from '@effect/io/Tracer'
7
-
8
- export const span = (
9
- name: string,
10
- options?: {
11
- readonly attributes?: Record<string, Tracer.AttributeValue>
12
- readonly links?: ReadonlyArray<Tracer.SpanLink>
13
- readonly parent?: Tracer.ParentSpan
14
- readonly root?: boolean
15
- readonly context?: Context.Context<never>
16
- },
17
- onEnd?: (span: Tracer.Span) => Effect.Effect<never, never, void>,
18
- ): Layer.Layer<never, never, never> => {
19
- const scopedEffect = pipe(
20
- // eslint-disable-next-line react-hooks/rules-of-hooks
21
- Effect.useSpanScoped(name, options),
22
- Effect.tap((span) => Effect.withParentSpanScoped(span)),
23
- Effect.tap((span) => (onEnd ? Effect.addFinalizer(() => onEnd(span)) : Effect.unit)),
24
- )
25
-
26
- return Layer.scopedDiscard(scopedEffect)
27
- }
28
-
29
- export const withSpan =
30
- (
31
- name: string,
32
- options?: {
33
- readonly attributes?: Record<string, Tracer.AttributeValue>
34
- readonly links?: ReadonlyArray<Tracer.SpanLink>
35
- readonly parent?: Tracer.ParentSpan
36
- readonly root?: boolean
37
- readonly context?: Context.Context<never>
38
- },
39
- onEnd?: (span: Tracer.Span) => Effect.Effect<never, never, void>,
40
- ) =>
41
- <C, E, A>(layer: Layer.Layer<C, E, A>): Layer.Layer<C, E, A> =>
42
- Layer.provideMerge(span(name, options, onEnd), layer)