@azure-net/kit 6.0.0-next.1 → 6.0.0-next.3

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 (69) hide show
  1. package/README.md +178 -2
  2. package/dist/delivery/index.d.ts +2 -1
  3. package/dist/delivery/index.js +2 -1
  4. package/dist/delivery/injectable-dependencies/AsyncHelpers.d.ts +2 -4
  5. package/dist/delivery/injectable-dependencies/AsyncHelpers.js +96 -102
  6. package/dist/delivery/presenter/RegisterProvider.d.ts +9 -0
  7. package/dist/delivery/presenter/RegisterProvider.js +51 -0
  8. package/dist/delivery.d.ts +0 -1
  9. package/dist/delivery.js +0 -1
  10. package/dist/i18n/Internal.d.ts +13 -0
  11. package/dist/i18n/Internal.js +10 -0
  12. package/dist/i18n/Translations.svelte.d.ts +20 -0
  13. package/dist/i18n/Translations.svelte.js +254 -0
  14. package/dist/i18n/Types.d.ts +30 -0
  15. package/dist/i18n/Types.js +1 -0
  16. package/dist/i18n/index.d.ts +2 -0
  17. package/dist/i18n/index.js +1 -0
  18. package/dist/infra/datasource/BaseDatasource.d.ts +19 -6
  19. package/dist/infra/datasource/BaseDatasource.js +4 -4
  20. package/dist/infra/http-service/HttpServiceInstance.d.ts +26 -16
  21. package/dist/infra/http-service/HttpServiceInstance.js +21 -13
  22. package/dist/infra/index.d.ts +2 -2
  23. package/dist/infra/index.js +2 -2
  24. package/dist/infra/query/QueryBuilder.d.ts +6 -1
  25. package/dist/infra/query/QueryBuilder.js +14 -12
  26. package/dist/plugin/AzureNetPlugin.d.ts +1 -4
  27. package/dist/plugin/AzureNetPlugin.js +16 -64
  28. package/dist/plugin/index.d.ts +1 -1
  29. package/dist/server/Context/Runtime.d.ts +2 -0
  30. package/dist/server/Context/Runtime.js +18 -0
  31. package/dist/server/Context/index.d.ts +1 -0
  32. package/dist/server/Context/index.js +1 -0
  33. package/dist/shared/app/App.d.ts +44 -69
  34. package/dist/shared/app/App.js +91 -102
  35. package/dist/shared/app/index.d.ts +2 -1
  36. package/dist/shared/app/middleware/ClientMiddleware.d.ts +2 -2
  37. package/dist/shared/app/middleware/ClientMiddleware.js +0 -1
  38. package/dist/shared/app/middleware/ServerMiddleware.d.ts +1 -1
  39. package/dist/shared/app/middleware/ServerMiddleware.js +1 -1
  40. package/dist/shared/app-error/ErrorRuntime.d.ts +1 -1
  41. package/dist/shared/app-error/ErrorRuntime.js +4 -3
  42. package/dist/shared/boundary-provider/Provider.d.ts +1 -1
  43. package/dist/shared/boundary-provider/Provider.js +44 -29
  44. package/dist/shared/cookie/UniversalCookie.js +1 -1
  45. package/dist/shared/index.d.ts +1 -3
  46. package/dist/shared/index.js +1 -3
  47. package/dist/shared/logger/index.js +1 -1
  48. package/dist/shared/request-context/Internal.d.ts +16 -0
  49. package/dist/shared/request-context/Internal.js +24 -0
  50. package/dist/svelte/index.d.ts +1 -0
  51. package/dist/svelte/index.js +1 -0
  52. package/dist/svelte/query/Query.svelte.js +4 -2
  53. package/package.json +30 -21
  54. package/dist/external/edges/Dev.d.ts +0 -1
  55. package/dist/external/edges/Dev.js +0 -1
  56. package/dist/external/edges/Edges.d.ts +0 -1
  57. package/dist/external/edges/Edges.js +0 -1
  58. package/dist/external/edges/ServerContext.d.ts +0 -1
  59. package/dist/external/edges/ServerContext.js +0 -1
  60. package/dist/external/edges/_edges.d.ts +0 -1
  61. package/dist/external/edges/_edges.js +0 -1
  62. package/dist/external/i18n/index.d.ts +0 -1
  63. package/dist/external/i18n/index.js +0 -1
  64. package/dist/shared/event-bus/EventBus.d.ts +0 -12
  65. package/dist/shared/event-bus/EventBus.js +0 -3
  66. package/dist/shared/event-bus/index.d.ts +0 -1
  67. package/dist/shared/event-bus/index.js +0 -1
  68. /package/dist/{shared → svelte}/redirect/index.d.ts +0 -0
  69. /package/dist/{shared → svelte}/redirect/index.js +0 -0
@@ -1,14 +1,23 @@
1
+ import { getTranslationLifecycle } from '../../i18n/Internal.js';
2
+ import { hydratable } from 'svelte';
3
+ import { getContextInternals } from '../../shared/request-context/Internal.js';
1
4
  import { BROWSER } from '../../external/tools/index.js';
2
- import { RequestContext } from '../../external/edges/ServerContext.js';
3
- import { createBoundaryProvider } from '../boundary-provider/Provider.js';
5
+ import { RequestContext } from '../../shared/request-context/Internal.js';
4
6
  import { AppError, AzureNetKitInternalError } from '../app-error/AppError.js';
5
7
  import { bindAzureNetKitErrorResolver } from '../app-error/ErrorRuntime.js';
6
- import { AppEvents } from '../event-bus/EventBus.js';
7
8
  import { executeServerMiddlewares } from './middleware/ServerMiddleware.js';
8
9
  import { beforeNavigate } from '$app/navigation';
9
10
  import { executeClientMiddlewares } from './middleware/ClientMiddleware.js';
10
11
  import { useLogger } from '../logger/index.js';
11
- const DEFAULT_APP_NAME = '__AzureNetKitGlobalAppContainer__';
12
+ // Kit 3 nests safe status/message inside caught errors; unknown errors keep safe defaults.
13
+ const errorDetails = (input) => {
14
+ const legacy = input;
15
+ const error = input.kind !== 'unknown' && input.error && typeof input.error === 'object' ? input.error : {};
16
+ return {
17
+ status: typeof legacy.status === 'number' ? legacy.status : typeof error.status === 'number' ? error.status : 500,
18
+ message: typeof legacy.message === 'string' ? legacy.message : typeof error.message === 'string' ? error.message : 'Internal Error'
19
+ };
20
+ };
12
21
  const clientLifecycleFlags = new WeakMap();
13
22
  const getRequestContext = () => {
14
23
  try {
@@ -37,7 +46,7 @@ const getLifecycleFlags = (appKey, requestContext) => {
37
46
  if (!context) {
38
47
  throw new AzureNetKitInternalError('[createApp] RequestContext is not initialized on server.');
39
48
  }
40
- const flagsMap = (context.data.appLifecycleFlags ??= new WeakMap());
49
+ const flagsMap = (getContextInternals(context).appLifecycleFlags ??= new WeakMap());
41
50
  let flags = flagsMap.get(appKey);
42
51
  if (!flags) {
43
52
  flags = {};
@@ -51,8 +60,16 @@ const setCallback = (callbacks, key, callback) => {
51
60
  }
52
61
  callbacks[key] = callback;
53
62
  };
54
- const createBuilder = (dependencies, callbacks) => {
63
+ const createBuilder = (callbacks) => {
55
64
  const builder = {
65
+ useTranslations(manager) {
66
+ setCallback(callbacks, 'useTranslations', manager);
67
+ return builder;
68
+ },
69
+ useBoot(callback) {
70
+ setCallback(callbacks, 'useBoot', callback);
71
+ return builder;
72
+ },
56
73
  use(callback) {
57
74
  setCallback(callbacks, 'use', callback);
58
75
  return builder;
@@ -85,10 +102,6 @@ const createBuilder = (dependencies, callbacks) => {
85
102
  setCallback(callbacks, 'useServerFetch', callback);
86
103
  return builder;
87
104
  },
88
- useServerValidationError(callback) {
89
- setCallback(callbacks, 'useServerValidationError', callback);
90
- return builder;
91
- },
92
105
  useAzureNetKitError(callback) {
93
106
  setCallback(callbacks, 'useAzureNetKitError', callback);
94
107
  return builder;
@@ -100,60 +113,21 @@ const createBuilder = (dependencies, callbacks) => {
100
113
  useTransport(transport) {
101
114
  setCallback(callbacks, 'useTransport', transport);
102
115
  return builder;
103
- },
104
- dependencies(nextDependencies) {
105
- for (const [key, factory] of Object.entries(nextDependencies)) {
106
- dependencies.set(key, factory);
107
- }
108
- return builder;
109
116
  }
110
117
  };
111
118
  return builder;
112
119
  };
113
- export const createApp = (callback, name = DEFAULT_APP_NAME) => {
120
+ export const createApp = (callback) => {
114
121
  const appKey = {};
115
- const dependencies = new Map();
116
122
  const callbacks = {};
117
123
  let clientInitialized = false;
124
+ let translationInitPromise;
118
125
  let serverInitPromise;
119
- callback(createBuilder(dependencies, callbacks));
120
- const AppProvider = createBoundaryProvider(name, {
121
- register: () => {
122
- const factories = {};
123
- for (const [key, factory] of dependencies.entries()) {
124
- factories[key] = () => factory(Container);
125
- }
126
- return factories;
127
- }
128
- });
129
- const Container = new Proxy({}, {
130
- get(_, key) {
131
- if (typeof key === 'symbol')
132
- return undefined;
133
- return AppProvider()[key];
134
- },
135
- has(_, key) {
136
- return typeof key === 'string' && key in AppProvider();
137
- },
138
- ownKeys() {
139
- return Reflect.ownKeys(AppProvider());
140
- },
141
- getOwnPropertyDescriptor(_, key) {
142
- if (typeof key !== 'string' || !(key in AppProvider()))
143
- return undefined;
144
- return {
145
- configurable: true,
146
- enumerable: true,
147
- value: AppProvider()[key]
148
- };
149
- }
150
- });
126
+ callback(createBuilder(callbacks));
151
127
  const errorResolver = callbacks.useAzureNetKitError
152
128
  ? (error, retry) => {
153
129
  const requestContext = BROWSER ? undefined : getRequestContext();
154
130
  return callbacks.useAzureNetKitError({
155
- Container,
156
- AppEvents,
157
131
  error,
158
132
  retry,
159
133
  isClient: BROWSER,
@@ -172,39 +146,44 @@ export const createApp = (callback, name = DEFAULT_APP_NAME) => {
172
146
  bindErrorResolver();
173
147
  const flags = getLifecycleFlags(appKey);
174
148
  if (flags[kind])
175
- return undefined;
149
+ return kind === 'clientInit' ? translationInitPromise : undefined;
176
150
  flags[kind] = true;
177
151
  if (kind === 'clientInit') {
178
- const universalContext = {
179
- Container,
180
- isClient: true,
181
- isServer: false
152
+ const initialize = () => {
153
+ const universalContext = {
154
+ isClient: true,
155
+ isServer: false
156
+ };
157
+ const universalResult = callbacks.use?.(universalContext);
158
+ if (universalResult && typeof universalResult.then === 'function') {
159
+ return universalResult.then(() => callbacks.useClientInit?.());
160
+ }
161
+ return callbacks.useClientInit?.();
182
162
  };
183
- const universalResult = callbacks.use?.(universalContext);
184
- if (universalResult && typeof universalResult.then === 'function') {
185
- return universalResult.then(() => callbacks.useClientInit?.({ Container }));
186
- }
187
- return callbacks.useClientInit?.({ Container });
163
+ if (!callbacks.useTranslations)
164
+ return initialize();
165
+ translationInitPromise = getTranslationLifecycle(callbacks.useTranslations())
166
+ .initializeClient()
167
+ .then(initialize)
168
+ .catch((error) => {
169
+ delete flags.clientInit;
170
+ translationInitPromise = undefined;
171
+ throw error;
172
+ });
173
+ return translationInitPromise;
188
174
  }
189
175
  let internalMiddlewares = [];
190
- const clientResult = callbacks.useClient?.({
191
- Container,
192
- useMiddlewares: (middlewares) => {
193
- internalMiddlewares = middlewares;
194
- }
195
- });
196
- const registerNavigation = () => {
197
- if (clientInitialized)
198
- return;
199
- clientInitialized = true;
176
+ if (!clientInitialized) {
200
177
  beforeNavigate((navigation) => {
201
178
  executeClientMiddlewares(internalMiddlewares, navigation);
202
179
  });
203
- };
204
- if (clientResult && typeof clientResult.then === 'function') {
205
- return clientResult.then(registerNavigation);
180
+ clientInitialized = true;
206
181
  }
207
- registerNavigation();
182
+ return callbacks.useClient?.({
183
+ useMiddlewares: (middlewares) => {
184
+ internalMiddlewares = middlewares;
185
+ }
186
+ });
208
187
  };
209
188
  const runServerInit = () => {
210
189
  if (BROWSER)
@@ -212,17 +191,16 @@ export const createApp = (callback, name = DEFAULT_APP_NAME) => {
212
191
  serverInitPromise ??= Promise.resolve().then(() => callbacks.useServerInit?.());
213
192
  return serverInitPromise;
214
193
  };
215
- const runServerError = ({ error, event, status, message }) => {
194
+ const runServerError = (input) => {
195
+ const { status, message } = errorDetails(input);
216
196
  if (BROWSER)
217
197
  return undefined;
218
198
  const requestContext = getServerRequestContext();
219
199
  bindErrorResolver(requestContext);
220
200
  try {
221
201
  const result = callbacks.useServerError?.({
222
- Container,
223
202
  requestContext,
224
- error,
225
- event,
203
+ ...input,
226
204
  status,
227
205
  message,
228
206
  useLogger
@@ -238,14 +216,13 @@ export const createApp = (callback, name = DEFAULT_APP_NAME) => {
238
216
  throw error;
239
217
  }
240
218
  };
241
- const runClientError = ({ error, event, status, message }) => {
219
+ const runClientError = (input) => {
220
+ const { status, message } = errorDetails(input);
242
221
  if (!BROWSER)
243
222
  return undefined;
244
223
  bindErrorResolver();
245
224
  return callbacks.useClientError?.({
246
- Container,
247
- error,
248
- event,
225
+ ...input,
249
226
  status,
250
227
  message
251
228
  });
@@ -255,31 +232,27 @@ export const createApp = (callback, name = DEFAULT_APP_NAME) => {
255
232
  return input.fetch(input.request);
256
233
  return callbacks.useServerFetch({
257
234
  ...input,
258
- Container,
259
- requestContext: getServerRequestContext()
260
- });
261
- };
262
- const runServerValidationError = (input) => {
263
- if (!callbacks.useServerValidationError) {
264
- console.error('Remote function schema validation failed:', input.issues);
265
- return { message: 'Bad Request' };
266
- }
267
- return callbacks.useServerValidationError({
268
- ...input,
269
- Container,
270
235
  requestContext: getServerRequestContext()
271
236
  });
272
237
  };
273
238
  const reroute = (input) => callbacks.useReroute?.(input);
274
- const handle = async ({ event, resolve }) => {
239
+ const handle = async ({ event, resolve: originalResolve }) => {
240
+ const translations = callbacks.useTranslations ? getTranslationLifecycle(callbacks.useTranslations()) : undefined;
241
+ const resolve = translations
242
+ ? (event, options) => originalResolve(event, {
243
+ ...options,
244
+ transformPageChunk: async (chunk) => translations.transformHtml((await options?.transformPageChunk?.(chunk)) ?? chunk.html)
245
+ })
246
+ : originalResolve;
275
247
  const requestContext = getServerRequestContext();
276
248
  bindErrorResolver(requestContext);
277
249
  try {
278
250
  const flags = getLifecycleFlags(appKey, requestContext);
279
251
  if (!flags.server) {
280
252
  flags.server = true;
253
+ if (translations)
254
+ await translations.preloadTranslation();
281
255
  const universalResult = callbacks.use?.({
282
- Container,
283
256
  isClient: false,
284
257
  isServer: true,
285
258
  requestContext,
@@ -289,7 +262,6 @@ export const createApp = (callback, name = DEFAULT_APP_NAME) => {
289
262
  await universalResult;
290
263
  }
291
264
  const serverResult = await callbacks.useServer?.({
292
- Container,
293
265
  requestContext,
294
266
  event,
295
267
  resolve,
@@ -304,19 +276,36 @@ export const createApp = (callback, name = DEFAULT_APP_NAME) => {
304
276
  bindAzureNetKitErrorResolver(undefined, requestContext);
305
277
  }
306
278
  };
307
- const register = Object.assign(() => runClient('client'), {
279
+ const runBoot = () => {
280
+ if (!callbacks.useBoot && !callbacks.useTranslations)
281
+ return;
282
+ const flags = getLifecycleFlags(appKey);
283
+ if (flags.boot)
284
+ return;
285
+ flags.boot = true;
286
+ const state = hydratable('@azure-net/kit:initial-state:v1', () => (BROWSER ? {} : RequestContext.current().state));
287
+ if (callbacks.useTranslations)
288
+ getTranslationLifecycle(callbacks.useTranslations()).syncFromState(state);
289
+ const result = callbacks.useBoot?.({ state });
290
+ if (result && typeof result.then === 'function') {
291
+ void Promise.resolve(result).catch(() => undefined);
292
+ throw new AzureNetKitInternalError('[createApp] useBoot must be synchronous.');
293
+ }
294
+ };
295
+ const register = Object.assign(() => {
296
+ runBoot();
297
+ return runClient('client');
298
+ }, {
308
299
  clientInit: () => runClient('clientInit'),
309
300
  clientError: runClientError,
310
301
  serverInit: runServerInit,
311
302
  serverError: runServerError,
312
303
  serverFetch: runServerFetch,
313
- serverValidationError: runServerValidationError,
314
304
  handle,
315
305
  reroute,
316
306
  transport: callbacks.useTransport ?? {}
317
307
  });
318
308
  return {
319
- Container,
320
309
  register
321
310
  };
322
311
  };
@@ -1,4 +1,5 @@
1
- export { createApp, type AppAzureNetKitErrorCallback, type AppAzureNetKitErrorContext, type AppClientErrorCallback, type AppClientErrorContext, type AppClientInitLifecycleCallback, type AppClientInitLifecycleContext, type AppClientLifecycleCallback, type AppClientLifecycleContext, type AppContainer, type AppRegistrar, type AppServerErrorCallback, type AppServerErrorContext, type AppServerFetchCallback, type AppServerFetchContext, type AppServerInitLifecycleCallback, type AppServerInitLifecycleContext, type AppServerLifecycleCallback, type AppServerLifecycleContext, type AppServerValidationErrorCallback, type AppServerValidationErrorContext, type AppRerouteCallback, type AppUniversalLifecycleCallback, type AppUniversalLifecycleContext, type CreateAppInstance } from './App.js';
1
+ export { createApp, type AppAzureNetKitErrorCallback, type AppAzureNetKitErrorContext, type AppClientErrorCallback, type AppClientErrorContext, type AppClientInitLifecycleCallback, type AppClientInitLifecycleContext, type AppClientLifecycleCallback, type AppClientLifecycleContext, type AppRegistrar, type AppServerErrorCallback, type AppServerErrorContext, type AppServerFetchCallback, type AppServerFetchContext, type AppServerInitLifecycleCallback, type AppServerInitLifecycleContext, type AppServerLifecycleCallback, type AppServerLifecycleContext, type AppRerouteCallback, type AppUniversalLifecycleCallback, type AppUniversalLifecycleContext, type CreateAppInstance } from './App.js';
2
2
  export type { IClientMiddleware } from './middleware/ClientMiddleware.js';
3
3
  export type { IServerMiddleware } from './middleware/ServerMiddleware.js';
4
4
  export type { EnsureRoute, EnsureRouteSource, EnsureRouteTarget } from './middleware/Shared.js';
5
+ export type { AppBootContext, AppBootCallback } from './App.js';
@@ -1,6 +1,6 @@
1
- import { type BeforeNavigate } from '@sveltejs/kit';
2
1
  import { type EnsureRoute } from './Shared.js';
3
- import type { RedirectStatus } from '../../redirect/index.js';
2
+ import type { RedirectStatus } from '../../../svelte/redirect/index.js';
3
+ import type { BeforeNavigate } from '$app/navigation';
4
4
  export type IClientMiddleware = (middlewareData: {
5
5
  to: URL;
6
6
  from?: URL;
@@ -1,4 +1,3 @@
1
- import {} from '@sveltejs/kit';
2
1
  import { ensureRoute } from './Shared.js';
3
2
  import { page } from '$app/state';
4
3
  import { goto } from '$app/navigation';
@@ -1,6 +1,6 @@
1
1
  import { type RequestEvent } from '@sveltejs/kit';
2
2
  import { type EnsureRoute } from './Shared.js';
3
- import type { RedirectStatus } from '../../redirect/index.js';
3
+ import type { RedirectStatus } from '../../../svelte/redirect/index.js';
4
4
  export type IServerMiddleware = (middlewareData: {
5
5
  to: RequestEvent['url'];
6
6
  from?: RequestEvent['url'];
@@ -1,7 +1,7 @@
1
1
  import { error, redirect } from '@sveltejs/kit';
2
2
  import { ensureRoute } from './Shared.js';
3
3
  import { BROWSER } from '../../../external/tools/index.js';
4
- import { RequestContext } from '../../../external/edges/ServerContext.js';
4
+ import { RequestContext } from '../../../shared/request-context/Internal.js';
5
5
  export const executeServerMiddlewares = async (middlewares) => {
6
6
  if (!BROWSER && middlewares.length) {
7
7
  const event = RequestContext.current().event;
@@ -1,4 +1,4 @@
1
- import { type ContextData } from '../../external/edges/ServerContext.js';
1
+ import { type ContextData } from '../../shared/request-context/Internal.js';
2
2
  import { AppError, type IAppError } from './AppError.js';
3
3
  type MaybePromise<T> = T | Promise<T>;
4
4
  export interface AsyncHelperRetry {
@@ -1,14 +1,15 @@
1
+ import { getContextInternals } from '../../shared/request-context/Internal.js';
1
2
  import { BROWSER } from '../../external/tools/index.js';
2
- import { RequestContext } from '../../external/edges/ServerContext.js';
3
+ import { RequestContext } from '../../shared/request-context/Internal.js';
3
4
  import { AppError, AzureNetKitInternalError } from './AppError.js';
4
5
  const SERVER_BINDING_KEY = Symbol('azureNetKitErrorResolver');
5
6
  let clientBinding;
6
7
  const createBinding = (resolver) => ({ resolver });
7
8
  const getServerData = (requestContext) => {
8
9
  if (requestContext)
9
- return requestContext.data;
10
+ return getContextInternals(requestContext);
10
11
  try {
11
- return RequestContext.current().data;
12
+ return getContextInternals(RequestContext.current());
12
13
  }
13
14
  catch {
14
15
  return undefined;
@@ -16,6 +16,6 @@ export interface ProviderSettings<T extends ServiceMap, D extends Record<string,
16
16
  boot?: (services: ResolvedServices<T>) => undefined;
17
17
  register: ProviderFactory<T, D>;
18
18
  }
19
- export declare const createBoundaryProvider: <T extends ServiceMap, D extends Record<string, ProviderWithType<ServiceMap>>>(name: string, settings: ProviderSettings<T, D>) => ProviderWithType<T>;
19
+ export declare const CreateServiceContainer: <T extends ServiceMap, D extends Record<string, ProviderWithType<ServiceMap>>>(name: string, settings: ProviderSettings<T, D>) => ProviderWithType<T>;
20
20
  export declare function cleanupProvider(name: string): Promise<void>;
21
21
  export {};
@@ -1,4 +1,5 @@
1
- import { RequestContext } from '../../external/edges/ServerContext.js';
1
+ import { getContextInternals } from '../../shared/request-context/Internal.js';
2
+ import { RequestContext } from '../../shared/request-context/Internal.js';
2
3
  import { BROWSER } from '../../external/tools/index.js';
3
4
  import { AzureNetKitInternalError } from '../app-error/AppError.js';
4
5
  const clientCache = new Map();
@@ -14,30 +15,36 @@ const getProviderCache = (providerName) => {
14
15
  }
15
16
  else {
16
17
  const context = RequestContext.current();
17
- if (!context.data.azureNetKitBoundaryProviders) {
18
- context.data.azureNetKitBoundaryProviders = new Map();
18
+ if (!getContextInternals(context).azureNetKitBoundaryProviders) {
19
+ getContextInternals(context).azureNetKitBoundaryProviders = new Map();
19
20
  }
20
- const providers = context.data.azureNetKitBoundaryProviders;
21
+ const providers = getContextInternals(context).azureNetKitBoundaryProviders;
21
22
  if (!providers.has(providerName)) {
22
23
  providers.set(providerName, new Map());
23
24
  }
24
- if (!context.data.azureNetKitBoundaryProvidersToCleanup) {
25
- context.data.azureNetKitBoundaryProvidersToCleanup = new Set();
25
+ if (!getContextInternals(context).azureNetKitBoundaryProvidersToCleanup) {
26
+ getContextInternals(context).azureNetKitBoundaryProvidersToCleanup = new Set();
26
27
  }
27
- context.data.azureNetKitBoundaryProvidersToCleanup.add(providerName);
28
+ getContextInternals(context).azureNetKitBoundaryProvidersToCleanup.add(providerName);
28
29
  return providers.get(providerName);
29
30
  }
30
31
  };
32
+ const getProxyCache = () => {
33
+ if (BROWSER)
34
+ return providerProxyCache;
35
+ const context = RequestContext.current();
36
+ return (getContextInternals(context).azureNetKitBoundaryProviderProxies ??= new Map());
37
+ };
31
38
  const getBootFlag = (providerName) => {
32
39
  if (BROWSER) {
33
40
  return clientBootFlags.get(providerName) ?? false;
34
41
  }
35
42
  else {
36
43
  const context = RequestContext.current();
37
- if (!context.data.bootFlags) {
38
- context.data.bootFlags = new Map();
44
+ if (!getContextInternals(context).bootFlags) {
45
+ getContextInternals(context).bootFlags = new Map();
39
46
  }
40
- const bootFlags = context.data.bootFlags;
47
+ const bootFlags = getContextInternals(context).bootFlags;
41
48
  return bootFlags.get(providerName) ?? false;
42
49
  }
43
50
  };
@@ -47,10 +54,10 @@ const setBootFlag = (providerName, value) => {
47
54
  }
48
55
  else {
49
56
  const context = RequestContext.current();
50
- if (!context.data.bootFlags) {
51
- context.data.bootFlags = new Map();
57
+ if (!getContextInternals(context).bootFlags) {
58
+ getContextInternals(context).bootFlags = new Map();
52
59
  }
53
- const bootFlags = context.data.bootFlags;
60
+ const bootFlags = getContextInternals(context).bootFlags;
54
61
  bootFlags.set(providerName, value);
55
62
  }
56
63
  };
@@ -58,7 +65,7 @@ const getConstructionStack = () => {
58
65
  if (BROWSER)
59
66
  return clientConstructionStack;
60
67
  const context = RequestContext.current();
61
- return (context.data.boundaryProviderConstructionStack ??= []);
68
+ return (getContextInternals(context).boundaryProviderConstructionStack ??= []);
62
69
  };
63
70
  const runWithCycleGuard = (key, callback) => {
64
71
  const stack = getConstructionStack();
@@ -77,11 +84,12 @@ const runWithCycleGuard = (key, callback) => {
77
84
  stack.splice(idx, 1);
78
85
  }
79
86
  };
80
- export const createBoundaryProvider = (name, settings) => {
87
+ export const CreateServiceContainer = (name, settings) => {
81
88
  const { dependsOn = {}, boot, register } = settings;
82
89
  const providerFn = () => {
83
- if (BROWSER && providerProxyCache.has(name)) {
84
- return providerProxyCache.get(name);
90
+ const proxies = getProxyCache();
91
+ if (proxies.has(name)) {
92
+ return proxies.get(name);
85
93
  }
86
94
  const cache = getProviderCache(name);
87
95
  let factories = null;
@@ -101,7 +109,7 @@ export const createBoundaryProvider = (name, settings) => {
101
109
  }
102
110
  });
103
111
  }
104
- factories = register(deps);
112
+ factories = runWithCycleGuard(`${name}.register`, () => register(deps));
105
113
  return factories;
106
114
  };
107
115
  const providerProxy = new Proxy({}, {
@@ -157,17 +165,21 @@ export const createBoundaryProvider = (name, settings) => {
157
165
  };
158
166
  }
159
167
  });
160
- if (BROWSER) {
161
- providerProxyCache.set(name, providerProxy);
162
- }
163
- if (boot && !getBootFlag(name)) {
164
- getFactories();
165
- const bootResult = boot(providerProxy);
166
- if (bootResult && typeof bootResult.then === 'function') {
167
- void Promise.resolve(bootResult).catch(() => undefined);
168
- throw new AzureNetKitInternalError(`[BoundaryProvider] Boot for provider '${name}' must be synchronous.`);
168
+ proxies.set(name, providerProxy);
169
+ try {
170
+ if (boot && !getBootFlag(name)) {
171
+ getFactories();
172
+ const bootResult = boot(providerProxy);
173
+ if (bootResult && typeof bootResult.then === 'function') {
174
+ void Promise.resolve(bootResult).catch(() => undefined);
175
+ throw new AzureNetKitInternalError(`[BoundaryProvider] Boot for provider '${name}' must be synchronous.`);
176
+ }
177
+ setBootFlag(name, true);
169
178
  }
170
- setBootFlag(name, true);
179
+ }
180
+ catch (error) {
181
+ proxies.delete(name);
182
+ throw error;
171
183
  }
172
184
  return providerProxy;
173
185
  };
@@ -200,7 +212,10 @@ export async function cleanupProvider(name) {
200
212
  }
201
213
  else {
202
214
  const context = RequestContext.current();
203
- const providers = context.data.azureNetKitBoundaryProviders;
215
+ const providers = getContextInternals(context).azureNetKitBoundaryProviders;
216
+ getProxyCache().delete(name);
217
+ setBootFlag(name, false);
218
+ getContextInternals(context).azureNetKitBoundaryProvidersToCleanup?.delete(name);
204
219
  if (providers?.has(name)) {
205
220
  const cache = providers.get(name);
206
221
  providers.delete(name);
@@ -1,5 +1,5 @@
1
1
  import { BROWSER, Cookies } from '../../external/tools/index.js';
2
- import { RequestContext } from '../../external/edges/ServerContext.js';
2
+ import { RequestContext } from '../../shared/request-context/Internal.js';
3
3
  const cloneCookieOptions = (options) => ({
4
4
  ...options,
5
5
  expires: options.expires instanceof Date ? new Date(options.expires) : options.expires
@@ -1,8 +1,6 @@
1
1
  export { UniversalCookie, UniversalCookieInstance, UniversalNamedCookieInstance, type CookieOptions } from './cookie/index.js';
2
2
  export { BackgroundTask } from './background-task/index.js';
3
- export { AppEvents } from './event-bus/index.js';
4
3
  export { ClassMirror } from './class-mirror/index.js';
5
- export { createBoundaryProvider, cleanupProvider, type ProviderSettings } from './boundary-provider/index.js';
4
+ export { CreateServiceContainer, cleanupProvider, type ProviderSettings } from './boundary-provider/index.js';
6
5
  export * from './app/index.js';
7
6
  export { useLogger, LoggerErrors, type ILoggerError, type ILoggerSettings } from './logger/index.js';
8
- export { useRedirect, type IRedirectSettings, type RedirectStatus } from './redirect/index.js';
@@ -1,8 +1,6 @@
1
1
  export { UniversalCookie, UniversalCookieInstance, UniversalNamedCookieInstance } from './cookie/index.js';
2
2
  export { BackgroundTask } from './background-task/index.js';
3
- export { AppEvents } from './event-bus/index.js';
4
3
  export { ClassMirror } from './class-mirror/index.js';
5
- export { createBoundaryProvider, cleanupProvider } from './boundary-provider/index.js';
4
+ export { CreateServiceContainer, cleanupProvider } from './boundary-provider/index.js';
6
5
  export * from './app/index.js';
7
6
  export { useLogger, LoggerErrors } from './logger/index.js';
8
- export { useRedirect } from './redirect/index.js';
@@ -1,6 +1,6 @@
1
1
  import { AppError, AzureNetKitInternalError } from '../app-error/index.js';
2
2
  import { BROWSER } from '../../external/tools/index.js';
3
- import { RequestContext } from '../../external/edges/ServerContext.js';
3
+ import { RequestContext } from '../../shared/request-context/Internal.js';
4
4
  import { BackgroundTask } from '../background-task/index.js';
5
5
  export var LoggerErrors;
6
6
  (function (LoggerErrors) {
@@ -0,0 +1,16 @@
1
+ import type { RequestEvent } from '@sveltejs/kit';
2
+ declare global {
3
+ namespace App {
4
+ interface RequestContextState {
5
+ }
6
+ }
7
+ }
8
+ export interface ContextData {
9
+ readonly event: RequestEvent;
10
+ readonly state: App.RequestContextState;
11
+ }
12
+ export declare function initializeRequestContext(resolve: () => ContextData | undefined): void;
13
+ export declare function getContextInternals(context: ContextData): Record<PropertyKey, unknown>;
14
+ export declare const RequestContext: Readonly<{
15
+ current(): ContextData;
16
+ }>;
@@ -0,0 +1,24 @@
1
+ import { BROWSER } from '../../external/tools/index.js';
2
+ let getter;
3
+ const internals = new WeakMap();
4
+ export function initializeRequestContext(resolve) {
5
+ getter = resolve;
6
+ }
7
+ export function getContextInternals(context) {
8
+ let data = internals.get(context);
9
+ if (!data) {
10
+ data = {};
11
+ internals.set(context, data);
12
+ }
13
+ return data;
14
+ }
15
+ export const RequestContext = Object.freeze({
16
+ current() {
17
+ if (BROWSER)
18
+ throw new Error('[AzureNetKit] RequestContext is server-only.');
19
+ const context = getter?.();
20
+ if (!context)
21
+ throw new Error('[AzureNetKit] No active RequestContext. Use AzureNetPlugin and resolve services inside a request.');
22
+ return context;
23
+ }
24
+ });
@@ -2,3 +2,4 @@ export { createAsyncSignal, createAsyncSignalBatch, refreshAsyncSignal, refreshA
2
2
  export { createActiveForm, type ActiveForm, type ActiveFormCallbackContext, type ActiveFormController, type ActiveFormResponse, type ActiveFormStatus, type FormConfig, type InitialValuesHelpers, type LinkPromise, type LinkSignal, type LinkSignalOptions, type ResetBehaviors } from './active-form/ActiveForm.svelte.js';
3
3
  export { createEffect, type EffectCallback, type EffectCleanup, type EffectDependency } from './effect/Effect.svelte.js';
4
4
  export { createQuery, type CreateQueryOptions, type QueryController, type QueryPath, type QuerySearchParamsSync } from './query/Query.svelte.js';
5
+ export { useRedirect, type IRedirectSettings, type RedirectStatus } from './redirect/index.js';
@@ -2,3 +2,4 @@ export { createAsyncSignal, createAsyncSignalBatch, refreshAsyncSignal, refreshA
2
2
  export { createActiveForm } from './active-form/ActiveForm.svelte.js';
3
3
  export { createEffect } from './effect/Effect.svelte.js';
4
4
  export { createQuery } from './query/Query.svelte.js';
5
+ export { useRedirect } from './redirect/index.js';