@go-go-scope/adapter-remix 2.5.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 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.
@@ -0,0 +1,119 @@
1
+ import { LoaderFunctionArgs, ActionFunctionArgs } from '@remix-run/server-runtime';
2
+ import { Scope } from 'go-go-scope';
3
+
4
+ /**
5
+ * Remix adapter for go-go-scope
6
+ *
7
+ * Provides structured concurrency for Remix loaders and actions
8
+ * with automatic cleanup.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * // app/routes/users.tsx
13
+ * import { withScopeLoader, withScopeAction } from '@go-go-scope/adapter-remix'
14
+ * import { json } from '@remix-run/node'
15
+ *
16
+ * export const loader = withScopeLoader(async ({ request, scope }) => {
17
+ * const [err, users] = await scope.task(() => fetchUsers())
18
+ * if (err) throw new Response(err.message, { status: 500 })
19
+ * return json({ users })
20
+ * })
21
+ *
22
+ * export const action = withScopeAction(async ({ request, scope }) => {
23
+ * const formData = await request.formData()
24
+ * const [err, result] = await scope.task(() => createUser(formData))
25
+ * if (err) return json({ error: err.message }, { status: 400 })
26
+ * return json({ result })
27
+ * })
28
+ * ```
29
+ */
30
+
31
+ /**
32
+ * Remix context with scope
33
+ */
34
+ interface RemixContext<T extends Record<string, unknown> = Record<string, never>> {
35
+ /** The scope for this request */
36
+ scope: Scope<T>;
37
+ /** Request signal for cancellation */
38
+ signal: AbortSignal;
39
+ }
40
+ /**
41
+ * Options for scope configuration
42
+ */
43
+ interface RemixScopeOptions<T extends Record<string, unknown> = Record<string, never>> {
44
+ /** Scope timeout in milliseconds */
45
+ timeout?: number;
46
+ /** Initial services to provide */
47
+ services?: T;
48
+ }
49
+ /**
50
+ * Wrap a Remix loader with scope
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * // app/routes/users.tsx
55
+ * import { withScopeLoader } from '@go-go-scope/adapter-remix'
56
+ * import { json } from '@remix-run/node'
57
+ *
58
+ * export const loader = withScopeLoader(async ({ request, scope }) => {
59
+ * const url = new URL(request.url)
60
+ * const page = url.searchParams.get('page') || '1'
61
+ *
62
+ * const [err, users] = await scope.task(() => fetchUsers(page))
63
+ * if (err) throw new Response(err.message, { status: 500 })
64
+ *
65
+ * return json({ users })
66
+ * })
67
+ * ```
68
+ */
69
+ declare function withScopeLoader<T extends Record<string, unknown>, R>(loader: (args: LoaderFunctionArgs & RemixContext<T>) => Promise<R> | R, options?: RemixScopeOptions<T>): (args: LoaderFunctionArgs) => Promise<R>;
70
+ /**
71
+ * Wrap a Remix action with scope
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * // app/routes/users.tsx
76
+ * import { withScopeAction } from '@go-go-scope/adapter-remix'
77
+ * import { json } from '@remix-run/node'
78
+ *
79
+ * export const action = withScopeAction(async ({ request, scope }) => {
80
+ * const formData = await request.formData()
81
+ *
82
+ * const [err, result] = await scope.task(() => createUser(formData))
83
+ * if (err) return json({ error: err.message }, { status: 400 })
84
+ *
85
+ * return json({ result })
86
+ * })
87
+ * ```
88
+ */
89
+ declare function withScopeAction<T extends Record<string, unknown>, R>(action: (args: ActionFunctionArgs & RemixContext<T>) => Promise<R> | R, options?: RemixScopeOptions<T>): (args: ActionFunctionArgs) => Promise<R>;
90
+ /**
91
+ * Create reusable scope configuration for loaders/actions
92
+ *
93
+ * @example
94
+ * ```typescript
95
+ * // app/lib/scope.ts
96
+ * import { createRemixScope } from '@go-go-scope/adapter-remix'
97
+ * import { db } from './db'
98
+ *
99
+ * export const remixScope = createRemixScope({
100
+ * timeout: 10000,
101
+ * services: { db }
102
+ * })
103
+ *
104
+ * // app/routes/users.tsx
105
+ * import { remixScope } from '~/lib/scope'
106
+ *
107
+ * export const loader = remixScope.loader(async ({ request, scope }) => {
108
+ * const db = scope.use('db')
109
+ * // ...
110
+ * })
111
+ * ```
112
+ */
113
+ declare function createRemixScope<T extends Record<string, unknown>>(config: RemixScopeOptions<T>): {
114
+ loader: <R>(loader: (args: LoaderFunctionArgs & RemixContext<T>) => Promise<R> | R) => (args: LoaderFunctionArgs) => Promise<R>;
115
+ action: <R>(action: (args: ActionFunctionArgs & RemixContext<T>) => Promise<R> | R) => (args: ActionFunctionArgs) => Promise<R>;
116
+ };
117
+
118
+ export { createRemixScope, withScopeAction, withScopeLoader };
119
+ export type { RemixContext, RemixScopeOptions };
package/dist/index.mjs ADDED
@@ -0,0 +1,109 @@
1
+ import { scope } from 'go-go-scope';
2
+
3
+ var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
4
+ var __typeError = (msg) => {
5
+ throw TypeError(msg);
6
+ };
7
+ var __using = (stack, value, async) => {
8
+ if (value != null) {
9
+ if (typeof value !== "object" && typeof value !== "function") __typeError("Object expected");
10
+ var dispose, inner;
11
+ dispose = value[__knownSymbol("asyncDispose")];
12
+ if (dispose === void 0) {
13
+ dispose = value[__knownSymbol("dispose")];
14
+ inner = dispose;
15
+ }
16
+ if (typeof dispose !== "function") __typeError("Object not disposable");
17
+ if (inner) dispose = function() {
18
+ try {
19
+ inner.call(this);
20
+ } catch (e) {
21
+ return Promise.reject(e);
22
+ }
23
+ };
24
+ stack.push([async, dispose, value]);
25
+ } else {
26
+ stack.push([async]);
27
+ }
28
+ return value;
29
+ };
30
+ var __callDispose = (stack, error, hasError) => {
31
+ var E = typeof SuppressedError === "function" ? SuppressedError : function(e, s, m, _) {
32
+ return _ = Error(m), _.name = "SuppressedError", _.error = e, _.suppressed = s, _;
33
+ };
34
+ var fail = (e) => error = hasError ? new E(e, error, "An error was suppressed during disposal") : (hasError = true, e);
35
+ var next = (it) => {
36
+ while (it = stack.pop()) {
37
+ try {
38
+ var result = it[1] && it[1].call(it[2]);
39
+ if (it[0]) return Promise.resolve(result).then(next, (e) => (fail(e), next()));
40
+ } catch (e) {
41
+ fail(e);
42
+ }
43
+ }
44
+ if (hasError) throw error;
45
+ };
46
+ return next();
47
+ };
48
+ function withScopeLoader(loader, options = {}) {
49
+ return async (args) => {
50
+ var _stack = [];
51
+ try {
52
+ const s = __using(_stack, scope({
53
+ timeout: options.timeout,
54
+ signal: args.signal,
55
+ name: `remix-loader-${args.request.method}-${new URL(args.request.url).pathname}`
56
+ }), true);
57
+ if (options.services) {
58
+ for (const [key, value] of Object.entries(options.services)) {
59
+ s.provide(key, value);
60
+ }
61
+ }
62
+ const context = {
63
+ scope: s,
64
+ signal: s.signal
65
+ };
66
+ return await loader({ ...args, ...context });
67
+ } catch (_) {
68
+ var _error = _, _hasError = true;
69
+ } finally {
70
+ var _promise = __callDispose(_stack, _error, _hasError);
71
+ _promise && await _promise;
72
+ }
73
+ };
74
+ }
75
+ function withScopeAction(action, options = {}) {
76
+ return async (args) => {
77
+ var _stack = [];
78
+ try {
79
+ const s = __using(_stack, scope({
80
+ timeout: options.timeout,
81
+ signal: args.signal,
82
+ name: `remix-action-${args.request.method}-${new URL(args.request.url).pathname}`
83
+ }), true);
84
+ if (options.services) {
85
+ for (const [key, value] of Object.entries(options.services)) {
86
+ s.provide(key, value);
87
+ }
88
+ }
89
+ const context = {
90
+ scope: s,
91
+ signal: s.signal
92
+ };
93
+ return await action({ ...args, ...context });
94
+ } catch (_) {
95
+ var _error = _, _hasError = true;
96
+ } finally {
97
+ var _promise = __callDispose(_stack, _error, _hasError);
98
+ _promise && await _promise;
99
+ }
100
+ };
101
+ }
102
+ function createRemixScope(config) {
103
+ return {
104
+ loader: (loader) => withScopeLoader(loader, config),
105
+ action: (action) => withScopeAction(action, config)
106
+ };
107
+ }
108
+
109
+ export { createRemixScope, withScopeAction, withScopeLoader };
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@go-go-scope/adapter-remix",
3
+ "version": "2.5.0",
4
+ "description": "Remix adapter for go-go-scope",
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
+ "files": [
15
+ "dist"
16
+ ],
17
+ "keywords": [
18
+ "structured-concurrency",
19
+ "remix",
20
+ "loader",
21
+ "action",
22
+ "typescript"
23
+ ],
24
+ "author": "Your Name",
25
+ "license": "MIT",
26
+ "peerDependencies": {
27
+ "go-go-scope": "^2.4.0",
28
+ "@remix-run/server-runtime": "^2.0.0"
29
+ },
30
+ "devDependencies": {
31
+ "@remix-run/server-runtime": "^2.0.0",
32
+ "@types/node": "^22.13.15",
33
+ "pkgroll": "^2.6.1",
34
+ "typescript": "^5.8.3",
35
+ "vitest": "^3.1.1",
36
+ "go-go-scope": "2.5.0"
37
+ },
38
+ "scripts": {
39
+ "build": "pkgroll",
40
+ "typecheck": "tsc --noEmit",
41
+ "lint": "biome check --fix src",
42
+ "test": "vitest run",
43
+ "test:watch": "vitest",
44
+ "clean": "rm -rf dist"
45
+ }
46
+ }