Skip to content

Commit

Permalink
feat: impl SchemaService RFC (#9448)
Browse files Browse the repository at this point in the history
* feat: implement SchemaService RFC emberjs/rfcs#1027

* add deprecations, fix prod test

* delegating schema provider

* cleanup'
  • Loading branch information
runspired committed May 22, 2024
1 parent 8c4fbb9 commit b54f476
Show file tree
Hide file tree
Showing 92 changed files with 3,479 additions and 2,947 deletions.
4 changes: 1 addition & 3 deletions config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@
"eslint-plugin-n": "^16.6.2",
"eslint-plugin-qunit": "^8.1.1",
"eslint-plugin-simple-import-sort": "^12.1.0",
"minimatch": "^9.0.4",
"rollup": "^4.17.2",
"typescript": "^5.4.5",
"vite": "^5.2.11",
"vite-plugin-dts": "^3.9.1",
"walk-sync": "^3.0.0"
"vite-plugin-dts": "^3.9.1"
},
"engines": {
"node": ">= 22.1.0"
Expand Down
44 changes: 0 additions & 44 deletions config/rollup/keep-assets.js

This file was deleted.

1 change: 1 addition & 0 deletions config/vite/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export function createConfig(options, resolve) {
: undefined,
options.fixModule ? FixModuleOutputPlugin : undefined,
// options.compileTypes === true && options.rollupTypes === false ? CompileTypesPlugin(options.useGlint) : undefined,
...(options.plugins ?? []),
]
.concat(options.plugins || [])
.filter(Boolean),
Expand Down
21 changes: 21 additions & 0 deletions config/vite/keep-assets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { join } from 'path';
import { copyFileSync, globSync, mkdirSync } from 'fs';

export function keepAssets({ from, include, dist }) {
return {
name: 'copy-assets',

// the assets go into the output directory in the same relative locations as
// in the input directory
async closeBundle() {
const files = globSync(include, { cwd: join(process.cwd(), from) });
for (let name of files) {
const fromPath = join(process.cwd(), from, name);
const toPath = join(process.cwd(), dist, name);

mkdirSync(join(toPath, '..'), { recursive: true });
copyFileSync(fromPath, toPath);
}
},
};
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"scripts": {
"takeoff": "FORCE_COLOR=2 pnpm install --prefer-offline --reporter=append-only",
"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;",
"prepare:types": "tsc --build; turbo run build:glint;",
"prepare:types": "tsc --build --force; turbo run build:glint;",
"release": "./release/index.ts",
"build": "turbo _build --log-order=stream --filter=./packages/* --concurrency=10;",
"_task:sync-hardlinks": "pnpm run -r --parallel --if-present sync-hardlinks;",
Expand Down
7 changes: 5 additions & 2 deletions packages/-ember-data/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { buildSchema, instantiateRecord, modelFor, teardownRecord } from '@ember
import RequestManager from '@ember-data/request';
import Fetch from '@ember-data/request/fetch';
import BaseStore, { CacheHandler } from '@ember-data/store';
import type { CacheCapabilitiesManager, ModelSchema } from '@ember-data/store/types';
import type { CacheCapabilitiesManager, ModelSchema, SchemaService } from '@ember-data/store/types';
import type { StableRecordIdentifier } from '@warp-drive/core-types';
import type { Cache } from '@warp-drive/core-types/cache';
import type { TypeFromInstance } from '@warp-drive/core-types/record';
Expand All @@ -35,7 +35,10 @@ export default class Store extends BaseStore {
this.requestManager.use([LegacyNetworkHandler, Fetch]);
}
this.requestManager.useCache(CacheHandler);
this.registerSchema(buildSchema(this));
}

createSchemaService(): SchemaService {
return buildSchema(this);
}

createCache(storeWrapper: CacheCapabilitiesManager): Cache {
Expand Down
24 changes: 24 additions & 0 deletions packages/build-config/src/deprecation-versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,3 +398,27 @@ export const DEPRECATE_MANY_ARRAY_DUPLICATES = '5.3';
* @public
*/
export const DEPRECATE_STORE_EXTENDS_EMBER_OBJECT = '5.4';

/**
* **id: ember-data:schema-service-updates**
*
* When the flag is `true` (default), the legacy schema
* service features will be enabled on the store and
* the service, and deprecations will be thrown when
* they are used.
*
* Deprecated features include:
*
* - `Store.registerSchema` method is deprecated in favor of the `Store.createSchemaService` hook
* - `Store.registerSchemaDefinitionService` method is deprecated in favor of the `Store.createSchemaService` hook
* - `Store.getSchemaDefinitionService` method is deprecated in favor of `Store.schema` property
* - `SchemaService.doesTypeExist` method is deprecated in favor of the `SchemaService.hasResource` method
* - `SchemaService.attributesDefinitionFor` method is deprecated in favor of the `SchemaService.fields` method
* - `SchemaService.relationshipsDefinitionFor` method is deprecated in favor of the `SchemaService.fields` method
*
* @property ENABLE_LEGACY_SCHEMA_SERVICE
* @since 5.4
* @until 6.0
* @public
*/
export const ENABLE_LEGACY_SCHEMA_SERVICE = '5.4';
1 change: 1 addition & 0 deletions packages/build-config/src/deprecations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export const DEPRECATE_NON_UNIQUE_PAYLOADS: boolean = true;
export const DEPRECATE_RELATIONSHIP_REMOTE_UPDATE_CLEARING_LOCAL_STATE: boolean = true;
export const DEPRECATE_MANY_ARRAY_DUPLICATES: boolean = true;
export const DEPRECATE_STORE_EXTENDS_EMBER_OBJECT: boolean = true;
export const ENABLE_LEGACY_SCHEMA_SERVICE: boolean = true;
21 changes: 21 additions & 0 deletions packages/core-types/src/schema/concepts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { StableRecordIdentifier } from '../identifier';
import type { ObjectValue, Value } from '../json/raw';
import type { OpaqueRecordInstance } from '../record';
import type { Type } from '../symbols';

export type Transformation<T extends Value = Value, PT = unknown> = {
serialize(value: PT, options: ObjectValue | null, record: OpaqueRecordInstance): T;
hydrate(value: T | undefined, options: ObjectValue | null, record: OpaqueRecordInstance): PT;
defaultValue?(options: ObjectValue | null, identifier: StableRecordIdentifier): T;
[Type]: string;
};

export type Derivation<R = unknown, T = unknown, FM extends ObjectValue | null = ObjectValue | null> = {
[Type]: string;
} & ((record: R, options: FM, prop: string) => T);

export type HashFn<T extends object = object> = { [Type]: string } & ((
data: T,
options: ObjectValue | null,
prop: string | null
) => string);
Loading

0 comments on commit b54f476

Please sign in to comment.