Skip to content

Commit f52c007

Browse files
committed
feat: implement SchemaService RFC emberjs/rfcs#1027
1 parent 92a3320 commit f52c007

File tree

90 files changed

+3320
-2945
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+3320
-2945
lines changed

config/package.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@
2121
"eslint-plugin-n": "^16.6.2",
2222
"eslint-plugin-qunit": "^8.1.1",
2323
"eslint-plugin-simple-import-sort": "^12.1.0",
24-
"minimatch": "^9.0.4",
2524
"rollup": "^4.17.2",
2625
"typescript": "^5.4.5",
2726
"vite": "^5.2.11",
28-
"vite-plugin-dts": "^3.9.1",
29-
"walk-sync": "^3.0.0"
27+
"vite-plugin-dts": "^3.9.1"
3028
},
3129
"engines": {
3230
"node": ">= 22.1.0"

config/rollup/keep-assets.js

-44
This file was deleted.

config/vite/config.js

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export function createConfig(options, resolve) {
4848
: undefined,
4949
options.fixModule ? FixModuleOutputPlugin : undefined,
5050
// options.compileTypes === true && options.rollupTypes === false ? CompileTypesPlugin(options.useGlint) : undefined,
51+
...(options.plugins ?? []),
5152
]
5253
.concat(options.plugins || [])
5354
.filter(Boolean),

config/vite/keep-assets.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { join } from 'path';
2+
import { copyFileSync, globSync, mkdirSync } from 'fs';
3+
4+
export function keepAssets({ from, include, dist }) {
5+
return {
6+
name: 'copy-assets',
7+
8+
// the assets go into the output directory in the same relative locations as
9+
// in the input directory
10+
async closeBundle() {
11+
const files = globSync(include, { cwd: join(process.cwd(), from) });
12+
for (let name of files) {
13+
const fromPath = join(process.cwd(), from, name);
14+
const toPath = join(process.cwd(), dist, name);
15+
16+
mkdirSync(join(toPath, '..'), { recursive: true });
17+
copyFileSync(fromPath, toPath);
18+
}
19+
},
20+
};
21+
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"scripts": {
1010
"takeoff": "FORCE_COLOR=2 pnpm install --prefer-offline --reporter=append-only",
1111
"prepare": "turbo run build:infra; pnpm --filter './packages/*' run --parallel --if-present sync-hardlinks; turbo run build:pkg; pnpm run prepare:types; pnpm run _task:sync-hardlinks;",
12-
"prepare:types": "tsc --build; turbo run build:glint;",
12+
"prepare:types": "tsc --build --force; turbo run build:glint;",
1313
"release": "./release/index.ts",
1414
"build": "turbo _build --log-order=stream --filter=./packages/* --concurrency=10;",
1515
"_task:sync-hardlinks": "pnpm run -r --parallel --if-present sync-hardlinks;",

packages/-ember-data/src/store.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { buildSchema, instantiateRecord, modelFor, teardownRecord } from '@ember
1515
import RequestManager from '@ember-data/request';
1616
import Fetch from '@ember-data/request/fetch';
1717
import BaseStore, { CacheHandler } from '@ember-data/store';
18-
import type { CacheCapabilitiesManager, ModelSchema } from '@ember-data/store/types';
18+
import type { CacheCapabilitiesManager, ModelSchema, SchemaService } from '@ember-data/store/types';
1919
import type { StableRecordIdentifier } from '@warp-drive/core-types';
2020
import type { Cache } from '@warp-drive/core-types/cache';
2121
import type { TypeFromInstance } from '@warp-drive/core-types/record';
@@ -35,7 +35,10 @@ export default class Store extends BaseStore {
3535
this.requestManager.use([LegacyNetworkHandler, Fetch]);
3636
}
3737
this.requestManager.useCache(CacheHandler);
38-
this.registerSchema(buildSchema(this));
38+
}
39+
40+
createSchemaService(): SchemaService {
41+
return buildSchema(this);
3942
}
4043

4144
createCache(storeWrapper: CacheCapabilitiesManager): Cache {

packages/build-config/src/deprecation-versions.ts

+24
Original file line numberDiff line numberDiff line change
@@ -398,3 +398,27 @@ export const DEPRECATE_MANY_ARRAY_DUPLICATES = '5.3';
398398
* @public
399399
*/
400400
export const DEPRECATE_STORE_EXTENDS_EMBER_OBJECT = '5.4';
401+
402+
/**
403+
* **id: ember-data:schema-service-updates**
404+
*
405+
* When the flag is `true` (default), the legacy schema
406+
* service features will be enabled on the store and
407+
* the service, and deprecations will be thrown when
408+
* they are used.
409+
*
410+
* Deprecated features include:
411+
*
412+
* - `Store.registerSchema` method is deprecated in favor of the `Store.createSchemaService` hook
413+
* - `Store.registerSchemaDefinitionService` method is deprecated in favor of the `Store.createSchemaService` hook
414+
* - `Store.getSchemaDefinitionService` method is deprecated in favor of `Store.schema` property
415+
* - `SchemaService.doesTypeExist` method is deprecated in favor of the `SchemaService.hasResource` method
416+
* - `SchemaService.attributesDefinitionFor` method is deprecated in favor of the `SchemaService.fields` method
417+
* - `SchemaService.relationshipsDefinitionFor` method is deprecated in favor of the `SchemaService.fields` method
418+
*
419+
* @property ENABLE_LEGACY_SCHEMA_SERVICE
420+
* @since 5.4
421+
* @until 6.0
422+
* @public
423+
*/
424+
export const ENABLE_LEGACY_SCHEMA_SERVICE = '5.4';

packages/build-config/src/deprecations.ts

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ export const DEPRECATE_NON_UNIQUE_PAYLOADS: boolean = true;
88
export const DEPRECATE_RELATIONSHIP_REMOTE_UPDATE_CLEARING_LOCAL_STATE: boolean = true;
99
export const DEPRECATE_MANY_ARRAY_DUPLICATES: boolean = true;
1010
export const DEPRECATE_STORE_EXTENDS_EMBER_OBJECT: boolean = true;
11+
export const ENABLE_LEGACY_SCHEMA_SERVICE: boolean = true;
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import type { StableRecordIdentifier } from '../identifier';
2+
import type { ObjectValue, Value } from '../json/raw';
3+
import type { OpaqueRecordInstance } from '../record';
4+
import type { Type } from '../symbols';
5+
6+
export type Transformation<T extends Value = Value, PT = unknown> = {
7+
serialize(value: PT, options: ObjectValue | null, record: OpaqueRecordInstance): T;
8+
hydrate(value: T | undefined, options: ObjectValue | null, record: OpaqueRecordInstance): PT;
9+
defaultValue?(options: ObjectValue | null, identifier: StableRecordIdentifier): T;
10+
[Type]: string;
11+
};
12+
13+
export type Derivation<R = unknown, T = unknown, FM extends ObjectValue | null = ObjectValue | null> = {
14+
[Type]: string;
15+
} & ((record: R, options: FM, prop: string) => T);
16+
17+
export type HashFn<T extends object = object> = { [Type]: string } & ((
18+
data: T,
19+
options: ObjectValue | null,
20+
prop: string | null
21+
) => string);

0 commit comments

Comments
 (0)