@rdlabo/ionic-angular-kit 21.5.19 → 21.5.21

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.
@@ -0,0 +1,56 @@
1
+ import * as i0 from '@angular/core';
2
+ import { inject, ApplicationRef, Injectable, makeEnvironmentProviders, provideEnvironmentInitializer } from '@angular/core';
3
+ import { DOCUMENT } from '@angular/common';
4
+ import { SwUpdate } from '@angular/service-worker';
5
+ import { filter, first } from 'rxjs';
6
+
7
+ /** Checks for and activates a complete Angular service-worker update when the application starts. */
8
+ class KitAppUpdateService {
9
+ #applicationRef = inject(ApplicationRef);
10
+ #document = inject(DOCUMENT);
11
+ #updates = inject(SwUpdate);
12
+ #started = false;
13
+ /** Starts one non-blocking update check after Angular reports the application as stable. */
14
+ start() {
15
+ if (this.#started || !this.#updates.isEnabled) {
16
+ return;
17
+ }
18
+ this.#started = true;
19
+ this.#applicationRef.isStable
20
+ .pipe(filter((stable) => stable), first())
21
+ .subscribe(() => void this.#activateUpdate());
22
+ }
23
+ async #activateUpdate() {
24
+ try {
25
+ if (!(await this.#updates.checkForUpdate())) {
26
+ return;
27
+ }
28
+ await this.#updates.activateUpdate();
29
+ this.#document.location?.reload();
30
+ }
31
+ catch (error) {
32
+ console.error('Angular service-worker update check failed', error);
33
+ }
34
+ }
35
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: KitAppUpdateService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
36
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: KitAppUpdateService, providedIn: 'root' }); }
37
+ }
38
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: KitAppUpdateService, decorators: [{
39
+ type: Injectable,
40
+ args: [{ providedIn: 'root' }]
41
+ }] });
42
+ /** Provides a startup check that activates and reloads into the latest complete web application version. */
43
+ function provideKitAppUpdate() {
44
+ return makeEnvironmentProviders([
45
+ provideEnvironmentInitializer(() => inject(KitAppUpdateService).start()),
46
+ ]);
47
+ }
48
+
49
+ /** Automatic startup updates for Angular service-worker web applications. */
50
+
51
+ /**
52
+ * Generated bundle index. Do not edit.
53
+ */
54
+
55
+ export { KitAppUpdateService, provideKitAppUpdate };
56
+ //# sourceMappingURL=rdlabo-ionic-angular-kit-app-update.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rdlabo-ionic-angular-kit-app-update.mjs","sources":["../../../projects/kit/app-update/src/lib/kit-app-update.provider.ts","../../../projects/kit/app-update/src/public-api.ts","../../../projects/kit/app-update/src/rdlabo-ionic-angular-kit-app-update.ts"],"sourcesContent":["import type { EnvironmentProviders } from '@angular/core';\nimport {\n ApplicationRef,\n Injectable,\n inject,\n makeEnvironmentProviders,\n provideEnvironmentInitializer,\n} from '@angular/core';\nimport { DOCUMENT } from '@angular/common';\nimport { SwUpdate } from '@angular/service-worker';\nimport { filter, first } from 'rxjs';\n\n/** Checks for and activates a complete Angular service-worker update when the application starts. */\n@Injectable({ providedIn: 'root' })\nexport class KitAppUpdateService {\n readonly #applicationRef = inject(ApplicationRef);\n readonly #document = inject(DOCUMENT);\n readonly #updates = inject(SwUpdate);\n #started = false;\n\n /** Starts one non-blocking update check after Angular reports the application as stable. */\n start(): void {\n if (this.#started || !this.#updates.isEnabled) {\n return;\n }\n this.#started = true;\n this.#applicationRef.isStable\n .pipe(\n filter((stable) => stable),\n first(),\n )\n .subscribe(() => void this.#activateUpdate());\n }\n\n async #activateUpdate(): Promise<void> {\n try {\n if (!(await this.#updates.checkForUpdate())) {\n return;\n }\n await this.#updates.activateUpdate();\n this.#document.location?.reload();\n } catch (error) {\n console.error('Angular service-worker update check failed', error);\n }\n }\n}\n\n/** Provides a startup check that activates and reloads into the latest complete web application version. */\nexport function provideKitAppUpdate(): EnvironmentProviders {\n return makeEnvironmentProviders([\n provideEnvironmentInitializer(() => inject(KitAppUpdateService).start()),\n ]);\n}\n","/** Automatic startup updates for Angular service-worker web applications. */\nexport * from './lib/kit-app-update.provider';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;AAYA;MAEa,mBAAmB,CAAA;AACrB,IAAA,eAAe,GAAG,MAAM,CAAC,cAAc,CAAC;AACxC,IAAA,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC;AAC5B,IAAA,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;IACpC,QAAQ,GAAG,KAAK;;IAGhB,KAAK,GAAA;QACH,IAAI,IAAI,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE;YAC7C;QACF;AACA,QAAA,IAAI,CAAC,QAAQ,GAAG,IAAI;QACpB,IAAI,CAAC,eAAe,CAAC;AAClB,aAAA,IAAI,CACH,MAAM,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,EAC1B,KAAK,EAAE;aAER,SAAS,CAAC,MAAM,KAAK,IAAI,CAAC,eAAe,EAAE,CAAC;IACjD;AAEA,IAAA,MAAM,eAAe,GAAA;AACnB,QAAA,IAAI;YACF,IAAI,EAAE,MAAM,IAAI,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC,EAAE;gBAC3C;YACF;AACA,YAAA,MAAM,IAAI,CAAC,QAAQ,CAAC,cAAc,EAAE;AACpC,YAAA,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE;QACnC;QAAE,OAAO,KAAK,EAAE;AACd,YAAA,OAAO,CAAC,KAAK,CAAC,4CAA4C,EAAE,KAAK,CAAC;QACpE;IACF;+GA9BW,mBAAmB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA,CAAA;AAAnB,IAAA,SAAA,IAAA,CAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,SAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,mBAAmB,cADN,MAAM,EAAA,CAAA,CAAA;;4FACnB,mBAAmB,EAAA,UAAA,EAAA,CAAA;kBAD/B,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE;;AAkClC;SACgB,mBAAmB,GAAA;AACjC,IAAA,OAAO,wBAAwB,CAAC;QAC9B,6BAA6B,CAAC,MAAM,MAAM,CAAC,mBAAmB,CAAC,CAAC,KAAK,EAAE,CAAC;AACzE,KAAA,CAAC;AACJ;;ACpDA;;ACAA;;AAEG;;;;"}
@@ -665,6 +665,11 @@ function normalizeOfflineReplicaMigrations(migrations, bundleVersion) {
665
665
  if (sorted.length > 0 && sorted[0].fromVersion !== 1) {
666
666
  throw new Error(`Replica migrations must advance consecutive schema versions; expected fromVersion 1, received ${sorted[0].fromVersion}.`);
667
667
  }
668
+ const finalRequiredFromVersion = bundleVersion - 1;
669
+ if (finalRequiredFromVersion > 0 && sorted.at(-1)?.fromVersion !== finalRequiredFromVersion) {
670
+ const firstMissingVersion = (sorted.at(-1)?.fromVersion ?? 0) + 1;
671
+ throw new Error(`Missing offline replica schema migration from version ${firstMissingVersion} to ${firstMissingVersion + 1}.`);
672
+ }
668
673
  return sorted;
669
674
  }
670
675
  function buildBundleSchemaFingerprintInput(version, entities, migrations) {