@outfoxx/sunday 1.0.8 → 1.0.10
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/LICENSE.txt +203 -0
- package/README.md +36 -2
- package/build/date-time-types.d.ts +35 -0
- package/build/date-time-types.js +699 -0
- package/build/date-time-types.js.map +1 -0
- package/build/event-parser.d.ts +17 -0
- package/build/event-parser.js +151 -0
- package/build/event-parser.js.map +1 -0
- package/build/fetch-event-source.d.ts +66 -0
- package/build/fetch-event-source.js +365 -0
- package/build/fetch-event-source.js.map +1 -0
- package/build/fetch-request-factory.d.ts +32 -0
- package/build/fetch-request-factory.js +316 -0
- package/build/fetch-request-factory.js.map +1 -0
- package/build/fetch.d.ts +9 -0
- package/build/fetch.js +140 -0
- package/build/fetch.js.map +1 -0
- package/build/header-parameters.d.ts +3 -0
- package/build/header-parameters.js +82 -0
- package/build/header-parameters.js.map +1 -0
- package/build/index.d.ts +26 -0
- package/build/index.js +41 -0
- package/build/index.js.map +1 -0
- package/{dist → build}/logger.d.ts +9 -0
- package/build/logger.js +36 -0
- package/build/logger.js.map +1 -0
- package/build/media-type-codecs/any-text-decoder.d.ts +7 -0
- package/build/media-type-codecs/any-text-decoder.js +29 -0
- package/build/media-type-codecs/any-text-decoder.js.map +1 -0
- package/build/media-type-codecs/any-text-encoder.d.ts +6 -0
- package/build/media-type-codecs/any-text-encoder.js +27 -0
- package/build/media-type-codecs/any-text-encoder.js.map +1 -0
- package/build/media-type-codecs/binary-decoder.d.ts +7 -0
- package/build/media-type-codecs/binary-decoder.js +33 -0
- package/build/media-type-codecs/binary-decoder.js.map +1 -0
- package/build/media-type-codecs/binary-encoder.d.ts +6 -0
- package/build/media-type-codecs/binary-encoder.js +30 -0
- package/build/media-type-codecs/binary-encoder.js.map +1 -0
- package/build/media-type-codecs/cbor-decoder.d.ts +13 -0
- package/build/media-type-codecs/cbor-decoder.js +38 -0
- package/build/media-type-codecs/cbor-decoder.js.map +1 -0
- package/build/media-type-codecs/cbor-encoder.d.ts +12 -0
- package/build/media-type-codecs/cbor-encoder.js +36 -0
- package/build/media-type-codecs/cbor-encoder.js.map +1 -0
- package/build/media-type-codecs/cbor-tags.d.ts +6 -0
- package/build/media-type-codecs/cbor-tags.js +20 -0
- package/build/media-type-codecs/cbor-tags.js.map +1 -0
- package/build/media-type-codecs/default-policies.d.ts +3 -0
- package/build/media-type-codecs/default-policies.js +33 -0
- package/build/media-type-codecs/default-policies.js.map +1 -0
- package/build/media-type-codecs/json-decoder.d.ts +14 -0
- package/build/media-type-codecs/json-decoder.js +40 -0
- package/build/media-type-codecs/json-decoder.js.map +1 -0
- package/build/media-type-codecs/json-encoder.d.ts +13 -0
- package/build/media-type-codecs/json-encoder.js +43 -0
- package/build/media-type-codecs/json-encoder.js.map +1 -0
- package/build/media-type-codecs/media-type-decoder.d.ts +14 -0
- package/build/media-type-codecs/media-type-decoder.js +18 -0
- package/build/media-type-codecs/media-type-decoder.js.map +1 -0
- package/build/media-type-codecs/media-type-decoders.d.ts +16 -0
- package/build/media-type-codecs/media-type-decoders.js +63 -0
- package/build/media-type-codecs/media-type-decoders.js.map +1 -0
- package/build/media-type-codecs/media-type-encoder.d.ts +12 -0
- package/build/media-type-codecs/media-type-encoder.js +22 -0
- package/build/media-type-codecs/media-type-encoder.js.map +1 -0
- package/build/media-type-codecs/media-type-encoders.d.ts +16 -0
- package/build/media-type-codecs/media-type-encoders.js +65 -0
- package/build/media-type-codecs/media-type-encoders.js.map +1 -0
- package/build/media-type-codecs/www-form-url-encoder.d.ts +31 -0
- package/build/media-type-codecs/www-form-url-encoder.js +281 -0
- package/build/media-type-codecs/www-form-url-encoder.js.map +1 -0
- package/build/media-type.d.ts +94 -0
- package/build/media-type.js +305 -0
- package/build/media-type.js.map +1 -0
- package/build/problem.d.ts +35 -0
- package/build/problem.js +122 -0
- package/build/problem.js.map +1 -0
- package/build/request-adapters.d.ts +23 -0
- package/build/request-adapters.js +53 -0
- package/build/request-adapters.js.map +1 -0
- package/build/request-factory.d.ts +39 -0
- package/build/request-factory.js +15 -0
- package/build/request-factory.js.map +1 -0
- package/build/result-response.d.ts +4 -0
- package/build/result-response.js +15 -0
- package/build/result-response.js.map +1 -0
- package/build/schema-builtins.d.ts +21 -0
- package/build/schema-builtins.js +201 -0
- package/build/schema-builtins.js.map +1 -0
- package/build/schema-policy.d.ts +31 -0
- package/build/schema-policy.js +41 -0
- package/build/schema-policy.js.map +1 -0
- package/build/schema-runtime.d.ts +25 -0
- package/build/schema-runtime.js +77 -0
- package/build/schema-runtime.js.map +1 -0
- package/build/sunday-error.d.ts +10 -0
- package/build/sunday-error.js +36 -0
- package/build/sunday-error.js.map +1 -0
- package/build/url-template.js +33 -0
- package/build/url-template.js.map +1 -0
- package/build/util/async-iterables.d.ts +15 -0
- package/build/util/async-iterables.js +179 -0
- package/build/util/async-iterables.js.map +1 -0
- package/build/util/errors.d.ts +2 -0
- package/build/util/errors.js +65 -0
- package/build/util/errors.js.map +1 -0
- package/build/util/nullify.d.ts +5 -0
- package/build/util/nullify.js +37 -0
- package/build/util/nullify.js.map +1 -0
- package/build/util/numbers.d.ts +11 -0
- package/build/util/numbers.js +41 -0
- package/build/util/numbers.js.map +1 -0
- package/build/util/subscriptions.d.ts +16 -0
- package/build/util/subscriptions.js +78 -0
- package/build/util/subscriptions.js.map +1 -0
- package/build/util/unknowns.d.ts +2 -0
- package/build/util/unknowns.js +23 -0
- package/build/util/unknowns.js.map +1 -0
- package/package.json +72 -49
- package/dist/any-type.d.ts +0 -2
- package/dist/any-type.js +0 -2
- package/dist/any-type.js.map +0 -1
- package/dist/binary-decoder.d.ts +0 -6
- package/dist/binary-decoder.js +0 -16
- package/dist/binary-decoder.js.map +0 -1
- package/dist/binary-encoder.d.ts +0 -5
- package/dist/binary-encoder.js +0 -13
- package/dist/binary-encoder.js.map +0 -1
- package/dist/cbor-decoder.d.ts +0 -15
- package/dist/cbor-decoder.js +0 -126
- package/dist/cbor-decoder.js.map +0 -1
- package/dist/cbor-encoder.d.ts +0 -29
- package/dist/cbor-encoder.js +0 -81
- package/dist/cbor-encoder.js.map +0 -1
- package/dist/cbor-tags.d.ts +0 -3
- package/dist/cbor-tags.js +0 -4
- package/dist/cbor-tags.js.map +0 -1
- package/dist/class-type.d.ts +0 -2
- package/dist/class-type.js +0 -2
- package/dist/class-type.js.map +0 -1
- package/dist/date-time-types.d.ts +0 -7
- package/dist/date-time-types.js +0 -5
- package/dist/date-time-types.js.map +0 -1
- package/dist/fetch-event-source.d.ts +0 -52
- package/dist/fetch-event-source.js +0 -271
- package/dist/fetch-event-source.js.map +0 -1
- package/dist/fetch-request-factory.d.ts +0 -26
- package/dist/fetch-request-factory.js +0 -125
- package/dist/fetch-request-factory.js.map +0 -1
- package/dist/fetch.d.ts +0 -1
- package/dist/fetch.js +0 -19
- package/dist/fetch.js.map +0 -1
- package/dist/http-error.d.ts +0 -10
- package/dist/http-error.js +0 -45
- package/dist/http-error.js.map +0 -1
- package/dist/index.d.ts +0 -25
- package/dist/index.js +0 -26
- package/dist/index.js.map +0 -1
- package/dist/json-decoder.d.ts +0 -31
- package/dist/json-decoder.js +0 -139
- package/dist/json-decoder.js.map +0 -1
- package/dist/json-encoder.d.ts +0 -35
- package/dist/json-encoder.js +0 -116
- package/dist/json-encoder.js.map +0 -1
- package/dist/logger.js +0 -2
- package/dist/logger.js.map +0 -1
- package/dist/media-type-decoder.d.ts +0 -4
- package/dist/media-type-decoder.js +0 -2
- package/dist/media-type-decoder.js.map +0 -1
- package/dist/media-type-decoders.d.ts +0 -17
- package/dist/media-type-decoders.js +0 -40
- package/dist/media-type-decoders.js.map +0 -1
- package/dist/media-type-encoder.d.ts +0 -8
- package/dist/media-type-encoder.js +0 -6
- package/dist/media-type-encoder.js.map +0 -1
- package/dist/media-type-encoders.d.ts +0 -17
- package/dist/media-type-encoders.js +0 -42
- package/dist/media-type-encoders.js.map +0 -1
- package/dist/media-type.d.ts +0 -14
- package/dist/media-type.js +0 -18
- package/dist/media-type.js.map +0 -1
- package/dist/problem.d.ts +0 -16
- package/dist/problem.js +0 -11
- package/dist/problem.js.map +0 -1
- package/dist/request-factory.d.ts +0 -38
- package/dist/request-factory.js +0 -2
- package/dist/request-factory.js.map +0 -1
- package/dist/url-encoder.d.ts +0 -59
- package/dist/url-encoder.js +0 -141
- package/dist/url-encoder.js.map +0 -1
- package/dist/url-template.js +0 -18
- package/dist/url-template.js.map +0 -1
- package/dist/util/base64.d.ts +0 -5
- package/dist/util/base64.js +0 -64
- package/dist/util/base64.js.map +0 -1
- package/dist/util/hex.d.ts +0 -4
- package/dist/util/hex.js +0 -18
- package/dist/util/hex.js.map +0 -1
- package/dist/util/rxjs.d.ts +0 -2
- package/dist/util/rxjs.js +0 -14
- package/dist/util/rxjs.js.map +0 -1
- package/dist/util/stream-rxjs.d.ts +0 -2
- package/dist/util/stream-rxjs.js +0 -26
- package/dist/util/stream-rxjs.js.map +0 -1
- package/src/any-type.ts +0 -4
- package/src/binary-decoder.ts +0 -24
- package/src/binary-encoder.ts +0 -19
- package/src/cbor-decoder.ts +0 -148
- package/src/cbor-encoder.ts +0 -95
- package/src/cbor-tags.ts +0 -3
- package/src/class-type.ts +0 -3
- package/src/date-time-types.ts +0 -10
- package/src/fetch-event-source.ts +0 -387
- package/src/fetch-request-factory.ts +0 -225
- package/src/fetch.ts +0 -30
- package/src/http-error.ts +0 -55
- package/src/index.ts +0 -26
- package/src/json-decoder.ts +0 -164
- package/src/json-encoder.ts +0 -144
- package/src/logger.ts +0 -8
- package/src/media-type-decoder.ts +0 -5
- package/src/media-type-decoders.ts +0 -59
- package/src/media-type-encoder.ts +0 -16
- package/src/media-type-encoders.ts +0 -61
- package/src/media-type.ts +0 -25
- package/src/problem.ts +0 -25
- package/src/request-factory.ts +0 -76
- package/src/url-encoder.ts +0 -173
- package/src/url-template.ts +0 -21
- package/src/util/base64.ts +0 -77
- package/src/util/hex.ts +0 -15
- package/src/util/rxjs.ts +0 -18
- package/src/util/stream-rxjs.ts +0 -28
- /package/{dist → build}/url-template.d.ts +0 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
// Copyright 2020 Outfox, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
export async function firstValueFrom(iterable) {
|
|
15
|
+
const next = await iterable[Symbol.asyncIterator]().next();
|
|
16
|
+
if (next.done) {
|
|
17
|
+
throw new Error('No value');
|
|
18
|
+
}
|
|
19
|
+
return next.value;
|
|
20
|
+
}
|
|
21
|
+
export function fromEvent(target, type, options = {}) {
|
|
22
|
+
const overflow = options.overflow ?? 'preserve';
|
|
23
|
+
const highWaterMark = options.highWaterMark ?? 1;
|
|
24
|
+
if (!Number.isFinite(highWaterMark) || highWaterMark < 0) {
|
|
25
|
+
throw new TypeError('fromEventTarget highWaterMark must be a finite number >= 0');
|
|
26
|
+
}
|
|
27
|
+
let finalized = false;
|
|
28
|
+
let eventListenerRegistered = false;
|
|
29
|
+
let abortListenerRegistered = false;
|
|
30
|
+
let controllerRef;
|
|
31
|
+
const finalize = () => {
|
|
32
|
+
if (finalized) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
finalized = true;
|
|
36
|
+
if (eventListenerRegistered) {
|
|
37
|
+
target.removeEventListener(type, onEvent);
|
|
38
|
+
eventListenerRegistered = false;
|
|
39
|
+
}
|
|
40
|
+
if (abortListenerRegistered) {
|
|
41
|
+
options.signal?.removeEventListener('abort', onAbort);
|
|
42
|
+
abortListenerRegistered = false;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const onAbort = () => {
|
|
46
|
+
const controller = controllerRef;
|
|
47
|
+
if (!controller || finalized) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
finalize();
|
|
51
|
+
controller.close();
|
|
52
|
+
};
|
|
53
|
+
const onEvent = (event) => {
|
|
54
|
+
const controller = controllerRef;
|
|
55
|
+
if (!controller || finalized) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (overflow !== 'preserve') {
|
|
59
|
+
const desiredSize = controller.desiredSize;
|
|
60
|
+
if (desiredSize !== null && desiredSize <= 0) {
|
|
61
|
+
if (overflow === 'drop') {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
finalize();
|
|
65
|
+
controller.error(new Error(`fromEventTarget("${type}") stream buffer overflow`));
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
controller.enqueue(event);
|
|
70
|
+
};
|
|
71
|
+
const stream = new ReadableStream({
|
|
72
|
+
start(controller) {
|
|
73
|
+
controllerRef = controller;
|
|
74
|
+
if (options.signal?.aborted) {
|
|
75
|
+
finalize();
|
|
76
|
+
controller.close();
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
target.addEventListener(type, onEvent);
|
|
80
|
+
eventListenerRegistered = true;
|
|
81
|
+
if (options.signal) {
|
|
82
|
+
options.signal.addEventListener('abort', onAbort, { once: true });
|
|
83
|
+
abortListenerRegistered = true;
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
cancel() {
|
|
87
|
+
finalize();
|
|
88
|
+
},
|
|
89
|
+
}, { highWaterMark });
|
|
90
|
+
async function* iterate() {
|
|
91
|
+
const reader = stream.getReader();
|
|
92
|
+
try {
|
|
93
|
+
while (true) {
|
|
94
|
+
const next = await reader.read();
|
|
95
|
+
if (next.done) {
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
yield next.value;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
finally {
|
|
102
|
+
try {
|
|
103
|
+
await reader.cancel();
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
// no-op
|
|
107
|
+
}
|
|
108
|
+
reader.releaseLock();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
[Symbol.asyncIterator]() {
|
|
113
|
+
return iterate();
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
export function subscribe(stream, observer) {
|
|
118
|
+
const iterator = stream[Symbol.asyncIterator]();
|
|
119
|
+
let closed = false;
|
|
120
|
+
let stopPromise;
|
|
121
|
+
const stop = () => {
|
|
122
|
+
if (stopPromise !== undefined) {
|
|
123
|
+
return stopPromise;
|
|
124
|
+
}
|
|
125
|
+
closed = true;
|
|
126
|
+
stopPromise = (async () => {
|
|
127
|
+
if (typeof iterator.return === 'function') {
|
|
128
|
+
await iterator.return();
|
|
129
|
+
}
|
|
130
|
+
})().catch(() => undefined);
|
|
131
|
+
return stopPromise;
|
|
132
|
+
};
|
|
133
|
+
const done = (async () => {
|
|
134
|
+
try {
|
|
135
|
+
while (!closed) {
|
|
136
|
+
const next = await iterator.next();
|
|
137
|
+
if (closed) {
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
if (next.done) {
|
|
141
|
+
await observer.complete?.();
|
|
142
|
+
closed = true;
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
await observer.next(next.value);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
if (!closed) {
|
|
150
|
+
if (observer.error) {
|
|
151
|
+
await observer.error(error);
|
|
152
|
+
await stop();
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
await stop();
|
|
156
|
+
throw error;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
finally {
|
|
160
|
+
if (stopPromise !== undefined) {
|
|
161
|
+
await stopPromise;
|
|
162
|
+
}
|
|
163
|
+
closed = true;
|
|
164
|
+
}
|
|
165
|
+
})();
|
|
166
|
+
return {
|
|
167
|
+
get closed() {
|
|
168
|
+
return closed;
|
|
169
|
+
},
|
|
170
|
+
unsubscribe() {
|
|
171
|
+
if (closed) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
void stop();
|
|
175
|
+
},
|
|
176
|
+
done,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=async-iterables.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-iterables.js","sourceRoot":"","sources":["../../src/util/async-iterables.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,gDAAgD;AAChD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,QAA0B;IAE1B,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC;IAC3D,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC;IAC9B,CAAC;IACD,OAAO,IAAI,CAAC,KAAK,CAAC;AACpB,CAAC;AAUD,MAAM,UAAU,SAAS,CACvB,MAAmB,EACnB,IAAY,EACZ,UAA2C,EAAE;IAE7C,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,UAAU,CAAC;IAChD,MAAM,aAAa,GAAG,OAAO,CAAC,aAAa,IAAI,CAAC,CAAC;IAEjD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,aAAa,GAAG,CAAC,EAAE,CAAC;QACzD,MAAM,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AC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAClC,CAAC;QACH,CAAC;QACD,OAAO,KAAK,EAAE,CAAC;YACb,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,IAAI,QAAQ,CAAC,KAAK,EAAE,CAAC;oBACnB,MAAM,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;oBAC5B,MAAM,IAAI,EAAE,CAAC;oBACb,OAAO;gBACT,CAAC;gBAED,MAAM,IAAI,EAAE,CAAC;gBACb,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;gBACO,CAAC;YACP,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;gBAC9B,MAAM,WAAW,CAAC;YACpB,CAAC;YACD,MAAM,GAAG,IAAI,CAAC;QAChB,CAAC;IACH,CAAC,CAAC,EAAE,CAAC;IAEL,OAAO;QACL,IAAI,MAAM;YACR,OAAO,MAAM,CAAC;QAChB,CAAC;QACD,WAAW;YACT,IAAI,MAAM,EAAE,CAAC;gBACX,OAAO;YACT,CAAC;YACD,KAAK,IAAI,EAAE,CAAC;QACd,CAAC;QACD,IAAI;KACL,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Copyright 2020 Outfox, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
export function isError(value) {
|
|
15
|
+
return value instanceof Error;
|
|
16
|
+
}
|
|
17
|
+
export function errorToMessage(value, defMsg) {
|
|
18
|
+
return isError(value) ? value.message : defMsg ?? fmtMsg(value);
|
|
19
|
+
}
|
|
20
|
+
function fmtMsg(value) {
|
|
21
|
+
if (typeof value === 'string') {
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
if (value === null) {
|
|
25
|
+
return 'null';
|
|
26
|
+
}
|
|
27
|
+
if (value === undefined) {
|
|
28
|
+
return 'undefined';
|
|
29
|
+
}
|
|
30
|
+
if (typeof value === 'function') {
|
|
31
|
+
return value.name ? `[function ${value.name}]` : '[function]';
|
|
32
|
+
}
|
|
33
|
+
if (typeof value === 'symbol') {
|
|
34
|
+
return value.toString();
|
|
35
|
+
}
|
|
36
|
+
if (typeof value === 'bigint') {
|
|
37
|
+
return `${value}n`;
|
|
38
|
+
}
|
|
39
|
+
if (typeof value === 'object') {
|
|
40
|
+
return fmtObj(value);
|
|
41
|
+
}
|
|
42
|
+
return String(value);
|
|
43
|
+
}
|
|
44
|
+
function fmtObj(value) {
|
|
45
|
+
const ctorName = value.constructor?.name;
|
|
46
|
+
try {
|
|
47
|
+
const json = JSON.stringify(value);
|
|
48
|
+
if (json != null) {
|
|
49
|
+
if (ctorName &&
|
|
50
|
+
ctorName !== 'Object' &&
|
|
51
|
+
ctorName !== 'Array') {
|
|
52
|
+
return `${ctorName} ${json}`;
|
|
53
|
+
}
|
|
54
|
+
return json;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
// ignore and fall back below
|
|
59
|
+
}
|
|
60
|
+
if (ctorName) {
|
|
61
|
+
return `[${ctorName}]`;
|
|
62
|
+
}
|
|
63
|
+
return '[object]';
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/util/errors.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,EAAE;AACF,kEAAkE;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AAC,KAAa;IAC3B,MAAM,QAAQ,GAAG,KAAK,CAAC,WAAW,EAAE,IAAI,CAAC;IAEzC,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QACnC,IAAI,IAAI,IAAI,IAAI,EAAE,CAAC;YACjB,IACE,QAAQ;gBACR,QAAQ,KAAK,QAAQ;gBACrB,QAAQ,KAAK,OAAO,EACpB,CAAC;gBACD,OAAO,GAAG,QAAQ,IAAI,IAAI,EAAE,CAAC;YAC/B,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,6BAA6B;IAC/B,CAAC;IAED,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO,IAAI,QAAQ,GAAG,CAAC;IACzB,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { Problem } from '../problem.js';
|
|
3
|
+
export type ProblemMatcher = z.ZodType<Problem> | ((problem: Problem) => boolean);
|
|
4
|
+
export declare function nullifyNotFound<T>(promise: Promise<T>): Promise<T | null>;
|
|
5
|
+
export declare function nullifyProblem<T>(promise: Promise<T>, statuses: number[], problemTypes: ProblemMatcher[]): Promise<T | null>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Copyright 2020 Outfox, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
import { Problem } from '../problem.js';
|
|
15
|
+
export async function nullifyNotFound(promise) {
|
|
16
|
+
return await nullifyProblem(promise, [404], []);
|
|
17
|
+
}
|
|
18
|
+
export async function nullifyProblem(promise, statuses, problemTypes) {
|
|
19
|
+
try {
|
|
20
|
+
return await promise;
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
if (error instanceof Problem && matchesProblem(error, statuses, problemTypes)) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function matchesProblem(error, statuses, problemTypes) {
|
|
30
|
+
if (statuses.includes(error.status)) {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
return problemTypes.some((matcher) => typeof matcher === 'function'
|
|
34
|
+
? matcher(error)
|
|
35
|
+
: matcher.safeParse(error).success);
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=nullify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nullify.js","sourceRoot":"","sources":["../../src/util/nullify.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,gDAAgD;AAChD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAIxC,MAAM,CAAC,KAAK,UAAU,eAAe,CAAI,OAAmB;IAC1D,OAAO,MAAM,cAAc,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,OAAmB,EACnB,QAAkB,EAClB,YAA8B;IAE9B,IAAI,CAAC;QACH,OAAO,MAAM,OAAO,CAAC;IACvB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,OAAO,IAAI,cAAc,CAAC,KAAK,EAAE,QAAQ,EAAE,YAAY,CAAC,EAAE,CAAC;YAC9E,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,SAAS,cAAc,CACrB,KAAc,EACd,QAAkB,EAClB,YAA8B;IAE9B,IAAI,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;QACpC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,YAAY,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CACnC,OAAO,OAAO,KAAK,UAAU;QAC3B,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;QAChB,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CACrC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function secondsToNumber(seconds: number, nanos: number): number;
|
|
2
|
+
/**
|
|
3
|
+
* Encodes seconds and fraction into an array of numbers that matches
|
|
4
|
+
* Jackson's optional second/fraction timestamp fields.
|
|
5
|
+
*/
|
|
6
|
+
export declare function encodeNumericArray(seconds: number, fraction: number): number[];
|
|
7
|
+
/**
|
|
8
|
+
* Appends Jackson-style optional second/fraction fields to a required
|
|
9
|
+
* date/time prefix (such as year-month-day-hour-minute).
|
|
10
|
+
*/
|
|
11
|
+
export declare function appendNumericTimeFields(prefix: number[], seconds: number, fraction: number): number[];
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Copyright 2020 Outfox, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
export function secondsToNumber(seconds, nanos) {
|
|
15
|
+
if (nanos == 0) {
|
|
16
|
+
return seconds;
|
|
17
|
+
}
|
|
18
|
+
return seconds + (nanos / 1e9);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Encodes seconds and fraction into an array of numbers that matches
|
|
22
|
+
* Jackson's optional second/fraction timestamp fields.
|
|
23
|
+
*/
|
|
24
|
+
export function encodeNumericArray(seconds, fraction) {
|
|
25
|
+
const result = [];
|
|
26
|
+
if (seconds != 0 || fraction != 0) {
|
|
27
|
+
result.push(seconds);
|
|
28
|
+
if (fraction != 0) {
|
|
29
|
+
result.push(fraction);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Appends Jackson-style optional second/fraction fields to a required
|
|
36
|
+
* date/time prefix (such as year-month-day-hour-minute).
|
|
37
|
+
*/
|
|
38
|
+
export function appendNumericTimeFields(prefix, seconds, fraction) {
|
|
39
|
+
return [...prefix, ...encodeNumericArray(seconds, fraction)];
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=numbers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"numbers.js","sourceRoot":"","sources":["../../src/util/numbers.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,gDAAgD;AAChD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,MAAM,UAAU,eAAe,CAAC,OAAe,EAAE,KAAa;IAC5D,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;QACf,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,OAAO,OAAO,GAAG,CAAC,KAAK,GAAG,GAAG,CAAC,CAAC;AACjC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAe,EAAE,QAAgB;IAClE,MAAM,MAAM,GAAG,EAAE,CAAC;IAClB,IAAI,OAAO,IAAI,CAAC,IAAI,QAAQ,IAAI,CAAC,EAAE,CAAC;QAClC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACrB,IAAI,QAAQ,IAAI,CAAC,EAAE,CAAC;YAClB,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,uBAAuB,CACrC,MAAgB,EAChB,OAAe,EACf,QAAgB;IAEhB,OAAO,CAAC,GAAG,MAAM,EAAE,GAAG,kBAAkB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;AAC/D,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface Unsubscribable {
|
|
2
|
+
unsubscribe(): void;
|
|
3
|
+
}
|
|
4
|
+
export interface SubscriptionLike extends Unsubscribable {
|
|
5
|
+
readonly closed: boolean;
|
|
6
|
+
readonly done: Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export declare class Subscription implements SubscriptionLike {
|
|
9
|
+
private readonly _collection;
|
|
10
|
+
private readonly _done;
|
|
11
|
+
closed: boolean;
|
|
12
|
+
add(sub: (() => unknown) | Unsubscribable): void;
|
|
13
|
+
remove(sub: (() => void) | Unsubscribable): void;
|
|
14
|
+
unsubscribe(): void;
|
|
15
|
+
get done(): Promise<void>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// Copyright 2020 Outfox, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
export class Subscription {
|
|
15
|
+
_collection = new Set();
|
|
16
|
+
_done = Promise.withResolvers();
|
|
17
|
+
closed = false;
|
|
18
|
+
add(sub) {
|
|
19
|
+
let unsub;
|
|
20
|
+
if (typeof sub == 'function') {
|
|
21
|
+
unsub = {
|
|
22
|
+
unsubscribe: sub,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
else if (Object.hasOwn(sub, 'unsubscribe')) {
|
|
26
|
+
unsub = sub;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
throw new TypeError('Invalid argument');
|
|
30
|
+
}
|
|
31
|
+
this._collection.add(unsub);
|
|
32
|
+
}
|
|
33
|
+
remove(sub) {
|
|
34
|
+
let unsub = undefined;
|
|
35
|
+
if (typeof sub == 'function') {
|
|
36
|
+
for (const curUnsub of this._collection) {
|
|
37
|
+
if (curUnsub.unsubscribe === sub) {
|
|
38
|
+
unsub = curUnsub;
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (!unsub) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else if (Object.hasOwn(sub, 'unsubscribe')) {
|
|
47
|
+
unsub = sub;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
throw new TypeError('Invalid argument');
|
|
51
|
+
}
|
|
52
|
+
this._collection.delete(unsub);
|
|
53
|
+
}
|
|
54
|
+
unsubscribe() {
|
|
55
|
+
if (this.closed) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
this.closed = true;
|
|
59
|
+
try {
|
|
60
|
+
this._collection.forEach((sub) => {
|
|
61
|
+
try {
|
|
62
|
+
sub.unsubscribe();
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
// Ensure all subscriptions are attempted even if any `unsubscribe` fails.
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
finally {
|
|
70
|
+
this._collection.clear();
|
|
71
|
+
this._done.resolve();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
get done() {
|
|
75
|
+
return this._done.promise;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=subscriptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscriptions.js","sourceRoot":"","sources":["../../src/util/subscriptions.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,gDAAgD;AAChD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAWjC,MAAM,OAAO,YAAY;IACN,WAAW,GAAG,IAAI,GAAG,EAAkB,CAAC;IACxC,KAAK,GAAG,OAAO,CAAC,aAAa,EAAQ,CAAC;IACvD,MAAM,GAAG,KAAK,CAAC;IAEf,GAAG,CAAC,GAAqC;QACvC,IAAI,KAAqB,CAAC;QAC1B,IAAI,OAAO,GAAG,IAAI,UAAU,EAAE,CAAC;YAC7B,KAAK,GAAG;gBACN,WAAW,EAAE,GAAG;aACjB,CAAC;QACJ,CAAC;aAAM,IAAI,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,aAAa,CAAC,EAAE,CAAC;YAC7C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C,KAAK,CAAC,OAAO,EAAE,CAAC;QACvB,CAAC;IACH,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;IAC5B,CAAC;CACF"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Copyright 2020 Outfox, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
export function unknownGet(obj, key) {
|
|
15
|
+
return obj?.[key];
|
|
16
|
+
}
|
|
17
|
+
export function unknownSet(obj, key, value) {
|
|
18
|
+
if (obj == null) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
obj[key] = value;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=unknowns.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unknowns.js","sourceRoot":"","sources":["../../src/util/unknowns.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,gDAAgD;AAChD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,MAAM,UAAU,UAAU,CAAc,GAAY,EAAE,GAAW;IAC/D,OAAQ,GAA+B,EAAE,CAAC,GAAG,CAAM,CAAC;AACtD,CAAC;AAED,MAAM,UAAU,UAAU,CAAI,GAAY,EAAE,GAAW,EAAE,KAAQ;IAC/D,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;QAChB,OAAO;IACT,CAAC;IACA,GAA+B,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAChD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,18 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@outfoxx/sunday",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Sunday
|
|
5
|
-
"
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
3
|
+
"version": "v1.0.10",
|
|
4
|
+
"description": "Sunday 🙏 The framework of REST for TypeScript/JavaScript",
|
|
5
|
+
"packageManager": "bun@1.3.10",
|
|
7
6
|
"type": "module",
|
|
7
|
+
"types": "build/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./build/index.d.ts",
|
|
11
|
+
"import": "./build/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./*": {
|
|
14
|
+
"types": "./build/*.d.ts",
|
|
15
|
+
"import": "./build/*.js"
|
|
16
|
+
},
|
|
17
|
+
"./package.json": "./package.json"
|
|
18
|
+
},
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=22"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"build",
|
|
24
|
+
"LICENSE.txt",
|
|
25
|
+
"README.md"
|
|
26
|
+
],
|
|
8
27
|
"scripts": {
|
|
9
|
-
"test": "
|
|
10
|
-
"test:watch": "
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
28
|
+
"test": "mkdir -p reports reports/coverage && bun test -r ./test/setup.ts --coverage --coverage-reporter=lcov --coverage-dir=reports/coverage --reporter=junit --reporter-outfile=reports/test-report.xml",
|
|
29
|
+
"test:watch": "bun test -r ./test/setup.ts --watch",
|
|
30
|
+
"typecheck": "tsc -p tsconfig.build.json --noEmit && tsc -p tsconfig.test.json --noEmit",
|
|
31
|
+
"build": "tsc -p tsconfig.build.json",
|
|
32
|
+
"build:watch": "tsc -p tsconfig.build.json --watch",
|
|
33
|
+
"check": "bun run lint && bun run typecheck && bun run test && bun run build",
|
|
34
|
+
"clean": "rimraf build docs reports",
|
|
35
|
+
"pretty": "prettier src test",
|
|
36
|
+
"lint": "mkdir -p reports && eslint -f json -o reports/lint.json src test",
|
|
37
|
+
"lint:html": "mkdir -p reports && eslint -f html -o reports/lint.html src test",
|
|
38
|
+
"docs": "typedoc --excludeInternal --excludePrivate --tsconfig tsconfig.build.json src/index.ts",
|
|
39
|
+
"prepublishOnly": "bun run clean && bun run check",
|
|
40
|
+
"publish:dry-run": "bun publish --dry-run",
|
|
41
|
+
"smoke:esm:bun": "bun ./tools/ci/esm-smoke.mjs",
|
|
42
|
+
"smoke:esm:node": "node ./tools/ci/esm-smoke.mjs",
|
|
43
|
+
"build:stub": "dts-bundle-generator --project tools/stub/tsconfig.json --no-check --out-file tools/stub/out/index.d.ts tools/stub/index.ts"
|
|
16
44
|
},
|
|
17
45
|
"husky": {
|
|
18
46
|
"hooks": {
|
|
@@ -24,46 +52,41 @@
|
|
|
24
52
|
"eslint"
|
|
25
53
|
]
|
|
26
54
|
},
|
|
27
|
-
"keywords": [
|
|
55
|
+
"keywords": [
|
|
56
|
+
"HTTP",
|
|
57
|
+
"REST",
|
|
58
|
+
"fetch"
|
|
59
|
+
],
|
|
60
|
+
"repository": {
|
|
61
|
+
"type": "git",
|
|
62
|
+
"url": "https://github.com/outfoxx/sunday-js"
|
|
63
|
+
},
|
|
28
64
|
"author": "kdubb",
|
|
29
|
-
"license": "
|
|
65
|
+
"license": "Apache-2.0",
|
|
30
66
|
"dependencies": {
|
|
31
|
-
"@
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
67
|
+
"@js-joda/core": "^5.7.0",
|
|
68
|
+
"cbor-redux": "^1.0.0",
|
|
69
|
+
"tslib": "^2.8.1",
|
|
70
|
+
"uri-template": "^2.0.0",
|
|
71
|
+
"zod": "^4.3.6"
|
|
36
72
|
},
|
|
73
|
+
"peerDependencies": {},
|
|
37
74
|
"devDependencies": {
|
|
38
|
-
"@
|
|
39
|
-
"@types/
|
|
40
|
-
"@
|
|
41
|
-
"@
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
|
|
55
|
-
"karma-typescript": "^5.2.0",
|
|
56
|
-
"karma-typescript-es6-transform": "^5.2.0",
|
|
57
|
-
"lint-staged": "^10.4.0",
|
|
58
|
-
"prettier": "^2.1.2",
|
|
59
|
-
"pretty-quick": "^3.0.2",
|
|
60
|
-
"rimraf": "^3.0.2",
|
|
61
|
-
"typescript": "^4.0.2",
|
|
62
|
-
"web-streams-polyfill": "^3.0.0"
|
|
63
|
-
},
|
|
64
|
-
"files": [
|
|
65
|
-
"dist",
|
|
66
|
-
"src",
|
|
67
|
-
"package.json"
|
|
68
|
-
]
|
|
75
|
+
"@eslint/js": "^10.0.1",
|
|
76
|
+
"@types/bun": "^1.3.9",
|
|
77
|
+
"@typescript-eslint/eslint-plugin": "^8.56.1",
|
|
78
|
+
"@typescript-eslint/parser": "^8.56.1",
|
|
79
|
+
"dts-bundle-generator": "^9.5.1",
|
|
80
|
+
"eslint": "^10.0.2",
|
|
81
|
+
"eslint-config-prettier": "^10.1.8",
|
|
82
|
+
"fetch-mock": "^12.6.0",
|
|
83
|
+
"globals": "^17.3.0",
|
|
84
|
+
"husky": "^9.1.7",
|
|
85
|
+
"lint-staged": "^16.2.7",
|
|
86
|
+
"prettier": "^3.8.1",
|
|
87
|
+
"pretty-quick": "^4.2.2",
|
|
88
|
+
"rimraf": "^6.1.3",
|
|
89
|
+
"typedoc": "^0.28.17",
|
|
90
|
+
"typescript": "^5.9.3"
|
|
91
|
+
}
|
|
69
92
|
}
|
package/dist/any-type.d.ts
DELETED
package/dist/any-type.js
DELETED
package/dist/any-type.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"any-type.js","sourceRoot":"","sources":["../src/any-type.ts"],"names":[],"mappings":""}
|