Skip to content

Commit

Permalink
feat: ember data primitives
Browse files Browse the repository at this point in the history
  • Loading branch information
runspired committed Mar 19, 2024
1 parent 630ed26 commit 42f1a68
Show file tree
Hide file tree
Showing 113 changed files with 6,341 additions and 3,522 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ packages/schema-record/addon/
packages/serializer/addon
packages/store/addon
packages/tracking/addon
packages/ember/addon

# dependencies
bower_components
Expand Down
16 changes: 16 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
module.exports = {
trailingComma: 'es5',
printWidth: 120,
plugins: ['prettier-plugin-ember-template-tag'],
overrides: [
{
files: '*.{js,ts,cjs,cts,mjs,mts}',
options: {
singleQuote: true,
},
},
{
files: ['*.hbs'],
options: {
singleQuote: false,
},
},
{
files: ['*.gjs', '*.gts'],
options: {
parser: 'ember-template-tag',
singleQuote: true,
templateSingleQuote: false,
trailingComma: 'es5',
},
},
],
};
2 changes: 1 addition & 1 deletion @types/@glimmer/tracking.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function cached(target: object, key: string, desc: PropertyDescriptor): void;

export function tracked(target: object, key: string): void;
export function tracked(target: object, key: string, desc?: object): void;
2 changes: 1 addition & 1 deletion config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"eslint-plugin-n": "^16.5.0",
"eslint-plugin-qunit": "^8.0.1",
"eslint-plugin-simple-import-sort": "^10.0.0",
"typescript": "~5.3.3"
"typescript": "^5.4.2"
},
"engines": {
"node": ">= 18.19.1"
Expand Down
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@
"test-external:ember-data-relationship-tracker": "node ./scripts/test-external-partner-project.js ember-data-relationship-tracker https://github.com/ef4/ember-data-relationship-tracker.git"
},
"devDependencies": {
"bun-types": "^1.0.25",
"@glint/core": "^1.3.0",
"@types/semver": "^7.5.6",
"bun-types": "^1.0.25",
"chalk": "^4.1.2",
"co": "^4.6.0",
"command-line-args": "^5.2.1",
Expand All @@ -51,9 +52,11 @@
"lerna-changelog": "^2.2.0",
"pnpm-sync-dependencies-meta-injected": "0.0.10",
"prettier": "^3.1.1",
"prettier-plugin-ember-template-tag": "^2.0.0",
"rimraf": "^5.0.5",
"semver": "^7.5.4",
"silent-error": "^1.1.1",
"typescript": "^5.4.2",
"url": "^0.11.3",
"yuidocjs": "^0.10.2",
"zlib": "1.0.5"
Expand Down Expand Up @@ -117,8 +120,8 @@
"@embroider/macros": "^1.13.4",
"broccoli-funnel": "^3.0.8",
"broccoli-merge-trees": "^4.2.0",
"@glimmer/validator": "^0.84.3",
"ember-cli-babel": "^8.1.0",
"@glimmer/validator": "^0.89.0",
"ember-cli-babel": "^8.2.0",
"ember-cli-htmlbars": "^6.3.0",
"ember-cli-typescript": "^5.2.1",
"@ember/string": "3.1.1",
Expand All @@ -139,7 +142,8 @@
},
"patchedDependencies": {
"qunit@2.19.4": "patches/qunit@2.19.4.patch",
"testem@3.11.0": "patches/testem@3.11.0.patch"
"testem@3.11.0": "patches/testem@3.11.0.patch",
"@ember/test-helpers@3.3.0": "patches/@ember__test-helpers@3.3.0.patch"
}
}
}
2 changes: 1 addition & 1 deletion packages/-ember-data/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"ember-auto-import": "^2.7.0",
"ember-cli-babel": "^8.2.0",
"ember-inflector": "^4.0.2",
"typescript": "^5.3.3",
"typescript": "^5.4.2",
"pnpm-sync-dependencies-meta-injected": "0.0.10",
"webpack": "^5.89.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/active-record/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
"ember-inflector": "^4.0.2",
"ember-source": "~5.6.0",
"rollup": "^4.9.6",
"typescript": "^5.3.3",
"typescript": "^5.4.2",
"walk-sync": "^3.0.0"
},
"ember": {
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
"ember-inflector": "^4.0.2",
"ember-source": "~5.6.0",
"rollup": "^4.9.6",
"typescript": "^5.3.3",
"typescript": "^5.4.2",
"walk-sync": "^3.0.0",
"webpack": "^5.89.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/core-types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"@warp-drive/internal-config": "workspace:5.4.0-alpha.39",
"ember-source": "~5.6.0",
"rollup": "^4.9.6",
"typescript": "^5.3.3",
"typescript": "^5.4.2",
"walk-sync": "^3.0.0",
"webpack": "^5.89.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/diagnostic/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
base.rules(),
imports.rules(),
isolation.rules({
allowedImports: ['@ember/debug', '@ember/test-helpers'],
allowedImports: ['@ember/debug', '@ember/test-helpers', '@glimmer/manager', '@ember/runloop'],
}),
{}
),
Expand Down
2 changes: 1 addition & 1 deletion packages/diagnostic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ module('My Module', function(hooks) {
1. Add the following peer-deps to your app:

```diff
+ "@ember/test-helpers": ">= 3.2.0",
+ "@ember/test-helpers": ">= 3.3.0",
+ "ember-cli-test-loader": ">= 3.1.0",
+ "@embroider/addon-shim": ">= 1.8.6"
```
Expand Down
13 changes: 9 additions & 4 deletions packages/diagnostic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@
"_syncPnpm": "bun run sync-dependencies-meta-injected"
},
"peerDependencies": {
"@ember/test-helpers": ">= 3.2.1",
"@ember/test-helpers": ">= 3.3.0",
"@embroider/addon-shim": ">= 1.8.7",
"ember-cli-test-loader": ">= 3.1.0"
"ember-cli-test-loader": ">= 3.1.0",
"ember-source": ">= 4.12.0"
},
"peerDependenciesMeta": {
"@ember/test-helpers": {
Expand All @@ -86,12 +87,16 @@
},
"@embroider/addon-shim": {
"optional": true
},
"ember-source": {
"optional": true
}
},
"dependencies": {
"chalk": "^5.3.0",
"debug": "^4.3.4",
"pnpm-sync-dependencies-meta-injected": "0.0.10",
"ember-cli-htmlbars": "^6.3.0",
"tmp": "^0.2.1"
},
"devDependencies": {
Expand All @@ -107,12 +112,12 @@
"@rollup/plugin-node-resolve": "^15.2.3",
"@warp-drive/internal-config": "workspace:5.4.0-alpha.39",
"bun-types": "^1.0.25",
"@ember/test-helpers": "^3.2.1",
"@ember/test-helpers": "^3.3.0",
"ember-source": "~5.6.0",
"@glimmer/component": "^1.1.2",
"ember-cli-test-loader": "^3.1.0",
"rollup": "^4.9.6",
"typescript": "^5.3.3",
"typescript": "^5.4.2",
"walk-sync": "^3.0.0"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion packages/diagnostic/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default {
// You can augment this if you need to.
output: addon.output(),

external: external(['@ember/test-helpers', 'ember-cli-test-loader/test-support/index']),
external: external(['@ember/runloop', '@ember/test-helpers', 'ember-cli-test-loader/test-support/index']),

plugins: [
// These are the modules that users should be able to import from your
Expand Down
116 changes: 116 additions & 0 deletions packages/diagnostic/src/-define.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import type { ModuleCallback, ModuleInfo, OrderedMap, TestCallback, TestContext, TestInfo } from './-types';
import { assert, generateHash } from './-utils';
import { Config, getCurrentModule, HooksDelegate, setCurrentModule } from './internals/config';

export { registerReporter } from './internals/delegating-reporter';
export { setupGlobalHooks, configure } from './internals/config';
export { PublicTestInfo } from './internals/run';

export const Modules: OrderedMap<ModuleInfo<TestContext>> = {
byName: new Map(),
byOrder: [],
};

export type { Diagnostic, Hooks as NestedHooks, GlobalHooks, TestContext } from './-types';

export function module<TC extends TestContext = TestContext>(name: string, cb: ModuleCallback<TC>): void {
const parentModule = getCurrentModule<TC>() ?? null;
let moduleName = name;
if (parentModule) {
moduleName = `${parentModule.name} > ${name}`;
} else {
Config.totals.primaryModules++;
}
Config.totals.modules++;

assert(`Cannot add the same module name twice: ${moduleName}`, !Modules.byName.has(moduleName));
const moduleConfig: ModuleInfo<TC>['config'] = {
beforeEach: [],
afterEach: [],
beforeModule: [],
afterModule: [],
};
const tests: OrderedMap<TestInfo<TC>> = { byName: new Map(), byOrder: [] };
const modules: OrderedMap<ModuleInfo<TC>> = { byName: new Map(), byOrder: [] };
const moduleInfo = {
moduleName,
name,
cb,
config: moduleConfig,
tests,
modules,
parent: parentModule,
};

setCurrentModule(moduleInfo);

if (parentModule) {
parentModule.modules.byName.set(name, moduleInfo);
parentModule.modules.byOrder.push(moduleInfo);
} else {
// @ts-expect-error TS poorly handles subtype constraints
Modules.byName.set(name, moduleInfo);
// @ts-expect-error TS poorly handles subtype constraints
Modules.byOrder.push(moduleInfo);
}

cb(HooksDelegate);
setCurrentModule(parentModule as unknown as ModuleInfo<TC>);
}

export function test<TC extends TestContext = TestContext>(name: string, cb: TestCallback<TC>): void {
const currentModule = getCurrentModule<TC>();
assert(`Cannot add a test outside of a module`, !!currentModule);
assert(`Cannot add the same test name twice: ${name}`, !currentModule.tests.byName.has(name));
Config.totals.tests++;

const testInfo = {
id: generateHash(currentModule.moduleName + ' > ' + name),
name,
cb,
skip: false,
todo: false,
module: currentModule,
};

currentModule.tests.byName.set(name, testInfo);
currentModule.tests.byOrder.push(testInfo);
}

export function todo<TC extends TestContext = TestContext>(name: string, cb: TestCallback<TC>): void {
const currentModule = getCurrentModule<TC>();
assert(`Cannot add a test outside of a module`, !!currentModule);
assert(`Cannot add the same test name twice: ${name}`, !currentModule.tests.byName.has(name));
Config.totals.todo++;

const testInfo = {
id: generateHash(currentModule.moduleName + ' > ' + name),
name,
cb,
skip: false,
todo: true,
module: currentModule,
};

currentModule.tests.byName.set(name, testInfo);
currentModule.tests.byOrder.push(testInfo);
}

export function skip<TC extends TestContext = TestContext>(name: string, cb: TestCallback<TC>): void {
const currentModule = getCurrentModule<TC>();
assert(`Cannot add a test outside of a module`, !!currentModule);
assert(`Cannot add the same test name twice: ${name}`, !currentModule.tests.byName.has(name));
Config.totals.skipped++;

const testInfo = {
id: generateHash(currentModule.moduleName + ' > ' + name),
name,
cb,
skip: true,
todo: false,
module: currentModule,
};

currentModule.tests.byName.set(name, testInfo);
currentModule.tests.byOrder.push(testInfo);
}
19 changes: 19 additions & 0 deletions packages/diagnostic/src/-ember/is-component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// @ts-expect-error: types for this API is not consistently available (via transitive
// deps) and we do not currently want to make it an explicit dependency. It
// does, however, consistently work at runtime. :sigh:
import { getInternalComponentManager as getComponentManager } from '@glimmer/manager';

export type ComponentLike = object;

/**
* We should ultimately get a new API from @glimmer/runtime that provides this functionality
* (see https://github.com/emberjs/rfcs/pull/785 for more info).
* @private
* @param {Object} maybeComponent The thing you think might be a component
* @returns {boolean} True if it's a component, false if not
*/
function isComponent(maybeComponent: object): maybeComponent is ComponentLike {
return !!getComponentManager(maybeComponent, true);
}

export default isComponent;
Loading

0 comments on commit 42f1a68

Please sign in to comment.