@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.
- package/dist/cipher.class.js +117 -50
- package/dist/enumerate.library.js +55 -6
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -2
- package/dist/logify.class.js +88 -39
- package/dist/pledge.class.js +185 -115
- package/dist/tempo.class.d.ts +1 -0
- package/dist/tempo.class.js +1325 -1292
- package/package.json +5 -1
package/dist/pledge.class.js
CHANGED
|
@@ -1,3 +1,52 @@
|
|
|
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 __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
40
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
41
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
42
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
43
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
44
|
+
};
|
|
45
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
46
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
47
|
+
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");
|
|
48
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
49
|
+
};
|
|
1
50
|
import { Logify } from './logify.class.js';
|
|
2
51
|
import { asArray } from './array.library.js';
|
|
3
52
|
import { sprintf } from './string.library.js';
|
|
@@ -14,118 +63,139 @@ import { isEmpty, isObject } from './type.library.js';
|
|
|
14
63
|
new Pledge<T>(tag?: string)
|
|
15
64
|
```
|
|
16
65
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
this.#
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
this.#
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
66
|
+
let Pledge = (() => {
|
|
67
|
+
var _Pledge_static;
|
|
68
|
+
let _classDecorators = [Immutable];
|
|
69
|
+
let _classDescriptor;
|
|
70
|
+
let _classExtraInitializers = [];
|
|
71
|
+
let _classThis;
|
|
72
|
+
var Pledge = class {
|
|
73
|
+
static { _classThis = this; }
|
|
74
|
+
static { __setFunctionName(this, "Pledge"); }
|
|
75
|
+
static {
|
|
76
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
77
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
78
|
+
Pledge = _classThis = _classDescriptor.value;
|
|
79
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
80
|
+
}
|
|
81
|
+
#pledge;
|
|
82
|
+
#status = {};
|
|
83
|
+
#dbg;
|
|
84
|
+
static {
|
|
85
|
+
_Pledge_static = { value: {} };
|
|
86
|
+
}
|
|
87
|
+
static STATE = secure({
|
|
88
|
+
Pending: Symbol('pending'),
|
|
89
|
+
Resolved: Symbol('resolved'),
|
|
90
|
+
Rejected: Symbol('rejected')
|
|
91
|
+
});
|
|
92
|
+
/** initialize future Pledge instances */
|
|
93
|
+
static init(arg) {
|
|
94
|
+
if (isObject(arg)) {
|
|
95
|
+
if (isEmpty(arg))
|
|
96
|
+
__classPrivateFieldSet(Pledge, _classThis, {}, "f", _Pledge_static); // reset static values
|
|
97
|
+
Object.assign(__classPrivateFieldGet(Pledge, _classThis, "f", _Pledge_static), ifDefined({ tag: arg.tag, debug: arg.debug, catch: arg.catch, }), ifDefined({ onResolve: arg.onResolve, onReject: arg.onReject, onSettle: arg.onSettle, }));
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
Object.assign(__classPrivateFieldGet(Pledge, _classThis, "f", _Pledge_static), ifDefined({ tag: arg, }));
|
|
101
|
+
}
|
|
102
|
+
if (__classPrivateFieldGet(Pledge, _classThis, "f", _Pledge_static).debug)
|
|
103
|
+
console.log('Pledge: ', __classPrivateFieldGet(Pledge, _classThis, "f", _Pledge_static)); // debug
|
|
104
|
+
return Pledge.status;
|
|
105
|
+
}
|
|
106
|
+
static get status() {
|
|
107
|
+
return __classPrivateFieldGet(Pledge, _classThis, "f", _Pledge_static);
|
|
108
|
+
}
|
|
109
|
+
/** use catch:boolean to determine whether to throw or return */
|
|
110
|
+
#catch(...msg) {
|
|
111
|
+
if (this.status.catch) {
|
|
112
|
+
this.#dbg.warn(...msg); // catch, but warn {error}
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
this.#dbg.error(...msg); // assume {error}
|
|
116
|
+
throw new Error(sprintf('pledge: ', ...msg));
|
|
117
|
+
}
|
|
118
|
+
constructor(arg) {
|
|
119
|
+
this.#pledge = Promise.withResolvers();
|
|
120
|
+
this.#status = { state: Pledge.STATE.Pending, ...__classPrivateFieldGet(Pledge, _classThis, "f", _Pledge_static) };
|
|
121
|
+
if (isObject(arg)) {
|
|
122
|
+
this.#dbg = new Logify({ debug: arg.debug, catch: arg.catch });
|
|
123
|
+
Object.assign(this.#status, ifDefined({ tag: __classPrivateFieldGet(Pledge, _classThis, "f", _Pledge_static).tag, debug: __classPrivateFieldGet(Pledge, _classThis, "f", _Pledge_static).debug, catch: __classPrivateFieldGet(Pledge, _classThis, "f", _Pledge_static).catch }), ifDefined({ tag: arg.tag, debug: arg.debug, catch: arg.catch, }));
|
|
124
|
+
asArray(__classPrivateFieldGet(Pledge, _classThis, "f", _Pledge_static).onResolve) // stack any static onResolve actions
|
|
125
|
+
.concat(asArray(arg.onResolve)) // stack any instance onResolve actions
|
|
126
|
+
.forEach(resolve => this.#pledge.promise.then(resolve));
|
|
127
|
+
asArray(__classPrivateFieldGet(Pledge, _classThis, "f", _Pledge_static).onReject) // stack any static onReject actions
|
|
128
|
+
.concat(asArray(arg.onReject)) // stack any instance onReject actions
|
|
129
|
+
.forEach(reject => this.#pledge.promise.catch(reject));
|
|
130
|
+
asArray(__classPrivateFieldGet(Pledge, _classThis, "f", _Pledge_static).onSettle) // stack any static onSettle actions
|
|
131
|
+
.concat(asArray(arg.onSettle)) // stack any instance onSettle actions
|
|
132
|
+
.forEach(settle => this.#pledge.promise.finally(settle));
|
|
133
|
+
if (this.#status.catch) // stack a 'catch-all'
|
|
134
|
+
this.#pledge.promise.catch(_ => this.#catch(this.#status, this.#status.error));
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
this.#dbg = new Logify();
|
|
138
|
+
Object.assign(this.#status, ifDefined({ tag: arg ?? __classPrivateFieldGet(Pledge, _classThis, "f", _Pledge_static).tag, }));
|
|
139
|
+
}
|
|
140
|
+
Object.freeze(this); // make this instance immutable
|
|
141
|
+
}
|
|
142
|
+
get [Symbol.toStringTag]() {
|
|
143
|
+
return 'Pledge';
|
|
144
|
+
}
|
|
145
|
+
[Symbol.dispose]() {
|
|
146
|
+
if (this.isPending)
|
|
147
|
+
this.reject(new Error(`Pledge disposed`)); // discard pending Pledge (to notify wait-ers)
|
|
148
|
+
}
|
|
149
|
+
get status() {
|
|
150
|
+
return cleanify(this.#status);
|
|
151
|
+
}
|
|
152
|
+
get promise() {
|
|
153
|
+
return this.#pledge.promise;
|
|
154
|
+
}
|
|
155
|
+
get state() {
|
|
156
|
+
return this.#status.state.description;
|
|
157
|
+
}
|
|
158
|
+
get isPending() {
|
|
159
|
+
return this.#status.state === Pledge.STATE.Pending;
|
|
160
|
+
}
|
|
161
|
+
get isResolved() {
|
|
162
|
+
return this.#status.state === Pledge.STATE.Resolved;
|
|
163
|
+
}
|
|
164
|
+
get isRejected() {
|
|
165
|
+
return this.#status.state === Pledge.STATE.Rejected;
|
|
166
|
+
}
|
|
167
|
+
get isSettled() {
|
|
168
|
+
return this.#status.state !== Pledge.STATE.Pending;
|
|
169
|
+
}
|
|
170
|
+
toString() {
|
|
171
|
+
return JSON.stringify(this.status);
|
|
172
|
+
}
|
|
173
|
+
resolve(value) {
|
|
174
|
+
if (this.isPending) {
|
|
175
|
+
this.#status.settled = value;
|
|
176
|
+
this.#status.state = Pledge.STATE.Resolved;
|
|
177
|
+
this.#pledge.resolve(value); // resolve, then trigger any Pledge.onResolve, then Pledge.onSettle
|
|
178
|
+
}
|
|
179
|
+
else
|
|
180
|
+
this.#dbg.warn(this.#status, `Pledge was already ${this.state}`);
|
|
181
|
+
return this.#pledge.promise;
|
|
182
|
+
}
|
|
183
|
+
reject(error) {
|
|
184
|
+
if (this.isPending) {
|
|
185
|
+
this.#status.error = error;
|
|
186
|
+
this.#status.state = Pledge.STATE.Rejected;
|
|
187
|
+
this.#pledge.reject(error); // reject, then trigger any Pledge.onReject, then Pledge.onSettle
|
|
188
|
+
}
|
|
189
|
+
else
|
|
190
|
+
this.#dbg.warn(this.#status, `Pledge was already ${this.state}`);
|
|
191
|
+
return this.#pledge.promise;
|
|
192
|
+
}
|
|
193
|
+
then(fn) {
|
|
194
|
+
}
|
|
195
|
+
static {
|
|
196
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
return Pledge = _classThis;
|
|
200
|
+
})();
|
|
201
|
+
export { Pledge };
|
package/dist/tempo.class.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import './temporal.polyfill.js';
|
|
1
2
|
import type { IntRange, LiteralKey, LooseUnion, NonOptional, Property, Type } from './type.library.js';
|
|
2
3
|
import * as enums from './tempo.config/tempo.enum.js';
|
|
3
4
|
import { Token, Snippet, Layout, Event, Period } from './tempo.config/tempo.default.js';
|