@ngx-pwa/local-storage 18.0.0 → 20.0.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.
Files changed (40) hide show
  1. package/LICENSE +1 -1
  2. package/fesm2022/ngx-pwa-local-storage.mjs +89 -63
  3. package/fesm2022/ngx-pwa-local-storage.mjs.map +1 -1
  4. package/index.d.ts +656 -3
  5. package/package.json +3 -5
  6. package/schematics/ng-add/index.js +9 -9
  7. package/schematics/ng-add/index.js.map +1 -1
  8. package/schematics/ng-update/index.js +14 -24
  9. package/schematics/ng-update/index.js.map +1 -1
  10. package/schematics/utility/config.js +24 -34
  11. package/schematics/utility/config.js.map +1 -1
  12. package/schematics/utility/module.js +3 -3
  13. package/schematics/utility/module.js.map +1 -1
  14. package/esm2022/lib/databases/exceptions.mjs +0 -28
  15. package/esm2022/lib/databases/indexeddb-database.mjs +0 -308
  16. package/esm2022/lib/databases/local-database.mjs +0 -66
  17. package/esm2022/lib/databases/localstorage-database.mjs +0 -158
  18. package/esm2022/lib/databases/memory-database.mjs +0 -84
  19. package/esm2022/lib/providers.mjs +0 -66
  20. package/esm2022/lib/storage.module.mjs +0 -34
  21. package/esm2022/lib/storages/exceptions.mjs +0 -15
  22. package/esm2022/lib/storages/storage-map.service.mjs +0 -340
  23. package/esm2022/lib/tokens.mjs +0 -59
  24. package/esm2022/lib/validation/json-schema.mjs +0 -5
  25. package/esm2022/lib/validation/json-validator.mjs +0 -244
  26. package/esm2022/ngx-pwa-local-storage.mjs +0 -5
  27. package/esm2022/public-api.mjs +0 -9
  28. package/lib/databases/exceptions.d.ts +0 -20
  29. package/lib/databases/indexeddb-database.d.ts +0 -107
  30. package/lib/databases/local-database.d.ts +0 -18
  31. package/lib/databases/localstorage-database.d.ts +0 -64
  32. package/lib/databases/memory-database.d.ts +0 -50
  33. package/lib/providers.d.ts +0 -56
  34. package/lib/storage.module.d.ts +0 -19
  35. package/lib/storages/exceptions.d.ts +0 -10
  36. package/lib/storages/storage-map.service.d.ts +0 -254
  37. package/lib/tokens.d.ts +0 -75
  38. package/lib/validation/json-schema.d.ts +0 -260
  39. package/lib/validation/json-validator.d.ts +0 -71
  40. package/public-api.d.ts +0 -7
@@ -1,56 +0,0 @@
1
- import { type EnvironmentProviders } from "@angular/core";
2
- /**
3
- * Allows to add a prefix before `localStorage` keys.
4
- *
5
- * *Use only* for interoperability with other APIs or to avoid collision for multiple applications on the same subdomain.
6
- *
7
- * **WARNING: do not change this option in an application already deployed in production, as previously stored data would be lost.**
8
- *
9
- * @example
10
- * export const appConfig: ApplicationConfig = {
11
- * providers: [provideLocalStoragePrefix('custom_')]
12
- * };
13
- */
14
- export declare function provideLocalStoragePrefix(prefix: string): EnvironmentProviders;
15
- /**
16
- * Allows to change the name used for `indexedDB` database.
17
- *
18
- * *Use only* for interoperability with other APIs or to avoid collision for multiple applications on the same subdomain.
19
- *
20
- * **WARNING: do not change this option in an application already deployed in production, as previously stored data would be lost.**
21
- *
22
- * @example
23
- * export const appConfig: ApplicationConfig = {
24
- * providers: [provideIndexedDBDataBaseName('custom')]
25
- * };
26
- */
27
- export declare function provideIndexedDBDataBaseName(name: string): EnvironmentProviders;
28
- /**
29
- * Allows to change the database version used for `indexedDB` database.
30
- * Must be an unsigned **integer**.
31
- *
32
- * **Use with caution as the creation of the store depends on the version.**
33
- *
34
- * *Use only* for interoperability with other APIs or to avoid collision for multiple applications on the same subdomain.
35
- *
36
- * **WARNING: do not change this option in an applicattion already deployed in production, as previously stored data would be lost.**
37
- *
38
- * @example
39
- * export const appConfig: ApplicationConfig = {
40
- * providers: [provideIndexedDBDataBaseVersion(2)]
41
- * };
42
- */
43
- export declare function provideIndexedDBDataBaseVersion(version: number): EnvironmentProviders;
44
- /**
45
- * Allows to change the name used for `indexedDB` object store.
46
- *
47
- * *Use only* for interoperability with other APIs.
48
- *
49
- * **WARNING: do not change this option in an application already deployed in production, as previously stored data would be lost.**
50
- *
51
- * @example
52
- * export const appConfig: ApplicationConfig = {
53
- * providers: [provideIndexedDBStoreName('custom')]
54
- * };
55
- */
56
- export declare function provideIndexedDBStoreName(name: string): EnvironmentProviders;
@@ -1,19 +0,0 @@
1
- import { type ModuleWithProviders } from "@angular/core";
2
- import { type StorageConfig } from "./tokens";
3
- import * as i0 from "@angular/core";
4
- /**
5
- * This module is only here for backward compatibility, **do not add it by yourself**
6
- *
7
- * @ignore
8
- */
9
- export declare class StorageModule {
10
- /**
11
- * Only useful to provide options, otherwise it does nothing.
12
- *
13
- * **Must be used at initialization, ie. in `AppModule`, and must not be loaded again in another module.**
14
- */
15
- static forRoot(config: StorageConfig): ModuleWithProviders<StorageModule>;
16
- static ɵfac: i0.ɵɵFactoryDeclaration<StorageModule, never>;
17
- static ɵmod: i0.ɵɵNgModuleDeclaration<StorageModule, never, never, never>;
18
- static ɵinj: i0.ɵɵInjectorDeclaration<StorageModule>;
19
- }
@@ -1,10 +0,0 @@
1
- /**
2
- * Exception message when a value is not valid against the JSON schema
3
- */
4
- export declare const VALIDATION_ERROR = "Data stored is not valid against the provided JSON schema.\nCheck your JSON schema, otherwise it means data has been corrupted.";
5
- /**
6
- * Exception throwned when a value is not valid against the JSON schema
7
- */
8
- export declare class ValidationError extends Error {
9
- message: string;
10
- }
@@ -1,254 +0,0 @@
1
- import { Observable } from "rxjs";
2
- import { LocalDatabase } from "../databases/local-database";
3
- import type { JSONSchema, JSONSchemaArrayOf, JSONSchemaBoolean, JSONSchemaInteger, JSONSchemaNumber, JSONSchemaString } from "../validation/json-schema";
4
- import * as i0 from "@angular/core";
5
- export declare class StorageMap {
6
- #private;
7
- /**
8
- * Constructor params are provided by Angular (but can also be passed manually in tests)
9
- * @param database Storage to use
10
- */
11
- constructor(database: LocalDatabase);
12
- /**
13
- * **Number of items** in storage, wrapped in an Observable.
14
- *
15
- * Note you do *not* need to unsubscribe (it is a self-completing Observable).
16
- *
17
- * @example
18
- * this.storageMap.size.subscribe((size) => {
19
- * console.log(size);
20
- * });
21
- */
22
- get size(): Observable<number>;
23
- /**
24
- * Tells you which storage engine is used.
25
- *
26
- * *Only useful for interoperability.*
27
- *
28
- * Note that due to some browsers issues in some special contexts
29
- * (like Safari cross-origin iframes),
30
- * **this information may be wrong at initialization,**
31
- * as the storage could fallback from `indexedDB` to `localStorage`
32
- * only after a first read or write operation.
33
- * @returns Storage engine used
34
- *
35
- * @see {@link https://github.com/cyrilletuzi/angular-async-local-storage/blob/main/docs/INTEROPERABILITY.md}
36
- *
37
- * @example
38
- * if (this.storageMap.backingEngine === 'indexedDB') {}
39
- */
40
- get backingEngine(): "indexedDB" | "localStorage" | "memory" | "unknown";
41
- /**
42
- * Information about `indexedDB` database.
43
- *
44
- * *Only useful for interoperability.*
45
- *
46
- * @returns `indexedDB` database name, store name and database version.
47
- * **Values will be empty if the storage is not `indexedDB`, so it should be used after an engine check**.
48
- *
49
- * @see {@link https://github.com/cyrilletuzi/angular-async-local-storage/blob/main/docs/INTEROPERABILITY.md}
50
- *
51
- * @example
52
- * if (this.storageMap.backingEngine === 'indexedDB') {
53
- * const { database, store, version } = this.storageMap.backingStore;
54
- * }
55
- */
56
- get backingStore(): {
57
- database: string;
58
- store: string;
59
- version: number;
60
- };
61
- /**
62
- * Information about `localStorage` fallback storage.
63
- *
64
- * *Only useful for interoperability.*
65
- *
66
- * @returns `localStorage` prefix.
67
- * **Values will be empty if the storage is not `localStorage`, so it should be used after an engine check**.
68
- *
69
- * @see {@link https://github.com/cyrilletuzi/angular-async-local-storage/blob/main/docs/INTEROPERABILITY.md}
70
- *
71
- * @example
72
- * if (this.storageMap.backingEngine === 'localStorage') {
73
- * const { prefix } = this.storageMap.fallbackBackingStore;
74
- * }
75
- */
76
- get fallbackBackingStore(): {
77
- prefix: string;
78
- };
79
- /**
80
- * Get an item value in storage.
81
- *
82
- * Note that:
83
- * * not finding an item is not an error, it succeeds but returns `undefined`,
84
- * * you do *not* need to unsubscribe (it is a self-completing Observable),
85
- * * you will only get *one* value: the Observable is here for asynchrony but is *not* meant to emit again when the stored data is changed. If you need to watch the value, see the `watch` method.
86
- *
87
- * Do not forget it is client-side storage: **always check the data**, as it could have been forged.
88
- * @see {@link https://github.com/cyrilletuzi/angular-async-local-storage/blob/main/docs/VALIDATION.md}
89
- *
90
- * @param key The item's key
91
- * @param schema Optional but recommended JSON schema to validate the data
92
- * @returns The item's value if the key exists, `undefined` otherwise, wrapped in a RxJS Observable
93
- *
94
- * @example
95
- * this.storageMap.get('key', { type: 'string' }).subscribe((result) => {
96
- * result; // string or undefined
97
- * });
98
- *
99
- * @example
100
- * interface User {
101
- * firstName: string;
102
- * lastName?: string;
103
- * }
104
- *
105
- * const schema = {
106
- * type: 'object',
107
- * properties: {
108
- * firstName: { type: 'string' },
109
- * lastName: { type: 'string' },
110
- * },
111
- * required: ['firstName'],
112
- * } satisfies JSONSchema;
113
- *
114
- * this.storageMap.get<User>('user', schema).subscribe((user) => {
115
- * if (user) {
116
- * user.firstName;
117
- * }
118
- * });
119
- */
120
- get(key: string): Observable<unknown>;
121
- get<T extends string = string>(key: string, schema: JSONSchemaString): Observable<T | undefined>;
122
- get<T extends number = number>(key: string, schema: JSONSchemaInteger | JSONSchemaNumber): Observable<T | undefined>;
123
- get<T extends boolean = boolean>(key: string, schema: JSONSchemaBoolean): Observable<T | undefined>;
124
- get<T extends readonly string[] = string[]>(key: string, schema: JSONSchemaArrayOf<JSONSchemaString>): Observable<T | undefined>;
125
- get<T extends readonly number[] = number[]>(key: string, schema: JSONSchemaArrayOf<JSONSchemaInteger | JSONSchemaNumber>): Observable<T | undefined>;
126
- get<T extends readonly boolean[] = boolean[]>(key: string, schema: JSONSchemaArrayOf<JSONSchemaBoolean>): Observable<T | undefined>;
127
- get<T>(key: string, schema: JSONSchema): Observable<T | undefined>;
128
- /**
129
- * Store an item in storage.
130
- *
131
- * Note that:
132
- * * you *do* need to subscribe, even if you do not have something specific to do after writing in storage, otherwise nothing happens (because it is how RxJS Observables work),
133
- * * but you do *not* need to unsubscribe (it is a self-completing Observable),
134
- * * setting `null` or `undefined` will remove the item to avoid some browsers issues,
135
- * * you should stick to serializable JSON data, meaning primitive types, arrays and literal objects. Date, Map, Set, Blob and other special structures can cause issues in some scenarios.
136
- * @see {@link https://github.com/cyrilletuzi/angular-async-local-storage/blob/main/docs/SERIALIZATION.md}
137
- *
138
- * @param key The item's key
139
- * @param data The item's value
140
- * @param schema Optional JSON schema to validate the data
141
- * @returns A RxJS Observable to wait the end of the operation
142
- *
143
- * @example
144
- * this.storageMap.set('key', 'value').subscribe(() => {});
145
- */
146
- set(key: string, data: unknown, schema?: JSONSchema): Observable<undefined>;
147
- /**
148
- * Delete an item in storage.
149
- *
150
- * Note that:
151
- * * you *do* need to subscribe, even if you do not have something specific to do after deleting, otherwise nothing happens (because it is how RxJS Observables work),
152
- * * but you do *not* need to unsubscribe (it is a self-completing Observable).
153
- *
154
- * @param key The item's key
155
- * @returns A RxJS Observable to wait the end of the operation
156
- *
157
- * @example
158
- * this.storageMap.delete('key').subscribe(() => {});
159
- */
160
- delete(key: string): Observable<undefined>;
161
- /**
162
- * Delete all items in storage.
163
- *
164
- * Note that:
165
- * * you *do* need to subscribe, even if you do not have something specific to do after clearing, otherwise nothing happens (because it is how RxJS Observables work),
166
- * * but you do *not* need to unsubscribe (it is a self-completing Observable).
167
- *
168
- * @returns A RxJS Observable to wait the end of the operation
169
- *
170
- * @example
171
- * this.storageMap.clear().subscribe(() => {});
172
- */
173
- clear(): Observable<undefined>;
174
- /**
175
- * Get all keys stored in storage.
176
- *
177
- * Note **this is an *iterating* Observable**:
178
- * * if there is no key, the `next` callback will not be invoked,
179
- * * if you need to wait the whole operation to end, be sure to act in the `complete` callback,
180
- * as this Observable can emit several values and so will invoke the `next` callback several times,
181
- * * you do *not* need to unsubscribe (it is a self-completing Observable).
182
- *
183
- * @returns A list of the keys wrapped in a RxJS Observable
184
- *
185
- * @example
186
- * this.storageMap.keys().subscribe({
187
- * next: (key) => { console.log(key); },
188
- * complete: () => { console.log('Done'); },
189
- * });
190
- */
191
- keys(): Observable<string>;
192
- /**
193
- * Tells if a key exists in storage.
194
- *
195
- * Note you do *not* need to unsubscribe (it is a self-completing Observable).
196
- *
197
- * @returns A RxJS Observable telling if the key exists
198
- *
199
- * @example
200
- * this.storageMap.has('key').subscribe((hasKey) => {
201
- * if (hasKey) {}
202
- * });
203
- */
204
- has(key: string): Observable<boolean>;
205
- /**
206
- * Watch an item value in storage.
207
- *
208
- * Note that:
209
- * * it is an infinite Observable, do not forget to unsubscribe,
210
- * * only changes done via this library will be watched, external changes in storage cannot be detected.
211
- *
212
- * The signature has many overloads due to validation, **please refer to the documentation.**
213
- * @see https://github.com/cyrilletuzi/angular-async-local-storage/blob/main/docs/VALIDATION.md
214
- *
215
- * @param key The item's key to watch
216
- * @param schema Optional JSON schema to validate the initial value
217
- * @returns An infinite Observable giving the current value
218
- *
219
- * @example
220
- * Component()
221
- * export class MyComponent implements OnInit, OnDestroy {
222
- *
223
- * private storageSubscription?: Subscription;
224
- *
225
- * ngOnInit(): void {
226
- * this.storageSubscription = this.storageMap.watch('key', { type: 'string' }).subscribe((result) => {
227
- * result; // string or undefined
228
- * });
229
- * }
230
- *
231
- * ngOnDestroy(): void {
232
- * this.storageSubscription?.unsubscribe();
233
- * }
234
- *
235
- * }
236
- */
237
- watch(key: string): Observable<unknown>;
238
- watch<T extends string = string>(key: string, schema: JSONSchemaString): Observable<T | undefined>;
239
- watch<T extends number = number>(key: string, schema: JSONSchemaInteger | JSONSchemaNumber): Observable<T | undefined>;
240
- watch<T extends boolean = boolean>(key: string, schema: JSONSchemaBoolean): Observable<T | undefined>;
241
- watch<T extends readonly string[] = string[]>(key: string, schema: JSONSchemaArrayOf<JSONSchemaString>): Observable<T | undefined>;
242
- watch<T extends readonly number[] = number[]>(key: string, schema: JSONSchemaArrayOf<JSONSchemaInteger | JSONSchemaNumber>): Observable<T | undefined>;
243
- watch<T extends readonly boolean[] = boolean[]>(key: string, schema: JSONSchemaArrayOf<JSONSchemaBoolean>): Observable<T | undefined>;
244
- watch<T>(key: string, schema: JSONSchema): Observable<T | undefined>;
245
- /**
246
- * THIS METHOD IS FOR INTERNAL PURPOSE ONLY AND MUST NOT BE USED,
247
- * IT CAN BE REMOVED AT ANY TIME AND MESSING WITH IT CAN CAUSE ISSUES
248
- * @private
249
- * @ignore
250
- */
251
- private ɵinternalGetDatabase;
252
- static ɵfac: i0.ɵɵFactoryDeclaration<StorageMap, never>;
253
- static ɵprov: i0.ɵɵInjectableDeclaration<StorageMap>;
254
- }
package/lib/tokens.d.ts DELETED
@@ -1,75 +0,0 @@
1
- import { InjectionToken } from "@angular/core";
2
- /**
3
- * Token to provide a prefix to `localStorage` keys.
4
- */
5
- export declare const LS_PREFIX: InjectionToken<string>;
6
- /**
7
- * Default name used for `indexedDB` database.
8
- */
9
- export declare const DEFAULT_IDB_DB_NAME = "ngStorage";
10
- /**
11
- * Token to provide `indexedDB` database name.
12
- */
13
- export declare const IDB_DB_NAME: InjectionToken<string>;
14
- /**
15
- * Default version used for `indexedDB` database.
16
- */
17
- export declare const DEFAULT_IDB_DB_VERSION = 1;
18
- /**
19
- * Token to provide `indexedDB` database version.
20
- * Must be an unsigned **integer**.
21
- */
22
- export declare const IDB_DB_VERSION: InjectionToken<number>;
23
- /**
24
- * Default name used for `indexedDB` object store.
25
- */
26
- export declare const DEFAULT_IDB_STORE_NAME = "localStorage";
27
- /**
28
- * Token to provide `indexedDB` store name.
29
- * For backward compatibility, the default can't be set now, `IndexedDBDatabase` will do it at runtime.
30
- */
31
- export declare const IDB_STORE_NAME: InjectionToken<string>;
32
- /**
33
- * Default value for interoperability with native `indexedDB` and other storage libs,
34
- * by changing how values are stored in `indexedDB` database.
35
- */
36
- export declare const DEFAULT_IDB_NO_WRAP = true;
37
- /**
38
- * Token to allow interoperability with native `indexedDB` and other storage libs,
39
- * by changing how values are stored in `indexedDB` database.
40
- * Defaults to `true`. Change to `false` for backward compatiblity in existing applications.
41
- * **DO NOT CHANGE THIS BEHAVIOR ONCE IN PRODUCTION**, as it would break with existing data.
42
- */
43
- export declare const IDB_NO_WRAP: InjectionToken<boolean>;
44
- /**
45
- * This interface is only here for backward compatibility, **do not add it by yourself**
46
- *
47
- * @ignore
48
- */
49
- export interface StorageConfig {
50
- /**
51
- * @deprecated Use `provideLocalStoragePrefix()` method instead
52
- */
53
- LSPrefix?: string;
54
- /**
55
- * @deprecated Use `provideIndexedDBDataBaseName()` method instead
56
- */
57
- IDBDBName?: string;
58
- /**
59
- * @deprecated Use `provideIndexedDBStoreName()` method instead
60
- */
61
- IDBStoreName?: string;
62
- /**
63
- * @deprecated Use `provideIndexedDBDataBaseVersion()` method instead
64
- */
65
- IDBDBVersion?: number;
66
- /**
67
- * Allows interoperability with native `indexedDB` and other storage libs,
68
- * by changing how values are stored in `indexedDB` database.
69
- *
70
- * Defaults to `true`. Change to `false` for backward compatiblity in existing applications.
71
- *
72
- * **DO NOT CHANGE THIS BEHAVIOR ONCE IN PRODUCTION**, as it would break with existing data.
73
- */
74
- IDBNoWrap?: boolean;
75
- }
@@ -1,260 +0,0 @@
1
- /**
2
- * JSON Schema to describe a boolean value.
3
- */
4
- export interface JSONSchemaBoolean {
5
- /**
6
- * Type for a boolean value.
7
- */
8
- type: "boolean";
9
- /**
10
- * Checks if a value is strictly equal to this.
11
- */
12
- const?: boolean;
13
- }
14
- /**
15
- * JSON Schema to describe a number value.
16
- */
17
- export interface JSONSchemaNumber {
18
- /**
19
- * Type for a numeric value.
20
- */
21
- type: "number";
22
- /**
23
- * Checks if a value is strictly equal to this.
24
- */
25
- const?: number;
26
- /**
27
- * Checks if a value is strictly equal to one of the value of enum.
28
- */
29
- enum?: readonly number[];
30
- /**
31
- * Check if a number is a multiple of x.
32
- * Must be strictly greater than 0.
33
- */
34
- multipleOf?: number;
35
- /**
36
- * Check if a number is lower or equal than this maximum.
37
- */
38
- maximum?: number;
39
- /**
40
- * Check if a number is strictly lower than this maximum.
41
- */
42
- exclusiveMaximum?: number;
43
- /**
44
- * Check if a number is greater or equal than this minimum.
45
- */
46
- minimum?: number;
47
- /**
48
- * Check if a number is strictly greater than this minimum.
49
- */
50
- exclusiveMinimum?: number;
51
- }
52
- /**
53
- * JSON Schema to describe an integer value.
54
- */
55
- export interface JSONSchemaInteger {
56
- /**
57
- * Type for an integer value.
58
- */
59
- type: "integer";
60
- /**
61
- * Checks if a value is strictly equal to this.
62
- */
63
- const?: number;
64
- /**
65
- * Checks if a value is strictly equal to one of the value of enum.
66
- */
67
- enum?: readonly number[];
68
- /**
69
- * Check if a number is a multiple of x.
70
- * Must be strictly greater than 0.
71
- */
72
- multipleOf?: number;
73
- /**
74
- * Check if a number is lower or equal than this maximum.
75
- */
76
- maximum?: number;
77
- /**
78
- * Check if a number is strictly lower than this maximum.
79
- */
80
- exclusiveMaximum?: number;
81
- /**
82
- * Check if a number is greater or equal than this minimum.
83
- */
84
- minimum?: number;
85
- /**
86
- * Check if a number is strictly greater than this minimum.
87
- */
88
- exclusiveMinimum?: number;
89
- }
90
- /**
91
- * JSON Schema to describe a string value.
92
- */
93
- export interface JSONSchemaString {
94
- /**
95
- * Type for a string value.
96
- */
97
- type: "string";
98
- /**
99
- * Checks if a value is strictly equal to this.
100
- */
101
- const?: string;
102
- /**
103
- * Checks if a value is strictly equal to one of the value of enum.
104
- */
105
- enum?: readonly string[];
106
- /**
107
- * Maxium length for a string.
108
- * Must be a non-negative integer.
109
- */
110
- maxLength?: number;
111
- /**
112
- * Minimum length for a string.
113
- * Must be a non-negative integer.
114
- */
115
- minLength?: number;
116
- /**
117
- * Pattern to match for a string.
118
- * Must be a valid regular expression, *without* the `/` delimiters.
119
- */
120
- pattern?: string;
121
- }
122
- /**
123
- * JSON schema to describe an array of values.
124
- */
125
- export interface JSONSchemaArray {
126
- /**
127
- * Type for an array of values.
128
- */
129
- type: "array";
130
- /**
131
- * Schema for the values of the array.
132
- */
133
- items: JSONSchema;
134
- /**
135
- * Check if an array length is lower or equal to this value.
136
- * Must be a non negative integer.
137
- */
138
- maxItems?: number;
139
- /**
140
- * Check if an array length is greater or equal to this value.
141
- * Must be a non negative integer.
142
- */
143
- minItems?: number;
144
- /**
145
- * Check if an array only have unique values.
146
- */
147
- uniqueItems?: boolean;
148
- }
149
- /**
150
- * JSON Schema to describe an array of primitive values:
151
- * - array of booleans: `JSONSchemaArrayOf<JSONSchemaBoolean>`,
152
- * - array of numbers: `JSONSchemaArrayOf<JSONSchemaNumber>`,
153
- * - array of integers: `JSONSchemaArrayOf<JSONSchemaInteger>`,
154
- * - array of strings: `JSONSchemaArrayOf<JSONSchemaString>`.
155
- */
156
- export interface JSONSchemaArrayOf<T extends JSONSchemaBoolean | JSONSchemaNumber | JSONSchemaInteger | JSONSchemaString> {
157
- /**
158
- * Type for an array of values.
159
- */
160
- type: "array";
161
- /**
162
- * Schema for the values of an array.
163
- */
164
- items: T;
165
- /**
166
- * Check if an array length is lower or equal to this value.
167
- * Must be a non negative integer.
168
- */
169
- maxItems?: number;
170
- /**
171
- * Check if an array length is greater or equal to this value.
172
- * Must be a non negative integer.
173
- */
174
- minItems?: number;
175
- /**
176
- * Check if an array only have unique values.
177
- */
178
- uniqueItems?: boolean;
179
- }
180
- /**
181
- * JSON schema to describe a tuple.
182
- */
183
- export interface JSONSchemaTuple {
184
- /**
185
- * Type for an array of values.
186
- */
187
- type: "array";
188
- /**
189
- * Schema for the values of the tuple.
190
- */
191
- items?: readonly JSONSchema[];
192
- /**
193
- * Check if an array length is lower or equal to this value.
194
- * Must be a non negative integer.
195
- */
196
- maxItems?: number;
197
- /**
198
- * Check if an array length is greater or equal to this value.
199
- * Must be a non negative integer.
200
- */
201
- minItems?: number;
202
- /**
203
- * Check if an array only have unique values.
204
- */
205
- uniqueItems?: boolean;
206
- }
207
- /**
208
- * JSON schema to describe an object.
209
- */
210
- export interface JSONSchemaObject {
211
- /**
212
- * Type for an object.
213
- */
214
- type: "object";
215
- /**
216
- * List of properties of the object and their associated JSON schemas.
217
- */
218
- properties: Record<string, JSONSchema>;
219
- /**
220
- * Array of names of the required properties for an object.
221
- * Properties set as required should be present in `properties` too.
222
- */
223
- required?: readonly string[];
224
- }
225
- /**
226
- * Subset of the JSON Schema standard.
227
- *
228
- * Types are enforced to validate everything: each value **must** have a `type`.
229
- *
230
- * @see {@link https://github.com/cyrilletuzi/angular-async-local-storage/blob/main/docs/VALIDATION.md}
231
- *
232
- * @example
233
- * const schema = { type: 'string' } satisfies JSONSchema;
234
- *
235
- * @example
236
- * const schema = { type: 'number' } satisfies JSONSchema;
237
- *
238
- * @example
239
- * const schema = { type: 'integer' } satisfies JSONSchema;
240
- *
241
- * @example
242
- * const schema = { type: 'boolean' } satisfies JSONSchema;
243
- *
244
- * @example
245
- * const schema = {
246
- * type: 'array',
247
- * items: { type: 'string' },
248
- * } satisfies JSONSchema;
249
- *
250
- * @example
251
- * const schema = {
252
- * type: 'object',
253
- * properties: {
254
- * firstName: { type: 'string' },
255
- * lastName: { type: 'string' },
256
- * },
257
- * required: ['firstName'],
258
- * } satisfies JSONSchema;
259
- */
260
- export type JSONSchema = JSONSchemaString | JSONSchemaNumber | JSONSchemaInteger | JSONSchemaBoolean | JSONSchemaArray | JSONSchemaTuple | JSONSchemaObject;