dbcrossbarlib 0.5.3

Library for copying data between databases (pre-release)
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
//! Support for schemas specified using a subset of TypeScript.

#![allow(clippy::redundant_closure_call)]

use std::{
    collections::{HashMap, HashSet},
    fmt,
    hash::Hash,
    ops::Range,
    sync::Arc,
};

use crate::common::*;
use crate::parse_error::{Annotation, FileInfo, ParseError};
use crate::schema::{Column, DataType, StructField, Table};

/// We represent a span in our source code using a Rust range.
type Span = Range<usize>;

/// A node in our abstract syntax tree.
pub(crate) trait Node: fmt::Debug {
    /// The source span corresponding to this node.
    fn span(&self) -> Span;

    /// Recursively chec this node and all its child nodes for correctness.
    fn check(&self, source_file: &SourceFile) -> Result<(), ParseError>;
}

/// Interface for types which can be converted to `DataType`.
pub(crate) trait ToDataType {
    /// Convert this type to a `DataType`, given
    fn to_data_type(&self, source_file: &SourceFile) -> Result<DataType, ParseError>;
}

/// A TypeScript source file containing a limited set of type definitions.
pub(crate) struct SourceFile {
    /// Information about our input file. We manage this using an atomic reference count,
    /// so that we can share ownership with `ParseError`.
    file_info: Arc<FileInfo>,
    /// The type definitions found in this file.
    definitions: HashMap<String, Definition>,
}

impl SourceFile {
    /// Parse a source file containing TypeScript definitions.
    pub(crate) fn parse(
        file_name: String,
        file_contents: String,
    ) -> Result<Self, ParseError> {
        // Parse our input file into statements.
        let file_info = Arc::new(FileInfo::new(file_name, file_contents));
        let statements =
            typescript_grammar::statements(&file_info.contents).map_err(|err| {
                ParseError::new(
                    file_info.clone(),
                    vec![Annotation::primary(
                        err.location.offset,
                        format!("expected {}", err.expected),
                    )],
                    format!("error parsing {}", file_info.name),
                )
            })?;

        // Keep just the definitions.
        let definitions_vec = statements
            .into_iter()
            .filter_map(Statement::definition)
            .collect::<Vec<_>>();

        // Build a `HashMap` of our definitions, returning an error if we find
        // duplicate names.
        let mut definitions = HashMap::with_capacity(definitions_vec.len());
        for d in definitions_vec {
            let name = d.name().to_owned();
            if let Some(existing) = definitions.insert(name.as_str().to_owned(), d) {
                return Err(ParseError::new(
                    file_info,
                    vec![
                        Annotation::primary(name.span(), "duplicate definition here"),
                        Annotation::secondary(
                            existing.name().span(),
                            "existing definition here",
                        ),
                    ],
                    format!("duplicate definition of {}", name),
                ));
            }
        }

        // Build our `source_file` and check it for correctness.
        let source_file = SourceFile {
            file_info,
            definitions,
        };
        for d in source_file.definitions.values() {
            d.check(&source_file)?;
        }
        Ok(source_file)
    }

    /// Look up a definition in this source file.
    pub(crate) fn definition<'a>(&'a self, name: &str) -> Result<&'a Definition> {
        self.definitions.get(name).ok_or_else(|| {
            format_err!("type `{}` is not defined in {}", name, self.file_info.name)
        })
    }

    /// Look up a definition in the source file using an identifier.
    fn definition_for_identifier<'a>(
        &'a self,
        id: &Identifier,
    ) -> Result<&'a Definition, ParseError> {
        self.definitions.get(id.as_str()).ok_or_else(|| {
            ParseError::new(
                self.file_info.clone(),
                vec![Annotation::primary(
                    id.span(),
                    "cannot find the definition of this type",
                )],
                format!("cannot find definition of {}", id),
            )
        })
    }

    /// Look up a definition and recursively convert it to a portable [`Table`].
    pub(crate) fn definition_to_table(&self, name: &str) -> Result<Table> {
        let def = self.definition(name)?;
        match def.to_data_type(self)? {
            DataType::Struct(fields) => {
                Ok(Table {
                    name: name.to_owned(),
                    columns: fields.into_iter().map(|f| {
                        Column {
                            name: f.name,
                            is_nullable: f.is_nullable,
                            data_type: f.data_type,
                            comment: None,
                        }
                    }).collect(),
                })
            }
            _ => Err(ParseError::new(
                self.file_info.clone(),
                vec![Annotation::primary(
                    def.name().span(),
                    "expected an interface type",
                )],
                format!("cannot convert {} to a table schema because it is not an interface", name),
            ).into()),
        }
    }

    /// Look up an identifier and recursively convert it to a [`DataType`].
    pub(crate) fn identifier_to_data_type(
        &self,
        id: &Identifier,
    ) -> Result<DataType, ParseError> {
        let def = self.definition_for_identifier(id)?;
        def.to_data_type(self)
    }
}

#[derive(Debug)]
pub(crate) enum Statement {
    Definition(Definition),
    Empty,
}

impl Statement {
    fn definition(self) -> Option<Definition> {
        match self {
            Statement::Definition(d) => Some(d),
            Statement::Empty => None,
        }
    }
}

/// A type definition.
#[derive(Debug)]
pub(crate) enum Definition {
    /// An interface definition.
    Interface(Interface),
    /// A type alias.
    TypeAlias(Span, Identifier, Type),
}

impl Definition {
    pub(crate) fn name(&self) -> &Identifier {
        match self {
            Definition::Interface(iface) => &iface.name,
            Definition::TypeAlias(_, name, _) => name,
        }
    }
}

impl Node for Definition {
    fn span(&self) -> Span {
        match self {
            Definition::Interface(iface) => iface.span(),
            Definition::TypeAlias(span, _, _) => span.to_owned(),
        }
    }

    fn check(&self, source_file: &SourceFile) -> Result<(), ParseError> {
        match self {
            Definition::Interface(iface) => iface.check(source_file),
            Definition::TypeAlias(_, name, ty) => {
                name.check(source_file)?;
                ty.check(source_file)
            }
        }
    }
}

impl ToDataType for Definition {
    fn to_data_type(&self, source_file: &SourceFile) -> Result<DataType, ParseError> {
        match self {
            Definition::Interface(iface) => iface.to_data_type(source_file),
            Definition::TypeAlias(_, id, ty) => match id.as_str() {
                // These type aliases are magic when converting to a data type.
                "decimal" => {
                    ty.expect_string_and_or_number_type(source_file, id)?;
                    Ok(DataType::Decimal)
                }
                "int16" => {
                    ty.expect_string_and_or_number_type(source_file, id)?;
                    Ok(DataType::Int16)
                }
                "int32" => {
                    ty.expect_string_and_or_number_type(source_file, id)?;
                    Ok(DataType::Int32)
                }
                "int64" => {
                    ty.expect_string_and_or_number_type(source_file, id)?;
                    Ok(DataType::Int64)
                }

                // Ordinary type aliases are converted normally.
                _ => ty.to_data_type(source_file),
            },
        }
    }
}

/// An `interface` type.
#[derive(Debug)]
pub(crate) struct Interface {
    span: Span,
    name: Identifier,
    fields: Vec<Field>,
}

impl Node for Interface {
    fn span(&self) -> Span {
        self.span.clone()
    }

    fn check(&self, source_file: &SourceFile) -> Result<(), ParseError> {
        self.name.check(source_file)?;

        // Check our field.
        let mut seen = HashSet::new();
        for f in &self.fields {
            // Check for duplicate field names.
            if !seen.insert(f.name.clone()) {
                let existing = seen.get(&f.name).expect("item should be in set");
                return Err(ParseError::new(
                    source_file.file_info.clone(),
                    vec![
                        Annotation::primary(f.name.span(), "defined again here"),
                        Annotation::secondary(
                            existing.span(),
                            "original definition here",
                        ),
                    ],
                    format!("duplicate definition of {} field", f.name),
                ));
            }

            // Check our field itself.
            f.check(source_file)?;
        }
        Ok(())
    }
}

impl ToDataType for Interface {
    fn to_data_type(&self, source_file: &SourceFile) -> Result<DataType, ParseError> {
        // Convert our struct.
        let fields = self
            .fields
            .iter()
            .map(|f| {
                let (optional, ty) = f.ty.to_possibly_optional_type();
                Ok(StructField {
                    name: f.name.as_str().to_owned(),
                    is_nullable: f.optional | optional,
                    data_type: ty.to_data_type(source_file)?,
                })
            })
            .collect::<Result<_, _>>()?;
        Ok(DataType::Struct(fields))
    }
}

/// A field in an interface (or other struct-like type).
#[derive(Debug)]
pub(crate) struct Field {
    span: Span,
    name: Identifier,
    optional: bool,
    ty: Type,
}

impl Node for Field {
    fn span(&self) -> Span {
        self.span.clone()
    }

    fn check(&self, source_file: &SourceFile) -> Result<(), ParseError> {
        self.name.check(source_file)?;
        self.ty.check(source_file)
    }
}

/// A TypeScript type, without any span information.
#[derive(Debug)]
pub(crate) enum TypeDetails {
    /// Any value.
    Any,
    //// An array type.
    Array(Box<Type>),
    /// A true or false value.
    Boolean,
    /// An ISO 8601 date, including timezone.
    Date,
    /// The null value.
    Null,
    /// A 64-bit floating point number.
    Number,
    /// A reference to another type by name.
    Ref(Identifier),
    /// A string.
    String,
    /// A type union (made with `|`).
    Union(Box<Type>, Box<Type>),
}

/// A TypeScript type.
#[derive(Debug)]
pub(crate) struct Type {
    span: Span,
    details: TypeDetails,
}

impl Type {
    /// Is this type equivalent to an SQL NULL?
    fn is_sql_null(&self) -> bool {
        matches!(&self.details, TypeDetails::Null)
    }

    /// Is this a string type?
    fn is_string(&self) -> bool {
        matches!(&self.details, TypeDetails::String)
    }

    /// Is this a numeric type?
    fn is_number(&self) -> bool {
        matches!(&self.details, TypeDetails::Number)
    }

    /// If this type is `x | null` or `null | x`, return `(true, x)`. Otherwise,
    /// return `(false, self)`.
    fn to_possibly_optional_type(&self) -> (bool, &Type) {
        match &self.details {
            TypeDetails::Union(t1, t2) if t2.is_sql_null() => (true, t1),
            TypeDetails::Union(t1, t2) if t1.is_sql_null() => (true, t2),
            _ => (false, self),
        }
    }

    /// Check to see if this type is equal to `number`, `string`, or `number |
    /// string`, and if it isn't, blame it on `id`.
    fn expect_string_and_or_number_type(
        &self,
        source_file: &SourceFile,
        id: &Identifier,
    ) -> Result<(), ParseError> {
        match &self.details {
            TypeDetails::Number => Ok(()),
            TypeDetails::String => Ok(()),
            TypeDetails::Union(t1, t2) if t1.is_string() && t2.is_number() => Ok(()),
            TypeDetails::Union(t1, t2) if t1.is_number() && t2.is_string() => Ok(()),
            _ => Err(ParseError::new(
                source_file.file_info.clone(),
                vec![
                    Annotation::primary(
                        self.span.clone(),
                        "expected `number | string`",
                    ),
                    Annotation::secondary(id.span(), "because this name is reserved"),
                ],
                format!("unexpected definition of type {}", id),
            )),
        }
    }
}

impl Node for Type {
    fn span(&self) -> Span {
        self.span.clone()
    }

    fn check(&self, source_file: &SourceFile) -> Result<(), ParseError> {
        match &self.details {
            TypeDetails::Any
            | TypeDetails::Boolean
            | TypeDetails::Date
            | TypeDetails::Null
            | TypeDetails::Number
            | TypeDetails::String => Ok(()),

            TypeDetails::Array(elem_ty) => elem_ty.check(source_file),

            // Make sure names refer to something.
            TypeDetails::Ref(id) => {
                source_file.definition_for_identifier(id).map(|_| ())
            }

            TypeDetails::Union(t1, t2) => {
                t1.check(source_file)?;
                t2.check(source_file)
            }
        }
    }
}

impl ToDataType for Type {
    fn to_data_type(&self, source_file: &SourceFile) -> Result<DataType, ParseError> {
        match &self.details {
            TypeDetails::Any => Ok(DataType::Json),

            TypeDetails::Array(elem) => elem
                .to_data_type(source_file)
                .map(|ty| DataType::Array(Box::new(ty))),

            TypeDetails::Boolean => Ok(DataType::Bool),

            TypeDetails::Date => Ok(DataType::TimestampWithTimeZone),

            TypeDetails::Null => Err(ParseError::new(
                source_file.file_info.clone(),
                vec![Annotation::primary(
                    self.span.clone(),
                    "null type found here",
                )],
                "cannot convert `null` type to dbcrossbar type",
            )),

            TypeDetails::Number => Ok(DataType::Float64),

            TypeDetails::Ref(id) => source_file.identifier_to_data_type(id),

            TypeDetails::String => Ok(DataType::Text),

            TypeDetails::Union(_, _) => Err(ParseError::new(
                source_file.file_info.clone(),
                vec![Annotation::primary(
                    self.span.clone(),
                    "union type found here",
                )],
                "cannot convert union type to dbcrossbar type",
            )),
        }
    }
}

/// A TypeScript identifier.
#[derive(Clone, Debug)]
pub(crate) struct Identifier(Span, String);

impl Identifier {
    /// The underlying string for this identifier.
    fn as_str(&self) -> &str {
        &self.1
    }
}

/// Two identifiers are equal if their name is equal, ignoring the span information.
impl PartialEq for Identifier {
    fn eq(&self, other: &Self) -> bool {
        self.1.eq(&other.1)
    }
}

/// Two identifiers are equal if their name is equal, ignoring the span information.
impl Eq for Identifier {}

/// Two identifiers hash the same if their names hash the same, ignoring the
/// span information.
impl Hash for Identifier {
    fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
        self.1.hash(state)
    }
}

impl fmt::Display for Identifier {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "`{}`", self.1)
    }
}

impl Node for Identifier {
    fn span(&self) -> Span {
        self.0.clone()
    }

    fn check(&self, _source_file: &SourceFile) -> Result<(), ParseError> {
        // There's nothing to check here, not really.
        Ok(())
    }
}

peg::parser! {
    grammar typescript_grammar() for str {
        pub(crate) rule statements() -> Vec<Statement>
            = ws()? statements:(statement() ** (ws()?)) ws()? {
                statements
            }

        rule statement() -> Statement
            = d:definition() { Statement::Definition(d) }
            / ";" { Statement::Empty }

        rule definition() -> Definition
            = iface:interface() { Definition::Interface(iface) }
            / s:position!() "type" ws() name:identifier() ws()? "=" ws()?
                ty:ty() ws()? e:position!() ";"
            {
                Definition::TypeAlias(s..e, name, ty)
            }

        rule interface() -> Interface
            = s:position!() "interface" ws() name:identifier() ws()? "{"
                ws()? fields:fields() ws()? "}" e:position!()
            {
                Interface { span: s..e, name, fields }
            }

        rule fields() -> Vec<Field>
            = fields:(field() ** (ws()? "," ws()?)) (ws()? ",")? { fields }

        rule field() -> Field
            = s:position!() name:identifier() optional:optional_mark() ":" ws()?
                ty:ty() e:position!()
            {
                Field { span: s..e, name, optional, ty }
            }

        // For optional fields.
        rule optional_mark() -> bool
            = ws()? "?" { true }
            / { false }

        // Type expressions. We parse this using `precedence!`, which parses
        // prefix, postfix, left-associative and right associative operators
        // using the "packrat" algorithm, so we don't need to write this rule
        // out the hard way.
        //
        // The lowest-pecedence operators are on top, and the highest on bottom.
        rule ty() -> Type = precedence! {
            // This rule is special: it exists to wrap all the other rules in a
            // `Type` with span information. The `position!()` macro only works
            // in this rule.
            s:position!() details:@ e:position!() {
                Type { span: s..e, details }
            }
            --
            left:(@) ws()? "|" ws()? right:@ {
                TypeDetails::Union(Box::new(left), Box::new(right))
            }
            --
            elem:@ ws()? "[" ws()? "]" {
                TypeDetails::Array(Box::new(elem))
            }
            --
            "any" { TypeDetails::Any }
            "boolean" { TypeDetails::Boolean }
            "Date" { TypeDetails::Date }
            "null" { TypeDetails::Null }
            "number" { TypeDetails::Number }
            "string" { TypeDetails::String }
            id:identifier() { TypeDetails::Ref(id) }
        }

        rule identifier() -> Identifier
            = quiet! {
                s:position!()
                id:$(
                    ['A'..='Z' | 'a'..='z' | '_']
                    ['A'..='Z' | 'a'..='z' | '_' | '0'..='9']*
                )
                e:position!()
                { Identifier(s..e, id.to_owned()) }

            }
            / expected!("identifier")

        // Whitespace, including comments. We don't normally want whitespace to
        // show up as an "expected" token in error messages, so we carefully
        // enclose _most_ of this in `quiet!`. The exception is the closing
        // "*/" in a block comment, which we want to mention explicitly.
        rule ws() = (quiet! { [' ' | '\t' | '\r' | '\n'] } / line_comment() / block_comment())+

        rule line_comment() = quiet! { "//" (!['\n'][_])* ( "\n" / ![_] ) }

        rule block_comment() = quiet! { "/*"(!"*/"[_])* } "*/"
    }
}

#[test]
fn parses_typescript_and_converts_to_data_type() -> Result<()> {
    let input = r#"
type decimal = string;

/** Prices in the shop's currency, and the user's currency. */
interface PriceSet {
    shop_money: Money,
    presentement_money: Money,
};

/** A quantity of money, and an associated currency. */
interface Money {
    amount: decimal, // Currency decimal encoded as string.
    currency_code: string,
};
"#;
    let source_file = SourceFile::parse("test.ts".to_owned(), input.to_owned())?;
    assert_eq!(
        source_file.definition_to_table("PriceSet")?,
        Table {
            name: "PriceSet".to_owned(),
            columns: vec![
                Column {
                    name: "shop_money".to_owned(),
                    is_nullable: false,
                    data_type: DataType::Struct(vec![
                        StructField {
                            name: "amount".to_owned(),
                            is_nullable: false,
                            data_type: DataType::Decimal,
                        },
                        StructField {
                            name: "currency_code".to_owned(),
                            is_nullable: false,
                            data_type: DataType::Text,
                        },
                    ]),
                    comment: None,
                },
                Column {
                    name: "presentement_money".to_owned(),
                    is_nullable: false,
                    data_type: DataType::Struct(vec![
                        StructField {
                            name: "amount".to_owned(),
                            is_nullable: false,
                            data_type: DataType::Decimal,
                        },
                        StructField {
                            name: "currency_code".to_owned(),
                            is_nullable: false,
                            data_type: DataType::Text,
                        },
                    ]),
                    comment: None,
                },
            ]
        },
    );
    Ok(())
}

#[test]
fn handles_magic_types() -> Result<()> {
    let input = r#"
// These type declarations are automatically recognized and converted to the
// appropriate `dbcrossbar` types.
type decimal = string;
type int16 = number | string;
type int32 = string | number;
type int64 = number | string;

interface Magic {
    decimal: decimal,
    int16: int16,
    int32: int32,
    int64: int64,
}
"#;
    let source_file = SourceFile::parse("test.ts".to_owned(), input.to_owned())?;
    assert_eq!(
        source_file.definition_to_table("Magic")?,
        Table {
            name: "Magic".to_owned(),
            columns: vec![
                Column {
                    name: "decimal".to_owned(),
                    is_nullable: false,
                    data_type: DataType::Decimal,
                    comment: None,
                },
                Column {
                    name: "int16".to_owned(),
                    is_nullable: false,
                    data_type: DataType::Int16,
                    comment: None,
                },
                Column {
                    name: "int32".to_owned(),
                    is_nullable: false,
                    data_type: DataType::Int32,
                    comment: None,
                },
                Column {
                    name: "int64".to_owned(),
                    is_nullable: false,
                    data_type: DataType::Int64,
                    comment: None,
                },
            ]
        },
    );
    Ok(())
}

#[test]
fn rejects_invalid_magic_types() {
    let invalid_declarations = &[
        "type decimal = boolean;\ninterface Example { f: decimal, }",
        "type int16 = boolean;\ninterface Example { f: int16, }",
        "type int32 = boolean;\ninterface Example { f: int32, }",
    ];
    for &decl in invalid_declarations {
        let source_file =
            SourceFile::parse("test.ts".to_owned(), decl.to_owned()).unwrap();
        assert!(source_file.definition_to_table("Example").is_err());
    }
}

#[test]
fn detects_duplicate_field_names() {
    let input = r#"
interface Point {
    x: number,
    x: number,
};
"#;
    // This error should be detected at `parse` time.
    assert!(SourceFile::parse("test.ts".to_owned(), input.to_owned()).is_err());
}

#[test]
fn parses_shopify_schema() -> Result<()> {
    let file_string = include_str!("../../../../dbcrossbar/fixtures/shopify.ts");
    let source_file =
        SourceFile::parse("shopify.ts".to_owned(), file_string.to_owned())?;
    source_file.definition_to_table("Order")?;
    Ok(())
}