@go-go-scope/adapter-solid-start 2.7.0
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.
- package/LICENSE +21 -0
- package/dist/index.d.mts +122 -0
- package/dist/index.mjs +60 -0
- package/package.json +58 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 thelinuxlich (Alisson Cavalcante Agiani)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { FetchEvent } from '@solidjs/start/server';
|
|
2
|
+
import { Scope } from 'go-go-scope';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* SolidStart adapter for go-go-scope
|
|
6
|
+
* Provides request-scoped structured concurrency for SolidStart applications
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
declare module "@solidjs/start/server" {
|
|
10
|
+
interface FetchEvent {
|
|
11
|
+
scope: Scope;
|
|
12
|
+
request: Request;
|
|
13
|
+
respondWith(response: Response | Promise<Response>): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
interface SolidStartGoGoScopeOptions {
|
|
17
|
+
/** Root scope name */
|
|
18
|
+
name?: string;
|
|
19
|
+
/** Default timeout for all requests in ms */
|
|
20
|
+
timeout?: number;
|
|
21
|
+
/** Enable debug logging */
|
|
22
|
+
debug?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* SolidStart middleware for go-go-scope integration
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* // src/middleware.ts
|
|
30
|
+
* import { createMiddleware } from '@solidjs/start/middleware'
|
|
31
|
+
* import { solidStartGoGoScope } from '@go-go-scope/adapter-solid-start'
|
|
32
|
+
*
|
|
33
|
+
* export default createMiddleware({
|
|
34
|
+
* onRequest: [
|
|
35
|
+
* solidStartGoGoScope({
|
|
36
|
+
* name: 'my-solid-app',
|
|
37
|
+
* timeout: 30000
|
|
38
|
+
* })
|
|
39
|
+
* ]
|
|
40
|
+
* })
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* // src/routes/api/users/[id].ts
|
|
46
|
+
* import { json } from '@solidjs/router'
|
|
47
|
+
* import { getScope } from '@go-go-scope/adapter-solid-start'
|
|
48
|
+
* import type { APIEvent } from '@solidjs/start/server'
|
|
49
|
+
*
|
|
50
|
+
* export const GET = async (event: APIEvent) => {
|
|
51
|
+
* const s = getScope(event)
|
|
52
|
+
* const id = event.params.id
|
|
53
|
+
*
|
|
54
|
+
* const [err, user] = await s.task(
|
|
55
|
+
* () => fetchUser(id),
|
|
56
|
+
* { retry: 'exponential', timeout: 5000 }
|
|
57
|
+
* )
|
|
58
|
+
*
|
|
59
|
+
* if (err) {
|
|
60
|
+
* return json({ error: err.message }, { status: 500 })
|
|
61
|
+
* }
|
|
62
|
+
* return json(user)
|
|
63
|
+
* }
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
declare function solidStartGoGoScope(options?: SolidStartGoGoScopeOptions): (event: FetchEvent) => Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Helper to get the current scope from the fetch event
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* const GET = async (event: APIEvent) => {
|
|
73
|
+
* const s = getScope(event)
|
|
74
|
+
* const [err, data] = await s.task(() => fetchData())
|
|
75
|
+
* // ...
|
|
76
|
+
* }
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
declare function getScope(event: {
|
|
80
|
+
scope?: Scope<any>;
|
|
81
|
+
}): Scope<any>;
|
|
82
|
+
/**
|
|
83
|
+
* Helper to create an API handler with automatic scope integration
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* import { defineScopedHandler } from '@go-go-scope/adapter-solid-start'
|
|
88
|
+
* import type { APIEvent } from '@solidjs/start/server'
|
|
89
|
+
*
|
|
90
|
+
* export const GET = defineScopedHandler(async (event, scope) => {
|
|
91
|
+
* const [err, users] = await scope.task(() => fetchUsers())
|
|
92
|
+
* if (err) return json({ error: err.message }, { status: 500 })
|
|
93
|
+
* return json(users)
|
|
94
|
+
* })
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
declare function defineScopedHandler<T>(handler: (event: FetchEvent, scope: Scope<any>) => Promise<T>): (event: FetchEvent) => Promise<T>;
|
|
98
|
+
/**
|
|
99
|
+
* Server function wrapper with scope access
|
|
100
|
+
* For use with SolidStart's createServerData$, createServerAction$, etc.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* // src/lib/users.ts
|
|
105
|
+
* import { createServerAction$ } from '@solidjs/router'
|
|
106
|
+
* import { withScope } from '@go-go-scope/adapter-solid-start'
|
|
107
|
+
*
|
|
108
|
+
* export const createUser = withScope(async (scope, formData: FormData) => {
|
|
109
|
+
* const name = formData.get('name') as string
|
|
110
|
+
* const [err, user] = await scope.task(() => db.insert('users', { name }))
|
|
111
|
+
* if (err) throw err
|
|
112
|
+
* return user
|
|
113
|
+
* })
|
|
114
|
+
*
|
|
115
|
+
* // Usage in component
|
|
116
|
+
* const [, createUserAction] = createServerAction$(createUser)
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
declare function withScope<TArgs extends unknown[], TReturn>(fn: (scope: Scope<any>, ...args: TArgs) => Promise<TReturn>): (...args: TArgs) => Promise<TReturn>;
|
|
120
|
+
|
|
121
|
+
export { defineScopedHandler, getScope, solidStartGoGoScope, withScope };
|
|
122
|
+
export type { SolidStartGoGoScopeOptions };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { scope } from 'go-go-scope';
|
|
2
|
+
|
|
3
|
+
function solidStartGoGoScope(options = {}) {
|
|
4
|
+
const { name = "solid-start-app", timeout, debug = false } = options;
|
|
5
|
+
const rootScope = scope({ name });
|
|
6
|
+
if (debug) {
|
|
7
|
+
console.log(`[go-go-scope] Root scope created: ${name}`);
|
|
8
|
+
}
|
|
9
|
+
return async (event) => {
|
|
10
|
+
const scopeOptions = {
|
|
11
|
+
parent: rootScope,
|
|
12
|
+
name: `request-${event.request.url}`
|
|
13
|
+
};
|
|
14
|
+
if (timeout) scopeOptions.timeout = timeout;
|
|
15
|
+
event.scope = scope(scopeOptions);
|
|
16
|
+
if (debug) {
|
|
17
|
+
console.log(`[go-go-scope] Request scope created: ${scopeOptions.name}`);
|
|
18
|
+
}
|
|
19
|
+
const originalRespondWith = event.respondWith.bind(event);
|
|
20
|
+
event.respondWith = async (response) => {
|
|
21
|
+
try {
|
|
22
|
+
return await originalRespondWith(response);
|
|
23
|
+
} finally {
|
|
24
|
+
await event.scope[Symbol.asyncDispose]().catch(() => {
|
|
25
|
+
});
|
|
26
|
+
if (debug) {
|
|
27
|
+
console.log(`[go-go-scope] Request scope disposed`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function getScope(event) {
|
|
34
|
+
const s = event.scope;
|
|
35
|
+
if (!s) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
"No scope found in event. Make sure the solidStartGoGoScope middleware is registered."
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
return s;
|
|
41
|
+
}
|
|
42
|
+
function defineScopedHandler(handler) {
|
|
43
|
+
return async (event) => {
|
|
44
|
+
const s = getScope(event);
|
|
45
|
+
return handler(event, s);
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function withScope(fn) {
|
|
49
|
+
return async (...args) => {
|
|
50
|
+
const s = scope({ name: "solid-start-server-fn" });
|
|
51
|
+
try {
|
|
52
|
+
return await fn(s, ...args);
|
|
53
|
+
} finally {
|
|
54
|
+
await s[Symbol.asyncDispose]().catch(() => {
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { defineScopedHandler, getScope, solidStartGoGoScope, withScope };
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@go-go-scope/adapter-solid-start",
|
|
3
|
+
"version": "2.7.0",
|
|
4
|
+
"description": "SolidStart adapter for go-go-scope - Request-scoped structured concurrency for SolidStart applications",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.mts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.mts",
|
|
11
|
+
"default": "./dist/index.mjs"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"go-go-scope",
|
|
16
|
+
"solid",
|
|
17
|
+
"solidjs",
|
|
18
|
+
"solid-start",
|
|
19
|
+
"structured-concurrency"
|
|
20
|
+
],
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=24.0.0"
|
|
23
|
+
},
|
|
24
|
+
"author": "thelinuxlich",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/thelinuxlich/go-go-scope.git",
|
|
29
|
+
"directory": "packages/adapter-solid-start"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist/",
|
|
33
|
+
"README.md",
|
|
34
|
+
"LICENSE"
|
|
35
|
+
],
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"go-go-scope": "2.7.0"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@biomejs/biome": "^2.4.4",
|
|
41
|
+
"@solidjs/start": "^1.0.0",
|
|
42
|
+
"@types/node": "^24",
|
|
43
|
+
"pkgroll": "^2.26.3",
|
|
44
|
+
"typescript": "^5.9.3",
|
|
45
|
+
"vitest": "^4.0.18"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"@solidjs/start": "^1.0.0",
|
|
49
|
+
"@solidjs/router": "^0.13.0"
|
|
50
|
+
},
|
|
51
|
+
"scripts": {
|
|
52
|
+
"build": "pkgroll --clean-dist",
|
|
53
|
+
"test": "vitest run --passWithNoTests",
|
|
54
|
+
"lint": "biome check --write src/",
|
|
55
|
+
"typecheck": "tsc --noEmit",
|
|
56
|
+
"clean": "rm -rf dist"
|
|
57
|
+
}
|
|
58
|
+
}
|