This repository has been archived by the owner on Nov 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
517 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
module.exports = | ||
|
||
# Variables | ||
expanded: {} | ||
dataStructures: {} | ||
|
||
# Copy all member types from one data structure to another | ||
# | ||
# @param supertTypeName [String] The name of the super type data structure | ||
# @param memberTypeSection [Object] Member Type Section to be copied into | ||
copyMembers: (superTypeName, memberTypeSection) -> | ||
return if not @dataStructures[superTypeName] | ||
|
||
for section in @dataStructures[superTypeName].sections | ||
if section['class'] is 'memberType' | ||
|
||
for member in section.content | ||
memberTypeSection.content.push member if member['class'] is 'property' | ||
|
||
# Given a data structure, expand it's inheritance recursively | ||
# | ||
# @param name [String] Name of the data structure | ||
# @param dataStructure [Object] Data structure | ||
expandInheritance: (name, dataStructure) -> | ||
return if @expanded[name] | ||
|
||
# Check for inheritance | ||
superType = dataStructure.typeDefinition.typeSpecification.name | ||
|
||
if typeof superType isnt 'object' or not superType?.literal | ||
return @expanded[superType] = true | ||
|
||
# Expand the super type first | ||
@expandInheritance superType, @dataStructures[superType.literal] | ||
|
||
# If super type is not an object | ||
superTypeBaseName = @dataStructures[superType.literal].typeDefinition.typeSpecification.name | ||
|
||
if superTypeBaseName isnt 'object' | ||
dataStructure.typeDefinition.typeSpecification.name = superTypeBaseName | ||
memberTypeSection = | ||
content: [] | ||
|
||
memberTypeSection['class'] = 'memberType' | ||
@copyMembers superType.literal, memberTypeSection | ||
|
||
dataStructure.sections.push memberTypeSection if memberTypeSection.content.length | ||
return @expanded[name] = true | ||
|
||
# Find member type section of the current data structure | ||
memberTypeSection = null | ||
push = false | ||
|
||
for section in dataStructure.sections | ||
memberTypeSection = section if section['class'] is 'memberType' | ||
|
||
# If no member type sections, create one | ||
if not memberTypeSection | ||
memberTypeSection = | ||
content: [] | ||
|
||
memberTypeSection['class'] = 'memberType' | ||
push = true | ||
|
||
# Copy super-type and all the member types to sub type | ||
dataStructure.typeDefinition.typeSpecification.name = superTypeBaseName | ||
@copyMembers superType.literal, memberTypeSection | ||
|
||
# Push the created type section | ||
dataStructure.sections.push memberTypeSection if push and memberTypeSection.content.length | ||
|
||
# Denote this type as expanded | ||
@expanded[name] = true | ||
|
||
init: (dataStructures) -> | ||
@expanded = {} | ||
@dataStructures = dataStructures | ||
|
||
# Initiate flags | ||
for name, dataStructure of @dataStructures | ||
@expanded[name] = false | ||
|
||
# Actual expansion | ||
for name, dataStructure of @dataStructures | ||
@expandInheritance name, dataStructure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = | ||
|
||
dataStructures: (dataStructures) -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = | ||
|
||
dataStructures: (dataStructures) -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
FORMAT: 1A | ||
|
||
# Stripe | ||
Inspired by stripe API | ||
|
||
# Data Structures | ||
|
||
## Timestamp (number) | ||
Unix timestamp as an integer | ||
|
||
## Timestamps (object) | ||
This object contains the following unix timestamps | ||
|
||
+ created - Denoting the time when the object is created | ||
+ modified - Denoting the time when the object has been recently updated | ||
|
||
### Properties | ||
+ created (Timestamp) | ||
|
||
### Properties | ||
+ modified (Timestamp) | ||
|
||
## Coupon Base (Timestamps) | ||
+ percent_off: 25 (number) | ||
|
||
A positive integer between 1 and 100 that represents the discount the coupon will apply. | ||
|
||
+ redeem_by (number) - Date after which the coupon can no longer be redeemed | ||
|
||
## Coupon Base Clone (Coupon Base) | ||
A clone of Coupon Base to be used for testing | ||
|
||
## Timestamp Clone (Timestamp) | ||
A clone of timestamp to be used for testing |
Oops, something went wrong.