-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from superfaceai/feat/document-id-interfaces
Feat/document id interfaces
- Loading branch information
Showing
11 changed files
with
447 additions
and
381 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,45 @@ | ||
/** | ||
* Structure representing semver version tag. | ||
*/ | ||
export type DocumentVersion = { | ||
major: number; | ||
minor?: number; | ||
/** Patch version cannot appear without minor version. */ | ||
patch?: number; | ||
/** Label can appear even without major and minor version. */ | ||
label?: string; | ||
}; | ||
/** | ||
* Generic structure that covers both partial profile and partial map ids. | ||
*/ | ||
export type DocumentId = { | ||
/** The optional leading scope before `/`. */ | ||
scope?: string; | ||
/** The middle portion between of the `[<scope>/]middle[@<version>]`, split by `.`. */ | ||
middle: string[]; | ||
/** The optional trailing version after `@`. */ | ||
version?: DocumentVersion; | ||
}; | ||
|
||
/** Information encoded in the profile id string. */ | ||
export type ProfileDocumentId = { | ||
/** Scope of the profile, if any. */ | ||
scope?: string; | ||
/** Name of the profile. */ | ||
name: string; | ||
/** Version of the profile. */ | ||
version: DocumentVersion; | ||
}; | ||
|
||
/** Information encoded in the map id string. */ | ||
export type MapDocumentId = { | ||
scope?: string; | ||
name: string; | ||
provider: string; | ||
variant?: string; | ||
version: { | ||
major: number; | ||
minor?: number; | ||
revision?: number; | ||
}; | ||
}; |
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 |
---|---|---|
@@ -1,12 +1,33 @@ | ||
import { parseMapId, parseProfileId, parseVersion } from './document_id'; | ||
import { | ||
parseDocumentId, | ||
parseMapId, | ||
parseProfileId, | ||
parseVersion, | ||
} from './parser'; | ||
|
||
describe('document name parsing', () => { | ||
it('parses minimal profile name', () => { | ||
it('parses partial profile name', () => { | ||
const id = 'my-profile'; | ||
|
||
expect(parseDocumentId(id)).toEqual({ | ||
kind: 'parsed', | ||
value: { | ||
middle: ['my-profile'], | ||
}, | ||
}); | ||
}); | ||
|
||
it('parses minimal profile name', () => { | ||
const id = 'my_profile@17'; | ||
|
||
expect(parseProfileId(id)).toEqual({ | ||
kind: 'parsed', | ||
name: 'my-profile', | ||
value: { | ||
name: 'my_profile', | ||
version: { | ||
major: 17, | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
|
@@ -15,47 +36,70 @@ describe('document name parsing', () => { | |
|
||
expect(parseProfileId(id)).toEqual({ | ||
kind: 'parsed', | ||
scope: 'my-sc0pe', | ||
name: 'my-profile', | ||
version: { | ||
major: 1, | ||
minor: 2, | ||
patch: 34, | ||
value: { | ||
scope: 'my-sc0pe', | ||
name: 'my-profile', | ||
version: { | ||
major: 1, | ||
minor: 2, | ||
patch: 34, | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('parses minimal map name', () => { | ||
it('parses partial map name', () => { | ||
const id = 'my-profile.x_prov1der'; | ||
|
||
expect(parseDocumentId(id)).toEqual({ | ||
kind: 'parsed', | ||
value: { | ||
middle: ['my-profile', 'x_prov1der'], | ||
}, | ||
}); | ||
}); | ||
|
||
it('parses minimal map name', () => { | ||
const id = 'prof.prov@32'; | ||
|
||
expect(parseMapId(id)).toEqual({ | ||
kind: 'parsed', | ||
name: 'my-profile', | ||
provider: 'x_prov1der', | ||
value: { | ||
name: 'prof', | ||
provider: 'prov', | ||
version: { | ||
major: 32, | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('parses full map name', () => { | ||
const id = 'our_scope/[email protected].34-rev567'; | ||
const id = 'our_scope/[email protected]'; | ||
|
||
expect(parseMapId(id)).toEqual({ | ||
kind: 'parsed', | ||
scope: 'our_scope', | ||
name: 'my-profile', | ||
provider: 'x_prov1der', | ||
variant: 'v4riant', | ||
version: { | ||
major: 1, | ||
minor: 2, | ||
patch: 34, | ||
revision: 567, | ||
value: { | ||
scope: 'our_scope', | ||
name: 'my-profile', | ||
provider: 'x_prov1der', | ||
variant: 'v4riant', | ||
version: { | ||
major: 1, | ||
minor: 2, | ||
revision: 567, | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('returns an error for uppercase', () => { | ||
const id = 'SCOPE/profile'; | ||
|
||
expect(parseDocumentId(id)).toStrictEqual({ | ||
kind: 'error', | ||
message: 'scope is not a valid lowercase identifier', | ||
}); | ||
expect(parseProfileId(id)).toStrictEqual({ | ||
kind: 'error', | ||
message: 'scope is not a valid lowercase identifier', | ||
|
@@ -67,12 +111,12 @@ describe('document name parsing', () => { | |
|
||
expect(parseMapId(id)).toStrictEqual({ | ||
kind: 'error', | ||
message: 'provider is not a valid lowercase identifier', | ||
message: '"" is not a valid lowercase identifier', | ||
}); | ||
|
||
expect(parseProfileId(id)).toStrictEqual({ | ||
kind: 'error', | ||
message: 'name is not a valid lowercase identifier', | ||
message: '"" is not a valid lowercase identifier', | ||
}); | ||
}); | ||
|
||
|
@@ -81,12 +125,12 @@ describe('document name parsing', () => { | |
|
||
expect(parseMapId(id)).toStrictEqual({ | ||
kind: 'error', | ||
message: 'variant is not a valid lowercase identifier', | ||
message: '"" is not a valid lowercase identifier', | ||
}); | ||
|
||
expect(parseProfileId(id)).toStrictEqual({ | ||
kind: 'error', | ||
message: 'name is not a valid lowercase identifier', | ||
message: '"" is not a valid lowercase identifier', | ||
}); | ||
}); | ||
|
||
|
@@ -96,7 +140,7 @@ describe('document name parsing', () => { | |
expect(parseMapId(id)).toStrictEqual({ | ||
kind: 'error', | ||
message: | ||
'could not parse revision: label must be in format `revN` where N is a non-negative integer', | ||
'revision label must be in format `revN` where N is a non-negative integer', | ||
}); | ||
}); | ||
|
||
|
Oops, something went wrong.