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

Fixed model name parsing from OData name #277

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## [3.13.0-beta.1] - 2024-06-03
### Fixed
- Model name parsing from OData name.

## [3.12.0] - 2024-05-03
### Changed
- Increase version to match ember-flexberry.
Expand Down
4 changes: 2 additions & 2 deletions addon/adapters/odata.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { A, isArray } from '@ember/array';

import SnapshotTransform from '../utils/snapshot-transform';
import ODataQueryAdapter from '../query/odata-adapter';
import { capitalize, camelize, dasherize, odataPluralize, odataSingularize } from '../utils/string-functions';
import { capitalize, camelize, odataDasherize, odataPluralize, odataSingularize } from '../utils/string-functions';
import isUUID from '../utils/is-uuid';
import generateUniqueId from '../utils/generate-unique-id';
import { getResponseMeta, getBatchResponses, parseBatchResponse } from '../utils/batch-queries';
Expand Down Expand Up @@ -705,7 +705,7 @@ export default DS.RESTAdapter.extend({
getModelNameFromOdataContext(context) {
const regex = /(?<=\$metadata#)\w*(?=[\(\/])/g;

return odataSingularize(dasherize(regex.exec(context)[0]));
return odataSingularize(odataDasherize(regex.exec(context)[0]));
},

/**
Expand Down
6 changes: 3 additions & 3 deletions addon/serializers/base.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { merge } from '@ember/polyfills';
import DS from 'ember-data';
import { capitalize, camelize, dasherize, odataPluralize, odataSingularize } from '../utils/string-functions';
import { capitalize, camelize, odataDasherize, odataPluralize, odataSingularize } from '../utils/string-functions';

/**
* Base serializer class.
Expand Down Expand Up @@ -192,10 +192,10 @@ export default DS.RESTSerializer.extend({
*/
modelNameFromPayloadKey(key) {
if (key.startsWith('#.')) {
return dasherize(key.replace(/[#\.]/g, ''));
return odataDasherize(key.replace(/[#\.]/g, ''));
}

return odataSingularize(dasherize(key.replace(/[#\.]/g, '')));
return odataSingularize(odataDasherize(key.replace(/[#\.]/g, '')));
},

/**
Expand Down
16 changes: 15 additions & 1 deletion addon/utils/string-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const STRING_UNDERSCORE_REGEXP_2 = (/\-|\s+/g);
const STRING_CAPITALIZE_REGEXP = (/(^|\/)([a-zа-яё])/g);

const STRING_DECAMELIZE_REGEXP = (/([a-zа-яё\d])([A-ZА-ЯЁ])/g);
const ODATA_DECAMELIZE_REGEXP = (/([A-ZА-ЯЁa-zа-яё\d])(?=[A-ZА-ЯЁ])/g);
/* eslint-enable no-useless-escape */

/**
Expand Down Expand Up @@ -161,6 +162,18 @@ function odataPluralize(str) {
return str + 's';
}

/**
Returns the dasheraized form of a string for parsing OData to model name

@method odataDasherize
@param {String} str The string to dasherize.
@return {String} The dasherized string.
*/
function odataDasherize(str) {
let decamelizedStr = str.replace(ODATA_DECAMELIZE_REGEXP, '$1_').toLowerCase();
return decamelizedStr.replace(STRING_DASHERIZE_REGEXP, '-');
}

export {
decamelize,
dasherize,
Expand All @@ -169,5 +182,6 @@ export {
underscore,
capitalize,
odataSingularize,
odataPluralize
odataPluralize,
odataDasherize
};
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ember-flexberry-data",
"version": "3.12.0",
"version": "3.13.0-beta.1",
"description": "Support of database projections, JavaScript Query Language and working with several kinds of backends",
"keywords": [
"ember-addon",
Expand Down
2 changes: 1 addition & 1 deletion vendor/ember-flexberry-data/register-version.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/* globals Ember */
var version = '3.12.0';
var version = '3.13.0-beta.1';
Ember.libraries.register('Ember Flexberry Data', version);
Loading