@tstdl/base 0.83.2 → 0.83.4
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/.eslintrc.cjs +14 -5
- package/authentication/server/authentication.service.d.ts +10 -2
- package/authentication/server/authentication.service.js +17 -6
- package/examples/mail/templates/hello-name.d.ts +1 -1
- package/examples/pdf/templates/hello-name.d.ts +1 -1
- package/examples/template/templates/hello-jsx.d.ts +1 -1
- package/examples/template/templates/hello-name.d.ts +1 -1
- package/mail/mail.service.d.ts +1 -1
- package/mail/models/mail-template.model.d.ts +4 -4
- package/package.json +1 -1
- package/pdf/pdf.service.d.ts +3 -3
- package/templates/template.model.d.ts +4 -1
- package/templates/template.model.js +3 -1
- package/templates/template.service.d.ts +2 -2
- package/utils/cryptography.d.ts +10 -4
- package/utils/cryptography.js +6 -1
- package/utils/type-guards.d.ts +6 -0
- package/utils/type-guards.js +26 -0
package/.eslintrc.cjs
CHANGED
|
@@ -35,6 +35,7 @@ module.exports = {
|
|
|
35
35
|
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
|
36
36
|
'@typescript-eslint/indent': 'off',
|
|
37
37
|
'@typescript-eslint/init-declarations': 'off',
|
|
38
|
+
'@typescript-eslint/lines-around-comment': 'off',
|
|
38
39
|
'@typescript-eslint/lines-between-class-members': ['warn', 'always', { exceptAfterSingleLine: true }],
|
|
39
40
|
'@typescript-eslint/method-signature-style': 'off',
|
|
40
41
|
'@typescript-eslint/no-confusing-void-expression': ['error', { ignoreArrowShorthand: true, ignoreVoidOperator: true }],
|
|
@@ -93,7 +94,7 @@ module.exports = {
|
|
|
93
94
|
'function-paren-newline': ['warn', 'consistent'],
|
|
94
95
|
'generator-star-spacing': ['off', { before: false, after: true }],
|
|
95
96
|
'id-length': 'off',
|
|
96
|
-
'indent':
|
|
97
|
+
'indent': 'off',
|
|
97
98
|
'init-declarations': 'off',
|
|
98
99
|
'line-comment-position': 'off',
|
|
99
100
|
'linebreak-style': ['error', 'unix'],
|
|
@@ -183,9 +184,11 @@ module.exports = {
|
|
|
183
184
|
'protected-static-field',
|
|
184
185
|
'public-static-field',
|
|
185
186
|
|
|
187
|
+
/*
|
|
186
188
|
'private-decorated-field',
|
|
187
189
|
'protected-decorated-field',
|
|
188
190
|
'public-decorated-field',
|
|
191
|
+
*/
|
|
189
192
|
|
|
190
193
|
'#private-instance-field',
|
|
191
194
|
'private-instance-field',
|
|
@@ -204,7 +207,7 @@ module.exports = {
|
|
|
204
207
|
'instance-field',
|
|
205
208
|
'abstract-field',
|
|
206
209
|
|
|
207
|
-
'decorated-field',
|
|
210
|
+
// 'decorated-field',
|
|
208
211
|
|
|
209
212
|
'field',
|
|
210
213
|
|
|
@@ -214,9 +217,11 @@ module.exports = {
|
|
|
214
217
|
'protected-static-get',
|
|
215
218
|
'public-static-get',
|
|
216
219
|
|
|
220
|
+
/*
|
|
217
221
|
'private-decorated-get',
|
|
218
222
|
'protected-decorated-get',
|
|
219
223
|
'public-decorated-get',
|
|
224
|
+
*/
|
|
220
225
|
|
|
221
226
|
'#private-instance-get',
|
|
222
227
|
'private-instance-get',
|
|
@@ -235,7 +240,7 @@ module.exports = {
|
|
|
235
240
|
'instance-get',
|
|
236
241
|
'abstract-get',
|
|
237
242
|
|
|
238
|
-
'decorated-get',
|
|
243
|
+
// 'decorated-get',
|
|
239
244
|
|
|
240
245
|
'get',
|
|
241
246
|
|
|
@@ -245,9 +250,11 @@ module.exports = {
|
|
|
245
250
|
'protected-static-set',
|
|
246
251
|
'public-static-set',
|
|
247
252
|
|
|
253
|
+
/*
|
|
248
254
|
'private-decorated-set',
|
|
249
255
|
'protected-decorated-set',
|
|
250
256
|
'public-decorated-set',
|
|
257
|
+
*/
|
|
251
258
|
|
|
252
259
|
'#private-instance-set',
|
|
253
260
|
'private-instance-set',
|
|
@@ -266,7 +273,7 @@ module.exports = {
|
|
|
266
273
|
'instance-set',
|
|
267
274
|
'abstract-set',
|
|
268
275
|
|
|
269
|
-
'decorated-set',
|
|
276
|
+
// 'decorated-set',
|
|
270
277
|
|
|
271
278
|
'set',
|
|
272
279
|
|
|
@@ -286,9 +293,11 @@ module.exports = {
|
|
|
286
293
|
'private-static-method',
|
|
287
294
|
'#private-static-method',
|
|
288
295
|
|
|
296
|
+
/*
|
|
289
297
|
'public-decorated-method',
|
|
290
298
|
'protected-decorated-method',
|
|
291
299
|
'private-decorated-method',
|
|
300
|
+
*/
|
|
292
301
|
|
|
293
302
|
'public-instance-method',
|
|
294
303
|
'protected-instance-method',
|
|
@@ -307,7 +316,7 @@ module.exports = {
|
|
|
307
316
|
'instance-method',
|
|
308
317
|
'abstract-method',
|
|
309
318
|
|
|
310
|
-
'decorated-method',
|
|
319
|
+
// 'decorated-method',
|
|
311
320
|
|
|
312
321
|
'method'
|
|
313
322
|
]
|
|
@@ -9,8 +9,15 @@ import { AuthenticationSessionRepository } from './authentication-session.reposi
|
|
|
9
9
|
import { AuthenticationSubjectResolver } from './authentication-subject.resolver.js';
|
|
10
10
|
import { AuthenticationTokenPayloadProvider } from './authentication-token-payload.provider.js';
|
|
11
11
|
export declare class AuthenticationServiceOptions {
|
|
12
|
-
/**
|
|
13
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Secrets used for signing tokens and refreshTokens
|
|
14
|
+
* If single secret is provided, multiple secrets are derived internally
|
|
15
|
+
*/
|
|
16
|
+
secret: string | BinaryData | {
|
|
17
|
+
tokenSigningSecret: Uint8Array;
|
|
18
|
+
refreshTokenSigningSecret: Uint8Array;
|
|
19
|
+
secretResetTokenSigningSecret: Uint8Array;
|
|
20
|
+
};
|
|
14
21
|
/** Token version, forces refresh on mismatch (useful if payload changes) */
|
|
15
22
|
version?: number;
|
|
16
23
|
/** How long a token is valid */
|
|
@@ -39,6 +46,7 @@ export declare class AuthenticationService<AdditionalTokenPayload = Record<never
|
|
|
39
46
|
private readonly tokenPayloadProvider;
|
|
40
47
|
private readonly subjectResolver;
|
|
41
48
|
private readonly authenticationResetSecretHandler;
|
|
49
|
+
private readonly options;
|
|
42
50
|
private readonly secret;
|
|
43
51
|
private readonly tokenVersion;
|
|
44
52
|
private readonly tokenTimeToLive;
|
|
@@ -60,7 +60,10 @@ var __param = function(paramIndex, decorator) {
|
|
|
60
60
|
};
|
|
61
61
|
};
|
|
62
62
|
class AuthenticationServiceOptions {
|
|
63
|
-
/**
|
|
63
|
+
/**
|
|
64
|
+
* Secrets used for signing tokens and refreshTokens
|
|
65
|
+
* If single secret is provided, multiple secrets are derived internally
|
|
66
|
+
*/
|
|
64
67
|
secret;
|
|
65
68
|
/** Token version, forces refresh on mismatch (useful if payload changes) */
|
|
66
69
|
version;
|
|
@@ -79,6 +82,7 @@ let AuthenticationService = class AuthenticationService2 {
|
|
|
79
82
|
tokenPayloadProvider;
|
|
80
83
|
subjectResolver;
|
|
81
84
|
authenticationResetSecretHandler;
|
|
85
|
+
options;
|
|
82
86
|
secret;
|
|
83
87
|
tokenVersion;
|
|
84
88
|
tokenTimeToLive;
|
|
@@ -94,7 +98,7 @@ let AuthenticationService = class AuthenticationService2 {
|
|
|
94
98
|
this.subjectResolver = subjectResolver;
|
|
95
99
|
this.tokenPayloadProvider = tokenPayloadProvider;
|
|
96
100
|
this.authenticationResetSecretHandler = authenticationResetSecretHandler;
|
|
97
|
-
this.
|
|
101
|
+
this.options = options;
|
|
98
102
|
this.tokenVersion = options.version ?? 1;
|
|
99
103
|
this.tokenTimeToLive = options.tokenTimeToLive ?? 5 * import_units.millisecondsPerMinute;
|
|
100
104
|
this.refreshTokenTimeToLive = options.refreshTokenTimeToLive ?? 5 * import_units.millisecondsPerDay;
|
|
@@ -104,7 +108,13 @@ let AuthenticationService = class AuthenticationService2 {
|
|
|
104
108
|
await this.initialize();
|
|
105
109
|
}
|
|
106
110
|
async initialize() {
|
|
107
|
-
|
|
111
|
+
if ((0, import_type_guards.isString)(this.options.secret) || (0, import_type_guards.isBinaryData)(this.options.secret)) {
|
|
112
|
+
await this.deriveSigningSecrets(this.options.secret);
|
|
113
|
+
} else {
|
|
114
|
+
this.derivedTokenSigningSecret = this.options.secret.tokenSigningSecret;
|
|
115
|
+
this.derivedRefreshTokenSigningSecret = this.options.secret.refreshTokenSigningSecret;
|
|
116
|
+
this.derivedSecretResetTokenSigningSecret = this.options.secret.secretResetTokenSigningSecret;
|
|
117
|
+
}
|
|
108
118
|
}
|
|
109
119
|
async setCredentials(subject, secret) {
|
|
110
120
|
const actualSubject = await this.resolveSubject(subject);
|
|
@@ -269,9 +279,10 @@ let AuthenticationService = class AuthenticationService2 {
|
|
|
269
279
|
const token = await (0, import_jwt.createJwtTokenString)(jsonToken, this.derivedSecretResetTokenSigningSecret);
|
|
270
280
|
return { token, jsonToken };
|
|
271
281
|
}
|
|
272
|
-
async deriveSigningSecrets() {
|
|
273
|
-
const key = await (0, import_cryptography.importPbkdf2Key)(
|
|
274
|
-
const
|
|
282
|
+
async deriveSigningSecrets(secret) {
|
|
283
|
+
const key = await (0, import_cryptography.importPbkdf2Key)(secret);
|
|
284
|
+
const algorithm = { name: "PBKDF2", hash: "SHA-512", iterations: 5e5, salt: new Uint8Array() };
|
|
285
|
+
const [derivedTokenSigningSecret, derivedRefreshTokenSigningSecret, derivedSecretResetTokenSigningSecret] = await (0, import_cryptography.deriveBytesMultiple)(algorithm, key, 3, SIGNING_SECRETS_LENGTH / 8);
|
|
275
286
|
this.derivedTokenSigningSecret = derivedTokenSigningSecret;
|
|
276
287
|
this.derivedRefreshTokenSigningSecret = derivedRefreshTokenSigningSecret;
|
|
277
288
|
this.derivedSecretResetTokenSigningSecret = derivedSecretResetTokenSigningSecret;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const template: import("../../../mail/index.js").MailTemplate
|
|
1
|
+
declare const template: import("../../../mail/index.js").MailTemplate<object>;
|
|
2
2
|
export default template;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const template: import("../../../pdf/pdf.service.js").PdfTemplate
|
|
1
|
+
declare const template: import("../../../pdf/pdf.service.js").PdfTemplate<any>;
|
|
2
2
|
export default template;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const template: import("../../../templates/template.model.js").Template<import("../../../types.js").Record<string, boolean>, any>;
|
|
1
|
+
export declare const template: import("../../../templates/template.model.js").Template<import("../../../types.js").Record<string, boolean>, any, any>;
|
|
2
2
|
export default template;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const template: import("../../../templates/template.model.js").Template<import("../../../types.js").Record<string, boolean>, any>;
|
|
1
|
+
declare const template: import("../../../templates/template.model.js").Template<import("../../../types.js").Record<string, boolean>, any, any>;
|
|
2
2
|
export default template;
|
package/mail/mail.service.d.ts
CHANGED
|
@@ -14,5 +14,5 @@ export declare class MailService {
|
|
|
14
14
|
send(mailData: MailData): Promise<MailSendResult>;
|
|
15
15
|
/** @deprecated internal */
|
|
16
16
|
send(mailData: MailData, templateName?: string): Promise<MailSendResult>;
|
|
17
|
-
sendTemplate(keyOrTemplate: string | MailTemplate
|
|
17
|
+
sendTemplate<Context extends object>(keyOrTemplate: string | MailTemplate<Context>, mailData: TypedOmit<MailData, 'content' | 'subject'>, templateContext?: Context): Promise<MailSendResult>;
|
|
18
18
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { Template, TemplateField } from '../../templates/template.model.js';
|
|
2
|
-
export type MailTemplate = Template<{
|
|
2
|
+
export type MailTemplate<Context extends object = any> = Template<{
|
|
3
3
|
subject: false;
|
|
4
4
|
html: false;
|
|
5
5
|
text: false;
|
|
6
|
-
}, undefined>;
|
|
7
|
-
export declare function mailTemplate(name: string, fields: {
|
|
6
|
+
}, undefined, Context>;
|
|
7
|
+
export declare function mailTemplate<Context extends object>(name: string, fields: {
|
|
8
8
|
subject?: TemplateField;
|
|
9
9
|
html?: TemplateField;
|
|
10
10
|
text?: TemplateField;
|
|
11
|
-
}): MailTemplate
|
|
11
|
+
}): MailTemplate<Context>;
|
package/package.json
CHANGED
package/pdf/pdf.service.d.ts
CHANGED
|
@@ -45,11 +45,11 @@ export declare class PdfRenderOptions {
|
|
|
45
45
|
timeout?: number;
|
|
46
46
|
}
|
|
47
47
|
export type PdfTemplateOptions = PdfRenderOptions;
|
|
48
|
-
export declare class PdfTemplate extends Template<{
|
|
48
|
+
export declare class PdfTemplate<Context extends object = any> extends Template<{
|
|
49
49
|
header: false;
|
|
50
50
|
body: true;
|
|
51
51
|
footer: false;
|
|
52
|
-
}, PdfRenderOptions> {
|
|
52
|
+
}, PdfRenderOptions, Context> {
|
|
53
53
|
options?: PdfTemplateOptions;
|
|
54
54
|
}
|
|
55
55
|
export type PdfServiceOptions = {
|
|
@@ -101,7 +101,7 @@ export declare class PdfService implements AsyncDisposable, AfterResolve, Inject
|
|
|
101
101
|
* @param options additional options, overwrites options specified in template
|
|
102
102
|
* @returns pdf bytes
|
|
103
103
|
*/
|
|
104
|
-
renderTemplateStream(keyOrTemplate: string | PdfTemplate
|
|
104
|
+
renderTemplateStream<Context extends object>(keyOrTemplate: string | PdfTemplate<Context>, templateContext?: Context, options?: PdfRenderOptions): ReadableStream<Uint8Array>;
|
|
105
105
|
/**
|
|
106
106
|
* Renders a template to pdf
|
|
107
107
|
* @param key template key
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { PickBy, Record, SimplifyObject } from '../types.js';
|
|
2
|
+
export type TemplateContext<T extends Template> = T[typeof templateContext];
|
|
3
|
+
export declare const templateContext: unique symbol;
|
|
2
4
|
export declare class TemplateField<Resolver extends string = string, Renderer extends string = string, Options = any> {
|
|
3
5
|
resolver: Resolver;
|
|
4
6
|
renderer: Renderer;
|
|
@@ -9,7 +11,8 @@ export type TemplateFields<Fields extends Record<string, boolean>, Resolver exte
|
|
|
9
11
|
} & {
|
|
10
12
|
[P in keyof PickBy<Fields, false>]?: TemplateField<Resolver, Renderer, Options>;
|
|
11
13
|
}>;
|
|
12
|
-
export declare abstract class Template<Fields extends Record<string, boolean> = Record<string, boolean>, TemplateOptions = any> {
|
|
14
|
+
export declare abstract class Template<Fields extends Record<string, boolean> = Record<string, boolean>, TemplateOptions = any, Context extends object = any> {
|
|
15
|
+
readonly [templateContext]?: Context;
|
|
13
16
|
/** name of template */
|
|
14
17
|
name: string;
|
|
15
18
|
fields: TemplateFields<Fields>;
|
|
@@ -20,7 +20,8 @@ var template_model_exports = {};
|
|
|
20
20
|
__export(template_model_exports, {
|
|
21
21
|
Template: () => Template,
|
|
22
22
|
TemplateField: () => TemplateField,
|
|
23
|
-
simpleTemplate: () => simpleTemplate
|
|
23
|
+
simpleTemplate: () => simpleTemplate,
|
|
24
|
+
templateContext: () => templateContext
|
|
24
25
|
});
|
|
25
26
|
module.exports = __toCommonJS(template_model_exports);
|
|
26
27
|
var import_schema = require("../schema/index.js");
|
|
@@ -38,6 +39,7 @@ var __metadata = function(k, v) {
|
|
|
38
39
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
39
40
|
return Reflect.metadata(k, v);
|
|
40
41
|
};
|
|
42
|
+
const templateContext = Symbol("templateData");
|
|
41
43
|
let TemplateField = class TemplateField2 {
|
|
42
44
|
resolver;
|
|
43
45
|
renderer;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Record } from '../types.js';
|
|
2
2
|
import { TemplateRendererProvider } from './template-renderer.provider.js';
|
|
3
3
|
import { TemplateResolverProvider } from './template-resolver.provider.js';
|
|
4
|
-
import type { Template } from './template.model.js';
|
|
4
|
+
import type { Template, TemplateContext } from './template.model.js';
|
|
5
5
|
import { TemplateProvider } from './template.provider.js';
|
|
6
6
|
export type TemplateServiceRenderResult<T extends Template = Template> = {
|
|
7
7
|
name: string;
|
|
@@ -14,5 +14,5 @@ export declare class TemplateService {
|
|
|
14
14
|
private readonly templateResolverProvider;
|
|
15
15
|
constructor(templateProvider: TemplateProvider | undefined, templateRendererProvider: TemplateRendererProvider, templateResolverProvider: TemplateResolverProvider);
|
|
16
16
|
get<T extends Template = Template>(key: string): Promise<T>;
|
|
17
|
-
render<T extends Template = Template>(keyOrTemplate: string | T, templateContext?:
|
|
17
|
+
render<T extends Template = Template>(keyOrTemplate: string | T, templateContext?: TemplateContext<T>): Promise<TemplateServiceRenderResult<T>>;
|
|
18
18
|
}
|
package/utils/cryptography.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export type AsymmetricAlgorithm = 'RSASSA-PKCS1-v1_5' | 'RSA-PSS' | 'RSA-OAEP' |
|
|
|
8
8
|
export type CryptionAlgorithm = Parameters<typeof crypto.subtle.encrypt>[0];
|
|
9
9
|
export type SignAlgorithm = Parameters<typeof crypto.subtle.sign>[0];
|
|
10
10
|
export type KeyAlgorithm = Parameters<typeof crypto.subtle.generateKey>[0];
|
|
11
|
+
export type DeriveAlgorithm = Parameters<typeof globalThis.crypto.subtle.deriveBits>['0'];
|
|
11
12
|
export type KeyType = 'raw' | 'pkcs8' | 'spki' | 'jwk';
|
|
12
13
|
export type Key = JsonWebKey | BinaryData;
|
|
13
14
|
export type ScryptOptions = {
|
|
@@ -105,13 +106,18 @@ export declare function generateEcdsaKey(curve: EcdsaCurve, extractable?: boolea
|
|
|
105
106
|
* @param extractable whether the key can be used for exportKey
|
|
106
107
|
*/
|
|
107
108
|
export declare function generatePbkdf2Key(extractable?: boolean): Promise<CryptoKey>;
|
|
108
|
-
type AlgorithmParameter = Parameters<typeof globalThis.crypto.subtle.deriveBits>['0'];
|
|
109
109
|
/**
|
|
110
|
-
* derive
|
|
110
|
+
* derive byte array from key
|
|
111
|
+
* @param length length in bytes
|
|
112
|
+
* @param algorithm algorithm to derive with
|
|
113
|
+
* @param baseKey key to derive from
|
|
114
|
+
*/
|
|
115
|
+
export declare function deriveBytes(algorithm: DeriveAlgorithm, baseKey: CryptoKey, length: number): Promise<Uint8Array>;
|
|
116
|
+
/**
|
|
117
|
+
* derive multiply byte arrays from key
|
|
111
118
|
* @param count how many Uint8Arrays to dervice
|
|
112
119
|
* @param length length of each Uint8Array in bytes
|
|
113
120
|
* @param algorithm algorithm to derive with
|
|
114
121
|
* @param baseKey key to derive from
|
|
115
122
|
*/
|
|
116
|
-
export declare function deriveBytesMultiple<C extends number>(
|
|
117
|
-
export {};
|
|
123
|
+
export declare function deriveBytesMultiple<C extends number>(algorithm: DeriveAlgorithm, baseKey: CryptoKey, count: C, length: number): Promise<ReadonlyTuple<Uint8Array, C>>;
|
package/utils/cryptography.js
CHANGED
|
@@ -19,6 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var cryptography_exports = {};
|
|
20
20
|
__export(cryptography_exports, {
|
|
21
21
|
decrypt: () => decrypt,
|
|
22
|
+
deriveBytes: () => deriveBytes,
|
|
22
23
|
deriveBytesMultiple: () => deriveBytesMultiple,
|
|
23
24
|
digest: () => digest,
|
|
24
25
|
encrypt: () => encrypt,
|
|
@@ -122,7 +123,11 @@ async function generatePbkdf2Key(extractable = false) {
|
|
|
122
123
|
const key = (0, import_random.getRandomBytes)(16);
|
|
123
124
|
return importPbkdf2Key(key, extractable);
|
|
124
125
|
}
|
|
125
|
-
async function
|
|
126
|
+
async function deriveBytes(algorithm, baseKey, length) {
|
|
127
|
+
const bytes = await globalThis.crypto.subtle.deriveBits(algorithm, baseKey, length * 8);
|
|
128
|
+
return new Uint8Array(bytes);
|
|
129
|
+
}
|
|
130
|
+
async function deriveBytesMultiple(algorithm, baseKey, count, length) {
|
|
126
131
|
const totalBits = count * length * 8;
|
|
127
132
|
const bytes = await globalThis.crypto.subtle.deriveBits(algorithm, baseKey, totalBits);
|
|
128
133
|
return (0, import_array.createArray)(count, (index) => new Uint8Array(bytes.slice(index * length, index * length + length)));
|
package/utils/type-guards.d.ts
CHANGED
|
@@ -118,6 +118,12 @@ export declare function assertBlob(value: any, message?: AssertionMessage): asse
|
|
|
118
118
|
export declare function assertNotBlob<T>(value: T, message?: AssertionMessage): asserts value is InferIsNotType<T, typeof isBlob>;
|
|
119
119
|
export declare function assertBlobPass(value: any, message?: AssertionMessage): InferIsType<typeof isBlob>;
|
|
120
120
|
export declare function assertNotBlobPass<T>(value: T, message?: AssertionMessage): InferIsNotType<T, typeof isBlob>;
|
|
121
|
+
export declare function isBinaryData(value: any): value is BinaryData;
|
|
122
|
+
export declare function isNotBinaryData<T>(value: T): value is InferIsNotType<T, typeof isBinaryData>;
|
|
123
|
+
export declare function assertBinaryData(value: any, message?: AssertionMessage): asserts value is InferIsType<typeof isBinaryData>;
|
|
124
|
+
export declare function assertNotBinaryData<T>(value: T, message?: AssertionMessage): asserts value is InferIsNotType<T, typeof isBinaryData>;
|
|
125
|
+
export declare function assertBinaryDataPass(value: any, message?: AssertionMessage): InferIsType<typeof isBinaryData>;
|
|
126
|
+
export declare function assertNotBinaryDataPass<T>(value: T, message?: AssertionMessage): InferIsNotType<T, typeof isBinaryData>;
|
|
121
127
|
export declare function isArrayBuffer(value: any): value is ArrayBuffer;
|
|
122
128
|
export declare function isNotArrayBuffer<T>(value: T): value is InferIsNotType<T, typeof isArrayBuffer>;
|
|
123
129
|
export declare function assertArrayBuffer(value: any, message?: AssertionMessage): asserts value is InferIsType<typeof isArrayBuffer>;
|
package/utils/type-guards.js
CHANGED
|
@@ -31,6 +31,8 @@ __export(type_guards_exports, {
|
|
|
31
31
|
assertBigIntPass: () => assertBigIntPass,
|
|
32
32
|
assertBigUint64Array: () => assertBigUint64Array,
|
|
33
33
|
assertBigUint64ArrayPass: () => assertBigUint64ArrayPass,
|
|
34
|
+
assertBinaryData: () => assertBinaryData,
|
|
35
|
+
assertBinaryDataPass: () => assertBinaryDataPass,
|
|
34
36
|
assertBlob: () => assertBlob,
|
|
35
37
|
assertBlobPass: () => assertBlobPass,
|
|
36
38
|
assertBoolean: () => assertBoolean,
|
|
@@ -70,6 +72,8 @@ __export(type_guards_exports, {
|
|
|
70
72
|
assertNotBigIntPass: () => assertNotBigIntPass,
|
|
71
73
|
assertNotBigUint64Array: () => assertNotBigUint64Array,
|
|
72
74
|
assertNotBigUint64ArrayPass: () => assertNotBigUint64ArrayPass,
|
|
75
|
+
assertNotBinaryData: () => assertNotBinaryData,
|
|
76
|
+
assertNotBinaryDataPass: () => assertNotBinaryDataPass,
|
|
73
77
|
assertNotBlob: () => assertNotBlob,
|
|
74
78
|
assertNotBlobPass: () => assertNotBlobPass,
|
|
75
79
|
assertNotBoolean: () => assertNotBoolean,
|
|
@@ -178,6 +182,7 @@ __export(type_guards_exports, {
|
|
|
178
182
|
isBigInt: () => isBigInt,
|
|
179
183
|
isBigInt64Array: () => isBigInt64Array,
|
|
180
184
|
isBigUint64Array: () => isBigUint64Array,
|
|
185
|
+
isBinaryData: () => isBinaryData,
|
|
181
186
|
isBlob: () => isBlob,
|
|
182
187
|
isBoolean: () => isBoolean,
|
|
183
188
|
isDataView: () => isDataView,
|
|
@@ -197,6 +202,7 @@ __export(type_guards_exports, {
|
|
|
197
202
|
isNotBigInt: () => isNotBigInt,
|
|
198
203
|
isNotBigInt64Array: () => isNotBigInt64Array,
|
|
199
204
|
isNotBigUint64Array: () => isNotBigUint64Array,
|
|
205
|
+
isNotBinaryData: () => isNotBinaryData,
|
|
200
206
|
isNotBlob: () => isNotBlob,
|
|
201
207
|
isNotBoolean: () => isNotBoolean,
|
|
202
208
|
isNotDataView: () => isNotDataView,
|
|
@@ -642,6 +648,26 @@ function assertNotBlobPass(value, message) {
|
|
|
642
648
|
assertNotBlob(value, message);
|
|
643
649
|
return value;
|
|
644
650
|
}
|
|
651
|
+
function isBinaryData(value) {
|
|
652
|
+
return isArrayBuffer(value) || isArrayBufferView(value);
|
|
653
|
+
}
|
|
654
|
+
function isNotBinaryData(value) {
|
|
655
|
+
return !isBinaryData(value);
|
|
656
|
+
}
|
|
657
|
+
function assertBinaryData(value, message = "Expected value to be BinaryData.") {
|
|
658
|
+
assert(isBinaryData(value), message);
|
|
659
|
+
}
|
|
660
|
+
function assertNotBinaryData(value, message = "Expected value to not be BinaryData.") {
|
|
661
|
+
assert(isNotBinaryData(value), message);
|
|
662
|
+
}
|
|
663
|
+
function assertBinaryDataPass(value, message) {
|
|
664
|
+
assertBinaryData(value, message);
|
|
665
|
+
return value;
|
|
666
|
+
}
|
|
667
|
+
function assertNotBinaryDataPass(value, message) {
|
|
668
|
+
assertNotBinaryData(value, message);
|
|
669
|
+
return value;
|
|
670
|
+
}
|
|
645
671
|
function isArrayBuffer(value) {
|
|
646
672
|
return value instanceof ArrayBuffer;
|
|
647
673
|
}
|