@@ -4,6 +4,7 @@ import { posix } from './create-paths';
4
4
import { AuthenticationClientService } from '../auth/authentication-client-service' ;
5
5
import { ArduinoPreferences } from '../arduino-preferences' ;
6
6
import { SketchCache } from '../widgets/cloud-sketchbook/cloud-sketch-cache' ;
7
+ import { Create , CreateError } from './typings' ;
7
8
8
9
export interface ResponseResultProvider {
9
10
( response : Response ) : Promise < any > ;
@@ -19,7 +20,7 @@ type ResourceType = 'f' | 'd';
19
20
@injectable ( )
20
21
export class CreateApi {
21
22
@inject ( SketchCache )
22
- protected readonly sketchCache : SketchCache ;
23
+ protected sketchCache : SketchCache ;
23
24
24
25
protected authenticationService : AuthenticationClientService ;
25
26
protected arduinoPreferences : ArduinoPreferences ;
@@ -34,10 +35,6 @@ export class CreateApi {
34
35
return this ;
35
36
}
36
37
37
- public wipeCache ( ) : void {
38
- this . sketchCache . init ( ) ;
39
- }
40
-
41
38
getSketchSecretStat ( sketch : Create . Sketch ) : Create . Resource {
42
39
return {
43
40
href : `${ sketch . href } ${ posix . sep } ${ Create . arduino_secrets_file } ` ,
@@ -50,7 +47,7 @@ export class CreateApi {
50
47
} ;
51
48
}
52
49
53
- async sketch ( id : string ) : Promise < Create . Sketch | undefined > {
50
+ async sketch ( id : string ) : Promise < Create . Sketch > {
54
51
const url = new URL ( `${ this . domain ( ) } /sketches/byID/${ id } ` ) ;
55
52
56
53
url . searchParams . set ( 'user_id' , 'me' ) ;
@@ -303,7 +300,9 @@ export class CreateApi {
303
300
secrets : { data : secrets } ,
304
301
} ;
305
302
306
- // replace the sketch in the cache, so other calls will not overwrite each other
303
+ // replace the sketch in the cache with the one we are pushing
304
+ // TODO: we should do a get after the POST, in order to be sure the cache
305
+ // is updated the most recent metadata
307
306
this . sketchCache . addSketch ( sketch ) ;
308
307
309
308
const init = {
@@ -458,76 +457,3 @@ void loop() {
458
457
459
458
` ;
460
459
}
461
-
462
- export namespace Create {
463
- export interface Sketch {
464
- readonly name : string ;
465
- readonly path : string ;
466
- readonly modified_at : string ;
467
- readonly created_at : string ;
468
-
469
- readonly secrets ?: { name : string ; value : string } [ ] ;
470
-
471
- readonly id : string ;
472
- readonly is_public : boolean ;
473
- // readonly board_fqbn: '',
474
- // readonly board_name: '',
475
- // readonly board_type: 'serial' | 'network' | 'cloud' | '',
476
- readonly href ?: string ;
477
- readonly libraries : string [ ] ;
478
- // readonly tutorials: string[] | null;
479
- // readonly types: string[] | null;
480
- // readonly user_id: string;
481
- }
482
-
483
- export type ResourceType = 'sketch' | 'folder' | 'file' ;
484
- export const arduino_secrets_file = 'arduino_secrets.h' ;
485
- export interface Resource {
486
- readonly name : string ;
487
- /**
488
- * Note: this path is **not** the POSIX path we use. It has the leading segments with the `user_id`.
489
- */
490
- readonly path : string ;
491
- readonly type : ResourceType ;
492
- readonly sketchId ?: string ;
493
- readonly modified_at : string ; // As an ISO-8601 formatted string: `YYYY-MM-DDTHH:mm:ss.sssZ`
494
- readonly created_at : string ; // As an ISO-8601 formatted string: `YYYY-MM-DDTHH:mm:ss.sssZ`
495
- readonly children ?: number ; // For 'sketch' and 'folder' types.
496
- readonly size ?: number ; // For 'sketch' type only.
497
- readonly isPublic ?: boolean ; // For 'sketch' type only.
498
-
499
- readonly mimetype ?: string ; // For 'file' type.
500
- readonly href ?: string ;
501
- }
502
- export namespace Resource {
503
- export function is ( arg : any ) : arg is Resource {
504
- return (
505
- ! ! arg &&
506
- 'name' in arg &&
507
- typeof arg [ 'name' ] === 'string' &&
508
- 'path' in arg &&
509
- typeof arg [ 'path' ] === 'string' &&
510
- 'type' in arg &&
511
- typeof arg [ 'type' ] === 'string' &&
512
- 'modified_at' in arg &&
513
- typeof arg [ 'modified_at' ] === 'string' &&
514
- ( arg [ 'type' ] === 'sketch' ||
515
- arg [ 'type' ] === 'folder' ||
516
- arg [ 'type' ] === 'file' )
517
- ) ;
518
- }
519
- }
520
-
521
- export type RawResource = Omit < Resource , 'sketchId' | 'isPublic' > ;
522
- }
523
-
524
- export class CreateError extends Error {
525
- constructor (
526
- message : string ,
527
- readonly status : number ,
528
- readonly details ?: string
529
- ) {
530
- super ( message ) ;
531
- Object . setPrototypeOf ( this , CreateError . prototype ) ;
532
- }
533
- }
0 commit comments