Skip to content

Commit

Permalink
Add good descriptions for the match patterns for seedPacketLocation, …
Browse files Browse the repository at this point in the history
…seedReferenceID, etc.

These descriptions shou up in the messages in schema validation.

Part of #3.
  • Loading branch information
jkomoros committed Jun 24, 2023
1 parent 27d0c5b commit deb40cc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
3 changes: 2 additions & 1 deletion seed-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"properties": {
"ref": {
"type": "string",
"pattern": "^(([.]{1,2}\\/[\\w./-]+#)|#?)[a-zA-Z0-9-_]*$"
"pattern": "^(([.]{1,2}\\/[\\w./-]+#)|#?)[a-zA-Z0-9-_]*$",
"description": "A seed reference is either a naked SeedLocalID, or includes a prepended #, or a location#id"
}
},
"required": [
Expand Down
16 changes: 12 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ const absoluteRegExp = (r : RegExp) : RegExp => {

const localSeedIDRegExp = new RegExp('[a-zA-Z0-9-_]*');

export const localSeedID = z.string().regex(absoluteRegExp(localSeedIDRegExp));
export const localSeedID = z
.string()
.regex(absoluteRegExp(localSeedIDRegExp))
.describe('A local seed ID must just be letters, numbers, dashes, and underscores');

//A localSeedID is what a Seed is known as within the context of a specific seed packet:
export type LocalSeedID = z.infer<typeof localSeedID>;
Expand All @@ -58,15 +61,20 @@ export type LocalSeedID = z.infer<typeof localSeedID>;
const locationRegExp = new RegExp('[.]{1,2}\/[\\w./-]+');

//TODO: support https://
//TODO: give good descriptions of the pattern with describe()
export const seedPacketLocation = z.string().regex(absoluteRegExp(locationRegExp));
export const seedPacketLocation = z
.string()
.regex(absoluteRegExp(locationRegExp))
.describe('A seed packet location must be a relative path, starting with . or ..');

export type SeedPacketLocation = z.infer<typeof seedPacketLocation>;

//You can skip the preceding '#' if there is no location
const seedReferenceIDRegExp = new RegExp('((' + locationRegExp.source + '#)|#?)' + localSeedIDRegExp.source);

export const seedReferenceID = z.string().regex(absoluteRegExp(seedReferenceIDRegExp));
export const seedReferenceID = z
.string()
.regex(absoluteRegExp(seedReferenceIDRegExp))
.describe('A seed reference is either a naked SeedLocalID, or includes a prepended #, or a location#id');

export type SeedReferenceID = z.infer<typeof seedReferenceID>;

Expand Down

0 comments on commit deb40cc

Please sign in to comment.