@etsoo/appscript 1.4.63 → 1.4.64

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.
@@ -5,7 +5,6 @@ import { Currency } from './Currency';
5
5
  * 购物篮所有人
6
6
  */
7
7
  export type ShoppingCartOwner = DataTypes.IdNameItem & {
8
- isSupplier?: boolean;
9
8
  culture?: string;
10
9
  currency?: Currency;
11
10
  };
@@ -20,6 +19,7 @@ export type ShoppingCartData<T extends ShoppingCartItem> = {
20
19
  items: T[];
21
20
  promotions: ShoppingPromotion[];
22
21
  formData?: any;
22
+ cache?: Record<string, unknown>;
23
23
  };
24
24
  /**
25
25
  * Shopping promotion
@@ -122,7 +122,7 @@ export declare class ShoppingCart<T extends ShoppingCartItem> {
122
122
  * @param key Additional key
123
123
  * @returns Result
124
124
  */
125
- static createKey(currency: Currency, culture: string, key?: string): string;
125
+ static createKey(currency: Currency, culture: string, key: string): string;
126
126
  /**
127
127
  * Clear shopping cart
128
128
  * 清除购物篮
@@ -130,14 +130,6 @@ export declare class ShoppingCart<T extends ShoppingCartItem> {
130
130
  * @param storage Storage
131
131
  */
132
132
  static clear(identifier: string, storage: IStorage): void;
133
- /**
134
- * Clear shopping cart
135
- * 清除购物篮
136
- * @param currency Currency
137
- * @param culture Culture
138
- * @param storage Storage
139
- */
140
- static clearWith(currency: Currency, culture: string, storage?: IStorage): void;
141
133
  /**
142
134
  * Get cart data
143
135
  * 获取购物篮数据
@@ -186,6 +178,11 @@ export declare class ShoppingCart<T extends ShoppingCartItem> {
186
178
  * 关联的表单数据
187
179
  */
188
180
  formData: any;
181
+ /**
182
+ * Cache
183
+ * 缓存对象
184
+ */
185
+ cache?: Record<string, unknown>;
189
186
  _symbol: string | undefined;
190
187
  /**
191
188
  * Currency symbol
@@ -193,6 +190,10 @@ export declare class ShoppingCart<T extends ShoppingCartItem> {
193
190
  */
194
191
  get symbol(): string | undefined;
195
192
  private set symbol(value);
193
+ /**
194
+ * Key for identifier
195
+ */
196
+ readonly key: string;
196
197
  /**
197
198
  * Cart identifier
198
199
  * 购物篮标识
@@ -237,17 +238,19 @@ export declare class ShoppingCart<T extends ShoppingCartItem> {
237
238
  /**
238
239
  * Constructor
239
240
  * 构造函数
241
+ * @param key Key for identifier
240
242
  * @param init Currency & culture ISO code array
241
243
  * @param storage Data storage
242
244
  */
243
- constructor(init: [Currency, string], storage?: IStorage);
245
+ constructor(key: string, init: [Currency, string], storage?: IStorage);
244
246
  /**
245
247
  * Constructor
246
248
  * 构造函数
249
+ * @param key Key for identifier
247
250
  * @param state Initialization state
248
251
  * @param storage Data storage
249
252
  */
250
- constructor(state: ShoppingCartData<T>, storage?: IStorage);
253
+ constructor(key: string, state: ShoppingCartData<T>, storage?: IStorage);
251
254
  private setCartData;
252
255
  private doChange;
253
256
  /**
@@ -16,7 +16,7 @@ class ShoppingCart {
16
16
  * @param key Additional key
17
17
  * @returns Result
18
18
  */
19
- static createKey(currency, culture, key = 'KEY') {
19
+ static createKey(currency, culture, key) {
20
20
  return `ETSOO-CART-${culture}-${key}-${currency}`;
21
21
  }
22
22
  /**
@@ -34,17 +34,6 @@ class ShoppingCart {
34
34
  console.log('ShoppingCart clear', error);
35
35
  }
36
36
  }
37
- /**
38
- * Clear shopping cart
39
- * 清除购物篮
40
- * @param currency Currency
41
- * @param culture Culture
42
- * @param storage Storage
43
- */
44
- static clearWith(currency, culture, storage = new shared_1.WindowStorage()) {
45
- const identifier = this.createKey(currency, culture);
46
- this.clear(identifier, storage);
47
- }
48
37
  /**
49
38
  * Get cart data
50
39
  * 获取购物篮数据
@@ -135,7 +124,7 @@ class ShoppingCart {
135
124
  */
136
125
  get identifier() {
137
126
  const o = this.owner;
138
- return ShoppingCart.createKey(this.currency, this.culture, o ? `${o.isSupplier ? 'S' : 'C'}${o.id}` : undefined);
127
+ return ShoppingCart.createKey(this.currency, this.culture, this.key);
139
128
  }
140
129
  /**
141
130
  * All data keys
@@ -182,10 +171,12 @@ class ShoppingCart {
182
171
  /**
183
172
  * Constructor
184
173
  * 构造函数
174
+ * @param key Key for identifier
185
175
  * @param currency Currency ISO code
186
176
  * @param storage Data storage
187
177
  */
188
- constructor(currencyOrState, storage = new shared_1.WindowStorage()) {
178
+ constructor(key, currencyOrState, storage = new shared_1.WindowStorage()) {
179
+ var _a;
189
180
  this.storage = storage;
190
181
  this._items = [];
191
182
  this._promotions = [];
@@ -194,9 +185,11 @@ class ShoppingCart {
194
185
  * 缓存的价格
195
186
  */
196
187
  this.prices = {};
188
+ this.key = key;
197
189
  if (Array.isArray(currencyOrState)) {
198
190
  this.changeCurrency(currencyOrState[0]);
199
191
  this.changeCulture(currencyOrState[1]);
192
+ this.setCartData((_a = this.storage.getPersistedObject(this.identifier)) !== null && _a !== void 0 ? _a : this.storage.getObject(this.identifier));
200
193
  }
201
194
  else {
202
195
  this.setCartData(currencyOrState);
@@ -205,11 +198,12 @@ class ShoppingCart {
205
198
  }
206
199
  }
207
200
  setCartData(state) {
208
- const { owner, items = [], promotions = [], formData } = state !== null && state !== void 0 ? state : {};
201
+ const { owner, items = [], promotions = [], formData, cache } = state !== null && state !== void 0 ? state : {};
209
202
  this.owner = owner;
210
203
  this.items = items;
211
204
  this.promotions = promotions;
212
205
  this.formData = formData;
206
+ this.cache = cache;
213
207
  }
214
208
  doChange(reason, changedItems) {
215
209
  if (this.onChange)
@@ -343,14 +337,15 @@ class ShoppingCart {
343
337
  save(persisted = true) {
344
338
  if (this.owner == null)
345
339
  return;
346
- const { currency, culture, owner, items, promotions, formData } = this;
340
+ const { currency, culture, owner, items, promotions, formData, cache } = this;
347
341
  const data = {
348
342
  currency,
349
343
  culture,
350
344
  owner,
351
345
  items,
352
346
  promotions,
353
- formData
347
+ formData,
348
+ cache
354
349
  };
355
350
  try {
356
351
  if (persisted) {
@@ -5,7 +5,6 @@ import { Currency } from './Currency';
5
5
  * 购物篮所有人
6
6
  */
7
7
  export type ShoppingCartOwner = DataTypes.IdNameItem & {
8
- isSupplier?: boolean;
9
8
  culture?: string;
10
9
  currency?: Currency;
11
10
  };
@@ -20,6 +19,7 @@ export type ShoppingCartData<T extends ShoppingCartItem> = {
20
19
  items: T[];
21
20
  promotions: ShoppingPromotion[];
22
21
  formData?: any;
22
+ cache?: Record<string, unknown>;
23
23
  };
24
24
  /**
25
25
  * Shopping promotion
@@ -122,7 +122,7 @@ export declare class ShoppingCart<T extends ShoppingCartItem> {
122
122
  * @param key Additional key
123
123
  * @returns Result
124
124
  */
125
- static createKey(currency: Currency, culture: string, key?: string): string;
125
+ static createKey(currency: Currency, culture: string, key: string): string;
126
126
  /**
127
127
  * Clear shopping cart
128
128
  * 清除购物篮
@@ -130,14 +130,6 @@ export declare class ShoppingCart<T extends ShoppingCartItem> {
130
130
  * @param storage Storage
131
131
  */
132
132
  static clear(identifier: string, storage: IStorage): void;
133
- /**
134
- * Clear shopping cart
135
- * 清除购物篮
136
- * @param currency Currency
137
- * @param culture Culture
138
- * @param storage Storage
139
- */
140
- static clearWith(currency: Currency, culture: string, storage?: IStorage): void;
141
133
  /**
142
134
  * Get cart data
143
135
  * 获取购物篮数据
@@ -186,6 +178,11 @@ export declare class ShoppingCart<T extends ShoppingCartItem> {
186
178
  * 关联的表单数据
187
179
  */
188
180
  formData: any;
181
+ /**
182
+ * Cache
183
+ * 缓存对象
184
+ */
185
+ cache?: Record<string, unknown>;
189
186
  _symbol: string | undefined;
190
187
  /**
191
188
  * Currency symbol
@@ -193,6 +190,10 @@ export declare class ShoppingCart<T extends ShoppingCartItem> {
193
190
  */
194
191
  get symbol(): string | undefined;
195
192
  private set symbol(value);
193
+ /**
194
+ * Key for identifier
195
+ */
196
+ readonly key: string;
196
197
  /**
197
198
  * Cart identifier
198
199
  * 购物篮标识
@@ -237,17 +238,19 @@ export declare class ShoppingCart<T extends ShoppingCartItem> {
237
238
  /**
238
239
  * Constructor
239
240
  * 构造函数
241
+ * @param key Key for identifier
240
242
  * @param init Currency & culture ISO code array
241
243
  * @param storage Data storage
242
244
  */
243
- constructor(init: [Currency, string], storage?: IStorage);
245
+ constructor(key: string, init: [Currency, string], storage?: IStorage);
244
246
  /**
245
247
  * Constructor
246
248
  * 构造函数
249
+ * @param key Key for identifier
247
250
  * @param state Initialization state
248
251
  * @param storage Data storage
249
252
  */
250
- constructor(state: ShoppingCartData<T>, storage?: IStorage);
253
+ constructor(key: string, state: ShoppingCartData<T>, storage?: IStorage);
251
254
  private setCartData;
252
255
  private doChange;
253
256
  /**
@@ -13,7 +13,7 @@ export class ShoppingCart {
13
13
  * @param key Additional key
14
14
  * @returns Result
15
15
  */
16
- static createKey(currency, culture, key = 'KEY') {
16
+ static createKey(currency, culture, key) {
17
17
  return `ETSOO-CART-${culture}-${key}-${currency}`;
18
18
  }
19
19
  /**
@@ -31,17 +31,6 @@ export class ShoppingCart {
31
31
  console.log('ShoppingCart clear', error);
32
32
  }
33
33
  }
34
- /**
35
- * Clear shopping cart
36
- * 清除购物篮
37
- * @param currency Currency
38
- * @param culture Culture
39
- * @param storage Storage
40
- */
41
- static clearWith(currency, culture, storage = new WindowStorage()) {
42
- const identifier = this.createKey(currency, culture);
43
- this.clear(identifier, storage);
44
- }
45
34
  /**
46
35
  * Get cart data
47
36
  * 获取购物篮数据
@@ -132,7 +121,7 @@ export class ShoppingCart {
132
121
  */
133
122
  get identifier() {
134
123
  const o = this.owner;
135
- return ShoppingCart.createKey(this.currency, this.culture, o ? `${o.isSupplier ? 'S' : 'C'}${o.id}` : undefined);
124
+ return ShoppingCart.createKey(this.currency, this.culture, this.key);
136
125
  }
137
126
  /**
138
127
  * All data keys
@@ -179,10 +168,12 @@ export class ShoppingCart {
179
168
  /**
180
169
  * Constructor
181
170
  * 构造函数
171
+ * @param key Key for identifier
182
172
  * @param currency Currency ISO code
183
173
  * @param storage Data storage
184
174
  */
185
- constructor(currencyOrState, storage = new WindowStorage()) {
175
+ constructor(key, currencyOrState, storage = new WindowStorage()) {
176
+ var _a;
186
177
  this.storage = storage;
187
178
  this._items = [];
188
179
  this._promotions = [];
@@ -191,9 +182,11 @@ export class ShoppingCart {
191
182
  * 缓存的价格
192
183
  */
193
184
  this.prices = {};
185
+ this.key = key;
194
186
  if (Array.isArray(currencyOrState)) {
195
187
  this.changeCurrency(currencyOrState[0]);
196
188
  this.changeCulture(currencyOrState[1]);
189
+ this.setCartData((_a = this.storage.getPersistedObject(this.identifier)) !== null && _a !== void 0 ? _a : this.storage.getObject(this.identifier));
197
190
  }
198
191
  else {
199
192
  this.setCartData(currencyOrState);
@@ -202,11 +195,12 @@ export class ShoppingCart {
202
195
  }
203
196
  }
204
197
  setCartData(state) {
205
- const { owner, items = [], promotions = [], formData } = state !== null && state !== void 0 ? state : {};
198
+ const { owner, items = [], promotions = [], formData, cache } = state !== null && state !== void 0 ? state : {};
206
199
  this.owner = owner;
207
200
  this.items = items;
208
201
  this.promotions = promotions;
209
202
  this.formData = formData;
203
+ this.cache = cache;
210
204
  }
211
205
  doChange(reason, changedItems) {
212
206
  if (this.onChange)
@@ -340,14 +334,15 @@ export class ShoppingCart {
340
334
  save(persisted = true) {
341
335
  if (this.owner == null)
342
336
  return;
343
- const { currency, culture, owner, items, promotions, formData } = this;
337
+ const { currency, culture, owner, items, promotions, formData, cache } = this;
344
338
  const data = {
345
339
  currency,
346
340
  culture,
347
341
  owner,
348
342
  items,
349
343
  promotions,
350
- formData
344
+ formData,
345
+ cache
351
346
  };
352
347
  try {
353
348
  if (persisted) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.4.63",
3
+ "version": "1.4.64",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -6,7 +6,6 @@ import { Currency } from './Currency';
6
6
  * 购物篮所有人
7
7
  */
8
8
  export type ShoppingCartOwner = DataTypes.IdNameItem & {
9
- isSupplier?: boolean;
10
9
  culture?: string;
11
10
  currency?: Currency;
12
11
  };
@@ -22,6 +21,7 @@ export type ShoppingCartData<T extends ShoppingCartItem> = {
22
21
  items: T[];
23
22
  promotions: ShoppingPromotion[];
24
23
  formData?: any;
24
+ cache?: Record<string, unknown>;
25
25
  };
26
26
 
27
27
  /**
@@ -145,7 +145,7 @@ export class ShoppingCart<T extends ShoppingCartItem> {
145
145
  * @param key Additional key
146
146
  * @returns Result
147
147
  */
148
- static createKey(currency: Currency, culture: string, key: string = 'KEY') {
148
+ static createKey(currency: Currency, culture: string, key: string) {
149
149
  return `ETSOO-CART-${culture}-${key}-${currency}`;
150
150
  }
151
151
 
@@ -164,22 +164,6 @@ export class ShoppingCart<T extends ShoppingCartItem> {
164
164
  }
165
165
  }
166
166
 
167
- /**
168
- * Clear shopping cart
169
- * 清除购物篮
170
- * @param currency Currency
171
- * @param culture Culture
172
- * @param storage Storage
173
- */
174
- static clearWith(
175
- currency: Currency,
176
- culture: string,
177
- storage: IStorage = new WindowStorage()
178
- ) {
179
- const identifier = this.createKey(currency, culture);
180
- this.clear(identifier, storage);
181
- }
182
-
183
167
  /**
184
168
  * Get cart data
185
169
  * 获取购物篮数据
@@ -277,6 +261,12 @@ export class ShoppingCart<T extends ShoppingCartItem> {
277
261
  */
278
262
  formData: any;
279
263
 
264
+ /**
265
+ * Cache
266
+ * 缓存对象
267
+ */
268
+ cache?: Record<string, unknown>;
269
+
280
270
  _symbol: string | undefined;
281
271
  /**
282
272
  * Currency symbol
@@ -289,17 +279,18 @@ export class ShoppingCart<T extends ShoppingCartItem> {
289
279
  this._symbol = value;
290
280
  }
291
281
 
282
+ /**
283
+ * Key for identifier
284
+ */
285
+ readonly key: string;
286
+
292
287
  /**
293
288
  * Cart identifier
294
289
  * 购物篮标识
295
290
  */
296
291
  get identifier() {
297
292
  const o = this.owner;
298
- return ShoppingCart.createKey(
299
- this.currency,
300
- this.culture,
301
- o ? `${o.isSupplier ? 'S' : 'C'}${o.id}` : undefined
302
- );
293
+ return ShoppingCart.createKey(this.currency, this.culture, this.key);
303
294
  }
304
295
 
305
296
  /**
@@ -369,32 +360,43 @@ export class ShoppingCart<T extends ShoppingCartItem> {
369
360
  /**
370
361
  * Constructor
371
362
  * 构造函数
363
+ * @param key Key for identifier
372
364
  * @param init Currency & culture ISO code array
373
365
  * @param storage Data storage
374
366
  */
375
- constructor(init: [Currency, string], storage?: IStorage);
367
+ constructor(key: string, init: [Currency, string], storage?: IStorage);
376
368
 
377
369
  /**
378
370
  * Constructor
379
371
  * 构造函数
372
+ * @param key Key for identifier
380
373
  * @param state Initialization state
381
374
  * @param storage Data storage
382
375
  */
383
- constructor(state: ShoppingCartData<T>, storage?: IStorage);
376
+ constructor(key: string, state: ShoppingCartData<T>, storage?: IStorage);
384
377
 
385
378
  /**
386
379
  * Constructor
387
380
  * 构造函数
381
+ * @param key Key for identifier
388
382
  * @param currency Currency ISO code
389
383
  * @param storage Data storage
390
384
  */
391
385
  constructor(
386
+ key: string,
392
387
  currencyOrState: [Currency, string] | ShoppingCartData<T>,
393
388
  private readonly storage: IStorage = new WindowStorage()
394
389
  ) {
390
+ this.key = key;
391
+
395
392
  if (Array.isArray(currencyOrState)) {
396
393
  this.changeCurrency(currencyOrState[0]);
397
394
  this.changeCulture(currencyOrState[1]);
395
+
396
+ this.setCartData(
397
+ this.storage.getPersistedObject(this.identifier) ??
398
+ this.storage.getObject(this.identifier)
399
+ );
398
400
  } else {
399
401
  this.setCartData(currencyOrState);
400
402
  this.changeCurrency(currencyOrState.currency);
@@ -403,11 +405,18 @@ export class ShoppingCart<T extends ShoppingCartItem> {
403
405
  }
404
406
 
405
407
  private setCartData(state: ShoppingCartData<T> | undefined) {
406
- const { owner, items = [], promotions = [], formData } = state ?? {};
408
+ const {
409
+ owner,
410
+ items = [],
411
+ promotions = [],
412
+ formData,
413
+ cache
414
+ } = state ?? {};
407
415
  this.owner = owner;
408
416
  this.items = items;
409
417
  this.promotions = promotions;
410
418
  this.formData = formData;
419
+ this.cache = cache;
411
420
  }
412
421
 
413
422
  private doChange(reason: ShoppingCartChangeReason, changedItems: T[]) {
@@ -555,14 +564,16 @@ export class ShoppingCart<T extends ShoppingCartItem> {
555
564
  save(persisted: boolean = true) {
556
565
  if (this.owner == null) return;
557
566
 
558
- const { currency, culture, owner, items, promotions, formData } = this;
567
+ const { currency, culture, owner, items, promotions, formData, cache } =
568
+ this;
559
569
  const data: ShoppingCartData<T> = {
560
570
  currency,
561
571
  culture,
562
572
  owner,
563
573
  items,
564
574
  promotions,
565
- formData
575
+ formData,
576
+ cache
566
577
  };
567
578
 
568
579
  try {