Skip to content

Commit

Permalink
feat: Store.request (#8472)
Browse files Browse the repository at this point in the history
* all the, nice things

* more nice things

* ember-data auto configures request manager

* fix lockfile

* feat: queryRecord op

* feat query/findAll via handler

* nice things

* fast node setup

* somehow mostly working

* cleanup

* lots of fixes

* all the things

* more

* restructure

* fix all the things

* final tweaks

* fix lint

* fix docs

* deactivate fastboot test

* remove

* fixes
  • Loading branch information
runspired authored Mar 17, 2023
1 parent 087e14b commit 24eb0e9
Show file tree
Hide file tree
Showing 88 changed files with 1,525 additions and 568 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
/packages/model/addon/
/packages/json-api/addon/
/packages/graph/addon/
/packages/legacy-compat/addon/

**/DEBUG/

Expand Down
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ module.exports = {
'ember-data-types/q/ds-model.ts',
'packages/store/src/-private/managers/record-data-store-wrapper.ts',
'packages/store/src/-private/network/snapshot.ts',
'packages/store/src/-private/network/snapshot-record-array.ts',
'packages/store/src/-private/legacy-model-support/schema-definition-service.ts',
'packages/store/src/-private/network/request-cache.ts',
'packages/store/src/-private/legacy-model-support/record-reference.ts',
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ packages/serializer/addon
packages/model/addon
packages/json-api/addon
packages/graph/addon
packages/legacy-compat/addon

# dependencies
bower_components
Expand Down
7 changes: 4 additions & 3 deletions docs-generator/yuidoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@
"paths": [
"../ember-data-types",
"../packages/-ember-data/addon",
"../packages/debug/addon",
"../packages/private-build-infra/addon",
"../packages/canary-features/addon",
"../packages/adapter/src",
"../packages/model/src",
"../packages/serializer/src",
"../packages/store/src",
"../packages/json-api/src",
"../packages/graph/src",
"../packages/debug/addon",
"../packages/private-build-infra/addon",
"../packages/canary-features/addon",
"../packages/legacy-compat/src",
"../packages/tracking/src",
"../packages/request/src"
],
Expand Down
6 changes: 3 additions & 3 deletions ember-data-types/cache/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ export type ResourceDocument =

export interface StructuredDataDocument<T> {
request?: RequestInfo;
response?: ResponseInfo;
response?: ResponseInfo | Response | null;
content: T;
}
export interface StructuredErrorDocument extends Error {
request?: RequestInfo;
response?: ResponseInfo;
response?: ResponseInfo | Response | null;
error: string | object;
content?: ResourceErrorDocument;
content?: unknown;
}
export type StructuredDocument<T> = StructuredDataDocument<T> | StructuredErrorDocument;
2 changes: 1 addition & 1 deletion ember-data-types/q/ember-data-json-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ interface Document {
meta?: Dict<JSONValue>;
included?: ExistingResourceObject[];
jsonapi?: Dict<JSONValue>;
links?: Dict<string | JSONValue>;
links?: Links | PaginationLinks;
errors?: JSONValue[];
}

Expand Down
2 changes: 1 addition & 1 deletion ember-data-types/q/minimum-adapter-interface.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* @module @ember-data/experimental-preview-types
*/
import type { SnapshotRecordArray } from '@ember-data/legacy-compat/-private';
import type Store from '@ember-data/store';
import type Snapshot from '@ember-data/store/-private/network/snapshot';
import type SnapshotRecordArray from '@ember-data/store/-private/network/snapshot-record-array';
import type { Collection } from '@ember-data/store/-private/record-arrays/identifier-array';

import type { ModelSchema } from './ds-model';
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
"pnpm": "7.29.1"
},
"volta": {
"node": "19.0.0",
"node": "18.15.0",
"pnpm": "7.29.1"
},
"packageManager": "pnpm@7.29.1",
Expand Down
17 changes: 15 additions & 2 deletions packages/-ember-data/addon/-private/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,27 @@ import ArrayProxy from '@ember/array/proxy';
import PromiseProxyMixin from '@ember/object/promise-proxy-mixin';
import ObjectProxy from '@ember/object/proxy';

export { default as Store } from '@ember-data/store';
import { LegacyNetworkHandler } from '@ember-data/legacy-compat';
import { RequestManager } from '@ember-data/request';
import { Fetch } from '@ember-data/request/fetch';
import BaseStore from '@ember-data/store';

export class Store extends BaseStore {
constructor() {
super(...arguments);
this.requestManager = new RequestManager();
this.requestManager.use([LegacyNetworkHandler, Fetch]);
}
}

export { default as DS } from './core';
export { Errors } from '@ember-data/model/-private';
export { Snapshot } from '@ember-data/store/-private';

// `ember-data-model-fragments' and `ember-data-change-tracker` rely on `normalizeModelName`
export { RecordArrayManager, SnapshotRecordArray, normalizeModelName, coerceId } from '@ember-data/store/-private';
export { RecordArrayManager, normalizeModelName, coerceId } from '@ember-data/store/-private';
export { ManyArray, PromiseManyArray } from '@ember-data/model/-private';
export { SnapshotRecordArray } from '@ember-data/legacy-compat/-private';

export const PromiseArray = ArrayProxy.extend(PromiseProxyMixin);
export const PromiseObject = ObjectProxy.extend(PromiseProxyMixin);
2 changes: 1 addition & 1 deletion packages/-ember-data/addon/setup-container.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type Application from '@ember/application';

import Store from '@ember-data/store';
import Store from 'ember-data/store';

function initializeStore(application: Application) {
application.registerOptionsForType('serializer', { singleton: false });
Expand Down
2 changes: 1 addition & 1 deletion packages/-ember-data/addon/store.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default } from '@ember-data/store';
export { Store as default } from './-private';
10 changes: 9 additions & 1 deletion packages/-ember-data/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ember-data",
"version": "4.12.0-alpha.8",
"description": "A data layer for your Ember applications.",
"description": "The lightweight reactive data library for JavaScript applications",
"repository": {
"type": "git",
"url": "git+ssh://git@github.com:emberjs/data.git",
Expand All @@ -25,6 +25,8 @@
"@ember-data/model": "workspace:4.12.0-alpha.8",
"@ember-data/private-build-infra": "workspace:4.12.0-alpha.8",
"@ember-data/json-api": "workspace:4.12.0-alpha.8",
"@ember-data/legacy-compat": "workspace:4.12.0-alpha.8",
"@ember-data/request": "workspace:4.12.0-alpha.8",
"@ember-data/serializer": "workspace:4.12.0-alpha.8",
"@ember-data/store": "workspace:4.12.0-alpha.8",
"@ember-data/tracking": "workspace:4.12.0-alpha.8",
Expand Down Expand Up @@ -53,6 +55,12 @@
"@ember-data/json-api": {
"injected": true
},
"@ember-data/request": {
"injected": true
},
"@ember-data/legacy-compat": {
"injected": true
},
"@ember-data/serializer": {
"injected": true
},
Expand Down
1 change: 1 addition & 0 deletions packages/adapter/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default {
external: [
'@embroider/macros',
'@ember/service',
'@ember-data/store/-private',
'require',
'rsvp',
'ember-inflector',
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter/src/-private/build-url-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { camelize } from '@ember/string';

import { pluralize } from 'ember-inflector';

import type { SnapshotRecordArray } from '@ember-data/legacy-compat/-private';
import type Snapshot from '@ember-data/store/-private/network/snapshot';
import type SnapshotRecordArray from '@ember-data/store/-private/network/snapshot-record-array';
import type { Dict } from '@ember-data/types/q/utils';

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ import { DEBUG } from '@glimmer/env';

import { Promise as RSVPPromise } from 'rsvp';

import type { SnapshotRecordArray } from '@ember-data/legacy-compat/-private';
import type Store from '@ember-data/store';
import type { Snapshot } from '@ember-data/store/-private';
import type ShimModelClass from '@ember-data/store/-private/legacy-model-support/shim-model-class';
import type SnapshotRecordArray from '@ember-data/store/-private/network/snapshot-record-array';
import type { AdapterPayload, MinimumAdapterInterface } from '@ember-data/types/q/minimum-adapter-interface';
import type { Dict } from '@ember-data/types/q/utils';

Expand Down
2 changes: 1 addition & 1 deletion packages/adapter/src/rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import { DEBUG } from '@glimmer/env';

import { Promise as RSVPPromise } from 'rsvp';

import type { SnapshotRecordArray } from '@ember-data/legacy-compat/-private';
import type Store from '@ember-data/store';
import type ShimModelClass from '@ember-data/store/-private/legacy-model-support/shim-model-class';
import type Snapshot from '@ember-data/store/-private/network/snapshot';
import type SnapshotRecordArray from '@ember-data/store/-private/network/snapshot-record-array';
import type { AdapterPayload } from '@ember-data/types/q/minimum-adapter-interface';
import type { Dict } from '@ember-data/types/q/utils';

Expand Down
14 changes: 7 additions & 7 deletions packages/json-api/src/-private/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ import type { ImplicitRelationship } from '@ember-data/graph/-private/graph/inde
import type BelongsToRelationship from '@ember-data/graph/-private/relationships/state/belongs-to';
import type ManyRelationship from '@ember-data/graph/-private/relationships/state/has-many';
import { LOG_MUTATIONS, LOG_OPERATIONS } from '@ember-data/private-build-infra/debugging';
import { StructuredDataDocument } from '@ember-data/request/-private/types';
import { IdentifierCache } from '@ember-data/store/-private/caches/identifier-cache';
import { ResourceBlob } from '@ember-data/types/cache/aliases';
import { Change } from '@ember-data/types/cache/change';
import {
import type { IdentifierCache } from '@ember-data/store/-private/caches/identifier-cache';
import type { ResourceBlob } from '@ember-data/types/cache/aliases';
import type { Change } from '@ember-data/types/cache/change';
import type {
CollectionResourceDataDocument,
ResourceDocument,
ResourceErrorDocument,
ResourceMetaDocument,
SingleResourceDataDocument,
StructuredDataDocument,
StructuredDocument,
} from '@ember-data/types/cache/document';
import { StableDocumentIdentifier } from '@ember-data/types/cache/identifier';
import type { StableDocumentIdentifier } from '@ember-data/types/cache/identifier';
import type { Cache, ChangedAttributesHash, MergeOperation } from '@ember-data/types/q/cache';
import type { CacheStoreWrapper, V2CacheStoreWrapper } from '@ember-data/types/q/cache-store-wrapper';
import {
import type {
CollectionResourceDocument,
CollectionResourceRelationship,
ExistingResourceObject,
Expand Down
11 changes: 11 additions & 0 deletions packages/legacy-compat/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
The MIT License (MIT)

Copyright (C) 2017-2022 Ember.js contributors
Portions Copyright (C) 2011-2017 Tilde, Inc. and contributors.
Portions Copyright (C) 2011 LivingSocial Inc.

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:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

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.
26 changes: 26 additions & 0 deletions packages/legacy-compat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<p align="center">
<img
class="project-logo"
src="./ember-data-logo-dark.svg#gh-dark-mode-only"
alt="EmberData LegacyCompat"
width="240px"
title="EmberData LegacyCompat"
/>
<img
class="project-logo"
src="./ember-data-logo-light.svg#gh-light-mode-only"
alt="EmberData LegacyCompat"
width="240px"
title="EmberData LegacyCompat"
/>
</p>

<p align="center">Utils For Compatibility with Legacy EmberData</p>

## Installation

Install using your javascript package manager of choice. For instance with [pnpm](https://pnpm.io/)

```no-highlight
pnpm add @ember-data/legacy-compat
```
90 changes: 90 additions & 0 deletions packages/legacy-compat/addon-main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
const pkg = require('./package.json');

module.exports = {
name: pkg.name,

options: {
'@embroider/macros': {
setOwnConfig: {},
},
},

_emberDataConfig: null,
configureEmberData() {
if (this._emberDataConfig) {
return this._emberDataConfig;
}
const app = this._findHost();
const isProd = /production/.test(process.env.EMBER_ENV);
const hostOptions = app.options?.emberData || {};
const debugOptions = Object.assign(
{
LOG_PAYLOADS: false,
LOG_OPERATIONS: false,
LOG_MUTATIONS: false,
LOG_NOTIFICATIONS: false,
LOG_REQUEST_STATUS: false,
LOG_IDENTIFIERS: false,
LOG_GRAPH: false,
LOG_INSTANCE_CACHE: false,
},
hostOptions.debug || {}
);
let HAS_DEBUG_PACKAGE, HAS_META_PACKAGE;

try {
// eslint-disable-next-line node/no-missing-require
require.resolve('@ember-data/debug', { paths: [process.cwd(), __dirname] });
HAS_DEBUG_PACKAGE = true;
} catch {
HAS_DEBUG_PACKAGE = false;
}
try {
// eslint-disable-next-line node/no-missing-require
require.resolve('ember-data', { paths: [process.cwd(), __dirname] });
HAS_META_PACKAGE = true;
} catch {
HAS_META_PACKAGE = false;
}
const includeDataAdapterInProduction =
typeof hostOptions.includeDataAdapterInProduction === 'boolean'
? hostOptions.includeDataAdapterInProduction
: HAS_META_PACKAGE;

const includeDataAdapter = HAS_DEBUG_PACKAGE ? (isProd ? includeDataAdapterInProduction : true) : false;
const DEPRECATIONS = require('@ember-data/private-build-infra/src/deprecations')(hostOptions.compatWith || null);
const FEATURES = require('@ember-data/private-build-infra/src/features')(isProd);

// copy configs forward
const ownConfig = this.options['@embroider/macros'].setOwnConfig;
ownConfig.compatWith = hostOptions.compatWith || null;
ownConfig.debug = debugOptions;
ownConfig.deprecations = Object.assign(DEPRECATIONS, ownConfig.deprecations || {});
ownConfig.features = Object.assign({}, FEATURES);
ownConfig.includeDataAdapter = includeDataAdapter;

this._emberDataConfig = ownConfig;
return ownConfig;
},

included() {
this.configureEmberData();
return this._super.included.call(this, ...arguments);
},

treeForVendor() {
return;
},
treeForPublic() {
return;
},
treeForStyles() {
return;
},
treeForAddonStyles() {
return;
},
treeForApp() {
return;
},
};
13 changes: 13 additions & 0 deletions packages/legacy-compat/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const macros = require('@ember-data/private-build-infra/src/v2-babel-build-pack');

module.exports = {
plugins: [
...macros,
// '@embroider/macros/src/babel/macros-babel-plugin.js',
['@babel/plugin-transform-runtime', { loose: true }],
['@babel/plugin-transform-typescript', { allowDeclareFields: true }],
['@babel/plugin-proposal-decorators', { legacy: true, loose: true }],
['@babel/plugin-proposal-private-methods', { loose: true }],
['@babel/plugin-proposal-class-properties', { loose: true }],
],
};
Loading

0 comments on commit 24eb0e9

Please sign in to comment.