@labeg/tfetch 0.4.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Evgeny Labutin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,22 @@
1
+ Typescript Serializable Fetch
2
+ =====
3
+
4
+ A small library for sending serialized data and receiving deserialized data with strict data type checking.
5
+
6
+ Installation
7
+ ------
8
+
9
+ You can use the following command to install this package:
10
+
11
+ ``` bash
12
+ npm install ts-fetch
13
+ ```
14
+
15
+ Usage
16
+ ------
17
+
18
+ todo...
19
+
20
+ ```typescript
21
+ todo...
22
+ ```
@@ -0,0 +1,16 @@
1
+ import type { Serializable } from "ts-serializable";
2
+ import type { IGraphQuery } from "../models/view-models/graph-query.vm.js";
3
+ import type { PageListQuery } from "../models/view-models/page-list-query.vm.js";
4
+ import type { PagedList } from "../models/view-models/paged-list.vm.js";
5
+ import { TsFetch } from "./TsFetch.js";
6
+ export declare abstract class CrudHttpRepository<T1 extends Serializable> extends TsFetch {
7
+ protected abstract apiRoot: string;
8
+ protected abstract modelConstructor: new () => T1;
9
+ getById(id: number | string, ...keys: (number | string)[]): Promise<T1>;
10
+ getAll(...keys: (number | string)[]): Promise<T1[]>;
11
+ create(value: T1, ...keys: (number | string)[]): Promise<T1>;
12
+ update(id: number | string, value: T1, ...keys: (number | string)[]): Promise<void>;
13
+ delete(id: number | string, ...keys: (number | string)[]): Promise<void>;
14
+ getGraphById(_id: number | string, ..._keys: (IGraphQuery | number | string)[]): Promise<T1>;
15
+ getPaged(..._keys: (PageListQuery | number | string)[]): Promise<PagedList<T1>>;
16
+ }
@@ -0,0 +1,68 @@
1
+ import { TsFetch } from "./TsFetch.js";
2
+ export class CrudHttpRepository extends TsFetch {
3
+ async getById(id, ...keys) {
4
+ let url = this.apiRoot;
5
+ keys.forEach((key) => {
6
+ url = url.replace(/\{.+\}/gu, String(key));
7
+ });
8
+ return this.send({
9
+ method: "GET",
10
+ url: `${url}/${String(id)}`,
11
+ returnType: this.modelConstructor
12
+ });
13
+ }
14
+ async getAll(...keys) {
15
+ let url = this.apiRoot;
16
+ keys.forEach((key) => {
17
+ url = url.replace(/\{.+\}/gu, String(key));
18
+ });
19
+ return this.send({
20
+ method: "GET",
21
+ url: `${url}/`,
22
+ returnType: [this.modelConstructor]
23
+ });
24
+ }
25
+ async create(value, ...keys) {
26
+ let url = this.apiRoot;
27
+ keys.forEach((key) => {
28
+ url = url.replace(/\{.+\}/gu, String(key));
29
+ });
30
+ return this.send({
31
+ method: "POST",
32
+ url: `${url}/`,
33
+ body: value,
34
+ returnType: this.modelConstructor
35
+ });
36
+ }
37
+ async update(id, value, ...keys) {
38
+ let url = this.apiRoot;
39
+ keys.forEach((key) => {
40
+ url = url.replace(/\{.+\}/gu, String(key));
41
+ });
42
+ return this.send({
43
+ method: "PUT",
44
+ url: `${url}/${String(id)}`,
45
+ body: value
46
+ });
47
+ }
48
+ async delete(id, ...keys) {
49
+ let url = this.apiRoot;
50
+ keys.forEach((key) => {
51
+ url = url.replace(/\{.+\}/gu, String(key));
52
+ });
53
+ return this.send({
54
+ method: "DELETE",
55
+ url: `${url}/${String(id)}`
56
+ });
57
+ }
58
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars, class-methods-use-this
59
+ async getGraphById(_id, ..._keys) {
60
+ await Promise.resolve();
61
+ throw new Error("Method not implemented.");
62
+ }
63
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars, class-methods-use-this
64
+ async getPaged(..._keys) {
65
+ await Promise.resolve();
66
+ throw new Error("Method not implemented.");
67
+ }
68
+ }
@@ -0,0 +1,30 @@
1
+ import { BackError } from "../models/errors/back.error.js";
2
+ import { BodyInit } from "undici-types";
3
+ type PromiseResRej = (obj: any) => void;
4
+ export interface TsRequestInit<T> extends Omit<RequestInit, "body"> {
5
+ /**
6
+ * URL for request
7
+ */
8
+ url: string | URL | globalThis.Request;
9
+ /**
10
+ * Body for fetch
11
+ */
12
+ body?: BodyInit | object;
13
+ /**
14
+ * Response Type
15
+ */
16
+ returnType?: T;
17
+ }
18
+ export declare class TsFetch {
19
+ protected readonly requestCache: Map<string, [PromiseResRej, PromiseResRej][]>;
20
+ send(options: TsRequestInit<void>): Promise<void>;
21
+ send<T extends boolean>(options: TsRequestInit<T>): Promise<T>;
22
+ send<T extends number>(options: TsRequestInit<T>): Promise<T>;
23
+ send<T extends string>(options: TsRequestInit<T>): Promise<T>;
24
+ send<T>(options: TsRequestInit<new () => T>): Promise<T>;
25
+ send<T>(options: TsRequestInit<[new () => T]>): Promise<T[]>;
26
+ protected handleError(response: Response): Promise<Response>;
27
+ protected setHeaders(): Headers;
28
+ protected parseBackendError(response: Response, body: string): BackError;
29
+ }
30
+ export {};
@@ -0,0 +1,165 @@
1
+ /* eslint-disable class-methods-use-this */
2
+ import { Serializable } from "ts-serializable";
3
+ import { BackError } from "../models/errors/back.error.js";
4
+ import { NetError } from "../models/errors/net.error.js";
5
+ export class TsFetch {
6
+ constructor() {
7
+ // Cache for all GET and HEAD request
8
+ this.requestCache = new Map();
9
+ }
10
+ // eslint-disable-next-line max-lines-per-function, max-statements, complexity
11
+ async send(options) {
12
+ const { url, body, returnType, ...otherInits } = options;
13
+ const headers = options.headers ?? this.setHeaders();
14
+ const input = url;
15
+ /**
16
+ * Setup cache
17
+ */
18
+ const isCacheableRequest = options.method === "GET" || options.method === "HEAD";
19
+ const cacheKey = [
20
+ options.method,
21
+ input instanceof globalThis.Request ? input.url : input
22
+ ].join(" ");
23
+ if (isCacheableRequest) {
24
+ if (this.requestCache.has(cacheKey)) {
25
+ return new Promise((res, rej) => {
26
+ this.requestCache.get(cacheKey)?.push([res, rej]); // [res, rej] - its tuple
27
+ });
28
+ }
29
+ this.requestCache.set(cacheKey, []);
30
+ }
31
+ /**
32
+ * Process request
33
+ */
34
+ // eslint-disable-next-line no-useless-assignment
35
+ let responseText = "";
36
+ try {
37
+ let response = await fetch(input, {
38
+ method: options.method,
39
+ body: typeof body === "undefined" ? void 0 : JSON.stringify(body),
40
+ headers,
41
+ ...otherInits
42
+ });
43
+ response = await this.handleError(response);
44
+ responseText = await response.text();
45
+ }
46
+ catch (fetchError) {
47
+ if (isCacheableRequest && this.requestCache.has(cacheKey)) {
48
+ this.requestCache.get(cacheKey)?.forEach((tuple) => {
49
+ try {
50
+ tuple[1](fetchError);
51
+ }
52
+ catch (re) {
53
+ // eslint-disable-next-line no-console
54
+ console.error(re);
55
+ }
56
+ });
57
+ this.requestCache.delete(cacheKey);
58
+ }
59
+ throw fetchError;
60
+ }
61
+ /**
62
+ * Parse data
63
+ */
64
+ let data = void 0;
65
+ if (returnType === void 0) {
66
+ data = void 0;
67
+ }
68
+ else if (Array.isArray(returnType) &&
69
+ responseText.startsWith("[")) {
70
+ data = JSON.parse(responseText);
71
+ // Return models.map((model: object) => new returnType[0]().fromJSON(model));
72
+ }
73
+ else if (typeof returnType === "function" &&
74
+ returnType.prototype instanceof Serializable &&
75
+ responseText.startsWith("{")) {
76
+ const constructor = returnType;
77
+ data = new constructor().fromJSON(JSON.parse(responseText));
78
+ }
79
+ else if (typeof returnType === "object" && responseText.startsWith("{")) {
80
+ data = JSON.parse(responseText);
81
+ }
82
+ else if (typeof returnType === "string") {
83
+ data = responseText;
84
+ }
85
+ else if (typeof returnType === "number") {
86
+ data = Number(responseText);
87
+ }
88
+ else if (typeof returnType === "boolean") {
89
+ data = Boolean(responseText);
90
+ }
91
+ else if (typeof returnType === "undefined") {
92
+ data = void 0;
93
+ }
94
+ else {
95
+ const error = new NetError(`Wrong returned type. Must by ${typeof returnType} but return ${typeof responseText}`);
96
+ if (isCacheableRequest && this.requestCache.has(cacheKey)) {
97
+ this.requestCache.get(cacheKey)?.forEach((tuple) => {
98
+ try {
99
+ tuple[1](error);
100
+ }
101
+ catch (typeError) {
102
+ // eslint-disable-next-line no-console
103
+ console.error(typeError);
104
+ }
105
+ });
106
+ this.requestCache.delete(cacheKey);
107
+ }
108
+ throw error;
109
+ }
110
+ /**
111
+ * Restore cache
112
+ */
113
+ if (isCacheableRequest && this.requestCache.has(cacheKey)) {
114
+ this.requestCache.get(cacheKey)?.forEach((tuple) => {
115
+ try {
116
+ tuple[0](data);
117
+ }
118
+ catch (promiseError) {
119
+ // eslint-disable-next-line no-console
120
+ console.error(promiseError);
121
+ }
122
+ });
123
+ this.requestCache.delete(cacheKey);
124
+ }
125
+ return data;
126
+ }
127
+ // eslint-disable-next-line max-statements
128
+ async handleError(response) {
129
+ if (response.ok) {
130
+ return response;
131
+ }
132
+ const body = await response.text();
133
+ // eslint-disable-next-line no-useless-assignment
134
+ let error = null;
135
+ if (response.status === 401) {
136
+ error = new NetError("Authorization exception", 401);
137
+ }
138
+ else if (body.startsWith("<")) { // Java xml response
139
+ // eslint-disable-next-line prefer-named-capture-group
140
+ const match = (/<b>description<\/b> <u>(.+?)<\/u>/gu).exec(body);
141
+ error = new NetError(`${response.status.toString()} - ${((match?.[1] ?? response.statusText) || "Ошибка не указана")}`);
142
+ }
143
+ else if (body.startsWith("{")) { // Backend response
144
+ error = this.parseBackendError(response, body);
145
+ }
146
+ else {
147
+ error = new NetError(`${response.status.toString()} - ${response.statusText}`);
148
+ }
149
+ error.status = response.status;
150
+ error.body = body;
151
+ throw error;
152
+ }
153
+ setHeaders() {
154
+ const headers = new Headers();
155
+ headers.set("content-type", "application/json");
156
+ headers.set("Pragma", "no-cache");
157
+ return headers;
158
+ }
159
+ parseBackendError(response, body) {
160
+ // Override method, check on message property
161
+ const backError = new BackError(`${response.status.toString()} - ${response.statusText}`);
162
+ backError.body = body;
163
+ return backError;
164
+ }
165
+ }
@@ -0,0 +1,14 @@
1
+ export * from "./models/index.js";
2
+ export * from "./contructors/TsFetch.js";
3
+ export * from "./contructors/CrudHttpRepository.js";
4
+ import { TsFetch } from "./contructors/TsFetch.js";
5
+ declare const instance: TsFetch;
6
+ export declare const tsfetch: typeof instance.send;
7
+ export declare const tf: {
8
+ (options: import("./contructors/TsFetch.js").TsRequestInit<void>): Promise<void>;
9
+ <T extends boolean>(options: import("./contructors/TsFetch.js").TsRequestInit<T>): Promise<T>;
10
+ <T extends number>(options: import("./contructors/TsFetch.js").TsRequestInit<T>): Promise<T>;
11
+ <T extends string>(options: import("./contructors/TsFetch.js").TsRequestInit<T>): Promise<T>;
12
+ <T>(options: import("./contructors/TsFetch.js").TsRequestInit<new () => T>): Promise<T>;
13
+ <T>(options: import("./contructors/TsFetch.js").TsRequestInit<[new () => T]>): Promise<T[]>;
14
+ };
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ export * from "./models/index.js";
2
+ export * from "./contructors/TsFetch.js";
3
+ export * from "./contructors/CrudHttpRepository.js";
4
+ import { TsFetch } from "./contructors/TsFetch.js";
5
+ const instance = new TsFetch();
6
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-return
7
+ export const tsfetch = (options) => instance.send(options);
8
+ export const tf = tsfetch; // Alias
@@ -0,0 +1,5 @@
1
+ export declare class BackError extends Error {
2
+ status: number | null;
3
+ body: string | null;
4
+ constructor(message: string, status?: number | null);
5
+ }
@@ -0,0 +1,11 @@
1
+ export class BackError extends Error {
2
+ constructor(message, status = null) {
3
+ super(message);
4
+ this.status = null;
5
+ this.body = null;
6
+ // Set the prototype explicitly.
7
+ Object.setPrototypeOf(this, BackError.prototype);
8
+ this.name = "BackError";
9
+ this.status = status;
10
+ }
11
+ }
@@ -0,0 +1,5 @@
1
+ export declare class NetError extends Error {
2
+ status: number | null;
3
+ body: string | null;
4
+ constructor(message: string, status?: number | null);
5
+ }
@@ -0,0 +1,11 @@
1
+ export class NetError extends Error {
2
+ constructor(message, status = null) {
3
+ super(message);
4
+ this.status = null;
5
+ this.body = null;
6
+ // Set the prototype explicitly.
7
+ Object.setPrototypeOf(this, NetError.prototype);
8
+ this.name = "NetError";
9
+ this.status = status;
10
+ }
11
+ }
@@ -0,0 +1,6 @@
1
+ export * from "./errors/back.error.js";
2
+ export * from "./errors/net.error.js";
3
+ export * from "./view-models/graph-query.vm.js";
4
+ export * from "./view-models/page-list-query.vm.js";
5
+ export * from "./view-models/page-meta.vm.js";
6
+ export * from "./view-models/paged-list.vm.js";
@@ -0,0 +1,6 @@
1
+ export * from "./errors/back.error.js";
2
+ export * from "./errors/net.error.js";
3
+ export * from "./view-models/graph-query.vm.js";
4
+ export * from "./view-models/page-list-query.vm.js";
5
+ export * from "./view-models/page-meta.vm.js";
6
+ export * from "./view-models/paged-list.vm.js";
@@ -0,0 +1,6 @@
1
+ export type IGraphQueryDeep5 = Record<string, object | null>;
2
+ export type IGraphQueryDeep4 = Record<string, IGraphQueryDeep5 | null>;
3
+ export type IGraphQueryDeep3 = Record<string, IGraphQueryDeep4 | null>;
4
+ export type IGraphQueryDeep2 = Record<string, IGraphQueryDeep3 | null>;
5
+ export type IGraphQueryDeep1 = Record<string, IGraphQueryDeep2 | null>;
6
+ export type IGraphQuery = Record<string, IGraphQueryDeep1 | null>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,32 @@
1
+ import type { IGraphQuery } from "./graph-query.vm";
2
+ export declare enum PageListQueryFilterMethod {
3
+ Less = "Less",
4
+ LessOrEqual = "LessOrEqual",
5
+ Equal = "Equal",
6
+ GreatOrEqual = "GreatOrEqual",
7
+ Great = "Great",
8
+ Like = "Like",
9
+ ILike = "ILike"
10
+ }
11
+ export declare class PageListQueryFilter {
12
+ property: string;
13
+ method?: PageListQueryFilterMethod;
14
+ value: number | string;
15
+ constructor(property: string, value: number | string, method?: PageListQueryFilterMethod);
16
+ }
17
+ export declare enum PageListQuerySortDirection {
18
+ Asc = "Asc",
19
+ Desc = "Desc"
20
+ }
21
+ export declare class PageListQuerySort {
22
+ property: string;
23
+ direction?: PageListQuerySortDirection;
24
+ constructor(property: string, direction?: PageListQuerySortDirection);
25
+ }
26
+ export declare class PageListQuery {
27
+ pageNumber?: number;
28
+ pageSize?: number;
29
+ filter?: PageListQueryFilter[];
30
+ sort?: PageListQuerySort[];
31
+ graph?: IGraphQuery;
32
+ }
@@ -0,0 +1,42 @@
1
+ export var PageListQueryFilterMethod;
2
+ (function (PageListQueryFilterMethod) {
3
+ PageListQueryFilterMethod["Less"] = "Less";
4
+ PageListQueryFilterMethod["LessOrEqual"] = "LessOrEqual";
5
+ PageListQueryFilterMethod["Equal"] = "Equal";
6
+ PageListQueryFilterMethod["GreatOrEqual"] = "GreatOrEqual";
7
+ PageListQueryFilterMethod["Great"] = "Great";
8
+ PageListQueryFilterMethod["Like"] = "Like";
9
+ PageListQueryFilterMethod["ILike"] = "ILike";
10
+ })(PageListQueryFilterMethod || (PageListQueryFilterMethod = {}));
11
+ export class PageListQueryFilter {
12
+ constructor(property, value, method = PageListQueryFilterMethod.Equal) {
13
+ this.property = "";
14
+ this.method = PageListQueryFilterMethod.Equal;
15
+ this.value = "";
16
+ this.property = property;
17
+ this.method = method;
18
+ this.value = value;
19
+ }
20
+ }
21
+ export var PageListQuerySortDirection;
22
+ (function (PageListQuerySortDirection) {
23
+ PageListQuerySortDirection["Asc"] = "Asc";
24
+ PageListQuerySortDirection["Desc"] = "Desc";
25
+ })(PageListQuerySortDirection || (PageListQuerySortDirection = {}));
26
+ export class PageListQuerySort {
27
+ constructor(property, direction = PageListQuerySortDirection.Asc) {
28
+ this.property = "";
29
+ this.direction = PageListQuerySortDirection.Asc;
30
+ this.property = property;
31
+ this.direction = direction;
32
+ }
33
+ }
34
+ export class PageListQuery {
35
+ constructor() {
36
+ this.pageNumber = 0;
37
+ this.pageSize = 0;
38
+ this.filter = [];
39
+ this.sort = [];
40
+ this.graph = void 0;
41
+ }
42
+ }
@@ -0,0 +1,9 @@
1
+ import "reflect-metadata";
2
+ import { Serializable } from "ts-serializable";
3
+ export declare class PageMeta extends Serializable {
4
+ pageNumber: number;
5
+ pageSize: number;
6
+ elementsInPage: number;
7
+ totalPages: number;
8
+ totalElements: number;
9
+ }
@@ -0,0 +1,41 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import "reflect-metadata";
11
+ import { jsonProperty, Serializable } from "ts-serializable";
12
+ export class PageMeta extends Serializable {
13
+ constructor() {
14
+ super(...arguments);
15
+ this.pageNumber = 0;
16
+ this.pageSize = 0;
17
+ this.elementsInPage = 0;
18
+ this.totalPages = 0;
19
+ this.totalElements = 0;
20
+ }
21
+ }
22
+ __decorate([
23
+ jsonProperty(Number),
24
+ __metadata("design:type", Number)
25
+ ], PageMeta.prototype, "pageNumber", void 0);
26
+ __decorate([
27
+ jsonProperty(Number),
28
+ __metadata("design:type", Number)
29
+ ], PageMeta.prototype, "pageSize", void 0);
30
+ __decorate([
31
+ jsonProperty(Number),
32
+ __metadata("design:type", Number)
33
+ ], PageMeta.prototype, "elementsInPage", void 0);
34
+ __decorate([
35
+ jsonProperty(Number),
36
+ __metadata("design:type", Number)
37
+ ], PageMeta.prototype, "totalPages", void 0);
38
+ __decorate([
39
+ jsonProperty(Number),
40
+ __metadata("design:type", Number)
41
+ ], PageMeta.prototype, "totalElements", void 0);
@@ -0,0 +1,6 @@
1
+ import { Serializable } from "ts-serializable";
2
+ import { PageMeta } from "./page-meta.vm.js";
3
+ export declare class PagedList<TEntity> extends Serializable {
4
+ pageMeta: PageMeta;
5
+ elements: TEntity[];
6
+ }
@@ -0,0 +1,26 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { jsonProperty, Serializable } from "ts-serializable";
11
+ import { PageMeta } from "./page-meta.vm.js";
12
+ export class PagedList extends Serializable {
13
+ constructor() {
14
+ super(...arguments);
15
+ this.pageMeta = new PageMeta();
16
+ this.elements = [];
17
+ }
18
+ }
19
+ __decorate([
20
+ jsonProperty(PageMeta),
21
+ __metadata("design:type", PageMeta)
22
+ ], PagedList.prototype, "pageMeta", void 0);
23
+ __decorate([
24
+ jsonProperty([Object]),
25
+ __metadata("design:type", Array)
26
+ ], PagedList.prototype, "elements", void 0);
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@labeg/tfetch",
3
+ "version": "0.4.0",
4
+ "author": "Eugene Labutin",
5
+ "license": "MIT",
6
+ "homepage": "https://github.com/LabEG/ts-fetch#readme",
7
+ "description": "A small library for sending serialized data and receiving deserialized data with strict data type checking.",
8
+ "main": "./dist/index.js",
9
+ "type": "module",
10
+ "typings": "./dist/index.d.ts",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": " git@github.com:LabEG/ts-fetch.git"
14
+ },
15
+ "bugs": {
16
+ "url": "https://github.com/LabEG/ts-fetch/issues"
17
+ },
18
+ "lint-staged": {
19
+ "./(src|tests)/**/*.(ts|tsx|js|jsx)": [
20
+ "eslint --fix"
21
+ ]
22
+ },
23
+ "scripts": {
24
+ "lint": "eslint --fix ./src/ ./tests/",
25
+ "test": "node --import ./ts-loader.js --test --test-reporter=spec --test-reporter-destination=stdout \"tests/**/*.spec.ts\"",
26
+ "test-watch": "node --watch --import ./ts-loader.js --test --test-reporter=spec --test-reporter-destination=stdout \"tests/**/*.spec.ts\"",
27
+ "coverage": "node --import ./ts-loader.js --test --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=coverage/lcov.info \"tests/**/*.spec.ts\"",
28
+ "build": "tsc --project tsconfig.build.json && node ./dist/index.js",
29
+ "prepublishOnly": "npm run lint && npm run build && npm run test",
30
+ "upgrade": "ncu -u && rimraf node_modules package-lock.json && npm i",
31
+ "release": "cliff-jumper --name 'ts-fetch' --package-path '.' --no-skip-changelog --no-skip-tag",
32
+ "prepare": "husky install"
33
+ },
34
+ "peerDependencies": {
35
+ "ts-serializable": ">=3.0.0"
36
+ },
37
+ "devDependencies": {
38
+ "@commitlint/cli": "^19.6.1",
39
+ "@commitlint/config-conventional": "^19.6.0",
40
+ "@favware/cliff-jumper": "^6.0.0",
41
+ "@labeg/code-style": "^6.0.0",
42
+ "@swc-node/register": "^1.10.9",
43
+ "@types/chai": "^5.0.1",
44
+ "chai": "^5.1.2",
45
+ "husky": "^9.1.7",
46
+ "lint-staged": "^15.3.0",
47
+ "ts-serializable": "^3.7.3",
48
+ "rimraf": "^6.0.1",
49
+ "npm-check-updates": "^17.1.13",
50
+ "typescript": "^5.7.2"
51
+ },
52
+ "keywords": [
53
+ "serialization",
54
+ "deserialization",
55
+ "fetch",
56
+ "request",
57
+ "ajax"
58
+ ]
59
+ }