@etsoo/appscript 1.3.91 → 1.3.93

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.
@@ -215,7 +215,7 @@ test('Tests for getStatusList', () => {
215
215
  EntityStatus.Deleted
216
216
  ]);
217
217
  expect(statuses.length).toBe(5);
218
- expect(statuses.some((s) => s.id === EntityStatus.Doing)).toBeTruthy();
218
+ expect(statuses.map((s) => s.id)).toStrictEqual([0, 100, 110, 250, 255]);
219
219
 
220
220
  expect(app.getStatusList().length).toBe(9);
221
221
  });
@@ -376,7 +376,7 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
376
376
  * @param filter Filter
377
377
  * @returns List
378
378
  */
379
- getEnumList<E extends DataTypes.EnumBase = DataTypes.EnumBase>(em: E, prefix: string, filter?: (id: E[keyof E], key: keyof E & string) => E[keyof E] | undefined): ListType[];
379
+ getEnumList<E extends DataTypes.EnumBase = DataTypes.EnumBase>(em: E, prefix: string, filter?: ((id: E[keyof E], key: keyof E & string) => E[keyof E] | undefined) | E[keyof E][]): ListType[];
380
380
  /**
381
381
  * Get enum item string id list
382
382
  * @param em Enum
@@ -908,19 +908,31 @@ class CoreApp {
908
908
  getEnumList(em, prefix, filter) {
909
909
  var _a;
910
910
  const list = [];
911
- const keys = shared_1.DataTypes.getEnumKeys(em);
912
- for (const key of keys) {
913
- let id = em[key];
914
- if (filter) {
915
- const fid = filter(id, key);
916
- if (fid == null)
911
+ if (Array.isArray(filter)) {
912
+ filter.forEach((id) => {
913
+ var _a;
914
+ if (typeof id !== 'number')
915
+ return;
916
+ const key = shared_1.DataTypes.getEnumKey(em, id);
917
+ var label = (_a = this.get(prefix + key)) !== null && _a !== void 0 ? _a : key;
918
+ list.push({ id, label });
919
+ });
920
+ }
921
+ else {
922
+ const keys = shared_1.DataTypes.getEnumKeys(em);
923
+ for (const key of keys) {
924
+ let id = em[key];
925
+ if (filter) {
926
+ const fid = filter(id, key);
927
+ if (fid == null)
928
+ continue;
929
+ id = fid;
930
+ }
931
+ if (typeof id !== 'number')
917
932
  continue;
918
- id = fid;
933
+ var label = (_a = this.get(prefix + key)) !== null && _a !== void 0 ? _a : key;
934
+ list.push({ id, label });
919
935
  }
920
- if (typeof id !== 'number')
921
- continue;
922
- var label = (_a = this.get(prefix + key)) !== null && _a !== void 0 ? _a : key;
923
- list.push({ id, label });
924
936
  }
925
937
  return list;
926
938
  }
@@ -981,10 +993,8 @@ class CoreApp {
981
993
  * @param ids Limited ids
982
994
  * @returns list
983
995
  */
984
- getStatusList(ids = []) {
985
- return this.getEnumList(EntityStatus_1.EntityStatus, 'status', ids.length > 0
986
- ? (id, _key) => (ids.includes(id) ? id : undefined)
987
- : undefined);
996
+ getStatusList(ids) {
997
+ return this.getEnumList(EntityStatus_1.EntityStatus, 'status', ids);
988
998
  }
989
999
  /**
990
1000
  * Get status label
@@ -320,7 +320,7 @@ export interface IApp {
320
320
  * @param filter Filter
321
321
  * @returns List
322
322
  */
323
- getEnumStrList<E extends DataTypes.EnumBase = DataTypes.EnumBase>(em: E, prefix: string, filter?: (id: E[keyof E], key: keyof E & string) => E[keyof E] | undefined): ListType1[];
323
+ getEnumStrList<E extends DataTypes.EnumBase = DataTypes.EnumBase>(em: E, prefix: string, filter?: ((id: E[keyof E], key: keyof E & string) => E[keyof E] | undefined) | E[keyof E][]): ListType1[];
324
324
  /**
325
325
  * Get region label
326
326
  * @param id Region id
@@ -110,9 +110,10 @@ export declare class ShoppingCart<T extends ShoppingCartItem> {
110
110
  * Create identifier key
111
111
  * 创建识别键
112
112
  * @param currency Currency
113
+ * @param key Additional key
113
114
  * @returns Result
114
115
  */
115
- static createKey(currency: string): string;
116
+ static createKey(currency: string, key?: string): string;
116
117
  /**
117
118
  * Clear shopping cart
118
119
  * 清除购物篮
@@ -197,15 +198,17 @@ export declare class ShoppingCart<T extends ShoppingCartItem> {
197
198
  * 构造函数
198
199
  * @param currency Currency ISO code
199
200
  * @param storage Data storage
201
+ * @param key Additional key
200
202
  */
201
- constructor(currency: string, storage?: IStorage);
203
+ constructor(currency: string, storage?: IStorage, key?: string);
202
204
  /**
203
205
  * Constructor
204
206
  * 构造函数
205
207
  * @param state Initialization state
206
208
  * @param storage Data storage
209
+ * @param key Additional key
207
210
  */
208
- constructor(state: ShoppingCartData<T>, storage?: IStorage);
211
+ constructor(state: ShoppingCartData<T>, storage?: IStorage, key?: string);
209
212
  private doChange;
210
213
  /**
211
214
  * Add item
@@ -11,10 +11,11 @@ class ShoppingCart {
11
11
  * Create identifier key
12
12
  * 创建识别键
13
13
  * @param currency Currency
14
+ * @param key Additional key
14
15
  * @returns Result
15
16
  */
16
- static createKey(currency) {
17
- return `ETSOO-CART-${currency}`;
17
+ static createKey(currency, key = 'KEY') {
18
+ return `ETSOO-CART-${key}-${currency}`;
18
19
  }
19
20
  /**
20
21
  * Clear shopping cart
@@ -78,9 +79,9 @@ class ShoppingCart {
78
79
  * 构造函数
79
80
  * @param currency Currency ISO code
80
81
  * @param storage Data storage
81
- * @param state Initialization state
82
+ * @param key Additional key
82
83
  */
83
- constructor(currencyOrState, storage = new shared_1.WindowStorage()) {
84
+ constructor(currencyOrState, storage = new shared_1.WindowStorage(), key) {
84
85
  var _a;
85
86
  this.storage = storage;
86
87
  /**
@@ -90,14 +91,14 @@ class ShoppingCart {
90
91
  this.prices = {};
91
92
  const isCurrency = typeof currencyOrState === 'string';
92
93
  this.currency = isCurrency ? currencyOrState : currencyOrState.currency;
93
- const key = ShoppingCart.createKey(this.currency);
94
- this.identifier = key;
94
+ const id = ShoppingCart.createKey(this.currency, key);
95
+ this.identifier = id;
95
96
  this.symbol = shared_1.NumberUtils.getCurrencySymbol(this.currency);
96
97
  let state;
97
98
  if (isCurrency) {
98
99
  try {
99
100
  state =
100
- (_a = storage.getPersistedObject(key)) !== null && _a !== void 0 ? _a : storage.getObject(key);
101
+ (_a = storage.getPersistedObject(id)) !== null && _a !== void 0 ? _a : storage.getObject(id);
101
102
  }
102
103
  catch (error) {
103
104
  console.log('ShoppingCart constructor', error);
@@ -376,7 +376,7 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
376
376
  * @param filter Filter
377
377
  * @returns List
378
378
  */
379
- getEnumList<E extends DataTypes.EnumBase = DataTypes.EnumBase>(em: E, prefix: string, filter?: (id: E[keyof E], key: keyof E & string) => E[keyof E] | undefined): ListType[];
379
+ getEnumList<E extends DataTypes.EnumBase = DataTypes.EnumBase>(em: E, prefix: string, filter?: ((id: E[keyof E], key: keyof E & string) => E[keyof E] | undefined) | E[keyof E][]): ListType[];
380
380
  /**
381
381
  * Get enum item string id list
382
382
  * @param em Enum
@@ -905,19 +905,31 @@ export class CoreApp {
905
905
  getEnumList(em, prefix, filter) {
906
906
  var _a;
907
907
  const list = [];
908
- const keys = DataTypes.getEnumKeys(em);
909
- for (const key of keys) {
910
- let id = em[key];
911
- if (filter) {
912
- const fid = filter(id, key);
913
- if (fid == null)
908
+ if (Array.isArray(filter)) {
909
+ filter.forEach((id) => {
910
+ var _a;
911
+ if (typeof id !== 'number')
912
+ return;
913
+ const key = DataTypes.getEnumKey(em, id);
914
+ var label = (_a = this.get(prefix + key)) !== null && _a !== void 0 ? _a : key;
915
+ list.push({ id, label });
916
+ });
917
+ }
918
+ else {
919
+ const keys = DataTypes.getEnumKeys(em);
920
+ for (const key of keys) {
921
+ let id = em[key];
922
+ if (filter) {
923
+ const fid = filter(id, key);
924
+ if (fid == null)
925
+ continue;
926
+ id = fid;
927
+ }
928
+ if (typeof id !== 'number')
914
929
  continue;
915
- id = fid;
930
+ var label = (_a = this.get(prefix + key)) !== null && _a !== void 0 ? _a : key;
931
+ list.push({ id, label });
916
932
  }
917
- if (typeof id !== 'number')
918
- continue;
919
- var label = (_a = this.get(prefix + key)) !== null && _a !== void 0 ? _a : key;
920
- list.push({ id, label });
921
933
  }
922
934
  return list;
923
935
  }
@@ -978,10 +990,8 @@ export class CoreApp {
978
990
  * @param ids Limited ids
979
991
  * @returns list
980
992
  */
981
- getStatusList(ids = []) {
982
- return this.getEnumList(EntityStatus, 'status', ids.length > 0
983
- ? (id, _key) => (ids.includes(id) ? id : undefined)
984
- : undefined);
993
+ getStatusList(ids) {
994
+ return this.getEnumList(EntityStatus, 'status', ids);
985
995
  }
986
996
  /**
987
997
  * Get status label
@@ -320,7 +320,7 @@ export interface IApp {
320
320
  * @param filter Filter
321
321
  * @returns List
322
322
  */
323
- getEnumStrList<E extends DataTypes.EnumBase = DataTypes.EnumBase>(em: E, prefix: string, filter?: (id: E[keyof E], key: keyof E & string) => E[keyof E] | undefined): ListType1[];
323
+ getEnumStrList<E extends DataTypes.EnumBase = DataTypes.EnumBase>(em: E, prefix: string, filter?: ((id: E[keyof E], key: keyof E & string) => E[keyof E] | undefined) | E[keyof E][]): ListType1[];
324
324
  /**
325
325
  * Get region label
326
326
  * @param id Region id
@@ -110,9 +110,10 @@ export declare class ShoppingCart<T extends ShoppingCartItem> {
110
110
  * Create identifier key
111
111
  * 创建识别键
112
112
  * @param currency Currency
113
+ * @param key Additional key
113
114
  * @returns Result
114
115
  */
115
- static createKey(currency: string): string;
116
+ static createKey(currency: string, key?: string): string;
116
117
  /**
117
118
  * Clear shopping cart
118
119
  * 清除购物篮
@@ -197,15 +198,17 @@ export declare class ShoppingCart<T extends ShoppingCartItem> {
197
198
  * 构造函数
198
199
  * @param currency Currency ISO code
199
200
  * @param storage Data storage
201
+ * @param key Additional key
200
202
  */
201
- constructor(currency: string, storage?: IStorage);
203
+ constructor(currency: string, storage?: IStorage, key?: string);
202
204
  /**
203
205
  * Constructor
204
206
  * 构造函数
205
207
  * @param state Initialization state
206
208
  * @param storage Data storage
209
+ * @param key Additional key
207
210
  */
208
- constructor(state: ShoppingCartData<T>, storage?: IStorage);
211
+ constructor(state: ShoppingCartData<T>, storage?: IStorage, key?: string);
209
212
  private doChange;
210
213
  /**
211
214
  * Add item
@@ -8,10 +8,11 @@ export class ShoppingCart {
8
8
  * Create identifier key
9
9
  * 创建识别键
10
10
  * @param currency Currency
11
+ * @param key Additional key
11
12
  * @returns Result
12
13
  */
13
- static createKey(currency) {
14
- return `ETSOO-CART-${currency}`;
14
+ static createKey(currency, key = 'KEY') {
15
+ return `ETSOO-CART-${key}-${currency}`;
15
16
  }
16
17
  /**
17
18
  * Clear shopping cart
@@ -75,9 +76,9 @@ export class ShoppingCart {
75
76
  * 构造函数
76
77
  * @param currency Currency ISO code
77
78
  * @param storage Data storage
78
- * @param state Initialization state
79
+ * @param key Additional key
79
80
  */
80
- constructor(currencyOrState, storage = new WindowStorage()) {
81
+ constructor(currencyOrState, storage = new WindowStorage(), key) {
81
82
  var _a;
82
83
  this.storage = storage;
83
84
  /**
@@ -87,14 +88,14 @@ export class ShoppingCart {
87
88
  this.prices = {};
88
89
  const isCurrency = typeof currencyOrState === 'string';
89
90
  this.currency = isCurrency ? currencyOrState : currencyOrState.currency;
90
- const key = ShoppingCart.createKey(this.currency);
91
- this.identifier = key;
91
+ const id = ShoppingCart.createKey(this.currency, key);
92
+ this.identifier = id;
92
93
  this.symbol = NumberUtils.getCurrencySymbol(this.currency);
93
94
  let state;
94
95
  if (isCurrency) {
95
96
  try {
96
97
  state =
97
- (_a = storage.getPersistedObject(key)) !== null && _a !== void 0 ? _a : storage.getObject(key);
98
+ (_a = storage.getPersistedObject(id)) !== null && _a !== void 0 ? _a : storage.getObject(id);
98
99
  }
99
100
  catch (error) {
100
101
  console.log('ShoppingCart constructor', error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.3.91",
3
+ "version": "1.3.93",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -54,7 +54,7 @@
54
54
  "dependencies": {
55
55
  "@etsoo/notificationbase": "^1.1.24",
56
56
  "@etsoo/restclient": "^1.0.87",
57
- "@etsoo/shared": "^1.2.0",
57
+ "@etsoo/shared": "^1.2.1",
58
58
  "@types/crypto-js": "^4.1.1",
59
59
  "crypto-js": "^4.1.1"
60
60
  },
@@ -1237,23 +1237,35 @@ export abstract class CoreApp<
1237
1237
  getEnumList<E extends DataTypes.EnumBase = DataTypes.EnumBase>(
1238
1238
  em: E,
1239
1239
  prefix: string,
1240
- filter?: (
1241
- id: E[keyof E],
1242
- key: keyof E & string
1243
- ) => E[keyof E] | undefined
1240
+ filter?:
1241
+ | ((
1242
+ id: E[keyof E],
1243
+ key: keyof E & string
1244
+ ) => E[keyof E] | undefined)
1245
+ | E[keyof E][]
1244
1246
  ): ListType[] {
1245
1247
  const list: ListType[] = [];
1246
- const keys = DataTypes.getEnumKeys(em);
1247
- for (const key of keys) {
1248
- let id = em[key as keyof E];
1249
- if (filter) {
1250
- const fid = filter(id, key);
1251
- if (fid == null) continue;
1252
- id = fid;
1248
+
1249
+ if (Array.isArray(filter)) {
1250
+ filter.forEach((id) => {
1251
+ if (typeof id !== 'number') return;
1252
+ const key = DataTypes.getEnumKey(em, id);
1253
+ var label = this.get<string>(prefix + key) ?? key;
1254
+ list.push({ id, label });
1255
+ });
1256
+ } else {
1257
+ const keys = DataTypes.getEnumKeys(em);
1258
+ for (const key of keys) {
1259
+ let id = em[key as keyof E];
1260
+ if (filter) {
1261
+ const fid = filter(id, key);
1262
+ if (fid == null) continue;
1263
+ id = fid;
1264
+ }
1265
+ if (typeof id !== 'number') continue;
1266
+ var label = this.get<string>(prefix + key) ?? key;
1267
+ list.push({ id, label });
1253
1268
  }
1254
- if (typeof id !== 'number') continue;
1255
- var label = this.get<string>(prefix + key) ?? key;
1256
- list.push({ id, label });
1257
1269
  }
1258
1270
  return list;
1259
1271
  }
@@ -1322,14 +1334,8 @@ export abstract class CoreApp<
1322
1334
  * @param ids Limited ids
1323
1335
  * @returns list
1324
1336
  */
1325
- getStatusList(ids: EntityStatus[] = []) {
1326
- return this.getEnumList(
1327
- EntityStatus,
1328
- 'status',
1329
- ids.length > 0
1330
- ? (id, _key) => (ids.includes(id) ? id : undefined)
1331
- : undefined
1332
- );
1337
+ getStatusList(ids?: EntityStatus[]) {
1338
+ return this.getEnumList(EntityStatus, 'status', ids);
1333
1339
  }
1334
1340
 
1335
1341
  /**
package/src/app/IApp.ts CHANGED
@@ -434,10 +434,12 @@ export interface IApp {
434
434
  getEnumStrList<E extends DataTypes.EnumBase = DataTypes.EnumBase>(
435
435
  em: E,
436
436
  prefix: string,
437
- filter?: (
438
- id: E[keyof E],
439
- key: keyof E & string
440
- ) => E[keyof E] | undefined
437
+ filter?:
438
+ | ((
439
+ id: E[keyof E],
440
+ key: keyof E & string
441
+ ) => E[keyof E] | undefined)
442
+ | E[keyof E][]
441
443
  ): ListType1[];
442
444
 
443
445
  /**
@@ -130,10 +130,11 @@ export class ShoppingCart<T extends ShoppingCartItem> {
130
130
  * Create identifier key
131
131
  * 创建识别键
132
132
  * @param currency Currency
133
+ * @param key Additional key
133
134
  * @returns Result
134
135
  */
135
- static createKey(currency: string) {
136
- return `ETSOO-CART-${currency}`;
136
+ static createKey(currency: string, key: string = 'KEY') {
137
+ return `ETSOO-CART-${key}-${currency}`;
137
138
  }
138
139
 
139
140
  /**
@@ -262,41 +263,44 @@ export class ShoppingCart<T extends ShoppingCartItem> {
262
263
  * 构造函数
263
264
  * @param currency Currency ISO code
264
265
  * @param storage Data storage
266
+ * @param key Additional key
265
267
  */
266
- constructor(currency: string, storage?: IStorage);
268
+ constructor(currency: string, storage?: IStorage, key?: string);
267
269
 
268
270
  /**
269
271
  * Constructor
270
272
  * 构造函数
271
273
  * @param state Initialization state
272
274
  * @param storage Data storage
275
+ * @param key Additional key
273
276
  */
274
- constructor(state: ShoppingCartData<T>, storage?: IStorage);
277
+ constructor(state: ShoppingCartData<T>, storage?: IStorage, key?: string);
275
278
 
276
279
  /**
277
280
  * Constructor
278
281
  * 构造函数
279
282
  * @param currency Currency ISO code
280
283
  * @param storage Data storage
281
- * @param state Initialization state
284
+ * @param key Additional key
282
285
  */
283
286
  constructor(
284
287
  currencyOrState: string | ShoppingCartData<T>,
285
- private readonly storage: IStorage = new WindowStorage()
288
+ private readonly storage: IStorage = new WindowStorage(),
289
+ key?: string
286
290
  ) {
287
291
  const isCurrency = typeof currencyOrState === 'string';
288
292
  this.currency = isCurrency ? currencyOrState : currencyOrState.currency;
289
293
 
290
- const key = ShoppingCart.createKey(this.currency);
291
- this.identifier = key;
294
+ const id = ShoppingCart.createKey(this.currency, key);
295
+ this.identifier = id;
292
296
  this.symbol = NumberUtils.getCurrencySymbol(this.currency);
293
297
 
294
298
  let state: ShoppingCartData<T> | undefined;
295
299
  if (isCurrency) {
296
300
  try {
297
301
  state =
298
- storage.getPersistedObject<ShoppingCartData<T>>(key) ??
299
- storage.getObject<ShoppingCartData<T>>(key);
302
+ storage.getPersistedObject<ShoppingCartData<T>>(id) ??
303
+ storage.getObject<ShoppingCartData<T>>(id);
300
304
  } catch (error) {
301
305
  console.log('ShoppingCart constructor', error);
302
306
  }