Skip to content

Commit

Permalink
Make it so objects can have keys that include ':', '.', etc.
Browse files Browse the repository at this point in the history
This allows `let-multi` to be used to set environment variables that have a prefix, as is convention.

Part of #36.
  • Loading branch information
jkomoros committed Jul 4, 2023
1 parent 7203a03 commit a925bdb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
8 changes: 4 additions & 4 deletions seed-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@
"$ref": "#/definitions/seedData/anyOf/5/properties/value/anyOf/2/anyOf/0"
},
"propertyNames": {
"pattern": "^(?!type$)[a-zA-Z0-9_-]+$"
"pattern": "^(?!type$)[a-zA-Z0-9-_.:]*$"
}
}
]
Expand Down Expand Up @@ -1172,7 +1172,7 @@
"$ref": "#/definitions/seedData/anyOf/5/properties/value/anyOf/2/anyOf/0"
},
"propertyNames": {
"pattern": "^(?!type$)[a-zA-Z0-9_-]+$"
"pattern": "^(?!type$)[a-zA-Z0-9-_.:]*$"
},
"description": "The object to select a property from"
}
Expand Down Expand Up @@ -1239,7 +1239,7 @@
]
},
"propertyNames": {
"pattern": "^(?!type$)[a-zA-Z0-9_-]+$"
"pattern": "^(?!type$)[a-zA-Z0-9-_.:]*$"
}
}
},
Expand Down Expand Up @@ -1473,7 +1473,7 @@
]
},
"propertyNames": {
"pattern": "^(?!type$)[a-zA-Z0-9_-]+$"
"pattern": "^(?!type$)[a-zA-Z0-9-_.:]*$"
},
"description": "The map of name -> variables to set"
}
Expand Down
28 changes: 15 additions & 13 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ export const DEFAULT_PROFILE = '_default_profile';
*
*/

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

const absoluteRegExp = (r : RegExp) : RegExp => {
return new RegExp('^' + r.source + '$');
};

const genericID = z.string().regex(absoluteRegExp(genericIDRegExp));

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

const genericExtraID = z.string().regex(absoluteRegExp(genericIDExtraRegExp));

export const leafValue = z.union([
z.null(),
z.number(),
Expand All @@ -39,7 +51,9 @@ export const leafValue = z.union([

export type LeafValue = z.infer<typeof leafValue>;

const nonTypeKey = z.string().regex(/^(?!type$)[a-zA-Z0-9_-]+$/);
const nonTypeRegExp = new RegExp('(?!type$)');

const nonTypeKey = z.string().regex(absoluteRegExp(new RegExp(nonTypeRegExp.source + genericIDExtraRegExp.source)));

const valueObject = z.record(nonTypeKey, leafValue);

Expand Down Expand Up @@ -94,18 +108,6 @@ export const modelProvider = z.literal('openai.com');

export type ModelProvider = z.infer<typeof modelProvider>;

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

const absoluteRegExp = (r : RegExp) : RegExp => {
return new RegExp('^' + r.source + '$');
};

const genericID = z.string().regex(absoluteRegExp(genericIDRegExp));

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

const genericExtraID = z.string().regex(absoluteRegExp(genericIDExtraRegExp));

const memoryID = genericExtraID;

export type MemoryID = z.infer<typeof memoryID>;
Expand Down

0 comments on commit a925bdb

Please sign in to comment.