@vmelou/jsonapi-angular 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/README.md ADDED
@@ -0,0 +1,319 @@
1
+ # @vmelou/jsonapi-angular
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@vmelou/jsonapi-angular)](https://www.npmjs.com/package/@vmelou/jsonapi-angular)
4
+ [![License: MIT](https://img.shields.io/npm/l/@vmelou/jsonapi-angular)](https://opensource.org/licenses/MIT)
5
+
6
+ Angular integration for [@vmelou/jsonapi](../core/README.md) library. Provides mixins for easy integration with Angular's HttpClient and RxJS for JSON:API endpoints.
7
+
8
+ ## Table of Contents
9
+
10
+ - [Installation](#installation)
11
+ - [Features](#features)
12
+ - [Usage](#usage)
13
+ - [Basic Setup](#basic-setup)
14
+ - [Using Mixins](#using-mixins)
15
+ - [Handling Relationships](#handling-relationships)
16
+ - [Error Handling](#error-handling)
17
+ - [API Reference](#api-reference)
18
+ - [Examples](#examples)
19
+ - [Contributing](#contributing)
20
+ - [Changelog](#changelog)
21
+ - [License](#license)
22
+
23
+ ## Installation
24
+
25
+ ```bash
26
+ npm install @vmelou/jsonapi @vmelou/jsonapi-angular
27
+ # or
28
+ yarn add @vmelou/jsonapi @vmelou/jsonapi-angular
29
+ ```
30
+
31
+ ## Features
32
+
33
+ - Complete integration with Angular's HttpClient
34
+ - RxJS Observables for all API operations
35
+ - Support for CRUD operations (Create, Read, Update, Delete)
36
+ - List operations with pagination and filtering
37
+ - Error handling with JSON:API error objects
38
+ - TypeScript type safety
39
+
40
+ ## Usage
41
+
42
+ ### Basic Setup
43
+
44
+ First, define your models using the core library's decorators:
45
+
46
+ ```typescript
47
+ import { BaseResource, JsonResource, JsonAttribute } from '@vmelou/jsonapi';
48
+
49
+ @JsonResource('authors')
50
+ export class Author extends BaseResource {
51
+ @JsonAttribute()
52
+ name = '';
53
+
54
+ @JsonAttribute(Date, 'created-at')
55
+ createdAt: Date = new Date();
56
+ }
57
+ ```
58
+
59
+ ### Using Mixins
60
+
61
+ Create a service that uses the provided mixins through composition:
62
+
63
+ ```typescript
64
+ import { Injectable } from '@angular/core';
65
+ import { HttpClient } from '@angular/common/http';
66
+ import { CreateMixin, RetrieveMixin, UpdateMixin, DeleteMixin, ListMixin } from '@vmelou/jsonapi-angular';
67
+ import { Observable } from 'rxjs';
68
+ import { Author } from './author.model';
69
+
70
+ @Injectable({ providedIn: 'root' })
71
+ export class AuthorService {
72
+ private createMixin: CreateMixin<Author>;
73
+ private retrieveMixin: RetrieveMixin<Author>;
74
+ private updateMixin: UpdateMixin<Author>;
75
+ private deleteMixin: DeleteMixin<Author>;
76
+ private listMixin: ListMixin<Author>;
77
+ private endpoint = 'authors';
78
+
79
+ constructor(http: HttpClient) {
80
+ this.createMixin = new CreateMixin<Author>(http, this.endpoint, Author);
81
+ this.retrieveMixin = new RetrieveMixin<Author>(http, this.endpoint, Author);
82
+ this.updateMixin = new UpdateMixin<Author>(http, this.endpoint, Author);
83
+ this.deleteMixin = new DeleteMixin<Author>(http, this.endpoint, Author);
84
+ this.listMixin = new ListMixin<Author>(http, this.endpoint, Author);
85
+ }
86
+
87
+ list(query?: { [key: string]: string }): Observable<Results<Author>> {
88
+ return this.listMixin.list(query);
89
+ }
90
+
91
+ create(data: Partial<Author>): Observable<Author> {
92
+ return this.createMixin.create(data);
93
+ }
94
+
95
+ retrieve(id: string, include: string[] = []): Observable<Author> {
96
+ return this.retrieveMixin.retrieve(id, include);
97
+ }
98
+
99
+ update(id: string, data: Partial<Author>): Observable<Author> {
100
+ return this.updateMixin.update(id, data);
101
+ }
102
+
103
+ delete(id: string): Observable<void> {
104
+ return this.deleteMixin.delete(id);
105
+ }
106
+
107
+ // Custom endpoint example
108
+ retrieveProfile(id: string): Observable<Author> {
109
+ return this.retrieveMixin.retrieve(`${id}/profile`);
110
+ }
111
+ }
112
+ ```
113
+
114
+ Now you can use the service in your components:
115
+
116
+ ```typescript
117
+ @Component({
118
+ selector: 'app-authors',
119
+ template: `
120
+ <div *ngFor="let author of authors$ | async">
121
+ {{ author.name }}
122
+ </div>
123
+ `,
124
+ })
125
+ export class AuthorsComponent {
126
+ authors$ = this.authorService.list();
127
+
128
+ constructor(private authorService: AuthorService) {}
129
+ }
130
+ ```
131
+
132
+ ### Handling Relationships
133
+
134
+ The mixins automatically handle relationships defined in your models:
135
+
136
+ ```typescript
137
+ @JsonResource('books')
138
+ export class Book extends BaseResource {
139
+ @JsonAttribute()
140
+ title = '';
141
+
142
+ @JsonAttribute(Author)
143
+ author?: Author;
144
+
145
+ @JsonAttribute(Author, 'co-authors')
146
+ coAuthors: Author[] = [];
147
+ }
148
+
149
+ @Injectable({ providedIn: 'root' })
150
+ export class BookService {
151
+ private retrieveMixin: RetrieveMixin<Book>;
152
+ private endpoint = 'books';
153
+
154
+ constructor(http: HttpClient) {
155
+ this.retrieveMixin = new RetrieveMixin<Book>(http, this.endpoint, Book);
156
+ }
157
+
158
+ getBookWithAuthor(id: string): Observable<Book> {
159
+ return this.retrieveMixin.retrieve(id, ['author', 'co-authors']);
160
+ }
161
+
162
+ // Custom endpoint example
163
+ getBookReviews(id: string): Observable<Book> {
164
+ return this.retrieveMixin.retrieve(`${id}/reviews`);
165
+ }
166
+ }
167
+ ```
168
+
169
+ ### Error Handling
170
+
171
+ All mixins include built-in error handling that converts JSON:API error responses to ApiError objects:
172
+
173
+ ```typescript
174
+ this.bookService.create(newBook).subscribe({
175
+ next: (book) => console.log('Book created:', book),
176
+ error: (errors: ApiError[]) => {
177
+ errors.forEach((error) => {
178
+ console.error(`Error: ${error.title} - ${error.detail}`);
179
+ });
180
+ },
181
+ });
182
+ ```
183
+
184
+ ## API Reference
185
+
186
+ ### Mixins
187
+
188
+ - `ListMixin<T>`: List resources with pagination and filtering
189
+
190
+ - `list(query?: { [key: string]: string }, url?: string): Observable<Results<T>>`
191
+
192
+ - `CreateMixin<T>`: Create new resources
193
+
194
+ - `create(data: Partial<T>): Observable<T>`
195
+
196
+ - `RetrieveMixin<T>`: Retrieve single resources
197
+
198
+ - `retrieve(id: string, include: string[] = []): Observable<T>`
199
+
200
+ - `UpdateMixin<T>`: Update existing resources
201
+
202
+ - `update(id: string, data: Partial<T>): Observable<T>`
203
+
204
+ - `DeleteMixin<T>`: Delete resources
205
+ - `delete(id: string): Observable<void>`
206
+
207
+ ### Query Parameters
208
+
209
+ The `list` method supports various query parameters:
210
+
211
+ ```typescript
212
+ // Pagination
213
+ service.list({ 'page[number]': '1', 'page[size]': '10' });
214
+
215
+ // Filtering
216
+ service.list({ 'filter[name]': 'John' });
217
+
218
+ // Including relationships
219
+ service.list({ include: 'author,co-authors' });
220
+
221
+ // Sorting
222
+ service.list({ sort: '-created-at,name' });
223
+ ```
224
+
225
+ ## Examples
226
+
227
+ ### Complete CRUD Example
228
+
229
+ ```typescript
230
+ @Component({
231
+ template: `
232
+ <div *ngFor="let book of books$ | async">
233
+ <h2>{{ book.title }}</h2>
234
+ <p>Author: {{ book.author?.name }}</p>
235
+ <button (click)="updateBook(book)">Edit</button>
236
+ <button (click)="deleteBook(book)">Delete</button>
237
+ </div>
238
+ `,
239
+ })
240
+ export class BooksComponent {
241
+ books$ = this.bookService.list();
242
+
243
+ constructor(private bookService: BookService) {}
244
+
245
+ createBook(bookData: Partial<Book>) {
246
+ this.bookService.create(bookData).subscribe({
247
+ next: (book) => console.log('Book created:', book),
248
+ error: (errors) => console.error('Failed to create book:', errors),
249
+ });
250
+ }
251
+
252
+ updateBook(book: Book) {
253
+ this.bookService.update(book.id, { title: 'Updated Title' }).subscribe({
254
+ next: (updated) => console.log('Book updated:', updated),
255
+ error: (errors) => console.error('Failed to update book:', errors),
256
+ });
257
+ }
258
+
259
+ deleteBook(book: Book) {
260
+ this.bookService.delete(book.id).subscribe({
261
+ next: () => console.log('Book deleted'),
262
+ error: (errors) => console.error('Failed to delete book:', errors),
263
+ });
264
+ }
265
+ }
266
+ ```
267
+
268
+ ### Handling Pagination Results
269
+
270
+ ```typescript
271
+ interface PaginationMeta {
272
+ pagination: {
273
+ count: number;
274
+ page: number;
275
+ pages: number;
276
+ };
277
+ }
278
+
279
+ @Component({
280
+ template: `
281
+ <div *ngIf="results$ | async as results">
282
+ <div *ngFor="let item of results.data">
283
+ {{ item.title }}
284
+ </div>
285
+
286
+ <div class="pagination">
287
+ <button [disabled]="!results.links?.prev" (click)="loadPage(results.links?.prev)">Previous</button>
288
+ <span>Page {{ results.meta?.pagination?.page }} of {{ results.meta?.pagination?.pages }}</span>
289
+ <button [disabled]="!results.links?.next" (click)="loadPage(results.links?.next)">Next</button>
290
+ </div>
291
+ </div>
292
+ `,
293
+ })
294
+ export class PaginatedListComponent {
295
+ results$: Observable<Results<Book>>;
296
+
297
+ constructor(private bookService: BookService) {
298
+ this.results$ = this.bookService.list({ 'page[size]': '10' });
299
+ }
300
+
301
+ loadPage(url: string | null) {
302
+ if (url) {
303
+ this.results$ = this.bookService.list({}, url);
304
+ }
305
+ }
306
+ }
307
+ ```
308
+
309
+ ## Contributing
310
+
311
+ We welcome contributions! Please see our [Contributing Guidelines](../../../CONTRIBUTING.md) for more details on how to get involved.
312
+
313
+ ## Changelog
314
+
315
+ Detailed changes for each release are documented in the [CHANGELOG.md](../../../CHANGELOG.md) file.
316
+
317
+ ## License
318
+
319
+ MIT
@@ -0,0 +1,144 @@
1
+ import { throwError, map, catchError } from 'rxjs';
2
+ import { ApiError, serialize, deserialize, deserializeCollection } from '@vmelou/jsonapi';
3
+ import { HttpParams } from '@angular/common/http';
4
+
5
+ class BaseMixin {
6
+ handleErrors(error
7
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
+ ) {
9
+ let errors = [];
10
+ if (error.error instanceof ProgressEvent ||
11
+ error.error instanceof ErrorEvent ||
12
+ error.error instanceof TypeError) {
13
+ // A client-side or network error occurred. Handle it accordingly.
14
+ const httpError = new ApiError('', error.message, '0');
15
+ errors.push(httpError);
16
+ }
17
+ else if (error?.error?.errors) {
18
+ // The backend returned an unsuccessful response code.
19
+ // The response body may contain clues as to what went wrong.
20
+ errors = ApiError.fromErrors(error.error.errors);
21
+ }
22
+ return throwError(() => errors);
23
+ }
24
+ }
25
+
26
+ class CreateMixin extends BaseMixin {
27
+ http;
28
+ endpoint;
29
+ cls;
30
+ constructor(http, endpoint, cls) {
31
+ super();
32
+ this.http = http;
33
+ this.endpoint = endpoint;
34
+ this.cls = cls;
35
+ }
36
+ create(data) {
37
+ return this.http
38
+ .post(`${this.endpoint}/`, serialize(this.cls, data))
39
+ .pipe(map((response) => {
40
+ return deserialize(this.cls, response.data, response.included);
41
+ }), catchError(this.handleErrors));
42
+ }
43
+ }
44
+
45
+ class DeleteMixin extends BaseMixin {
46
+ http;
47
+ endpoint;
48
+ cls;
49
+ constructor(http, endpoint, cls) {
50
+ super();
51
+ this.http = http;
52
+ this.endpoint = endpoint;
53
+ this.cls = cls;
54
+ }
55
+ delete(id) {
56
+ return this.http
57
+ .delete(`${this.endpoint}/${id}/`)
58
+ .pipe(catchError(this.handleErrors));
59
+ }
60
+ }
61
+
62
+ function createHttpParams(query) {
63
+ let params = new HttpParams();
64
+ if (query !== undefined) {
65
+ Object.keys(query).forEach((key) => {
66
+ if (key === 'include') {
67
+ params = params.append(key, query[key]);
68
+ return;
69
+ }
70
+ const values = query[key].split(',');
71
+ values.forEach((value) => {
72
+ if (value.trim()) {
73
+ params = params.append(key, value);
74
+ }
75
+ });
76
+ });
77
+ }
78
+ return params;
79
+ }
80
+ class ListMixin {
81
+ http;
82
+ endpoint;
83
+ cls;
84
+ constructor(http, endpoint, cls) {
85
+ this.http = http;
86
+ this.endpoint = endpoint;
87
+ this.cls = cls;
88
+ }
89
+ list(query, url) {
90
+ const params = createHttpParams(query);
91
+ return this.http
92
+ .get(url ?? `${this.endpoint}/`, { params })
93
+ .pipe(map((response) => {
94
+ return deserializeCollection(this.cls, response);
95
+ }));
96
+ }
97
+ }
98
+
99
+ class RetrieveMixin {
100
+ http;
101
+ endpoint;
102
+ cls;
103
+ constructor(http, endpoint, cls) {
104
+ this.http = http;
105
+ this.endpoint = endpoint;
106
+ this.cls = cls;
107
+ }
108
+ retrieve(id, include = []) {
109
+ let params = new HttpParams();
110
+ if (include.length !== 0) {
111
+ params = params.set('include', include.join(','));
112
+ }
113
+ return this.http
114
+ .get(`${this.endpoint}/${id}/`, { params })
115
+ .pipe(map((response) => {
116
+ return deserialize(this.cls, response.data, response.included);
117
+ }));
118
+ }
119
+ }
120
+
121
+ class UpdateMixin {
122
+ http;
123
+ endpoint;
124
+ cls;
125
+ constructor(http, endpoint, cls) {
126
+ this.http = http;
127
+ this.endpoint = endpoint;
128
+ this.cls = cls;
129
+ }
130
+ update(id, data) {
131
+ return this.http
132
+ .patch(`${this.endpoint}/${id}/`, serialize(this.cls, { id, ...data }))
133
+ .pipe(map((response) => {
134
+ return deserialize(this.cls, response.data, []);
135
+ }));
136
+ }
137
+ }
138
+
139
+ /**
140
+ * Generated bundle index. Do not edit.
141
+ */
142
+
143
+ export { BaseMixin, CreateMixin, DeleteMixin, ListMixin, RetrieveMixin, UpdateMixin };
144
+ //# sourceMappingURL=vmelou-jsonapi-angular.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vmelou-jsonapi-angular.mjs","sources":["../../../../../libs/jsonapi/angular/src/lib/mixins/base.mixin.ts","../../../../../libs/jsonapi/angular/src/lib/mixins/create.mixin.ts","../../../../../libs/jsonapi/angular/src/lib/mixins/delete.mixin.ts","../../../../../libs/jsonapi/angular/src/lib/mixins/list.mixin.ts","../../../../../libs/jsonapi/angular/src/lib/mixins/retrieve.mixin.ts","../../../../../libs/jsonapi/angular/src/lib/mixins/update.mixin.ts","../../../../../libs/jsonapi/angular/src/vmelou-jsonapi-angular.ts"],"sourcesContent":["import { HttpErrorResponse } from '@angular/common/http';\nimport { Observable, throwError } from 'rxjs';\nimport { ApiError } from '@vmelou/jsonapi';\n\nexport class BaseMixin {\n protected handleErrors(\n error: HttpErrorResponse\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ): Observable<ApiError[] | any> {\n let errors: ApiError[] = [];\n\n if (\n error.error instanceof ProgressEvent ||\n error.error instanceof ErrorEvent ||\n error.error instanceof TypeError\n ) {\n // A client-side or network error occurred. Handle it accordingly.\n const httpError = new ApiError('', error.message, '0');\n errors.push(httpError);\n } else if (error?.error?.errors) {\n // The backend returned an unsuccessful response code.\n // The response body may contain clues as to what went wrong.\n errors = ApiError.fromErrors(error.error.errors);\n }\n\n return throwError(() => errors);\n }\n}\n","import { HttpClient } from '@angular/common/http';\nimport { Observable, catchError, map } from 'rxjs';\nimport {\n BaseResource,\n deserialize,\n JsonDetailResponse,\n serialize,\n} from '@vmelou/jsonapi';\n\nimport { BaseMixin } from './base.mixin';\n\nexport class CreateMixin<T extends BaseResource> extends BaseMixin {\n constructor(\n private http: HttpClient,\n private endpoint: string,\n protected readonly cls: new () => T\n ) {\n super();\n }\n\n create(data: Partial<T>): Observable<T> {\n return this.http\n .post<JsonDetailResponse>(`${this.endpoint}/`, serialize(this.cls, data))\n .pipe(\n map((response: JsonDetailResponse) => {\n return deserialize<T>(this.cls, response.data, response.included);\n }),\n catchError(this.handleErrors)\n );\n }\n}\n","import { HttpClient } from '@angular/common/http';\nimport { Observable, catchError } from 'rxjs';\nimport { BaseResource } from '@vmelou/jsonapi';\n\nimport { BaseMixin } from './base.mixin';\n\nexport class DeleteMixin<T extends BaseResource> extends BaseMixin {\n constructor(\n private http: HttpClient,\n private endpoint: string,\n protected readonly cls: new () => T\n ) {\n super();\n }\n\n delete(id: string): Observable<void> {\n return this.http\n .delete<void>(`${this.endpoint}/${id}/`)\n .pipe(catchError(this.handleErrors));\n }\n}\n","import { HttpClient, HttpParams } from '@angular/common/http';\nimport { Observable, map } from 'rxjs';\n\nimport {\n BaseResource,\n deserializeCollection,\n JsonListResponse,\n Results,\n} from '@vmelou/jsonapi';\n\nfunction createHttpParams(query?: { [key: string]: string }): HttpParams {\n let params = new HttpParams();\n if (query !== undefined) {\n Object.keys(query).forEach((key: string) => {\n if (key === 'include') {\n params = params.append(key, query[key]);\n return;\n }\n\n const values = query[key].split(',');\n values.forEach((value: string) => {\n if (value.trim()) {\n params = params.append(key, value);\n }\n });\n });\n }\n return params;\n}\n\nexport class ListMixin<T extends BaseResource> {\n constructor(\n private http: HttpClient,\n private endpoint: string,\n protected readonly cls: new () => T\n ) {}\n\n list(\n query?: { [key: string]: string },\n url?: string\n ): Observable<Results<T>> {\n const params = createHttpParams(query);\n\n return this.http\n .get<JsonListResponse>(url ?? `${this.endpoint}/`, { params })\n .pipe(\n map((response: JsonListResponse) => {\n return deserializeCollection(this.cls, response);\n })\n );\n }\n}\n","import { HttpClient, HttpParams } from '@angular/common/http';\nimport { Observable, map } from 'rxjs';\nimport { BaseResource, deserialize, JsonDetailResponse } from '@vmelou/jsonapi';\n\nexport class RetrieveMixin<T extends BaseResource> {\n constructor(\n private http: HttpClient,\n private endpoint: string,\n protected readonly cls: new () => T\n ) {}\n\n retrieve(id: string, include: string[] = []): Observable<T> {\n let params = new HttpParams();\n\n if (include.length !== 0) {\n params = params.set('include', include.join(','));\n }\n\n return this.http\n .get<JsonDetailResponse>(`${this.endpoint}/${id}/`, { params })\n .pipe(\n map((response: JsonDetailResponse) => {\n return deserialize<T>(this.cls, response.data, response.included);\n })\n );\n }\n}\n","import { HttpClient } from '@angular/common/http';\nimport { Observable, map } from 'rxjs';\nimport {\n JsonDetailResponse,\n BaseResource,\n deserialize,\n serialize,\n} from '@vmelou/jsonapi';\n\nexport class UpdateMixin<T extends BaseResource> {\n constructor(\n private http: HttpClient,\n private endpoint: string,\n protected readonly cls: new () => T\n ) {}\n\n update(id: string, data: Partial<T>): Observable<T> {\n return this.http\n .patch<JsonDetailResponse>(\n `${this.endpoint}/${id}/`,\n serialize(this.cls, { id, ...data })\n )\n .pipe(\n map((response: JsonDetailResponse) => {\n return deserialize(this.cls, response.data, []);\n })\n );\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"m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AG,EAAE,EAAE,MAAM,EAAE;AAC7D,aAAA,IAAI,CACH,GAAG,CAAC,CAAC,QAA4B,KAAI;AACnC,YAAA,OAAO,WAAW,CAAI,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,QAAQ,CAAC;SAClE,CAAC,CACH;;AAEN;;MCjBY,WAAW,CAAA;AAEZ,IAAA,IAAA;AACA,IAAA,QAAA;AACW,IAAA,GAAA;AAHrB,IAAA,WAAA,CACU,IAAgB,EAChB,QAAgB,EACL,GAAgB,EAAA;QAF3B,IAAI,CAAA,IAAA,GAAJ,IAAI;QACJ,IAAQ,CAAA,QAAA,GAAR,QAAQ;QACG,IAAG,CAAA,GAAA,GAAH,GAAG;;IAGxB,MAAM,CAAC,EAAU,EAAE,IAAgB,EAAA;QACjC,OAAO,IAAI,CAAC;aACT,KAAK,CACJ,GAAG,IAAI,CAAC,QAAQ,CAAI,CAAA,EAAA,EAAE,CAAG,CAAA,CAAA,EACzB,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE,GAAG,IAAI,EAAE,CAAC;AAErC,aAAA,IAAI,CACH,GAAG,CAAC,CAAC,QAA4B,KAAI;AACnC,YAAA,OAAO,WAAW,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC;SAChD,CAAC,CACH;;AAEN;;AC5BD;;AAEG;;;;"}
package/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ export * from './lib/mixins/base.mixin';
2
+ export * from './lib/mixins/create.mixin';
3
+ export * from './lib/mixins/delete.mixin';
4
+ export * from './lib/mixins/list.mixin';
5
+ export * from './lib/mixins/retrieve.mixin';
6
+ export * from './lib/mixins/update.mixin';
@@ -0,0 +1,6 @@
1
+ import { HttpErrorResponse } from '@angular/common/http';
2
+ import { Observable } from 'rxjs';
3
+ import { ApiError } from '@vmelou/jsonapi';
4
+ export declare class BaseMixin {
5
+ protected handleErrors(error: HttpErrorResponse): Observable<ApiError[] | any>;
6
+ }
@@ -0,0 +1,11 @@
1
+ import { HttpClient } from '@angular/common/http';
2
+ import { Observable } from 'rxjs';
3
+ import { BaseResource } from '@vmelou/jsonapi';
4
+ import { BaseMixin } from './base.mixin';
5
+ export declare class CreateMixin<T extends BaseResource> extends BaseMixin {
6
+ private http;
7
+ private endpoint;
8
+ protected readonly cls: new () => T;
9
+ constructor(http: HttpClient, endpoint: string, cls: new () => T);
10
+ create(data: Partial<T>): Observable<T>;
11
+ }
@@ -0,0 +1,11 @@
1
+ import { HttpClient } from '@angular/common/http';
2
+ import { Observable } from 'rxjs';
3
+ import { BaseResource } from '@vmelou/jsonapi';
4
+ import { BaseMixin } from './base.mixin';
5
+ export declare class DeleteMixin<T extends BaseResource> extends BaseMixin {
6
+ private http;
7
+ private endpoint;
8
+ protected readonly cls: new () => T;
9
+ constructor(http: HttpClient, endpoint: string, cls: new () => T);
10
+ delete(id: string): Observable<void>;
11
+ }
@@ -0,0 +1,12 @@
1
+ import { HttpClient } from '@angular/common/http';
2
+ import { Observable } from 'rxjs';
3
+ import { BaseResource, Results } from '@vmelou/jsonapi';
4
+ export declare class ListMixin<T extends BaseResource> {
5
+ private http;
6
+ private endpoint;
7
+ protected readonly cls: new () => T;
8
+ constructor(http: HttpClient, endpoint: string, cls: new () => T);
9
+ list(query?: {
10
+ [key: string]: string;
11
+ }, url?: string): Observable<Results<T>>;
12
+ }
@@ -0,0 +1,10 @@
1
+ import { HttpClient } from '@angular/common/http';
2
+ import { Observable } from 'rxjs';
3
+ import { BaseResource } from '@vmelou/jsonapi';
4
+ export declare class RetrieveMixin<T extends BaseResource> {
5
+ private http;
6
+ private endpoint;
7
+ protected readonly cls: new () => T;
8
+ constructor(http: HttpClient, endpoint: string, cls: new () => T);
9
+ retrieve(id: string, include?: string[]): Observable<T>;
10
+ }
@@ -0,0 +1,10 @@
1
+ import { HttpClient } from '@angular/common/http';
2
+ import { Observable } from 'rxjs';
3
+ import { BaseResource } from '@vmelou/jsonapi';
4
+ export declare class UpdateMixin<T extends BaseResource> {
5
+ private http;
6
+ private endpoint;
7
+ protected readonly cls: new () => T;
8
+ constructor(http: HttpClient, endpoint: string, cls: new () => T);
9
+ update(id: string, data: Partial<T>): Observable<T>;
10
+ }
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@vmelou/jsonapi-angular",
3
+ "version": "0.4.0",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
7
+ "peerDependencies": {
8
+ "@angular/common": "^19.2.0",
9
+ "@vmelou/jsonapi": "^0.4.0",
10
+ "rxjs": "^7.8.0"
11
+ },
12
+ "sideEffects": false,
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/valerymelou/json-api.git"
16
+ },
17
+ "license": "MIT",
18
+ "module": "fesm2022/vmelou-jsonapi-angular.mjs",
19
+ "typings": "index.d.ts",
20
+ "exports": {
21
+ "./package.json": {
22
+ "default": "./package.json"
23
+ },
24
+ ".": {
25
+ "types": "./index.d.ts",
26
+ "default": "./fesm2022/vmelou-jsonapi-angular.mjs"
27
+ }
28
+ },
29
+ "dependencies": {
30
+ "tslib": "^2.3.0"
31
+ }
32
+ }