@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,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
- @Immutable
18
- export class Pledge {
19
- #pledge;
20
- #status = {};
21
- #dbg;
22
- static #static = {};
23
- static STATE = secure({
24
- Pending: Symbol('pending'),
25
- Resolved: Symbol('resolved'),
26
- Rejected: Symbol('rejected')
27
- });
28
- /** initialize future Pledge instances */
29
- static init(arg) {
30
- if (isObject(arg)) {
31
- if (isEmpty(arg))
32
- Pledge.#static = {}; // reset static values
33
- Object.assign(Pledge.#static, ifDefined({ tag: arg.tag, debug: arg.debug, catch: arg.catch, }), ifDefined({ onResolve: arg.onResolve, onReject: arg.onReject, onSettle: arg.onSettle, }));
34
- }
35
- else {
36
- Object.assign(Pledge.#static, ifDefined({ tag: arg, }));
37
- }
38
- if (Pledge.#static.debug)
39
- console.log('Pledge: ', Pledge.#static); // debug
40
- return Pledge.status;
41
- }
42
- static get status() {
43
- return Pledge.#static;
44
- }
45
- /** use catch:boolean to determine whether to throw or return */
46
- #catch(...msg) {
47
- if (this.status.catch) {
48
- this.#dbg.warn(...msg); // catch, but warn {error}
49
- return;
50
- }
51
- this.#dbg.error(...msg); // assume {error}
52
- throw new Error(sprintf('pledge: ', ...msg));
53
- }
54
- constructor(arg) {
55
- this.#pledge = Promise.withResolvers();
56
- this.#status = { state: Pledge.STATE.Pending, ...Pledge.#static };
57
- if (isObject(arg)) {
58
- this.#dbg = new Logify({ debug: arg.debug, catch: arg.catch });
59
- Object.assign(this.#status, ifDefined({ tag: Pledge.#static.tag, debug: Pledge.#static.debug, catch: Pledge.#static.catch }), ifDefined({ tag: arg.tag, debug: arg.debug, catch: arg.catch, }));
60
- asArray(Pledge.#static.onResolve) // stack any static onResolve actions
61
- .concat(asArray(arg.onResolve)) // stack any instance onResolve actions
62
- .forEach(resolve => this.#pledge.promise.then(resolve));
63
- asArray(Pledge.#static.onReject) // stack any static onReject actions
64
- .concat(asArray(arg.onReject)) // stack any instance onReject actions
65
- .forEach(reject => this.#pledge.promise.catch(reject));
66
- asArray(Pledge.#static.onSettle) // stack any static onSettle actions
67
- .concat(asArray(arg.onSettle)) // stack any instance onSettle actions
68
- .forEach(settle => this.#pledge.promise.finally(settle));
69
- if (this.#status.catch) // stack a 'catch-all'
70
- this.#pledge.promise.catch(_ => this.#catch(this.#status, this.#status.error));
71
- }
72
- else {
73
- this.#dbg = new Logify();
74
- Object.assign(this.#status, ifDefined({ tag: arg ?? Pledge.#static.tag, }));
75
- }
76
- Object.freeze(this); // make this instance immutable
77
- }
78
- get [Symbol.toStringTag]() {
79
- return 'Pledge';
80
- }
81
- [Symbol.dispose]() {
82
- if (this.isPending)
83
- this.reject(new Error(`Pledge disposed`)); // discard pending Pledge (to notify wait-ers)
84
- }
85
- get status() {
86
- return cleanify(this.#status);
87
- }
88
- get promise() {
89
- return this.#pledge.promise;
90
- }
91
- get state() {
92
- return this.#status.state.description;
93
- }
94
- get isPending() {
95
- return this.#status.state === Pledge.STATE.Pending;
96
- }
97
- get isResolved() {
98
- return this.#status.state === Pledge.STATE.Resolved;
99
- }
100
- get isRejected() {
101
- return this.#status.state === Pledge.STATE.Rejected;
102
- }
103
- get isSettled() {
104
- return this.#status.state !== Pledge.STATE.Pending;
105
- }
106
- toString() {
107
- return JSON.stringify(this.status);
108
- }
109
- resolve(value) {
110
- if (this.isPending) {
111
- this.#status.settled = value;
112
- this.#status.state = Pledge.STATE.Resolved;
113
- this.#pledge.resolve(value); // resolve, then trigger any Pledge.onResolve, then Pledge.onSettle
114
- }
115
- else
116
- this.#dbg.warn(this.#status, `Pledge was already ${this.state}`);
117
- return this.#pledge.promise;
118
- }
119
- reject(error) {
120
- if (this.isPending) {
121
- this.#status.error = error;
122
- this.#status.state = Pledge.STATE.Rejected;
123
- this.#pledge.reject(error); // reject, then trigger any Pledge.onReject, then Pledge.onSettle
124
- }
125
- else
126
- this.#dbg.warn(this.#status, `Pledge was already ${this.state}`);
127
- return this.#pledge.promise;
128
- }
129
- then(fn) {
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 };
@@ -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';