@autometa/app 0.2.4 → 0.3.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @autometa/app
2
2
 
3
+ ## 0.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 6c4bb8d: fix: getApp function not defined
8
+
9
+ ## 0.3.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 98d911f: feat: replace tsyringe with custom DI solution
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies [98d911f]
18
+ - @autometa/injection@0.1.0
19
+
3
20
  ## 0.2.4
4
21
 
5
22
  ### Patch Changes
package/dist/esm/index.js CHANGED
@@ -1,109 +1,36 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __decorateClass = (decorators, target, key, kind) => {
4
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
5
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
6
- if (decorator = decorators[i])
7
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8
- if (kind && result)
9
- __defProp(target, key, result);
10
- return result;
11
- };
12
-
13
1
  // src/autometa-app.ts
14
2
  var AutometaApp = class {
15
3
  };
16
4
 
17
5
  // src/autometa-world.ts
18
- import { PhraseParser } from "@autometa/phrases";
19
6
  var AutometaWorld = class {
20
7
  };
21
- AutometaWorld = __decorateClass([
22
- PhraseParser
23
- ], AutometaWorld);
24
8
 
25
9
  // src/get-app.ts
26
- import { container } from "tsyringe";
27
- import { AutomationError } from "@autometa/errors";
28
10
  import { v4 } from "uuid";
29
- import { ErrorCatcherProxy } from "@autometa/fixture-proxies";
30
- function getApp(appType, worldType, ...instances) {
31
- if (!appType) {
32
- throw new AutomationError(`A reference to an 'app' and 'world' is required to run tests.
33
-
34
- Configure the app by extending 'AutometaApp' and adding it to your
35
- 'autometa.config.ts' file:
36
-
37
- @AppType(MyWorld)
38
- export class MyAutometaApp extends AutometaApp {
39
- ...
40
- }
41
- defineConfig({
42
- roots: {
43
- app: './src/app'
44
- }
45
- })`);
46
- }
47
- instances.forEach(({ token, instance, cls }) => {
48
- const proxiedCls = cls ? ErrorCatcherProxy(cls) : void 0;
49
- const proxiedInst = instance ? ErrorCatcherProxy(instance) : void 0;
50
- return child.register(token, proxiedInst ?? proxiedCls);
51
- });
52
- const child = container.createChildContainer();
53
- const app = ErrorCatcherProxy(child.resolve(appType));
54
- app.world = child.resolve(worldType);
55
- app.id = v4();
56
- return app;
11
+ import { Container, defineContainerContext } from "@autometa/injection";
12
+ function getApp(appType, containerName = v4()) {
13
+ const context = defineContainerContext(containerName);
14
+ const container = new Container(context);
15
+ return container.get(appType);
57
16
  }
58
17
 
59
- // src/decorators/fixture.ts
60
- import "reflect-metadata";
61
- import {
62
- scoped,
63
- inject,
64
- Lifecycle as LC,
65
- injectable,
66
- singleton
67
- } from "tsyringe";
68
- function Fixture(arg) {
69
- if (arg !== void 0 && typeof arg !== "number") {
70
- injectable()(arg);
71
- scoped(LC.ContainerScoped)(arg);
72
- return;
73
- }
74
- return (target) => {
75
- injectable()(target);
76
- if (arg === LIFE_CYCLE.Singleton) {
77
- singleton()(target);
78
- return;
79
- }
80
- scoped(arg ?? LIFE_CYCLE.ContainerScoped)(target);
81
- };
82
- }
83
- var Inject = inject;
84
- var LIFE_CYCLE = {
85
- Transient: LC.Transient,
86
- Singleton: LC.Singleton,
87
- ResolutionScoped: LC.ResolutionScoped,
88
- ContainerScoped: LC.ContainerScoped
89
- };
90
-
91
18
  // src/decorators/app-type.ts
92
- import { Lifecycle } from "tsyringe";
93
- function AppType(container2, world, environment = "default") {
19
+ import { metadata } from "@autometa/injection";
20
+ function AppType(container, world, environment = "default") {
94
21
  const env = environment ?? "default";
95
22
  return (target) => {
96
- Fixture(Lifecycle.ContainerScoped)(target);
97
- container2[env] = { app: target, world };
23
+ metadata(target.prototype).set({
24
+ key: "world",
25
+ class: world
26
+ });
27
+ container[env] = { app: target, world };
98
28
  };
99
29
  }
100
30
  export {
101
31
  AppType,
102
32
  AutometaApp,
103
33
  AutometaWorld,
104
- Fixture,
105
- Inject,
106
- LIFE_CYCLE,
107
34
  getApp
108
35
  };
109
36
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/autometa-app.ts","../../src/autometa-world.ts","../../src/get-app.ts","../../src/decorators/fixture.ts","../../src/decorators/app-type.ts"],"sourcesContent":["import { World } from \"./fixtures.typings\";\n\nexport abstract class AutometaApp {\n id: string;\n [key: string]: unknown;\n world: World\n}\n","import { PhraseParser } from \"@autometa/phrases\";\n\n@PhraseParser\nexport class AutometaWorld {\n [key: string]: unknown;\n}\n","import { container } from \"tsyringe\";\nimport { AutometaApp } from \"./autometa-app\";\nimport { Class } from \"@autometa/types\";\nimport { AutomationError } from \"@autometa/errors\";\nimport { AutometaWorld } from \".\";\nimport { v4 } from \"uuid\";\nimport { ErrorCatcherProxy } from \"@autometa/fixture-proxies\";\nexport function getApp<T extends AutometaApp, K extends AutometaWorld>(\n appType: Class<T>,\n worldType: Class<K>,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ...instances: { token: any; instance?: any; cls?: Class<any> }[]\n) {\n if (!appType) {\n throw new AutomationError(`A reference to an 'app' and 'world' is required to run tests.\n\nConfigure the app by extending 'AutometaApp' and adding it to your\n'autometa.config.ts' file:\n\n@AppType(MyWorld)\nexport class MyAutometaApp extends AutometaApp {\n ...\n}\ndefineConfig({\n roots: {\n app: './src/app'\n }\n})`);\n }\n instances.forEach(({ token, instance, cls }) => {\n const proxiedCls = cls ? ErrorCatcherProxy(cls) : undefined;\n const proxiedInst = instance ? ErrorCatcherProxy(instance) : undefined;\n return child.register(token, proxiedInst ?? proxiedCls);\n });\n\n const child = container.createChildContainer();\n const app = ErrorCatcherProxy(child.resolve(appType));\n app.world = child.resolve(worldType);\n app.id = v4();\n return app;\n}\n","import \"reflect-metadata\";\n\nimport { Class } from \"@autometa/types\";\nimport {\n scoped,\n inject,\n Lifecycle as LC,\n injectable,\n singleton\n} from \"tsyringe\";\n/**\n * Marks a class as an injectable fixture. Constructor parameters\n * which are also injectable will be automatically constructed\n * and passed to the constructor.\n *\n * Example fixtures are the `App` which acts as shared\n * entry point for all steps in a test, and the World,\n * which stores persistent data across tests.\n *\n * Fixtures are persistent by default, meaning each class\n * will exist as a singleton for the duration of the test\n * ```ts\n * @Fixture\n * export class World {\n * [key: string]: unknown;\n *\n * declare someExpectedData: MyDataType\n * }\n *\n * @Fixture\n * export class MyClient {\n * constructor(world: MyWorld){}\n *\n * login = async ()=>{\n * this.world.someExpectedData = await fetch(...)\n * }\n * }\n *\n * @Fixture\n * export class App {\n * constructor(\n * world: MyWorld,\n * client: MyClient\n * ){}\n * }\n * ```\n */\nexport function Fixture(target: Class<unknown>): void;\nexport function Fixture<T extends Class<unknown>>(\n scope?: Lifecycle\n): (target: T) => void;\nexport function Fixture(arg: Lifecycle | undefined | Class<unknown>) {\n if (arg !== undefined && typeof arg !== \"number\") {\n injectable()(arg);\n scoped(LC.ContainerScoped)(arg);\n return;\n }\n return (target: Class<unknown>) => {\n injectable()(target);\n if (arg === LIFE_CYCLE.Singleton) {\n singleton()(target);\n return;\n }\n scoped(arg ?? (LIFE_CYCLE.ContainerScoped as number))(target);\n };\n}\n\nexport const Inject = inject;\n\nexport const LIFE_CYCLE = {\n Transient: LC.Transient as 0,\n Singleton: LC.Singleton as 1,\n ResolutionScoped: LC.ResolutionScoped as 2,\n ContainerScoped: LC.ContainerScoped as 3\n} as const;\n\nexport type Lifecycle = (typeof LIFE_CYCLE)[keyof typeof LIFE_CYCLE];\n","import { Class } from \"@autometa/types\";\nimport { Lifecycle } from \"tsyringe\";\nimport { AutometaWorld } from \"..\";\nimport { Fixture } from \"./fixture\";\n\n\nexport function AppType(\n container: Record<string, { app: unknown; world: unknown; }>,\n world: Class<AutometaWorld>,\n environment = \"default\"\n) {\n const env = environment ?? \"default\";\n return (target: Class<unknown>) => {\n Fixture(Lifecycle.ContainerScoped)(target);\n container[env] = { app: target, world };\n };\n}\n"],"mappings":";;;;;;;;;;;;;AAEO,IAAe,cAAf,MAA2B;AAIlC;;;ACNA,SAAS,oBAAoB;AAGtB,IAAM,gBAAN,MAAoB;AAE3B;AAFa,gBAAN;AAAA,EADN;AAAA,GACY;;;ACHb,SAAS,iBAAiB;AAG1B,SAAS,uBAAuB;AAEhC,SAAS,UAAU;AACnB,SAAS,yBAAyB;AAC3B,SAAS,OACd,SACA,cAEG,WACH;AACA,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,gBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAa3B;AAAA,EACD;AACA,YAAU,QAAQ,CAAC,EAAE,OAAO,UAAU,IAAI,MAAM;AAC9C,UAAM,aAAa,MAAM,kBAAkB,GAAG,IAAI;AAClD,UAAM,cAAc,WAAW,kBAAkB,QAAQ,IAAI;AAC7D,WAAO,MAAM,SAAS,OAAO,eAAe,UAAU;AAAA,EACxD,CAAC;AAED,QAAM,QAAQ,UAAU,qBAAqB;AAC7C,QAAM,MAAM,kBAAkB,MAAM,QAAQ,OAAO,CAAC;AACpD,MAAI,QAAQ,MAAM,QAAQ,SAAS;AACnC,MAAI,KAAK,GAAG;AACZ,SAAO;AACT;;;ACxCA,OAAO;AAGP;AAAA,EACE;AAAA,EACA;AAAA,EACA,aAAa;AAAA,EACb;AAAA,EACA;AAAA,OACK;AA0CA,SAAS,QAAQ,KAA6C;AACnE,MAAI,QAAQ,UAAa,OAAO,QAAQ,UAAU;AAChD,eAAW,EAAE,GAAG;AAChB,WAAO,GAAG,eAAe,EAAE,GAAG;AAC9B;AAAA,EACF;AACA,SAAO,CAAC,WAA2B;AACjC,eAAW,EAAE,MAAM;AACnB,QAAI,QAAQ,WAAW,WAAW;AAChC,gBAAU,EAAE,MAAM;AAClB;AAAA,IACF;AACA,WAAO,OAAQ,WAAW,eAA0B,EAAE,MAAM;AAAA,EAC9D;AACF;AAEO,IAAM,SAAS;AAEf,IAAM,aAAa;AAAA,EACxB,WAAW,GAAG;AAAA,EACd,WAAW,GAAG;AAAA,EACd,kBAAkB,GAAG;AAAA,EACrB,iBAAiB,GAAG;AACtB;;;ACzEA,SAAS,iBAAiB;AAKnB,SAAS,QACdA,YACA,OACA,cAAc,WACd;AACA,QAAM,MAAM,eAAe;AAC3B,SAAO,CAAC,WAA2B;AACjC,YAAQ,UAAU,eAAe,EAAE,MAAM;AACzC,IAAAA,WAAU,GAAG,IAAI,EAAE,KAAK,QAAQ,MAAM;AAAA,EACxC;AACF;","names":["container"]}
1
+ {"version":3,"sources":["../../src/autometa-app.ts","../../src/autometa-world.ts","../../src/get-app.ts","../../src/decorators/app-type.ts"],"sourcesContent":["import { World } from \"./fixtures.typings\";\nexport abstract class AutometaApp {\n id: string;\n [key: string]: unknown;\n world: World;\n}\n","export class AutometaWorld {}\n","import { AutometaApp } from \"./autometa-app\";\nimport { Class } from \"@autometa/types\";\nimport { v4 } from \"uuid\";\nimport { Container, defineContainerContext } from \"@autometa/injection\";\nimport { App } from \"./fixtures.typings\";\nexport function getApp<T extends AutometaApp>(\n appType: Class<T>,\n containerName = v4()\n): App {\n const context = defineContainerContext(containerName);\n const container = new Container(context);\n return container.get(appType);\n}\n","import { Class } from \"@autometa/types\";\nimport { App, World, AutometaWorld } from \"..\";\nimport { metadata } from \"@autometa/injection\";\nexport function AppType(\n container: Record<string, { app: Class<App>; world: Class<World> }>,\n world: Class<AutometaWorld>,\n environment = \"default\"\n) {\n const env = environment ?? \"default\";\n return (target: Class<unknown>) => {\n metadata(target.prototype).set({\n key: \"world\",\n class: world\n });\n container[env] = { app: target as Class<App>, world: world as Class<World> };\n };\n}\n"],"mappings":";AACO,IAAe,cAAf,MAA2B;AAIlC;;;ACLO,IAAM,gBAAN,MAAoB;AAAC;;;ACE5B,SAAS,UAAU;AACnB,SAAS,WAAW,8BAA8B;AAE3C,SAAS,OACd,SACA,gBAAgB,GAAG,GACd;AACL,QAAM,UAAU,uBAAuB,aAAa;AACpD,QAAM,YAAY,IAAI,UAAU,OAAO;AACvC,SAAO,UAAU,IAAI,OAAO;AAC9B;;;ACVA,SAAS,gBAAgB;AAClB,SAAS,QACd,WACA,OACA,cAAc,WACd;AACA,QAAM,MAAM,eAAe;AAC3B,SAAO,CAAC,WAA2B;AACjC,aAAS,OAAO,SAAS,EAAE,IAAI;AAAA,MAC7B,KAAK;AAAA,MACL,OAAO;AAAA,IACT,CAAC;AACD,cAAU,GAAG,IAAI,EAAE,KAAK,QAAsB,MAA6B;AAAA,EAC7E;AACF;","names":[]}
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
+ import { Container } from '@autometa/injection';
1
2
  import { Class } from '@autometa/types';
2
- import { inject } from 'tsyringe';
3
3
 
4
4
  /**
5
5
  * Basic Key Value store for managing state across Step Definitions. A unique copy of this object
@@ -87,8 +87,8 @@ interface World {
87
87
  * ```
88
88
  */
89
89
  interface App {
90
- readonly id: string;
91
90
  world: World;
91
+ di: Container;
92
92
  }
93
93
 
94
94
  declare abstract class AutometaApp {
@@ -98,66 +98,13 @@ declare abstract class AutometaApp {
98
98
  }
99
99
 
100
100
  declare class AutometaWorld {
101
- [key: string]: unknown;
102
101
  }
103
102
 
104
- declare function getApp<T extends AutometaApp, K extends AutometaWorld>(appType: Class<T>, worldType: Class<K>, ...instances: {
105
- token: any;
106
- instance?: any;
107
- cls?: Class<any>;
108
- }[]): T;
109
-
110
- /**
111
- * Marks a class as an injectable fixture. Constructor parameters
112
- * which are also injectable will be automatically constructed
113
- * and passed to the constructor.
114
- *
115
- * Example fixtures are the `App` which acts as shared
116
- * entry point for all steps in a test, and the World,
117
- * which stores persistent data across tests.
118
- *
119
- * Fixtures are persistent by default, meaning each class
120
- * will exist as a singleton for the duration of the test
121
- * ```ts
122
- * @Fixture
123
- * export class World {
124
- * [key: string]: unknown;
125
- *
126
- * declare someExpectedData: MyDataType
127
- * }
128
- *
129
- * @Fixture
130
- * export class MyClient {
131
- * constructor(world: MyWorld){}
132
- *
133
- * login = async ()=>{
134
- * this.world.someExpectedData = await fetch(...)
135
- * }
136
- * }
137
- *
138
- * @Fixture
139
- * export class App {
140
- * constructor(
141
- * world: MyWorld,
142
- * client: MyClient
143
- * ){}
144
- * }
145
- * ```
146
- */
147
- declare function Fixture(target: Class<unknown>): void;
148
- declare function Fixture<T extends Class<unknown>>(scope?: Lifecycle): (target: T) => void;
149
- declare const Inject: typeof inject;
150
- declare const LIFE_CYCLE: {
151
- readonly Transient: 0;
152
- readonly Singleton: 1;
153
- readonly ResolutionScoped: 2;
154
- readonly ContainerScoped: 3;
155
- };
156
- type Lifecycle = (typeof LIFE_CYCLE)[keyof typeof LIFE_CYCLE];
103
+ declare function getApp<T extends AutometaApp>(appType: Class<T>, containerName?: string): App;
157
104
 
158
105
  declare function AppType(container: Record<string, {
159
- app: unknown;
160
- world: unknown;
106
+ app: Class<App>;
107
+ world: Class<World>;
161
108
  }>, world: Class<AutometaWorld>, environment?: string): (target: Class<unknown>) => void;
162
109
 
163
- export { App, AppType, AutometaApp, AutometaWorld, Fixture, Inject, LIFE_CYCLE, Lifecycle, World, getApp };
110
+ export { App, AppType, AutometaApp, AutometaWorld, World, getApp };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
+ import { Container } from '@autometa/injection';
1
2
  import { Class } from '@autometa/types';
2
- import { inject } from 'tsyringe';
3
3
 
4
4
  /**
5
5
  * Basic Key Value store for managing state across Step Definitions. A unique copy of this object
@@ -87,8 +87,8 @@ interface World {
87
87
  * ```
88
88
  */
89
89
  interface App {
90
- readonly id: string;
91
90
  world: World;
91
+ di: Container;
92
92
  }
93
93
 
94
94
  declare abstract class AutometaApp {
@@ -98,66 +98,13 @@ declare abstract class AutometaApp {
98
98
  }
99
99
 
100
100
  declare class AutometaWorld {
101
- [key: string]: unknown;
102
101
  }
103
102
 
104
- declare function getApp<T extends AutometaApp, K extends AutometaWorld>(appType: Class<T>, worldType: Class<K>, ...instances: {
105
- token: any;
106
- instance?: any;
107
- cls?: Class<any>;
108
- }[]): T;
109
-
110
- /**
111
- * Marks a class as an injectable fixture. Constructor parameters
112
- * which are also injectable will be automatically constructed
113
- * and passed to the constructor.
114
- *
115
- * Example fixtures are the `App` which acts as shared
116
- * entry point for all steps in a test, and the World,
117
- * which stores persistent data across tests.
118
- *
119
- * Fixtures are persistent by default, meaning each class
120
- * will exist as a singleton for the duration of the test
121
- * ```ts
122
- * @Fixture
123
- * export class World {
124
- * [key: string]: unknown;
125
- *
126
- * declare someExpectedData: MyDataType
127
- * }
128
- *
129
- * @Fixture
130
- * export class MyClient {
131
- * constructor(world: MyWorld){}
132
- *
133
- * login = async ()=>{
134
- * this.world.someExpectedData = await fetch(...)
135
- * }
136
- * }
137
- *
138
- * @Fixture
139
- * export class App {
140
- * constructor(
141
- * world: MyWorld,
142
- * client: MyClient
143
- * ){}
144
- * }
145
- * ```
146
- */
147
- declare function Fixture(target: Class<unknown>): void;
148
- declare function Fixture<T extends Class<unknown>>(scope?: Lifecycle): (target: T) => void;
149
- declare const Inject: typeof inject;
150
- declare const LIFE_CYCLE: {
151
- readonly Transient: 0;
152
- readonly Singleton: 1;
153
- readonly ResolutionScoped: 2;
154
- readonly ContainerScoped: 3;
155
- };
156
- type Lifecycle = (typeof LIFE_CYCLE)[keyof typeof LIFE_CYCLE];
103
+ declare function getApp<T extends AutometaApp>(appType: Class<T>, containerName?: string): App;
157
104
 
158
105
  declare function AppType(container: Record<string, {
159
- app: unknown;
160
- world: unknown;
106
+ app: Class<App>;
107
+ world: Class<World>;
161
108
  }>, world: Class<AutometaWorld>, environment?: string): (target: Class<unknown>) => void;
162
109
 
163
- export { App, AppType, AutometaApp, AutometaWorld, Fixture, Inject, LIFE_CYCLE, Lifecycle, World, getApp };
110
+ export { App, AppType, AutometaApp, AutometaWorld, World, getApp };
package/dist/index.js CHANGED
@@ -16,15 +16,6 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var __decorateClass = (decorators, target, key, kind) => {
20
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
21
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
22
- if (decorator = decorators[i])
23
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
24
- if (kind && result)
25
- __defProp(target, key, result);
26
- return result;
27
- };
28
19
 
29
20
  // src/index.ts
30
21
  var src_exports = {};
@@ -32,9 +23,6 @@ __export(src_exports, {
32
23
  AppType: () => AppType,
33
24
  AutometaApp: () => AutometaApp,
34
25
  AutometaWorld: () => AutometaWorld,
35
- Fixture: () => Fixture,
36
- Inject: () => Inject,
37
- LIFE_CYCLE: () => LIFE_CYCLE,
38
26
  getApp: () => getApp
39
27
  });
40
28
  module.exports = __toCommonJS(src_exports);
@@ -44,80 +32,28 @@ var AutometaApp = class {
44
32
  };
45
33
 
46
34
  // src/autometa-world.ts
47
- var import_phrases = require("@autometa/phrases");
48
35
  var AutometaWorld = class {
49
36
  };
50
- AutometaWorld = __decorateClass([
51
- import_phrases.PhraseParser
52
- ], AutometaWorld);
53
37
 
54
38
  // src/get-app.ts
55
- var import_tsyringe = require("tsyringe");
56
- var import_errors = require("@autometa/errors");
57
39
  var import_uuid = require("uuid");
58
- var import_fixture_proxies = require("@autometa/fixture-proxies");
59
- function getApp(appType, worldType, ...instances) {
60
- if (!appType) {
61
- throw new import_errors.AutomationError(`A reference to an 'app' and 'world' is required to run tests.
62
-
63
- Configure the app by extending 'AutometaApp' and adding it to your
64
- 'autometa.config.ts' file:
65
-
66
- @AppType(MyWorld)
67
- export class MyAutometaApp extends AutometaApp {
68
- ...
40
+ var import_injection = require("@autometa/injection");
41
+ function getApp(appType, containerName = (0, import_uuid.v4)()) {
42
+ const context = (0, import_injection.defineContainerContext)(containerName);
43
+ const container = new import_injection.Container(context);
44
+ return container.get(appType);
69
45
  }
70
- defineConfig({
71
- roots: {
72
- app: './src/app'
73
- }
74
- })`);
75
- }
76
- instances.forEach(({ token, instance, cls }) => {
77
- const proxiedCls = cls ? (0, import_fixture_proxies.ErrorCatcherProxy)(cls) : void 0;
78
- const proxiedInst = instance ? (0, import_fixture_proxies.ErrorCatcherProxy)(instance) : void 0;
79
- return child.register(token, proxiedInst ?? proxiedCls);
80
- });
81
- const child = import_tsyringe.container.createChildContainer();
82
- const app = (0, import_fixture_proxies.ErrorCatcherProxy)(child.resolve(appType));
83
- app.world = child.resolve(worldType);
84
- app.id = (0, import_uuid.v4)();
85
- return app;
86
- }
87
-
88
- // src/decorators/fixture.ts
89
- var import_reflect_metadata = require("reflect-metadata");
90
- var import_tsyringe2 = require("tsyringe");
91
- function Fixture(arg) {
92
- if (arg !== void 0 && typeof arg !== "number") {
93
- (0, import_tsyringe2.injectable)()(arg);
94
- (0, import_tsyringe2.scoped)(import_tsyringe2.Lifecycle.ContainerScoped)(arg);
95
- return;
96
- }
97
- return (target) => {
98
- (0, import_tsyringe2.injectable)()(target);
99
- if (arg === LIFE_CYCLE.Singleton) {
100
- (0, import_tsyringe2.singleton)()(target);
101
- return;
102
- }
103
- (0, import_tsyringe2.scoped)(arg ?? LIFE_CYCLE.ContainerScoped)(target);
104
- };
105
- }
106
- var Inject = import_tsyringe2.inject;
107
- var LIFE_CYCLE = {
108
- Transient: import_tsyringe2.Lifecycle.Transient,
109
- Singleton: import_tsyringe2.Lifecycle.Singleton,
110
- ResolutionScoped: import_tsyringe2.Lifecycle.ResolutionScoped,
111
- ContainerScoped: import_tsyringe2.Lifecycle.ContainerScoped
112
- };
113
46
 
114
47
  // src/decorators/app-type.ts
115
- var import_tsyringe3 = require("tsyringe");
116
- function AppType(container2, world, environment = "default") {
48
+ var import_injection2 = require("@autometa/injection");
49
+ function AppType(container, world, environment = "default") {
117
50
  const env = environment ?? "default";
118
51
  return (target) => {
119
- Fixture(import_tsyringe3.Lifecycle.ContainerScoped)(target);
120
- container2[env] = { app: target, world };
52
+ (0, import_injection2.metadata)(target.prototype).set({
53
+ key: "world",
54
+ class: world
55
+ });
56
+ container[env] = { app: target, world };
121
57
  };
122
58
  }
123
59
  // Annotate the CommonJS export names for ESM import in node:
@@ -125,9 +61,6 @@ function AppType(container2, world, environment = "default") {
125
61
  AppType,
126
62
  AutometaApp,
127
63
  AutometaWorld,
128
- Fixture,
129
- Inject,
130
- LIFE_CYCLE,
131
64
  getApp
132
65
  });
133
66
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/autometa-app.ts","../src/autometa-world.ts","../src/get-app.ts","../src/decorators/fixture.ts","../src/decorators/app-type.ts"],"sourcesContent":["export * from './autometa-app'\nexport * from './autometa-world'\nexport * from './get-app'\nexport * from './decorators'\nexport * from './fixtures.typings'","import { World } from \"./fixtures.typings\";\n\nexport abstract class AutometaApp {\n id: string;\n [key: string]: unknown;\n world: World\n}\n","import { PhraseParser } from \"@autometa/phrases\";\n\n@PhraseParser\nexport class AutometaWorld {\n [key: string]: unknown;\n}\n","import { container } from \"tsyringe\";\nimport { AutometaApp } from \"./autometa-app\";\nimport { Class } from \"@autometa/types\";\nimport { AutomationError } from \"@autometa/errors\";\nimport { AutometaWorld } from \".\";\nimport { v4 } from \"uuid\";\nimport { ErrorCatcherProxy } from \"@autometa/fixture-proxies\";\nexport function getApp<T extends AutometaApp, K extends AutometaWorld>(\n appType: Class<T>,\n worldType: Class<K>,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ...instances: { token: any; instance?: any; cls?: Class<any> }[]\n) {\n if (!appType) {\n throw new AutomationError(`A reference to an 'app' and 'world' is required to run tests.\n\nConfigure the app by extending 'AutometaApp' and adding it to your\n'autometa.config.ts' file:\n\n@AppType(MyWorld)\nexport class MyAutometaApp extends AutometaApp {\n ...\n}\ndefineConfig({\n roots: {\n app: './src/app'\n }\n})`);\n }\n instances.forEach(({ token, instance, cls }) => {\n const proxiedCls = cls ? ErrorCatcherProxy(cls) : undefined;\n const proxiedInst = instance ? ErrorCatcherProxy(instance) : undefined;\n return child.register(token, proxiedInst ?? proxiedCls);\n });\n\n const child = container.createChildContainer();\n const app = ErrorCatcherProxy(child.resolve(appType));\n app.world = child.resolve(worldType);\n app.id = v4();\n return app;\n}\n","import \"reflect-metadata\";\n\nimport { Class } from \"@autometa/types\";\nimport {\n scoped,\n inject,\n Lifecycle as LC,\n injectable,\n singleton\n} from \"tsyringe\";\n/**\n * Marks a class as an injectable fixture. Constructor parameters\n * which are also injectable will be automatically constructed\n * and passed to the constructor.\n *\n * Example fixtures are the `App` which acts as shared\n * entry point for all steps in a test, and the World,\n * which stores persistent data across tests.\n *\n * Fixtures are persistent by default, meaning each class\n * will exist as a singleton for the duration of the test\n * ```ts\n * @Fixture\n * export class World {\n * [key: string]: unknown;\n *\n * declare someExpectedData: MyDataType\n * }\n *\n * @Fixture\n * export class MyClient {\n * constructor(world: MyWorld){}\n *\n * login = async ()=>{\n * this.world.someExpectedData = await fetch(...)\n * }\n * }\n *\n * @Fixture\n * export class App {\n * constructor(\n * world: MyWorld,\n * client: MyClient\n * ){}\n * }\n * ```\n */\nexport function Fixture(target: Class<unknown>): void;\nexport function Fixture<T extends Class<unknown>>(\n scope?: Lifecycle\n): (target: T) => void;\nexport function Fixture(arg: Lifecycle | undefined | Class<unknown>) {\n if (arg !== undefined && typeof arg !== \"number\") {\n injectable()(arg);\n scoped(LC.ContainerScoped)(arg);\n return;\n }\n return (target: Class<unknown>) => {\n injectable()(target);\n if (arg === LIFE_CYCLE.Singleton) {\n singleton()(target);\n return;\n }\n scoped(arg ?? (LIFE_CYCLE.ContainerScoped as number))(target);\n };\n}\n\nexport const Inject = inject;\n\nexport const LIFE_CYCLE = {\n Transient: LC.Transient as 0,\n Singleton: LC.Singleton as 1,\n ResolutionScoped: LC.ResolutionScoped as 2,\n ContainerScoped: LC.ContainerScoped as 3\n} as const;\n\nexport type Lifecycle = (typeof LIFE_CYCLE)[keyof typeof LIFE_CYCLE];\n","import { Class } from \"@autometa/types\";\nimport { Lifecycle } from \"tsyringe\";\nimport { AutometaWorld } from \"..\";\nimport { Fixture } from \"./fixture\";\n\n\nexport function AppType(\n container: Record<string, { app: unknown; world: unknown; }>,\n world: Class<AutometaWorld>,\n environment = \"default\"\n) {\n const env = environment ?? \"default\";\n return (target: Class<unknown>) => {\n Fixture(Lifecycle.ContainerScoped)(target);\n container[env] = { app: target, world };\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,IAAe,cAAf,MAA2B;AAIlC;;;ACNA,qBAA6B;AAGtB,IAAM,gBAAN,MAAoB;AAE3B;AAFa,gBAAN;AAAA,EADN;AAAA,GACY;;;ACHb,sBAA0B;AAG1B,oBAAgC;AAEhC,kBAAmB;AACnB,6BAAkC;AAC3B,SAAS,OACd,SACA,cAEG,WACH;AACA,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,8BAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAa3B;AAAA,EACD;AACA,YAAU,QAAQ,CAAC,EAAE,OAAO,UAAU,IAAI,MAAM;AAC9C,UAAM,aAAa,UAAM,0CAAkB,GAAG,IAAI;AAClD,UAAM,cAAc,eAAW,0CAAkB,QAAQ,IAAI;AAC7D,WAAO,MAAM,SAAS,OAAO,eAAe,UAAU;AAAA,EACxD,CAAC;AAED,QAAM,QAAQ,0BAAU,qBAAqB;AAC7C,QAAM,UAAM,0CAAkB,MAAM,QAAQ,OAAO,CAAC;AACpD,MAAI,QAAQ,MAAM,QAAQ,SAAS;AACnC,MAAI,SAAK,gBAAG;AACZ,SAAO;AACT;;;ACxCA,8BAAO;AAGP,IAAAA,mBAMO;AA0CA,SAAS,QAAQ,KAA6C;AACnE,MAAI,QAAQ,UAAa,OAAO,QAAQ,UAAU;AAChD,qCAAW,EAAE,GAAG;AAChB,iCAAO,iBAAAC,UAAG,eAAe,EAAE,GAAG;AAC9B;AAAA,EACF;AACA,SAAO,CAAC,WAA2B;AACjC,qCAAW,EAAE,MAAM;AACnB,QAAI,QAAQ,WAAW,WAAW;AAChC,sCAAU,EAAE,MAAM;AAClB;AAAA,IACF;AACA,iCAAO,OAAQ,WAAW,eAA0B,EAAE,MAAM;AAAA,EAC9D;AACF;AAEO,IAAM,SAAS;AAEf,IAAM,aAAa;AAAA,EACxB,WAAW,iBAAAA,UAAG;AAAA,EACd,WAAW,iBAAAA,UAAG;AAAA,EACd,kBAAkB,iBAAAA,UAAG;AAAA,EACrB,iBAAiB,iBAAAA,UAAG;AACtB;;;ACzEA,IAAAC,mBAA0B;AAKnB,SAAS,QACdC,YACA,OACA,cAAc,WACd;AACA,QAAM,MAAM,eAAe;AAC3B,SAAO,CAAC,WAA2B;AACjC,YAAQ,2BAAU,eAAe,EAAE,MAAM;AACzC,IAAAA,WAAU,GAAG,IAAI,EAAE,KAAK,QAAQ,MAAM;AAAA,EACxC;AACF;","names":["import_tsyringe","LC","import_tsyringe","container"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/autometa-app.ts","../src/autometa-world.ts","../src/get-app.ts","../src/decorators/app-type.ts"],"sourcesContent":["export * from \"./autometa-app\";\nexport * from \"./autometa-world\";\nexport * from \"./get-app\";\nexport * from \"./decorators\";\nexport * from \"./fixtures.typings\";\n","import { World } from \"./fixtures.typings\";\nexport abstract class AutometaApp {\n id: string;\n [key: string]: unknown;\n world: World;\n}\n","export class AutometaWorld {}\n","import { AutometaApp } from \"./autometa-app\";\nimport { Class } from \"@autometa/types\";\nimport { v4 } from \"uuid\";\nimport { Container, defineContainerContext } from \"@autometa/injection\";\nimport { App } from \"./fixtures.typings\";\nexport function getApp<T extends AutometaApp>(\n appType: Class<T>,\n containerName = v4()\n): App {\n const context = defineContainerContext(containerName);\n const container = new Container(context);\n return container.get(appType);\n}\n","import { Class } from \"@autometa/types\";\nimport { App, World, AutometaWorld } from \"..\";\nimport { metadata } from \"@autometa/injection\";\nexport function AppType(\n container: Record<string, { app: Class<App>; world: Class<World> }>,\n world: Class<AutometaWorld>,\n environment = \"default\"\n) {\n const env = environment ?? \"default\";\n return (target: Class<unknown>) => {\n metadata(target.prototype).set({\n key: \"world\",\n class: world\n });\n container[env] = { app: target as Class<App>, world: world as Class<World> };\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCO,IAAe,cAAf,MAA2B;AAIlC;;;ACLO,IAAM,gBAAN,MAAoB;AAAC;;;ACE5B,kBAAmB;AACnB,uBAAkD;AAE3C,SAAS,OACd,SACA,oBAAgB,gBAAG,GACd;AACL,QAAM,cAAU,yCAAuB,aAAa;AACpD,QAAM,YAAY,IAAI,2BAAU,OAAO;AACvC,SAAO,UAAU,IAAI,OAAO;AAC9B;;;ACVA,IAAAA,oBAAyB;AAClB,SAAS,QACd,WACA,OACA,cAAc,WACd;AACA,QAAM,MAAM,eAAe;AAC3B,SAAO,CAAC,WAA2B;AACjC,oCAAS,OAAO,SAAS,EAAE,IAAI;AAAA,MAC7B,KAAK;AAAA,MACL,OAAO;AAAA,IACT,CAAC;AACD,cAAU,GAAG,IAAI,EAAE,KAAK,QAAsB,MAA6B;AAAA,EAC7E;AACF;","names":["import_injection"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autometa/app",
3
- "version": "0.2.4",
3
+ "version": "0.3.1",
4
4
  "description": "App and World container for Autometa",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -51,6 +51,7 @@
51
51
  "@autometa/asserters": "0.1.8",
52
52
  "@autometa/errors": "0.2.2",
53
53
  "@autometa/fixture-proxies": "^0.1.3",
54
+ "@autometa/injection": "^0.1.0",
54
55
  "@autometa/phrases": "0.1.12",
55
56
  "tsyringe": "^4.8.0",
56
57
  "uuid": "^9.0.1"