@contello/astro 1.4.0 → 1.4.1

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/dist/index.cjs CHANGED
@@ -87,6 +87,7 @@ var Contello = class {
87
87
  _routes;
88
88
  _i18nMessages;
89
89
  _i18nSubscription;
90
+ _initialized = false;
90
91
  _als = new import_node_async_hooks.AsyncLocalStorage();
91
92
  media;
92
93
  constructor(options) {
@@ -101,31 +102,39 @@ var Contello = class {
101
102
  }
102
103
  // --- lifecycle ---
103
104
  async init(options) {
104
- await this._store.init();
105
- this._assets = this._store.defineAssets(this._options.assets);
106
- this._routes = this._store.defineRoutes(this._options.routes);
107
- if (this._options.i18n) {
108
- const { collection, languages } = this._options.i18n;
109
- const { register = true, load = true } = options?.i18n ?? {};
110
- this._i18nMessages = this._store.defineI18nMessages({ collection });
111
- await import_i18n.i18n.configure({ locales: languages });
112
- if (register) {
113
- const registrations = buildI18nRegistrations();
114
- if (registrations.length > 0) {
115
- await this._i18nMessages.register(registrations);
105
+ try {
106
+ await this._store.init();
107
+ this._assets = this._store.defineAssets(this._options.assets);
108
+ this._routes = this._store.defineRoutes(this._options.routes);
109
+ if (this._options.i18n) {
110
+ const { collection, languages } = this._options.i18n;
111
+ const { register = true, load = true } = options?.i18n ?? {};
112
+ this._i18nMessages = this._store.defineI18nMessages({ collection });
113
+ await import_i18n.i18n.configure({ locales: languages });
114
+ if (register) {
115
+ const registrations = buildI18nRegistrations();
116
+ if (registrations.length > 0) {
117
+ await this._i18nMessages.register(registrations);
118
+ }
119
+ }
120
+ if (load) {
121
+ await applyTranslations(this._i18nMessages);
122
+ const messages = this._i18nMessages;
123
+ this._i18nSubscription = messages.refresh$.subscribe(() => applyTranslations(messages));
116
124
  }
117
125
  }
118
- if (load) {
119
- await applyTranslations(this._i18nMessages);
120
- const messages = this._i18nMessages;
121
- this._i18nSubscription = messages.refresh$.subscribe(() => applyTranslations(messages));
126
+ if (options?.load) {
127
+ await Promise.all(options.load.map((l) => l.load()));
122
128
  }
123
- }
124
- if (options?.load) {
125
- await Promise.all(options.load.map((l) => l.load()));
129
+ this._initialized = true;
130
+ } catch (err) {
131
+ await this.destroy().catch(() => {
132
+ });
133
+ throw err;
126
134
  }
127
135
  }
128
136
  async destroy() {
137
+ this._initialized = false;
129
138
  this._i18nSubscription?.unsubscribe();
130
139
  this._i18nSubscription = void 0;
131
140
  await this._store.destroy();
@@ -137,24 +146,24 @@ var Contello = class {
137
146
  return this._store.ping();
138
147
  }
139
148
  get isReady() {
140
- return !!this._routes;
149
+ return this._initialized;
141
150
  }
142
151
  // --- pre-wired collections ---
143
152
  get assets() {
144
- if (!this._assets) {
145
- throw new Error("@contello/astro: .assets accessed before init()");
153
+ if (!this._initialized || !this._assets) {
154
+ throw new Error("@contello/astro: .assets accessed before init() completed");
146
155
  }
147
156
  return this._assets;
148
157
  }
149
158
  get routes() {
150
- if (!this._routes) {
151
- throw new Error("@contello/astro: .routes accessed before init()");
159
+ if (!this._initialized || !this._routes) {
160
+ throw new Error("@contello/astro: .routes accessed before init() completed");
152
161
  }
153
162
  return this._routes;
154
163
  }
155
164
  get i18nMessages() {
156
- if (!this._i18nMessages) {
157
- throw new Error("@contello/astro: .i18nMessages accessed before init() with i18n config");
165
+ if (!this._initialized || !this._i18nMessages) {
166
+ throw new Error("@contello/astro: .i18nMessages accessed before init() completed (or i18n is not configured)");
158
167
  }
159
168
  return this._i18nMessages;
160
169
  }
package/dist/index.d.cts CHANGED
@@ -43,6 +43,7 @@ declare class Contello<TOps extends OperationMap | undefined = undefined, TModel
43
43
  private _routes;
44
44
  private _i18nMessages;
45
45
  private _i18nSubscription;
46
+ private _initialized;
46
47
  private readonly _als;
47
48
  readonly media: ContelloMediaConfig;
48
49
  constructor(options: ContelloOptions<TOps, TModels>);
package/dist/index.d.ts CHANGED
@@ -43,6 +43,7 @@ declare class Contello<TOps extends OperationMap | undefined = undefined, TModel
43
43
  private _routes;
44
44
  private _i18nMessages;
45
45
  private _i18nSubscription;
46
+ private _initialized;
46
47
  private readonly _als;
47
48
  readonly media: ContelloMediaConfig;
48
49
  constructor(options: ContelloOptions<TOps, TModels>);
package/dist/index.js CHANGED
@@ -50,6 +50,7 @@ var Contello = class {
50
50
  _routes;
51
51
  _i18nMessages;
52
52
  _i18nSubscription;
53
+ _initialized = false;
53
54
  _als = new AsyncLocalStorage();
54
55
  media;
55
56
  constructor(options) {
@@ -64,31 +65,39 @@ var Contello = class {
64
65
  }
65
66
  // --- lifecycle ---
66
67
  async init(options) {
67
- await this._store.init();
68
- this._assets = this._store.defineAssets(this._options.assets);
69
- this._routes = this._store.defineRoutes(this._options.routes);
70
- if (this._options.i18n) {
71
- const { collection, languages } = this._options.i18n;
72
- const { register = true, load = true } = options?.i18n ?? {};
73
- this._i18nMessages = this._store.defineI18nMessages({ collection });
74
- await i18n.configure({ locales: languages });
75
- if (register) {
76
- const registrations = buildI18nRegistrations();
77
- if (registrations.length > 0) {
78
- await this._i18nMessages.register(registrations);
68
+ try {
69
+ await this._store.init();
70
+ this._assets = this._store.defineAssets(this._options.assets);
71
+ this._routes = this._store.defineRoutes(this._options.routes);
72
+ if (this._options.i18n) {
73
+ const { collection, languages } = this._options.i18n;
74
+ const { register = true, load = true } = options?.i18n ?? {};
75
+ this._i18nMessages = this._store.defineI18nMessages({ collection });
76
+ await i18n.configure({ locales: languages });
77
+ if (register) {
78
+ const registrations = buildI18nRegistrations();
79
+ if (registrations.length > 0) {
80
+ await this._i18nMessages.register(registrations);
81
+ }
82
+ }
83
+ if (load) {
84
+ await applyTranslations(this._i18nMessages);
85
+ const messages = this._i18nMessages;
86
+ this._i18nSubscription = messages.refresh$.subscribe(() => applyTranslations(messages));
79
87
  }
80
88
  }
81
- if (load) {
82
- await applyTranslations(this._i18nMessages);
83
- const messages = this._i18nMessages;
84
- this._i18nSubscription = messages.refresh$.subscribe(() => applyTranslations(messages));
89
+ if (options?.load) {
90
+ await Promise.all(options.load.map((l) => l.load()));
85
91
  }
86
- }
87
- if (options?.load) {
88
- await Promise.all(options.load.map((l) => l.load()));
92
+ this._initialized = true;
93
+ } catch (err) {
94
+ await this.destroy().catch(() => {
95
+ });
96
+ throw err;
89
97
  }
90
98
  }
91
99
  async destroy() {
100
+ this._initialized = false;
92
101
  this._i18nSubscription?.unsubscribe();
93
102
  this._i18nSubscription = void 0;
94
103
  await this._store.destroy();
@@ -100,24 +109,24 @@ var Contello = class {
100
109
  return this._store.ping();
101
110
  }
102
111
  get isReady() {
103
- return !!this._routes;
112
+ return this._initialized;
104
113
  }
105
114
  // --- pre-wired collections ---
106
115
  get assets() {
107
- if (!this._assets) {
108
- throw new Error("@contello/astro: .assets accessed before init()");
116
+ if (!this._initialized || !this._assets) {
117
+ throw new Error("@contello/astro: .assets accessed before init() completed");
109
118
  }
110
119
  return this._assets;
111
120
  }
112
121
  get routes() {
113
- if (!this._routes) {
114
- throw new Error("@contello/astro: .routes accessed before init()");
122
+ if (!this._initialized || !this._routes) {
123
+ throw new Error("@contello/astro: .routes accessed before init() completed");
115
124
  }
116
125
  return this._routes;
117
126
  }
118
127
  get i18nMessages() {
119
- if (!this._i18nMessages) {
120
- throw new Error("@contello/astro: .i18nMessages accessed before init() with i18n config");
128
+ if (!this._initialized || !this._i18nMessages) {
129
+ throw new Error("@contello/astro: .i18nMessages accessed before init() completed (or i18n is not configured)");
121
130
  }
122
131
  return this._i18nMessages;
123
132
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contello/astro",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "description": "Astro integration for Contello CMS — route middleware and i18n bridge",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -14,9 +14,9 @@
14
14
  "@astroscope/excludes": ">=0.1.0",
15
15
  "@astroscope/i18n": ">=0.3.0",
16
16
  "astro": "^6.0.0",
17
- "@contello/client": "^1.1.0",
17
+ "@contello/client": "^1.1.1",
18
18
  "@contello/media": "^1.0.0",
19
- "@contello/store": "^1.5.0"
19
+ "@contello/store": "^1.5.1"
20
20
  },
21
21
  "peerDependenciesMeta": {
22
22
  "@astroscope/i18n": {
@@ -27,9 +27,9 @@
27
27
  "@astroscope/excludes": "^0.3.2",
28
28
  "@astroscope/i18n": "^0.4.5",
29
29
  "astro": "^6.1.8",
30
- "@contello/client": "^1.1.0",
31
30
  "@contello/media": "^1.0.0",
32
- "@contello/store": "^1.5.0"
31
+ "@contello/store": "^1.5.1",
32
+ "@contello/client": "^1.1.1"
33
33
  },
34
34
  "files": [
35
35
  "dist"