@magmacomputing/tempo 1.0.0 → 1.0.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.
@@ -1,3 +1,46 @@
1
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
2
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
3
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
4
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
5
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
6
+ var _, done = false;
7
+ for (var i = decorators.length - 1; i >= 0; i--) {
8
+ var context = {};
9
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
10
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
11
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
12
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
13
+ if (kind === "accessor") {
14
+ if (result === void 0) continue;
15
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
16
+ if (_ = accept(result.get)) descriptor.get = _;
17
+ if (_ = accept(result.set)) descriptor.set = _;
18
+ if (_ = accept(result.init)) initializers.unshift(_);
19
+ }
20
+ else if (_ = accept(result)) {
21
+ if (kind === "field") initializers.unshift(_);
22
+ else descriptor[key] = _;
23
+ }
24
+ }
25
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
26
+ done = true;
27
+ };
28
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
29
+ var useValue = arguments.length > 2;
30
+ for (var i = 0; i < initializers.length; i++) {
31
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
32
+ }
33
+ return useValue ? value : void 0;
34
+ };
35
+ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
36
+ if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
37
+ return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
38
+ };
39
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
40
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
41
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
42
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
43
+ };
1
44
  import { toHex } from './number.library.js';
2
45
  import { asString } from './string.library.js';
3
46
  import { Immutable, Static } from './class.library.js';
@@ -12,54 +55,78 @@ const keys = {
12
55
  TypeKey: 'AES-GCM',
13
56
  };
14
57
  /** Static-only cryptographic methods */
15
- @Immutable
16
- @Static // prevent instantiation
17
- export class Cipher {
18
- static #cryptoKey = subtle.generateKey({ name: keys.TypeKey, length: 128 }, false, ['encrypt', 'decrypt']);
19
- static #vector = crypto.getRandomValues(new Uint8Array(16));
20
- static #asymmetricKey = subtle.generateKey({
21
- name: keys.SignKey,
22
- modulusLength: 2048,
23
- publicExponent: new Uint8Array([1, 0, 1]),
24
- hash: { name: keys.Algorithm },
25
- }, false, ['sign', 'verify']);
26
- /** random UUID */
27
- static randomKey = () => crypto.randomUUID().split('-')[0];
28
- /** decode base64 back into object */
29
- static decodeBase64 = (buf = '') => {
30
- const uint8 = base64DecToArr(buf); // first, convert to UInt8Array
31
- const str = UTF8ArrToStr(uint8); // convert to string
32
- return objectify(str); // rebuild the original object
33
- };
34
- /** encode object into base64 */
35
- static encodeBase64 = (buf) => {
36
- const str = stringify(buf); // first, stringify the incoming buffer
37
- const uint8 = strToUTF8Arr(str); // convert to Uint8Array
38
- return base64EncArr(uint8); // convert to string
39
- };
40
- static hmac = async (source, secret, alg = 'SHA-512', len) => {
41
- const encoder = new TextEncoder();
42
- const keyData = encoder.encode(secret);
43
- const messageData = encoder.encode(asString(source));
44
- const key = await subtle.importKey('raw', keyData, { name: 'HMAC', hash: { name: alg } }, false, ['sign']);
45
- const signature = await subtle.sign('HMAC', key, messageData);
46
- return toHex(Array.from(new Uint8Array(signature)), len);
47
- };
48
- static hash = async (source, len, alg = 'SHA-256') => {
49
- const buffer = Cipher.encodeBuffer(asString(source));
50
- const hash = await subtle.digest(alg, buffer);
51
- return toHex(Array.from(new Uint8Array(hash)), len);
58
+ let Cipher = (() => {
59
+ var _Cipher_cryptoKey, _Cipher_vector, _Cipher_asymmetricKey;
60
+ let _classDecorators = [Immutable, Static];
61
+ let _classDescriptor;
62
+ let _classExtraInitializers = [];
63
+ let _classThis;
64
+ var Cipher = class {
65
+ static { _classThis = this; }
66
+ static { __setFunctionName(this, "Cipher"); }
67
+ static {
68
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
69
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
70
+ Cipher = _classThis = _classDescriptor.value;
71
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
72
+ }
73
+ static {
74
+ _Cipher_cryptoKey = { value: subtle.generateKey({ name: keys.TypeKey, length: 128 }, false, ['encrypt', 'decrypt']) };
75
+ }
76
+ static {
77
+ _Cipher_vector = { value: crypto.getRandomValues(new Uint8Array(16)) };
78
+ }
79
+ static {
80
+ _Cipher_asymmetricKey = { value: subtle.generateKey({
81
+ name: keys.SignKey,
82
+ modulusLength: 2048,
83
+ publicExponent: new Uint8Array([1, 0, 1]),
84
+ hash: { name: keys.Algorithm },
85
+ }, false, ['sign', 'verify']) };
86
+ }
87
+ /** random UUID */
88
+ static randomKey = () => crypto.randomUUID().split('-')[0];
89
+ /** decode base64 back into object */
90
+ static decodeBase64 = (buf = '') => {
91
+ const uint8 = base64DecToArr(buf); // first, convert to UInt8Array
92
+ const str = UTF8ArrToStr(uint8); // convert to string
93
+ return objectify(str); // rebuild the original object
94
+ };
95
+ /** encode object into base64 */
96
+ static encodeBase64 = (buf) => {
97
+ const str = stringify(buf); // first, stringify the incoming buffer
98
+ const uint8 = strToUTF8Arr(str); // convert to Uint8Array
99
+ return base64EncArr(uint8); // convert to string
100
+ };
101
+ static hmac = async (source, secret, alg = 'SHA-512', len) => {
102
+ const encoder = new TextEncoder();
103
+ const keyData = encoder.encode(secret);
104
+ const messageData = encoder.encode(asString(source));
105
+ const key = await subtle.importKey('raw', keyData, { name: 'HMAC', hash: { name: alg } }, false, ['sign']);
106
+ const signature = await subtle.sign('HMAC', key, messageData);
107
+ return toHex(Array.from(new Uint8Array(signature)), len);
108
+ };
109
+ static hash = async (source, len, alg = 'SHA-256') => {
110
+ const buffer = Cipher.encodeBuffer(asString(source));
111
+ const hash = await subtle.digest(alg, buffer);
112
+ return toHex(Array.from(new Uint8Array(hash)), len);
113
+ };
114
+ static encodeBuffer = (str) => new Uint16Array(new TextEncoder().encode(str));
115
+ static decodeBuffer = (buf) => new TextDecoder(keys.Encoding).decode(buf);
116
+ static encrypt = async (data) => subtle.encrypt({ name: keys.TypeKey, iv: __classPrivateFieldGet(Cipher, _classThis, "f", _Cipher_vector) }, await __classPrivateFieldGet(Cipher, _classThis, "f", _Cipher_cryptoKey), Cipher.encodeBuffer(data))
117
+ .then(result => new Uint16Array(result))
118
+ .then(Cipher.decodeBuffer);
119
+ static decrypt = async (secret) => subtle.decrypt({ name: keys.TypeKey, iv: __classPrivateFieldGet(Cipher, _classThis, "f", _Cipher_vector) }, await __classPrivateFieldGet(Cipher, _classThis, "f", _Cipher_cryptoKey), await secret)
120
+ .then(result => new Uint16Array(result))
121
+ .then(Cipher.decodeBuffer);
122
+ static sign = async (doc) => subtle.sign(keys.SignKey, (await __classPrivateFieldGet(Cipher, _classThis, "f", _Cipher_asymmetricKey)).privateKey, Cipher.encodeBuffer(doc))
123
+ .then(result => new Uint16Array(result))
124
+ .then(Cipher.decodeBuffer);
125
+ static verify = async (signature, doc) => subtle.verify(keys.SignKey, (await __classPrivateFieldGet(Cipher, _classThis, "f", _Cipher_asymmetricKey)).publicKey, await signature, Cipher.encodeBuffer(doc));
126
+ static {
127
+ __runInitializers(_classThis, _classExtraInitializers);
128
+ }
52
129
  };
53
- static encodeBuffer = (str) => new Uint16Array(new TextEncoder().encode(str));
54
- static decodeBuffer = (buf) => new TextDecoder(keys.Encoding).decode(buf);
55
- static encrypt = async (data) => subtle.encrypt({ name: keys.TypeKey, iv: Cipher.#vector }, await Cipher.#cryptoKey, Cipher.encodeBuffer(data))
56
- .then(result => new Uint16Array(result))
57
- .then(Cipher.decodeBuffer);
58
- static decrypt = async (secret) => subtle.decrypt({ name: keys.TypeKey, iv: Cipher.#vector }, await Cipher.#cryptoKey, await secret)
59
- .then(result => new Uint16Array(result))
60
- .then(Cipher.decodeBuffer);
61
- static sign = async (doc) => subtle.sign(keys.SignKey, (await Cipher.#asymmetricKey).privateKey, Cipher.encodeBuffer(doc))
62
- .then(result => new Uint16Array(result))
63
- .then(Cipher.decodeBuffer);
64
- static verify = async (signature, doc) => subtle.verify(keys.SignKey, (await Cipher.#asymmetricKey).publicKey, await signature, Cipher.encodeBuffer(doc));
65
- }
130
+ return Cipher = _classThis;
131
+ })();
132
+ export { Cipher };
@@ -1,3 +1,37 @@
1
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
2
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
3
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
4
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
5
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
6
+ var _, done = false;
7
+ for (var i = decorators.length - 1; i >= 0; i--) {
8
+ var context = {};
9
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
10
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
11
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
12
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
13
+ if (kind === "accessor") {
14
+ if (result === void 0) continue;
15
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
16
+ if (_ = accept(result.get)) descriptor.get = _;
17
+ if (_ = accept(result.set)) descriptor.set = _;
18
+ if (_ = accept(result.init)) initializers.unshift(_);
19
+ }
20
+ else if (_ = accept(result)) {
21
+ if (kind === "field") initializers.unshift(_);
22
+ else descriptor[key] = _;
23
+ }
24
+ }
25
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
26
+ done = true;
27
+ };
28
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
29
+ var useValue = arguments.length > 2;
30
+ for (var i = 0; i < initializers.length; i++) {
31
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
32
+ }
33
+ return useValue ? value : void 0;
34
+ };
1
35
  import { secure } from './utility.library.js';
2
36
  import { Serializable } from './class.library.js';
3
37
  import { stringify } from './serialize.library.js';
@@ -46,9 +80,24 @@ export function enumify(list) {
46
80
  return secure(Object.create(ENUM, Object.getOwnPropertyDescriptors(stash)));
47
81
  }
48
82
  /** create an entry in the Serialization Registry to describe how to rebuild an Enum */
49
- @Serializable
50
- export class Enumify {
51
- constructor(list) {
52
- return enumify(list);
53
- }
54
- }
83
+ let Enumify = (() => {
84
+ let _classDecorators = [Serializable];
85
+ let _classDescriptor;
86
+ let _classExtraInitializers = [];
87
+ let _classThis;
88
+ var Enumify = class {
89
+ static { _classThis = this; }
90
+ static {
91
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
92
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
93
+ Enumify = _classThis = _classDescriptor.value;
94
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
95
+ __runInitializers(_classThis, _classExtraInitializers);
96
+ }
97
+ constructor(list) {
98
+ return enumify(list);
99
+ }
100
+ };
101
+ return Enumify = _classThis;
102
+ })();
103
+ export { Enumify };
package/dist/index.d.ts CHANGED
@@ -1 +1,2 @@
1
+ import './temporal.polyfill.js';
1
2
  export { Tempo } from './tempo.class.js';
package/dist/index.js CHANGED
@@ -1,3 +1,2 @@
1
+ import './temporal.polyfill.js';
1
2
  export { Tempo } from './tempo.class.js';
2
- // Add any other intended public exports here.
3
- // For now, Tempo is the primary interface.
@@ -1,3 +1,37 @@
1
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
2
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
3
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
4
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
5
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
6
+ var _, done = false;
7
+ for (var i = decorators.length - 1; i >= 0; i--) {
8
+ var context = {};
9
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
10
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
11
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
12
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
13
+ if (kind === "accessor") {
14
+ if (result === void 0) continue;
15
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
16
+ if (_ = accept(result.get)) descriptor.get = _;
17
+ if (_ = accept(result.set)) descriptor.set = _;
18
+ if (_ = accept(result.init)) initializers.unshift(_);
19
+ }
20
+ else if (_ = accept(result)) {
21
+ if (kind === "field") initializers.unshift(_);
22
+ else descriptor[key] = _;
23
+ }
24
+ }
25
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
26
+ done = true;
27
+ };
28
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
29
+ var useValue = arguments.length > 2;
30
+ for (var i = 0; i < initializers.length; i++) {
31
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
32
+ }
33
+ return useValue ? value : void 0;
34
+ };
1
35
  import { Immutable } from './class.library.js';
2
36
  import { asType } from './type.library.js';
3
37
  const Method = {
@@ -10,44 +44,59 @@ const Method = {
10
44
  /**
11
45
  * provide standard logging methods to the console for a class
12
46
  */
13
- @Immutable
14
- export class Logify {
15
- #name;
16
- #opts = {};
17
- #log(method, ...msg) {
18
- if (this.#opts.debug)
19
- console[method](this.#name, ...msg);
20
- }
21
- /**
22
- * if {catch:true} then show a warning on the console and return
23
- * otherwise show an error on the console and re-throw the error
24
- */
25
- catch(...msg) {
26
- if (this.#opts.catch) {
27
- this.warn(...msg); // show a warning on the console
28
- return; // safe-return
47
+ let Logify = (() => {
48
+ let _classDecorators = [Immutable];
49
+ let _classDescriptor;
50
+ let _classExtraInitializers = [];
51
+ let _classThis;
52
+ var Logify = class {
53
+ static { _classThis = this; }
54
+ static {
55
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
56
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
57
+ Logify = _classThis = _classDescriptor.value;
58
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
59
+ __runInitializers(_classThis, _classExtraInitializers);
29
60
  }
30
- this.error(...msg); // this goes to the console
31
- throw new Error(`${this.#name}${msg}`); // this goes back to the caller
32
- }
33
- /** console.log */ log = this.#log.bind(this, Method.Log);
34
- /** console.info */ info = this.#log.bind(this, Method.Info);
35
- /** console.warn */ warn = this.#log.bind(this, Method.Warn);
36
- /** console.debug */ debug = this.#log.bind(this, Method.Debug);
37
- /** console.error */ error = this.#log.bind(this, Method.Error);
38
- constructor(self, opts = {}) {
39
- const arg = asType(self);
40
- switch (arg.type) {
41
- case 'String':
42
- this.#name = arg.value;
43
- break;
44
- // @ts-ignore
45
- case 'Object':
46
- Object.assign(opts, arg.value);
47
- default:
48
- this.#name = (self ?? this).constructor.name.concat(': ') ?? '';
61
+ #name;
62
+ #opts = {};
63
+ #log(method, ...msg) {
64
+ if (this.#opts.debug)
65
+ console[method](this.#name, ...msg);
49
66
  }
50
- this.#opts.debug = opts.debug ?? false; // default debug to 'false'
51
- this.#opts.catch = opts.catch ?? false; // default catch to 'false'
52
- }
53
- }
67
+ /**
68
+ * if {catch:true} then show a warning on the console and return
69
+ * otherwise show an error on the console and re-throw the error
70
+ */
71
+ catch(...msg) {
72
+ if (this.#opts.catch) {
73
+ this.warn(...msg); // show a warning on the console
74
+ return; // safe-return
75
+ }
76
+ this.error(...msg); // this goes to the console
77
+ throw new Error(`${this.#name}${msg}`); // this goes back to the caller
78
+ }
79
+ /** console.log */ log = this.#log.bind(this, Method.Log);
80
+ /** console.info */ info = this.#log.bind(this, Method.Info);
81
+ /** console.warn */ warn = this.#log.bind(this, Method.Warn);
82
+ /** console.debug */ debug = this.#log.bind(this, Method.Debug);
83
+ /** console.error */ error = this.#log.bind(this, Method.Error);
84
+ constructor(self, opts = {}) {
85
+ const arg = asType(self);
86
+ switch (arg.type) {
87
+ case 'String':
88
+ this.#name = arg.value;
89
+ break;
90
+ // @ts-ignore
91
+ case 'Object':
92
+ Object.assign(opts, arg.value);
93
+ default:
94
+ this.#name = (self ?? this).constructor.name.concat(': ') ?? '';
95
+ }
96
+ this.#opts.debug = opts.debug ?? false; // default debug to 'false'
97
+ this.#opts.catch = opts.catch ?? false; // default catch to 'false'
98
+ }
99
+ };
100
+ return Logify = _classThis;
101
+ })();
102
+ export { Logify };