@forgeax/engine-plugin 0.1.21 → 0.1.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +94 -10
- package/dist/__tests__/composition-contract.test-d.d.ts +2 -0
- package/dist/__tests__/composition-contract.test-d.d.ts.map +1 -0
- package/dist/__tests__/composition.integration.test.d.ts +2 -0
- package/dist/__tests__/composition.integration.test.d.ts.map +1 -0
- package/dist/__tests__/public-api.test-d.d.ts +2 -0
- package/dist/__tests__/public-api.test-d.d.ts.map +1 -0
- package/dist/__tests__/realm-loader.integration.test.d.ts +2 -0
- package/dist/__tests__/realm-loader.integration.test.d.ts.map +1 -0
- package/dist/browser.d.ts +2 -0
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.mjs +548 -1
- package/dist/browser.mjs.map +1 -1
- package/dist/composition.d.ts +73 -0
- package/dist/composition.d.ts.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +560 -8
- package/dist/index.mjs.map +1 -1
- package/dist/inspection.d.ts +26 -0
- package/dist/inspection.d.ts.map +1 -0
- package/dist/loader.d.ts +51 -3
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.mjs +12 -7
- package/dist/loader.mjs.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/browser-entry.test.ts +1 -0
- package/src/__tests__/composition-contract.test-d.ts +74 -0
- package/src/__tests__/composition.integration.test.ts +1347 -0
- package/src/__tests__/public-api.test-d.ts +70 -0
- package/src/__tests__/realm-loader.integration.test.ts +56 -0
- package/src/browser.ts +18 -0
- package/src/composition.ts +642 -0
- package/src/index.ts +18 -0
- package/src/inspection.ts +160 -0
- package/src/loader.ts +82 -13
- package/dist/.tsbuildinfo +0 -1
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { Context, Fiber, Plugin } from '@deepseek-ai/cordis';
|
|
2
|
+
import { expectTypeOf, it } from 'vitest';
|
|
3
|
+
import type { CatalogLoaderError } from '../index.js';
|
|
4
|
+
import { definePluginGroup, usePlugin } from '../index.js';
|
|
5
|
+
|
|
6
|
+
interface MovementConfig {
|
|
7
|
+
readonly speed: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const movement: Plugin.Function<MovementConfig> = (_ctx: Context, _config: MovementConfig) => {};
|
|
11
|
+
const camera: Plugin = { name: 'camera', apply: () => undefined };
|
|
12
|
+
|
|
13
|
+
const movementChild = usePlugin(movement, { speed: 6 });
|
|
14
|
+
const game = definePluginGroup({
|
|
15
|
+
name: 'game',
|
|
16
|
+
children: () => [movementChild, usePlugin(camera)],
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
expectTypeOf(game).toMatchTypeOf<Plugin>();
|
|
20
|
+
expectTypeOf(game).not.toMatchTypeOf<Fiber>();
|
|
21
|
+
|
|
22
|
+
// @ts-expect-error usePlugin must reject config values outside Plugin.Config.
|
|
23
|
+
usePlugin(movement, { speed: 'fast' });
|
|
24
|
+
|
|
25
|
+
// @ts-expect-error a required Plugin.Config cannot be omitted.
|
|
26
|
+
usePlugin(movement);
|
|
27
|
+
|
|
28
|
+
// @ts-expect-error excess config fields are rejected before activation.
|
|
29
|
+
usePlugin(movement, { speed: 6, unexpected: true });
|
|
30
|
+
|
|
31
|
+
usePlugin(movement, { speed: 1 }, { key: 'wave-one' });
|
|
32
|
+
usePlugin(movement, { speed: 2 }, { key: 'wave-two' });
|
|
33
|
+
|
|
34
|
+
function describeCatalogLoaderError(error: CatalogLoaderError): string {
|
|
35
|
+
switch (error.code) {
|
|
36
|
+
case 'plugin-catalog-missing':
|
|
37
|
+
expectTypeOf(error.detail.name).toBeString();
|
|
38
|
+
// @ts-expect-error a missing-catalog detail cannot expose realm-mismatch fields.
|
|
39
|
+
error.detail.actual;
|
|
40
|
+
return `${error.expected}:${error.hint}:${error.detail.name}`;
|
|
41
|
+
case 'plugin-realm-mismatch':
|
|
42
|
+
expectTypeOf(error.detail.name).toBeString();
|
|
43
|
+
expectTypeOf(error.detail.actual).toBeString();
|
|
44
|
+
expectTypeOf(error.detail.expected).toBeString();
|
|
45
|
+
// @ts-expect-error a realm mismatch detail cannot expose group ownership fields.
|
|
46
|
+
error.detail.group;
|
|
47
|
+
return `${error.expected}:${error.hint}:${error.detail.name}:${error.detail.actual}`;
|
|
48
|
+
case 'plugin-entry-realm-mixed':
|
|
49
|
+
expectTypeOf(error.detail.group).toBeString();
|
|
50
|
+
expectTypeOf(error.detail.actual).toBeString();
|
|
51
|
+
expectTypeOf(error.detail.expected).toBeString();
|
|
52
|
+
// @ts-expect-error a mixed-realm detail cannot expose a catalog module name.
|
|
53
|
+
error.detail.name;
|
|
54
|
+
return `${error.expected}:${error.hint}:${error.detail.group}`;
|
|
55
|
+
case 'plugin-realm-unsupported':
|
|
56
|
+
expectTypeOf(error.detail.realm).toBeString();
|
|
57
|
+
expectTypeOf(error.detail.supportedRealms).toMatchTypeOf<readonly string[]>();
|
|
58
|
+
// @ts-expect-error an unsupported-realm detail cannot expose a module name.
|
|
59
|
+
error.detail.name;
|
|
60
|
+
return `${error.expected}:${error.hint}:${error.detail.realm}`;
|
|
61
|
+
case 'plugin-catalog-digest-mismatch':
|
|
62
|
+
expectTypeOf(error.detail.actual).toBeString();
|
|
63
|
+
expectTypeOf(error.detail.expected).toBeString();
|
|
64
|
+
// @ts-expect-error a digest detail cannot expose group ownership fields.
|
|
65
|
+
error.detail.group;
|
|
66
|
+
return `${error.expected}:${error.hint}:${error.detail.actual}`;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
it('exposes a native Plugin group and typed child declarations', () => {
|
|
71
|
+
expectTypeOf(movementChild).toMatchTypeOf<unknown>();
|
|
72
|
+
expectTypeOf(game).toMatchTypeOf<Plugin>();
|
|
73
|
+
expectTypeOf(describeCatalogLoaderError).toBeFunction();
|
|
74
|
+
});
|