@azure-net/kit 4.1.0 → 5.0.0-1

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 (149) hide show
  1. package/dist/delivery/index.d.ts +3 -0
  2. package/dist/delivery/index.js +3 -0
  3. package/dist/{core/delivery/injectableDependencies → delivery/injectable-dependencies}/AsyncHelpers.d.ts +1 -1
  4. package/dist/{core/delivery/injectableDependencies → delivery/injectable-dependencies}/AsyncHelpers.js +1 -1
  5. package/dist/{core/delivery/injectableDependencies → delivery/injectable-dependencies}/ErrorHandler.d.ts +2 -2
  6. package/dist/{core/delivery/injectableDependencies → delivery/injectable-dependencies}/ErrorHandler.js +2 -2
  7. package/dist/{core/delivery → delivery}/schema/Schema.js +2 -2
  8. package/dist/{core/delivery → delivery}/schema/rules/Rules.d.ts +1 -1
  9. package/dist/{core/delivery → delivery}/schema/rules/Rules.js +1 -1
  10. package/dist/{core/delivery → delivery}/schema/rules/messages/En.d.ts +1 -1
  11. package/dist/{core/delivery → delivery}/schema/rules/messages/Ru.d.ts +1 -1
  12. package/dist/{core/delivery → delivery}/schema/rules/messages/WithI18n.d.ts +1 -1
  13. package/dist/{core/delivery → delivery}/schema/rules/messages/index.d.ts +1 -1
  14. package/dist/{core/delivery → delivery}/schema/rules/messages/index.js +1 -1
  15. package/dist/delivery.d.ts +2 -0
  16. package/dist/delivery.js +2 -0
  17. package/dist/errors.d.ts +4 -0
  18. package/dist/errors.js +4 -0
  19. package/dist/external/edges/Dev.d.ts +1 -0
  20. package/dist/external/edges/Dev.js +1 -0
  21. package/dist/external/edges/Edges.d.ts +1 -0
  22. package/dist/external/edges/Edges.js +1 -0
  23. package/dist/external/edges/ServerContext.d.ts +1 -0
  24. package/dist/index.d.ts +2 -2
  25. package/dist/index.js +2 -2
  26. package/dist/{core/infra → infra}/datasource/BaseDatasource.d.ts +1 -1
  27. package/dist/{core/infra → infra}/datasource/BaseDatasource.js +1 -1
  28. package/dist/{core/infra/httpService → infra/http-service}/HttpServiceInstance.js +2 -2
  29. package/dist/infra/index.d.ts +5 -0
  30. package/dist/infra/index.js +5 -0
  31. package/dist/{core/infra → infra}/query/QueryBuilder.js +1 -1
  32. package/dist/{core/infra → infra}/response/BaseResponse.d.ts +1 -1
  33. package/dist/{core/infra → infra}/response/BaseResponse.js +1 -1
  34. package/dist/infra.d.ts +1 -0
  35. package/dist/infra.js +1 -0
  36. package/dist/plugin/AzureNetPlugin.d.ts +7 -0
  37. package/dist/plugin/AzureNetPlugin.js +402 -0
  38. package/dist/plugin/index.d.ts +1 -0
  39. package/dist/plugin/index.js +1 -0
  40. package/dist/shared/app/App.d.ts +96 -0
  41. package/dist/shared/app/App.js +244 -0
  42. package/dist/shared/app/index.d.ts +4 -0
  43. package/dist/shared/app/index.js +1 -0
  44. package/dist/shared/app/middleware/ClientMiddleware.d.ts +8 -0
  45. package/dist/shared/app/middleware/ClientMiddleware.js +31 -0
  46. package/dist/shared/app/middleware/ServerMiddleware.d.ts +9 -0
  47. package/dist/shared/app/middleware/ServerMiddleware.js +31 -0
  48. package/dist/shared/app/middleware/Shared.d.ts +1 -0
  49. package/dist/{core/shared/appError → shared/app-error}/AppError.d.ts +1 -1
  50. package/dist/{core/shared/appError → shared/app-error}/AppError.js +2 -2
  51. package/dist/shared/app-error/index.d.ts +1 -0
  52. package/dist/shared/app-error/index.js +1 -0
  53. package/dist/{core/shared/boundaryProvider → shared/boundary-provider}/Provider.js +3 -3
  54. package/dist/{core/shared → shared}/cookie/UniversalCookie.js +2 -3
  55. package/dist/shared/event-bus/EventBus.d.ts +2 -0
  56. package/dist/shared/event-bus/EventBus.js +6 -0
  57. package/dist/shared/index.d.ts +5 -0
  58. package/dist/shared/index.js +5 -0
  59. package/dist/{core/svelte/ActiveForm → svelte/active-form}/ActiveForm.svelte.d.ts +1 -1
  60. package/dist/{core/svelte/ActiveForm → svelte/active-form}/ActiveForm.svelte.js +1 -1
  61. package/dist/{core/svelte/AsyncSignal → svelte/async-signal}/AsyncSignal.svelte.js +1 -1
  62. package/dist/svelte/index.d.ts +3 -0
  63. package/dist/svelte/index.js +3 -0
  64. package/dist/{core/svelte/Query → svelte/query}/Query.svelte.js +1 -1
  65. package/package.json +26 -33
  66. package/dist/core/delivery/index.js +0 -1
  67. package/dist/core/delivery.d.ts +0 -5
  68. package/dist/core/delivery.js +0 -5
  69. package/dist/core/errors.d.ts +0 -4
  70. package/dist/core/errors.js +0 -4
  71. package/dist/core/index.d.ts +0 -6
  72. package/dist/core/index.js +0 -6
  73. package/dist/core/infra/index.d.ts +0 -5
  74. package/dist/core/infra/index.js +0 -5
  75. package/dist/core/infra.d.ts +0 -6
  76. package/dist/core/infra.js +0 -6
  77. package/dist/core/shared/appEventBus/EventBus.d.ts +0 -2
  78. package/dist/core/shared/appEventBus/EventBus.js +0 -6
  79. package/dist/core/shared/middleware/Middleware.d.ts +0 -21
  80. package/dist/core/shared/middleware/Middleware.js +0 -76
  81. package/dist/core/shared/middleware/index.d.ts +0 -1
  82. package/dist/core/shared/middleware/index.js +0 -1
  83. package/dist/core/svelte/index.d.ts +0 -3
  84. package/dist/core/svelte/index.js +0 -3
  85. package/dist/edges/context/index.js +0 -1
  86. package/dist/edges/dev/index.d.ts +0 -1
  87. package/dist/edges/dev/index.js +0 -1
  88. package/dist/edges/index.d.ts +0 -1
  89. package/dist/edges/index.js +0 -1
  90. package/dist/edges/plugin/index.d.ts +0 -1
  91. package/dist/edges/plugin/index.js +0 -2
  92. package/dist/edges/state/index.d.ts +0 -1
  93. package/dist/edges/state/index.js +0 -1
  94. /package/dist/{core/delivery/injectableDependencies → delivery/injectable-dependencies}/index.d.ts +0 -0
  95. /package/dist/{core/delivery/injectableDependencies → delivery/injectable-dependencies}/index.js +0 -0
  96. /package/dist/{core/delivery → delivery}/schema/Schema.d.ts +0 -0
  97. /package/dist/{core/delivery → delivery}/schema/index.d.ts +0 -0
  98. /package/dist/{core/delivery → delivery}/schema/index.js +0 -0
  99. /package/dist/{core/delivery → delivery}/schema/rules/index.d.ts +0 -0
  100. /package/dist/{core/delivery → delivery}/schema/rules/index.js +0 -0
  101. /package/dist/{core/delivery → delivery}/schema/rules/messages/En.js +0 -0
  102. /package/dist/{core/delivery → delivery}/schema/rules/messages/Ru.js +0 -0
  103. /package/dist/{core/delivery/schema/rules/messages/types.d.ts → delivery/schema/rules/messages/Types.d.ts} +0 -0
  104. /package/dist/{core/delivery/index.d.ts → delivery/schema/rules/messages/Types.js} +0 -0
  105. /package/dist/{core/delivery → delivery}/schema/rules/messages/WithI18n.js +0 -0
  106. /package/dist/{edges/context/index.d.ts → external/edges/ServerContext.js} +0 -0
  107. /package/dist/{edges/server/index.d.ts → external/edges/_edges.d.ts} +0 -0
  108. /package/dist/{edges/server/index.js → external/edges/_edges.js} +0 -0
  109. /package/dist/{i18n → external/i18n}/index.d.ts +0 -0
  110. /package/dist/{i18n → external/i18n}/index.js +0 -0
  111. /package/dist/{tools → external/tools}/index.d.ts +0 -0
  112. /package/dist/{tools → external/tools}/index.js +0 -0
  113. /package/dist/{core/infra → infra}/datasource/index.d.ts +0 -0
  114. /package/dist/{core/infra → infra}/datasource/index.js +0 -0
  115. /package/dist/{core/infra/httpService → infra/http-service}/HttpServiceInstance.d.ts +0 -0
  116. /package/dist/{core/infra/httpService → infra/http-service}/Statuses.d.ts +0 -0
  117. /package/dist/{core/infra/httpService → infra/http-service}/Statuses.js +0 -0
  118. /package/dist/{core/infra/httpService → infra/http-service}/index.d.ts +0 -0
  119. /package/dist/{core/infra/httpService → infra/http-service}/index.js +0 -0
  120. /package/dist/{core/infra → infra}/query/QueryBuilder.d.ts +0 -0
  121. /package/dist/{core/infra → infra}/query/index.d.ts +0 -0
  122. /package/dist/{core/infra → infra}/query/index.js +0 -0
  123. /package/dist/{core/infra → infra}/resource/BaseResource.d.ts +0 -0
  124. /package/dist/{core/infra → infra}/resource/BaseResource.js +0 -0
  125. /package/dist/{core/infra → infra}/resource/index.d.ts +0 -0
  126. /package/dist/{core/infra → infra}/resource/index.js +0 -0
  127. /package/dist/{core/infra → infra}/response/index.d.ts +0 -0
  128. /package/dist/{core/infra → infra}/response/index.js +0 -0
  129. /package/dist/{core/delivery/schema/rules/messages/types.js → shared/app/middleware/Shared.js} +0 -0
  130. /package/dist/{core/shared/boundaryProvider → shared/boundary-provider}/Provider.d.ts +0 -0
  131. /package/dist/{core/shared/boundaryProvider → shared/boundary-provider}/index.d.ts +0 -0
  132. /package/dist/{core/shared/boundaryProvider → shared/boundary-provider}/index.js +0 -0
  133. /package/dist/{core/shared/classMirror → shared/class-mirror}/ClassMirror.d.ts +0 -0
  134. /package/dist/{core/shared/classMirror → shared/class-mirror}/ClassMirror.js +0 -0
  135. /package/dist/{core/shared/classMirror → shared/class-mirror}/index.d.ts +0 -0
  136. /package/dist/{core/shared/classMirror → shared/class-mirror}/index.js +0 -0
  137. /package/dist/{core/shared → shared}/cookie/UniversalCookie.d.ts +0 -0
  138. /package/dist/{core/shared → shared}/cookie/index.d.ts +0 -0
  139. /package/dist/{core/shared → shared}/cookie/index.js +0 -0
  140. /package/dist/{core/shared/appEventBus → shared/event-bus}/index.d.ts +0 -0
  141. /package/dist/{core/shared/appEventBus → shared/event-bus}/index.js +0 -0
  142. /package/dist/{core/svelte/ActiveForm → svelte/active-form}/index.d.ts +0 -0
  143. /package/dist/{core/svelte/ActiveForm → svelte/active-form}/index.js +0 -0
  144. /package/dist/{core/svelte/AsyncSignal → svelte/async-signal}/AsyncSignal.svelte.d.ts +0 -0
  145. /package/dist/{core/svelte/AsyncSignal → svelte/async-signal}/index.d.ts +0 -0
  146. /package/dist/{core/svelte/AsyncSignal → svelte/async-signal}/index.js +0 -0
  147. /package/dist/{core/svelte/Query → svelte/query}/Query.svelte.d.ts +0 -0
  148. /package/dist/{core/svelte/Query → svelte/query}/index.d.ts +0 -0
  149. /package/dist/{core/svelte/Query → svelte/query}/index.js +0 -0
@@ -0,0 +1,3 @@
1
+ export { createAsyncHelpers, createErrorHandler, type AsyncHelperRetry, type AsyncResourceSettings, type AsyncActionResponse } from './injectable-dependencies/index.js';
2
+ export { createSchemaFactory, schema, type Schema, type RequestErrors, type ISchemaError, type ValidationResult, type ValidationRuleResult, type ValidationParams, type ValidationMessage, type ValidationErrorsMap } from './schema/index.js';
3
+ export { createRules, validationMessagesRu, validationMessagesI18n, validationMessagesEn, type ValidationRuleParams, type BaseValidationMessages } from './schema/rules/index.js';
@@ -0,0 +1,3 @@
1
+ export { createAsyncHelpers, createErrorHandler } from './injectable-dependencies/index.js';
2
+ export { createSchemaFactory, schema } from './schema/index.js';
3
+ export { createRules, validationMessagesRu, validationMessagesI18n, validationMessagesEn } from './schema/rules/index.js';
@@ -1,5 +1,5 @@
1
1
  import { createErrorHandler } from './ErrorHandler.js';
2
- import { type AppError, type IAppError } from '../../shared/appError/AppError.js';
2
+ import { type AppError, type IAppError } from '../../shared/app-error/AppError.js';
3
3
  export interface AsyncActionResponse<T, D = never, ErrorResult = Record<never, never>> {
4
4
  success: boolean;
5
5
  response: T;
@@ -1,5 +1,5 @@
1
1
  import { createErrorHandler } from './ErrorHandler.js';
2
- import {} from '../../shared/appError/AppError.js';
2
+ import {} from '../../shared/app-error/AppError.js';
3
3
  export class AsyncHelperError extends Error {
4
4
  }
5
5
  export const createAsyncHelpers = (opts) => {
@@ -1,5 +1,5 @@
1
- import { AppError, type IAppError } from '../../shared/appError/AppError.js';
2
- import { AppEvents } from '../../shared/appEventBus/index.js';
1
+ import { AppError, type IAppError } from '../../shared/app-error/AppError.js';
2
+ import { AppEvents } from '../../shared/event-bus/EventBus.js';
3
3
  import type { AsyncHelperRetry } from './AsyncHelpers.js';
4
4
  export type ErrorHandlerContext = {
5
5
  AppEvents: typeof AppEvents;
@@ -1,5 +1,5 @@
1
- import { AppError } from '../../shared/appError/AppError.js';
2
- import { AppEvents } from '../../shared/appEventBus/index.js';
1
+ import { AppError } from '../../shared/app-error/AppError.js';
2
+ import { AppEvents } from '../../shared/event-bus/EventBus.js';
3
3
  export const createErrorHandler = (handle) => {
4
4
  return async (error, asyncHelperRetry) => {
5
5
  const appError = new AppError(error);
@@ -1,5 +1,5 @@
1
- import { FormDataUtil } from '@azure-net/tools';
2
- import { AzureNetKitInternalError } from '../../shared/appError/AppError.js';
1
+ import { FormDataUtil } from '../../external/tools/index.js';
2
+ import { AzureNetKitInternalError } from '../../shared/app-error/AppError.js';
3
3
  export class SchemaFail extends Error {
4
4
  _errors;
5
5
  data;
@@ -1,4 +1,4 @@
1
- import type { BaseValidationMessages } from './messages/types.js';
1
+ import type { BaseValidationMessages } from './messages/Types.js';
2
2
  import type { ValidationParams, ValidationRuleResult } from '../index.js';
3
3
  export type ValidationRuleParams<T extends keyof BaseValidationMessages, D = object> = D & {
4
4
  message?: BaseValidationMessages[T];
@@ -1,4 +1,4 @@
1
- import { DateUtil } from '@azure-net/tools';
1
+ import { DateUtil } from '../../../external/tools/index.js';
2
2
  /**
3
3
  *
4
4
  * @param validationMessages - BaseValidationMessages
@@ -1,2 +1,2 @@
1
- import type { BaseValidationMessages } from './types.js';
1
+ import type { BaseValidationMessages } from './Types.js';
2
2
  export declare const validationMessagesEn: BaseValidationMessages;
@@ -1,2 +1,2 @@
1
- import type { BaseValidationMessages } from './types.js';
1
+ import type { BaseValidationMessages } from './Types.js';
2
2
  export declare const validationMessagesRu: BaseValidationMessages;
@@ -1,2 +1,2 @@
1
- import type { BaseValidationMessages } from './types.js';
1
+ import type { BaseValidationMessages } from './Types.js';
2
2
  export declare const validationMessagesI18n: BaseValidationMessages;
@@ -1,4 +1,4 @@
1
1
  export * from './Ru.js';
2
2
  export * from './En.js';
3
3
  export * from './WithI18n.js';
4
- export * from './types.js';
4
+ export * from './Types.js';
@@ -1,4 +1,4 @@
1
1
  export * from './Ru.js';
2
2
  export * from './En.js';
3
3
  export * from './WithI18n.js';
4
- export * from './types.js';
4
+ export * from './Types.js';
@@ -0,0 +1,2 @@
1
+ export * from './external/edges/Edges.js';
2
+ export * from './delivery/index.js';
@@ -0,0 +1,2 @@
1
+ export * from './external/edges/Edges.js';
2
+ export * from './delivery/index.js';
@@ -0,0 +1,4 @@
1
+ export { AppError, ErrorTypes, AzureNetKitInternalError, type IAppError } from './shared/app-error/AppError.js';
2
+ export { HttpServiceError } from './infra/http-service/HttpServiceInstance.js';
3
+ export { AsyncHelperError } from './delivery/injectable-dependencies/AsyncHelpers.js';
4
+ export { SchemaFail } from './delivery/schema/Schema.js';
package/dist/errors.js ADDED
@@ -0,0 +1,4 @@
1
+ export { AppError, ErrorTypes, AzureNetKitInternalError } from './shared/app-error/AppError.js';
2
+ export { HttpServiceError } from './infra/http-service/HttpServiceInstance.js';
3
+ export { AsyncHelperError } from './delivery/injectable-dependencies/AsyncHelpers.js';
4
+ export { SchemaFail } from './delivery/schema/Schema.js';
@@ -0,0 +1 @@
1
+ export * from '@azure-net/edges/dev';
@@ -0,0 +1 @@
1
+ export * from '@azure-net/edges/dev';
@@ -0,0 +1 @@
1
+ export { clearCache, createPresenter, createPresenterFactory, createStore, createStoreFactory, batch, transaction } from '@azure-net/edges';
@@ -0,0 +1 @@
1
+ export { clearCache, createPresenter, createPresenterFactory, createStore, createStoreFactory, batch, transaction } from '@azure-net/edges';
@@ -0,0 +1 @@
1
+ export { RequestContext, type ContextData } from '@azure-net/edges/context';
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from './core/index.js';
2
- export { __withEdgesUniversalLoad } from './edges/index.js';
1
+ export * from './shared/index.js';
2
+ export * from './svelte/index.js';
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export * from './core/index.js';
2
- export { __withEdgesUniversalLoad } from './edges/index.js';
1
+ export * from './shared/index.js';
2
+ export * from './svelte/index.js';
@@ -1,4 +1,4 @@
1
- import { type IHttpServiceInstance, type IHttpServiceResponse } from '../httpService/HttpServiceInstance.js';
1
+ import { type IHttpServiceInstance, type IHttpServiceResponse } from '../http-service/HttpServiceInstance.js';
2
2
  import { type IQueryBuilderInstance } from '../query/index.js';
3
3
  export type CreateRequestCallbackType<T> = (params: {
4
4
  http: IHttpServiceInstance;
@@ -1,4 +1,4 @@
1
- import { createHttpServiceInstance } from '../httpService/HttpServiceInstance.js';
1
+ import { createHttpServiceInstance } from '../http-service/HttpServiceInstance.js';
2
2
  import { createQueryInstance } from '../query/index.js';
3
3
  export class BaseHttpDatasource {
4
4
  httpClient;
@@ -1,5 +1,5 @@
1
- import { BROWSER } from '@azure-net/tools/environment';
2
- import { RequestContext } from '@azure-net/edges/context';
1
+ import { BROWSER } from '../../external/tools/index.js';
2
+ import { RequestContext } from '../../external/edges/ServerContext.js';
3
3
  export var HttpInstanceFetchMethods;
4
4
  (function (HttpInstanceFetchMethods) {
5
5
  HttpInstanceFetchMethods["GET"] = "GET";
@@ -0,0 +1,5 @@
1
+ export { BaseHttpDatasource, type CreateRequestCallbackType } from './datasource/index.js';
2
+ export { DTOMapper, type IDTOMapper } from './resource/index.js';
3
+ export { HttpStatusCode, createHttpServiceInstance, HttpInstanceFetchMethods, HttpErrorTypes, HttpServiceResponse, HttpServiceError, type IHttpServiceError, type IHttpServiceResponse, type IHttpServiceInstance, type IHttpInstanceOptions, type HttpInstanceNormalizedRequest, type HttpInstanceOnRequest, type HttpInstanceOnError, type HttpInstanceDoFetch, type HttpInstanceRequestMethod } from './http-service/index.js';
4
+ export { ResponseBuilder } from './response/index.js';
5
+ export { createQueryInstance, type IQueryBuilderInstance, type ArrayFormat, type ObjectFormat, type IQueryBuilderSettings } from './query/QueryBuilder.js';
@@ -0,0 +1,5 @@
1
+ export { BaseHttpDatasource } from './datasource/index.js';
2
+ export { DTOMapper } from './resource/index.js';
3
+ export { HttpStatusCode, createHttpServiceInstance, HttpInstanceFetchMethods, HttpErrorTypes, HttpServiceResponse, HttpServiceError } from './http-service/index.js';
4
+ export { ResponseBuilder } from './response/index.js';
5
+ export { createQueryInstance } from './query/QueryBuilder.js';
@@ -1,4 +1,4 @@
1
- import { AzureNetKitInternalError } from '../../shared/appError/AppError.js';
1
+ import { AzureNetKitInternalError } from '../../shared/app-error/AppError.js';
2
2
  const normalizeSettings = (base, override) => {
3
3
  return {
4
4
  delimiter: override?.delimiter ?? base?.delimiter ?? true,
@@ -1,4 +1,4 @@
1
- import type { HttpServiceResponse } from '../httpService/index.js';
1
+ import type { HttpServiceResponse } from '../http-service/index.js';
2
2
  type DeepKeys<T> = T extends object ? {
3
3
  [K in keyof T & string]: T[K] extends object ? K | `${K}.${DeepKeys<T[K]>}` : K;
4
4
  }[keyof T & string] : never;
@@ -1,4 +1,4 @@
1
- import { AzureNetKitInternalError } from '../../shared/appError/AppError.js';
1
+ import { AzureNetKitInternalError } from '../../shared/app-error/AppError.js';
2
2
  export class ResponseBuilder {
3
3
  response;
4
4
  state;
@@ -0,0 +1 @@
1
+ export * from './infra/index.js';
package/dist/infra.js ADDED
@@ -0,0 +1 @@
1
+ export * from './infra/index.js';
@@ -0,0 +1,7 @@
1
+ import type { Plugin } from 'vite';
2
+ export interface AzureNetPluginOptions {
3
+ silentChromeDevtools?: boolean;
4
+ syncFromServer?: boolean;
5
+ syncTransformMode?: 'ast' | 'regex' | 'hybrid';
6
+ }
7
+ export declare const AzureNetPlugin: (options?: AzureNetPluginOptions) => Plugin;
@@ -0,0 +1,402 @@
1
+ import path from 'node:path';
2
+ import fs from 'node:fs';
3
+ import ts from 'typescript';
4
+ const VIRTUAL_SERVER_UTILS_ID = 'virtual:azure-net-kit/server-utils';
5
+ const VIRTUAL_UNIVERSAL_UTILS_ID = 'virtual:azure-net-kit/universal-utils';
6
+ const RESOLVED_VIRTUAL_SERVER_UTILS_ID = `\0${VIRTUAL_SERVER_UTILS_ID}`;
7
+ const RESOLVED_VIRTUAL_UNIVERSAL_UTILS_ID = `\0${VIRTUAL_UNIVERSAL_UTILS_ID}`;
8
+ const VIRTUAL_SERVER_HOOKS_ID = 'virtual:azure-net-kit/hooks.server';
9
+ const VIRTUAL_CLIENT_HOOKS_ID = 'virtual:azure-net-kit/hooks.client';
10
+ const RESOLVED_VIRTUAL_SERVER_HOOKS_ID = `\0${VIRTUAL_SERVER_HOOKS_ID}`;
11
+ const RESOLVED_VIRTUAL_CLIENT_HOOKS_ID = `\0${VIRTUAL_CLIENT_HOOKS_ID}`;
12
+ const VIRTUAL_PROGRAM_ID = 'virtual:azure-net-kit/program';
13
+ const RESOLVED_VIRTUAL_PROGRAM_ID = `\0${VIRTUAL_PROGRAM_ID}`;
14
+ const GENERATED_MARKER = '__AZURE_NET_KIT_VIRTUAL_HOOK__';
15
+ const SYNC_MARKER = "void '__EDGES_SYNC_WRAPPED__';";
16
+ const LOAD_EXPORT_PATTERN = /export\s+const\s+load\s*(?::\s*[^=]+)?=/;
17
+ const ACTIONS_EXPORT_PATTERN = /export\s+const\s+actions\s*(?::\s*[^=]+)?=/;
18
+ const SERVER_ROUTE_PATTERN = /[\\/]\+((page|layout)\.server)\.(t|j)s$/;
19
+ const UNIVERSAL_ROUTE_PATTERN = /[\\/]\+((page|layout))\.(t|j)s$/;
20
+ const AST_SERVER_LOAD_ALIAS = '__edgesWrappedServerLoad';
21
+ const AST_ACTIONS_ALIAS = '__edgesWrappedActions';
22
+ const AST_UNIVERSAL_LOAD_ALIAS = '__edgesWrappedUniversalLoad';
23
+ const applyEdits = (sourceCode, edits) => {
24
+ if (edits.length === 0)
25
+ return sourceCode;
26
+ const sorted = edits.sort((a, b) => b.start - a.start);
27
+ let result = sourceCode;
28
+ for (const edit of sorted) {
29
+ result = result.slice(0, edit.start) + edit.text + result.slice(edit.end);
30
+ }
31
+ return result;
32
+ };
33
+ const findImportInsertPosition = (sourceCode) => {
34
+ const importRegex = /(?:^|\n)((?:import|export)\s+(?:type\s+)?(?:\{[^}]*\}|\*|\w+)(?:\s+from)?\s+['"][^'"]+['"];?)/gm;
35
+ let lastMatch = null;
36
+ let match;
37
+ while ((match = importRegex.exec(sourceCode)) !== null) {
38
+ lastMatch = match;
39
+ }
40
+ return lastMatch ? lastMatch.index + lastMatch[0].length : 0;
41
+ };
42
+ const findStaticImportInsertPosition = (sourceCode) => {
43
+ const importRegex = /(?:^|\n)(import\s+(?:type\s+)?(?:\{[^}]*\}|\*|\w+)(?:\s+from)?\s+['"][^'"]+['"];?)/gm;
44
+ let lastMatch = null;
45
+ let match;
46
+ while ((match = importRegex.exec(sourceCode)) !== null) {
47
+ lastMatch = match;
48
+ }
49
+ return lastMatch ? lastMatch.index + lastMatch[0].length : 0;
50
+ };
51
+ const ensureSyncImport = (sourceCode, importLine) => {
52
+ if (sourceCode.includes('__EDGES_SYNC_WRAPPED__'))
53
+ return sourceCode;
54
+ const insertPos = findImportInsertPosition(sourceCode);
55
+ const beforeImports = sourceCode.slice(0, insertPos);
56
+ const afterImports = sourceCode.slice(insertPos);
57
+ return `${beforeImports}\n${SYNC_MARKER}\n${importLine}\n${afterImports}`;
58
+ };
59
+ const ensureAstServerImport = (sourceCode) => ensureSyncImport(sourceCode, `import { __withEdgesServerLoad as ${AST_SERVER_LOAD_ALIAS}, __withEdgesActions as ${AST_ACTIONS_ALIAS} } from '${VIRTUAL_SERVER_UTILS_ID}';`);
60
+ const ensureAstUniversalImport = (sourceCode) => ensureSyncImport(sourceCode, `import { __withEdgesUniversalLoad as ${AST_UNIVERSAL_LOAD_ALIAS} } from '${VIRTUAL_UNIVERSAL_UTILS_ID}';`);
61
+ const ensureRegexServerImport = (sourceCode) => ensureSyncImport(sourceCode, `import { __withEdgesServerLoad, __withEdgesActions } from '${VIRTUAL_SERVER_UTILS_ID}';`);
62
+ const ensureRegexUniversalImport = (sourceCode) => ensureSyncImport(sourceCode, `import { __withEdgesUniversalLoad } from '${VIRTUAL_UNIVERSAL_UTILS_ID}';`);
63
+ const findExportedLocal = (sourceFile, code, exportedName) => {
64
+ const edits = [];
65
+ let localName = null;
66
+ let found = false;
67
+ for (const stmt of sourceFile.statements) {
68
+ if (ts.isVariableStatement(stmt)) {
69
+ const exportModifier = stmt.modifiers?.find((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword);
70
+ if (!exportModifier)
71
+ continue;
72
+ for (const declaration of stmt.declarationList.declarations) {
73
+ if (!ts.isIdentifier(declaration.name) || declaration.name.text !== exportedName)
74
+ continue;
75
+ localName = declaration.name.text;
76
+ found = true;
77
+ const modifierStart = exportModifier.getStart(sourceFile);
78
+ let modifierEnd = exportModifier.end;
79
+ while (modifierEnd < code.length && /\s/.test(code[modifierEnd]))
80
+ modifierEnd += 1;
81
+ edits.push({ start: modifierStart, end: modifierEnd, text: '' });
82
+ break;
83
+ }
84
+ }
85
+ if (!ts.isExportDeclaration(stmt) || !stmt.exportClause || !ts.isNamedExports(stmt.exportClause) || stmt.moduleSpecifier)
86
+ continue;
87
+ const keepSpecs = [];
88
+ let statementHasTarget = false;
89
+ for (const element of stmt.exportClause.elements) {
90
+ const exportName = element.name.text;
91
+ const sourceName = element.propertyName?.text ?? element.name.text;
92
+ if (exportName === exportedName) {
93
+ statementHasTarget = true;
94
+ found = true;
95
+ localName = sourceName;
96
+ continue;
97
+ }
98
+ keepSpecs.push(code.slice(element.getStart(sourceFile), element.end).trim());
99
+ }
100
+ if (!statementHasTarget)
101
+ continue;
102
+ if (keepSpecs.length === 0) {
103
+ edits.push({ start: stmt.getStart(sourceFile), end: stmt.end, text: '' });
104
+ }
105
+ else {
106
+ edits.push({ start: stmt.getStart(sourceFile), end: stmt.end, text: `export { ${keepSpecs.join(', ')} };` });
107
+ }
108
+ }
109
+ return { localName, edits, found };
110
+ };
111
+ const wrapServerRouteModuleRegex = (sourceCode) => {
112
+ if (!LOAD_EXPORT_PATTERN.test(sourceCode) && !ACTIONS_EXPORT_PATTERN.test(sourceCode))
113
+ return null;
114
+ let wrapped = ensureRegexServerImport(sourceCode);
115
+ if (LOAD_EXPORT_PATTERN.test(wrapped)) {
116
+ wrapped = wrapped
117
+ .replace(LOAD_EXPORT_PATTERN, (match) => match.replace('export const load', 'const __userLoad'))
118
+ .concat('\n\nexport const load = __withEdgesServerLoad(__userLoad);');
119
+ }
120
+ if (ACTIONS_EXPORT_PATTERN.test(wrapped)) {
121
+ wrapped = wrapped
122
+ .replace(ACTIONS_EXPORT_PATTERN, (match) => match.replace('export const actions', 'const __userActions'))
123
+ .concat('\n\nexport const actions = __withEdgesActions(__userActions);');
124
+ }
125
+ return wrapped;
126
+ };
127
+ const wrapUniversalRouteModuleRegex = (sourceCode) => {
128
+ if (!LOAD_EXPORT_PATTERN.test(sourceCode))
129
+ return null;
130
+ return ensureRegexUniversalImport(sourceCode)
131
+ .replace(LOAD_EXPORT_PATTERN, (match) => match.replace('export const load', 'const __userUniversalLoad'))
132
+ .concat('\n\nexport const load = __withEdgesUniversalLoad(__userUniversalLoad);');
133
+ };
134
+ const wrapServerRouteModuleAst = (sourceCode) => {
135
+ if (sourceCode.includes('__EDGES_SYNC_WRAPPED__'))
136
+ return null;
137
+ let sourceFile;
138
+ try {
139
+ sourceFile = ts.createSourceFile('route.ts', sourceCode, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
140
+ }
141
+ catch {
142
+ return null;
143
+ }
144
+ const loadInfo = findExportedLocal(sourceFile, sourceCode, 'load');
145
+ const actionsInfo = findExportedLocal(sourceFile, sourceCode, 'actions');
146
+ if (!loadInfo.found && !actionsInfo.found)
147
+ return null;
148
+ if ((loadInfo.found && !loadInfo.localName) || (actionsInfo.found && !actionsInfo.localName))
149
+ return null;
150
+ let nextCode = applyEdits(sourceCode, [...loadInfo.edits, ...actionsInfo.edits]);
151
+ nextCode = ensureAstServerImport(nextCode);
152
+ const append = [];
153
+ if (loadInfo.localName) {
154
+ append.push(`const __edgesServerLoad = ${AST_SERVER_LOAD_ALIAS}(${loadInfo.localName});`);
155
+ append.push('export { __edgesServerLoad as load };');
156
+ }
157
+ if (actionsInfo.localName) {
158
+ append.push(`const __edgesServerActions = ${AST_ACTIONS_ALIAS}(${actionsInfo.localName});`);
159
+ append.push('export { __edgesServerActions as actions };');
160
+ }
161
+ return `${nextCode}\n\n${append.join('\n')}`;
162
+ };
163
+ const wrapUniversalRouteModuleAst = (sourceCode) => {
164
+ if (sourceCode.includes('__EDGES_SYNC_WRAPPED__'))
165
+ return null;
166
+ let sourceFile;
167
+ try {
168
+ sourceFile = ts.createSourceFile('route.ts', sourceCode, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
169
+ }
170
+ catch {
171
+ return null;
172
+ }
173
+ const loadInfo = findExportedLocal(sourceFile, sourceCode, 'load');
174
+ if (!loadInfo.found || !loadInfo.localName)
175
+ return null;
176
+ let nextCode = applyEdits(sourceCode, [...loadInfo.edits]);
177
+ nextCode = ensureAstUniversalImport(nextCode);
178
+ return `${nextCode}\n\nconst __edgesUniversalLoad = ${AST_UNIVERSAL_LOAD_ALIAS}(${loadInfo.localName});\nexport { __edgesUniversalLoad as load };`;
179
+ };
180
+ const createVirtualServerHooks = (silentChromeDevtools) => `// ${GENERATED_MARKER}
181
+ import { edgesHandle } from '${VIRTUAL_SERVER_UTILS_ID}';
182
+ import { register } from '${VIRTUAL_PROGRAM_ID}';
183
+
184
+ export const init = register.serverInit;
185
+
186
+ export const handle = edgesHandle(({ serialize, edgesEvent, resolve }) =>
187
+ register.handle({
188
+ event: edgesEvent,
189
+ resolve: (event, options) =>
190
+ resolve(event, {
191
+ ...options,
192
+ transformPageChunk: async (chunk) => {
193
+ const html = options?.transformPageChunk ? await options.transformPageChunk(chunk) : chunk.html;
194
+ return serialize(html);
195
+ }
196
+ })
197
+ })
198
+ ${silentChromeDevtools ? ')' : ', false)'};
199
+
200
+ export const handleError = register.serverError;
201
+ `;
202
+ const createVirtualServerUtils = () => "export { edgesHandle, edgesHandleRaw, __autoWrapHandle, __withEdgesServerLoad, __withEdgesActions } from '@azure-net/edges/server';";
203
+ const createVirtualUniversalUtils = () => `const EDGES_STATE_FIELD = '__edges_state__';
204
+ const EDGES_REV_FIELD = '__edges_rev__';
205
+
206
+ const isObjectRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
207
+
208
+ export const __withEdgesUniversalLoad = (load) => {
209
+ \tconst wrapped = async (...args) => {
210
+ \t\tconst event = args[0];
211
+ \t\tconst result = await load(...args);
212
+ \t\tif (!isObjectRecord(event?.data)) return result;
213
+
214
+ \t\tconst inheritedState = event.data[EDGES_STATE_FIELD];
215
+ \t\tconst inheritedRev = event.data[EDGES_REV_FIELD];
216
+ \t\tif (!inheritedState) return result;
217
+
218
+ \t\tif (isObjectRecord(result)) {
219
+ \t\t\treturn {
220
+ \t\t\t\t...result,
221
+ \t\t\t\t[EDGES_STATE_FIELD]: inheritedState,
222
+ \t\t\t\t[EDGES_REV_FIELD]: inheritedRev
223
+ \t\t\t};
224
+ \t\t}
225
+
226
+ \t\tif (result === undefined) {
227
+ \t\t\treturn {
228
+ \t\t\t\t[EDGES_STATE_FIELD]: inheritedState,
229
+ \t\t\t\t[EDGES_REV_FIELD]: inheritedRev
230
+ \t\t\t};
231
+ \t\t}
232
+
233
+ \t\treturn result;
234
+ \t};
235
+
236
+ \treturn wrapped;
237
+ };
238
+ `;
239
+ const createVirtualClientHooks = () => `// ${GENERATED_MARKER}
240
+ import { register } from '${VIRTUAL_PROGRAM_ID}';
241
+
242
+ export const init = register.clientInit;
243
+ export const handleError = register.clientError;
244
+ `;
245
+ const createVirtualProgram = (root) => {
246
+ const tsProgram = path.join(root, 'src', 'program.ts');
247
+ const jsProgram = path.join(root, 'src', 'program.js');
248
+ if (fs.existsSync(tsProgram))
249
+ return `export { register } from '/src/program.ts';`;
250
+ if (fs.existsSync(jsProgram))
251
+ return `export { register } from '/src/program.js';`;
252
+ return `import { createApp } from '@azure-net/kit';
253
+
254
+ export const { register, App } = createApp((app) => app);
255
+ `;
256
+ };
257
+ const hasUserHook = (root, hookName) => {
258
+ const srcPath = path.join(root, 'src');
259
+ const candidates = ['.ts', '.js'].map((extension) => path.join(srcPath, `${hookName}${extension}`));
260
+ for (const candidate of candidates) {
261
+ if (fs.existsSync(candidate))
262
+ return candidate;
263
+ }
264
+ return null;
265
+ };
266
+ const assertNoUserHooks = (root) => {
267
+ const serverHook = hasUserHook(root, 'hooks.server');
268
+ const clientHook = hasUserHook(root, 'hooks.client');
269
+ const hook = serverHook ?? clientHook;
270
+ if (!hook)
271
+ return;
272
+ throw new Error(`[AzureNetPlugin] ${path.relative(root, hook)} is not allowed when AzureNetPlugin is enabled. ` +
273
+ 'Move your lifecycle code to src/program.ts via createApp().');
274
+ };
275
+ const ensureVirtualImport = (sourceCode, importLine) => {
276
+ if (sourceCode.includes(importLine))
277
+ return sourceCode;
278
+ const insertPos = findStaticImportInsertPosition(sourceCode);
279
+ return `${sourceCode.slice(0, insertPos)}\n${importLine}\n${sourceCode.slice(insertPos)}`;
280
+ };
281
+ const transformGeneratedServerInternal = (sourceCode) => {
282
+ if (sourceCode.includes(GENERATED_MARKER))
283
+ return null;
284
+ const universalImportMatch = sourceCode.match(/\(\{\s*reroute,\s*transport\s*\}\s*=\s*await\s*import\([^)]+\)\);/);
285
+ const universalImport = universalImportMatch?.[0] ? `\n\t${universalImportMatch[0]}` : '';
286
+ const importLine = `import * as __azureNetServerHooks from '${VIRTUAL_SERVER_HOOKS_ID}';`;
287
+ const getHooksReplacement = `export async function get_hooks() {
288
+ \tlet reroute;
289
+ \tlet transport;${universalImport}
290
+
291
+ \treturn {
292
+ \t\thandle: __azureNetServerHooks.handle,
293
+ \t\thandleFetch: undefined,
294
+ \t\thandleError: __azureNetServerHooks.handleError,
295
+ \t\thandleValidationError: undefined,
296
+ \t\tinit: __azureNetServerHooks.init,
297
+ \t\treroute,
298
+ \t\ttransport
299
+ \t};
300
+ }`;
301
+ const transformed = ensureVirtualImport(sourceCode, `// ${GENERATED_MARKER}\n${importLine}`).replace(/export\s+async\s+function\s+get_hooks\s*\(\)\s*\{[\s\S]*?\n\}/m, getHooksReplacement);
302
+ return transformed;
303
+ };
304
+ const transformGeneratedClientApp = (sourceCode) => {
305
+ if (sourceCode.includes(GENERATED_MARKER))
306
+ return null;
307
+ let transformed = ensureVirtualImport(sourceCode, `// ${GENERATED_MARKER}\nimport * as __azureNetClientHooks from '${VIRTUAL_CLIENT_HOOKS_ID}';`);
308
+ transformed = transformed.replace(/import\s+\*\s+as\s+client_hooks\s+from\s+['"][^'"]*hooks\.client\.(?:ts|js)['"];\s*\n*/g, '');
309
+ transformed = transformed.replace(/handleError:\s*(?:client_hooks\.handleError\s*\|\|\s*)?\(\(\{\s*error\s*\}\)\s*=>\s*\{\s*console\.error\(error\)\s*\}\)/m, 'handleError: __azureNetClientHooks.handleError');
310
+ if (/^\s*init:\s*[^,\n]+,?/m.test(transformed)) {
311
+ transformed = transformed.replace(/^\s*init:\s*[^,\n]+,?/m, '\tinit: __azureNetClientHooks.init,');
312
+ }
313
+ else {
314
+ transformed = transformed.replace(/handleError:\s*__azureNetClientHooks\.handleError,?/m, 'handleError: __azureNetClientHooks.handleError,\n\tinit: __azureNetClientHooks.init,');
315
+ }
316
+ return transformed;
317
+ };
318
+ export const AzureNetPlugin = (options) => {
319
+ const { silentChromeDevtools = true, syncFromServer = true, syncTransformMode = 'hybrid' } = options || {};
320
+ let root = process.cwd();
321
+ let isTestMode = false;
322
+ return {
323
+ name: 'azure-net-kit-plugin',
324
+ enforce: 'pre',
325
+ config(config, env) {
326
+ root = path.resolve(config.root ?? process.cwd());
327
+ isTestMode = env.mode === 'test';
328
+ assertNoUserHooks(root);
329
+ },
330
+ configResolved(config) {
331
+ root = config.root;
332
+ isTestMode ||= config.mode === 'test';
333
+ assertNoUserHooks(root);
334
+ },
335
+ buildStart() {
336
+ assertNoUserHooks(root);
337
+ },
338
+ resolveId(id) {
339
+ if (id === VIRTUAL_SERVER_UTILS_ID)
340
+ return RESOLVED_VIRTUAL_SERVER_UTILS_ID;
341
+ if (id === VIRTUAL_UNIVERSAL_UTILS_ID)
342
+ return RESOLVED_VIRTUAL_UNIVERSAL_UTILS_ID;
343
+ if (id === VIRTUAL_SERVER_HOOKS_ID)
344
+ return RESOLVED_VIRTUAL_SERVER_HOOKS_ID;
345
+ if (id === VIRTUAL_CLIENT_HOOKS_ID)
346
+ return RESOLVED_VIRTUAL_CLIENT_HOOKS_ID;
347
+ if (id === VIRTUAL_PROGRAM_ID)
348
+ return RESOLVED_VIRTUAL_PROGRAM_ID;
349
+ return null;
350
+ },
351
+ load(id) {
352
+ if (id === RESOLVED_VIRTUAL_SERVER_UTILS_ID)
353
+ return createVirtualServerUtils();
354
+ if (id === RESOLVED_VIRTUAL_UNIVERSAL_UTILS_ID)
355
+ return createVirtualUniversalUtils();
356
+ if (id === RESOLVED_VIRTUAL_SERVER_HOOKS_ID)
357
+ return createVirtualServerHooks(silentChromeDevtools);
358
+ if (id === RESOLVED_VIRTUAL_CLIENT_HOOKS_ID)
359
+ return createVirtualClientHooks();
360
+ if (id === RESOLVED_VIRTUAL_PROGRAM_ID)
361
+ return createVirtualProgram(root);
362
+ return null;
363
+ },
364
+ transform(code, id) {
365
+ const normalizedId = id.split(path.sep).join('/');
366
+ if (!isTestMode && normalizedId.endsWith('/.svelte-kit/generated/server/internal.js')) {
367
+ const transformed = transformGeneratedServerInternal(code);
368
+ if (transformed)
369
+ return { code: transformed, map: null };
370
+ return null;
371
+ }
372
+ if (!isTestMode &&
373
+ (normalizedId.endsWith('/.svelte-kit/generated/client/app.js') || normalizedId.endsWith('/.svelte-kit/generated/client-optimized/app.js'))) {
374
+ const transformed = transformGeneratedClientApp(code);
375
+ if (transformed)
376
+ return { code: transformed, map: null };
377
+ return null;
378
+ }
379
+ if (code.includes('__EDGES_SYNC_WRAPPED__'))
380
+ return null;
381
+ if (syncFromServer && SERVER_ROUTE_PATTERN.test(id) && !id.includes('hooks.server')) {
382
+ const wrapped = syncTransformMode === 'regex'
383
+ ? wrapServerRouteModuleRegex(code)
384
+ : syncTransformMode === 'ast'
385
+ ? wrapServerRouteModuleAst(code)
386
+ : (wrapServerRouteModuleAst(code) ?? wrapServerRouteModuleRegex(code));
387
+ if (wrapped)
388
+ return { code: wrapped, map: null };
389
+ }
390
+ if (syncFromServer && UNIVERSAL_ROUTE_PATTERN.test(id) && !id.includes('.server.')) {
391
+ const wrapped = syncTransformMode === 'regex'
392
+ ? wrapUniversalRouteModuleRegex(code)
393
+ : syncTransformMode === 'ast'
394
+ ? wrapUniversalRouteModuleAst(code)
395
+ : (wrapUniversalRouteModuleAst(code) ?? wrapUniversalRouteModuleRegex(code));
396
+ if (wrapped)
397
+ return { code: wrapped, map: null };
398
+ }
399
+ return null;
400
+ }
401
+ };
402
+ };
@@ -0,0 +1 @@
1
+ export { AzureNetPlugin, type AzureNetPluginOptions } from './AzureNetPlugin.js';
@@ -0,0 +1 @@
1
+ export { AzureNetPlugin } from './AzureNetPlugin.js';