Skip to content

Commit 095402b

Browse files
committed
Fix sending dates through the protocol
Fixes #253.
1 parent 7883753 commit 095402b

File tree

9 files changed

+267
-22
lines changed

9 files changed

+267
-22
lines changed

packages/protocol/src/browser/modules/fs.ts

+5-11
Original file line numberDiff line numberDiff line change
@@ -317,17 +317,7 @@ export class FsModule {
317317
}
318318

319319
class Stats implements fs.Stats {
320-
public readonly atime: Date;
321-
public readonly mtime: Date;
322-
public readonly ctime: Date;
323-
public readonly birthtime: Date;
324-
325-
public constructor(private readonly stats: IStats) {
326-
this.atime = new Date(stats.atime);
327-
this.mtime = new Date(stats.mtime);
328-
this.ctime = new Date(stats.ctime);
329-
this.birthtime = new Date(stats.birthtime);
330-
}
320+
public constructor(private readonly stats: IStats) {}
331321

332322
public get dev(): number { return this.stats.dev; }
333323
public get ino(): number { return this.stats.ino; }
@@ -339,6 +329,10 @@ class Stats implements fs.Stats {
339329
public get size(): number { return this.stats.size; }
340330
public get blksize(): number { return this.stats.blksize; }
341331
public get blocks(): number { return this.stats.blocks; }
332+
public get atime(): Date { return this.stats.atime; }
333+
public get mtime(): Date { return this.stats.mtime; }
334+
public get ctime(): Date { return this.stats.ctime; }
335+
public get birthtime(): Date { return this.stats.birthtime; }
342336
public get atimeMs(): number { return this.stats.atimeMs; }
343337
public get mtimeMs(): number { return this.stats.mtimeMs; }
344338
public get ctimeMs(): number { return this.stats.ctimeMs; }

packages/protocol/src/common/util.ts

+7
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ export const argumentToProto = (
6565
const arg = new Argument.ProxyValue();
6666
arg.setId(storeProxy(currentValue));
6767
message.setProxy(arg);
68+
} else if (currentValue instanceof Date
69+
|| (currentValue && typeof currentValue.getTime === "function")) {
70+
const arg = new Argument.DateValue();
71+
arg.setDate(currentValue.toString());
72+
message.setDate(arg);
6873
} else if (currentValue !== null && typeof currentValue === "object") {
6974
const arg = new Argument.ObjectValue();
7075
const map = arg.getDataMap();
@@ -136,6 +141,8 @@ export const protoToArgument = (
136141
}
137142

138143
return createProxy(currentMessage.getProxy()!.getId());
144+
case Argument.MsgCase.DATE:
145+
return new Date(currentMessage.getDate()!.getDate());
139146
case Argument.MsgCase.OBJECT:
140147
const obj: { [Key: string]: any } = {};
141148
currentMessage.getObject()!.getDataMap().forEach((argument, key) => {

packages/protocol/src/node/modules/fs.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ export interface Stats {
2424
mtimeMs: number;
2525
ctimeMs: number;
2626
birthtimeMs: number;
27-
atime: Date | string;
28-
mtime: Date | string;
29-
ctime: Date | string;
30-
birthtime: Date | string;
27+
atime: Date;
28+
mtime: Date;
29+
ctime: Date;
30+
birthtime: Date;
3131
_isFile: boolean;
3232
_isDirectory: boolean;
3333
_isBlockDevice: boolean;

packages/protocol/src/node/server.ts

+1
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ export class Server {
317317
logger.trace(() => [
318318
"sending reject",
319319
field("id", id) ,
320+
field("message", error.message),
320321
]);
321322

322323
const failedMessage = new Method.Fail();

packages/protocol/src/proto/node.proto

+5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ message Argument {
4040

4141
message UndefinedValue {}
4242

43+
message DateValue {
44+
string date = 1;
45+
}
46+
4347
oneof msg {
4448
ErrorValue error = 1;
4549
BufferValue buffer = 2;
@@ -52,6 +56,7 @@ message Argument {
5256
double number = 9;
5357
string string = 10;
5458
bool boolean = 11;
59+
DateValue date = 12;
5560
}
5661
}
5762

packages/protocol/src/proto/node_pb.d.ts

+27
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ export class Argument extends jspb.Message {
5959
getBoolean(): boolean;
6060
setBoolean(value: boolean): void;
6161

62+
hasDate(): boolean;
63+
clearDate(): void;
64+
getDate(): Argument.DateValue | undefined;
65+
setDate(value?: Argument.DateValue): void;
66+
6267
getMsgCase(): Argument.MsgCase;
6368
serializeBinary(): Uint8Array;
6469
toObject(includeInstance?: boolean): Argument.AsObject;
@@ -83,6 +88,7 @@ export namespace Argument {
8388
number: number,
8489
string: string,
8590
pb_boolean: boolean,
91+
date?: Argument.DateValue.AsObject,
8692
}
8793

8894
export class ErrorValue extends jspb.Message {
@@ -248,6 +254,26 @@ export namespace Argument {
248254
}
249255
}
250256

257+
export class DateValue extends jspb.Message {
258+
getDate(): string;
259+
setDate(value: string): void;
260+
261+
serializeBinary(): Uint8Array;
262+
toObject(includeInstance?: boolean): DateValue.AsObject;
263+
static toObject(includeInstance: boolean, msg: DateValue): DateValue.AsObject;
264+
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
265+
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
266+
static serializeBinaryToWriter(message: DateValue, writer: jspb.BinaryWriter): void;
267+
static deserializeBinary(bytes: Uint8Array): DateValue;
268+
static deserializeBinaryFromReader(message: DateValue, reader: jspb.BinaryReader): DateValue;
269+
}
270+
271+
export namespace DateValue {
272+
export type AsObject = {
273+
date: string,
274+
}
275+
}
276+
251277
export enum MsgCase {
252278
MSG_NOT_SET = 0,
253279
ERROR = 1,
@@ -261,6 +287,7 @@ export namespace Argument {
261287
NUMBER = 9,
262288
STRING = 10,
263289
BOOLEAN = 11,
290+
DATE = 12,
264291
}
265292
}
266293

0 commit comments

Comments
 (0)