Skip to content

Commit

Permalink
feat: findRecord as legacy op, native promises
Browse files Browse the repository at this point in the history
  • Loading branch information
runspired committed Mar 26, 2023
1 parent 92ea63e commit a754ec7
Show file tree
Hide file tree
Showing 66 changed files with 959 additions and 817 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ module.exports = {
'ember-data-types/q/ember-data-json-api.ts',
'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/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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ let app = new EmberApp(defaults, {
LOG_OPERATIONS: false, // updates to cache remote state
LOG_MUTATIONS: false, // updates to cache local state
LOG_NOTIFICATIONS: false,
LOG_REQUESTS: false, // log Requests issued via the request manager
LOG_REQUEST_STATUS: false,
LOG_IDENTIFIERS: false,
LOG_GRAPH: false, // relationship storage
Expand Down
3 changes: 1 addition & 2 deletions ember-data-types/q/minimum-adapter-interface.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/**
* @module @ember-data/experimental-preview-types
*/
import type { SnapshotRecordArray } from '@ember-data/legacy-compat/-private';
import type { Snapshot, 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 { Collection } from '@ember-data/store/-private/record-arrays/identifier-array';

import type { ModelSchema } from './ds-model';
Expand Down
2 changes: 1 addition & 1 deletion ember-data-types/q/minimum-serializer-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
*/
import type { Object as JSONObject } from 'json-typescript';

import type { Snapshot } 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 { ModelSchema } from './ds-model';
import type { JsonApiDocument, SingleResourceDocument } from './ember-data-json-api';
Expand Down
1 change: 1 addition & 0 deletions packages/-ember-data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ let app = new EmberApp(defaults, {
LOG_OPERATIONS: false, // updates to cache remote state
LOG_MUTATIONS: false, // updates to cache local state
LOG_NOTIFICATIONS: false,
LOG_REQUESTS: false, // log Requests issued via the request manager
LOG_REQUEST_STATUS: false,
LOG_IDENTIFIERS: false,
LOG_GRAPH: false, // relationship storage
Expand Down
30 changes: 30 additions & 0 deletions packages/-ember-data/addon-test-support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { assert } from '@ember/debug';
import { render as renderTemplate, settled } from '@ember/test-helpers';

import * as QUnit from 'qunit';

import { PRODUCTION } from '@ember-data/env';

/*
Temporary replacement for the render test helper
which we will deprecate in EmberData 5.0, this allows
an app to incrementally migrate to tests that render async
relationships in stages with potential for tests in between.
*/
export async function render(template) {
await renderTemplate(template);
const owner = QUnit.config.current.testEnvironment.owner;
const pending = owner.lookup('service:store')._getAllPending();

// this should only be necessary in production tests
// where @ember/test-waiters is deactivated :()
if (PRODUCTION) {
assert(
`No pending requests exist in this test, use \`import { render } from '@ember/test-helpers';\``,
pending.length
);

await pending;
await settled();
}
}
2 changes: 1 addition & 1 deletion packages/-ember-data/addon/-private/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class Store extends BaseStore {

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

// `ember-data-model-fragments' and `ember-data-change-tracker` rely on `normalizeModelName`
export { RecordArrayManager, normalizeModelName, coerceId } from '@ember-data/store/-private';
Expand Down
1 change: 1 addition & 0 deletions packages/-ember-data/addon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ that has not explicitly activated it. To activate it set the appropriate flag to
LOG_OPERATIONS: false, // updates to cache remote state
LOG_MUTATIONS: false, // updates to cache local state
LOG_NOTIFICATIONS: false,
LOG_REQUESTS: false, // log Requests issued via the request manager
LOG_REQUEST_STATUS: false,
LOG_IDENTIFIERS: false,
LOG_GRAPH: false,
Expand Down
7 changes: 4 additions & 3 deletions packages/adapter/addon-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module.exports = {
LOG_OPERATIONS: false,
LOG_MUTATIONS: false,
LOG_NOTIFICATIONS: false,
LOG_REQUESTS: false,
LOG_REQUEST_STATUS: false,
LOG_IDENTIFIERS: false,
LOG_GRAPH: false,
Expand All @@ -35,8 +36,8 @@ module.exports = {
hostOptions.debug || {}
);

const HAS_DEBUG_PACKAGE = detectModule('@ember-data/debug', __dirname, pkg);
const HAS_META_PACKAGE = detectModule('ember-data', __dirname, pkg);
const HAS_DEBUG_PACKAGE = detectModule(require, '@ember-data/debug', __dirname, pkg);
const HAS_META_PACKAGE = detectModule(require, 'ember-data', __dirname, pkg);

const includeDataAdapterInProduction =
typeof hostOptions.includeDataAdapterInProduction === 'boolean'
Expand All @@ -52,7 +53,7 @@ module.exports = {
delete MACRO_PACKAGE_FLAGS['HAS_DEBUG_PACKAGE'];

Object.keys(MACRO_PACKAGE_FLAGS).forEach((key) => {
MACRO_PACKAGE_FLAGS[key] = detectModule(MACRO_PACKAGE_FLAGS[key], __dirname, pkg);
MACRO_PACKAGE_FLAGS[key] = detectModule(require, MACRO_PACKAGE_FLAGS[key], __dirname, pkg);
});

// copy configs forward
Expand Down
3 changes: 1 addition & 2 deletions packages/adapter/src/-private/build-url-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ 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 { Snapshot, SnapshotRecordArray } from '@ember-data/legacy-compat/-private';
import type { Dict } from '@ember-data/types/q/utils';

/**
Expand Down
3 changes: 1 addition & 2 deletions packages/adapter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,8 @@ import EmberObject from '@ember/object';
import { inject as service } from '@ember/service';

import { DEBUG } from '@ember-data/env';
import type { SnapshotRecordArray } from '@ember-data/legacy-compat/-private';
import type { Snapshot, 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 { 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/json-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { dasherize } from '@ember/string';

import { pluralize } from 'ember-inflector';

import type { Snapshot } 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 { AdapterPayload } from '@ember-data/types/q/minimum-adapter-interface';

import { serializeIntoHash } from './-private';
Expand Down
3 changes: 1 addition & 2 deletions packages/adapter/src/rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import { computed } from '@ember/object';
import { join } from '@ember/runloop';

import { DEBUG } from '@ember-data/env';
import type { SnapshotRecordArray } from '@ember-data/legacy-compat/-private';
import type { Snapshot, 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 { AdapterPayload } from '@ember-data/types/q/minimum-adapter-interface';
import type { Dict } from '@ember-data/types/q/utils';

Expand Down
7 changes: 4 additions & 3 deletions packages/graph/addon-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module.exports = {
LOG_OPERATIONS: false,
LOG_MUTATIONS: false,
LOG_NOTIFICATIONS: false,
LOG_REQUESTS: false,
LOG_REQUEST_STATUS: false,
LOG_IDENTIFIERS: false,
LOG_GRAPH: false,
Expand All @@ -35,8 +36,8 @@ module.exports = {
hostOptions.debug || {}
);

const HAS_DEBUG_PACKAGE = detectModule('@ember-data/debug', __dirname, pkg);
const HAS_META_PACKAGE = detectModule('ember-data', __dirname, pkg);
const HAS_DEBUG_PACKAGE = detectModule(require, '@ember-data/debug', __dirname, pkg);
const HAS_META_PACKAGE = detectModule(require, 'ember-data', __dirname, pkg);

const includeDataAdapterInProduction =
typeof hostOptions.includeDataAdapterInProduction === 'boolean'
Expand All @@ -52,7 +53,7 @@ module.exports = {
delete MACRO_PACKAGE_FLAGS['HAS_DEBUG_PACKAGE'];

Object.keys(MACRO_PACKAGE_FLAGS).forEach((key) => {
MACRO_PACKAGE_FLAGS[key] = detectModule(MACRO_PACKAGE_FLAGS[key], __dirname, pkg);
MACRO_PACKAGE_FLAGS[key] = detectModule(require, MACRO_PACKAGE_FLAGS[key], __dirname, pkg);
});

// copy configs forward
Expand Down
7 changes: 4 additions & 3 deletions packages/json-api/addon-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module.exports = {
LOG_OPERATIONS: false,
LOG_MUTATIONS: false,
LOG_NOTIFICATIONS: false,
LOG_REQUESTS: false,
LOG_REQUEST_STATUS: false,
LOG_IDENTIFIERS: false,
LOG_GRAPH: false,
Expand All @@ -35,8 +36,8 @@ module.exports = {
hostOptions.debug || {}
);

const HAS_DEBUG_PACKAGE = detectModule('@ember-data/debug', __dirname, pkg);
const HAS_META_PACKAGE = detectModule('ember-data', __dirname, pkg);
const HAS_DEBUG_PACKAGE = detectModule(require, '@ember-data/debug', __dirname, pkg);
const HAS_META_PACKAGE = detectModule(require, 'ember-data', __dirname, pkg);

const includeDataAdapterInProduction =
typeof hostOptions.includeDataAdapterInProduction === 'boolean'
Expand All @@ -52,7 +53,7 @@ module.exports = {
delete MACRO_PACKAGE_FLAGS['HAS_DEBUG_PACKAGE'];

Object.keys(MACRO_PACKAGE_FLAGS).forEach((key) => {
MACRO_PACKAGE_FLAGS[key] = detectModule(MACRO_PACKAGE_FLAGS[key], __dirname, pkg);
MACRO_PACKAGE_FLAGS[key] = detectModule(require, MACRO_PACKAGE_FLAGS[key], __dirname, pkg);
});

// copy configs forward
Expand Down
7 changes: 4 additions & 3 deletions packages/legacy-compat/addon-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module.exports = {
LOG_OPERATIONS: false,
LOG_MUTATIONS: false,
LOG_NOTIFICATIONS: false,
LOG_REQUESTS: false,
LOG_REQUEST_STATUS: false,
LOG_IDENTIFIERS: false,
LOG_GRAPH: false,
Expand All @@ -35,8 +36,8 @@ module.exports = {
hostOptions.debug || {}
);

const HAS_DEBUG_PACKAGE = detectModule('@ember-data/debug', __dirname, pkg);
const HAS_META_PACKAGE = detectModule('ember-data', __dirname, pkg);
const HAS_DEBUG_PACKAGE = detectModule(require, '@ember-data/debug', __dirname, pkg);
const HAS_META_PACKAGE = detectModule(require, 'ember-data', __dirname, pkg);

const includeDataAdapterInProduction =
typeof hostOptions.includeDataAdapterInProduction === 'boolean'
Expand All @@ -52,7 +53,7 @@ module.exports = {
delete MACRO_PACKAGE_FLAGS['HAS_DEBUG_PACKAGE'];

Object.keys(MACRO_PACKAGE_FLAGS).forEach((key) => {
MACRO_PACKAGE_FLAGS[key] = detectModule(MACRO_PACKAGE_FLAGS[key], __dirname, pkg);
MACRO_PACKAGE_FLAGS[key] = detectModule(require, MACRO_PACKAGE_FLAGS[key], __dirname, pkg);
});

// copy configs forward
Expand Down
13 changes: 12 additions & 1 deletion packages/legacy-compat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,18 @@
"injected": true
}
},
"peerDependencies": {},
"peerDependencies": {
"@ember-data/graph": "workspace:4.12.0-alpha.11",
"@ember-data/json-api": "workspace:4.12.0-alpha.11"
},
"peerDependenciesMeta": {
"@ember-data/graph": {
"optional": true
},
"@ember-data/json-api": {
"optional": true
}
},
"devDependencies": {
"@embroider/addon-dev": "^3.0.0",
"rollup": "^3.20.1",
Expand Down
1 change: 1 addition & 0 deletions packages/legacy-compat/src/-private.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { default as SnapshotRecordArray } from './legacy-network-handler/snapshot-record-array';
export { SaveOp } from './legacy-network-handler/fetch-manager';
export { default as FetchManager } from './legacy-network-handler/fetch-manager';
export { default as Snapshot } from './legacy-network-handler/snapshot';
Loading

0 comments on commit a754ec7

Please sign in to comment.