Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using simple schema with $ fields suppresses Collection definition #16

Open
paulbalomiri opened this issue Mar 11, 2016 · 1 comment
Open

Comments

@paulbalomiri
Copy link

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"
}

  1. generation of the whole Collection related code is suppressed,
  2. 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?

@paulbalomiri
Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant