@tiboli/types 0.0.10 → 0.0.12

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 (32) hide show
  1. package/README.md +117 -0
  2. package/dist/cjs/classes/errors.class.js +50 -0
  3. package/dist/cjs/classes/index.js +9 -0
  4. package/dist/cjs/{index.cjs → index.js} +1 -0
  5. package/dist/cjs/package.json +3 -0
  6. package/dist/cjs/types/utility.type.js +2 -0
  7. package/dist/esm/classes/errors.class.js +43 -0
  8. package/dist/esm/classes/errors.class.js.map +1 -0
  9. package/dist/esm/classes/index.js +2 -0
  10. package/dist/esm/classes/index.js.map +1 -0
  11. package/dist/esm/index.js +1 -0
  12. package/dist/esm/index.js.map +1 -1
  13. package/dist/esm/types/utility.type.js +2 -0
  14. package/dist/esm/types/utility.type.js.map +1 -0
  15. package/dist/types/classes/errors.class.d.ts +26 -0
  16. package/dist/types/classes/index.d.ts +1 -0
  17. package/dist/types/index.d.ts +1 -0
  18. package/dist/types/types/index.d.ts +1 -0
  19. package/dist/types/types/utility.type.d.ts +9 -0
  20. package/package.json +6 -5
  21. /package/dist/cjs/schemas/{book.schema.cjs → book.schema.js} +0 -0
  22. /package/dist/cjs/schemas/{copy.schema.cjs → copy.schema.js} +0 -0
  23. /package/dist/cjs/schemas/{customer.schema.cjs → customer.schema.js} +0 -0
  24. /package/dist/cjs/schemas/{group.schema.cjs → group.schema.js} +0 -0
  25. /package/dist/cjs/schemas/{index.cjs → index.js} +0 -0
  26. /package/dist/cjs/schemas/{loan.schema.cjs → loan.schema.js} +0 -0
  27. /package/dist/cjs/types/{book.type.cjs → book.type.js} +0 -0
  28. /package/dist/cjs/types/{copy.type.cjs → copy.type.js} +0 -0
  29. /package/dist/cjs/types/{customer.type.cjs → customer.type.js} +0 -0
  30. /package/dist/cjs/types/{group.types.cjs → group.types.js} +0 -0
  31. /package/dist/cjs/types/{index.cjs → index.js} +0 -0
  32. /package/dist/cjs/types/{loan.type.cjs → loan.type.js} +0 -0
package/README.md CHANGED
@@ -5,3 +5,120 @@ Here you can find all the type definitions for [TiBoLi](https://tiboli.tech4web.
5
5
  ## Contributing
6
6
 
7
7
  If you want to Contribute, make sure to follow the Guidelines highlighted in `CONTRIBUTING.md`
8
+
9
+ ## Documentation
10
+
11
+ The following Zod schemas define the structure of the core data entities and their corresponding creation and update payloads.
12
+
13
+ ### Book
14
+
15
+ Represents a book in the library.
16
+
17
+ | Field | Type | Description |
18
+ | -------- | --------- | ----------------------------- |
19
+ | `id` | `integer` | Unique identifier of the book |
20
+ | `title` | `string` | Title of the book |
21
+ | `author` | `string` | Author of the book |
22
+
23
+ #### Variants
24
+
25
+ * **`BookSchema`** — Complete book object.
26
+ * **`BookCreationSchema`** — Book data for creation. Omits `id`.
27
+ * **`BookUpdateSchema`** — Partial book update. Requires `id`; all other fields are optional.
28
+
29
+ ---
30
+
31
+ ### Copy
32
+
33
+ Represents a physical copy of a book.
34
+
35
+ | Field | Type | Description |
36
+ | -------- | --------- | ----------------------------------- |
37
+ | `id` | `integer` | Unique identifier of the copy |
38
+ | `bookId` | `integer` | ID of the book this copy belongs to |
39
+
40
+ #### Variants
41
+
42
+ * **`CopySchema`** — Complete copy object.
43
+ * **`CopyCreationSchema`** — Copy data for creation. Omits `id`.
44
+ * **`CopyUpdateSchema`** — Partial copy update. Requires `id`; all other fields are optional.
45
+
46
+ ---
47
+
48
+ ### Customer
49
+
50
+ Represents a customer or borrower in the library.
51
+
52
+ | Field | Type | Description |
53
+ | ---------- | --------- | ----------------------------------- |
54
+ | `id` | `integer` | Unique identifier of the customer |
55
+ | `name` | `string` | First name of the customer |
56
+ | `lastname` | `string` | Last name of the customer |
57
+ | `email` | `email` | Valid email address of the customer |
58
+
59
+ #### Variants
60
+
61
+ * **`CustomerSchema`** — Complete customer object.
62
+ * **`CustomerCreationSchema`** — Customer data for creation. Omits `id`.
63
+ * **`CustomerUpdateSchema`** — Partial customer update. Requires `id`; all other fields are optional.
64
+
65
+ ---
66
+
67
+ ### Group
68
+
69
+ Represents a group of customers.
70
+
71
+ | Field | Type | Description |
72
+ | ------ | --------- | ------------------------------ |
73
+ | `id` | `integer` | Unique identifier of the group |
74
+ | `name` | `string` | Name of the group |
75
+
76
+ #### Variants
77
+
78
+ * **`GroupSchema`** — Complete group object.
79
+ * **`GroupCreationSchema`** — Group data for creation. Omits `id`.
80
+ * **`GroupUpdateSchema`** — Partial group update. Requires `id`; all other fields are optional.
81
+
82
+ ---
83
+
84
+ ### Loan
85
+
86
+ Represents a loan of a physical book copy to a customer.
87
+
88
+ | Field | Type | Description |
89
+ | ------------ | --------- | ---------------------------------------- |
90
+ | `id` | `integer` | Unique identifier of the loan |
91
+ | `copyId` | `integer` | ID of the borrowed book copy |
92
+ | `customerId` | `integer` | ID of the customer who borrowed the copy |
93
+ | `lentDate` | `date` | Date on which the copy was lent |
94
+ | `dueDate` | `date` | Date on which the copy is due |
95
+ | `returnDate` | `date` | Date on which the copy was returned |
96
+
97
+ #### Variants
98
+
99
+ * **`LoanSchema`** — Complete loan object.
100
+ * **`LoanCreationSchema`** — Loan data for creation. Omits `id`.
101
+ * **`LoanUpdateSchema`** — Partial loan update. Requires `id`; all other fields are optional.
102
+
103
+ ### Schema Variants
104
+
105
+ All entities follow the same pattern:
106
+
107
+ ```text
108
+ EntitySchema
109
+ ├── EntityCreationSchema
110
+ │ └── Omits `id`
111
+ └── EntityUpdateSchema
112
+ ├── Requires `id`
113
+ └── Makes all other fields optional
114
+ ```
115
+
116
+ This allows the schemas to be reused consistently for validating complete entities, creation requests, and partial update requests.
117
+
118
+ ### Inferred types
119
+
120
+ Each of the Schemas get's a Type inferred using `z.infer`. The types are named `Attributes` instead of Schemas. For instance.
121
+
122
+ - `EntitySchema` -> `EntityAttributes`
123
+ - `EntityCreationSchema` -> `EntityCreationAttributes`
124
+
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InternalServerError = exports.MalformedRequestError = exports.NotFoundError = exports.HttpError = exports.BaseError = void 0;
4
+ /**
5
+ * Defines the Base Error class for handling Errors.
6
+ * @param {string} message Error message. Should be representing to the error
7
+ * @param {ErrorParameters} options Parameters for the Error, like cause and context.
8
+ * @returns {undefined}
9
+ */
10
+ class BaseError extends Error {
11
+ context;
12
+ constructor(message, options = {}) {
13
+ const { cause, context } = options;
14
+ super(message, { cause });
15
+ this.name = this.constructor.name;
16
+ this.context = context;
17
+ }
18
+ }
19
+ exports.BaseError = BaseError;
20
+ class HttpError extends BaseError {
21
+ statusCode;
22
+ descriptorString;
23
+ constructor(message, status, descriptor, options = {}) {
24
+ super(message, options);
25
+ this.statusCode = status;
26
+ this.descriptorString = descriptor;
27
+ }
28
+ toResponse() {
29
+ return this.descriptorString;
30
+ }
31
+ }
32
+ exports.HttpError = HttpError;
33
+ class NotFoundError extends HttpError {
34
+ constructor(message, options = {}) {
35
+ super(message, 404, 'Entity not found', options);
36
+ }
37
+ }
38
+ exports.NotFoundError = NotFoundError;
39
+ class MalformedRequestError extends HttpError {
40
+ constructor(message, options = {}) {
41
+ super(message, 400, 'Malformed Request', options);
42
+ }
43
+ }
44
+ exports.MalformedRequestError = MalformedRequestError;
45
+ class InternalServerError extends HttpError {
46
+ constructor(message, options = {}) {
47
+ super(message, 500, 'Internal Server Error', options);
48
+ }
49
+ }
50
+ exports.InternalServerError = InternalServerError;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InternalServerError = exports.MalformedRequestError = exports.NotFoundError = exports.HttpError = exports.BaseError = void 0;
4
+ var errors_class_js_1 = require("./errors.class.js");
5
+ Object.defineProperty(exports, "BaseError", { enumerable: true, get: function () { return errors_class_js_1.BaseError; } });
6
+ Object.defineProperty(exports, "HttpError", { enumerable: true, get: function () { return errors_class_js_1.HttpError; } });
7
+ Object.defineProperty(exports, "NotFoundError", { enumerable: true, get: function () { return errors_class_js_1.NotFoundError; } });
8
+ Object.defineProperty(exports, "MalformedRequestError", { enumerable: true, get: function () { return errors_class_js_1.MalformedRequestError; } });
9
+ Object.defineProperty(exports, "InternalServerError", { enumerable: true, get: function () { return errors_class_js_1.InternalServerError; } });
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./schemas"), exports);
18
18
  __exportStar(require("./types"), exports);
19
+ __exportStar(require("./classes"), exports);
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Defines the Base Error class for handling Errors.
3
+ * @param {string} message Error message. Should be representing to the error
4
+ * @param {ErrorParameters} options Parameters for the Error, like cause and context.
5
+ * @returns {undefined}
6
+ */
7
+ export class BaseError extends Error {
8
+ context;
9
+ constructor(message, options = {}) {
10
+ const { cause, context } = options;
11
+ super(message, { cause });
12
+ this.name = this.constructor.name;
13
+ this.context = context;
14
+ }
15
+ }
16
+ export class HttpError extends BaseError {
17
+ statusCode;
18
+ descriptorString;
19
+ constructor(message, status, descriptor, options = {}) {
20
+ super(message, options);
21
+ this.statusCode = status;
22
+ this.descriptorString = descriptor;
23
+ }
24
+ toResponse() {
25
+ return this.descriptorString;
26
+ }
27
+ }
28
+ export class NotFoundError extends HttpError {
29
+ constructor(message, options = {}) {
30
+ super(message, 404, 'Entity not found', options);
31
+ }
32
+ }
33
+ export class MalformedRequestError extends HttpError {
34
+ constructor(message, options = {}) {
35
+ super(message, 400, 'Malformed Request', options);
36
+ }
37
+ }
38
+ export class InternalServerError extends HttpError {
39
+ constructor(message, options = {}) {
40
+ super(message, 500, 'Internal Server Error', options);
41
+ }
42
+ }
43
+ //# sourceMappingURL=errors.class.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.class.js","sourceRoot":"","sources":["../../../src/classes/errors.class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@ -0,0 +1,2 @@
1
+ export { BaseError, HttpError, NotFoundError, MalformedRequestError, InternalServerError, } from './errors.class.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/classes/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,SAAS,EACT,SAAS,EACT,aAAa,EACb,qBAAqB,EACrB,mBAAmB,GACnB,MAAM,mBAAmB,CAAC"}
package/dist/esm/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './schemas';
2
2
  export * from './types';
3
+ export * from './classes';
3
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=utility.type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utility.type.js","sourceRoot":"","sources":["../../../src/types/utility.type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,26 @@
1
+ import { ErrorParameters, Jsonable } from '../types';
2
+ /**
3
+ * Defines the Base Error class for handling Errors.
4
+ * @param {string} message Error message. Should be representing to the error
5
+ * @param {ErrorParameters} options Parameters for the Error, like cause and context.
6
+ * @returns {undefined}
7
+ */
8
+ export declare class BaseError extends Error {
9
+ readonly context?: Jsonable;
10
+ constructor(message: string, options?: ErrorParameters);
11
+ }
12
+ export declare class HttpError extends BaseError {
13
+ readonly statusCode: number;
14
+ readonly descriptorString: string;
15
+ constructor(message: string, status: number, descriptor: string, options?: ErrorParameters);
16
+ toResponse(): string;
17
+ }
18
+ export declare class NotFoundError extends HttpError {
19
+ constructor(message: string, options?: ErrorParameters);
20
+ }
21
+ export declare class MalformedRequestError extends HttpError {
22
+ constructor(message: string, options?: ErrorParameters);
23
+ }
24
+ export declare class InternalServerError extends HttpError {
25
+ constructor(message: string, options?: ErrorParameters);
26
+ }
@@ -0,0 +1 @@
1
+ export { BaseError, HttpError, NotFoundError, MalformedRequestError, InternalServerError, } from './errors.class.js';
@@ -1,2 +1,3 @@
1
1
  export * from './schemas';
2
2
  export * from './types';
3
+ export * from './classes';
@@ -3,3 +3,4 @@ export { CopyAttributes, CopyCreationAttributes, CopyUpdateAttributes } from './
3
3
  export { CustomerAttributes, CustomerCreationAttributes, CustomerUpdateAttributes, } from './customer.type';
4
4
  export { GroupAttributes, GroupCreationAttributes, GroupUpdateAttributes } from './group.types';
5
5
  export { LoanAttributes, LoanCreationAttributes, LoanUpdateAttributes } from './loan.type';
6
+ export { Jsonable, ErrorParameters } from './utility.type.js';
@@ -0,0 +1,9 @@
1
+ export type Jsonable = string | number | boolean | null | undefined | readonly Jsonable[] | {
2
+ readonly [key: string]: Jsonable;
3
+ } | {
4
+ toJSON(): Jsonable;
5
+ };
6
+ export type ErrorParameters = {
7
+ context?: Jsonable;
8
+ cause?: Jsonable;
9
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tiboli/types",
3
3
  "scope": "@tiboli",
4
- "version": "0.0.10",
4
+ "version": "0.0.12",
5
5
  "description": "Typedefinitions for Tiboli",
6
6
  "keywords": [
7
7
  "tiboli",
@@ -15,24 +15,24 @@
15
15
  "files": [
16
16
  "dist"
17
17
  ],
18
- "main": "./dist/cjs/index.cjs",
18
+ "main": "./dist/cjs/index.js",
19
19
  "module": "./dist/esm/index.js",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "exports": {
22
22
  ".": {
23
23
  "types": "./dist/types/index.d.ts",
24
24
  "import": "./dist/esm/index.js",
25
- "require": "./dist/cjs/index.cjs"
25
+ "require": "./dist/cjs/index.js"
26
26
  },
27
27
  "./schemas": {
28
28
  "types": "./dist/types/schemas/index.d.ts",
29
29
  "import": "./dist/esm/schemas/index.js",
30
- "require": "./dist/cjs/schemas/index.cjs"
30
+ "require": "./dist/cjs/schemas/index.js"
31
31
  },
32
32
  "./types": {
33
33
  "types": "./dist/types/types/index.d.ts",
34
34
  "import": "./dist/esm/types/index.js",
35
- "require": "./dist/cjs/types/index.cjs"
35
+ "require": "./dist/cjs/types/index.js"
36
36
  }
37
37
  },
38
38
  "scripts": {
@@ -45,6 +45,7 @@
45
45
  "dev": "tsx watch -r tsconfig-paths/register src",
46
46
  "prepare": "husky",
47
47
  "lint": "eslint --max-warnings=0 .",
48
+ "lint:fix": "eslint --max-warnings=0 --fix .",
48
49
  "lint:staged": "lint-staged",
49
50
  "test": "jest --passWithNoTests"
50
51
  },
File without changes
File without changes
File without changes
File without changes
File without changes