api-def 0.12.0-alpha.11 → 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
@@ -21,6 +21,7 @@ export declare class Api implements ApiInfo {
21
21
  private readonly info;
22
22
  protected readonly endpoints: Record<string, Endpoint>;
23
23
  private mutable;
24
+ private wasMutable;
24
25
  constructor(options: ApiOptions & {
25
26
  readonly mutable?: boolean;
26
27
  });
package/cjs/Api.js CHANGED
@@ -92,6 +92,7 @@ var Api = /** @class */ (function () {
92
92
  var _a, _b, _c;
93
93
  this.endpoints = {};
94
94
  this.mutable = false;
95
+ this.wasMutable = false;
95
96
  this.hotRequest = function (requestMethod) {
96
97
  return function (path, config) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
97
98
  switch (_a.label) {
@@ -119,6 +120,7 @@ var Api = /** @class */ (function () {
119
120
  requestBackend: requestBackend,
120
121
  };
121
122
  this.mutable = (_c = options.mutable) !== null && _c !== void 0 ? _c : false;
123
+ this.wasMutable = this.mutable;
122
124
  this.endpoints = {};
123
125
  }
124
126
  Object.defineProperty(Api.prototype, "requestBackend", {
@@ -193,9 +195,10 @@ var Api = /** @class */ (function () {
193
195
  };
194
196
  Api.prototype.configure = function (info) {
195
197
  if (!this.mutable) {
196
- throw new Error("[api-def] Cannot configure an immutable API");
198
+ throw new Error("[api-def] ".concat(this.wasMutable ? "Cannot configure a mutable API twice" : "Cannot configure an immutable API"));
197
199
  }
198
200
  Object.assign(this.info, info);
201
+ this.mutable = false;
199
202
  };
200
203
  return Api;
201
204
  }());
package/esm/Api.d.ts CHANGED
@@ -21,6 +21,7 @@ export declare class Api implements ApiInfo {
21
21
  private readonly info;
22
22
  protected readonly endpoints: Record<string, Endpoint>;
23
23
  private mutable;
24
+ private wasMutable;
24
25
  constructor(options: ApiOptions & {
25
26
  readonly mutable?: boolean;
26
27
  });
package/esm/Api.js CHANGED
@@ -53,6 +53,7 @@ export class Api {
53
53
  var _a, _b, _c;
54
54
  this.endpoints = {};
55
55
  this.mutable = false;
56
+ this.wasMutable = false;
56
57
  this.hotRequest = (requestMethod) => (path, config) => __awaiter(this, void 0, void 0, function* () { return yield Requester.submit(new HotRequestHost(this, path, requestMethod), config, null); });
57
58
  this.get = this.hotRequest(RequestMethod.GET);
58
59
  this.post = this.hotRequest(RequestMethod.POST);
@@ -73,6 +74,7 @@ export class Api {
73
74
  requestBackend: requestBackend,
74
75
  };
75
76
  this.mutable = (_c = options.mutable) !== null && _c !== void 0 ? _c : false;
77
+ this.wasMutable = this.mutable;
76
78
  this.endpoints = {};
77
79
  }
78
80
  get requestBackend() {
@@ -119,8 +121,9 @@ export class Api {
119
121
  }
120
122
  configure(info) {
121
123
  if (!this.mutable) {
122
- throw new Error("[api-def] Cannot configure an immutable API");
124
+ throw new Error(`[api-def] ${this.wasMutable ? "Cannot configure a mutable API twice" : "Cannot configure an immutable API"}`);
123
125
  }
124
126
  Object.assign(this.info, info);
127
+ this.mutable = false;
125
128
  }
126
129
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "api-def",
3
- "version": "0.12.0-alpha.11",
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",