Skip to content

Commit

Permalink
DEV: warn if missing unique properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael O'Brien committed Jun 16, 2024
1 parent 728314d commit d38f3c9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 21 deletions.
14 changes: 0 additions & 14 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,6 @@ You can run the test suite locally with:
npm test
```

If you do not have Java installed, then you can run via docker with:

```bash
DOCKER=yes npm test
```

If you need to change the port, that local dynamodb runs on, then set the `PORT` environment variable.

```bash
PORT=12345 npm test
# This is also compatible with docker
DOCKER=true PORT=12344 npm test
```

You can run the linter with:

```bash
Expand Down
41 changes: 34 additions & 7 deletions src/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,14 @@ export class Model {
let scope = ''
if (field.scope) {
scope = this.runTemplate(null, null, field, properties, params, field.scope) + '#'
if (scope == undefined) {
throw new OneTableError('Missing properties to resolve unique scope', {
properties,
field,
scope: field.scope,
code: 'UniqueError',
})
}
}
let pk = `_unique#${scope}${this.name}#${field.attribute}#${properties[field.name]}`
let sk = '_unique#'
Expand Down Expand Up @@ -759,6 +767,15 @@ export class Model {
let scope = ''
if (field.scope) {
scope = this.runTemplate(null, null, field, properties, params, field.scope) + '#'
if (scope == undefined) {
throw new OneTableError('Missing properties to resolve unique scope', {
properties,
field,
params,
scope: field.scope,
code: 'UniqueError',
})
}
}
// If we had a prior record, remove unique values that existed
if (prior && prior[field.name]) {
Expand Down Expand Up @@ -858,6 +875,14 @@ export class Model {
let scope = ''
if (field.scope) {
scope = this.runTemplate(null, null, field, properties, params, field.scope) + '#'
if (scope == undefined) {
throw new OneTableError('Missing properties to resolve unique scope', {
properties,
field,
scope: field.scope,
code: 'UniqueError',
})
}
}
let pk = `_unique#${scope}${this.name}#${field.attribute}#${properties[field.name]}`
let sk = `_unique#`
Expand Down Expand Up @@ -1668,13 +1693,15 @@ export class Model {
Consider unresolved template variables. If field is the sort key and doing find,
then use sort key prefix and begins_with, (provide no where clause).
*/
if (value.indexOf('${') >= 0 && index) {
if (field.attribute[0] == index.sort) {
if (op == 'find') {
// Strip from first ${ onward and retain fixed prefix portion
value = value.replace(/\${.*/g, '')
if (value) {
return {begins: value}
if (value.indexOf('${') >= 0) {
if (index) {
if (field.attribute[0] == index.sort) {
if (op == 'find') {
// Strip from first ${ onward and retain fixed prefix portion
value = value.replace(/\${.*/g, '')
if (value) {
return {begins: value}
}
}
}
}
Expand Down

0 comments on commit d38f3c9

Please sign in to comment.