@azure-net/kit 6.0.0-next.1 → 6.0.0-next.10
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/README.md +335 -2
- package/dist/delivery/index.d.ts +3 -1
- package/dist/delivery/index.js +3 -1
- package/dist/delivery/injectable-dependencies/AsyncHelpers.d.ts +2 -4
- package/dist/delivery/injectable-dependencies/AsyncHelpers.js +96 -102
- package/dist/delivery/presenter/Bound.d.ts +1 -0
- package/dist/delivery/presenter/Bound.js +9 -0
- package/dist/delivery/presenter/RegisterProvider.d.ts +16 -0
- package/dist/delivery/presenter/RegisterProvider.js +99 -0
- package/dist/delivery/schema/rules/Rules.js +2 -1
- package/dist/delivery.d.ts +0 -1
- package/dist/delivery.js +0 -1
- package/dist/i18n/Internal.d.ts +15 -0
- package/dist/i18n/Internal.js +11 -0
- package/dist/i18n/TranslationManager.d.ts +19 -0
- package/dist/i18n/TranslationManager.js +26 -0
- package/dist/i18n/Translations.svelte.d.ts +20 -0
- package/dist/i18n/Translations.svelte.js +254 -0
- package/dist/i18n/Types.d.ts +30 -0
- package/dist/i18n/Types.js +1 -0
- package/dist/i18n/index.d.ts +3 -0
- package/dist/i18n/index.js +2 -0
- package/dist/infra/datasource/BaseDatasource.d.ts +19 -6
- package/dist/infra/datasource/BaseDatasource.js +4 -4
- package/dist/infra/http-service/HttpServiceInstance.d.ts +26 -16
- package/dist/infra/http-service/HttpServiceInstance.js +21 -13
- package/dist/infra/index.d.ts +2 -2
- package/dist/infra/index.js +2 -2
- package/dist/infra/query/QueryBuilder.d.ts +6 -1
- package/dist/infra/query/QueryBuilder.js +14 -12
- package/dist/plugin/AzureNetPlugin.d.ts +1 -4
- package/dist/plugin/AzureNetPlugin.js +21 -64
- package/dist/plugin/index.d.ts +1 -1
- package/dist/server/Context/Runtime.d.ts +3 -0
- package/dist/server/Context/Runtime.js +109 -0
- package/dist/shared/app/App.d.ts +47 -77
- package/dist/shared/app/App.js +80 -106
- package/dist/shared/app/index.d.ts +5 -3
- package/dist/shared/app/middleware/ClientMiddleware.d.ts +14 -8
- package/dist/shared/app/middleware/ClientMiddleware.js +32 -11
- package/dist/shared/app/middleware/ServerMiddleware.d.ts +10 -5
- package/dist/shared/app/middleware/ServerMiddleware.js +3 -3
- package/dist/shared/app/middleware/Types.d.ts +4 -0
- package/dist/shared/app/middleware/Types.js +1 -0
- package/dist/shared/app-error/ErrorRuntime.d.ts +1 -1
- package/dist/shared/app-error/ErrorRuntime.js +4 -3
- package/dist/shared/boundary-provider/CompositionRoot.d.ts +21 -0
- package/dist/shared/boundary-provider/CompositionRoot.js +11 -0
- package/dist/shared/boundary-provider/Provider.d.ts +3 -2
- package/dist/shared/boundary-provider/Provider.js +56 -40
- package/dist/shared/boundary-provider/index.d.ts +1 -0
- package/dist/shared/boundary-provider/index.js +1 -0
- package/dist/shared/cookie/UniversalCookie.js +1 -1
- package/dist/shared/index.d.ts +2 -3
- package/dist/shared/index.js +2 -3
- package/dist/shared/logger/index.js +1 -1
- package/dist/shared/request-context/Internal.d.ts +16 -0
- package/dist/shared/request-context/Internal.js +24 -0
- package/dist/shared/request-context/index.d.ts +1 -0
- package/dist/shared/request-context/index.js +2 -0
- package/dist/svelte/async-signal/AsyncSignal.svelte.d.ts +20 -4
- package/dist/svelte/async-signal/AsyncSignal.svelte.js +53 -13
- package/dist/svelte/async-signal/README.md +89 -0
- package/dist/svelte/index.d.ts +1 -0
- package/dist/svelte/index.js +1 -0
- package/dist/svelte/query/Query.svelte.d.ts +1 -1
- package/dist/svelte/query/Query.svelte.js +14 -6
- package/dist/svelte/query/SearchParamsSync.js +11 -3
- package/dist/{shared → svelte}/redirect/index.d.ts +2 -8
- package/package.json +35 -26
- package/dist/external/edges/Dev.d.ts +0 -1
- package/dist/external/edges/Dev.js +0 -1
- package/dist/external/edges/Edges.d.ts +0 -1
- package/dist/external/edges/Edges.js +0 -1
- package/dist/external/edges/ServerContext.d.ts +0 -1
- package/dist/external/edges/ServerContext.js +0 -1
- package/dist/external/edges/_edges.d.ts +0 -1
- package/dist/external/edges/_edges.js +0 -1
- package/dist/external/i18n/index.d.ts +0 -1
- package/dist/external/i18n/index.js +0 -1
- package/dist/shared/event-bus/EventBus.d.ts +0 -12
- package/dist/shared/event-bus/EventBus.js +0 -3
- package/dist/shared/event-bus/index.d.ts +0 -1
- package/dist/shared/event-bus/index.js +0 -1
- /package/dist/{shared → svelte}/redirect/index.js +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BROWSER } from '../../external/tools/index.js';
|
|
2
|
-
import { RequestContext } from '../../
|
|
2
|
+
import { RequestContext } from '../../shared/request-context/Internal.js';
|
|
3
3
|
export var HttpInstanceFetchMethods;
|
|
4
4
|
(function (HttpInstanceFetchMethods) {
|
|
5
5
|
HttpInstanceFetchMethods["GET"] = "GET";
|
|
@@ -344,15 +344,23 @@ const makeMethod = (method, defaults) => {
|
|
|
344
344
|
}
|
|
345
345
|
};
|
|
346
346
|
};
|
|
347
|
-
export
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
347
|
+
export class HttpServiceInstance {
|
|
348
|
+
defaults;
|
|
349
|
+
get;
|
|
350
|
+
post;
|
|
351
|
+
put;
|
|
352
|
+
delete;
|
|
353
|
+
patch;
|
|
354
|
+
head;
|
|
355
|
+
options;
|
|
356
|
+
constructor(config = {}) {
|
|
357
|
+
this.defaults = { ...config };
|
|
358
|
+
this.get = makeMethod(HttpInstanceFetchMethods.GET, this.defaults);
|
|
359
|
+
this.post = makeMethod(HttpInstanceFetchMethods.POST, this.defaults);
|
|
360
|
+
this.put = makeMethod(HttpInstanceFetchMethods.PUT, this.defaults);
|
|
361
|
+
this.delete = makeMethod(HttpInstanceFetchMethods.DELETE, this.defaults);
|
|
362
|
+
this.patch = makeMethod(HttpInstanceFetchMethods.PATCH, this.defaults);
|
|
363
|
+
this.head = makeMethod(HttpInstanceFetchMethods.HEAD, this.defaults);
|
|
364
|
+
this.options = makeMethod(HttpInstanceFetchMethods.OPTIONS, this.defaults);
|
|
365
|
+
}
|
|
366
|
+
}
|
package/dist/infra/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { BaseHttpDatasource, type CreateRequestCallbackType } from './datasource/index.js';
|
|
2
2
|
export { DTOMapper, type IDTOMapper } from './resource/index.js';
|
|
3
|
-
export { HttpStatusCode,
|
|
3
|
+
export { HttpStatusCode, HttpServiceInstance, HttpInstanceFetchMethods, HttpErrorTypes, HttpServiceResponse, HttpServiceError, type IHttpServiceError, type IHttpServiceResponse, type IHttpServiceInstance, type IHttpInstanceOptions, type IHttpInstanceNormalizedRequest, type IHttpInstanceOnRequest, type IHttpInstanceOnError, type IHttpInstanceDoFetch, type IHttpInstanceRequestMethod } from './http-service/index.js';
|
|
4
4
|
export { ResponseBuilder } from './response/index.js';
|
|
5
|
-
export {
|
|
5
|
+
export { QueryBuilder, type IQueryBuilderInstance, type ArrayFormat, type ObjectFormat, type IQueryBuilderSettings } from './query/QueryBuilder.js';
|
package/dist/infra/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { BaseHttpDatasource } from './datasource/index.js';
|
|
2
2
|
export { DTOMapper } from './resource/index.js';
|
|
3
|
-
export { HttpStatusCode,
|
|
3
|
+
export { HttpStatusCode, HttpServiceInstance, HttpInstanceFetchMethods, HttpErrorTypes, HttpServiceResponse, HttpServiceError } from './http-service/index.js';
|
|
4
4
|
export { ResponseBuilder } from './response/index.js';
|
|
5
|
-
export {
|
|
5
|
+
export { QueryBuilder } from './query/QueryBuilder.js';
|
|
@@ -10,4 +10,9 @@ export interface IQueryBuilderInstance<TTransformInput extends object = object>
|
|
|
10
10
|
toString: (query: object, settings?: IQueryBuilderSettings<TTransformInput>) => string;
|
|
11
11
|
toSearchParams: (query: object, settings?: Omit<IQueryBuilderSettings<TTransformInput>, 'delimiter'>) => URLSearchParams;
|
|
12
12
|
}
|
|
13
|
-
export declare
|
|
13
|
+
export declare class QueryBuilder<TTransformInputGlobal extends object = object> implements IQueryBuilderInstance<TTransformInputGlobal> {
|
|
14
|
+
private readonly defaults;
|
|
15
|
+
constructor(config?: IQueryBuilderSettings<TTransformInputGlobal>);
|
|
16
|
+
readonly toSearchParams: <TTransformInput extends TTransformInputGlobal = TTransformInputGlobal>(query: object, settings?: Omit<IQueryBuilderSettings<TTransformInput>, "delimiter">) => URLSearchParams;
|
|
17
|
+
readonly toString: <TTransformInput extends TTransformInputGlobal = TTransformInputGlobal>(query: object, settings?: IQueryBuilderSettings<TTransformInput>) => string;
|
|
18
|
+
}
|
|
@@ -75,16 +75,18 @@ const toSearchParamsWithSettings = (query, settings) => {
|
|
|
75
75
|
}
|
|
76
76
|
return params;
|
|
77
77
|
};
|
|
78
|
-
export
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const serialized = encodeQuery(Array.from(toSearchParamsWithSettings(query, resolved).entries()));
|
|
87
|
-
return resolved.delimiter && serialized ? `?${serialized}` : serialized;
|
|
88
|
-
}
|
|
78
|
+
export class QueryBuilder {
|
|
79
|
+
defaults;
|
|
80
|
+
constructor(config) {
|
|
81
|
+
this.defaults = { ...config };
|
|
82
|
+
}
|
|
83
|
+
toSearchParams = (query, settings) => {
|
|
84
|
+
const resolved = normalizeSettings(this.defaults, settings);
|
|
85
|
+
return toSearchParamsWithSettings(query, resolved);
|
|
89
86
|
};
|
|
90
|
-
|
|
87
|
+
toString = (query, settings) => {
|
|
88
|
+
const resolved = normalizeSettings(this.defaults, settings);
|
|
89
|
+
const serialized = encodeQuery(Array.from(toSearchParamsWithSettings(query, resolved).entries()));
|
|
90
|
+
return resolved.delimiter && serialized ? `?${serialized}` : serialized;
|
|
91
|
+
};
|
|
92
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url';
|
|
1
2
|
import path from 'node:path';
|
|
2
3
|
import fs from 'node:fs';
|
|
3
|
-
const VIRTUAL_SERVER_UTILS_ID = 'virtual:azure-net-kit/server-utils';
|
|
4
|
-
const RESOLVED_VIRTUAL_SERVER_UTILS_ID = `\0${VIRTUAL_SERVER_UTILS_ID}`;
|
|
5
4
|
const VIRTUAL_SERVER_HOOKS_ID = 'virtual:azure-net-kit/hooks.server';
|
|
6
5
|
const VIRTUAL_CLIENT_HOOKS_ID = 'virtual:azure-net-kit/hooks.client';
|
|
7
6
|
const RESOLVED_VIRTUAL_SERVER_HOOKS_ID = `\0${VIRTUAL_SERVER_HOOKS_ID}`;
|
|
@@ -18,62 +17,21 @@ const findStaticImportInsertPosition = (sourceCode) => {
|
|
|
18
17
|
}
|
|
19
18
|
return lastMatch ? lastMatch.index + lastMatch[0].length : 0;
|
|
20
19
|
};
|
|
21
|
-
const createVirtualServerHooks = (
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
|
|
20
|
+
const createVirtualServerHooks = () => `// ${GENERATED_MARKER}
|
|
21
|
+
import { runRequest } from '@azure-net/kit/internal/server';
|
|
22
|
+
import { render } from 'svelte/server';
|
|
25
23
|
const getRegister = async () => (await import('${VIRTUAL_PROGRAM_ID}')).register;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
} catch {
|
|
31
|
-
return edgesHandleRaw(event, callback);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return callback();
|
|
24
|
+
export const init = async () => {
|
|
25
|
+
// Initialize Svelte's cached async-render promise outside any request ALS scope.
|
|
26
|
+
await render(() => {});
|
|
27
|
+
return (await getRegister()).serverInit();
|
|
35
28
|
};
|
|
36
|
-
|
|
37
|
-
export const
|
|
38
|
-
export const
|
|
39
|
-
export const handleValidationError = (input) => withRequestContext(
|
|
40
|
-
input.event,
|
|
41
|
-
async () => (await getRegister()).serverValidationError(input)
|
|
42
|
-
);
|
|
29
|
+
export const handle = (input) => runRequest(input.event, async () => (await getRegister()).handle(input));
|
|
30
|
+
export const handleFetch = (input) => runRequest(input.event, async () => (await getRegister()).serverFetch(input));
|
|
31
|
+
export const handleError = (input) => runRequest(input.event, async () => (await getRegister()).serverError(input));
|
|
43
32
|
export const reroute = async (input) => (await getRegister()).reroute(input);
|
|
44
33
|
export const getTransport = async () => (await getRegister()).transport;
|
|
45
|
-
|
|
46
|
-
export const handle = edgesHandle(async ({ serialize, edgesEvent, resolve }) => {
|
|
47
|
-
const register = await getRegister();
|
|
48
|
-
|
|
49
|
-
return register.handle({
|
|
50
|
-
event: edgesEvent,
|
|
51
|
-
resolve: (event, options) =>
|
|
52
|
-
resolve(event, {
|
|
53
|
-
...options,
|
|
54
|
-
transformPageChunk: async (chunk) => {
|
|
55
|
-
const html = (options?.transformPageChunk ? await options.transformPageChunk(chunk) : undefined) ?? chunk.html;
|
|
56
|
-
return serialize(html);
|
|
57
|
-
}
|
|
58
|
-
})
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
${silentChromeDevtools ? ')' : ', false)'};
|
|
62
|
-
|
|
63
|
-
export const handleError = async ({ error, event, status, message }) => {
|
|
64
|
-
let result;
|
|
65
|
-
|
|
66
|
-
await edgesHandleRaw(event, async () => {
|
|
67
|
-
const register = await getRegister();
|
|
68
|
-
result = await register.serverError({ error, event, status, message });
|
|
69
|
-
|
|
70
|
-
return new Response(null, { status: 204 });
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
return result;
|
|
74
|
-
};
|
|
75
34
|
`;
|
|
76
|
-
const createVirtualServerUtils = () => "export { edgesHandle, edgesHandleRaw } from '@azure-net/kit/edges/internal-package/utils';";
|
|
77
35
|
const createVirtualClientHooks = () => `// ${GENERATED_MARKER}
|
|
78
36
|
const getRegister = async () => (await import('${VIRTUAL_PROGRAM_ID}')).register;
|
|
79
37
|
|
|
@@ -155,7 +113,6 @@ const transformGeneratedServerInternal = (sourceCode) => {
|
|
|
155
113
|
\t\thandle: __azureNetServerHooks.handle,
|
|
156
114
|
\t\thandleFetch: __azureNetServerHooks.handleFetch,
|
|
157
115
|
\t\thandleError: __azureNetServerHooks.handleError,
|
|
158
|
-
\t\thandleValidationError: __azureNetServerHooks.handleValidationError,
|
|
159
116
|
\t\tinit: __azureNetServerHooks.init,
|
|
160
117
|
\t\treroute: __azureNetServerHooks.reroute,
|
|
161
118
|
\t\ttransport: await __azureNetServerHooks.getTransport()
|
|
@@ -170,7 +127,7 @@ const transformGeneratedClientApp = (sourceCode) => {
|
|
|
170
127
|
if (/hooks\.client\.(?:ts|js)/.test(sourceCode)) {
|
|
171
128
|
throw new Error('[AzureNetPlugin] SvelteKit detected a user-managed hooks.client file. Move its lifecycle code to src/program.ts via createApp().');
|
|
172
129
|
}
|
|
173
|
-
const handleErrorPattern = /handleError:\s*\(\(\{\s*error\s*\}\)\s*=>\s*\{\s*console\.error\(error\)
|
|
130
|
+
const handleErrorPattern = /handleError:\s*\(\(\{\s*(?:kind,\s*)?error\s*\}\)\s*=>\s*\{\s*(?:if\s*\(kind === ['"]unknown['"]\)\s*\{\s*)?console\.error\(error\);?\s*\}\s*(?:\}\s*)?\)/m;
|
|
174
131
|
if (!handleErrorPattern.test(sourceCode)) {
|
|
175
132
|
throw new Error('[AzureNetPlugin] Unsupported SvelteKit generated client app: default handleError was not found.');
|
|
176
133
|
}
|
|
@@ -193,8 +150,7 @@ const transformGeneratedClientApp = (sourceCode) => {
|
|
|
193
150
|
transformed = transformed.replace(encodersPattern, 'export const encoders = __azureNetClientHooks.encoders;');
|
|
194
151
|
return transformed;
|
|
195
152
|
};
|
|
196
|
-
export const AzureNetPlugin = (
|
|
197
|
-
const { silentChromeDevtools = true } = options ?? {};
|
|
153
|
+
export const AzureNetPlugin = () => {
|
|
198
154
|
let root = process.cwd();
|
|
199
155
|
return {
|
|
200
156
|
name: 'azure-net-kit-plugin',
|
|
@@ -214,8 +170,10 @@ export const AzureNetPlugin = (options) => {
|
|
|
214
170
|
assertProgramExists(root);
|
|
215
171
|
},
|
|
216
172
|
resolveId(id) {
|
|
217
|
-
if (id ===
|
|
218
|
-
|
|
173
|
+
if (id === '@azure-net/kit/internal/server') {
|
|
174
|
+
const runtime = fileURLToPath(new URL('../server/Context/Runtime.js', import.meta.url));
|
|
175
|
+
return fs.existsSync(runtime) ? runtime : runtime.replace(/\.js$/, '.ts');
|
|
176
|
+
}
|
|
219
177
|
if (id === VIRTUAL_SERVER_HOOKS_ID)
|
|
220
178
|
return RESOLVED_VIRTUAL_SERVER_HOOKS_ID;
|
|
221
179
|
if (id === VIRTUAL_CLIENT_HOOKS_ID)
|
|
@@ -225,10 +183,8 @@ export const AzureNetPlugin = (options) => {
|
|
|
225
183
|
return null;
|
|
226
184
|
},
|
|
227
185
|
load(id) {
|
|
228
|
-
if (id === RESOLVED_VIRTUAL_SERVER_UTILS_ID)
|
|
229
|
-
return createVirtualServerUtils();
|
|
230
186
|
if (id === RESOLVED_VIRTUAL_SERVER_HOOKS_ID)
|
|
231
|
-
return createVirtualServerHooks(
|
|
187
|
+
return createVirtualServerHooks();
|
|
232
188
|
if (id === RESOLVED_VIRTUAL_CLIENT_HOOKS_ID)
|
|
233
189
|
return createVirtualClientHooks();
|
|
234
190
|
if (id === RESOLVED_VIRTUAL_PROGRAM_ID)
|
|
@@ -237,11 +193,12 @@ export const AzureNetPlugin = (options) => {
|
|
|
237
193
|
},
|
|
238
194
|
transform(code, id) {
|
|
239
195
|
const normalizedId = id.split('?')[0].split(path.sep).join('/');
|
|
240
|
-
if (normalizedId.endsWith('/.svelte-kit/generated/server/internal.js')
|
|
196
|
+
if (normalizedId.endsWith('/.svelte-kit/generated/server/internal.js') ||
|
|
197
|
+
/\/.svelte-kit\/generated\/(?:build|dev)\/server\.js$/.test(normalizedId)) {
|
|
241
198
|
const transformed = transformGeneratedServerInternal(code);
|
|
242
199
|
return transformed ? { code: transformed, map: null } : null;
|
|
243
200
|
}
|
|
244
|
-
if (
|
|
201
|
+
if (/\/.svelte-kit\/generated\/(?:(?:build|dev)\/)?client(?:-optimized)?\/app\.js$/.test(normalizedId)) {
|
|
245
202
|
const transformed = transformGeneratedClientApp(code);
|
|
246
203
|
return transformed ? { code: transformed, map: null } : null;
|
|
247
204
|
}
|
package/dist/plugin/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { AzureNetPlugin
|
|
1
|
+
export { AzureNetPlugin } from './AzureNetPlugin.js';
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import '$app/server';
|
|
2
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
3
|
+
import { initializeRequestContext, getContextInternals } from '../../shared/request-context/Internal.js';
|
|
4
|
+
// Cached import promises may retain their ALS store forever. The store must not
|
|
5
|
+
// strongly own a completed request, while pending work still needs a live context.
|
|
6
|
+
const storage = new AsyncLocalStorage();
|
|
7
|
+
const contexts = new WeakMap();
|
|
8
|
+
const scopes = new WeakMap();
|
|
9
|
+
const currentContext = () => storage.getStore()?.ref.deref();
|
|
10
|
+
initializeRequestContext(currentContext);
|
|
11
|
+
function release(scope) {
|
|
12
|
+
if (--scope.leases === 0)
|
|
13
|
+
scope.active = undefined;
|
|
14
|
+
}
|
|
15
|
+
function retainResponse(response, scope) {
|
|
16
|
+
if (!response.body)
|
|
17
|
+
return response;
|
|
18
|
+
let reader = response.body.getReader();
|
|
19
|
+
// Keep this lease on the stream, not the ALS store: abandoned responses must
|
|
20
|
+
// also be collectible without requiring callers to explicitly consume them.
|
|
21
|
+
let context = scope.active;
|
|
22
|
+
const finish = () => {
|
|
23
|
+
if (!reader)
|
|
24
|
+
return;
|
|
25
|
+
reader.releaseLock();
|
|
26
|
+
reader = undefined;
|
|
27
|
+
context = undefined;
|
|
28
|
+
};
|
|
29
|
+
const body = new ReadableStream({
|
|
30
|
+
async pull(controller) {
|
|
31
|
+
if (!context || !reader)
|
|
32
|
+
return;
|
|
33
|
+
try {
|
|
34
|
+
const chunk = await storage.run(scope, () => reader.read());
|
|
35
|
+
if (chunk.done) {
|
|
36
|
+
finish();
|
|
37
|
+
controller.close();
|
|
38
|
+
}
|
|
39
|
+
else
|
|
40
|
+
controller.enqueue(chunk.value);
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
finish();
|
|
44
|
+
controller.error(error);
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
async cancel(reason) {
|
|
48
|
+
try {
|
|
49
|
+
await storage.run(scope, () => reader?.cancel(reason));
|
|
50
|
+
}
|
|
51
|
+
finally {
|
|
52
|
+
finish();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
const retained = new Response(body, { status: response.status, statusText: response.statusText, headers: response.headers });
|
|
57
|
+
// Fetch response metadata is not copied by the Response constructor.
|
|
58
|
+
Object.defineProperties(retained, {
|
|
59
|
+
url: { value: response.url },
|
|
60
|
+
redirected: { value: response.redirected },
|
|
61
|
+
type: { value: response.type }
|
|
62
|
+
});
|
|
63
|
+
return retained;
|
|
64
|
+
}
|
|
65
|
+
function complete(value, scope) {
|
|
66
|
+
try {
|
|
67
|
+
return (value instanceof Response ? retainResponse(value, scope) : value);
|
|
68
|
+
}
|
|
69
|
+
finally {
|
|
70
|
+
release(scope);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function invoke(scope, callback) {
|
|
74
|
+
let value;
|
|
75
|
+
let promise;
|
|
76
|
+
try {
|
|
77
|
+
value = callback();
|
|
78
|
+
if (value && typeof value.then === 'function')
|
|
79
|
+
promise = Promise.resolve(value);
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
release(scope);
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
if (promise) {
|
|
86
|
+
return promise.then((result) => complete(result, scope), (error) => {
|
|
87
|
+
release(scope);
|
|
88
|
+
throw error;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return complete(value, scope);
|
|
92
|
+
}
|
|
93
|
+
export function runRequest(event, callback) {
|
|
94
|
+
initializeRequestContext(currentContext);
|
|
95
|
+
let context = contexts.get(event);
|
|
96
|
+
if (!context) {
|
|
97
|
+
context = Object.freeze({ event, state: {} });
|
|
98
|
+
contexts.set(event, context);
|
|
99
|
+
getContextInternals(context).requestId = Symbol('request');
|
|
100
|
+
}
|
|
101
|
+
let scope = scopes.get(context);
|
|
102
|
+
if (!scope) {
|
|
103
|
+
scope = { ref: new WeakRef(context), leases: 0 };
|
|
104
|
+
scopes.set(context, scope);
|
|
105
|
+
}
|
|
106
|
+
scope.active = context;
|
|
107
|
+
scope.leases++;
|
|
108
|
+
return storage.run(scope, () => invoke(scope, callback));
|
|
109
|
+
}
|
package/dist/shared/app/App.d.ts
CHANGED
|
@@ -1,74 +1,44 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type TranslationManagerSource } from '../../i18n/Internal.js';
|
|
2
|
+
import { type ContextData } from '../../shared/request-context/Internal.js';
|
|
2
3
|
import { AppError, type IAppError } from '../app-error/AppError.js';
|
|
3
4
|
import { type AsyncHelperRetry } from '../app-error/ErrorRuntime.js';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import type {
|
|
7
|
-
import { type
|
|
5
|
+
import { type ServerMiddlewareClass } from './middleware/ServerMiddleware.js';
|
|
6
|
+
import type { Handle, HandleFetch, HandleServerError, HandleClientError, Reroute, ServerInit, Transport } from '@sveltejs/kit/hooks';
|
|
7
|
+
import type { RequestEvent } from '@sveltejs/kit';
|
|
8
|
+
import { type ClientMiddlewareClass } from './middleware/ClientMiddleware.js';
|
|
8
9
|
import { useLogger } from '../logger/index.js';
|
|
9
10
|
type MaybePromise<T> = T | Promise<T>;
|
|
10
11
|
type HandleInput = Parameters<Handle>[0];
|
|
11
12
|
type Resolve = HandleInput['resolve'];
|
|
12
|
-
type
|
|
13
|
-
type AppDependencyFactories<TApp> = Record<string, AppDependencyFactory<TApp>>;
|
|
14
|
-
type ResolvedDependencies<T> = {
|
|
15
|
-
[K in keyof T]: T[K] extends (...args: never[]) => infer TReturn ? TReturn : never;
|
|
16
|
-
};
|
|
17
|
-
type BuilderFlags = Partial<Record<'use' | 'useClient' | 'useClientInit' | 'useClientError' | 'useServerInit' | 'useServer' | 'useServerError' | 'useServerFetch' | 'useServerValidationError' | 'useAzureNetKitError' | 'useReroute' | 'useTransport', true>>;
|
|
13
|
+
type BuilderFlags = Partial<Record<'useTranslations' | 'useBoot' | 'use' | 'useClient' | 'useClientInit' | 'useClientError' | 'useServerInit' | 'useServer' | 'useServerError' | 'useServerFetch' | 'useAzureNetKitError' | 'useReroute' | 'useTransport', true>>;
|
|
18
14
|
type WithFlag<TFlags extends BuilderFlags, TKey extends keyof BuilderFlags> = TFlags & Record<TKey, true>;
|
|
19
|
-
type BuilderDependencies<TBuilder> = TBuilder extends {
|
|
20
|
-
readonly __types__?: infer TDependencies;
|
|
21
|
-
} ? TDependencies : never;
|
|
22
15
|
type OnceMethod<TFlags extends BuilderFlags, TKey extends keyof BuilderFlags, TMethod> = TFlags[TKey] extends true ? object : TMethod;
|
|
23
|
-
export
|
|
24
|
-
export interface AppUniversalLifecycleContext<TDependencies extends Record<string, unknown>> {
|
|
25
|
-
Container: AppContainer<TDependencies>;
|
|
16
|
+
export interface AppUniversalLifecycleContext {
|
|
26
17
|
isClient: boolean;
|
|
27
18
|
isServer: boolean;
|
|
28
19
|
requestContext?: ContextData;
|
|
29
20
|
event?: RequestEvent;
|
|
30
21
|
}
|
|
31
|
-
export interface AppClientLifecycleContext
|
|
32
|
-
|
|
33
|
-
useMiddlewares: (middlewares: IClientMiddleware[]) => void;
|
|
34
|
-
}
|
|
35
|
-
export interface AppClientInitLifecycleContext<TDependencies extends Record<string, unknown>> {
|
|
36
|
-
Container: AppContainer<TDependencies>;
|
|
37
|
-
}
|
|
38
|
-
export interface AppClientErrorContext<TDependencies extends Record<string, unknown>> extends Omit<AppClientLifecycleContext<TDependencies>, 'useMiddlewares'> {
|
|
39
|
-
error: unknown;
|
|
40
|
-
event: Parameters<HandleClientError>[0]['event'];
|
|
41
|
-
status: number;
|
|
42
|
-
message: string;
|
|
22
|
+
export interface AppClientLifecycleContext {
|
|
23
|
+
useMiddlewares: (middlewares: readonly ClientMiddlewareClass[]) => void;
|
|
43
24
|
}
|
|
25
|
+
export type AppClientInitLifecycleContext = void;
|
|
26
|
+
export type AppClientErrorContext = Parameters<HandleClientError>[0];
|
|
44
27
|
export type AppServerInitLifecycleContext = void;
|
|
45
|
-
export interface AppServerLifecycleContext
|
|
46
|
-
Container: AppContainer<TDependencies>;
|
|
28
|
+
export interface AppServerLifecycleContext {
|
|
47
29
|
requestContext: ContextData;
|
|
48
30
|
event: RequestEvent;
|
|
49
31
|
resolve: Resolve;
|
|
50
|
-
useMiddlewares: (middlewares:
|
|
32
|
+
useMiddlewares: (middlewares: readonly ServerMiddlewareClass[]) => Promise<void>;
|
|
51
33
|
}
|
|
52
|
-
export
|
|
53
|
-
Container: AppContainer<TDependencies>;
|
|
34
|
+
export type AppServerErrorContext = Parameters<HandleServerError>[0] & {
|
|
54
35
|
requestContext: ContextData;
|
|
55
|
-
error: unknown;
|
|
56
|
-
event: RequestEvent;
|
|
57
|
-
status: number;
|
|
58
|
-
message: string;
|
|
59
36
|
useLogger: typeof useLogger;
|
|
60
|
-
}
|
|
61
|
-
export type AppServerFetchContext<TDependencies extends Record<string, unknown>> = Parameters<HandleFetch>[0] & {
|
|
62
|
-
Container: AppContainer<TDependencies>;
|
|
63
|
-
requestContext: ContextData;
|
|
64
37
|
};
|
|
65
|
-
export type
|
|
66
|
-
Container: AppContainer<TDependencies>;
|
|
38
|
+
export type AppServerFetchContext = Parameters<HandleFetch>[0] & {
|
|
67
39
|
requestContext: ContextData;
|
|
68
40
|
};
|
|
69
|
-
export interface AppAzureNetKitErrorContext
|
|
70
|
-
Container: AppContainer<TDependencies>;
|
|
71
|
-
AppEvents: typeof AppEvents;
|
|
41
|
+
export interface AppAzureNetKitErrorContext {
|
|
72
42
|
error: AppError;
|
|
73
43
|
retry: AsyncHelperRetry;
|
|
74
44
|
isClient: boolean;
|
|
@@ -76,44 +46,46 @@ export interface AppAzureNetKitErrorContext<TDependencies extends Record<string,
|
|
|
76
46
|
requestContext?: ContextData;
|
|
77
47
|
event?: RequestEvent;
|
|
78
48
|
}
|
|
79
|
-
export type AppUniversalLifecycleCallback
|
|
80
|
-
export type AppClientLifecycleCallback
|
|
81
|
-
export type AppClientInitLifecycleCallback
|
|
82
|
-
export type AppClientErrorCallback
|
|
49
|
+
export type AppUniversalLifecycleCallback = (context: AppUniversalLifecycleContext) => MaybePromise<void>;
|
|
50
|
+
export type AppClientLifecycleCallback = (context: AppClientLifecycleContext) => MaybePromise<void>;
|
|
51
|
+
export type AppClientInitLifecycleCallback = (context: AppClientInitLifecycleContext) => MaybePromise<void>;
|
|
52
|
+
export type AppClientErrorCallback = (context: AppClientErrorContext) => ReturnType<HandleClientError>;
|
|
83
53
|
export type AppServerInitLifecycleCallback = ServerInit;
|
|
84
|
-
export type AppServerLifecycleCallback
|
|
85
|
-
export type AppServerErrorCallback
|
|
86
|
-
export type AppServerFetchCallback
|
|
87
|
-
export type
|
|
88
|
-
export type AppAzureNetKitErrorCallback<TDependencies extends Record<string, unknown>> = (context: AppAzureNetKitErrorContext<TDependencies>) => MaybePromise<IAppError & object>;
|
|
54
|
+
export type AppServerLifecycleCallback = (context: AppServerLifecycleContext) => MaybePromise<Response | void>;
|
|
55
|
+
export type AppServerErrorCallback = (context: AppServerErrorContext) => ReturnType<HandleServerError>;
|
|
56
|
+
export type AppServerFetchCallback = (context: AppServerFetchContext) => ReturnType<HandleFetch>;
|
|
57
|
+
export type AppAzureNetKitErrorCallback = (context: AppAzureNetKitErrorContext) => MaybePromise<IAppError & object>;
|
|
89
58
|
export type AppRerouteCallback = Reroute;
|
|
90
|
-
export
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
59
|
+
export interface AppBootContext {
|
|
60
|
+
state: App.RequestContextState;
|
|
61
|
+
}
|
|
62
|
+
export type AppBootCallback = (context: AppBootContext) => undefined;
|
|
63
|
+
export type CreateAppBuilder<TFlags extends BuilderFlags = object> = OnceMethod<TFlags, 'useBoot', {
|
|
64
|
+
useBoot(callback: AppBootCallback): CreateAppBuilder<WithFlag<TFlags, 'useBoot'>>;
|
|
65
|
+
}> & OnceMethod<TFlags, 'useTranslations', {
|
|
66
|
+
useTranslations(manager: TranslationManagerSource): CreateAppBuilder<WithFlag<TFlags, 'useTranslations'>>;
|
|
67
|
+
}> & OnceMethod<TFlags, 'use', {
|
|
68
|
+
use(callback: AppUniversalLifecycleCallback): CreateAppBuilder<WithFlag<TFlags, 'use'>>;
|
|
95
69
|
}> & OnceMethod<TFlags, 'useClient', {
|
|
96
|
-
useClient(callback: AppClientLifecycleCallback
|
|
70
|
+
useClient(callback: AppClientLifecycleCallback): CreateAppBuilder<WithFlag<TFlags, 'useClient'>>;
|
|
97
71
|
}> & OnceMethod<TFlags, 'useClientInit', {
|
|
98
|
-
useClientInit(callback: AppClientInitLifecycleCallback
|
|
72
|
+
useClientInit(callback: AppClientInitLifecycleCallback): CreateAppBuilder<WithFlag<TFlags, 'useClientInit'>>;
|
|
99
73
|
}> & OnceMethod<TFlags, 'useClientError', {
|
|
100
|
-
useClientError(callback: AppClientErrorCallback
|
|
74
|
+
useClientError(callback: AppClientErrorCallback): CreateAppBuilder<WithFlag<TFlags, 'useClientError'>>;
|
|
101
75
|
}> & OnceMethod<TFlags, 'useServerInit', {
|
|
102
|
-
useServerInit(callback: AppServerInitLifecycleCallback): CreateAppBuilder<
|
|
76
|
+
useServerInit(callback: AppServerInitLifecycleCallback): CreateAppBuilder<WithFlag<TFlags, 'useServerInit'>>;
|
|
103
77
|
}> & OnceMethod<TFlags, 'useServer', {
|
|
104
|
-
useServer(callback: AppServerLifecycleCallback
|
|
78
|
+
useServer(callback: AppServerLifecycleCallback): CreateAppBuilder<WithFlag<TFlags, 'useServer'>>;
|
|
105
79
|
}> & OnceMethod<TFlags, 'useServerError', {
|
|
106
|
-
useServerError(callback: AppServerErrorCallback
|
|
80
|
+
useServerError(callback: AppServerErrorCallback): CreateAppBuilder<WithFlag<TFlags, 'useServerError'>>;
|
|
107
81
|
}> & OnceMethod<TFlags, 'useServerFetch', {
|
|
108
|
-
useServerFetch(callback: AppServerFetchCallback
|
|
109
|
-
}> & OnceMethod<TFlags, 'useServerValidationError', {
|
|
110
|
-
useServerValidationError(callback: AppServerValidationErrorCallback<TDependencies>): CreateAppBuilder<TDependencies, WithFlag<TFlags, 'useServerValidationError'>>;
|
|
82
|
+
useServerFetch(callback: AppServerFetchCallback): CreateAppBuilder<WithFlag<TFlags, 'useServerFetch'>>;
|
|
111
83
|
}> & OnceMethod<TFlags, 'useAzureNetKitError', {
|
|
112
|
-
useAzureNetKitError(callback: AppAzureNetKitErrorCallback
|
|
84
|
+
useAzureNetKitError(callback: AppAzureNetKitErrorCallback): CreateAppBuilder<WithFlag<TFlags, 'useAzureNetKitError'>>;
|
|
113
85
|
}> & OnceMethod<TFlags, 'useReroute', {
|
|
114
|
-
useReroute(callback: AppRerouteCallback): CreateAppBuilder<
|
|
86
|
+
useReroute(callback: AppRerouteCallback): CreateAppBuilder<WithFlag<TFlags, 'useReroute'>>;
|
|
115
87
|
}> & OnceMethod<TFlags, 'useTransport', {
|
|
116
|
-
useTransport(transport: Transport): CreateAppBuilder<
|
|
88
|
+
useTransport(transport: Transport): CreateAppBuilder<WithFlag<TFlags, 'useTransport'>>;
|
|
117
89
|
}>;
|
|
118
90
|
export interface AppRegistrar {
|
|
119
91
|
(): MaybePromise<void>;
|
|
@@ -122,14 +94,12 @@ export interface AppRegistrar {
|
|
|
122
94
|
serverInit: ServerInit;
|
|
123
95
|
serverError: HandleServerError;
|
|
124
96
|
serverFetch: HandleFetch;
|
|
125
|
-
serverValidationError: HandleValidationError;
|
|
126
97
|
handle: Handle;
|
|
127
98
|
reroute: Reroute;
|
|
128
99
|
transport: Transport;
|
|
129
100
|
}
|
|
130
|
-
export interface CreateAppInstance
|
|
131
|
-
Container: AppContainer<TDependencies>;
|
|
101
|
+
export interface CreateAppInstance {
|
|
132
102
|
register: AppRegistrar;
|
|
133
103
|
}
|
|
134
|
-
export declare const createApp:
|
|
104
|
+
export declare const createApp: (callback: (app: CreateAppBuilder) => unknown) => CreateAppInstance;
|
|
135
105
|
export {};
|