@azure-net/kit 1.3.3 → 1.3.7

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 CHANGED
@@ -1,58 +1,42 @@
1
- # Svelte library
1
+ # Welcome to **@azure-net/kit**
2
2
 
3
- Everything you need to build a Svelte library, powered by [`sv`](https://npmjs.com/package/sv).
3
+ #### [docs](https://svelte.kit.azure-net.ru)
4
4
 
5
- Read more about creating a library [in the docs](https://svelte.dev/docs/kit/packaging).
5
+ **@azure-net/kit** is a universal toolkit and library collection, developed as part of the **Azure-net** ecosystem. It is designed to speed up modern application development, reduce boilerplate code, and maintain a unified project architecture.
6
6
 
7
- ## Creating a project
7
+ ## What is it?
8
8
 
9
- If you're seeing this, you've probably already done this step. Congrats!
9
+ **@azure-net/kit** is much more than just a collection of utilities or components. It is a complete **architecture** (Azure-net Architecture) based on **DDD (Domain-Driven Design)** principles, helping you build scalable and maintainable projects with a clear structure.
10
10
 
11
- ```bash
12
- # create a new project in the current directory
13
- npx sv create
11
+ ## 🚀 What's included?
14
12
 
15
- # create a new project in my-app
16
- npx sv create my-app
17
- ```
13
+ - **Built-in store** flexible and SSR-friendly state management powered by [edges-svelte](https://github.com/Pixel1917/edge-s).
14
+ - **Localization and translation** — ready-to-use i18n solution ([edges-svelte-translations](https://github.com/Pixel1917/edges-svelte-translations)) for multilingual applications.
15
+ - **Extensive utilities** — for working with text, objects, dates, and common tasks.
16
+ - **Data validation** — handy rules and validators.
17
+ - **Reusable base abstractions** — `Repositories`, `Services`, `Providers`, and `Datasources` for quick setup and reuse.
18
+ - **Unified architecture approach** — the package provides a solid project structure and helps enforce consistent development standards.
18
19
 
19
- ## Developing
20
+ ## 🎯 Why use it?
20
21
 
21
- Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
22
+ By using **@azure-net/kit**, you get a ready-to-use project framework that:
22
23
 
23
- ```bash
24
- npm run dev
24
+ - reduces boilerplate code,
25
+ - accelerates development,
26
+ - simplifies testing,
27
+ - supports a clear and predictable architecture.
25
28
 
26
- # or start the server and open the app in a new browser tab
27
- npm run dev -- --open
28
- ```
29
+ This is especially useful for teamwork on medium to large-scale applications.
29
30
 
30
- Everything inside `src/lib` is part of your library, everything inside `src/routes` can be used as a showcase or preview app.
31
+ ## 📚 Learn more
31
32
 
32
- ## Building
33
+ In this guide, you will find:
33
34
 
34
- To build your library:
35
+ - Step-by-step instructions for setup and configuration.
36
+ - Detailed explanations of architectural patterns.
37
+ - Examples of using the built-in store and translation.
38
+ - Recommendations for organizing code with `Repositories`, `Services`, and `Datasources`.
35
39
 
36
- ```bash
37
- npm run package
38
- ```
40
+ ## 🚀 Get started
39
41
 
40
- To create a production version of your showcase app:
41
-
42
- ```bash
43
- npm run build
44
- ```
45
-
46
- You can preview the production build with `npm run preview`.
47
-
48
- > To deploy your app, you may need to install an [adapter](https://svelte.dev/docs/kit/adapters) for your target environment.
49
-
50
- ## Publishing
51
-
52
- Go into the `package.json` and give your package the desired name through the `"name"` option. Also consider adding a `"license"` field and point it to a `LICENSE` file which you can create from a template (one popular option is the [MIT license](https://opensource.org/license/mit/)).
53
-
54
- To publish your library to [npm](https://www.npmjs.com):
55
-
56
- ```bash
57
- npm publish
58
- ```
42
+ Ready to dive in? Check out the [docs](https://svelte.kit.azure-net.ru) and start building your app faster and more reliably with **Azure-net**.
@@ -1,4 +1,7 @@
1
1
  import { error, fail, redirect, type RequestEvent } from '@sveltejs/kit';
2
+ type NoConflict<I, D> = {
3
+ [K in keyof I]: K extends keyof D ? never : I[K];
4
+ };
2
5
  type Deps = {
3
6
  context: RequestEvent;
4
7
  utils: {
@@ -7,5 +10,6 @@ type Deps = {
7
10
  error: typeof error;
8
11
  };
9
12
  };
10
- export declare const createServerAction: <T>(factory: (args: Deps) => T) => (() => T);
13
+ export declare const createServerAction: <T, I extends Record<string, unknown> = Record<string, unknown>>(factory: (args: Deps & NoConflict<I, Deps>) => T, inject?: I) => (() => T);
14
+ export declare const createServerActionFactory: <I extends Record<string, unknown>>(inject: I) => <T>(factory: (args: Deps & NoConflict<I, Deps>) => T) => () => T;
11
15
  export {};
@@ -1,12 +1,22 @@
1
1
  import { RequestContext } from '../../../edges/context/index.js';
2
2
  import { error, fail, redirect } from '@sveltejs/kit';
3
3
  import { EnvironmentUtil } from 'azure-net-tools';
4
- export const createServerAction = (factory) => {
4
+ export const createServerAction = (factory, inject) => {
5
5
  return () => {
6
6
  if (EnvironmentUtil.isBrowser) {
7
7
  throw Error('Do not use actions on client side');
8
8
  }
9
9
  const context = RequestContext.current().event;
10
- return factory({ context, utils: { fail, redirect, error } });
10
+ const deps = {
11
+ context,
12
+ utils: { fail, redirect, error },
13
+ ...inject
14
+ };
15
+ return factory(deps);
16
+ };
17
+ };
18
+ export const createServerActionFactory = (inject) => {
19
+ return function createInjectedServerAction(factory) {
20
+ return createServerAction(factory, inject);
11
21
  };
12
22
  };
@@ -2,7 +2,6 @@ import type { HttpServiceResponse } from '../httpService/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;
5
- type DeepValue<T, Path extends string> = Path extends `${infer Key}.${infer Rest}` ? Key extends keyof T ? DeepValue<T[Key], Rest> : never : Path extends keyof T ? T[Path] : never;
6
5
  type ResponseBuilderState<TData, TMeta = unknown> = {
7
6
  data: TData;
8
7
  meta: TMeta;
@@ -15,12 +14,12 @@ export declare class ResponseBuilder<TData = unknown, TMeta = object, TWrapper =
15
14
  protected unwrapData(data: TWrapper): TData;
16
15
  mapUsing<TResource>(ResourceClass: new (data: TData) => {
17
16
  toPlainObject(): TResource;
18
- }): ResponseBuilder<TResource, TMeta, TWrapper>;
17
+ }): this;
19
18
  mapCollectionUsing<TResource>(ResourceClass: new (data: ArrayElement<TData>) => {
20
19
  toPlainObject(): TResource;
21
- }): ResponseBuilder<TResource[], TMeta, TWrapper>;
22
- extract<TPath extends DeepKeys<TData>>(path: TPath): ResponseBuilder<DeepValue<TData, TPath>, TMeta, TWrapper>;
23
- addMeta<TNewMeta extends Record<string, unknown>>(metaData: TNewMeta | ((current: TMeta) => TNewMeta)): ResponseBuilder<TData, TMeta & TNewMeta, TWrapper>;
20
+ }): this;
21
+ extract<TPath extends DeepKeys<TData>>(path: TPath): this;
22
+ addMeta<TNewMeta extends Record<string, unknown>>(metaData: TNewMeta | ((current: TMeta) => TNewMeta)): Omit<this, keyof ResponseBuilder<unknown, unknown, unknown>> & ResponseBuilder<TData, TMeta & TNewMeta, TWrapper>;
24
23
  getData(): TData;
25
24
  get(): {
26
25
  data: TData;
@@ -13,7 +13,7 @@ export class ResponseBuilder {
13
13
  }
14
14
  mapUsing(ResourceClass) {
15
15
  const resource = new ResourceClass(this.state.data);
16
- const newResponse = new ResponseBuilder(this.response);
16
+ const newResponse = new this.constructor(this.response);
17
17
  newResponse.state = {
18
18
  ...this.state,
19
19
  data: resource.toPlainObject()
@@ -25,7 +25,7 @@ export class ResponseBuilder {
25
25
  throw new Error('toCollection can only be used when data is an array');
26
26
  }
27
27
  const collection = this.state.data.map((dataElement) => new ResourceClass(dataElement).toPlainObject());
28
- const newResponse = new ResponseBuilder(this.response);
28
+ const newResponse = new this.constructor(this.response);
29
29
  newResponse.state = {
30
30
  ...this.state,
31
31
  data: collection
@@ -43,7 +43,7 @@ export class ResponseBuilder {
43
43
  throw new Error(`Path "${path}" not found in response data`);
44
44
  }
45
45
  }
46
- const newResponse = new ResponseBuilder(this.response);
46
+ const newResponse = new this.constructor(this.response);
47
47
  newResponse.state = {
48
48
  ...this.state,
49
49
  data: result
@@ -52,7 +52,7 @@ export class ResponseBuilder {
52
52
  }
53
53
  addMeta(metaData) {
54
54
  const newMeta = typeof metaData === 'function' ? metaData(this.state.meta) : metaData;
55
- const newResponse = new ResponseBuilder(this.response);
55
+ const newResponse = new this.constructor(this.response);
56
56
  newResponse.state = {
57
57
  ...this.state,
58
58
  meta: { ...this.state.meta, ...newMeta }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azure-net/kit",
3
- "version": "1.3.3",
3
+ "version": "1.3.7",
4
4
  "files": [
5
5
  "dist",
6
6
  "!dist/**/*.test.*",