Skip to content

Commit a1825dd

Browse files
committed
create alternate versions of modules to account for alternate stream types;
1 parent 9bd74dc commit a1825dd

File tree

7 files changed

+1852
-155
lines changed

7 files changed

+1852
-155
lines changed

src/Console__.re

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// We'll only bind to the instance version of console.Console for now: https://nodejs.org/api/console.html
2+
// For global console.log and others, use the existing Js.Console.* provided by BuckleScript out of the box
3+
4+
type t;
5+
[@bs.val] external console: t = "console";
6+
7+
type consoleOptions;
8+
[@bs.obj]
9+
external consoleOptions:
10+
(
11+
~stdout: Stream__.Writable.subtype('w, 'a),
12+
~stderr: Stream__.Writable.subtype('w, 'a)=?,
13+
~ignoreErrors: bool=?,
14+
~colorMode: bool=?,
15+
~inspectOptions: Util.inspectOptions=?,
16+
unit
17+
) =>
18+
consoleOptions;
19+
20+
[@bs.new] [@bs.module "console"]
21+
external make: consoleOptions => t = "Console";
22+
[@bs.new] [@bs.module "console"]
23+
external make2: {.. "stdout": Stream__.Writable.subtype('w, 'a)} => t =
24+
"Console";
25+
26+
[@bs.send] external assert_: (t, bool) => unit = "assert";
27+
// TODO: reconsider naming
28+
[@bs.send] external assertWithMessage: (t, bool, string) => unit = "assert";
29+
[@bs.send] external clear: (t, unit) => unit = "clear";
30+
[@bs.send] external count: (t, string) => unit = "count";
31+
[@bs.send] external countReset: (t, string) => unit = "countReset";
32+
33+
[@bs.send] external debug: (t, string) => unit = "debug";
34+
[@bs.send] [@bs.variadic]
35+
external debugMany: (t, array('a)) => unit = "debug";
36+
37+
[@bs.send] external dir: (t, string) => unit = "dir";
38+
[@bs.send] [@bs.variadic] external dirMany: (t, array('a)) => unit = "dir";
39+
40+
[@bs.send] external dirxml: (t, string) => unit = "dirxml";
41+
[@bs.send] [@bs.variadic]
42+
external dirxmlMany: (t, array('a)) => unit = "dirxml";
43+
44+
[@bs.send] external error: (t, string) => unit = "error";
45+
[@bs.send] [@bs.variadic]
46+
external errorMany: (t, array('a)) => unit = "error";
47+
48+
[@bs.send] external group: (t, string) => unit = "group";
49+
[@bs.send] [@bs.variadic]
50+
external groupMany: (t, array('a)) => unit = "group";
51+
52+
[@bs.send] external groupEnd: (t, unit) => unit = "groupEnd";
53+
54+
[@bs.send] external info: (t, string) => unit = "info";
55+
[@bs.send] [@bs.variadic] external infoMany: (t, array('a)) => unit = "info";
56+
57+
[@bs.send] external log: (t, string) => unit = "log";
58+
[@bs.send] [@bs.variadic] external logMany: (t, array('a)) => unit = "log";
59+
60+
[@bs.send] external table: (t, array('a)) => unit = "table";
61+
62+
[@bs.send] external time: (t, string) => unit = "time";
63+
64+
//TODO: research more into this function. Not sure how it works.
65+
[@bs.send] [@bs.variadic]
66+
external timeLog: (t, string, array('a)) => unit = "timeLog";
67+
68+
[@bs.send] external trace: (t, string) => unit = "trace";
69+
[@bs.send] [@bs.variadic]
70+
external traceMany: (t, array('a)) => unit = "trace";
71+
72+
[@bs.send] external warn: (t, string) => unit = "warn";
73+
[@bs.send] [@bs.variadic] external warnMany: (t, array('a)) => unit = "warn";

src/Crypto__.re

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
/**
2+
* UNDER CONSTRUCTION - API UNSTABLE
3+
*/
4+
// TODO: Consider alternative implementation of KeyObject subtype.
5+
module KeyObject = {
6+
type t('a, 'b);
7+
type symmetric = [ | `Symmetric];
8+
type asymmetric = [ | `Asymmetric];
9+
type publicKey = [ | `PublicKey];
10+
type privateKey = [ | `PrivateKey];
11+
type secretKey = [ | `SecretKey];
12+
[@bs.send]
13+
external symmetricExport:
14+
t(symmetric, [< publicKey | privateKey]) => Buffer.t =
15+
"export";
16+
[@bs.send]
17+
external asymmetricExport:
18+
t(asymmetric, [< publicKey | privateKey | secretKey]) => Buffer.t =
19+
"export";
20+
module Symmetric = {
21+
type kind = [ symmetric];
22+
type nonrec t('a) = t([ kind], 'a);
23+
module Impl = {};
24+
};
25+
module Asymmetric = {
26+
type kind = [ asymmetric];
27+
type nonrec t('a) = t([ kind], 'a);
28+
module Impl = {};
29+
};
30+
module Impl = {
31+
include Symmetric.Impl;
32+
include Asymmetric.Impl;
33+
};
34+
include Impl;
35+
};
36+
37+
module PivateKey = {
38+
include KeyObject.Impl;
39+
type kind = [ KeyObject.publicKey];
40+
type t('a) = KeyObject.t('a, [ kind]);
41+
[@bs.module "crypto"] external make: Buffer.t => t('a) = "createPrivateKey";
42+
[@bs.module "crypto"]
43+
external makeWithPassphrase:
44+
{
45+
..
46+
"key": Buffer.t,
47+
"passphrase": Buffer.t,
48+
} =>
49+
t('a) =
50+
"createPrivateKey";
51+
};
52+
53+
module PublicKey = {
54+
include KeyObject.Impl;
55+
type kind = [ KeyObject.publicKey];
56+
type t('a) = KeyObject.t('a, [ kind]);
57+
[@bs.module "crypto"] external make: Buffer.t => t('a) = "createPublicKey";
58+
[@bs.module "crypto"]
59+
external fromPrivateKey: KeyObject.t('a, [> KeyObject.privateKey]) => t('a) =
60+
"createPublicKey";
61+
};
62+
63+
module Hash = {
64+
type kind('w, 'r) = [ Stream__.transform('w, 'r) | `Hash];
65+
type subtype('w, 'r, 'a) = Stream__.subtype([> kind('w, 'r)] as 'a);
66+
type supertype('w, 'r, 'a) = Stream__.subtype([< kind('w, 'r)] as 'a);
67+
type t = subtype(Buffer.t, Buffer.t, kind('w, 'r));
68+
module Impl = {
69+
include Stream__.Transform.Impl;
70+
[@bs.send] external copy: t => t = "copy";
71+
[@bs.send] external digest: t => Buffer.t = "digest";
72+
[@bs.send] external update: (t, Buffer.t) => unit = "update";
73+
};
74+
include Impl;
75+
};
76+
77+
[@bs.module "crypto"] external createHash: string => Hash.t = "createHash";
78+
79+
module Hmac = {
80+
type kind('w, 'r) = [ Stream__.transform('w, 'r) | `Hmac];
81+
type subtype('w, 'r, 'a) = Stream__.subtype([> kind('w, 'r)] as 'a);
82+
type supertype('w, 'r, 'a) = Stream__.subtype([< kind('w, 'r)] as 'a);
83+
type t = subtype(Buffer.t, Buffer.t, kind('w, 'r));
84+
module Impl = {
85+
include Stream__.Transform.Impl;
86+
[@bs.send] external digest: t => Buffer.t = "digest";
87+
[@bs.send] external update: (t, Buffer.t) => unit = "update";
88+
};
89+
include Impl;
90+
};
91+
92+
[@bs.module "crypto"]
93+
external createHmac: (string, ~key: string) => Hmac.t = "createHmac";
94+
95+
module Certificate = {
96+
type t;
97+
[@bs.send]
98+
external exportChallenge: (t, Buffer.t) => Buffer.t = "exportChallenge";
99+
[@bs.send]
100+
external exportPublicKey: (t, Buffer.t) => Buffer.t = "exportPublicKey";
101+
[@bs.send]
102+
external verifyCertificate: (t, Buffer.t) => bool = "verifyCertificate";
103+
};
104+
105+
module Cipher = {
106+
type kind('w, 'r) = [ Stream__.transform('w, 'r) | `Cipher];
107+
type subtype('w, 'r, 'a) = Stream__.subtype([> kind('w, 'r)] as 'a);
108+
type supertype('w, 'r, 'a) = Stream__.subtype([< kind('w, 'r)] as 'a);
109+
type t = subtype(Buffer.t, Buffer.t, kind('w, 'r));
110+
module Impl = {
111+
include Stream__.Transform.Impl;
112+
[@bs.send] external final: (t, string) => Buffer.t = "final";
113+
[@bs.send] external setAAD: (t, Buffer.t) => t = "setAAD";
114+
[@bs.send]
115+
external setAADWith:
116+
(
117+
t,
118+
Buffer.t,
119+
~options: Stream__.Transform.makeOptions(Buffer.t, Buffer.t)
120+
) =>
121+
t =
122+
"setAAD";
123+
[@bs.send] external getAuthTag: t => Buffer.t = "getAuthTag";
124+
[@bs.send] external setAutoPadding: (t, bool) => t = "setAutoPadding";
125+
[@bs.send] external update: (t, Buffer.t) => Buffer.t = "update";
126+
};
127+
include Impl;
128+
[@bs.module "crypto"]
129+
external make:
130+
(
131+
~algorithm: string,
132+
~key: KeyObject.t('a, [> KeyObject.secretKey]),
133+
~iv: Js.Null.t(Buffer.t)
134+
) =>
135+
t =
136+
"createCipheriv";
137+
[@bs.module "crypto"]
138+
external makeWith:
139+
(
140+
~algorithm: string,
141+
~key: KeyObject.t('a, [> KeyObject.secretKey]),
142+
~iv: Js.Null.t(Buffer.t),
143+
~options: Stream__.Transform.makeOptions(Buffer.t, Buffer.t)=?
144+
) =>
145+
t =
146+
"createCipheriv";
147+
};
148+
149+
module Decipher = {
150+
type kind('w, 'r) = [ Stream__.transform('w, 'r) | `Decipher];
151+
type subtype('w, 'r, 'a) = Stream__.subtype([> kind('w, 'r)] as 'a);
152+
type supertype('w, 'r, 'a) = Stream__.subtype([< kind('w, 'r)] as 'a);
153+
type t = subtype(Buffer.t, Buffer.t, kind('w, 'r));
154+
module Impl = {
155+
[@bs.send]
156+
external final: (subtype('w, 'r, 'a), string) => Buffer.t = "final";
157+
[@bs.send]
158+
external setAAD: (subtype('w, 'r, 'a), Buffer.t) => t = "setAAD";
159+
[@bs.send]
160+
external setAADWith:
161+
(
162+
subtype('w, 'r, 'a),
163+
Buffer.t,
164+
~options: Stream__.Transform.makeOptions(Buffer.t, Buffer.t)
165+
) =>
166+
t =
167+
"setAAD";
168+
[@bs.send]
169+
external setAuthTag: (subtype('w, 'r, 'a), Buffer.t) => t = "setAuthTag";
170+
[@bs.send]
171+
external setAutoPatting: (subtype('w, 'r, 'a), bool) => t =
172+
"setAutoPadding";
173+
[@bs.send]
174+
external update: (subtype('w, 'r, 'a), Buffer.t) => Buffer.t = "update";
175+
};
176+
include Impl;
177+
[@bs.module "crypto"]
178+
external make:
179+
(
180+
~algorithm: string,
181+
~key: KeyObject.t('a, [> KeyObject.secretKey]),
182+
~iv: Js.Null.t(Buffer.t)
183+
) =>
184+
t =
185+
"createDecipheriv";
186+
[@bs.module "crypto"]
187+
external makeWith:
188+
(
189+
~algorithm: string,
190+
~key: KeyObject.t('a, [> KeyObject.secretKey]),
191+
~iv: Js.Null.t(Buffer.t),
192+
~options: Stream__.Transform.makeOptions(Buffer.t, Buffer.t)=?
193+
) =>
194+
t =
195+
"createDecipheriv";
196+
};
197+
198+
// module DiffieHellman = {
199+
200+
// };
201+
202+
// module DiffieHellmanGroup = {
203+
204+
// };
205+
206+
// module Sign = {
207+
208+
// };
209+
210+
// module Verify = {
211+
212+
// };

src/Fs2.re renamed to src/Fs__.re

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -352,12 +352,12 @@ external openWithMode:
352352
"open";
353353

354354
module WriteStream = {
355-
type kind('w) = [ Stream2.writable('w) | `FileSystem];
356-
type subtype('w, 'ty) = Stream2.subtype([> kind('w)] as 'ty);
357-
type supertype('w, 'ty) = Stream2.subtype([< kind('w)] as 'ty);
355+
type kind('w) = [ Stream__.writable('w) | `FileSystem];
356+
type subtype('w, 'ty) = Stream__.subtype([> kind('w)] as 'ty);
357+
type supertype('w, 'ty) = Stream__.subtype([< kind('w)] as 'ty);
358358
type t = subtype(Buffer.t, [ kind(Buffer.t)]);
359359
module Impl = {
360-
include Stream2.Writable.Impl;
360+
include Stream__.Writable.Impl;
361361
[@bs.send]
362362
external bytesWritten: subtype('w, [> kind('w)]) => int = "bytesWritten";
363363
[@bs.send] external path: subtype('w, [> kind('w)]) => string = "path";
@@ -386,13 +386,13 @@ module WriteStream = {
386386
};
387387

388388
module ReadStream = {
389-
type kind('r) = [ Stream2.readable('r) | `FileSystem];
390-
type subtype('r, 'ty) = Stream2.subtype([> kind('r)] as 'ty);
389+
type kind('r) = [ Stream__.readable('r) | `FileSystem];
390+
type subtype('r, 'ty) = Stream__.subtype([> kind('r)] as 'ty);
391391
type supertype('r, 'ty) =
392-
Stream2.subtype([< kind('r)] as 'ty);
392+
Stream__.subtype([< kind('r)] as 'ty);
393393
type t = subtype(Buffer.t, [ kind(Buffer.t)]);
394394
module Impl = {
395-
include Stream2.Readable.Impl;
395+
include Stream__.Readable.Impl;
396396
[@bs.send]
397397
external bytesRead: subtype('r, [> kind('r)]) => int = "bytesWritten";
398398
[@bs.send] external path: subtype('r, [> kind('r)]) => string = "path";

0 commit comments

Comments
 (0)