oc-server 1.1.10 → 1.1.11

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/dist/Server.d.ts CHANGED
@@ -7,21 +7,51 @@ type AnyAction = Action<any, any, any, any, any>;
7
7
  type IsGeneralStringName<T> = T extends {
8
8
  name: infer N;
9
9
  } ? N extends string ? string extends N ? true : false : false : false;
10
+ type OcParameter = {
11
+ description?: string;
12
+ mandatory?: boolean;
13
+ } & ({
14
+ type: 'string';
15
+ example?: string;
16
+ default?: string;
17
+ } | {
18
+ type: 'boolean';
19
+ example?: boolean;
20
+ default?: boolean;
21
+ } | {
22
+ type: 'number';
23
+ example?: number;
24
+ default?: number;
25
+ });
26
+ type OcParameters = Record<string, OcParameter>;
27
+ type TransformStringifiedTypeToType<T> = T extends 'string' ? string : T extends 'number' ? number : T extends 'boolean' ? boolean : never;
28
+ type TransformOcParameters<T extends OcParameters> = Prettify<Pick<{
29
+ [K in keyof T]: TransformStringifiedTypeToType<T[K]['type']>;
30
+ }, {
31
+ [K in keyof T]: T[K]['mandatory'] extends true ? K : never;
32
+ }[keyof T]> & Partial<Pick<{
33
+ [K in keyof T]: TransformStringifiedTypeToType<T[K]['type']>;
34
+ }, {
35
+ [K in keyof T]: T[K]['mandatory'] extends true ? never : K;
36
+ }[keyof T]>>>;
10
37
  export declare class Server<E = {
11
38
  name: string;
12
39
  }, P = unknown, A extends Record<string, AnyAction> = {}, InitialInput = any, InitialOutput = any, MiddlewareInput = any, MiddlewareOutput = any> {
40
+ private _parameters;
13
41
  private _middleware;
14
42
  constructor();
15
- middleware<I, O>(action: Action<I, O, E, P, unknown>): Omit<Server<E, P, A, InitialInput, InitialOutput, I, O>, P extends Record<string, unknown> ? IsGeneralStringName<E> extends false ? 'middleware' | 'definePlugins' | 'defineEnv' : 'middleware' | 'definePlugins' : IsGeneralStringName<E> extends false ? 'middleware' | 'defineEnv' : 'middleware'>;
43
+ middleware<I = MiddlewareInput, O = MiddlewareOutput>(action: Action<I, O, E, P, unknown>): Omit<Server<E, P, A, InitialInput, InitialOutput, I, O>, P extends Record<string, unknown> ? IsGeneralStringName<E> extends false ? 'middleware' | 'definePlugins' | 'defineEnv' : 'middleware' | 'definePlugins' : IsGeneralStringName<E> extends false ? 'middleware' | 'defineEnv' : 'middleware'>;
44
+ withParameters<T extends OcParameters>(params: T): Server<E, P, A, TransformOcParameters<T>, InitialOutput, TransformOcParameters<T>, MiddlewareOutput>;
16
45
  defineEnv<Env>(): P extends Record<string, any> ? Omit<Server<Env, P, A, InitialInput, InitialOutput>, 'defineEnv' | 'definePlugins'> : Omit<Server<Env, P, A, InitialInput, InitialOutput>, 'defineEnv'>;
17
46
  definePlugins<Plugins>(): IsGeneralStringName<E> extends true ? Omit<Server<E, Plugins, A, InitialInput, InitialOutput>, 'definePlugins'> : Omit<Server<E, Plugins, A, InitialInput, InitialOutput>, 'definePlugins' | 'defineEnv'>;
18
- handler<I, O>(action: Action<I, O, E, P, MiddlewareOutput>): HandledServer<E, P, A, I, O, MiddlewareInput, MiddlewareOutput>;
47
+ handler<I = InitialInput, O = InitialOutput>(action: Action<I, O, E, P, MiddlewareOutput>): HandledServer<E, P, A, I, O, MiddlewareInput, MiddlewareOutput>;
19
48
  }
20
49
  declare class HandledServer<E, P, A extends Record<string, AnyAction> = {}, InitialInput = any, InitialOutput = any, MiddlewareInput = any, MiddlewareOutput = any> {
21
50
  readonly initial: Action<InitialInput, InitialOutput, E, P, MiddlewareOutput>;
22
51
  private readonly _middleware;
52
+ private readonly _parameters;
23
53
  readonly actions: A;
24
- constructor(initial: Action<InitialInput, InitialOutput, E, P, MiddlewareOutput>, _middleware?: Action<MiddlewareInput, MiddlewareOutput, E, P, unknown> | null);
54
+ constructor(initial: Action<InitialInput, InitialOutput, E, P, MiddlewareOutput>, _middleware?: Action<MiddlewareInput, MiddlewareOutput, E, P, unknown> | null, _parameters?: OcParameters);
25
55
  action<ActionName extends string, I, O>(name: ActionName, action: Action<I, O, E, P, MiddlewareOutput>): HandledServer<E, P, Prettify<A & Record<ActionName, Action<I, O, E, P, MiddlewareOutput>>>, InitialInput, InitialOutput, MiddlewareInput, MiddlewareOutput>;
26
56
  getData(): DataProvider<any, any, any>;
27
57
  }
package/dist/Server.js CHANGED
@@ -2,12 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ServerError = exports.getSettings = exports.getInitialData = exports.Server = void 0;
4
4
  class Server {
5
+ _parameters = {};
5
6
  _middleware = null;
6
7
  constructor() { }
7
8
  middleware(action) {
8
9
  this._middleware = action;
9
10
  return this;
10
11
  }
12
+ withParameters(params) {
13
+ this._parameters = params;
14
+ return this;
15
+ }
11
16
  defineEnv() {
12
17
  return this;
13
18
  }
@@ -15,17 +20,19 @@ class Server {
15
20
  return this;
16
21
  }
17
22
  handler(action) {
18
- return new HandledServer(action, this._middleware);
23
+ return new HandledServer(action, this._middleware, this._parameters);
19
24
  }
20
25
  }
21
26
  exports.Server = Server;
22
27
  class HandledServer {
23
28
  initial;
24
29
  _middleware;
30
+ _parameters;
25
31
  actions = {};
26
- constructor(initial, _middleware = null) {
32
+ constructor(initial, _middleware = null, _parameters = {}) {
27
33
  this.initial = initial;
28
34
  this._middleware = _middleware;
35
+ this._parameters = _parameters;
29
36
  }
30
37
  action(name, action) {
31
38
  this.actions[name] = action;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oc-server",
3
- "version": "1.1.10",
3
+ "version": "1.1.11",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",