@lumjs/core 1.15.0 → 1.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.
@@ -0,0 +1,107 @@
1
+ 0 verbose cli /usr/bin/node /usr/bin/npm
2
+ 1 info using npm@9.7.1
3
+ 2 info using node@v18.16.0
4
+ 3 timing npm:load:whichnode Completed in 1ms
5
+ 4 timing config:load:defaults Completed in 1ms
6
+ 5 timing config:load:file:/usr/lib/node_modules/npm/npmrc Completed in 1ms
7
+ 6 timing config:load:builtin Completed in 1ms
8
+ 7 timing config:load:cli Completed in 1ms
9
+ 8 timing config:load:env Completed in 0ms
10
+ 9 timing config:load:file:/system/docs/dev/js/lumjs/core/.npmrc Completed in 0ms
11
+ 10 timing config:load:project Completed in 1ms
12
+ 11 timing config:load:file:/home/novus/.npmrc Completed in 1ms
13
+ 12 timing config:load:user Completed in 1ms
14
+ 13 timing config:load:file:/usr/etc/npmrc Completed in 0ms
15
+ 14 timing config:load:global Completed in 0ms
16
+ 15 timing config:load:setEnvs Completed in 1ms
17
+ 16 timing config:load Completed in 6ms
18
+ 17 timing npm:load:configload Completed in 6ms
19
+ 18 timing config:load:flatten Completed in 1ms
20
+ 19 timing npm:load:mkdirpcache Completed in 0ms
21
+ 20 timing npm:load:mkdirplogs Completed in 0ms
22
+ 21 verbose title npm publish
23
+ 22 verbose argv "publish"
24
+ 23 timing npm:load:setTitle Completed in 0ms
25
+ 24 timing npm:load:display Completed in 1ms
26
+ 25 verbose logfile logs-max:10 dir:/home/novus/.npm/_logs/2023-06-08T19_55_05_247Z-
27
+ 26 verbose logfile /home/novus/.npm/_logs/2023-06-08T19_55_05_247Z-debug-0.log
28
+ 27 timing npm:load:logFile Completed in 5ms
29
+ 28 timing npm:load:timers Completed in 0ms
30
+ 29 timing npm:load:configScope Completed in 0ms
31
+ 30 timing npm:load Completed in 22ms
32
+ 31 verbose publish [ '.' ]
33
+ 32 silly logfile start cleaning logs, removing 1 files
34
+ 33 silly logfile done cleaning log files
35
+ 34 timing arborist:ctor Completed in 0ms
36
+ 35 notice
37
+ 36 notice 📦 @lumjs/core@1.16.0
38
+ 37 notice === Tarball Contents ===
39
+ 38 notice 928B README.md
40
+ 38 notice 627B TODO.md
41
+ 38 notice 501B jsdoc.json
42
+ 38 notice 8.6kB lib/arrays.js
43
+ 38 notice 6.4kB lib/context.js
44
+ 38 notice 5.8kB lib/enum.js
45
+ 38 notice 1.3kB lib/flags.js
46
+ 38 notice 3.6kB lib/index.js
47
+ 38 notice 3.8kB lib/meta.js
48
+ 38 notice 3.6kB lib/modules.js
49
+ 38 notice 1.2kB lib/obj/apply.js
50
+ 38 notice 12.1kB lib/obj/clone.js
51
+ 38 notice 1.2kB lib/obj/copyall.js
52
+ 38 notice 12.5kB lib/obj/copyprops.js
53
+ 38 notice 3.2kB lib/obj/getmethods.js
54
+ 38 notice 1.2kB lib/obj/getproperty.js
55
+ 38 notice 870B lib/obj/index.js
56
+ 38 notice 2.2kB lib/obj/lock.js
57
+ 38 notice 2.8kB lib/obj/merge.js
58
+ 38 notice 6.8kB lib/obj/ns.js
59
+ 38 notice 2.5kB lib/objectid.js
60
+ 38 notice 8.7kB lib/observable.js
61
+ 38 notice 2.2kB lib/opt.js
62
+ 38 notice 5.3kB lib/strings.js
63
+ 38 notice 6.0kB lib/types/basics.js
64
+ 38 notice 4.7kB lib/types/console.js
65
+ 38 notice 7.2kB lib/types/def.js
66
+ 38 notice 1.1kB lib/types/dt.js
67
+ 38 notice 1.8kB lib/types/index.js
68
+ 38 notice 4.9kB lib/types/isa.js
69
+ 38 notice 457B lib/types/js.js
70
+ 38 notice 7.2kB lib/types/lazy.js
71
+ 38 notice 3.4kB lib/types/needs.js
72
+ 38 notice 2.7kB lib/types/root.js
73
+ 38 notice 3.8kB lib/types/stringify.js
74
+ 38 notice 5.5kB lib/types/typelist.js
75
+ 38 notice 826B package.json
76
+ 39 notice === Tarball Details ===
77
+ 40 notice name: @lumjs/core
78
+ 40 notice version: 1.16.0
79
+ 40 notice filename: lumjs-core-1.16.0.tgz
80
+ 40 notice package size: 42.7 kB
81
+ 40 notice unpacked size: 147.6 kB
82
+ 40 notice shasum: 424727206c94f94fbf8e18c5f62eab4aa64e52af
83
+ 40 notice integrity: sha512-iPLVQTAe/Bf8P[...]TV8PNxn6/ji5A==
84
+ 40 notice total files: 37
85
+ 41 notice
86
+ 42 notice Publishing to https://registry.npmjs.org/ with tag latest and default access
87
+ 43 http fetch PUT 401 https://registry.npmjs.org/@lumjs%2fcore 277ms
88
+ 44 timing command:publish Completed in 367ms
89
+ 45 verbose stack HttpErrorGeneral: 401 Unauthorized - PUT https://registry.npmjs.org/@lumjs%2fcore - unexpected status code from "get-packument" = 401
90
+ 45 verbose stack at /usr/lib/node_modules/npm/node_modules/npm-registry-fetch/lib/check-response.js:95:15
91
+ 45 verbose stack at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
92
+ 45 verbose stack at async publish (/usr/lib/node_modules/npm/node_modules/libnpmpublish/lib/publish.js:54:17)
93
+ 45 verbose stack at async otplease (/usr/lib/node_modules/npm/lib/utils/otplease.js:4:12)
94
+ 45 verbose stack at async Publish.exec (/usr/lib/node_modules/npm/lib/commands/publish.js:123:7)
95
+ 45 verbose stack at async module.exports (/usr/lib/node_modules/npm/lib/cli-entry.js:61:5)
96
+ 46 verbose statusCode 401
97
+ 47 verbose pkgid @lumjs/core@1.16.0
98
+ 48 verbose cwd /system/docs/dev/js/lumjs/core
99
+ 49 verbose Linux 5.10.0-22-amd64
100
+ 50 verbose node v18.16.0
101
+ 51 verbose npm v9.7.1
102
+ 52 error code E401
103
+ 53 error 401 Unauthorized - PUT https://registry.npmjs.org/@lumjs%2fcore - unexpected status code from "get-packument" = 401
104
+ 54 verbose exit 1
105
+ 55 timing npm Completed in 495ms
106
+ 56 verbose code 1
107
+ 57 error A complete log of this run can be found in: /home/novus/.npm/_logs/2023-06-08T19_55_05_247Z-debug-0.log
@@ -0,0 +1,52 @@
1
+ const {F,isObj} = require('../types');
2
+ const copyProps = require('./copyprops');
3
+
4
+ /**
5
+ * Apply functions to an object
6
+ *
7
+ * In addition to the parameters passed, we'll also define:
8
+ *
9
+ * - `cp` will be a `CopyProps` instance via `copyProps.cache.into(obj)`;
10
+ * - `args` will be an array of `[obj, opts]`;
11
+ * - `opts` will be an object of `{obj, cp, args}`;
12
+ *
13
+ * @param {(object|function)} obj - The target we're applying to.
14
+ *
15
+ * @param {...(function|object)} fns - Values we are applying.
16
+ *
17
+ * For each value of `fns` as `fn`:
18
+ *
19
+ * - If a `function` we'll call `fn.apply(obj, args)`;
20
+ * - If an `object` we'll call `cp.from(fn)`.
21
+ *
22
+ * @returns {object} `obj`
23
+ * @throws {TypeError} If a `fns` value is not valid.
24
+ * @alias module:@lumjs/core/obj.apply
25
+ */
26
+ function apply(obj, ...fns)
27
+ {
28
+ const cp = copyProps.cache.into(obj);
29
+ const opts = {obj, cp};
30
+ const args = [obj, opts];
31
+ opts.args = args;
32
+
33
+ for (const fn of fns)
34
+ {
35
+ if (typeof fn === F)
36
+ {
37
+ fn.apply(obj, args);
38
+ }
39
+ else if (isObj(fn))
40
+ {
41
+ cp.from(fn);
42
+ }
43
+ else
44
+ {
45
+ throw new TypeError("invalid parameter value");
46
+ }
47
+ }
48
+
49
+ return obj;
50
+ }
51
+
52
+ module.exports = apply;
@@ -39,7 +39,7 @@ exports.duplicateOne = copyAll.clone = obj => copyAll({}, obj);
39
39
  *
40
40
  * Use `copyProps.into({}).from(...sources)` for a more robust version.
41
41
  *
42
- * Alias: `copyAll.clone`
42
+ * Alias: `copyAll.duplicate`
43
43
  *
44
44
  * @alias module:@lumjs/core/obj.duplicateOne
45
45
  * @param {object} obj - The object to duplicate.
@@ -1,7 +1,7 @@
1
1
 
2
2
  // Get some constants
3
- const {B,N,F,isObj,isArray,needObj,def,console} = require('../types');
4
- const {duplicateOne: clone} = require('./copyall');
3
+ const {S,B,N,F,isObj,isArray,needObj,def,console} = require('../types');
4
+ const {copyAll, duplicateOne: clone} = require('./copyall');
5
5
 
6
6
  const RECURSE_NONE = 0;
7
7
  const RECURSE_ALL = -1;
@@ -233,22 +233,35 @@ def(copyProps, 'RECURSE_LIST', RECURSE_LIST);
233
233
  * // Get a copy of the `copyProps` function.
234
234
  * const cp = require('@lumjs/core').obj.copyProps;
235
235
  *
236
- * // Starting with the target:
236
+ * // Starting with the target(s):
237
237
  * cp.into(targetObj).given({all: true}).from(source1, source2);
238
238
  *
239
- * // Starting with the sources:
239
+ * // Starting with the source(s):
240
240
  * cp.from(sourceObj).given({exclude: ['dontCopy']}).into(target1, target2);
241
241
  *
242
242
  * // Starting with the options:
243
243
  * cp.given({recursive: cp.RECURSE_ALL}).from(source1, source2).into(target1, target2);
244
244
  *
245
+ * // Call `cp.into()` and cache the instance in a `Map`.
246
+ * // Future calls with the same `targetObj` will return the cached instance.
247
+ * // Unlike `cp.into()`, only supports a single `targetObj`.
248
+ * cp.cache.into(targetObj);
249
+ *
250
+ * // Call `cp.from()` and cache the instance in a `Map`.
251
+ * // Future calls with the same `sourceObj` will return the cached instance.
252
+ * // Unlike `cp.from()`, only supports a single `sourceObj`.
253
+ * cp.cache.from(sourceObj);
245
254
  *
255
+ * // Clear the `Map` instances for `cp.cache.into` and `cp.cache.from`
256
+ * cp.cache.clear();
257
+ *
246
258
  * ```
247
259
  *
248
260
  * @alias module:@lumjs/core/obj~CopyProps
249
261
  */
250
262
  class $CopyProps
251
263
  {
264
+ // Constructor is private so we won't document it.
252
265
  constructor(opts={})
253
266
  {
254
267
  this.opts = opts;
@@ -257,21 +270,42 @@ class $CopyProps
257
270
  }
258
271
 
259
272
  /**
260
- * Set a single option.
261
- * @param {string} name - The option name
262
- * @param {*} value - The option value
273
+ * Set options.
274
+ *
275
+ * @param {(string|object)} opt - Option(s) to set.
276
+ *
277
+ * If this is a `string` it's the name of an option to set.
278
+ * If this is an `object`, it's map of options to set with `copyAll`.
279
+ *
280
+ * @param {*} value - The option value.
281
+ *
282
+ * Only used if `option` is a `string`.
283
+ *
263
284
  * @returns {object} `this`
264
285
  */
265
- set(name, value)
286
+ set(opt, value)
266
287
  {
267
- this.opts[name] = value;
288
+ //console.debug("CopyProps.set(", opt, value, ')');
289
+ if (typeof opt === S)
290
+ { // Set a single option.
291
+ this.opts[opt] = value;
292
+ }
293
+ else if (isObj(opt))
294
+ { // Set a bunch of options.
295
+ copyAll(this.opts, opt);
296
+ }
297
+ else
298
+ { // That's not supported
299
+ console.error("invalid opt", {opt, value, cp: this});
300
+ }
301
+ //console.debug("CopyProps.set:after", this);
268
302
  return this;
269
303
  }
270
304
 
271
305
  /**
272
- * Set all of the options.
306
+ * Set all options.
273
307
  *
274
- * This replaces the currently set options entirely.
308
+ * This replaces any existing options entirely.
275
309
  *
276
310
  * @param {object} opts - The options to set.
277
311
  * @returns {object} `this`
@@ -372,4 +406,48 @@ copyProps.from = function(...sources)
372
406
  return ((new $CopyProps()).from(...sources));
373
407
  }
374
408
 
409
+ const CPC = copyProps.cache =
410
+ {
411
+ into(target)
412
+ {
413
+ if (this.intoCache === undefined)
414
+ this.intoCache = new Map();
415
+ const cache = this.intoCache;
416
+ if (cache.has(target))
417
+ {
418
+ return cache.get(target);
419
+ }
420
+ else
421
+ {
422
+ const cp = copyProps.into(target);
423
+ cache.set(target, cp);
424
+ return cp;
425
+ }
426
+ },
427
+ from(source)
428
+ {
429
+ if (this.fromCache === undefined)
430
+ this.fromCache = new Map();
431
+ const cache = this.fromCache;
432
+ if (cache.has(source))
433
+ {
434
+ return cache.get(source);
435
+ }
436
+ else
437
+ {
438
+ const cp = copyProps.from(source);
439
+ cache.set(source, cp);
440
+ return cp;
441
+ }
442
+ },
443
+ clear()
444
+ {
445
+ if (this.intoCache)
446
+ this.intoCache.clear();
447
+ if (this.fromCache)
448
+ this.fromCache.clear();
449
+ return this;
450
+ },
451
+ };
452
+
375
453
  module.exports = copyProps;
package/lib/obj/index.js CHANGED
@@ -3,6 +3,7 @@
3
3
  * @module @lumjs/core/obj
4
4
  */
5
5
 
6
+ const apply = require('./apply');
6
7
  const {copyAll,duplicateOne,duplicateAll} = require('./copyall');
7
8
  const copyProps = require('./copyprops');
8
9
  const {CLONE,clone,addClone,cloneIfLocked} = require('./clone');
@@ -23,5 +24,5 @@ module.exports =
23
24
  mergeNested, syncNested, copyProps, copyAll, ns,
24
25
  getObjectPath, setObjectPath, getNamespace, setNamespace,
25
26
  getProperty, duplicateAll, duplicateOne, getMethods, signatureOf,
26
- MethodFilter,
27
+ MethodFilter, apply,
27
28
  }
package/lib/observable.js CHANGED
@@ -1,4 +1,4 @@
1
-
1
+ // Defining these after observable.
2
2
  const {B,F,S,def,isObj,isComplex,TYPES,console} = require('./types');
3
3
  const {duplicateAll: clone} = require('./obj/copyall');
4
4
  const lock = Object.freeze;
@@ -150,7 +150,7 @@ function observable (el={}, opts={})
150
150
 
151
151
  let fobj;
152
152
 
153
- if (wrapthis || wrapargs)
153
+ if (wrapped)
154
154
  { // Something is going to use our wrapper object.
155
155
  const isWild = (name === wildcard);
156
156
  const fname = isWild ? (addname ? args[0] : args.shift()) : name;
@@ -2,7 +2,7 @@ const def = require('./def');
2
2
  const {F} = require('./js');
3
3
 
4
4
  /**
5
- * A super simple wrapper around the Javascript console.
5
+ * A super simple singleton wrapper around the Javascript console.
6
6
  *
7
7
  * By default includes `info`, `log`, `warn`, and `error` methods.
8
8
  * It may be expanded further using the `addMethod` method.
@@ -14,25 +14,68 @@ const LC =
14
14
  /**
15
15
  * A custom handler.
16
16
  *
17
- * If a `function`, will be passed the console method name as the
18
- * first parameter, and method arguments as subsequent parameters.
17
+ * If a `function`, it will be called to handle all method calls.
19
18
  *
20
19
  * If an `Array`, it will have all log entries added as objects with
21
- * `time`, `method`, and `arguments` properties.
20
+ * at least `time`, `method`, and `opts` properties.
21
+ * By default and `arguments` property will also be included.
22
+ * See `msgArguments` and `msgArgs` for further details.
22
23
  *
23
24
  * If the boolean value `false`, all output will be thrown into the void.
24
25
  *
25
- * Any other value (including the default `null`), passes the method call
26
- * through to the real console object.
26
+ * If it is an `object`, then each property name represents a method name,
27
+ * and the values will be treated as a handler for that method only.
28
+ * All handler types are supported (i.e. `function`, `Array`, or `false`.)
29
+ * A special method name of `DEFAULT` may be specified as a default handler
30
+ * for method names not explicitly specified in the object.
31
+ * If no `DEFAULT` is specified and there is no handler value for a method
32
+ * name, calls to it will be passed through to the real console object.
33
+ *
34
+ * If no handler was set, all methods are passed to the real console object.
35
+ *
36
+ * Default value: `null`
27
37
  */
28
- handler: null,
38
+ handler: null,
39
+
29
40
  /**
30
41
  * Return the message object?
31
42
  *
32
43
  * Only applicable if `handler` is an `Array`.
33
- * If true, return the message object. If false, returns void/undefined.
44
+ *
45
+ * If `true`, return the message `object`.
46
+ * If `false`, returns `undefined`.
47
+ *
48
+ * Default value: `false`
49
+ */
50
+ returnMsg: false,
51
+
52
+ /**
53
+ * The name to include the `arguments` magic object in the log.
54
+ *
55
+ * Only applicable if `handler` is an `Array`.
56
+ *
57
+ * This used to be hard-coded as `"arguments"` but the `shortArgs`
58
+ * option has replaced it as the array is simpler for most purposes.
59
+ *
60
+ * Default value: `null`
61
+ */
62
+ msgArguments: null,
63
+
64
+ /**
65
+ * The name to include the `args` array in the log.
66
+ *
67
+ * Only applicable if `handler` is an `Array`.
68
+ *
69
+ * Default value: `"arguments"`
34
70
  */
35
- returnMsg: false
71
+ msgArgs: 'arguments',
72
+
73
+ /**
74
+ * Use the method name as the first argument in function calls.
75
+ *
76
+ * Default value: `true`
77
+ */
78
+ methodArg: true,
36
79
  }
37
80
 
38
81
  /**
@@ -45,6 +88,12 @@ def(LC, 'real', RC);
45
88
  // Only including a few common ones.
46
89
  const DEFAULT_METHODS = ['debug','info','log','warn','error'];
47
90
 
91
+ // Options that can be changed via handler settings.
92
+ const HANDLER_OPTIONS =
93
+ [
94
+ 'returnMsg', 'methodArg', 'msgArguments', 'msgArgs'
95
+ ];
96
+
48
97
  /**
49
98
  * Add a wrapper method to the console wrapper object.
50
99
  * @param {string} method - The console method to wrap.
@@ -52,25 +101,75 @@ const DEFAULT_METHODS = ['debug','info','log','warn','error'];
52
101
  */
53
102
  function addMethod(method)
54
103
  {
55
- def(LC, method, function()
104
+ def(LC, method, function(...args)
56
105
  {
57
- if (typeof LC.handler === F)
58
- { // A custom handler.
59
- return LC.handler(method, ...arguments);
106
+ if (typeof LC.trigger === F)
107
+ { // Support for core.observable(core.types.console);
108
+ LC.trigger(method, ...args);
109
+ }
110
+
111
+ let handler = LC.handler;
112
+ const opts = {}
113
+
114
+ function checkHandlerOptions(src)
115
+ {
116
+ for (const opt of HANDLER_OPTIONS)
117
+ {
118
+ if (src[opt] !== undefined)
119
+ {
120
+ opts[opt] = src[opt];
121
+ }
122
+ }
123
+ }
124
+
125
+ // Get the default options.
126
+ checkHandlerOptions(LC);
127
+
128
+ // Check for complex handler definitions as a plain object.
129
+ if (isObj(handler) && !Array.isArray(handler))
130
+ { // Look for options in the handler defs.
131
+ checkHandlerOptions(handler);
132
+
133
+ if (handler[method] !== undefined)
134
+ { // A handler for that method was found.
135
+ handler = handler[method];
136
+ }
137
+ else if (handler.DEFAULT !== undefined)
138
+ { // A default handler.
139
+ handler = handler.DEFAULT;
140
+ }
60
141
  }
61
- else if (Array.isArray(LC.handler))
62
- { // Add a message item.
142
+
143
+ if (typeof handler === F)
144
+ { // A custom handler function.
145
+ checkHandlerOptions(handler);
146
+ if (opts.methodArg)
147
+ args.unshift(method)
148
+ return handler(...args);
149
+ }
150
+ else if (Array.isArray(handler))
151
+ { // Add a message item to a log array.
152
+ checkHandlerOptions(handler);
153
+
63
154
  const time = new Date().toJSON();
64
- const msg = {time, method, arguments};
65
- LC.handler.push(msg);
66
- if (LC.returnMsg) return msg;
155
+ const msg = {time, method, opts};
156
+
157
+ if (typeof opts.msgArguments === S)
158
+ msg[opts.msgArguments] = arguments;
159
+ if (typeof opts.msgArgs === S)
160
+ msg[opts.msgArgs] = args;
161
+
162
+ handler.push(msg);
163
+
164
+ if (opts.returnMsg) return msg;
67
165
  }
68
- else if (LC.handler !== false)
166
+ else if (handler !== false)
69
167
  { // Pass through to the real console.
70
- return RC[method](...arguments);
168
+ return RC[method](...args);
71
169
  }
72
170
  });
73
171
  }
172
+
74
173
  def(LC, 'addMethod', addMethod);
75
174
 
76
175
  for (const method of DEFAULT_METHODS)
@@ -35,6 +35,7 @@ const
35
35
  * @property {string} NIL - Either `null` or `undefined`.
36
36
  * @property {string} NOTNIL - Anything other than `null` or `undefined`.
37
37
  * @property {string} MAP - A `Map` object.
38
+ * @property {string} SET - A `Set` object.
38
39
  * @property {object} tests - A map of tests for the above types.
39
40
  */
40
41
  const TYPES = {};
@@ -162,6 +163,7 @@ const
162
163
  NIL: isNil,
163
164
  NOTNIL: notNil,
164
165
  MAP: v => v instanceof Map,
166
+ SET: v => v instanceof Set,
165
167
  });
166
168
 
167
169
  module.exports = TYPES;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lumjs/core",
3
- "version": "1.15.0",
3
+ "version": "1.16.0",
4
4
  "main": "lib/index.js",
5
5
  "exports":
6
6
  {