22 * @template T, ID
33 */
44export class RestService < T , ID > {
5+ static $nonscope : boolean ;
56 /**
7+ * Core REST service for CRUD operations.
8+ * Safe, predictable, and optionally maps raw JSON to entity class instances.
9+ *
610 * @param {ng.HttpService } $http Angular-like $http service
7- * @param {string } baseUrl Base URL template, e.g. "/users/:id{/subId}{?page,limit}"
8- * @param {{new(data: any): T}= } entityClass Optional constructor for mapping JSON to class instances
9- * @param {Object= } providerDefaults Optional defaults from RestProvider
11+ * @param {string } baseUrl Base URL or URI template
12+ * @param {{new(data: any): T}= } entityClass Optional constructor to map JSON to objects
13+ * @param {Object= } options Optional settings (interceptors, headers, etc.)
1014 */
1115 constructor (
1216 $http : ng . HttpService ,
@@ -16,74 +20,70 @@ export class RestService<T, ID> {
1620 new ( data : any ) : T ;
1721 }
1822 | undefined ,
19- providerDefaults ?: any | undefined ,
23+ options ?: any | undefined ,
2024 ) ;
21- /** @private @type { ng.HttpService } */
25+ /** @private */
2226 private $http ;
23- /** @private @type { string } */
27+ /** @private */
2428 private baseUrl ;
25- /** @private @type { {new(data: any): T}= } */
29+ /** @private */
2630 private entityClass ;
27- /** @type {Object } global defaults from provider */
28- providerDefaults : any ;
29- /** @type {Array<(config: any) => any | Promise<any>> } */
30- requestInterceptors : Array < ( config : any ) => any | Promise < any > > ;
31- /** @type {Array<(response: any) => any | Promise<any>> } */
32- responseInterceptors : Array < ( response : any ) => any | Promise < any > > ;
31+ /** @private */
32+ private options ;
3333 /**
34- * Apply all request interceptors sequentially
35- * @private
34+ * Build full URL from template and parameters
35+ * @param {string } template
36+ * @param {Record<string, any> } params
37+ * @returns {string }
3638 */
37- private _applyRequestInterceptors ;
39+ buildUrl ( template : string , params : Record < string , any > ) : string ;
3840 /**
39- * Apply all response interceptors sequentially
40- * @private
41+ * List entities
42+ * @param {Record<string, any>= } params
43+ * @returns {Promise<T[]> }
4144 */
42- private _applyResponseInterceptors ;
45+ list ( params ?: Record < string , any > | undefined ) : Promise < T [ ] > ;
4346 /**
44- * @private
47+ * Read single entity by ID
48+ * @param {ID } id
49+ * @param {Record<string, any>= } params
50+ * @returns {Promise<T|null> }
4551 */
46- private _request ;
47- /** @private map raw data to entity class */
48- private mapEntity ;
52+ read ( id : ID , params ?: Record < string , any > | undefined ) : Promise < T | null > ;
4953 /**
50- * @private
51- * Build URL by replacing colon-style params first, then expanding RFC 6570 template
52- * @param {string } template
53- * @param {Record<string, any> } [params]
54- * @returns {string }
54+ * Create a new entity
55+ * @param {T } item
56+ * @returns {Promise<T> }
5557 */
56- private buildUrl ;
57- /** List entities (optional query params) */
58- list ( params ?: { } ) : Promise < any > ;
59- /** Read entity by ID (ID can be in colon or RFC template) */
60- read ( id : any , params ?: { } ) : Promise < any > ;
61- create ( item : any , params ?: { } ) : Promise < any > ;
62- update ( id : any , item : any , params ?: { } ) : Promise < any > ;
63- delete ( id : any , params ?: { } ) : Promise < boolean > ;
58+ create ( item : T ) : Promise < T > ;
59+ /**
60+ * Update entity by ID
61+ * @param {ID } id
62+ * @param {Partial<T> } item
63+ * @returns {Promise<T|null> }
64+ */
65+ update ( id : ID , item : Partial < T > ) : Promise < T | null > ;
66+ /**
67+ * Delete entity by ID
68+ * @param {ID } id
69+ * @returns {Promise<boolean> }
70+ */
71+ delete ( id : ID ) : Promise < boolean > ;
72+ #private;
6473}
6574/**
66- * RestProvider - register named rest stores at config time.
67- *
68- * Usage (in config):
69- * restProvider.rest('user', '/api/users', User);
70- *
71- * Then at runtime you can inject `rest` factory and do:
72- * const userApi = rest('/api/users', User);
73- * or use the pre-registered named services:
74- * const userApi = rest.get('user');
75+ * Provider for registering REST endpoints during module configuration.
7576 */
7677export class RestProvider {
77- /** @private @type {import('./interface.ts'). RestDefinition[] } */
78+ /** @private @type {ng. RestDefinition<any> [] } */
7879 private definitions ;
79- /** provider-level defaults (optional) */
80- defaults : { } ;
8180 /**
82- * Register a named rest definition during configtime
81+ * Register a REST resource at config phase
8382 * @template T
84- * @param {string } name
85- * @param {string } url
86- * @param {{new(data:any):T}= } entityClass
83+ * @param {string } name Service name
84+ * @param {string } url Base URL or URI template
85+ * @param {{new(data:any):T}= } entityClass Optional entity constructor
86+ * @param {Object= } options Optional service options
8787 */
8888 rest < T > (
8989 name : string ,
@@ -93,17 +93,16 @@ export class RestProvider {
9393 new ( data : any ) : T ;
9494 }
9595 | undefined ,
96+ options ?: any | undefined ,
9697 ) : void ;
9798 /**
98- * $get factory: returns a `rest` factory function and allows access
99- * to pre-registered services via rest.get(name).
100- *
101- * @returns {(baseUrl:string, entityClass?:Function, options?:object) => RestService }
99+ * $get factory: returns a factory function and allows access to named services
100+ * @returns {(baseUrl:string, entityClass?:Function, options?:object) => RestService & { get(name:string): RestService, listNames(): string[] } }
102101 */
103102 $get : (
104103 | string
105104 | ( ( $http : any ) => {
106- ( baseUrl : any , entityClass : any , options : any ) : RestService < any , any > ;
105+ ( baseUrl : any , entityClass : any , options ?: { } ) : RestService < any , any > ;
107106 get ( name : any ) : any ;
108107 listNames ( ) : any [ ] ;
109108 } )
0 commit comments