effect-start 0.19.0 → 0.20.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 (144) hide show
  1. package/README.md +3 -3
  2. package/dist/Development.d.ts +3 -3
  3. package/dist/Development.js +3 -2
  4. package/dist/Effectify.d.ts +212 -0
  5. package/dist/Effectify.js +19 -0
  6. package/dist/FilePathPattern.d.ts +29 -0
  7. package/dist/FilePathPattern.js +86 -0
  8. package/dist/FileRouter.d.ts +39 -41
  9. package/dist/FileRouter.js +104 -158
  10. package/dist/FileRouterCodegen.d.ts +7 -8
  11. package/dist/FileRouterCodegen.js +97 -66
  12. package/dist/PlatformError.d.ts +46 -0
  13. package/dist/PlatformError.js +43 -0
  14. package/dist/PlatformRuntime.d.ts +23 -0
  15. package/dist/PlatformRuntime.js +42 -0
  16. package/dist/RouteBody.d.ts +1 -1
  17. package/dist/Start.d.ts +34 -3
  18. package/dist/Start.js +31 -6
  19. package/dist/bun/BunPlatformHttpServer.d.ts +10 -0
  20. package/dist/bun/BunPlatformHttpServer.js +53 -0
  21. package/dist/bun/BunRoute.d.ts +3 -5
  22. package/dist/bun/BunRoute.js +9 -17
  23. package/dist/bun/BunRuntime.d.ts +2 -1
  24. package/dist/bun/BunRuntime.js +10 -5
  25. package/dist/bun/BunServer.d.ts +33 -0
  26. package/dist/bun/BunServer.js +133 -0
  27. package/dist/bun/BunServerRequest.d.ts +60 -0
  28. package/dist/bun/BunServerRequest.js +252 -0
  29. package/dist/bun/index.d.ts +1 -1
  30. package/dist/bun/index.js +1 -1
  31. package/dist/datastar/actions/fetch.d.ts +30 -0
  32. package/dist/datastar/actions/fetch.js +411 -0
  33. package/dist/datastar/actions/peek.d.ts +1 -0
  34. package/dist/datastar/actions/peek.js +14 -0
  35. package/dist/datastar/actions/setAll.d.ts +1 -0
  36. package/dist/datastar/actions/setAll.js +13 -0
  37. package/dist/datastar/actions/toggleAll.d.ts +1 -0
  38. package/dist/datastar/actions/toggleAll.js +13 -0
  39. package/dist/datastar/attributes/attr.d.ts +1 -0
  40. package/dist/datastar/attributes/attr.js +49 -0
  41. package/dist/datastar/attributes/bind.d.ts +1 -0
  42. package/dist/datastar/attributes/bind.js +183 -0
  43. package/dist/datastar/attributes/class.d.ts +1 -0
  44. package/dist/datastar/attributes/class.js +50 -0
  45. package/dist/datastar/attributes/computed.d.ts +1 -0
  46. package/dist/datastar/attributes/computed.js +27 -0
  47. package/dist/datastar/attributes/effect.d.ts +1 -0
  48. package/dist/datastar/attributes/effect.js +10 -0
  49. package/dist/datastar/attributes/indicator.d.ts +1 -0
  50. package/dist/datastar/attributes/indicator.js +32 -0
  51. package/dist/datastar/attributes/init.d.ts +1 -0
  52. package/dist/datastar/attributes/init.js +27 -0
  53. package/dist/datastar/attributes/jsonSignals.d.ts +1 -0
  54. package/dist/datastar/attributes/jsonSignals.js +31 -0
  55. package/dist/datastar/attributes/on.d.ts +1 -0
  56. package/dist/datastar/attributes/on.js +59 -0
  57. package/dist/datastar/attributes/onIntersect.d.ts +1 -0
  58. package/dist/datastar/attributes/onIntersect.js +54 -0
  59. package/dist/datastar/attributes/onInterval.d.ts +1 -0
  60. package/dist/datastar/attributes/onInterval.js +31 -0
  61. package/dist/datastar/attributes/onSignalPatch.d.ts +1 -0
  62. package/dist/datastar/attributes/onSignalPatch.js +44 -0
  63. package/dist/datastar/attributes/ref.d.ts +1 -0
  64. package/dist/datastar/attributes/ref.js +11 -0
  65. package/dist/datastar/attributes/show.d.ts +1 -0
  66. package/dist/datastar/attributes/show.js +32 -0
  67. package/dist/datastar/attributes/signals.d.ts +1 -0
  68. package/dist/datastar/attributes/signals.js +18 -0
  69. package/dist/datastar/attributes/style.d.ts +1 -0
  70. package/dist/datastar/attributes/style.js +56 -0
  71. package/dist/datastar/attributes/text.d.ts +1 -0
  72. package/dist/datastar/attributes/text.js +27 -0
  73. package/dist/datastar/engine.d.ts +156 -0
  74. package/dist/datastar/engine.js +971 -0
  75. package/dist/datastar/index.d.ts +24 -0
  76. package/dist/datastar/index.js +24 -0
  77. package/dist/datastar/load.d.ts +24 -0
  78. package/dist/datastar/load.js +24 -0
  79. package/dist/datastar/utils.d.ts +51 -0
  80. package/dist/datastar/utils.js +205 -0
  81. package/dist/datastar/watchers/patchElements.d.ts +1 -0
  82. package/dist/datastar/watchers/patchElements.js +420 -0
  83. package/dist/datastar/watchers/patchSignals.d.ts +1 -0
  84. package/dist/datastar/watchers/patchSignals.js +15 -0
  85. package/dist/index.d.ts +1 -1
  86. package/dist/index.js +1 -1
  87. package/dist/node/NodeFileSystem.d.ts +7 -0
  88. package/dist/node/NodeFileSystem.js +420 -0
  89. package/dist/node/NodeUtils.d.ts +2 -0
  90. package/dist/node/NodeUtils.js +20 -0
  91. package/dist/x/tailwind/plugin.js +1 -1
  92. package/package.json +11 -7
  93. package/src/Development.ts +26 -25
  94. package/src/{node/Effectify.ts → Effectify.ts} +10 -3
  95. package/src/FilePathPattern.ts +115 -0
  96. package/src/FileRouter.ts +178 -255
  97. package/src/FileRouterCodegen.ts +135 -92
  98. package/src/{node/PlatformError.ts → PlatformError.ts} +34 -19
  99. package/src/PlatformRuntime.ts +97 -0
  100. package/src/RouteBody.ts +1 -1
  101. package/src/RouteHttp.ts +3 -1
  102. package/src/Start.ts +61 -14
  103. package/src/bun/BunPlatformHttpServer.ts +88 -0
  104. package/src/bun/BunRoute.ts +12 -22
  105. package/src/bun/BunRuntime.ts +21 -5
  106. package/src/bun/BunServer.ts +228 -0
  107. package/src/bun/index.ts +1 -1
  108. package/src/datastar/README.md +18 -0
  109. package/src/datastar/actions/fetch.ts +609 -0
  110. package/src/datastar/actions/peek.ts +17 -0
  111. package/src/datastar/actions/setAll.ts +20 -0
  112. package/src/datastar/actions/toggleAll.ts +20 -0
  113. package/src/datastar/attributes/attr.ts +50 -0
  114. package/src/datastar/attributes/bind.ts +220 -0
  115. package/src/datastar/attributes/class.ts +57 -0
  116. package/src/datastar/attributes/computed.ts +33 -0
  117. package/src/datastar/attributes/effect.ts +11 -0
  118. package/src/datastar/attributes/indicator.ts +39 -0
  119. package/src/datastar/attributes/init.ts +35 -0
  120. package/src/datastar/attributes/jsonSignals.ts +38 -0
  121. package/src/datastar/attributes/on.ts +71 -0
  122. package/src/datastar/attributes/onIntersect.ts +65 -0
  123. package/src/datastar/attributes/onInterval.ts +39 -0
  124. package/src/datastar/attributes/onSignalPatch.ts +63 -0
  125. package/src/datastar/attributes/ref.ts +12 -0
  126. package/src/datastar/attributes/show.ts +33 -0
  127. package/src/datastar/attributes/signals.ts +22 -0
  128. package/src/datastar/attributes/style.ts +63 -0
  129. package/src/datastar/attributes/text.ts +30 -0
  130. package/src/datastar/engine.ts +1341 -0
  131. package/src/datastar/index.ts +25 -0
  132. package/src/datastar/utils.ts +286 -0
  133. package/src/datastar/watchers/patchElements.ts +554 -0
  134. package/src/datastar/watchers/patchSignals.ts +15 -0
  135. package/src/index.ts +1 -1
  136. package/src/node/{FileSystem.ts → NodeFileSystem.ts} +2 -2
  137. package/src/node/{Utils.ts → NodeUtils.ts} +2 -0
  138. package/src/x/tailwind/plugin.ts +1 -1
  139. package/src/FileRouterCodegen.todo.ts +0 -1133
  140. package/src/FileRouterPattern.ts +0 -59
  141. package/src/RouterPattern.ts +0 -416
  142. package/src/StartApp.ts +0 -47
  143. package/src/bun/BunHttpServer.ts +0 -303
  144. /package/src/bun/{BunHttpServer_web.ts → BunServerRequest.ts} +0 -0
@@ -0,0 +1,56 @@
1
+ import { attribute } from "../engine.js";
2
+ import { effect } from "../engine.js";
3
+ import { kebab } from "../utils.js";
4
+ attribute({
5
+ name: "style",
6
+ requirement: {
7
+ value: "must",
8
+ },
9
+ returnsValue: true,
10
+ apply({ key, el, rx }) {
11
+ const { style } = el;
12
+ const initialStyles = new Map();
13
+ const apply = (prop, value) => {
14
+ const initial = initialStyles.get(prop);
15
+ if (!value && value !== 0) {
16
+ initial !== undefined
17
+ && (initial
18
+ ? style.setProperty(prop, initial)
19
+ : style.removeProperty(prop));
20
+ }
21
+ else {
22
+ initial === undefined
23
+ && initialStyles.set(prop, style.getPropertyValue(prop));
24
+ style.setProperty(prop, String(value));
25
+ }
26
+ };
27
+ const update = () => {
28
+ observer.disconnect();
29
+ if (key) {
30
+ apply(key, rx());
31
+ }
32
+ else {
33
+ const styles = rx();
34
+ for (const [prop, initial] of initialStyles) {
35
+ prop in styles
36
+ || (initial
37
+ ? style.setProperty(prop, initial)
38
+ : style.removeProperty(prop));
39
+ }
40
+ for (const prop in styles) {
41
+ apply(kebab(prop), styles[prop]);
42
+ }
43
+ }
44
+ observer.observe(el, { attributeFilter: ["style"] });
45
+ };
46
+ const observer = new MutationObserver(update);
47
+ const cleanup = effect(update);
48
+ return () => {
49
+ observer.disconnect();
50
+ cleanup();
51
+ for (const [prop, initial] of initialStyles) {
52
+ initial ? style.setProperty(prop, initial) : style.removeProperty(prop);
53
+ }
54
+ };
55
+ },
56
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,27 @@
1
+ import { attribute } from "../engine.js";
2
+ import { effect } from "../engine.js";
3
+ attribute({
4
+ name: "text",
5
+ requirement: {
6
+ key: "denied",
7
+ value: "must",
8
+ },
9
+ returnsValue: true,
10
+ apply({ el, rx }) {
11
+ const update = () => {
12
+ observer.disconnect();
13
+ el.textContent = `${rx()}`;
14
+ observer.observe(el, {
15
+ childList: true,
16
+ characterData: true,
17
+ subtree: true,
18
+ });
19
+ };
20
+ const observer = new MutationObserver(update);
21
+ const cleanup = effect(update);
22
+ return () => {
23
+ observer.disconnect();
24
+ cleanup();
25
+ };
26
+ },
27
+ });
@@ -0,0 +1,156 @@
1
+ export declare const DSP: string;
2
+ export declare const DSS: string;
3
+ export declare const DATASTAR_FETCH_EVENT = "datastar-fetch";
4
+ export declare const DATASTAR_SIGNAL_PATCH_EVENT = "datastar-signal-patch";
5
+ /*********
6
+ * types.ts
7
+ *********/
8
+ export type JSONPatch = Record<string, any> & {
9
+ length?: never;
10
+ };
11
+ export type Paths = [string, any][];
12
+ export type DatastarFetchEvent = {
13
+ type: string;
14
+ el: HTMLOrSVG;
15
+ argsRaw: Record<string, string>;
16
+ };
17
+ export type CustomEventMap = {
18
+ [DATASTAR_SIGNAL_PATCH_EVENT]: CustomEvent<JSONPatch>;
19
+ };
20
+ export type WatcherFn<K extends keyof CustomEventMap> = (this: Document, ev: CustomEventMap[K]) => void;
21
+ export type ErrorFn = (name: string, ctx?: Record<string, any>) => void;
22
+ export type ActionContext = {
23
+ el: HTMLOrSVG;
24
+ evt?: Event;
25
+ error: ErrorFn;
26
+ cleanups: Map<string, () => void>;
27
+ };
28
+ export type RequirementType = "allowed" | "must" | "denied" | "exclusive";
29
+ export type Requirement = RequirementType | {
30
+ key: Exclude<RequirementType, "exclusive">;
31
+ value?: Exclude<RequirementType, "exclusive">;
32
+ } | {
33
+ key?: Exclude<RequirementType, "exclusive">;
34
+ value: Exclude<RequirementType, "exclusive">;
35
+ };
36
+ type Rx<B extends boolean> = (...args: any[]) => B extends true ? unknown : void;
37
+ type ReqField<R, K extends "key" | "value", Return> = R extends "must" | {
38
+ [P in K]: "must";
39
+ } ? Return : R extends "denied" | {
40
+ [P in K]: "denied";
41
+ } ? undefined : R extends "allowed" | {
42
+ [P in K]: "allowed";
43
+ } | (K extends keyof R ? never : R) ? Return | undefined : never;
44
+ type ReqFields<R extends Requirement, B extends boolean> = R extends "exclusive" ? {
45
+ key: string;
46
+ value: undefined;
47
+ rx: undefined;
48
+ } | {
49
+ key: undefined;
50
+ value: string;
51
+ rx: Rx<B>;
52
+ } : {
53
+ key: ReqField<R, "key", string>;
54
+ value: ReqField<R, "value", string>;
55
+ rx: ReqField<R, "value", Rx<B>>;
56
+ };
57
+ export type AttributeContext<R extends Requirement = Requirement, RxReturn extends boolean = boolean> = {
58
+ el: HTMLOrSVG;
59
+ mods: Modifiers;
60
+ rawKey: string;
61
+ evt?: Event;
62
+ error: ErrorFn;
63
+ loadedPluginNames: {
64
+ actions: Readonly<Set<string>>;
65
+ attributes: Readonly<Set<string>>;
66
+ };
67
+ } & ReqFields<R, RxReturn>;
68
+ export type AttributePlugin<R extends Requirement = Requirement, RxReturn extends boolean = boolean> = {
69
+ name: string;
70
+ apply: (ctx: AttributeContext<R, RxReturn>) => void | (() => void);
71
+ requirement?: R;
72
+ returnsValue?: RxReturn;
73
+ argNames?: string[];
74
+ };
75
+ export type WatcherContext = {
76
+ error: ErrorFn;
77
+ };
78
+ export type WatcherPlugin = {
79
+ name: string;
80
+ apply: (ctx: WatcherContext, args: Record<string, string | undefined>) => void;
81
+ };
82
+ export type ActionPlugins = Record<string, ActionPlugin>;
83
+ export type ActionPlugin<T = any> = {
84
+ name: string;
85
+ apply: (ctx: ActionContext, ...args: any[]) => T;
86
+ };
87
+ export type MergePatchArgs = {
88
+ ifMissing?: boolean;
89
+ };
90
+ export type HTMLOrSVG = HTMLElement | SVGElement | MathMLElement;
91
+ export type Modifiers = Map<string, Set<string>>;
92
+ export type EventCallbackHandler = (...args: any[]) => void;
93
+ export type SignalFilter = RegExp;
94
+ export type SignalFilterOptions = {
95
+ include?: RegExp | string;
96
+ exclude?: RegExp | string;
97
+ };
98
+ export type Signal<T> = {
99
+ (): T;
100
+ (value: T): boolean;
101
+ };
102
+ export type Computed<T> = () => T;
103
+ export type Effect = () => void;
104
+ /*********
105
+ * signals.ts
106
+ *********/
107
+ interface ReactiveNode {
108
+ deps_?: Link;
109
+ depsTail_?: Link;
110
+ subs_?: Link;
111
+ subsTail_?: Link;
112
+ flags_: ReactiveFlags;
113
+ }
114
+ interface Link {
115
+ version_: number;
116
+ dep_: ReactiveNode;
117
+ sub_: ReactiveNode;
118
+ prevSub_?: Link;
119
+ nextSub_?: Link;
120
+ prevDep_?: Link;
121
+ nextDep_?: Link;
122
+ }
123
+ declare const ReactiveFlags: {
124
+ readonly None: 0;
125
+ readonly Mutable: number;
126
+ readonly Watching: number;
127
+ readonly RecursedCheck: number;
128
+ readonly Recursed: number;
129
+ readonly Dirty: number;
130
+ readonly Pending: number;
131
+ };
132
+ type ReactiveFlags = typeof ReactiveFlags[keyof typeof ReactiveFlags];
133
+ export declare const beginBatch: () => void;
134
+ export declare const endBatch: () => void;
135
+ export declare const startPeeking: (sub?: ReactiveNode) => void;
136
+ export declare const stopPeeking: () => void;
137
+ export declare const signal: <T>(initialValue?: T) => Signal<T>;
138
+ export declare const computed: <T>(getter: (previousValue?: T) => T) => Computed<T>;
139
+ export declare const effect: (fn: () => void) => Effect;
140
+ export declare const getPath: <T = any>(path: string) => T | undefined;
141
+ export declare const mergePatch: (patch: JSONPatch, { ifMissing }?: MergePatchArgs) => void;
142
+ export declare const mergePaths: (paths: Paths, options?: MergePatchArgs) => void;
143
+ export declare const filtered: ({ include, exclude }?: SignalFilterOptions, obj?: JSONPatch) => Record<string, any>;
144
+ export declare const root: Record<string, any>;
145
+ export declare const actions: Record<string, (ctx: ActionContext, ...args: any[]) => any>;
146
+ export declare const attribute: <R extends Requirement, B extends boolean>(plugin: AttributePlugin<R, B>) => void;
147
+ export declare const action: <T>(plugin: ActionPlugin<T>) => void;
148
+ export declare const watcher: (plugin: WatcherPlugin) => void;
149
+ export declare const parseAttributeKey: (rawKey: string) => {
150
+ pluginName: string;
151
+ key: string | undefined;
152
+ mods: Modifiers;
153
+ };
154
+ export declare const isDocumentObserverActive: () => boolean;
155
+ export declare const apply: (root?: HTMLOrSVG | ShadowRoot, observeRoot?: boolean) => void;
156
+ export {};