@angular-wave/angular.ts 0.12.0 → 0.13.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.
@@ -122,13 +122,13 @@ export class Angular {
122
122
  * function that will be invoked by the injector as a `config` block.
123
123
  * See: {@link angular.module modules}
124
124
  * @param {import("./interface.ts").AngularBootstrapConfig} [config]
125
- * @returns {import('./core/di/internal-injector.js').InjectorService} The created injector instance for this application.
125
+ * @returns {ng.InjectorService} The created injector instance for this application.
126
126
  */
127
127
  bootstrap(
128
128
  element: string | Element | Document,
129
129
  modules?: Array<string | any>,
130
130
  config?: import("./interface.ts").AngularBootstrapConfig,
131
- ): import("./core/di/internal-injector.js").InjectorService;
131
+ ): ng.InjectorService;
132
132
  $rootScope: import("./interface.ts").Scope;
133
133
  $injector: import("./interface.ts").InjectorService;
134
134
  /**
@@ -1,10 +1,9 @@
1
1
  /**
2
2
  * @typedef {import('./interface.ts').RafScheduler} RafScheduler
3
- * @typedef {import('../interface.ts').ServiceProvider} ServiceProvider
4
3
  */
5
4
  /**
6
5
  * Service provider that creates a requestAnimationFrame-based scheduler.
7
- * @type {ServiceProvider}
6
+ * @type {ng.ServiceProvider}
8
7
  */
9
8
  export class RafSchedulerProvider {
10
9
  /**
@@ -34,4 +33,3 @@ export class RafSchedulerProvider {
34
33
  $get(): RafScheduler;
35
34
  }
36
35
  export type RafScheduler = import("./interface.ts").RafScheduler;
37
- export type ServiceProvider = import("../interface.ts").ServiceProvider;
@@ -18,7 +18,7 @@ export class Attributes {
18
18
  );
19
19
  $rootScope: import("../scope/scope.js").Scope;
20
20
  $animate: import("../../interface.ts").AnimateService;
21
- $exceptionHandler: import("../../services/exception/interface.ts").ErrorHandler;
21
+ $exceptionHandler: import("../../interface.ts").ExceptionHandler;
22
22
  $sce: any;
23
23
  $attr: {};
24
24
  /** @type {import("../../shared/noderef.js").NodeRef} */
@@ -126,11 +126,11 @@ export class CompileProvider {
126
126
  | ((
127
127
  $injector: ng.InjectorService,
128
128
  $interpolate: any,
129
- $exceptionHandler: import("../../services/exception/exception-handler.js").ErrorHandler,
129
+ $exceptionHandler: ng.ExceptionHandlerService,
130
130
  $templateRequest: ng.TemplateRequestService,
131
131
  $parse: ng.ParseService,
132
132
  $controller: any,
133
- $rootScope: import("../scope/scope.js").Scope,
133
+ $rootScope: ng.Scope,
134
134
  $sce: any,
135
135
  $animate: ng.AnimateService,
136
136
  ) => (
@@ -50,6 +50,7 @@ export class NgModule {
50
50
  runBlocks: Array<ng.Injectable<any>>;
51
51
  services: any[];
52
52
  wasmModules: any[];
53
+ restDefinitions: any[];
53
54
  /**
54
55
  * @param {string} name
55
56
  * @param {any} object
@@ -180,18 +181,29 @@ export class NgModule {
180
181
  /**
181
182
  * @param {string} name
182
183
  * @param {Function} ctor
184
+ * @param {ng.StorageType} type
185
+ * @param {ng.StorageBackend} [backendOrConfig]
183
186
  * @returns {NgModule}
184
187
  */
185
- local(name: string, ctor: Function): NgModule;
188
+ store(
189
+ name: string,
190
+ ctor: Function,
191
+ type: ng.StorageType,
192
+ backendOrConfig?: ng.StorageBackend,
193
+ ): NgModule;
186
194
  /**
187
- * @param {string} name
188
- * @param {Function} ctor
189
- * @param {ng.StorageBackend} backendOrConfig
195
+ * @template T, ID
196
+ * Register a REST resource during module configuration.
197
+ * @param {string} name - Service name
198
+ * @param {string} url - Base URL or URI template
199
+ * @param {ng.EntityClass<T>} entityClass - Optional constructor for mapping JSON
200
+ * @param {Object=} options - Optional RestService options (interceptors, etc)
190
201
  * @returns {NgModule}
191
202
  */
192
- store(
203
+ rest<T, ID>(
193
204
  name: string,
194
- ctor: Function,
195
- backendOrConfig: ng.StorageBackend,
205
+ url: string,
206
+ entityClass: ng.EntityClass<T>,
207
+ options?: any | undefined,
196
208
  ): NgModule;
197
209
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
- * @returns {import('../../interface.ts').Directive}
2
+ * @returns {ng.Directive}
3
3
  */
4
- export function ngBindDirective(): import("../../interface.ts").Directive;
4
+ export function ngBindDirective(): ng.Directive;
5
5
  /**
6
6
  * @returns {import('../../interface.ts').Directive}
7
7
  */
@@ -3,15 +3,15 @@
3
3
  * @param {ng.TemplateRequestService} $templateRequest
4
4
  * @param {import("../../services/anchor-scroll/anchor-scroll.js").AnchorScrollFunction} $anchorScroll
5
5
  * @param {ng.AnimateService} $animate
6
- * @param {import('../../services/exception/interface.ts').ErrorHandler} $exceptionHandler
7
- * @returns {import('../../interface.ts').Directive}
6
+ * @param {ng.ExceptionHandlerService} $exceptionHandler
7
+ * @returns {ng.Directive}
8
8
  */
9
9
  export function ngIncludeDirective(
10
10
  $templateRequest: ng.TemplateRequestService,
11
11
  $anchorScroll: import("../../services/anchor-scroll/anchor-scroll.js").AnchorScrollFunction,
12
12
  $animate: ng.AnimateService,
13
- $exceptionHandler: import("../../services/exception/interface.ts").ErrorHandler,
14
- ): import("../../interface.ts").Directive;
13
+ $exceptionHandler: ng.ExceptionHandlerService,
14
+ ): ng.Directive;
15
15
  export namespace ngIncludeDirective {
16
16
  let $inject: string[];
17
17
  }
@@ -49,20 +49,20 @@ export class NgModelController {
49
49
  static $nonscope: boolean;
50
50
  static $inject: string[];
51
51
  /**
52
- * @param {import('../../core/scope/scope.js').Scope} $scope
53
- * @param {import('../../services/exception/exception-handler.js').ErrorHandler} $exceptionHandler
54
- * @param {import('../../core/compile/attributes.js').Attributes} $attr
52
+ * @param {ng.Scope} $scope
53
+ * @param {ng.ExceptionHandlerService} $exceptionHandler
54
+ * @param {ng.Attributes} $attr
55
55
  * @param {Element} $element
56
- * @param {import("../../core/parse/interface.ts").ParseService} $parse
56
+ * @param {ng.ParseService} $parse
57
57
  * @param {ng.AnimateService} $animate
58
58
  * @param {*} $interpolate
59
59
  */
60
60
  constructor(
61
- $scope: import("../../core/scope/scope.js").Scope,
62
- $exceptionHandler: import("../../services/exception/exception-handler.js").ErrorHandler,
63
- $attr: import("../../core/compile/attributes.js").Attributes,
61
+ $scope: ng.Scope,
62
+ $exceptionHandler: ng.ExceptionHandlerService,
63
+ $attr: ng.Attributes,
64
64
  $element: Element,
65
- $parse: import("../../core/parse/interface.ts").ParseService,
65
+ $parse: ng.ParseService,
66
66
  $animate: ng.AnimateService,
67
67
  $interpolate: any,
68
68
  );
@@ -123,11 +123,11 @@ export class NgModelController {
123
123
  $$parsedNgModelAssign: (context: any, value: any) => any;
124
124
  /**
125
125
  * @type {import("../../core/parse/interface.ts").CompiledExpression |
126
- * (function(import("../../core/scope/scope.js").Scope): any)}
126
+ * (function(ng.Scope): any)}
127
127
  */
128
128
  $$ngModelGet:
129
129
  | import("../../core/parse/interface.ts").CompiledExpression
130
- | ((arg0: import("../../core/scope/scope.js").Scope) => any);
130
+ | ((arg0: ng.Scope) => any);
131
131
  $$ngModelSet: (context: any, value: any) => any;
132
132
  $$pendingDebounce: number;
133
133
  $$parserValid: boolean;
@@ -135,13 +135,13 @@ export class NgModelController {
135
135
  $$parserName: string;
136
136
  /** @type {number} */
137
137
  $$currentValidationRunId: number;
138
- /** @type {import('../../core/scope/scope.js').Scope} */
139
- $$scope: import("../../core/scope/scope.js").Scope;
140
- $$attr: import("../../core/compile/attributes.js").Attributes;
138
+ /** @type {ng.Scope} */
139
+ $$scope: ng.Scope;
140
+ $$attr: ng.Attributes;
141
141
  $$element: Element;
142
142
  $$animate: import("../../interface.ts").AnimateService;
143
143
  $$parse: import("../../core/parse/interface.ts").ParseService;
144
- $$exceptionHandler: import("../../services/exception/interface.ts").ErrorHandler;
144
+ $$exceptionHandler: import("../../interface.ts").ExceptionHandler;
145
145
  $$hasNativeValidators: boolean;
146
146
  $$classCache: {};
147
147
  $$eventRemovers: Set<any>;
@@ -1,13 +1,13 @@
1
1
  /**
2
2
  *
3
3
  * @param {ng.CompileService} $compile
4
- * @param {import("../../core/parse/interface.ts").ParseService} $parse
5
- * @returns {import("../../interface.ts").Directive}
4
+ * @param {ng.ParseService} $parse
5
+ * @returns {ng.Directive}
6
6
  */
7
7
  export function ngOptionsDirective(
8
8
  $compile: ng.CompileService,
9
- $parse: import("../../core/parse/interface.ts").ParseService,
10
- ): import("../../interface.ts").Directive;
9
+ $parse: ng.ParseService,
10
+ ): ng.Directive;
11
11
  export namespace ngOptionsDirective {
12
12
  let $inject: string[];
13
13
  }
@@ -10,6 +10,11 @@ export * from "./index.js";
10
10
  export * from "./angular.js";
11
11
  export * from "./core/di/internal-injector.js";
12
12
  export * from "./core/scope/scope.js";
13
+ export * from "./services/cookie/cookie.js";
14
+ export * from "./services/cookie/interface.ts";
15
+ export * from "./services/exception/exception.ts";
16
+ export * from "./services/exception/interface.ts";
17
+ export * from "./core/parse/interface.ts";
13
18
  import { Attributes } from "./core/compile/attributes.js";
14
19
  import { Scope } from "./core/scope/scope.js";
15
20
  /**
@@ -64,7 +69,7 @@ export type InjectableClass<TInstance = any> = new (...args: any) => TInstance;
64
69
  *
65
70
  * Parentheses are required around constructor types when used in unions.
66
71
  */
67
- type FactoryFunction<T> = T extends abstract new (...args: any[]) => any
72
+ export type FactoryFunction<T> = T extends abstract new (...args: any[]) => any
68
73
  ? (...args: ConstructorParameters<T>) => InstanceType<T>
69
74
  : T;
70
75
  export type Injectable<
@@ -75,6 +80,12 @@ export type Injectable<
75
80
  ? InjectableClass<InstanceType<T>>
76
81
  : never)
77
82
  | T;
83
+ export interface ServiceProviderClass {
84
+ new (...args: any[]): ServiceProvider;
85
+ }
86
+ export interface ServiceProviderFactory {
87
+ (...args: any[]): ServiceProvider;
88
+ }
78
89
  /**
79
90
  * An object that defines how a service is constructed.
80
91
  *
@@ -163,6 +174,57 @@ export interface ChangesObject<T = any> {
163
174
  * Mapping of binding property names to their change metadata.
164
175
  */
165
176
  export type OnChangesObject = Record<string, ChangesObject>;
177
+ /**
178
+ * Interface for the $onInit lifecycle hook
179
+ * https://docs.angularjs.org/api/ng/service/$compile#life-cycle-hooks
180
+ */
181
+ export interface OnInit {
182
+ /**
183
+ * Called on each controller after all the controllers on an element have been constructed and had their bindings
184
+ * initialized (and before the pre & post linking functions for the directives on this element). This is a good
185
+ * place to put initialization code for your controller.
186
+ */
187
+ $onInit(): void;
188
+ }
189
+ /**
190
+ * Interface for the $onChanges lifecycle hook
191
+ * https://docs.angularjs.org/api/ng/service/$compile#life-cycle-hooks
192
+ */
193
+ export interface OnChanges {
194
+ /**
195
+ * Called whenever one-way bindings are updated. The onChangesObj is a hash whose keys are the names of the bound
196
+ * properties that have changed, and the values are an {@link IChangesObject} object of the form
197
+ * { currentValue, previousValue, isFirstChange() }. Use this hook to trigger updates within a component such as
198
+ * cloning the bound value to prevent accidental mutation of the outer value.
199
+ */
200
+ $onChanges(onChangesObj: OnChangesObject): void;
201
+ }
202
+ /**
203
+ * Interface for the $onDestroy lifecycle hook
204
+ * https://docs.angularjs.org/api/ng/service/$compile#life-cycle-hooks
205
+ */
206
+ export interface OnDestroy {
207
+ /**
208
+ * Called on a controller when its containing scope is destroyed. Use this hook for releasing external resources,
209
+ * watches and event handlers.
210
+ */
211
+ $onDestroy(): void;
212
+ }
213
+ /**
214
+ * Interface for the $postLink lifecycle hook
215
+ * https://docs.angularjs.org/api/ng/service/$compile#life-cycle-hooks
216
+ */
217
+ export interface PostLink {
218
+ /**
219
+ * Called after this controller's element and its children have been linked. Similar to the post-link function this
220
+ * hook can be used to set up DOM event handlers and do direct DOM manipulation. Note that child elements that contain
221
+ * templateUrl directives will not have been compiled and linked since they are waiting for their template to load
222
+ * asynchronously and their own compilation and linking has been suspended until that occurs. This hook can be considered
223
+ * analogous to the ngAfterViewInit and ngAfterContentInit hooks in Angular 2. Since the compilation process is rather
224
+ * different in Angular 1 there is no direct mapping and care should be taken when upgrading.
225
+ */
226
+ $postLink(): void;
227
+ }
166
228
  /**
167
229
  * AngularTS component lifecycle interface.
168
230
  * Directive controllers have a well-defined lifecycle. Each controller can implement "lifecycle hooks". These are methods that
@@ -13,7 +13,7 @@ import {
13
13
  AnchorScrollService as TAnchorScrollService,
14
14
  } from "./services/anchor-scroll/anchor-scroll.js";
15
15
  import { ControllerService as TControllerService } from "./core/controller/interface.ts";
16
- import { ErrorHandler as TErrorHandler } from "./services/exception/interface.ts";
16
+ import { ExceptionHandler as TExceptionHandler } from "./services/exception/interface.ts";
17
17
  import { ParseService as TParseService } from "./core/parse/interface.ts";
18
18
  import { TemplateRequestService as TTemplateRequestService } from "./services/template-request/interface.ts";
19
19
  import { HttpParamSerializer as THttpParamSerializer } from "./services/http/interface.ts";
@@ -64,8 +64,22 @@ import {
64
64
  import { Provider as TProvideService } from "./interface.ts";
65
65
  import { Location as TLocationService } from "./services/location/location.js";
66
66
  import { AnimateService as TAnimateService } from "./animations/interface.ts";
67
- import { StorageBackend as TStorageBackend } from "./services/storage/interface.ts";
67
+ import {
68
+ StorageBackend as TStorageBackend,
69
+ StorageType as TStorageType,
70
+ } from "./services/storage/interface.ts";
68
71
  import { StreamConnectionConfig as TStreamConnectionConfig } from "./services/stream/interface.ts";
72
+ import { CookieService as TCookieService } from "./services/cookie/cookie.js";
73
+ import {
74
+ CookieStoreOptions as TCookieStoreOptions,
75
+ CookieOptions as TCookieOptions,
76
+ } from "./services/cookie/interface.ts";
77
+ import {
78
+ RestDefinition as TRestDefinition,
79
+ EntityClass as TEntityClass,
80
+ } from "./services/rest/interface.ts";
81
+ import { RestService as TRestService } from "./services/rest/rest.js";
82
+ import { ServiceProvider as TServiceProvider } from "./interface.ts";
69
83
  declare global {
70
84
  interface Function {
71
85
  $inject?: readonly string[] | undefined;
@@ -100,7 +114,8 @@ declare global {
100
114
  type AnimateService = TAnimateService;
101
115
  type CompileService = TCompileFn;
102
116
  type ControllerService = TControllerService;
103
- type ExceptionHandlerService = TErrorHandler;
117
+ type CookieService = TCookieService;
118
+ type ExceptionHandlerService = TExceptionHandler;
104
119
  type FilterService = TFilterFactory;
105
120
  type HttpParamSerializerSerService = THttpParamSerializer;
106
121
  type HttpService = THttpService;
@@ -131,6 +146,13 @@ declare global {
131
146
  | (abstract new (...args: any[]) => any),
132
147
  > = TInjectable<T>;
133
148
  type StorageBackend = TStorageBackend;
149
+ type StorageType = TStorageType;
134
150
  type StreamConnectionConfig = TStreamConnectionConfig;
151
+ type CookieOptions = TCookieOptions;
152
+ type CookieStoreOptions = TCookieStoreOptions;
153
+ type RestService<T, ID> = TRestService<T, ID>;
154
+ type RestDefinition<T> = TRestDefinition<T>;
155
+ type EntityClass<T> = TEntityClass<T>;
156
+ type ServiceProvider = TServiceProvider;
135
157
  }
136
158
  }
@@ -60,10 +60,7 @@ export class UrlService {
60
60
  getHash(): string;
61
61
  $get: (
62
62
  | string
63
- | ((
64
- $location: import("../../services/location/location.js").Location,
65
- $rootScope: import("../../core/scope/scope.js").Scope,
66
- ) => UrlService)
63
+ | (($location: ng.LocationService, $rootScope: ng.Scope) => UrlService)
67
64
  )[];
68
65
  /**
69
66
  * @returns {string}
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Service provider that creates a {@link CookieService $cookie} service.
3
+ * @type {ng.ServiceProvider}
4
+ */
5
+ export class CookieProvider {
6
+ defaults: {};
7
+ $get: (
8
+ | string
9
+ | (($exceptionHandler: ng.ExceptionHandlerService) => CookieService)
10
+ )[];
11
+ }
12
+ /**
13
+ *
14
+ * Provides high-level APIs for interacting with browser cookies:
15
+ * - Raw get/set/remove
16
+ * - JSON serialization helpers
17
+ * - Global defaults supplied by $cookiesProvider
18
+ */
19
+ export class CookieService {
20
+ /**
21
+ * @param {ng.CookieOptions} defaults
22
+ * Default cookie attributes defined by `$cookiesProvider.defaults`.
23
+ * @param {ng.ExceptionHandlerService} $exceptionHandler
24
+ */
25
+ constructor(
26
+ defaults: ng.CookieOptions,
27
+ $exceptionHandler: ng.ExceptionHandlerService,
28
+ );
29
+ /** @type {ng.CookieOptions} */
30
+ defaults: ng.CookieOptions;
31
+ $exceptionHandler: import("../exception/interface.ts").ExceptionHandler;
32
+ /**
33
+ * Retrieves a raw cookie value.
34
+ *
35
+ * @param {string} key
36
+ * @returns {string|null}
37
+ */
38
+ get(key: string): string | null;
39
+ /**
40
+ * Retrieves a cookie and deserializes its JSON content.
41
+ *
42
+ * @template T
43
+ * @param {string} key
44
+ * @returns {T|null}
45
+ * @throws {SyntaxError} if cookie JSON is invalid
46
+ */
47
+ getObject<T>(key: string): T | null;
48
+ /**
49
+ * Returns an object containing all raw cookies.
50
+ *
51
+ * @returns {Record<string, string>}
52
+ */
53
+ getAll(): Record<string, string>;
54
+ /**
55
+ * Sets a raw cookie value.
56
+ *
57
+ * @param {string} key
58
+ * @param {string} value
59
+ * @param {ng.CookieOptions} [options]
60
+ */
61
+ put(key: string, value: string, options?: ng.CookieOptions): void;
62
+ /**
63
+ * Serializes an object as JSON and stores it as a cookie.
64
+ *
65
+ * @param {string} key
66
+ * @param {any} value
67
+ * @param {ng.CookieOptions} [options]
68
+ * @throws {TypeError} if Object cannot be converted to JSON
69
+ */
70
+ putObject(key: string, value: any, options?: ng.CookieOptions): void;
71
+ /**
72
+ * Removes a cookie by setting an expired date.
73
+ *
74
+ * @param {string} key
75
+ * @param {ng.CookieOptions} [options]
76
+ */
77
+ remove(key: string, options?: ng.CookieOptions): void;
78
+ }
@@ -0,0 +1,12 @@
1
+ export interface CookieOptions {
2
+ path?: string;
3
+ domain?: string;
4
+ expires?: Date | string | number;
5
+ secure?: boolean;
6
+ samesite?: "Lax" | "Strict" | "None";
7
+ }
8
+ export interface CookieStoreOptions {
9
+ serialize?: (value: any) => string;
10
+ deserialize?: (text: string) => any;
11
+ cookie?: CookieOptions;
12
+ }
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Unified exception handler used throughout AngularTS.
3
+ *
4
+ * This service receives uncaught exceptions from both synchronous and asynchronous operations.
5
+ * Its purpose is to provide a central point through which the framework
6
+ * processes errors.
7
+ *
8
+ * By default, `$exceptionHandler` simply rethrows the exception. This ensures fail-fast
9
+ * behavior, making errors visible immediately in development and in unit tests.
10
+ * Applications may override this service to introduce custom error handling.
11
+ *
12
+ * ### Example: Custom `$exceptionHandler`
13
+ *
14
+ * ```js
15
+ * angular
16
+ * .module('app')
17
+ * .factory('$exceptionHandler', function(myLogger) {
18
+ * return function handleError(error) {
19
+ * myLogger.capture(error);
20
+ * // Rethrow to preserve fail-fast behavior:
21
+ * throw error;
22
+ * };
23
+ * });
24
+ * ```
25
+ *
26
+ * IMPORTANT: custom implementation should always rethrow the error as the framework assumes that `$exceptionHandler` always does the throwing.
27
+ *
28
+ * ### Manual Invocation
29
+ *
30
+ * You can invoke the exception handler directly when catching errors in your own code:
31
+ *
32
+ * ```js
33
+ * try {
34
+ * riskyOperation();
35
+ * } catch (err) {
36
+ * $exceptionHandler(err);
37
+ * }
38
+ * ```
39
+ *
40
+ * @see {@link ng.ExceptionHandlerService ExceptionHandlerService}
41
+ */
42
+ /**
43
+ * Provider for the `$exceptionHandler` service.
44
+ *
45
+ * The default implementation rethrows exceptions, enabling strict fail-fast behavior.
46
+ * Applications may replace the handler via by setting `errorHandler`property or by providing their own
47
+ * `$exceptionHandler` factory.
48
+ */
49
+ export class ExceptionHandlerProvider {
50
+ /** @type {ng.ExceptionHandlerService} */
51
+ handler: ng.ExceptionHandlerService;
52
+ /**
53
+ * @returns {ng.ExceptionHandlerService}
54
+ */
55
+ $get(): ng.ExceptionHandlerService;
56
+ }
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * A callback type for handling errors.
3
3
  *
4
- * @param exception - The exception associated with the error.
5
- * @param [cause] - Optional information about the context in which the error was thrown.
4
+ * @param {Error} exception - The exception associated with the error.
6
5
  */
7
- export type ErrorHandler = (exception: Error, cause?: string) => void;
6
+ export type ExceptionHandler = (exception: Error) => void;
@@ -0,0 +1,17 @@
1
+ export interface RestDefinition<T = any> {
2
+ name: string;
3
+ url: string;
4
+ /** Constructor for mapping JSON to class instance */
5
+ entityClass?: EntityClass<T>;
6
+ options?: Record<string, any>;
7
+ }
8
+ /**
9
+ * A constructor type for mapping JSON objects to entity instances
10
+ */
11
+ export interface EntityClass<T = any> {
12
+ /**
13
+ * Creates a new instance of the entity from a raw object
14
+ * @param data - Raw data (typically JSON) to map
15
+ */
16
+ new (data: any): T;
17
+ }
@@ -0,0 +1,110 @@
1
+ /**
2
+ * @template T, ID
3
+ */
4
+ export class RestService<T, ID> {
5
+ static $nonscope: boolean;
6
+ /**
7
+ * Core REST service for CRUD operations.
8
+ * Safe, predictable, and optionally maps raw JSON to entity class instances.
9
+ *
10
+ * @param {ng.HttpService} $http Angular-like $http service
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.)
14
+ */
15
+ constructor(
16
+ $http: ng.HttpService,
17
+ baseUrl: string,
18
+ entityClass?:
19
+ | {
20
+ new (data: any): T;
21
+ }
22
+ | undefined,
23
+ options?: any | undefined,
24
+ );
25
+ /** @private */
26
+ private $http;
27
+ /** @private */
28
+ private baseUrl;
29
+ /** @private */
30
+ private entityClass;
31
+ /** @private */
32
+ private options;
33
+ /**
34
+ * Build full URL from template and parameters
35
+ * @param {string} template
36
+ * @param {Record<string, any>} params
37
+ * @returns {string}
38
+ */
39
+ buildUrl(template: string, params: Record<string, any>): string;
40
+ /**
41
+ * List entities
42
+ * @param {Record<string, any>=} params
43
+ * @returns {Promise<T[]>}
44
+ */
45
+ list(params?: Record<string, any> | undefined): Promise<T[]>;
46
+ /**
47
+ * Read single entity by ID
48
+ * @param {ID} id
49
+ * @param {Record<string, any>=} params
50
+ * @returns {Promise<T|null>}
51
+ */
52
+ read(id: ID, params?: Record<string, any> | undefined): Promise<T | null>;
53
+ /**
54
+ * Create a new entity
55
+ * @param {T} item
56
+ * @returns {Promise<T>}
57
+ */
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;
73
+ }
74
+ /**
75
+ * Provider for registering REST endpoints during module configuration.
76
+ */
77
+ export class RestProvider {
78
+ /** @private @type {ng.RestDefinition<any>[]} */
79
+ private definitions;
80
+ /**
81
+ * Register a REST resource at config phase
82
+ * @template T
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
87
+ */
88
+ rest<T>(
89
+ name: string,
90
+ url: string,
91
+ entityClass?:
92
+ | {
93
+ new (data: any): T;
94
+ }
95
+ | undefined,
96
+ options?: any | undefined,
97
+ ): void;
98
+ /**
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[] }}
101
+ */
102
+ $get: (
103
+ | string
104
+ | (($http: any) => {
105
+ (baseUrl: any, entityClass: any, options?: {}): RestService<any, any>;
106
+ get(name: any): any;
107
+ listNames(): any[];
108
+ })
109
+ )[];
110
+ }