@byearlybird/starling 0.1.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.
Files changed (52) hide show
  1. package/README.md +375 -0
  2. package/dist/core/crdt/clock.d.ts +15 -0
  3. package/dist/core/crdt/clock.d.ts.map +1 -0
  4. package/dist/core/crdt/operations.d.ts +8 -0
  5. package/dist/core/crdt/operations.d.ts.map +1 -0
  6. package/dist/core/index.d.ts +5 -0
  7. package/dist/core/index.d.ts.map +1 -0
  8. package/dist/core/index.js +454 -0
  9. package/dist/core/shared/types.d.ts +25 -0
  10. package/dist/core/shared/types.d.ts.map +1 -0
  11. package/dist/core/shared/utils.d.ts +5 -0
  12. package/dist/core/shared/utils.d.ts.map +1 -0
  13. package/dist/core/store/mutations.d.ts +16 -0
  14. package/dist/core/store/mutations.d.ts.map +1 -0
  15. package/dist/core/store/query.d.ts +16 -0
  16. package/dist/core/store/query.d.ts.map +1 -0
  17. package/dist/core/store/store.d.ts +77 -0
  18. package/dist/core/store/store.d.ts.map +1 -0
  19. package/dist/index.d.ts +2 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +454 -0
  22. package/dist/plugins/index.d.ts +3 -0
  23. package/dist/plugins/index.d.ts.map +1 -0
  24. package/dist/plugins/index.js +188 -0
  25. package/dist/plugins/persistence/index.d.ts +2 -0
  26. package/dist/plugins/persistence/index.d.ts.map +1 -0
  27. package/dist/plugins/persistence/unstorage-plugin.d.ts +5 -0
  28. package/dist/plugins/persistence/unstorage-plugin.d.ts.map +1 -0
  29. package/dist/plugins/push-pull-plugin.d.ts +13 -0
  30. package/dist/plugins/push-pull-plugin.d.ts.map +1 -0
  31. package/dist/plugins/sync/index.d.ts +3 -0
  32. package/dist/plugins/sync/index.d.ts.map +1 -0
  33. package/dist/plugins/sync/index.js +65 -0
  34. package/dist/plugins/sync/push-pull-plugin.d.ts +13 -0
  35. package/dist/plugins/sync/push-pull-plugin.d.ts.map +1 -0
  36. package/dist/plugins/unstorage-plugin.d.ts +5 -0
  37. package/dist/plugins/unstorage-plugin.d.ts.map +1 -0
  38. package/dist/react/index.d.ts +3 -0
  39. package/dist/react/index.d.ts.map +1 -0
  40. package/dist/react/index.js +893 -0
  41. package/dist/react/use-data.d.ts +9 -0
  42. package/dist/react/use-data.d.ts.map +1 -0
  43. package/dist/react/use-query.d.ts +7 -0
  44. package/dist/react/use-query.d.ts.map +1 -0
  45. package/dist/solid/index.d.ts +3 -0
  46. package/dist/solid/index.d.ts.map +1 -0
  47. package/dist/solid/index.js +299 -0
  48. package/dist/solid/use-data.d.ts +3 -0
  49. package/dist/solid/use-data.d.ts.map +1 -0
  50. package/dist/solid/use-query.d.ts +3 -0
  51. package/dist/solid/use-query.d.ts.map +1 -0
  52. package/package.json +65 -0
@@ -0,0 +1,65 @@
1
+ var __create = Object.create;
2
+ var __getProtoOf = Object.getPrototypeOf;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __toESM = (mod, isNodeMode, target) => {
7
+ target = mod != null ? __create(__getProtoOf(mod)) : {};
8
+ const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
9
+ for (let key of __getOwnPropNames(mod))
10
+ if (!__hasOwnProp.call(to, key))
11
+ __defProp(to, key, {
12
+ get: () => mod[key],
13
+ enumerable: true
14
+ });
15
+ return to;
16
+ };
17
+ var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
18
+
19
+ // lib/plugins/sync/push-pull-plugin.ts
20
+ var pushPullPlugin = (config) => {
21
+ const {
22
+ push,
23
+ pull,
24
+ preprocess,
25
+ pullInterval = 1000 * 60 * 5,
26
+ immediate = true
27
+ } = config;
28
+ const plugin = (store) => {
29
+ let intervalId = null;
30
+ let unwatch = null;
31
+ async function pullData() {
32
+ const data = await pull();
33
+ const processed = preprocess ? await preprocess("pull", data) : data;
34
+ store.merge(processed);
35
+ }
36
+ async function pushData(data) {
37
+ const processed = preprocess ? await preprocess("push", data) : data;
38
+ await push(processed);
39
+ }
40
+ return {
41
+ init: async () => {
42
+ unwatch = store.on("change", async () => {
43
+ const latest = store.snapshot();
44
+ if (latest.length > 0) {
45
+ await pushData(latest);
46
+ }
47
+ });
48
+ if (immediate)
49
+ await pullData();
50
+ intervalId = setInterval(pullData, pullInterval);
51
+ },
52
+ dispose: async () => {
53
+ if (intervalId !== null) {
54
+ clearInterval(intervalId);
55
+ intervalId = null;
56
+ }
57
+ unwatch?.();
58
+ }
59
+ };
60
+ };
61
+ return plugin;
62
+ };
63
+ export {
64
+ pushPullPlugin
65
+ };
@@ -0,0 +1,13 @@
1
+ import type { ArrayKV, EncodedObject } from "@core/shared/types";
2
+ import type { Plugin } from "@core/store/store";
3
+ type PushPullConfig = {
4
+ push: (data: ArrayKV<EncodedObject>) => Promise<void>;
5
+ pull: () => Promise<ArrayKV<EncodedObject>>;
6
+ pullInterval?: number;
7
+ preprocess?: (event: "pull" | "push", data: ArrayKV<EncodedObject>) => Promise<ArrayKV<EncodedObject>>;
8
+ immediate?: boolean;
9
+ };
10
+ declare const pushPullPlugin: <TValue extends object>(config: PushPullConfig) => Plugin<TValue>;
11
+ export { pushPullPlugin };
12
+ export type { PushPullConfig };
13
+ //# sourceMappingURL=push-pull-plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"push-pull-plugin.d.ts","sourceRoot":"","sources":["../../../lib/plugins/sync/push-pull-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD,KAAK,cAAc,GAAG;IACrB,IAAI,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,aAAa,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACtD,IAAI,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC;IAC5C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,CACZ,KAAK,EAAE,MAAM,GAAG,MAAM,EACtB,IAAI,EAAE,OAAO,CAAC,aAAa,CAAC,KACxB,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC;IACrC,SAAS,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,QAAA,MAAM,cAAc,GAAI,MAAM,SAAS,MAAM,EAC5C,QAAQ,cAAc,KACpB,MAAM,CAAC,MAAM,CAiDf,CAAC;AAEF,OAAO,EAAE,cAAc,EAAE,CAAC;AAC1B,YAAY,EAAE,cAAc,EAAE,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { Plugin } from "@core/store/store";
2
+ import { type Storage } from "unstorage";
3
+ declare const unstoragePlugin: <T extends object>(baseStorage: Storage) => Plugin<T>;
4
+ export { unstoragePlugin };
5
+ //# sourceMappingURL=unstorage-plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unstorage-plugin.d.ts","sourceRoot":"","sources":["../../lib/plugins/unstorage-plugin.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAiB,KAAK,OAAO,EAAE,MAAM,WAAW,CAAC;AAExD,QAAA,MAAM,eAAe,GAAI,CAAC,SAAS,MAAM,EAAE,aAAa,OAAO,KAAG,MAAM,CAAC,CAAC,CAyBzE,CAAC;AAEF,OAAO,EAAE,eAAe,EAAE,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { useData } from "./use-data";
2
+ export { useQuery } from "./use-query";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC"}