api-def 0.12.0-alpha.10 → 0.12.0-alpha.13

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/bin/index.js CHANGED
@@ -258564,6 +258564,7 @@ var openApiToSourceCode = async (options) => {
258564
258564
  const API = new Api({
258565
258565
  name: "${bundleResults.bundle.parsed.info.title || "Generate Api"}",
258566
258566
  baseUrl: "${server2.url}",
258567
+ mutable: true,
258567
258568
  });
258568
258569
 
258569
258570
  ${Object.entries(routes).flatMap(([path2, route]) => {
package/cjs/Api.d.ts CHANGED
@@ -20,7 +20,11 @@ export type ApiInfo = ApiOptions & Required<Pick<ApiOptions, "middleware" | "req
20
20
  export declare class Api implements ApiInfo {
21
21
  private readonly info;
22
22
  protected readonly endpoints: Record<string, Endpoint>;
23
- constructor(options: ApiOptions);
23
+ private mutable;
24
+ private wasMutable;
25
+ constructor(options: ApiOptions & {
26
+ readonly mutable?: boolean;
27
+ });
24
28
  get requestBackend(): RequestBackend;
25
29
  get baseUrl(): string;
26
30
  /**
@@ -41,6 +45,7 @@ export declare class Api implements ApiInfo {
41
45
  */
42
46
  getConfig(): BaseRequestConfig;
43
47
  computeRequestConfig(): BaseRequestConfig;
48
+ configure(info: Partial<ApiInfo>): void;
44
49
  private hotRequest;
45
50
  get: <R = unknown>(path: string, config: RequestConfig) => Promise<ApiResponse<R>>;
46
51
  post: <R = unknown>(path: string, config: RequestConfig) => Promise<ApiResponse<R>>;
package/cjs/Api.js CHANGED
@@ -89,25 +89,10 @@ var HotRequestHost = /** @class */ (function () {
89
89
  var Api = /** @class */ (function () {
90
90
  function Api(options) {
91
91
  var _this = this;
92
- var _a, _b;
92
+ var _a, _b, _c;
93
93
  this.endpoints = {};
94
- /*reconfigure(info: Partial<ApiInfo>): void {
95
- if (info.requestBackend) {
96
- (this as any).requestBackend = info.requestBackend;
97
- }
98
- if (info.config) {
99
- (this as any).config = info.config;
100
- }
101
- if (info.middleware) {
102
- (this as any).middleware = info.middleware;
103
- }
104
- if (info.mocking) {
105
- (this as any).mocking = info.mocking;
106
- }
107
- if (info.baseUrl) {
108
- (this as any).baseUrl = info.baseUrl;
109
- }
110
- }*/
94
+ this.mutable = false;
95
+ this.wasMutable = false;
111
96
  this.hotRequest = function (requestMethod) {
112
97
  return function (path, config) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
113
98
  switch (_a.label) {
@@ -134,6 +119,8 @@ var Api = /** @class */ (function () {
134
119
  mocking: (_b = options.mocking) !== null && _b !== void 0 ? _b : undefined,
135
120
  requestBackend: requestBackend,
136
121
  };
122
+ this.mutable = (_c = options.mutable) !== null && _c !== void 0 ? _c : false;
123
+ this.wasMutable = this.mutable;
137
124
  this.endpoints = {};
138
125
  }
139
126
  Object.defineProperty(Api.prototype, "requestBackend", {
@@ -206,6 +193,13 @@ var Api = /** @class */ (function () {
206
193
  Api.prototype.computeRequestConfig = function () {
207
194
  return (typeof this.requestConfig === "function" ? this.requestConfig() : this.requestConfig) || {};
208
195
  };
196
+ Api.prototype.configure = function (info) {
197
+ if (!this.mutable) {
198
+ throw new Error("[api-def] ".concat(this.wasMutable ? "Cannot configure a mutable API twice" : "Cannot configure an immutable API"));
199
+ }
200
+ Object.assign(this.info, info);
201
+ this.mutable = false;
202
+ };
209
203
  return Api;
210
204
  }());
211
205
  exports.Api = Api;
package/esm/Api.d.ts CHANGED
@@ -20,7 +20,11 @@ export type ApiInfo = ApiOptions & Required<Pick<ApiOptions, "middleware" | "req
20
20
  export declare class Api implements ApiInfo {
21
21
  private readonly info;
22
22
  protected readonly endpoints: Record<string, Endpoint>;
23
- constructor(options: ApiOptions);
23
+ private mutable;
24
+ private wasMutable;
25
+ constructor(options: ApiOptions & {
26
+ readonly mutable?: boolean;
27
+ });
24
28
  get requestBackend(): RequestBackend;
25
29
  get baseUrl(): string;
26
30
  /**
@@ -41,6 +45,7 @@ export declare class Api implements ApiInfo {
41
45
  */
42
46
  getConfig(): BaseRequestConfig;
43
47
  computeRequestConfig(): BaseRequestConfig;
48
+ configure(info: Partial<ApiInfo>): void;
44
49
  private hotRequest;
45
50
  get: <R = unknown>(path: string, config: RequestConfig) => Promise<ApiResponse<R>>;
46
51
  post: <R = unknown>(path: string, config: RequestConfig) => Promise<ApiResponse<R>>;
package/esm/Api.js CHANGED
@@ -50,25 +50,10 @@ class HotRequestHost {
50
50
  }
51
51
  export class Api {
52
52
  constructor(options) {
53
- var _a, _b;
53
+ var _a, _b, _c;
54
54
  this.endpoints = {};
55
- /*reconfigure(info: Partial<ApiInfo>): void {
56
- if (info.requestBackend) {
57
- (this as any).requestBackend = info.requestBackend;
58
- }
59
- if (info.config) {
60
- (this as any).config = info.config;
61
- }
62
- if (info.middleware) {
63
- (this as any).middleware = info.middleware;
64
- }
65
- if (info.mocking) {
66
- (this as any).mocking = info.mocking;
67
- }
68
- if (info.baseUrl) {
69
- (this as any).baseUrl = info.baseUrl;
70
- }
71
- }*/
55
+ this.mutable = false;
56
+ this.wasMutable = false;
72
57
  this.hotRequest = (requestMethod) => (path, config) => __awaiter(this, void 0, void 0, function* () { return yield Requester.submit(new HotRequestHost(this, path, requestMethod), config, null); });
73
58
  this.get = this.hotRequest(RequestMethod.GET);
74
59
  this.post = this.hotRequest(RequestMethod.POST);
@@ -88,6 +73,8 @@ export class Api {
88
73
  mocking: (_b = options.mocking) !== null && _b !== void 0 ? _b : undefined,
89
74
  requestBackend: requestBackend,
90
75
  };
76
+ this.mutable = (_c = options.mutable) !== null && _c !== void 0 ? _c : false;
77
+ this.wasMutable = this.mutable;
91
78
  this.endpoints = {};
92
79
  }
93
80
  get requestBackend() {
@@ -132,4 +119,11 @@ export class Api {
132
119
  computeRequestConfig() {
133
120
  return (typeof this.requestConfig === "function" ? this.requestConfig() : this.requestConfig) || {};
134
121
  }
122
+ configure(info) {
123
+ if (!this.mutable) {
124
+ throw new Error(`[api-def] ${this.wasMutable ? "Cannot configure a mutable API twice" : "Cannot configure an immutable API"}`);
125
+ }
126
+ Object.assign(this.info, info);
127
+ this.mutable = false;
128
+ }
135
129
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "api-def",
3
- "version": "0.12.0-alpha.10",
3
+ "version": "0.12.0-alpha.13",
4
4
  "description": "Typed API definitions with middleware support",
5
5
  "main": "cjs/index.js",
6
6
  "types": "esm/index.d.ts",