kodzero-front-sdk-alfa 0.0.2 → 0.0.5

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 (82) hide show
  1. package/README.md +28 -11
  2. package/dist/Kodzero.d.ts +3 -2
  3. package/dist/Kodzero.js +9 -5
  4. package/dist/__mocks__/fluid-fetch.d.ts +1 -0
  5. package/dist/__mocks__/fluid-fetch.js +23 -0
  6. package/dist/__mocks__/validno.d.ts +5 -0
  7. package/dist/__mocks__/validno.js +9 -0
  8. package/dist/auth/base.d.ts +3 -2
  9. package/dist/auth/base.js +10 -6
  10. package/dist/auth/email.d.ts +2 -2
  11. package/dist/auth/email.js +64 -62
  12. package/dist/auth/index.d.ts +4 -3
  13. package/dist/auth/index.js +6 -2
  14. package/dist/auth/tokens.d.ts +2 -1
  15. package/dist/auth/tokens.js +4 -1
  16. package/dist/errors/KodzeroApiError.js +3 -0
  17. package/dist/errors/KodzeroValidationError.js +1 -0
  18. package/dist/index.d.ts +2 -1
  19. package/dist/index.js +1 -48
  20. package/dist/model/BaseModel.d.ts +3 -3
  21. package/dist/model/BaseModel.js +26 -28
  22. package/dist/model/PaginatedResult.d.ts +28 -0
  23. package/dist/model/PaginatedResult.js +49 -0
  24. package/dist/model/createModel.d.ts +3 -1
  25. package/dist/model/createModel.js +146 -148
  26. package/dist/schemas/baseAuth.js +13 -13
  27. package/dist/schemas/baseModel.js +20 -20
  28. package/dist/tsconfig.tsbuildinfo +1 -1
  29. package/dist/utils/buildURL.js +3 -1
  30. package/dist/utils/validateApiResponse.js +1 -1
  31. package/jest.config.ts +23 -19
  32. package/package.json +7 -6
  33. package/src/Kodzero.ts +2 -2
  34. package/src/__mocks__/fluid-fetch.ts +35 -0
  35. package/src/__mocks__/validno.ts +12 -0
  36. package/src/__tests__/Kodzero.test.ts +9 -0
  37. package/src/__tests__/utils/buildURL.test.ts +18 -0
  38. package/src/auth/base.ts +5 -3
  39. package/src/auth/email.ts +3 -3
  40. package/src/auth/index.ts +6 -4
  41. package/src/auth/tokens.ts +4 -2
  42. package/src/index.ts +3 -0
  43. package/src/model/BaseModel.ts +11 -14
  44. package/src/model/PaginatedResult.ts +81 -0
  45. package/src/model/createModel.ts +40 -16
  46. package/src/schemas/baseAuth.ts +2 -1
  47. package/src/schemas/baseModel.ts +1 -1
  48. package/src/tsconfig.json +9 -8
  49. package/src/utils/{buildURL_rename.ts → buildURL.ts} +2 -1
  50. package/dist/fetcher/InterceptorManager.d.ts +0 -9
  51. package/dist/fetcher/InterceptorManager.js +0 -42
  52. package/dist/fetcher/MiddlewareManager.d.ts +0 -9
  53. package/dist/fetcher/MiddlewareManager.js +0 -42
  54. package/dist/fetcher/index.d.ts +0 -77
  55. package/dist/fetcher/index.js +0 -194
  56. package/dist/model/baseModelOptionsSchema.d.ts +0 -2
  57. package/dist/model/baseModelOptionsSchema.js +0 -10
  58. package/dist/model/configSchema.d.ts +0 -0
  59. package/dist/model/configSchema.js +0 -1
  60. package/dist/model/errors/KodzeroApiError.d.ts +0 -7
  61. package/dist/model/errors/KodzeroApiError.js +0 -10
  62. package/dist/model/modelFactory.d.ts +0 -50
  63. package/dist/model/modelFactory.js +0 -41
  64. package/dist/model/modelSchema.d.ts +0 -0
  65. package/dist/model/modelSchema.js +0 -1
  66. package/dist/model/schemas/baseModel.d.ts +0 -6
  67. package/dist/model/schemas/baseModel.js +0 -25
  68. package/dist/model/schemas/baseModelOptionsSchema.d.ts +0 -2
  69. package/dist/model/schemas/baseModelOptionsSchema.js +0 -10
  70. package/dist/model/statics/getAll.d.ts +0 -2
  71. package/dist/model/statics/getAll.js +0 -4
  72. package/dist/model/utils/processUrl.d.ts +0 -2
  73. package/dist/model/utils/processUrl.js +0 -7
  74. package/dist/model/utils/validateApiResponse.d.ts +0 -2
  75. package/dist/model/utils/validateApiResponse.js +0 -14
  76. package/dist/schemas/baseModel copy.d.ts +0 -6
  77. package/dist/schemas/baseModel copy.js +0 -25
  78. package/dist/utils/buildURL_rename.d.ts +0 -2
  79. package/dist/utils/buildURL_rename.js +0 -7
  80. package/dist/utils/processUrl.d.ts +0 -2
  81. package/dist/utils/processUrl.js +0 -7
  82. /package/{.eslintrc.cjs → eslintrc.cjs} +0 -0
@@ -0,0 +1,12 @@
1
+ // Simple mock for fluid-fetch
2
+ export default function Schema() {
3
+ return {
4
+ // Mock the methods and properties you're using
5
+ validate: () => {
6
+ return {
7
+ ok: true
8
+ }
9
+ },
10
+ // Add other methods as needed
11
+ };
12
+ }
@@ -0,0 +1,9 @@
1
+ import Kodzero from '../Kodzero.js';
2
+
3
+ it('should create an instance if host provided', async () => {
4
+ const kodzero = new Kodzero({
5
+ host: 'http://localhost:6969'
6
+ });
7
+
8
+ expect(kodzero).toBeInstanceOf(Kodzero);
9
+ });
@@ -0,0 +1,18 @@
1
+ import buildURL from '../../utils/buildURL.js';
2
+
3
+ describe('buildURL', () => {
4
+ test('buildURL constructs a URL without an ID', () => {
5
+ const url = buildURL('https://example.com', 'collection');
6
+ expect(url).toBe('https://example.com/collection');
7
+ });
8
+
9
+ test('buildURL constructs a URL with an ID', () => {
10
+ const url = buildURL('https://example.com', 'collection', '123');
11
+ expect(url).toBe('https://example.com/collection/123');
12
+ });
13
+
14
+ test('buildURL handles trailing slashes in baseUrl and collection', () => {
15
+ const url = buildURL('https://example.com/', '/collection/', '123');
16
+ expect(url).toBe('https://example.com/collection/123');
17
+ });
18
+ })
package/src/auth/base.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import FluidFetch from "fluid-fetch";
2
2
  import { AuthOptions } from "./index.js";
3
- import { TokensManagerClass } from "./tokens.js";
3
+ import TokensManagerClass from "./tokens.js";
4
4
  import BaseAuthSchema from "../schemas/baseAuth.js";
5
5
  import validateApiResponse from "../utils/validateApiResponse.js";
6
6
 
7
- export class KodzeroAuthBase {
7
+ class KodzeroAuthBase {
8
8
  host: string;
9
9
  api: typeof FluidFetch
10
10
  tokensManager: TokensManagerClass
@@ -34,4 +34,6 @@ export class KodzeroAuthBase {
34
34
  refresh = (...args: any[]): Promise<any> | void => {}
35
35
  signout = (...args: any[]): Promise<any> | void => {}
36
36
  verify = (...args: any[]): Promise<any> | void => {}
37
- }
37
+ }
38
+
39
+ export default KodzeroAuthBase
package/src/auth/email.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import FluidFetch from "fluid-fetch"
2
2
  import { AuthOptions } from "./index.js"
3
- import { KodzeroAuthBase } from "./base.js"
4
- import { TokensManagerClass } from "./tokens.js"
5
- import buildURL from "../utils/buildURL_rename.js"
3
+ import buildURL from "../utils/buildURL.js"
4
+ import KodzeroAuthBase from "./base.js"
5
+ import TokensManagerClass from "./tokens.js"
6
6
 
7
7
  interface KodzeroAuthEmailSignin {
8
8
  email: string
package/src/auth/index.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  import FluidFetch from "fluid-fetch";
2
- import { KodzeroAuthBase } from "./base.js";
2
+ import KodzeroAuthBase from "./base.js";
3
3
  import KodzeroAuthEmail from "./email.js";
4
- import { TokensManagerClass } from "./tokens.js";
4
+ import TokensManagerClass from "./tokens.js";
5
5
 
6
6
  export interface AuthOptions {
7
7
  host: string
8
8
  }
9
9
 
10
- export class KodzeroAuth extends KodzeroAuthBase {
10
+ class KodzeroAuth extends KodzeroAuthBase {
11
11
  email: KodzeroAuthEmail
12
12
  setTokens: (access: string, refresh?: string) => void
13
13
  clearTokens: () => void;
@@ -40,4 +40,6 @@ export class KodzeroAuth extends KodzeroAuthBase {
40
40
  tokensManager.clear()
41
41
  }
42
42
  }
43
- }
43
+ }
44
+
45
+ export default KodzeroAuth
@@ -2,7 +2,7 @@
2
2
  * TokensManagerClass is responsible for managing access and refresh tokens.
3
3
  * It provides methods to set, get, check existence, and clear tokens.
4
4
  */
5
- export class TokensManagerClass {
5
+ class TokensManagerClass {
6
6
  access: string
7
7
  refresh: string
8
8
 
@@ -46,4 +46,6 @@ export class TokensManagerClass {
46
46
  this.access = ''
47
47
  this.refresh = ''
48
48
  }
49
- }
49
+ }
50
+
51
+ export default TokensManagerClass
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ import Kodzero from "./Kodzero.js";
2
+
3
+ export default Kodzero
@@ -2,14 +2,14 @@ import Schema from "validno";
2
2
  import FluidFetch from "fluid-fetch";
3
3
 
4
4
  import constants from "./constants.js";
5
- import validateApiResponse from "../utils/validateApiResponse.js";
5
+ import buildURL from "../utils/buildURL.js";
6
6
  import BaseModelSchema from "../schemas/baseModel.js";
7
- import buildURL from "../utils/buildURL_rename.js";
7
+ import validateApiResponse from "../utils/validateApiResponse.js";
8
8
 
9
9
  export interface ModelOptions {
10
10
  host: string
11
11
  collection: string
12
- schema?: typeof Schema
12
+ schema?: Record<string, any>
13
13
  }
14
14
 
15
15
  /**
@@ -20,7 +20,7 @@ class BaseModel<T extends { _id?: string }> {
20
20
  collection: string
21
21
  modelData: T = {} as T
22
22
  schema?: typeof Schema
23
- api: typeof FluidFetch
23
+ apiClient: typeof FluidFetch
24
24
 
25
25
  id: string | null;
26
26
 
@@ -28,13 +28,13 @@ class BaseModel<T extends { _id?: string }> {
28
28
  static collection: string
29
29
  static api: typeof FluidFetch
30
30
 
31
- constructor(options: ModelOptions, api: typeof FluidFetch) {
31
+ constructor(options: ModelOptions, apiClient: typeof FluidFetch) {
32
32
  BaseModelSchema.validateOrThrow(options);
33
33
 
34
34
  this.host = options.host
35
35
  this.collection = options.collection
36
- this.schema = options.schema
37
- this.api = api
36
+ this.schema = options.schema ? new Schema({...options.schema}) : null
37
+ this.apiClient = apiClient
38
38
  this.id = null;
39
39
  }
40
40
 
@@ -148,7 +148,7 @@ class BaseModel<T extends { _id?: string }> {
148
148
 
149
149
  const updateUrl = buildURL(this.host, this.collection, this.id)
150
150
 
151
- const response = await this.api.patch(updateUrl, this._dataWithoutId())
151
+ const response = await this.apiClient.patch(updateUrl, this._dataWithoutId())
152
152
  .headers({ 'Content-Type': 'application/json' });
153
153
 
154
154
  await this._handleApiError(response);
@@ -168,8 +168,7 @@ class BaseModel<T extends { _id?: string }> {
168
168
  }
169
169
 
170
170
  const deleteUrl = buildURL(this.host, this.collection, this.id);
171
-
172
- const response = await this.api.delete(deleteUrl);
171
+ const response = await this.apiClient.delete(deleteUrl);
173
172
  await this._handleApiError(response);
174
173
 
175
174
  this._setId(null);
@@ -183,13 +182,11 @@ class BaseModel<T extends { _id?: string }> {
183
182
  */
184
183
  async create(): Promise<T> {
185
184
  const createUrl = buildURL(this.host, this.collection)
186
-
187
- const response = await this.api.post(createUrl, this._dataWithoutId())
185
+ const response = await this.apiClient.post(createUrl, this._dataWithoutId())
188
186
  .headers({ 'Content-Type': 'application/json' });
189
-
190
187
  await this._handleApiError(response);
191
- const json = await response.json();
192
188
 
189
+ const json = await response.json();
193
190
  this._setModelData(json.result);
194
191
 
195
192
  return this.modelData
@@ -0,0 +1,81 @@
1
+ import { FindManyOptions } from "./createModel.js"
2
+
3
+ interface PaginationState {
4
+ skip: number,
5
+ limit: number,
6
+ page: number,
7
+ total: number,
8
+ totalPages: number,
9
+ left: number
10
+ }
11
+
12
+ interface PaginationResultInput<T> {
13
+ data: T[],
14
+ state: PaginationState,
15
+ options: FindManyOptions | {},
16
+ findManyFunction: Function
17
+ }
18
+
19
+ class PaginatedResult<T = {}> {
20
+ state: PaginationState
21
+ data: Array<T>
22
+ options: FindManyOptions | {}
23
+ private findManyFunction: Function
24
+
25
+ constructor(input: PaginationResultInput<T>) {
26
+ const {findManyFunction, state, data, options} = input
27
+
28
+ this.options = options
29
+ this.findManyFunction = findManyFunction
30
+
31
+ this.state = {
32
+ skip: state.skip || 0,
33
+ limit: state.limit || 0,
34
+ page: state.page || 0,
35
+ total: state.total || 0,
36
+ totalPages: state.totalPages || 0,
37
+ left: state.left || 0
38
+ }
39
+
40
+ this.data = data
41
+ }
42
+
43
+ async next(): Promise<PaginatedResult<T>> {
44
+ this.state.page++;
45
+
46
+ const result = await this.findManyFunction(this.options, this.state.page, this.state.limit);
47
+ this.data = result.data;
48
+
49
+ return this;
50
+ }
51
+
52
+ async previous(): Promise<PaginatedResult<T>> {
53
+ if (this.state.page === 1) throw new Error('Page cannot be lower than 1')
54
+
55
+ this.state.page--;
56
+ const result = await this.findManyFunction(this.options, this.state.page, this.state.limit);
57
+ this.data = result.data
58
+
59
+ return this;
60
+ }
61
+
62
+ async page(pageNumber: number) {
63
+ if (pageNumber < 1) throw new Error('Page cannot be lower than 1')
64
+
65
+ this.state.page = pageNumber
66
+ const result = this.findManyFunction(this.options, this.state.page, this.state.limit);
67
+ this.data = result.data
68
+
69
+ return this;
70
+ }
71
+
72
+ hasNext(): boolean {
73
+ return this.state.page < this.state.totalPages
74
+ }
75
+
76
+ hasPrevious(): boolean {
77
+ return this.state.page > 1
78
+ }
79
+ }
80
+
81
+ export default PaginatedResult
@@ -2,8 +2,9 @@ import FluidFetch from 'fluid-fetch'
2
2
  import BaseModel, { ModelOptions } from './BaseModel.js'
3
3
  import {KzResponseFindMany } from '../types/responses.js'
4
4
  import validateApiResponse from '../utils/validateApiResponse.js'
5
- import buildURL from '../utils/buildURL_rename.js'
5
+ import buildURL from '../utils/buildURL.js'
6
6
  import constants from './constants.js'
7
+ import PaginatedResult from './PaginatedResult.js'
7
8
 
8
9
  export interface FindManyOptions {
9
10
  page: number
@@ -19,11 +20,11 @@ export interface FindManyOptions {
19
20
  const createModel = <
20
21
  T extends { _id?: string },
21
22
  M = {}
22
- >(options: ModelOptions, api: typeof FluidFetch) => {
23
+ >(options: ModelOptions, apiClient: typeof FluidFetch) => {
23
24
  const Model = class extends BaseModel<T> {
24
25
  static host = options.host
25
26
  static collection = options.collection
26
- static api = api
27
+ static apiClient = apiClient
27
28
 
28
29
  static async _handleApiError(response: Response) {
29
30
  return validateApiResponse(response)
@@ -62,7 +63,7 @@ const createModel = <
62
63
 
63
64
  const getUrl = buildURL(Model.host, Model.collection, id)
64
65
 
65
- const response = await Model.api.get(getUrl);
66
+ const response = await Model.apiClient.get(getUrl);
66
67
  await Model._handleApiError(response);
67
68
 
68
69
  const data = await response.json();
@@ -74,18 +75,40 @@ const createModel = <
74
75
 
75
76
  const params = {...options} as Record<string, any>;
76
77
 
77
- const response = await Model.api.get(getUrl).params(params);
78
+ const response = await Model.apiClient.get(getUrl).params(params);
78
79
  await Model._handleApiError(response);
79
80
 
80
81
  const data: KzResponseFindMany<T> = await response.json();
81
82
  return data.result.found;
82
83
  }
83
84
 
85
+ static async findManyPaginated(
86
+ options: FindManyOptions | {} = {},
87
+ page: number = 1,
88
+ perPage: number = 25
89
+ ): Promise<any> {
90
+ if (!page || page < 1) throw new Error('Page number must be greater than 0');
91
+
92
+ const getUrl = buildURL(Model.host, Model.collection)
93
+ const params = {...options, page, perPage} as Record<string, any>;
94
+ const response = await Model.apiClient.get(getUrl).params(params);
95
+ await Model._handleApiError(response);
96
+
97
+ const data: KzResponseFindMany<T> = await response.json();
98
+
99
+ return new PaginatedResult({
100
+ data: data.result.found,
101
+ state: data.result,
102
+ options,
103
+ findManyFunction: Model.findManyPaginated
104
+ })
105
+ }
106
+
84
107
  static async create(data: T): Promise<T> {
85
108
  const createUrl = buildURL(Model.host, Model.collection)
86
109
  const {_id, ...dataWithoutId} = data as T & {_id?: string};
87
110
 
88
- const response = await Model.api.post(createUrl)
111
+ const response = await Model.apiClient.post(createUrl)
89
112
  .body(dataWithoutId)
90
113
  .headers({
91
114
  'Content-Type': 'application/json'
@@ -109,7 +132,7 @@ const createModel = <
109
132
  return rest;
110
133
  });
111
134
 
112
- const response = await Model.api.post(createUrl)
135
+ const response = await Model.apiClient.post(createUrl)
113
136
  .body(dataWithoutId)
114
137
  .headers({
115
138
  'Content-Type': 'application/json'
@@ -127,7 +150,7 @@ const createModel = <
127
150
 
128
151
  const updateUrl = buildURL(Model.host, Model.collection, id)
129
152
  const {_id, ...dataWithoutId} = data as Partial<T> & {_id?: string};
130
- const response = await Model.api.patch(updateUrl)
153
+ const response = await Model.apiClient.patch(updateUrl)
131
154
  .body(dataWithoutId)
132
155
  .headers({ 'Content-Type': 'application/json' });
133
156
 
@@ -148,7 +171,7 @@ const createModel = <
148
171
 
149
172
  const updateUrl = buildURL(Model.host, Model.collection) + '/batch'
150
173
 
151
- const response = await Model.api.patch(updateUrl)
174
+ const response = await Model.apiClient.patch(updateUrl)
152
175
  .body(updates)
153
176
  .headers({ 'Content-Type': 'application/json' });
154
177
 
@@ -163,7 +186,7 @@ const createModel = <
163
186
 
164
187
  const deleteUrl = buildURL(Model.host, Model.collection, id)
165
188
 
166
- const response = await Model.api.delete(deleteUrl);
189
+ const response = await Model.apiClient.delete(deleteUrl);
167
190
  await Model._handleApiError(response);
168
191
 
169
192
  const json = await response.json();
@@ -171,13 +194,11 @@ const createModel = <
171
194
  }
172
195
 
173
196
  static async deleteMany(ids: string[]): Promise<Record<string, boolean>> {
174
- if (!ids || ids.length === 0) {
175
- throw new Error(constants.RequiresIdsArray);
176
- }
197
+ if (!ids || ids.length === 0) throw new Error(constants.RequiresIdsArray);
177
198
 
178
199
  const deleteUrl = buildURL(Model.host, Model.collection) + '/batch'
179
200
 
180
- const response = await Model.api.delete(deleteUrl)
201
+ const response = await Model.apiClient.delete(deleteUrl)
181
202
  .body({ ids })
182
203
  .headers({ 'Content-Type': 'application/json' });
183
204
 
@@ -188,13 +209,15 @@ const createModel = <
188
209
  }
189
210
 
190
211
  static async distinct(fields: string[], filter?: Record<string, any>): Promise<string[]> {
212
+ throw new Error('Distinct method is disabled in this SDK version'); // temporary disable
213
+
191
214
  if (!fields || fields.length === 0) {
192
215
  throw new Error(constants.DistinctRequiresFieldsArray);
193
216
  }
194
217
 
195
218
  const distinctUrl = buildURL(Model.host, Model.collection, 'distinct')
196
219
 
197
- const response = await Model.api.post(distinctUrl)
220
+ const response = await Model.apiClient.get(distinctUrl)
198
221
  .params({ fields: fields.join(','), filter: filter ? JSON.stringify(filter) : undefined })
199
222
  .headers({ 'Content-Type': 'application/json' });
200
223
 
@@ -205,7 +228,7 @@ const createModel = <
205
228
  }
206
229
 
207
230
  constructor(data: T) {
208
- super(options, api)
231
+ super(options, apiClient)
209
232
 
210
233
  this.modelData = {...data, _id: null}
211
234
  this.id = null;
@@ -220,6 +243,7 @@ const createModel = <
220
243
  registerMethod<K extends keyof M>(name: K, fn: M[K]): void;
221
244
  find(id: string): Promise<T>;
222
245
  findMany(options?: FindManyOptions | {}): Promise<T[]>;
246
+ findManyPaginated(options?: FindManyOptions | {}, page?: number, perPage?: number): Promise<PaginatedResult<T>>;
223
247
  create(data: T): Promise<T>;
224
248
  createMany(data: T[]): Promise<T[]>;
225
249
  update(id: string, data: Partial<T>): Promise<T>;
@@ -1,6 +1,7 @@
1
1
  import Schema from 'validno'
2
2
  import KodzeroValidationError from '../errors/KodzeroValidationError.js';
3
3
 
4
+ // TODO: сделать класс конструктор для таких реализаций?
4
5
  class BaseAuthSchema {
5
6
  // Validation schema for BaseAuth class constructor options
6
7
  static schema = new Schema({
@@ -16,7 +17,7 @@ class BaseAuthSchema {
16
17
 
17
18
  if (!validation.ok) {
18
19
  throw new KodzeroValidationError(
19
- 'Invalid auth options: ' + validation.failed.join(', '),
20
+ 'Invalid auth options: ' + validation.failed.join(', '), // TODO: to constants
20
21
  validation.errors
21
22
  );
22
23
  }
@@ -23,7 +23,7 @@ class BaseModelSchema {
23
23
 
24
24
  if (!validation.ok) {
25
25
  throw new KodzeroValidationError(
26
- 'Invalid model options: ' + validation.failed.join(', '),
26
+ 'Invalid model options: ' + validation.failed.join(', '), // TODO: to constants
27
27
  validation.errors
28
28
  );
29
29
  }
package/src/tsconfig.json CHANGED
@@ -11,7 +11,7 @@
11
11
  // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
12
12
 
13
13
  /* Language and Environment */
14
- "target": "ES2017", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
14
+ "target": "esnext", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
15
15
  // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
16
16
  // "jsx": "preserve", /* Specify what JSX code is generated. */
17
17
  // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
@@ -25,9 +25,9 @@
25
25
  // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
26
26
 
27
27
  /* Modules */
28
- "module": "ES2022", /* Specify what module code is generated. */
28
+ "module": "nodenext", /* Specify what module code is generated. */
29
29
  "rootDir": "../src/", /* Specify the root folder within your source files. */
30
- "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
30
+ "moduleResolution": "nodenext", /* Specify how TypeScript looks up a file from a given module specifier. */
31
31
  // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
32
32
  // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
33
33
  // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
@@ -70,11 +70,10 @@
70
70
 
71
71
  /* Interop Constraints */
72
72
  // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
73
- // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
73
+ "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
74
74
  "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
75
75
  // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
76
76
  "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
77
-
78
77
  /* Type Checking */
79
78
  "strict": true, /* Enable all strict type-checking options. */
80
79
  // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
@@ -95,9 +94,11 @@
95
94
  // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
96
95
  // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
97
96
  // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
98
-
99
97
  /* Completeness */
100
98
  // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
101
- "skipLibCheck": true /* Skip type checking all .d.ts files. */
102
- }
99
+ },
100
+ "exclude": [
101
+ "**/*.test.ts",
102
+ "**/__tests__/**"
103
+ ]
103
104
  }
@@ -1,5 +1,6 @@
1
1
  const buildURL = (baseUrl: string, collection: string, id?: string): string => {
2
- let url = `${baseUrl}/${collection}`;
2
+ let url = `${baseUrl}`
3
+ if (collection) url += `/${collection}`;
3
4
  if (id) url += `/${id}`;
4
5
 
5
6
  return url.replace(/\/+/g, '/').replace(':/', '://');
@@ -1,9 +0,0 @@
1
- declare class MiddlewareManager<T> {
2
- private handlers;
3
- private idCounter;
4
- use(fulfilled: (value: T) => Promise<T> | T, rejected?: (error: any) => any): number;
5
- eject(id: number): void;
6
- clear(): void;
7
- runMiddlewares(value: T): Promise<T>;
8
- }
9
- export default MiddlewareManager;
@@ -1,42 +0,0 @@
1
- class MiddlewareManager {
2
- constructor() {
3
- this.handlers = [];
4
- this.idCounter = 0;
5
- }
6
- use(fulfilled, rejected) {
7
- const id = this.idCounter++;
8
- this.handlers.push({
9
- fulfilled,
10
- rejected,
11
- id
12
- });
13
- return id;
14
- }
15
- eject(id) {
16
- const index = this.handlers.findIndex(handler => handler.id === id);
17
- if (index !== -1) {
18
- this.handlers.splice(index, 1);
19
- }
20
- }
21
- clear() {
22
- this.handlers = [];
23
- }
24
- async runMiddlewares(value) {
25
- let result = value;
26
- for (const handler of this.handlers) {
27
- try {
28
- result = await handler.fulfilled(result);
29
- }
30
- catch (error) {
31
- if (handler.rejected) {
32
- result = await handler.rejected(error);
33
- }
34
- else {
35
- throw error;
36
- }
37
- }
38
- }
39
- return result;
40
- }
41
- }
42
- export default MiddlewareManager;
@@ -1,9 +0,0 @@
1
- declare class MiddlewareManager<T> {
2
- private handlers;
3
- private idCounter;
4
- use(fulfilled: (value: T) => Promise<T> | T, rejected?: (error: any) => any): number;
5
- eject(id: number): void;
6
- clear(): void;
7
- runMiddlewares(value: T): Promise<T>;
8
- }
9
- export default MiddlewareManager;
@@ -1,42 +0,0 @@
1
- class MiddlewareManager {
2
- constructor() {
3
- this.handlers = [];
4
- this.idCounter = 0;
5
- }
6
- use(fulfilled, rejected) {
7
- const id = this.idCounter++;
8
- this.handlers.push({
9
- fulfilled,
10
- rejected,
11
- id
12
- });
13
- return id;
14
- }
15
- eject(id) {
16
- const index = this.handlers.findIndex(handler => handler.id === id);
17
- if (index !== -1) {
18
- this.handlers.splice(index, 1);
19
- }
20
- }
21
- clear() {
22
- this.handlers = [];
23
- }
24
- async runMiddlewares(value) {
25
- let result = value;
26
- for (const handler of this.handlers) {
27
- try {
28
- result = await handler.fulfilled(result);
29
- }
30
- catch (error) {
31
- if (handler.rejected) {
32
- result = await handler.rejected(error);
33
- }
34
- else {
35
- throw error;
36
- }
37
- }
38
- }
39
- return result;
40
- }
41
- }
42
- export default MiddlewareManager;