@lowdefy/helpers 4.0.0-alpha.9 → 4.0.0-rc.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.
@@ -0,0 +1,46 @@
1
+ /*
2
+ Copyright 2020-2023 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ // https://stackoverflow.com/a/46432113/8295949
16
+ // Implementation of Least Recently Updated cache.
17
+ // It uses the fact that the implementation of Map keep track of item insertion order
18
+ let LRUCache = class LRUCache {
19
+ get(key) {
20
+ const item = this.cache.get(key);
21
+ if (item) {
22
+ // Refresh key.
23
+ this.cache.delete(key);
24
+ this.cache.set(key, item);
25
+ }
26
+ return item;
27
+ }
28
+ set(key, val) {
29
+ if (this.cache.has(key)) {
30
+ // Refresh key
31
+ this.cache.delete(key);
32
+ } else if (this.cache.size === this.maxSize) {
33
+ // Evict oldest
34
+ this.cache.delete(this.first());
35
+ }
36
+ this.cache.set(key, val);
37
+ }
38
+ first() {
39
+ return this.cache.keys().next().value;
40
+ }
41
+ constructor({ maxSize =100 } = {}){
42
+ this.maxSize = maxSize;
43
+ this.cache = new Map();
44
+ }
45
+ };
46
+ export default LRUCache;
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2022 Lowdefy, Inc
2
+ Copyright 2020-2023 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2022 Lowdefy, Inc
2
+ Copyright 2020-2023 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -12,11 +12,11 @@
12
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
- */ function createCachedPromises(getter) {
16
- const cache = new Map();
15
+ */ function createCachedPromises({ getter , cache }) {
17
16
  function cachedPromises(key) {
18
- if (cache.has(key)) {
19
- return Promise.resolve(cache.get(key));
17
+ const cached = cache.get(key);
18
+ if (cached) {
19
+ return Promise.resolve(cached);
20
20
  }
21
21
  const promise = getter(key);
22
22
  cache.set(key, promise);
package/dist/get.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable no-param-reassign */ /*
2
- Copyright 2020-2022 Lowdefy, Inc
2
+ Copyright 2020-2023 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2022 Lowdefy, Inc
2
+ Copyright 2020-2023 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
15
15
  */ import applyArrayIndices from './applyArrayIndices.js';
16
16
  import cachedPromises from './cachedPromises.js';
17
17
  import get from './get.js';
18
+ import LRUCache from './LRUCache.js';
18
19
  import mergeObjects from './mergeObjects.js';
19
20
  import omit from './omit.js';
20
21
  import serializer from './serializer.js';
@@ -25,4 +26,4 @@ import type from './type.js';
25
26
  import unset from './unset.js';
26
27
  import urlQuery from './urlQuery.js';
27
28
  import wait from './wait.js';
28
- export { applyArrayIndices, cachedPromises, get, mergeObjects, omit, serializer, set, stableStringify, swap, type, unset, urlQuery, wait };
29
+ export { applyArrayIndices, cachedPromises, get, LRUCache, mergeObjects, omit, serializer, set, stableStringify, swap, type, unset, urlQuery, wait };
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2022 Lowdefy, Inc
2
+ Copyright 2020-2023 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -18,8 +18,7 @@ import type from './type.js';
18
18
  const mergeObjects = (objects)=>{
19
19
  let merged = objects;
20
20
  if (type.isArray(objects)) {
21
- merged = merge(...objects.filter((obj)=>type.isObject(obj)
22
- ));
21
+ merged = merge(...objects.filter((obj)=>type.isObject(obj)));
23
22
  }
24
23
  return merged;
25
24
  };
package/dist/omit.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2022 Lowdefy, Inc
2
+ Copyright 2020-2023 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable no-param-reassign */ /*
2
- Copyright 2020-2022 Lowdefy, Inc
2
+ Copyright 2020-2023 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -17,13 +17,11 @@ import stableStringify from './stableStringify.js';
17
17
  const makeReplacer = (customReplacer, isoStringDates)=>(key, value)=>{
18
18
  let dateReplacer = (date)=>({
19
19
  _date: date.valueOf()
20
- })
21
- ;
20
+ });
22
21
  if (isoStringDates) {
23
22
  dateReplacer = (date)=>({
24
23
  _date: date.toISOString()
25
- })
26
- ;
24
+ });
27
25
  }
28
26
  let newValue = value;
29
27
  if (customReplacer) {
@@ -59,8 +57,7 @@ const makeReplacer = (customReplacer, isoStringDates)=>(key, value)=>{
59
57
  });
60
58
  }
61
59
  return newValue;
62
- }
63
- ;
60
+ };
64
61
  const makeReviver = (customReviver)=>(key, value)=>{
65
62
  let newValue = value;
66
63
  if (customReviver) {
@@ -85,8 +82,7 @@ const makeReviver = (customReviver)=>(key, value)=>{
85
82
  return result;
86
83
  }
87
84
  return newValue;
88
- }
89
- ;
85
+ };
90
86
  const serialize = (json, options = {})=>{
91
87
  if (type.isUndefined(json)) return json;
92
88
  if (type.isDate(json)) {
package/dist/set.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable no-plusplus */ /* eslint-disable no-use-before-define */ /* eslint-disable no-param-reassign */ /*
2
- Copyright 2020-2022 Lowdefy, Inc
2
+ Copyright 2020-2023 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable no-continue */ /* eslint-disable no-plusplus */ /* eslint-disable consistent-return */ /* eslint-disable no-param-reassign */ /*
2
- Copyright 2020-2022 Lowdefy, Inc
2
+ Copyright 2020-2023 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -39,8 +39,7 @@ function stableStringify(obj, opts) {
39
39
  let space = opts.space || '';
40
40
  if (typeof space === 'number') space = Array(space + 1).join(' ');
41
41
  const cycles = typeof opts.cycles === 'boolean' ? opts.cycles : false;
42
- const replacer = opts.replacer || ((key, value)=>value
43
- );
42
+ const replacer = opts.replacer || ((key, value)=>value);
44
43
  const cmp = opts.cmp && ((f)=>{
45
44
  return (node)=>{
46
45
  return (a, b)=>{
@@ -57,7 +56,7 @@ function stableStringify(obj, opts) {
57
56
  };
58
57
  })(opts.cmp);
59
58
  const seen = [];
60
- return (function stringify(parent, key, node, level) {
59
+ return function stringify(parent, key, node, level) {
61
60
  const indent = space ? `\n${new Array(level + 1).join(space)}` : '';
62
61
  const colonSeparator = space ? ': ' : ':';
63
62
  if (node && node.toJSON && typeof node.toJSON === 'function') {
@@ -83,17 +82,17 @@ function stableStringify(obj, opts) {
83
82
  throw new TypeError('Converting circular structure to JSON');
84
83
  } else seen.push(node);
85
84
  const keys = Object.keys(node).sort(cmp && cmp(node));
86
- const out = [];
87
- for(let i = 0; i < keys.length; i++){
88
- const ky = keys[i];
85
+ const out1 = [];
86
+ for(let i1 = 0; i1 < keys.length; i1++){
87
+ const ky = keys[i1];
89
88
  const value = stringify(node, ky, node[ky], level + 1);
90
89
  if (!value) continue;
91
90
  const keyValue = JSON.stringify(ky) + colonSeparator + value;
92
- out.push(indent + space + keyValue);
91
+ out1.push(indent + space + keyValue);
93
92
  }
94
93
  seen.splice(seen.indexOf(node), 1);
95
- return `{${out.join(',')}${indent}}`;
96
- })({
94
+ return `{${out1.join(',')}${indent}}`;
95
+ }({
97
96
  '': obj
98
97
  }, '', obj, 0);
99
98
  }
package/dist/swap.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2022 Lowdefy, Inc
2
+ Copyright 2020-2023 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
package/dist/type.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable indent */ /* eslint-disable default-case */ /*
2
- Copyright 2020-2022 Lowdefy, Inc
2
+ Copyright 2020-2023 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -65,12 +65,12 @@ function kindOf(val) {
65
65
  // eslint-disable-next-line no-void
66
66
  if (val === void 0) return 'undefined';
67
67
  if (val === null) return 'null';
68
- let type1 = typeof val;
69
- if (type1 === 'boolean') return 'boolean';
70
- if (type1 === 'string') return 'string';
71
- if (type1 === 'number') return 'number';
72
- if (type1 === 'symbol') return 'symbol';
73
- if (type1 === 'function') {
68
+ let type = typeof val;
69
+ if (type === 'boolean') return 'boolean';
70
+ if (type === 'string') return 'string';
71
+ if (type === 'number') return 'number';
72
+ if (type === 'symbol') return 'symbol';
73
+ if (type === 'function') {
74
74
  return isGeneratorFn(val) ? 'generatorfunction' : 'function';
75
75
  }
76
76
  if (isArray(val)) return 'array';
@@ -119,8 +119,8 @@ function kindOf(val) {
119
119
  return 'generator';
120
120
  }
121
121
  // Non-plain objects
122
- type1 = toString.call(val);
123
- switch(type1){
122
+ type = toString.call(val);
123
+ switch(type){
124
124
  case '[object Object]':
125
125
  return 'object';
126
126
  // iterators
@@ -134,7 +134,7 @@ function kindOf(val) {
134
134
  return 'arrayiterator';
135
135
  }
136
136
  // other
137
- return type1.slice(8, -1).toLowerCase().replace(/\s/g, '');
137
+ return type.slice(8, -1).toLowerCase().replace(/\s/g, '');
138
138
  }
139
139
  const reISO = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*))(?:Z|(\+|-)([\d|:]*))?$/;
140
140
  function isDateString(val) {
@@ -146,39 +146,25 @@ type.isArray = isArray;
146
146
  type.isDate = isDate;
147
147
  type.isError = isError;
148
148
  type.isDateString = isDateString;
149
- type.isObject = (value)=>kindOf(value) === 'object'
150
- ;
151
- type.isString = (value)=>typeof value === 'string'
152
- ;
153
- type.isRegExp = (value)=>kindOf(value) === 'regexp'
154
- ;
155
- type.isFunction = (value)=>kindOf(value) === 'function'
156
- ;
157
- type.isBoolean = (value)=>typeof value === 'boolean'
158
- ;
159
- type.isNumber = (value)=>typeof value === 'number' && Number.isFinite(value)
160
- ;
161
- type.isNumeric = (value)=>!Number.isNaN(Number(value))
162
- ;
163
- type.isInt = (value)=>Number.isInteger(value) === true
164
- ;
165
- type.isSet = (value)=>kindOf(value) === 'set'
166
- ;
167
- type.isNull = (value)=>kindOf(value) === 'null'
168
- ;
169
- type.isUndefined = (value)=>kindOf(value) === 'undefined'
170
- ;
171
- type.isNone = (value)=>kindOf(value) === 'undefined' || kindOf(value) === 'null'
172
- ;
173
- type.isPrimitive = (value)=>kindOf(value) === 'undefined' || kindOf(value) === 'null' || kindOf(value) === 'string' || kindOf(value) === 'number' || kindOf(value) === 'boolean' || kindOf(value) === 'date'
174
- ;
175
- type.isEmptyObject = (value)=>kindOf(value) === 'object' && Object.keys(value).length === 0
176
- ;
149
+ type.isObject = (value)=>kindOf(value) === 'object';
150
+ type.isString = (value)=>typeof value === 'string';
151
+ type.isRegExp = (value)=>kindOf(value) === 'regexp';
152
+ type.isFunction = (value)=>kindOf(value) === 'function';
153
+ type.isBoolean = (value)=>typeof value === 'boolean';
154
+ type.isNumber = (value)=>typeof value === 'number' && Number.isFinite(value);
155
+ type.isNumeric = (value)=>!Number.isNaN(Number(value));
156
+ type.isInt = (value)=>Number.isInteger(value) === true;
157
+ type.isSet = (value)=>kindOf(value) === 'set';
158
+ type.isNull = (value)=>kindOf(value) === 'null';
159
+ type.isUndefined = (value)=>kindOf(value) === 'undefined';
160
+ type.isNone = (value)=>kindOf(value) === 'undefined' || kindOf(value) === 'null';
161
+ type.isPrimitive = (value)=>kindOf(value) === 'undefined' || // are we making undefined a primative ?
162
+ kindOf(value) === 'null' || kindOf(value) === 'string' || kindOf(value) === 'number' || kindOf(value) === 'boolean' || kindOf(value) === 'date';
163
+ type.isEmptyObject = (value)=>kindOf(value) === 'object' && Object.keys(value).length === 0;
177
164
  // Lowdefy operator types
178
165
  function isName(value) {
179
166
  if (!type.isString(value)) return false;
180
- const noLeadingNumeric = value.split('.').reduce((acc, val)=>acc && !type.isNumeric(val.charAt(0))
181
- , true);
167
+ const noLeadingNumeric = value.split('.').reduce((acc, val)=>acc && !type.isNumeric(val.charAt(0)), true);
182
168
  const noLeadTrailStop = value.charAt(0) !== '.' && value.charAt(value.length - 1) !== '.';
183
169
  const noLowdefy = !value.toLowerCase().startsWith('lowdefy');
184
170
  return /^[a-zA-Z0-9_.]+$/g.test(value) && noLeadTrailStop && noLeadingNumeric && noLowdefy;
package/dist/unset.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable no-param-reassign */ /*
2
- Copyright 2020-2022 Lowdefy, Inc
2
+ Copyright 2020-2023 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
package/dist/urlQuery.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2022 Lowdefy, Inc
2
+ Copyright 2020-2023 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
package/dist/wait.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2022 Lowdefy, Inc
2
+ Copyright 2020-2023 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -13,7 +13,6 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ async function wait(ms) {
16
- return new Promise((resolve)=>setTimeout(resolve, ms)
17
- );
16
+ return new Promise((resolve)=>setTimeout(resolve, ms));
18
17
  }
19
18
  export default wait;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lowdefy/helpers",
3
- "version": "4.0.0-alpha.9",
4
- "licence": "Apache-2.0",
3
+ "version": "4.0.0-rc.1",
4
+ "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
7
7
  "keywords": [
@@ -31,25 +31,25 @@
31
31
  "dist/*"
32
32
  ],
33
33
  "scripts": {
34
- "build": "yarn swc",
34
+ "build": "swc src --out-dir dist --config-file ../../../.swcrc --delete-dir-on-start",
35
35
  "clean": "rm -rf dist",
36
- "prepare": "yarn build",
37
- "swc": "swc src --out-dir dist --config-file ../../../.swcrc --delete-dir-on-start",
38
- "test": "jest --coverage"
36
+ "prepublishOnly": "pnpm build",
37
+ "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
39
38
  },
40
39
  "dependencies": {
41
40
  "lodash.merge": "4.6.2",
42
- "query-string": "7.1.0"
41
+ "query-string": "8.1.0"
43
42
  },
44
43
  "devDependencies": {
45
- "@swc/cli": "0.1.55",
46
- "@swc/core": "1.2.135",
47
- "@swc/jest": "0.2.17",
48
- "jest": "27.5.1",
49
- "jest-diff": "27.5.1"
44
+ "@jest/globals": "28.1.0",
45
+ "@swc/cli": "0.1.59",
46
+ "@swc/core": "1.3.24",
47
+ "@swc/jest": "0.2.24",
48
+ "jest": "28.1.0",
49
+ "jest-diff": "28.1.0"
50
50
  },
51
51
  "publishConfig": {
52
52
  "access": "public"
53
53
  },
54
- "gitHead": "98b544eca231bdcfca6c3a8601a891835d5ce571"
54
+ "gitHead": "ecc4f16c19eede929eda177db524cf13a8053379"
55
55
  }