@autometa/app 0.2.3 → 0.3.0

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,26 @@
1
1
  # @autometa/app
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 98d911f: feat: replace tsyringe with custom DI solution
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [98d911f]
12
+ - @autometa/injection@0.1.0
13
+
14
+ ## 0.2.4
15
+
16
+ ### Patch Changes
17
+
18
+ - Updated dependencies [3fe2ad4]
19
+ - @autometa/errors@0.2.2
20
+ - @autometa/asserters@0.1.8
21
+ - @autometa/fixture-proxies@0.1.3
22
+ - @autometa/phrases@0.1.12
23
+
3
24
  ## 0.2.3
4
25
 
5
26
  ### Patch Changes
package/dist/esm/index.js CHANGED
@@ -1,26 +1,10 @@
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
10
  import { container } from "tsyringe";
@@ -51,49 +35,19 @@ defineConfig({
51
35
  });
52
36
  const child = container.createChildContainer();
53
37
  const app = ErrorCatcherProxy(child.resolve(appType));
54
- app.world = child.resolve(worldType);
55
38
  app.id = v4();
56
39
  return app;
57
40
  }
58
41
 
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
42
  // src/decorators/app-type.ts
92
- import { Lifecycle } from "tsyringe";
43
+ import { metadata } from "@autometa/injection";
93
44
  function AppType(container2, world, environment = "default") {
94
45
  const env = environment ?? "default";
95
46
  return (target) => {
96
- Fixture(Lifecycle.ContainerScoped)(target);
47
+ metadata(target.prototype).set({
48
+ key: "world",
49
+ class: world
50
+ });
97
51
  container2[env] = { app: target, world };
98
52
  };
99
53
  }
@@ -101,9 +55,6 @@ export {
101
55
  AppType,
102
56
  AutometaApp,
103
57
  AutometaWorld,
104
- Fixture,
105
- Inject,
106
- LIFE_CYCLE,
107
58
  getApp
108
59
  };
109
60
  //# 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;A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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 { 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 { 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;;;ACA5B,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;AAEpD,MAAI,KAAK,GAAG;AACZ,SAAO;AACT;;;ACtCA,SAAS,gBAAgB;AAClB,SAAS,QACdA,YACA,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,IAAAA,WAAU,GAAG,IAAI,EAAE,KAAK,QAAsB,MAA6B;AAAA,EAC7E;AACF;","names":["container"]}
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,7 +98,6 @@ declare abstract class AutometaApp {
98
98
  }
99
99
 
100
100
  declare class AutometaWorld {
101
- [key: string]: unknown;
102
101
  }
103
102
 
104
103
  declare function getApp<T extends AutometaApp, K extends AutometaWorld>(appType: Class<T>, worldType: Class<K>, ...instances: {
@@ -107,57 +106,9 @@ declare function getApp<T extends AutometaApp, K extends AutometaWorld>(appType:
107
106
  cls?: Class<any>;
108
107
  }[]): T;
109
108
 
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];
157
-
158
109
  declare function AppType(container: Record<string, {
159
- app: unknown;
160
- world: unknown;
110
+ app: Class<App>;
111
+ world: Class<World>;
161
112
  }>, world: Class<AutometaWorld>, environment?: string): (target: Class<unknown>) => void;
162
113
 
163
- export { App, AppType, AutometaApp, AutometaWorld, Fixture, Inject, LIFE_CYCLE, Lifecycle, World, getApp };
114
+ 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,7 +98,6 @@ declare abstract class AutometaApp {
98
98
  }
99
99
 
100
100
  declare class AutometaWorld {
101
- [key: string]: unknown;
102
101
  }
103
102
 
104
103
  declare function getApp<T extends AutometaApp, K extends AutometaWorld>(appType: Class<T>, worldType: Class<K>, ...instances: {
@@ -107,57 +106,9 @@ declare function getApp<T extends AutometaApp, K extends AutometaWorld>(appType:
107
106
  cls?: Class<any>;
108
107
  }[]): T;
109
108
 
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];
157
-
158
109
  declare function AppType(container: Record<string, {
159
- app: unknown;
160
- world: unknown;
110
+ app: Class<App>;
111
+ world: Class<World>;
161
112
  }>, world: Class<AutometaWorld>, environment?: string): (target: Class<unknown>) => void;
162
113
 
163
- export { App, AppType, AutometaApp, AutometaWorld, Fixture, Inject, LIFE_CYCLE, Lifecycle, World, getApp };
114
+ 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,12 +32,8 @@ 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
39
  var import_tsyringe = require("tsyringe");
@@ -80,43 +64,19 @@ defineConfig({
80
64
  });
81
65
  const child = import_tsyringe.container.createChildContainer();
82
66
  const app = (0, import_fixture_proxies.ErrorCatcherProxy)(child.resolve(appType));
83
- app.world = child.resolve(worldType);
84
67
  app.id = (0, import_uuid.v4)();
85
68
  return app;
86
69
  }
87
70
 
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
-
114
71
  // src/decorators/app-type.ts
115
- var import_tsyringe3 = require("tsyringe");
72
+ var import_injection = require("@autometa/injection");
116
73
  function AppType(container2, world, environment = "default") {
117
74
  const env = environment ?? "default";
118
75
  return (target) => {
119
- Fixture(import_tsyringe3.Lifecycle.ContainerScoped)(target);
76
+ (0, import_injection.metadata)(target.prototype).set({
77
+ key: "world",
78
+ class: world
79
+ });
120
80
  container2[env] = { app: target, world };
121
81
  };
122
82
  }
@@ -125,9 +85,6 @@ function AppType(container2, world, environment = "default") {
125
85
  AppType,
126
86
  AutometaApp,
127
87
  AutometaWorld,
128
- Fixture,
129
- Inject,
130
- LIFE_CYCLE,
131
88
  getApp
132
89
  });
133
90
  //# 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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AAA,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 { 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 { 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;;;ACA5B,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;AAEpD,MAAI,SAAK,gBAAG;AACZ,SAAO;AACT;;;ACtCA,uBAAyB;AAClB,SAAS,QACdA,YACA,OACA,cAAc,WACd;AACA,QAAM,MAAM,eAAe;AAC3B,SAAO,CAAC,WAA2B;AACjC,mCAAS,OAAO,SAAS,EAAE,IAAI;AAAA,MAC7B,KAAK;AAAA,MACL,OAAO;AAAA,IACT,CAAC;AACD,IAAAA,WAAU,GAAG,IAAI,EAAE,KAAK,QAAsB,MAA6B;AAAA,EAC7E;AACF;","names":["container"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autometa/app",
3
- "version": "0.2.3",
3
+ "version": "0.3.0",
4
4
  "description": "App and World container for Autometa",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -48,10 +48,11 @@
48
48
  "vitest": "0.34.6"
49
49
  },
50
50
  "dependencies": {
51
- "@autometa/asserters": "0.1.7",
52
- "@autometa/errors": "0.2.1",
53
- "@autometa/fixture-proxies": "^0.1.2",
54
- "@autometa/phrases": "0.1.11",
51
+ "@autometa/asserters": "0.1.8",
52
+ "@autometa/errors": "0.2.2",
53
+ "@autometa/fixture-proxies": "^0.1.3",
54
+ "@autometa/injection": "^0.1.0",
55
+ "@autometa/phrases": "0.1.12",
55
56
  "tsyringe": "^4.8.0",
56
57
  "uuid": "^9.0.1"
57
58
  },