kitchen-cli
kitchen-cli copied to clipboard
Using simple schema with $ fields suppresses Collection definition
Hi,
When adding any SimpleSchema
array content type checking the output of the collection definition is skipped altogether.
Say you have this fields in a collection definition:
{
"name": "credit_contacts",
"type": "array",
},
{
"name": "credit_contacts.$.role",
"type": "string"
},
{
"name": "credit_contacts.$.contact_id",
"type": "string"
}
- generation of the whole
Collection
related code is suppressed, - the code regarding any joins defined on that
Collection
is not suppressed
Thus startup errors appear:
ReferenceError: Submissions is not defined
W20160311-08:13:29.531(2)? (STDERR) at both/joins/joins.coffee:2:1
W20160311-08:13:29.531(2)? (STDERR) at both/joins/joins.coffee:2:1
I looked at ~/.meteor-kitchen/templates/blaze/code/collection_shared.js
but that part seems unrelated as it is not rendered at all into both/collections/submissions.coffee
@perak Can you confirm that this happens because of code inside kitchen_cli, and add a bug
tag?
The above only happens like described with the --coffee
option.
Skipping --coffee
actually points to the root problem: the object literal in .meteor-kitchen/templates/blaze/code/collection_shared_schema.js
has unescaped keys which prevents defining schema keys containing .
like field.$.array_member_field
A most dirty hack around proper escaping is replacing the contents of collection_shared_schema.js
with the snippet below.
this.Schemas = this.Schemas || {};
var objKeysRegex = /({|,)(?:\s*)(?:')?([A-Za-z_$\.][A-Za-z0-9_ \-\.$]*)(?:')?(?:\s*):/g;
var json = `SIMPLE_SCHEMA`.replace(objKeysRegex, "$1\"\$2\":"); console.log(json);
eval( "json="+json);
this.Schemas.COLLECTION_VAR = new SimpleSchema(json);
this.COLLECTION_VAR.attachSchema(this.Schemas.COLLECTION_VAR);
The hack is dirty in so many ways:
- it uses ES6 string template literals
- it does evil-
eval
- it breaks coffeescript generation completely because ES6 does not work for
js2coffee
-
EDIT: it will break if you use
:
in field name, but why would you want to do that?
@perak On another note: Where is the output of js2coffee
? Do you send it to some file or just /dev/null
?