@orioro/util 0.15.0 → 0.16.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @orioro/util
2
2
 
3
+ ## 0.16.0
4
+
5
+ ### Minor Changes
6
+
7
+ - expose generateClientId method
8
+
9
+ ## 0.15.1
10
+
11
+ ### Patch Changes
12
+
13
+ - substitute arrayChunk for lodash-es chunk
14
+
3
15
  ## 0.15.0
4
16
 
5
17
  ### Minor Changes
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Generates a client id enough for locally identifying objects
3
+ * in the client application context.
4
+ *
5
+ * Should not be used for situations in which crypto randomness
6
+ * is required.
7
+ */
8
+ export declare function generateClientId(): string;
package/dist/index.d.ts CHANGED
@@ -13,3 +13,4 @@ export * from './slugify';
13
13
  export * from './hookFn';
14
14
  export * from './deprecate';
15
15
  export * from './url';
16
+ export * from './generateClientId';
package/dist/index.js CHANGED
@@ -1176,7 +1176,7 @@ function batchFn(itemFn) {
1176
1176
  itemFn = timeout ? withTimeout(itemFn, timeout) : itemFn;
1177
1177
  return function batchExec(items) {
1178
1178
  var _this = this;
1179
- var batches = arrayChunk(items, batchSize);
1179
+ var batches = lodashEs.chunk(items, batchSize);
1180
1180
  var promise = new PromiseLikeEventEmitter();
1181
1181
  // const events = new EventEmitter<EventTypes>()
1182
1182
  var progressCount = 0;
@@ -2031,6 +2031,30 @@ function url(spec) {
2031
2031
  }
2032
2032
  }
2033
2033
 
2034
+ //
2035
+ // For contexts in which crypto.randomUUID is not available
2036
+ // (non https, older browsers, etc)
2037
+ //
2038
+ function nonCryptoUUIDv4() {
2039
+ // RFC 4122–compliant v4 UUID (non-crypto fallback)
2040
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
2041
+ var r = Math.random() * 16 | 0;
2042
+ var v = c === 'x' ? r : r & 0x3 | 0x8;
2043
+ return v.toString(16);
2044
+ });
2045
+ }
2046
+ /**
2047
+ * Generates a client id enough for locally identifying objects
2048
+ * in the client application context.
2049
+ *
2050
+ * Should not be used for situations in which crypto randomness
2051
+ * is required.
2052
+ */
2053
+ function generateClientId() {
2054
+ var _a, _b;
2055
+ return (_b = (_a = crypto === null || crypto === void 0 ? void 0 : crypto.randomUUID) === null || _a === void 0 ? void 0 : _a.call(crypto)) !== null && _b !== void 0 ? _b : nonCryptoUUIDv4();
2056
+ }
2057
+
2034
2058
  exports.DEFAULT_TYPES = DEFAULT_TYPES;
2035
2059
  exports.PromiseLikeEventEmitter = PromiseLikeEventEmitter;
2036
2060
  exports.SKIPPED = SKIPPED;
@@ -2045,6 +2069,7 @@ exports.deprecateFn = deprecateFn;
2045
2069
  exports.deprecateInput = deprecateInput;
2046
2070
  exports.deprecateProperty = deprecateProperty;
2047
2071
  exports.fetchAllPages = fetchAllPages;
2072
+ exports.generateClientId = generateClientId;
2048
2073
  exports.hasNestedPromises = hasNestedPromises;
2049
2074
  exports.hookFn = hookFn;
2050
2075
  exports.inMemoryDataStore = inMemoryDataStore;
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { keyBy, get, set } from 'lodash-es';
1
+ import { keyBy, get, set, chunk } from 'lodash-es';
2
2
  import EventEmitter from 'eventemitter3';
3
3
  import copy from 'fast-copy';
4
4
  import traverse from 'traverse';
@@ -1174,7 +1174,7 @@ function batchFn(itemFn) {
1174
1174
  itemFn = timeout ? withTimeout(itemFn, timeout) : itemFn;
1175
1175
  return function batchExec(items) {
1176
1176
  var _this = this;
1177
- var batches = arrayChunk(items, batchSize);
1177
+ var batches = chunk(items, batchSize);
1178
1178
  var promise = new PromiseLikeEventEmitter();
1179
1179
  // const events = new EventEmitter<EventTypes>()
1180
1180
  var progressCount = 0;
@@ -2029,4 +2029,28 @@ function url(spec) {
2029
2029
  }
2030
2030
  }
2031
2031
 
2032
- export { DEFAULT_TYPES, PromiseLikeEventEmitter, SKIPPED, TimeoutError, arrayChunk, arrayLikeIterable, batchFn, dataJoin, debugFn, deepFreeze, deprecateFn, deprecateInput, deprecateProperty, fetchAllPages, hasNestedPromises, hookFn, inMemoryDataStore, interpolate, isPromise, isValidUrl, makeDeferred, makeTypeOf, maybeAsyncFn, maybeFn, maybeReturnPromise, normalizeString, paginatedHttpFetch, parseBatchedResults, pickPaths, promiseReduce, resolveNestedPromises, sequentialCallIdGenerator, slugify, strExpr, switchExec, switchValue, syntheticJson, typeMap, typeOf, untilConditionIsSatisfiedReducer, url, wait, withTimeout };
2032
+ //
2033
+ // For contexts in which crypto.randomUUID is not available
2034
+ // (non https, older browsers, etc)
2035
+ //
2036
+ function nonCryptoUUIDv4() {
2037
+ // RFC 4122–compliant v4 UUID (non-crypto fallback)
2038
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
2039
+ var r = Math.random() * 16 | 0;
2040
+ var v = c === 'x' ? r : r & 0x3 | 0x8;
2041
+ return v.toString(16);
2042
+ });
2043
+ }
2044
+ /**
2045
+ * Generates a client id enough for locally identifying objects
2046
+ * in the client application context.
2047
+ *
2048
+ * Should not be used for situations in which crypto randomness
2049
+ * is required.
2050
+ */
2051
+ function generateClientId() {
2052
+ var _a, _b;
2053
+ return (_b = (_a = crypto === null || crypto === void 0 ? void 0 : crypto.randomUUID) === null || _a === void 0 ? void 0 : _a.call(crypto)) !== null && _b !== void 0 ? _b : nonCryptoUUIDv4();
2054
+ }
2055
+
2056
+ export { DEFAULT_TYPES, PromiseLikeEventEmitter, SKIPPED, TimeoutError, arrayChunk, arrayLikeIterable, batchFn, dataJoin, debugFn, deepFreeze, deprecateFn, deprecateInput, deprecateProperty, fetchAllPages, generateClientId, hasNestedPromises, hookFn, inMemoryDataStore, interpolate, isPromise, isValidUrl, makeDeferred, makeTypeOf, maybeAsyncFn, maybeFn, maybeReturnPromise, normalizeString, paginatedHttpFetch, parseBatchedResults, pickPaths, promiseReduce, resolveNestedPromises, sequentialCallIdGenerator, slugify, strExpr, switchExec, switchValue, syntheticJson, typeMap, typeOf, untilConditionIsSatisfiedReducer, url, wait, withTimeout };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orioro/util",
3
- "version": "0.15.0",
3
+ "version": "0.16.0",
4
4
  "packageManager": "yarn@4.0.2",
5
5
  "type": "module",
6
6
  "main": "dist/index.mjs",
@@ -21,10 +21,10 @@
21
21
  "build": "rollup --config ./rollup.config.mjs",
22
22
  "test": "jest",
23
23
  "dev": "jest --watch",
24
- "prepublish": "yarn build"
24
+ "prepare": "yarn build && yarn readme"
25
25
  },
26
26
  "devDependencies": {
27
- "@orioro/dev": "^0.0.5",
27
+ "@orioro/dev": "^0.0.6",
28
28
  "@orioro/jest-util": "^2.0.2",
29
29
  "@types/clone-deep": "^4.0.4",
30
30
  "@types/jest": "^29.5.12",