abret 0.1.1 → 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.
@@ -0,0 +1,58 @@
1
+ // @bun
2
+ // src/jsx/index.ts
3
+ class SafeString {
4
+ value;
5
+ constructor(value) {
6
+ this.value = value;
7
+ }
8
+ toString() {
9
+ return this.value;
10
+ }
11
+ }
12
+
13
+ class AsyncBuffer extends ReadableStream {
14
+ promise;
15
+ constructor(promise) {
16
+ super({
17
+ async start(controller) {
18
+ try {
19
+ const result = await promise;
20
+ controller.enqueue(new TextEncoder().encode(result.toString()));
21
+ controller.close();
22
+ } catch (e) {
23
+ controller.error(e);
24
+ }
25
+ }
26
+ });
27
+ this.promise = promise;
28
+ }
29
+ then(onfulfilled, onrejected) {
30
+ return this.promise.then(onfulfilled, onrejected);
31
+ }
32
+ catch(onrejected) {
33
+ return this.promise.catch(onrejected);
34
+ }
35
+ finally(onfinally) {
36
+ return this.promise.finally(onfinally);
37
+ }
38
+ }
39
+
40
+ class VNode {
41
+ tag;
42
+ props;
43
+ children;
44
+ constructor(tag, props, children) {
45
+ this.tag = tag;
46
+ this.props = props;
47
+ this.children = children;
48
+ }
49
+ }
50
+ var Fragment = Symbol("Fragment");
51
+ function jsx(tag, props) {
52
+ const { children, ...rest } = props || {};
53
+ return new VNode(tag, { ...rest, children }, children);
54
+ }
55
+ var jsxs = jsx;
56
+ var jsxDEV = jsx;
57
+
58
+ export { SafeString, AsyncBuffer, VNode, Fragment, jsx, jsxs, jsxDEV };
@@ -0,0 +1,80 @@
1
+ // @bun
2
+ // src/store.ts
3
+ import { AsyncLocalStorage } from "async_hooks";
4
+ var contextStore = new AsyncLocalStorage;
5
+ function createContext(name, ...args) {
6
+ const [defaultValue] = args;
7
+ const id = Symbol(name);
8
+ if (args.length > 0) {
9
+ const Provider = (props) => {
10
+ return props.children;
11
+ };
12
+ Provider._context = { id, defaultValue };
13
+ return {
14
+ id,
15
+ defaultValue,
16
+ Provider
17
+ };
18
+ }
19
+ return id;
20
+ }
21
+ function getContextId(context) {
22
+ if (typeof context === "symbol") {
23
+ return context;
24
+ }
25
+ return context.id;
26
+ }
27
+ function getDefaultValue(context) {
28
+ if (typeof context !== "symbol" && "defaultValue" in context) {
29
+ return context.defaultValue;
30
+ }
31
+ return;
32
+ }
33
+ var setContext = (context, value) => {
34
+ const store = contextStore.getStore();
35
+ if (!store) {
36
+ throw new Error("setContext must be called within a context scope. " + "Ensure you are inside a route handler or use runWithContext.");
37
+ }
38
+ store.set(getContextId(context), value);
39
+ };
40
+ function useContext(context, options) {
41
+ const store = contextStore.getStore();
42
+ const id = getContextId(context);
43
+ const value = store?.get(id);
44
+ if (value !== undefined) {
45
+ return value;
46
+ }
47
+ const defaultVal = getDefaultValue(context);
48
+ if (defaultVal !== undefined) {
49
+ return defaultVal;
50
+ }
51
+ if (options?.required) {
52
+ const name = typeof context === "symbol" ? context.description : context.id.description;
53
+ throw new Error(`Context "${name}" is required but not set`);
54
+ }
55
+ return;
56
+ }
57
+ var hasContext = (context) => {
58
+ const store = contextStore.getStore();
59
+ return store?.has(getContextId(context)) ?? false;
60
+ };
61
+ var clearContext = (context) => {
62
+ const store = contextStore.getStore();
63
+ if (store) {
64
+ store.delete(getContextId(context));
65
+ }
66
+ };
67
+ function runWithContext(fn) {
68
+ const currentStore = contextStore.getStore();
69
+ const newStore = currentStore ? new Map(currentStore) : new Map;
70
+ return contextStore.run(newStore, fn);
71
+ }
72
+ function runWithContextValue(context, value, fn) {
73
+ const currentStore = contextStore.getStore() || new Map;
74
+ const newStore = new Map(currentStore);
75
+ newStore.set(getContextId(context), value);
76
+ return contextStore.run(newStore, fn);
77
+ }
78
+ var getContextStore = () => contextStore;
79
+
80
+ export { createContext, setContext, useContext, hasContext, clearContext, runWithContext, runWithContextValue, getContextStore };
package/dist/html.js CHANGED
@@ -1,137 +1,13 @@
1
1
  // @bun
2
- // src/store.ts
3
- import { AsyncLocalStorage } from "async_hooks";
4
- var contextStore = new AsyncLocalStorage;
5
- function createContext(name, ...args) {
6
- const [defaultValue] = args;
7
- const id = Symbol(name);
8
- if (args.length > 0) {
9
- const Provider = (props) => {
10
- return props.children;
11
- };
12
- Provider._context = { id, defaultValue };
13
- return {
14
- id,
15
- defaultValue,
16
- Provider
17
- };
18
- }
19
- return id;
20
- }
21
- function getContextId(context) {
22
- if (typeof context === "symbol") {
23
- return context;
24
- }
25
- return context.id;
26
- }
27
- function getDefaultValue(context) {
28
- if (typeof context !== "symbol" && "defaultValue" in context) {
29
- return context.defaultValue;
30
- }
31
- return;
32
- }
33
- var setContext = (context, value) => {
34
- const store = contextStore.getStore();
35
- if (!store) {
36
- throw new Error("setContext must be called within a context scope. " + "Ensure you are inside a route handler or use runWithContext.");
37
- }
38
- store.set(getContextId(context), value);
39
- };
40
- function useContext(context, options) {
41
- const store = contextStore.getStore();
42
- const id = getContextId(context);
43
- const value = store?.get(id);
44
- if (value !== undefined) {
45
- return value;
46
- }
47
- const defaultVal = getDefaultValue(context);
48
- if (defaultVal !== undefined) {
49
- return defaultVal;
50
- }
51
- if (options?.required) {
52
- const name = typeof context === "symbol" ? context.description : context.id.description;
53
- throw new Error(`Context "${name}" is required but not set`);
54
- }
55
- return;
56
- }
57
- var hasContext = (context) => {
58
- const store = contextStore.getStore();
59
- return store?.has(getContextId(context)) ?? false;
60
- };
61
- var clearContext = (context) => {
62
- const store = contextStore.getStore();
63
- if (store) {
64
- store.delete(getContextId(context));
65
- }
66
- };
67
- function runWithContext(fn) {
68
- const currentStore = contextStore.getStore();
69
- const newStore = currentStore ? new Map(currentStore) : new Map;
70
- return contextStore.run(newStore, fn);
71
- }
72
- function runWithContextValue(context, value, fn) {
73
- const currentStore = contextStore.getStore() || new Map;
74
- const newStore = new Map(currentStore);
75
- newStore.set(getContextId(context), value);
76
- return contextStore.run(newStore, fn);
77
- }
78
- var getContextStore = () => contextStore;
79
-
80
- // src/jsx/index.ts
81
- class SafeString {
82
- value;
83
- constructor(value) {
84
- this.value = value;
85
- }
86
- toString() {
87
- return this.value;
88
- }
89
- }
90
-
91
- class AsyncBuffer extends ReadableStream {
92
- promise;
93
- constructor(promise) {
94
- super({
95
- async start(controller) {
96
- try {
97
- const result = await promise;
98
- controller.enqueue(new TextEncoder().encode(result.toString()));
99
- controller.close();
100
- } catch (e) {
101
- controller.error(e);
102
- }
103
- }
104
- });
105
- this.promise = promise;
106
- }
107
- then(onfulfilled, onrejected) {
108
- return this.promise.then(onfulfilled, onrejected);
109
- }
110
- catch(onrejected) {
111
- return this.promise.catch(onrejected);
112
- }
113
- finally(onfinally) {
114
- return this.promise.finally(onfinally);
115
- }
116
- }
117
-
118
- class VNode {
119
- tag;
120
- props;
121
- children;
122
- constructor(tag, props, children) {
123
- this.tag = tag;
124
- this.props = props;
125
- this.children = children;
126
- }
127
- }
128
- var Fragment = Symbol("Fragment");
129
- function jsx(tag, props) {
130
- const { children, ...rest } = props || {};
131
- return new VNode(tag, { ...rest, children }, children);
132
- }
133
- var jsxs = jsx;
134
- var jsxDEV = jsx;
2
+ import {
3
+ getContextStore
4
+ } from "./chunk-xw5b0251.js";
5
+ import {
6
+ AsyncBuffer,
7
+ Fragment,
8
+ SafeString,
9
+ VNode
10
+ } from "./chunk-m9t91z6h.js";
135
11
 
136
12
  // src/html.ts
137
13
  class HTMLResponse extends Response {
@@ -402,11 +278,11 @@ function render(node) {
402
278
  const providerCtx = node.tag._context;
403
279
  if (providerCtx) {
404
280
  const value = node.props.value;
405
- const contextStore2 = getContextStore();
406
- const currentStore = contextStore2.getStore() || new Map;
281
+ const contextStore = getContextStore();
282
+ const currentStore = contextStore.getStore() || new Map;
407
283
  const newStore = new Map(currentStore);
408
284
  newStore.set(providerCtx.id, value);
409
- return contextStore2.run(newStore, () => {
285
+ return contextStore.run(newStore, () => {
410
286
  return render(node.props.children);
411
287
  });
412
288
  }
package/dist/index.js CHANGED
@@ -1,81 +1,10 @@
1
1
  // @bun
2
- // src/store.ts
3
- import { AsyncLocalStorage } from "async_hooks";
4
- var contextStore = new AsyncLocalStorage;
5
- function createContext(name, ...args) {
6
- const [defaultValue] = args;
7
- const id = Symbol(name);
8
- if (args.length > 0) {
9
- const Provider = (props) => {
10
- return props.children;
11
- };
12
- Provider._context = { id, defaultValue };
13
- return {
14
- id,
15
- defaultValue,
16
- Provider
17
- };
18
- }
19
- return id;
20
- }
21
- function getContextId(context) {
22
- if (typeof context === "symbol") {
23
- return context;
24
- }
25
- return context.id;
26
- }
27
- function getDefaultValue(context) {
28
- if (typeof context !== "symbol" && "defaultValue" in context) {
29
- return context.defaultValue;
30
- }
31
- return;
32
- }
33
- var setContext = (context, value) => {
34
- const store = contextStore.getStore();
35
- if (!store) {
36
- throw new Error("setContext must be called within a context scope. " + "Ensure you are inside a route handler or use runWithContext.");
37
- }
38
- store.set(getContextId(context), value);
39
- };
40
- function useContext(context, options) {
41
- const store = contextStore.getStore();
42
- const id = getContextId(context);
43
- const value = store?.get(id);
44
- if (value !== undefined) {
45
- return value;
46
- }
47
- const defaultVal = getDefaultValue(context);
48
- if (defaultVal !== undefined) {
49
- return defaultVal;
50
- }
51
- if (options?.required) {
52
- const name = typeof context === "symbol" ? context.description : context.id.description;
53
- throw new Error(`Context "${name}" is required but not set`);
54
- }
55
- return;
56
- }
57
- var hasContext = (context) => {
58
- const store = contextStore.getStore();
59
- return store?.has(getContextId(context)) ?? false;
60
- };
61
- var clearContext = (context) => {
62
- const store = contextStore.getStore();
63
- if (store) {
64
- store.delete(getContextId(context));
65
- }
66
- };
67
- function runWithContext(fn) {
68
- const currentStore = contextStore.getStore();
69
- const newStore = currentStore ? new Map(currentStore) : new Map;
70
- return contextStore.run(newStore, fn);
71
- }
72
- function runWithContextValue(context, value, fn) {
73
- const currentStore = contextStore.getStore() || new Map;
74
- const newStore = new Map(currentStore);
75
- newStore.set(getContextId(context), value);
76
- return contextStore.run(newStore, fn);
77
- }
78
- var getContextStore = () => contextStore;
2
+ import {
3
+ createContext,
4
+ runWithContext,
5
+ runWithContextValue,
6
+ useContext
7
+ } from "./chunk-xw5b0251.js";
79
8
 
80
9
  // src/index.ts
81
10
  var wrapWithMiddleware = (handler, middlewares) => {
@@ -1,59 +1,13 @@
1
1
  // @bun
2
- // src/jsx/index.ts
3
- class SafeString {
4
- value;
5
- constructor(value) {
6
- this.value = value;
7
- }
8
- toString() {
9
- return this.value;
10
- }
11
- }
12
-
13
- class AsyncBuffer extends ReadableStream {
14
- promise;
15
- constructor(promise) {
16
- super({
17
- async start(controller) {
18
- try {
19
- const result = await promise;
20
- controller.enqueue(new TextEncoder().encode(result.toString()));
21
- controller.close();
22
- } catch (e) {
23
- controller.error(e);
24
- }
25
- }
26
- });
27
- this.promise = promise;
28
- }
29
- then(onfulfilled, onrejected) {
30
- return this.promise.then(onfulfilled, onrejected);
31
- }
32
- catch(onrejected) {
33
- return this.promise.catch(onrejected);
34
- }
35
- finally(onfinally) {
36
- return this.promise.finally(onfinally);
37
- }
38
- }
39
-
40
- class VNode {
41
- tag;
42
- props;
43
- children;
44
- constructor(tag, props, children) {
45
- this.tag = tag;
46
- this.props = props;
47
- this.children = children;
48
- }
49
- }
50
- var Fragment = Symbol("Fragment");
51
- function jsx(tag, props) {
52
- const { children, ...rest } = props || {};
53
- return new VNode(tag, { ...rest, children }, children);
54
- }
55
- var jsxs = jsx;
56
- var jsxDEV = jsx;
2
+ import {
3
+ AsyncBuffer,
4
+ Fragment,
5
+ SafeString,
6
+ VNode,
7
+ jsx,
8
+ jsxDEV,
9
+ jsxs
10
+ } from "../chunk-m9t91z6h.js";
57
11
  export {
58
12
  jsxs,
59
13
  jsxDEV,
@@ -1,59 +1,13 @@
1
1
  // @bun
2
- // src/jsx/index.ts
3
- class SafeString {
4
- value;
5
- constructor(value) {
6
- this.value = value;
7
- }
8
- toString() {
9
- return this.value;
10
- }
11
- }
12
-
13
- class AsyncBuffer extends ReadableStream {
14
- promise;
15
- constructor(promise) {
16
- super({
17
- async start(controller) {
18
- try {
19
- const result = await promise;
20
- controller.enqueue(new TextEncoder().encode(result.toString()));
21
- controller.close();
22
- } catch (e) {
23
- controller.error(e);
24
- }
25
- }
26
- });
27
- this.promise = promise;
28
- }
29
- then(onfulfilled, onrejected) {
30
- return this.promise.then(onfulfilled, onrejected);
31
- }
32
- catch(onrejected) {
33
- return this.promise.catch(onrejected);
34
- }
35
- finally(onfinally) {
36
- return this.promise.finally(onfinally);
37
- }
38
- }
39
-
40
- class VNode {
41
- tag;
42
- props;
43
- children;
44
- constructor(tag, props, children) {
45
- this.tag = tag;
46
- this.props = props;
47
- this.children = children;
48
- }
49
- }
50
- var Fragment = Symbol("Fragment");
51
- function jsx(tag, props) {
52
- const { children, ...rest } = props || {};
53
- return new VNode(tag, { ...rest, children }, children);
54
- }
55
- var jsxs = jsx;
56
- var jsxDEV = jsx;
2
+ import {
3
+ AsyncBuffer,
4
+ Fragment,
5
+ SafeString,
6
+ VNode,
7
+ jsx,
8
+ jsxDEV,
9
+ jsxs
10
+ } from "../chunk-m9t91z6h.js";
57
11
  export {
58
12
  jsxs,
59
13
  jsxDEV,
package/dist/store.js CHANGED
@@ -1,81 +1,14 @@
1
1
  // @bun
2
- // src/store.ts
3
- import { AsyncLocalStorage } from "async_hooks";
4
- var contextStore = new AsyncLocalStorage;
5
- function createContext(name, ...args) {
6
- const [defaultValue] = args;
7
- const id = Symbol(name);
8
- if (args.length > 0) {
9
- const Provider = (props) => {
10
- return props.children;
11
- };
12
- Provider._context = { id, defaultValue };
13
- return {
14
- id,
15
- defaultValue,
16
- Provider
17
- };
18
- }
19
- return id;
20
- }
21
- function getContextId(context) {
22
- if (typeof context === "symbol") {
23
- return context;
24
- }
25
- return context.id;
26
- }
27
- function getDefaultValue(context) {
28
- if (typeof context !== "symbol" && "defaultValue" in context) {
29
- return context.defaultValue;
30
- }
31
- return;
32
- }
33
- var setContext = (context, value) => {
34
- const store = contextStore.getStore();
35
- if (!store) {
36
- throw new Error("setContext must be called within a context scope. " + "Ensure you are inside a route handler or use runWithContext.");
37
- }
38
- store.set(getContextId(context), value);
39
- };
40
- function useContext(context, options) {
41
- const store = contextStore.getStore();
42
- const id = getContextId(context);
43
- const value = store?.get(id);
44
- if (value !== undefined) {
45
- return value;
46
- }
47
- const defaultVal = getDefaultValue(context);
48
- if (defaultVal !== undefined) {
49
- return defaultVal;
50
- }
51
- if (options?.required) {
52
- const name = typeof context === "symbol" ? context.description : context.id.description;
53
- throw new Error(`Context "${name}" is required but not set`);
54
- }
55
- return;
56
- }
57
- var hasContext = (context) => {
58
- const store = contextStore.getStore();
59
- return store?.has(getContextId(context)) ?? false;
60
- };
61
- var clearContext = (context) => {
62
- const store = contextStore.getStore();
63
- if (store) {
64
- store.delete(getContextId(context));
65
- }
66
- };
67
- function runWithContext(fn) {
68
- const currentStore = contextStore.getStore();
69
- const newStore = currentStore ? new Map(currentStore) : new Map;
70
- return contextStore.run(newStore, fn);
71
- }
72
- function runWithContextValue(context, value, fn) {
73
- const currentStore = contextStore.getStore() || new Map;
74
- const newStore = new Map(currentStore);
75
- newStore.set(getContextId(context), value);
76
- return contextStore.run(newStore, fn);
77
- }
78
- var getContextStore = () => contextStore;
2
+ import {
3
+ clearContext,
4
+ createContext,
5
+ getContextStore,
6
+ hasContext,
7
+ runWithContext,
8
+ runWithContextValue,
9
+ setContext,
10
+ useContext
11
+ } from "./chunk-xw5b0251.js";
79
12
  export {
80
13
  useContext,
81
14
  setContext,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "abret",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Fast, type-safe web framework for Bun with built-in JSX and middleware support.",
5
5
  "license": "MIT",
6
6
  "author": "Arisris",