@ember-data-mirror/serializer 5.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +11 -0
- package/README.md +107 -0
- package/addon-main.cjs +5 -0
- package/blueprints/serializer/files/__root__/__path__/__name__.js +4 -0
- package/blueprints/serializer/index.js +80 -0
- package/blueprints/serializer/native-files/__root__/__path__/__name__.js +4 -0
- package/blueprints/serializer-test/index.js +35 -0
- package/blueprints/serializer-test/qunit-files/__root__/__path__/__test__.js +23 -0
- package/blueprints/transform/files/__root__/__path__/__name__.js +13 -0
- package/blueprints/transform/index.js +17 -0
- package/blueprints/transform/native-files/__root__/__path__/__name__.js +13 -0
- package/blueprints/transform-test/index.js +35 -0
- package/blueprints/transform-test/qunit-files/__root__/__path__/__test__.js +12 -0
- package/dist/index.js +373 -0
- package/dist/index.js.map +1 -0
- package/dist/json-BwMH6O_R.js +1396 -0
- package/dist/json-BwMH6O_R.js.map +1 -0
- package/dist/json-api.js +529 -0
- package/dist/json-api.js.map +1 -0
- package/dist/json.js +6 -0
- package/dist/json.js.map +1 -0
- package/dist/rest.js +1270 -0
- package/dist/rest.js.map +1 -0
- package/dist/transform.js +337 -0
- package/dist/transform.js.map +1 -0
- package/package.json +108 -0
- package/unstable-preview-types/-private/embedded-records-mixin.d.ts +103 -0
- package/unstable-preview-types/-private/embedded-records-mixin.d.ts.map +1 -0
- package/unstable-preview-types/-private/transforms/boolean.d.ts +52 -0
- package/unstable-preview-types/-private/transforms/boolean.d.ts.map +1 -0
- package/unstable-preview-types/-private/transforms/date.d.ts +33 -0
- package/unstable-preview-types/-private/transforms/date.d.ts.map +1 -0
- package/unstable-preview-types/-private/transforms/number.d.ts +34 -0
- package/unstable-preview-types/-private/transforms/number.d.ts.map +1 -0
- package/unstable-preview-types/-private/transforms/string.d.ts +34 -0
- package/unstable-preview-types/-private/transforms/string.d.ts.map +1 -0
- package/unstable-preview-types/-private/transforms/transform.d.ts +127 -0
- package/unstable-preview-types/-private/transforms/transform.d.ts.map +1 -0
- package/unstable-preview-types/-private/utils.d.ts +6 -0
- package/unstable-preview-types/-private/utils.d.ts.map +1 -0
- package/unstable-preview-types/index.d.ts +277 -0
- package/unstable-preview-types/index.d.ts.map +1 -0
- package/unstable-preview-types/json-api.d.ts +515 -0
- package/unstable-preview-types/json-api.d.ts.map +1 -0
- package/unstable-preview-types/json.d.ts +1094 -0
- package/unstable-preview-types/json.d.ts.map +1 -0
- package/unstable-preview-types/rest.d.ts +571 -0
- package/unstable-preview-types/rest.d.ts.map +1 -0
- package/unstable-preview-types/transform.d.ts +11 -0
- package/unstable-preview-types/transform.d.ts.map +1 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (C) 2017-2023 Ember.js contributors
|
|
4
|
+
Portions Copyright (C) 2011-2017 Tilde, Inc. and contributors.
|
|
5
|
+
Portions Copyright (C) 2011 LivingSocial Inc.
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
8
|
+
|
|
9
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
10
|
+
|
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img
|
|
3
|
+
class="project-logo"
|
|
4
|
+
src="./ember-data-logo-dark.svg#gh-dark-mode-only"
|
|
5
|
+
alt="EmberData Serializer"
|
|
6
|
+
width="240px"
|
|
7
|
+
title="EmberData Serializer"
|
|
8
|
+
/>
|
|
9
|
+
<img
|
|
10
|
+
class="project-logo"
|
|
11
|
+
src="./ember-data-logo-light.svg#gh-light-mode-only"
|
|
12
|
+
alt="EmberData Serializer"
|
|
13
|
+
width="240px"
|
|
14
|
+
title="EmberData Serializer"
|
|
15
|
+
/>
|
|
16
|
+
</p>
|
|
17
|
+
|
|
18
|
+
<p align="center">Provides JSON, REST and JSON:API Implementations of the legacy <a href="https://api.emberjs.com/ember-data/release/classes/%3CInterface%3E%20Serializer">Serializer Interface</a></p>
|
|
19
|
+
|
|
20
|
+
> **Caution** ⚠️ **This is LEGACY documentation** for a feature that is no longer encouraged to be used.
|
|
21
|
+
> If starting a new app or thinking of implementing a new serializer, consider writing a [Handler](https://api.emberjs.com/ember-data/release/classes/%3CInterface%3E%20Handler)
|
|
22
|
+
> instead to be used with the [RequestManager](https://github.com/emberjs/data/tree/main/packages/request#readme)
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
This package is currently installed when installing `ember-data`.
|
|
27
|
+
|
|
28
|
+
If installing `@ember-data/` packages individually install using your javascript package manager of choice. For instance with [pnpm](https://pnpm.io/)
|
|
29
|
+
|
|
30
|
+
```no-highlight
|
|
31
|
+
pnpm add @ember-data-mirror/serializer
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**Tagged Releases**
|
|
35
|
+
|
|
36
|
+
- 
|
|
37
|
+
- 
|
|
38
|
+
- 
|
|
39
|
+
- 
|
|
40
|
+
- 
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
## 🚀 Setup
|
|
44
|
+
|
|
45
|
+
If using `ember-data` no additional setup is necesssary.
|
|
46
|
+
|
|
47
|
+
> **Note**
|
|
48
|
+
> When using [ember-data](https://github.com/emberjs/data/blob/main/packages/-ember-data) the below
|
|
49
|
+
> configuration is handled for you automatically.
|
|
50
|
+
|
|
51
|
+
To use legacy serializers you will need to have installed and configured the LegacyNetworkHandler from [@ember-data-mirror/legacy-compat](https://github.com/emberjs/data/blob/main/packages/-ember-data)
|
|
52
|
+
|
|
53
|
+
```no-highlight
|
|
54
|
+
pnpm add @ember-data-mirror/legacy-compat
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import Store, { CacheHandler } from '@ember-data-mirror/store';
|
|
59
|
+
import RequestManager from '@ember-data-mirror/request';
|
|
60
|
+
import { LegacyNetworkHandler } from '@ember-data-mirror/legacy-compat';
|
|
61
|
+
|
|
62
|
+
export default class extends Store {
|
|
63
|
+
requestManager = new RequestManager();
|
|
64
|
+
|
|
65
|
+
constructor(args) {
|
|
66
|
+
super(args);
|
|
67
|
+
this.requestManager.use([LegacyNetworkHandler]);
|
|
68
|
+
this.requestManager.useCache(CacheHandler);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
## Usage
|
|
75
|
+
|
|
76
|
+
To use as either a per-type or application serializer, export one of the
|
|
77
|
+
implementations within the `serializers/` directory of your app as appropriate.
|
|
78
|
+
|
|
79
|
+
For instance, to configure an application serializer to use `JSON:API`
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
*app/serializers/application.ts*
|
|
83
|
+
```ts
|
|
84
|
+
export { default } from '@ember-data-mirror/serializer/json-api';
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
By default serializers are resolved by looking for a serializer with the same name in the `serializers/` folder as the `type` given to `store.serializerFor(<type>)`, falling back to looking for a serializer named `application`.
|
|
88
|
+
|
|
89
|
+
**Overriding Resolution**
|
|
90
|
+
|
|
91
|
+
If you would like to avoid using resolver semantics and your application has only one or a few serializers, you may ovveride the `serializerFor` hook on the store.
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
import Store from '@ember-data-mirror/store';
|
|
95
|
+
import Serializer from '@ember-data-mirror/serializer/json-api';
|
|
96
|
+
|
|
97
|
+
class extends Store {
|
|
98
|
+
#serializer = new Serializer();
|
|
99
|
+
|
|
100
|
+
serializerFor() {
|
|
101
|
+
return this.#serializer;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
For the full list of APIs available read the code documentation for [@ember-data-mirror/serializer](https://api.emberjs.com/ember-data/release/modules/@ember-data%2Fserializer). You may also be interested in learning more about *Ember***Data**'s [Serializer Interface](https://api.emberjs.com/ember-data/release/classes/%3CInterface%3E%20Serializer).
|
package/addon-main.cjs
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
|
|
4
|
+
const stringUtil = require('ember-cli-string-utils');
|
|
5
|
+
const pathUtil = require('ember-cli-path-utils');
|
|
6
|
+
|
|
7
|
+
const { has } = require('@ember/edition-utils');
|
|
8
|
+
|
|
9
|
+
module.exports = {
|
|
10
|
+
description: 'Generates an ember-data Serializer.',
|
|
11
|
+
|
|
12
|
+
availableOptions: [{ name: 'base-class', type: String }],
|
|
13
|
+
|
|
14
|
+
root: __dirname,
|
|
15
|
+
|
|
16
|
+
filesPath() {
|
|
17
|
+
let hasOctane = has('octane');
|
|
18
|
+
if (hasOctane && process.env.EMBER_EDITION === 'classic') {
|
|
19
|
+
hasOctane = false; //forcible override
|
|
20
|
+
}
|
|
21
|
+
let rootPath = hasOctane ? 'native-files' : 'files';
|
|
22
|
+
return path.join(__dirname, rootPath);
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
locals(options) {
|
|
26
|
+
return extendFromApplicationEntity('serializer', 'JSONAPISerializer', options);
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
function extendFromApplicationEntity(type, baseClass, options) {
|
|
31
|
+
let isAddon = options.inRepoAddon || options.project.isEmberCLIAddon();
|
|
32
|
+
|
|
33
|
+
let entityName = options.entity.name;
|
|
34
|
+
let relativePath = pathUtil.getRelativePath(options.entity.name);
|
|
35
|
+
|
|
36
|
+
if (options.pod && options.podPath) {
|
|
37
|
+
relativePath = pathUtil.getRelativePath(options.podPath + options.entity.name);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let applicationEntityPath = path.join(options.project.root, 'app', `${type}s`, 'application.js');
|
|
41
|
+
|
|
42
|
+
let hasApplicationEntity = fs.existsSync(applicationEntityPath);
|
|
43
|
+
if (!isAddon && !options.baseClass && entityName !== 'application' && hasApplicationEntity) {
|
|
44
|
+
options.baseClass = 'application';
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (options.baseClass === entityName) {
|
|
48
|
+
throw new Error(
|
|
49
|
+
stringUtil.classify(type) +
|
|
50
|
+
's cannot extend from themself. To resolve this, remove the `--base-class` option or change to a different base-class.'
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
let importStatement;
|
|
55
|
+
|
|
56
|
+
if (options.baseClass) {
|
|
57
|
+
let baseClassPath = options.baseClass;
|
|
58
|
+
baseClass = stringUtil.classify(baseClassPath.replace('/', '-'));
|
|
59
|
+
baseClass = baseClass + stringUtil.classify(type);
|
|
60
|
+
|
|
61
|
+
importStatement = `import ${baseClass} from '${relativePath}${baseClassPath}';`;
|
|
62
|
+
} else {
|
|
63
|
+
let baseClassPath = `@ember-data/${type}`;
|
|
64
|
+
|
|
65
|
+
if (baseClass.startsWith('JSONAPI')) {
|
|
66
|
+
baseClassPath += '/json-api';
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (baseClass.startsWith('REST')) {
|
|
70
|
+
baseClassPath += '/rest';
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
importStatement = `import ${baseClass} from '${baseClassPath}';`;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
importStatement,
|
|
78
|
+
baseClass,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
|
|
3
|
+
const testInfo = require('ember-cli-test-info');
|
|
4
|
+
const { dasherize } = require('ember-cli-string-utils');
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
description: 'Generates an EmberData Serializer unit test',
|
|
8
|
+
supportsAddon() { return false; },
|
|
9
|
+
|
|
10
|
+
root: __dirname,
|
|
11
|
+
|
|
12
|
+
fileMapTokens() {
|
|
13
|
+
return {
|
|
14
|
+
__root__() {
|
|
15
|
+
return 'tests';
|
|
16
|
+
},
|
|
17
|
+
__path__() {
|
|
18
|
+
return path.join('unit', 'serializers');
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
locals(options) {
|
|
24
|
+
const modulePrefix = dasherize(options.project.config().modulePrefix);
|
|
25
|
+
return {
|
|
26
|
+
friendlyTestDescription: testInfo.description(options.entity.name, 'Unit', 'Serializer'),
|
|
27
|
+
modulePrefix,
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
filesPath() {
|
|
32
|
+
return path.join(__dirname, 'qunit-files')
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { setupTest } from '<%= modulePrefix %>/tests/helpers';
|
|
2
|
+
import { module, test } from 'qunit';
|
|
3
|
+
|
|
4
|
+
module('<%= friendlyTestDescription %>', function (hooks) {
|
|
5
|
+
setupTest(hooks);
|
|
6
|
+
|
|
7
|
+
// Replace this with your real tests.
|
|
8
|
+
test('it exists', function (assert) {
|
|
9
|
+
const store = this.owner.lookup('service:store');
|
|
10
|
+
const serializer = store.serializerFor('<%= dasherizedModuleName %>');
|
|
11
|
+
|
|
12
|
+
assert.ok(serializer, 'serializer exists');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test('it serializes records', function (assert) {
|
|
16
|
+
const store = this.owner.lookup('service:store');
|
|
17
|
+
const record = store.createRecord('<%= dasherizedModuleName %>', {});
|
|
18
|
+
|
|
19
|
+
const serializedRecord = record.serialize();
|
|
20
|
+
|
|
21
|
+
assert.ok(serializedRecord, 'it serializes records');
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
|
|
3
|
+
const { has } = require('@ember/edition-utils');
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
description: 'Generates an ember-data Transform.',
|
|
7
|
+
root: __dirname,
|
|
8
|
+
|
|
9
|
+
filesPath() {
|
|
10
|
+
let hasOctane = has('octane');
|
|
11
|
+
if (hasOctane && process.env.EMBER_EDITION === 'classic') {
|
|
12
|
+
hasOctane = false; //forcible override
|
|
13
|
+
}
|
|
14
|
+
let rootPath = hasOctane ? 'native-files' : 'files';
|
|
15
|
+
return path.join(__dirname, rootPath);
|
|
16
|
+
},
|
|
17
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
|
|
3
|
+
const testInfo = require('ember-cli-test-info');
|
|
4
|
+
const { dasherize } = require('ember-cli-string-utils');
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
description: 'Generates an EmberData Transform unit test',
|
|
8
|
+
supportsAddon() { return false; },
|
|
9
|
+
|
|
10
|
+
root: __dirname,
|
|
11
|
+
|
|
12
|
+
fileMapTokens() {
|
|
13
|
+
return {
|
|
14
|
+
__root__() {
|
|
15
|
+
return 'tests';
|
|
16
|
+
},
|
|
17
|
+
__path__() {
|
|
18
|
+
return path.join('unit', 'transforms');
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
locals(options) {
|
|
24
|
+
const modulePrefix = dasherize(options.project.config().modulePrefix);
|
|
25
|
+
return {
|
|
26
|
+
friendlyTestDescription: testInfo.description(options.entity.name, 'Unit', 'Transform'),
|
|
27
|
+
modulePrefix,
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
filesPath() {
|
|
32
|
+
return path.join(__dirname, 'qunit-files')
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { setupTest } from '<%= modulePrefix %>/tests/helpers';
|
|
2
|
+
import { module, test } from 'qunit';
|
|
3
|
+
|
|
4
|
+
module('<%= friendlyTestDescription %>', function (hooks) {
|
|
5
|
+
setupTest(hooks);
|
|
6
|
+
|
|
7
|
+
// Replace this with your real tests.
|
|
8
|
+
test('it exists', function (assert) {
|
|
9
|
+
const transform = this.owner.lookup('transform:<%= dasherizedModuleName %>');
|
|
10
|
+
assert.ok(transform, 'transform exists');
|
|
11
|
+
});
|
|
12
|
+
});
|