From c03b77f406ab34726c29c3994f5adb3784a010f5 Mon Sep 17 00:00:00 2001 From: Chris Thoburn Date: Thu, 25 Jul 2024 22:44:57 -0700 Subject: [PATCH] updates --- .../graph/src/-private/-edge-definition.ts | 2 +- packages/graph/src/-private/graph.ts | 2 +- pnpm-lock.yaml | 5 ++ tests/ember-data__graph/config/environment.js | 11 +--- tests/ember-data__graph/package.json | 7 ++- .../tests/integration/graph.ts | 7 --- .../integration/resource/has-none-test.ts | 52 +++++++++++++++++++ tests/ember-data__graph/tsconfig.json | 7 ++- 8 files changed, 72 insertions(+), 21 deletions(-) delete mode 100644 tests/ember-data__graph/tests/integration/graph.ts create mode 100644 tests/ember-data__graph/tests/integration/resource/has-none-test.ts diff --git a/packages/graph/src/-private/-edge-definition.ts b/packages/graph/src/-private/-edge-definition.ts index ca3928cdaa5..95fd838c396 100644 --- a/packages/graph/src/-private/-edge-definition.ts +++ b/packages/graph/src/-private/-edge-definition.ts @@ -385,7 +385,7 @@ export function isRHS(info: EdgeDefinition, type: string, key: string): boolean export function upgradeDefinition( graph: Graph, - identifier: StableRecordIdentifier, + identifier: { type: string }, propertyName: string, isImplicit = false ): EdgeDefinition | null { diff --git a/packages/graph/src/-private/graph.ts b/packages/graph/src/-private/graph.ts index 6a9a441486d..2f0bccd198f 100644 --- a/packages/graph/src/-private/graph.ts +++ b/packages/graph/src/-private/graph.ts @@ -111,7 +111,7 @@ export class Graph { return relationships[propertyName] !== undefined; } - getDefinition(identifier: StableRecordIdentifier, propertyName: string): UpgradedMeta { + getDefinition(identifier: { type: string }, propertyName: string): UpgradedMeta { let defs = this._metaCache[identifier.type]; let meta: UpgradedMeta | null | undefined = defs?.[propertyName]; if (!meta) { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 08740573a1d..16a77150c9d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2487,6 +2487,9 @@ importers: '@warp-drive/internal-config': specifier: workspace:5.4.0-alpha.97 version: link:../../config + '@warp-drive/schema-record': + specifier: workspace:0.0.0-alpha.83 + version: file:packages/schema-record(@babel/core@7.24.5)(@ember-data/model@5.4.0-alpha.97)(@ember-data/request@5.4.0-alpha.97)(@ember-data/store@5.4.0-alpha.97)(@ember-data/tracking@5.4.0-alpha.97)(@warp-drive/core-types@0.0.0-alpha.83) ember-auto-import: specifier: ^2.7.4 version: 2.7.4(@glint/template@1.4.0) @@ -2568,6 +2571,8 @@ importers: injected: true '@warp-drive/diagnostic': injected: true + '@warp-drive/schema-record': + injected: true tests/ember-data__json-api: dependencies: diff --git a/tests/ember-data__graph/config/environment.js b/tests/ember-data__graph/config/environment.js index 94e67a34e77..78ae1c521a6 100644 --- a/tests/ember-data__graph/config/environment.js +++ b/tests/ember-data__graph/config/environment.js @@ -6,16 +6,7 @@ module.exports = function (environment) { environment, rootURL: '/', locationType: 'history', - EmberENV: { - FEATURES: { - // Here you can enable experimental features on an ember canary build - // e.g. EMBER_NATIVE_DECORATOR_SUPPORT: true - }, - EXTEND_PROTOTYPES: { - // Prevent Ember Data from overriding Date.parse. - Date: false, - }, - }, + EmberENV: {}, APP: { // Here you can pass flags/options to your application instance diff --git a/tests/ember-data__graph/package.json b/tests/ember-data__graph/package.json index 66faecd029e..8233782471d 100644 --- a/tests/ember-data__graph/package.json +++ b/tests/ember-data__graph/package.json @@ -20,6 +20,7 @@ "lint": "eslint . --quiet --cache --cache-strategy=content --report-unused-disable-directives", "check:types": "tsc --noEmit", "test": "bun ./diagnostic.js", + "start": "pnpm build:tests --watch", "test:production": "bun ./diagnostic.js", "sync-hardlinks": "bun run sync-dependencies-meta-injected" }, @@ -62,6 +63,9 @@ }, "@ember-data/debug": { "injected": true + }, + "@warp-drive/schema-record": { + "injected": true } }, "devDependencies": { @@ -88,6 +92,7 @@ "@warp-drive/build-config": "workspace:0.0.0-alpha.34", "@warp-drive/core-types": "workspace:0.0.0-alpha.83", "@warp-drive/internal-config": "workspace:5.4.0-alpha.97", + "@warp-drive/schema-record": "workspace:0.0.0-alpha.83", "@warp-drive/diagnostic": "workspace:0.0.0-alpha.83", "ember-auto-import": "^2.7.4", "ember-cli": "~5.9.0", @@ -121,4 +126,4 @@ "dependencies": { "pnpm-sync-dependencies-meta-injected": "0.0.14" } -} +} \ No newline at end of file diff --git a/tests/ember-data__graph/tests/integration/graph.ts b/tests/ember-data__graph/tests/integration/graph.ts deleted file mode 100644 index 526d87cf670..00000000000 --- a/tests/ember-data__graph/tests/integration/graph.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { module, test } from '@warp-drive/diagnostic'; - -module('RecordData', function () { - test('Test Suit Configured', function (assert) { - assert.ok('We are configured'); - }); -}); diff --git a/tests/ember-data__graph/tests/integration/resource/has-none-test.ts b/tests/ember-data__graph/tests/integration/resource/has-none-test.ts new file mode 100644 index 00000000000..debf45b4917 --- /dev/null +++ b/tests/ember-data__graph/tests/integration/resource/has-none-test.ts @@ -0,0 +1,52 @@ +import type { Graph } from '@ember-data/graph/-private'; +import { graphFor } from '@ember-data/graph/-private'; +import Store from '@ember-data/store'; +import { module, test as _test } from '@warp-drive/diagnostic'; +import type { TestContext } from '@warp-drive/diagnostic/ember'; +import { registerDerivations, SchemaService, withDefaults } from '@warp-drive/schema-record/schema'; + +interface LocalTestContext extends TestContext { + store: TestStore; + graph: Graph; +} + +type DiagnosticTest = Parameters>[1]; +function test(name: string, callback: DiagnosticTest): void { + return _test(name, callback); +} + +class TestStore extends Store { + createSchemaService() { + const schema = new SchemaService(); + registerDerivations(schema); + return schema; + } +} + +module('Integration | Graph | Resource > has-none', function (hooks) { + hooks.beforeEach(function () { + this.store = new TestStore(); + this.graph = graphFor(this.store._instanceCache._storeWrapper); + }); + + test('Graph.getDefinition works as expected', function (assert) { + const { store, graph } = this; + + // create a schema for a has-none relationship + const UserSchema = withDefaults({ + type: 'user', + fields: [ + { + name: 'bestFriend', + kind: 'resource', + type: 'user', + }, + ], + }); + store.schema.registerResource(UserSchema); + + // check that we can call getDefinition and get back something meaningful + const userDefinition = graph.getDefinition({ type: 'user' }, 'bestFriend'); + debugger; + }); +}); diff --git a/tests/ember-data__graph/tsconfig.json b/tests/ember-data__graph/tsconfig.json index d299b914f1c..16d7e5352b6 100644 --- a/tests/ember-data__graph/tsconfig.json +++ b/tests/ember-data__graph/tsconfig.json @@ -47,7 +47,9 @@ "@warp-drive/core-types": ["../../packages/core-types/unstable-preview-types"], "@warp-drive/core-types/*": ["../../packages/core-types/unstable-preview-types/*"], "@warp-drive/diagnostic": ["../../packages/diagnostic/unstable-preview-types"], - "@warp-drive/diagnostic/*": ["../../packages/diagnostic/unstable-preview-types/*"] + "@warp-drive/diagnostic/*": ["../../packages/diagnostic/unstable-preview-types/*"], + "@warp-drive/schema-record": ["../../packages/schema-record/unstable-preview-types"], + "@warp-drive/schema-record/*": ["../../packages/schema-record/unstable-preview-types/*"] }, "types": ["ember-source/types"] }, @@ -88,6 +90,9 @@ { "path": "../../packages/core-types" }, + { + "path": "../../packages/schema-record" + }, { "path": "../../packages/diagnostic" }