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

chore: [BREAKING to prior alpha/betas] prepare SchemaRecord for stable, lockdown exports #9697

Merged
merged 3 commits into from
Feb 23, 2025
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
2 changes: 1 addition & 1 deletion packages/experiments/src/data-worker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ import JSONAPICache from '@ember-data/json-api';
import { DataWorker, CacheHandler } from '@warp-drive/experiments/data-worker';
import type { CacheCapabilitiesManager } from '@ember-data/store/types';
import { CachePolicy } from '@ember-data/request-utils';
import { SchemaService } from '@warp-drive/schema-record/schema';
import { SchemaService } from '@warp-drive/schema-record';

class WorkerStore extends Store {
requestManager = new RequestManager()
Expand Down
11 changes: 5 additions & 6 deletions packages/schema-record/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ that instance, it will call `teardownRecord`.

```diff
import Store from '@ember-data/store';
+import { instantiateRecord, teardownRecord } from '@warp-drive/schema-record/hooks';
+import { registerDerivations, SchemaService } from '@warp-drive/schema-record/schema';
+import { instantiateRecord, teardownRecord, registerDerivations, SchemaService } from '@warp-drive/schema-record';

class AppStore extends Store {

Expand All @@ -75,11 +74,11 @@ class AppStore extends Store {
+ return schema;
+ }

+ instantiateRecord(identifier: StableRecordIdentifier, createArgs?: Record<string, unknown>): SchemaRecord {
+ instantiateRecord(identifier, createArgs) {
+ return instantiateRecord(this, identifier, createArgs);
+ }

+ teardownRecord(record: SchemaRecord): void {
+ teardownRecord(record) {
+ return teardownRecord(record);
+ }
}
Expand Down Expand Up @@ -230,7 +229,7 @@ in the process gaining access to an editable copy. The immutable version will
not show any in-process edits made to this editable copy.

```ts
import { Checkout } from '@warp-drive/schema-record/record';
import { Checkout } from '@warp-drive/schema-record';

const editable = await user[Checkout]();
```
Expand All @@ -242,7 +241,7 @@ conventional fields like identity and `$type`. We can rewrite the schema
definition above using this utility like so:

```ts
import { withDefaults } from '@warp-drive/schema-record/schema';
import { withDefaults } from '@warp-drive/schema-record';

store.registerSchemas([
withDefaults({
Expand Down
4 changes: 4 additions & 0 deletions packages/schema-record/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
"unstable-preview-types"
],
"exports": {
".": {
"types": "./unstable-preview-types/index.d.ts",
"default": "./dist/index.js"
},
"./*": {
"types": "./unstable-preview-types/*.d.ts",
"default": "./dist/*.js"
Expand Down
1 change: 1 addition & 0 deletions packages/schema-record/src/-private.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Editable, Legacy } from './-private/symbols';
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type Store from '@ember-data/store';
import { assert } from '@warp-drive/build-config/macros';
import type { StableRecordIdentifier } from '@warp-drive/core-types';

import { SchemaRecord } from './record';
Expand All @@ -25,6 +26,11 @@ export function instantiateRecord(
return record;
}

export function teardownRecord(record: SchemaRecord): void {
function assertSchemaRecord(record: unknown): asserts record is SchemaRecord {
assert('Expected a SchemaRecord', record && typeof record === 'object' && Destroy in record);
}

export function teardownRecord(record: unknown): void {
assertSchemaRecord(record);
record[Destroy]();
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
ManagedObjectMap,
peekManagedArray,
peekManagedObject,
} from './-private/compute';
} from './fields/compute';
import type { SchemaService } from './schema';
import {
ARRAY_SIGNAL,
Expand Down Expand Up @@ -125,6 +125,9 @@ export class SchemaRecord {
},

has(target: SchemaRecord, prop: string | number | symbol) {
if (prop === Destroy || prop === Checkout) {
return true;
}
return fields.has(prop as string);
},

Expand Down
4 changes: 4 additions & 0 deletions packages/schema-record/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export { instantiateRecord, teardownRecord } from './-private/hooks';
export { type Transformation, SchemaService, withDefaults, fromIdentity, registerDerivations } from './-private/schema';
export { type SchemaRecord } from './-private/record';
export { Checkout } from './-private/symbols';
2 changes: 1 addition & 1 deletion packages/schema-record/vite.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createConfig } from '@warp-drive/internal-config/vite/config.js';

export const externals = ['@ember/debug'];

export const entryPoints = ['src/hooks.ts', 'src/record.ts', 'src/schema.ts'];
export const entryPoints = ['src/index.ts', 'src/-private.ts'];

export default createConfig(
{
Expand Down
4 changes: 2 additions & 2 deletions packages/store/src/-private/store-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export interface Store {
* For Example, to use the default SchemaService for SchemaRecord
*
* ```ts
* import { SchemaService } from '@warp-drive/schema-record/schema';
* import { SchemaService } from '@warp-drive/schema-record';
*
* class extends Store {
* createSchemaService() {
Expand Down Expand Up @@ -302,7 +302,7 @@ export interface Store {
*
* ```ts
* import { DelegatingSchemaService } from '@ember-data/model/migration-support';
* import { SchemaService } from '@warp-drive/schema-record/schema';
* import { SchemaService } from '@warp-drive/schema-record';
*
* class extends Store {
* createSchemaService() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ import type { CacheCapabilitiesManager } from '@ember-data/store/types';
import type { StableRecordIdentifier } from '@warp-drive/core-types';
import type { SingleResourceDataDocument } from '@warp-drive/core-types/spec/document';
import type { Type } from '@warp-drive/core-types/symbols';
import { instantiateRecord, teardownRecord } from '@warp-drive/schema-record/hooks';
import type { SchemaRecord } from '@warp-drive/schema-record/record';
import { registerDerivations, SchemaService, withDefaults } from '@warp-drive/schema-record/schema';
import {
instantiateRecord,
registerDerivations,
SchemaService,
teardownRecord,
withDefaults,
} from '@warp-drive/schema-record';

type User = {
id: string;
Expand Down Expand Up @@ -40,7 +44,7 @@ class TestStore extends Store {
return instantiateRecord(this, identifier, createRecordArgs);
}

teardownRecord(record: SchemaRecord) {
teardownRecord(record: unknown) {
teardownRecord(record);
}
}
Expand Down
8 changes: 3 additions & 5 deletions tests/warp-drive__ember/app/services/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import DataStore, { CacheHandler } from '@ember-data/store';
import type { CacheCapabilitiesManager } from '@ember-data/store/types';
import type { StableRecordIdentifier } from '@warp-drive/core-types';
import type { Cache } from '@warp-drive/core-types/cache';
import { instantiateRecord, teardownRecord } from '@warp-drive/schema-record/hooks';
import type { SchemaRecord } from '@warp-drive/schema-record/record';
import { SchemaService } from '@warp-drive/schema-record/schema';
import { instantiateRecord, SchemaService, teardownRecord } from '@warp-drive/schema-record';

export default class Store extends DataStore {
constructor(args: unknown) {
Expand All @@ -26,11 +24,11 @@ export default class Store extends DataStore {
return new JSONAPICache(capabilities);
}

instantiateRecord(identifier: StableRecordIdentifier, createArgs?: Record<string, unknown>): SchemaRecord {
instantiateRecord(identifier: StableRecordIdentifier, createArgs?: Record<string, unknown>) {
return instantiateRecord(this, identifier, createArgs);
}

teardownRecord(record: SchemaRecord): void {
teardownRecord(record: unknown): void {
return teardownRecord(record);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ import { module, setupRenderingTest, test as _test } from '@warp-drive/diagnosti
import { Request } from '@warp-drive/ember';
import { MockServerHandler } from '@warp-drive/holodeck';
import { GET } from '@warp-drive/holodeck/mock';
import { instantiateRecord, teardownRecord } from '@warp-drive/schema-record/hooks';
import type { SchemaRecord } from '@warp-drive/schema-record/record';
import { registerDerivations, SchemaService, withDefaults } from '@warp-drive/schema-record/schema';
import {
instantiateRecord,
registerDerivations,
SchemaService,
teardownRecord,
withDefaults,
} from '@warp-drive/schema-record';

function trim(str?: string | null): string {
if (!str) {
Expand Down Expand Up @@ -83,7 +87,7 @@ class TestStore extends Store {
return instantiateRecord(this, identifier, createRecordArgs);
}

teardownRecord(record: SchemaRecord) {
teardownRecord(record: unknown) {
teardownRecord(record);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ import { module, setupRenderingTest, test as _test } from '@warp-drive/diagnosti
import { Request } from '@warp-drive/ember';
import { MockServerHandler } from '@warp-drive/holodeck';
import { GET } from '@warp-drive/holodeck/mock';
import { instantiateRecord, teardownRecord } from '@warp-drive/schema-record/hooks';
import type { SchemaRecord } from '@warp-drive/schema-record/record';
import { registerDerivations, SchemaService, withDefaults } from '@warp-drive/schema-record/schema';
import {
instantiateRecord,
registerDerivations,
SchemaService,
teardownRecord,
withDefaults,
} from '@warp-drive/schema-record';

type User = {
id: string;
Expand Down Expand Up @@ -112,7 +116,7 @@ class TestStore extends Store {
return instantiateRecord(this, identifier, createRecordArgs);
}

teardownRecord(record: SchemaRecord) {
teardownRecord(record: unknown) {
teardownRecord(record);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { module, setupRenderingTest, test as _test } from '@warp-drive/diagnosti
import { getRequestState, Request } from '@warp-drive/ember';
import { mock, MockServerHandler } from '@warp-drive/holodeck';
import { GET } from '@warp-drive/holodeck/mock';
import { registerDerivations, withDefaults } from '@warp-drive/schema-record/schema';
import { registerDerivations, withDefaults } from '@warp-drive/schema-record';

// our tests use a rendering test context and add manager to it
interface LocalTestContext extends RenderingTestContext {
Expand Down
8 changes: 3 additions & 5 deletions tests/warp-drive__experiments/app/services/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import DataStore, { CacheHandler } from '@ember-data/store';
import type { CacheCapabilitiesManager } from '@ember-data/store/types';
import type { StableRecordIdentifier } from '@warp-drive/core-types';
import type { Cache } from '@warp-drive/core-types/cache';
import { instantiateRecord, teardownRecord } from '@warp-drive/schema-record/hooks';
import type { SchemaRecord } from '@warp-drive/schema-record/record';
import { SchemaService } from '@warp-drive/schema-record/schema';
import { instantiateRecord, SchemaService, teardownRecord } from '@warp-drive/schema-record';

export default class Store extends DataStore {
constructor(args: unknown) {
Expand All @@ -26,11 +24,11 @@ export default class Store extends DataStore {
return new JSONAPICache(capabilities);
}

instantiateRecord(identifier: StableRecordIdentifier, createArgs?: Record<string, unknown>): SchemaRecord {
instantiateRecord(identifier: StableRecordIdentifier, createArgs?: Record<string, unknown>) {
return instantiateRecord(this, identifier, createArgs);
}

teardownRecord(record: SchemaRecord): void {
teardownRecord(record: unknown): void {
return teardownRecord(record);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import { module, test } from '@warp-drive/diagnostic';
import { WorkerFetch } from '@warp-drive/experiments/worker-fetch';
import { MockServerHandler } from '@warp-drive/holodeck';
import { GET } from '@warp-drive/holodeck/mock';
import { instantiateRecord, teardownRecord } from '@warp-drive/schema-record/hooks';
import type { SchemaRecord } from '@warp-drive/schema-record/record';
import { registerDerivations, SchemaService } from '@warp-drive/schema-record/schema';
import { instantiateRecord, registerDerivations, SchemaService, teardownRecord } from '@warp-drive/schema-record';

import { UserSchema } from './user-schema';

Expand Down Expand Up @@ -67,7 +65,7 @@ module('Unit | DataWorker | Basic', function (_hooks) {
}

teardownRecord(record: unknown): void {
return teardownRecord(record as SchemaRecord);
return teardownRecord(record);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CachePolicy } from '@ember-data/request-utils';
import Store from '@ember-data/store';
import type { CacheCapabilitiesManager } from '@ember-data/store/types';
import { CacheHandler, DataWorker } from '@warp-drive/experiments/data-worker';
import { SchemaService } from '@warp-drive/schema-record/schema';
import { SchemaService } from '@warp-drive/schema-record';

import { UserSchema } from './user-schema';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CachePolicy } from '@ember-data/request-utils';
import Store from '@ember-data/store';
import type { CacheCapabilitiesManager } from '@ember-data/store/types';
import { CacheHandler, DataWorker } from '@warp-drive/experiments/data-worker';
import { SchemaService } from '@warp-drive/schema-record/schema';
import { SchemaService } from '@warp-drive/schema-record';

import { UserSchema } from './user-schema';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import { module, test } from '@warp-drive/diagnostic';
import { WorkerFetch } from '@warp-drive/experiments/worker-fetch';
import { MockServerHandler } from '@warp-drive/holodeck';
import { GET } from '@warp-drive/holodeck/mock';
import { instantiateRecord, teardownRecord } from '@warp-drive/schema-record/hooks';
import type { SchemaRecord } from '@warp-drive/schema-record/record';
import { registerDerivations, SchemaService } from '@warp-drive/schema-record/schema';
import { instantiateRecord, registerDerivations, SchemaService, teardownRecord } from '@warp-drive/schema-record';

import { UserSchema } from './user-schema';

Expand Down Expand Up @@ -76,7 +74,7 @@ module('Unit | DataWorker | Serialization & Persistence', function (_hooks) {
}

teardownRecord(record: unknown): void {
return teardownRecord(record as SchemaRecord);
return teardownRecord(record);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { withDefaults } from '@warp-drive/schema-record/schema';
import { withDefaults } from '@warp-drive/schema-record';

export const UserSchema = withDefaults({
type: 'user',
Expand Down
8 changes: 3 additions & 5 deletions tests/warp-drive__schema-record/app/services/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import Fetch from '@ember-data/request/fetch';
import DataStore, { CacheHandler } from '@ember-data/store';
import type { CacheCapabilitiesManager } from '@ember-data/store/types';
import type { StableRecordIdentifier } from '@warp-drive/core-types';
import { instantiateRecord, teardownRecord } from '@warp-drive/schema-record/hooks';
import type { SchemaRecord } from '@warp-drive/schema-record/record';
import { SchemaService } from '@warp-drive/schema-record/schema';
import { instantiateRecord, SchemaService, teardownRecord } from '@warp-drive/schema-record';

export default class Store extends DataStore {
constructor(args: unknown) {
Expand All @@ -25,11 +23,11 @@ export default class Store extends DataStore {
return new JSONAPICache(capabilities);
}

override instantiateRecord(identifier: StableRecordIdentifier, createArgs?: Record<string, unknown>): SchemaRecord {
override instantiateRecord(identifier: StableRecordIdentifier, createArgs?: Record<string, unknown>) {
return instantiateRecord(this, identifier, createArgs);
}

override teardownRecord(record: SchemaRecord): void {
override teardownRecord(record: unknown): void {
return teardownRecord(record);
}
}
3 changes: 1 addition & 2 deletions tests/warp-drive__schema-record/tests/edit-workflow-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { serializePatch, serializeResources, updateRecord } from '@ember-data/js
import RequestManager from '@ember-data/request';
import { CacheHandler, recordIdentifierFor } from '@ember-data/store';
import type { Type } from '@warp-drive/core-types/symbols';
import { Checkout } from '@warp-drive/schema-record/record';
import { registerDerivations, withDefaults } from '@warp-drive/schema-record/schema';
import { Checkout, registerDerivations, withDefaults } from '@warp-drive/schema-record';

import type Store from '../app/services/store';

Expand Down
4 changes: 2 additions & 2 deletions tests/warp-drive__schema-record/tests/legacy/mode-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import RequestManager from '@ember-data/request';
import type Store from '@ember-data/store';
import { CacheHandler } from '@ember-data/store';
import type { Type } from '@warp-drive/core-types/symbols';
import { Editable, Legacy } from '@warp-drive/schema-record/record';
import { registerDerivations, withDefaults } from '@warp-drive/schema-record/schema';
import { registerDerivations, withDefaults } from '@warp-drive/schema-record';
import { Editable, Legacy } from '@warp-drive/schema-record/-private';

type Errors = Model['errors'];
type RecordState = Model['currentState'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import type Store from '@ember-data/store';
import { recordIdentifierFor } from '@ember-data/store';
import type { StableRecordIdentifier } from '@warp-drive/core-types';
import { Type } from '@warp-drive/core-types/symbols';
import type { SchemaRecord } from '@warp-drive/schema-record/record';
import type { Transformation } from '@warp-drive/schema-record/schema';
import type { SchemaRecord, Transformation } from '@warp-drive/schema-record';

import { simplePayloadNormalize } from '../../-utils/normalize-payload';
import { reactiveContext } from '../../-utils/reactive-context';
Expand Down
Loading
Loading