@autometa/app 0.1.3 → 0.1.5

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.
@@ -1,14 +1,14 @@
1
1
 
2
- > @autometa/app@0.1.1 test /Users/ben.aherne/Documents/GitHub/autometa/packages/app
2
+ > @autometa/app@0.1.4 test /Users/ben.aherne/Documents/GitHub/autometa/packages/app
3
3
  > vitest run
4
4
 
5
5
 
6
6
  RUN v0.33.0 /Users/ben.aherne/Documents/GitHub/autometa/packages/app
7
7
 
8
- ✓ src/decorators/fixture.spec.ts (2 tests) 11ms
8
+ ✓ src/decorators/fixture.spec.ts (2 tests) 2ms
9
9
 
10
10
  Test Files 1 passed (1)
11
11
  Tests 2 passed (2)
12
- Start at 17:02:43
13
- Duration 990ms (transform 75ms, setup 0ms, collect 168ms, tests 11ms, environment 0ms, prepare 174ms)
12
+ Start at 17:37:07
13
+ Duration 326ms (transform 54ms, setup 0ms, collect 87ms, tests 2ms, environment 0ms, prepare 93ms)
14
14
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @autometa/app
2
2
 
3
+ ## 0.1.5
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [12bd4b1e]
8
+ - @autometa/errors@0.1.2
9
+ - @autometa/asserters@0.1.2
10
+ - @autometa/phrases@0.1.4
11
+
12
+ ## 0.1.4
13
+
14
+ ### Patch Changes
15
+
16
+ - 4a16497d: fix(scopes): hooks not executing without tag expressions
17
+
3
18
  ## 0.1.3
4
19
 
5
20
  ### Patch Changes
package/dist/esm/index.js CHANGED
@@ -25,6 +25,7 @@ AutometaWorld = __decorateClass([
25
25
  // src/get-app.ts
26
26
  import { container } from "tsyringe";
27
27
  import { AutomationError } from "@autometa/errors";
28
+ import { v4 } from "uuid";
28
29
  function getApp(appType, worldType, ...instances) {
29
30
  if (!appType) {
30
31
  throw new AutomationError(`A reference to an 'app' and 'world' is required to run tests.
@@ -44,17 +45,24 @@ defineConfig({
44
45
  }
45
46
  container.registerType(worldType, worldType);
46
47
  instances.forEach(
47
- ({ token, instance, cls }) => instance ? child.registerInstance(token, instance) : cls ? child.registerType(token, cls) : null
48
+ ({ token, instance, cls }) => child.register(token, instance ?? cls)
48
49
  );
49
50
  const child = container.createChildContainer();
50
51
  const app = child.resolve(appType);
51
52
  app.world = child.resolve(worldType);
53
+ app.id = v4();
52
54
  return app;
53
55
  }
54
56
 
55
57
  // src/decorators/fixture.ts
56
58
  import "reflect-metadata";
57
- import { scoped, inject, Lifecycle as LC, injectable } from "tsyringe";
59
+ import {
60
+ scoped,
61
+ inject,
62
+ Lifecycle as LC,
63
+ injectable,
64
+ singleton
65
+ } from "tsyringe";
58
66
  function Fixture(arg) {
59
67
  if (arg && typeof arg !== "number") {
60
68
  injectable()(arg);
@@ -63,18 +71,27 @@ function Fixture(arg) {
63
71
  }
64
72
  return (target) => {
65
73
  injectable()(target);
74
+ if (arg === LIFE_CYCLE.Singleton) {
75
+ singleton()(target);
76
+ return;
77
+ }
66
78
  scoped(arg)(target);
67
79
  };
68
80
  }
69
81
  var Inject = inject;
70
- var Lifecycle = LC;
82
+ var LIFE_CYCLE = {
83
+ Transient: LC.Transient,
84
+ Singleton: LC.Singleton,
85
+ ResolutionScoped: LC.ResolutionScoped,
86
+ ContainerScoped: LC.ContainerScoped
87
+ };
71
88
 
72
89
  // src/decorators/app-type.ts
73
- import { Lifecycle as Lifecycle2 } from "tsyringe";
90
+ import { Lifecycle } from "tsyringe";
74
91
  function AppType(container2, world, environment = "default") {
75
92
  const env = environment ?? "default";
76
93
  return (target) => {
77
- Fixture(Lifecycle2.ContainerScoped)(target);
94
+ Fixture(Lifecycle.ContainerScoped)(target);
78
95
  container2[env] = { app: target, world };
79
96
  };
80
97
  }
@@ -84,7 +101,7 @@ export {
84
101
  AutometaWorld,
85
102
  Fixture,
86
103
  Inject,
87
- Lifecycle,
104
+ LIFE_CYCLE,
88
105
  getApp
89
106
  };
90
107
  //# 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 [key: string]: unknown;\n world: World\n}\n","import { PhraseParser, IFromPhrase } from \"@autometa/phrases\";\n\n@PhraseParser\nexport class AutometaWorld {\n [key: string]: unknown;\n\n dfromPhrase: IFromPhrase;\n}\n","import { container } from \"tsyringe\";\nimport { AutometaApp } from \"./autometa-app\";\nimport { Class } from \"@autometa/types\";\nimport { AutomationError } from \"@autometa/errors\";\nimport { AutometaWorld } from \".\";\n\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/apps'\n }\n})`);\n }\n container.registerType(worldType, worldType);\n instances.forEach(({ token, instance, cls }) =>\n instance\n ? child.registerInstance(token, instance)\n : cls\n ? child.registerType(token, cls)\n : null\n );\n\n const child = container.createChildContainer();\n const app = child.resolve(appType);\n app.world = child.resolve(worldType);\n return app;\n}\n","import \"reflect-metadata\";\n\nimport { Class } from \"@autometa/types\";\nimport { scoped, inject, Lifecycle as LC, injectable } 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(scope?: LC): (target: Class<unknown>) => void;\nexport function Fixture(arg: LC | undefined | Class<unknown>) {\n if (arg && typeof arg !== \"number\") {\n injectable()(arg);\n scoped(LC.ContainerScoped)(arg);\n return;\n }\n return (target: Class<unknown>) => {\n injectable()(target);\n scoped(arg as LC.ContainerScoped | LC.ResolutionScoped)(target);\n };\n}\n\nexport const Inject = inject;\nexport const Lifecycle = LC;\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;AAGlC;;;ACLA,SAAS,oBAAiC;AAGnC,IAAM,gBAAN,MAAoB;AAI3B;AAJa,gBAAN;AAAA,EADN;AAAA,GACY;;;ACHb,SAAS,iBAAiB;AAG1B,SAAS,uBAAuB;AAGzB,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,aAAa,WAAW,SAAS;AAC3C,YAAU;AAAA,IAAQ,CAAC,EAAE,OAAO,UAAU,IAAI,MACxC,WACI,MAAM,iBAAiB,OAAO,QAAQ,IACtC,MACA,MAAM,aAAa,OAAO,GAAG,IAC7B;AAAA,EACN;AAEA,QAAM,QAAQ,UAAU,qBAAqB;AAC7C,QAAM,MAAM,MAAM,QAAQ,OAAO;AACjC,MAAI,QAAQ,MAAM,QAAQ,SAAS;AACnC,SAAO;AACT;;;ACzCA,OAAO;AAGP,SAAS,QAAQ,QAAQ,aAAa,IAAI,kBAAkB;AAwCrD,SAAS,QAAQ,KAAsC;AAC5D,MAAI,OAAO,OAAO,QAAQ,UAAU;AAClC,eAAW,EAAE,GAAG;AAChB,WAAO,GAAG,eAAe,EAAE,GAAG;AAC9B;AAAA,EACF;AACA,SAAO,CAAC,WAA2B;AACjC,eAAW,EAAE,MAAM;AACnB,WAAO,GAA+C,EAAE,MAAM;AAAA,EAChE;AACF;AAEO,IAAM,SAAS;AACf,IAAM,YAAY;;;ACvDzB,SAAS,aAAAA,kBAAiB;AAKnB,SAAS,QACdC,YACA,OACA,cAAc,WACd;AACA,QAAM,MAAM,eAAe;AAC3B,SAAO,CAAC,WAA2B;AACjC,YAAQC,WAAU,eAAe,EAAE,MAAM;AACzC,IAAAD,WAAU,GAAG,IAAI,EAAE,KAAK,QAAQ,MAAM;AAAA,EACxC;AACF;","names":["Lifecycle","container","Lifecycle"]}
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, IFromPhrase } from \"@autometa/phrases\";\n\n@PhraseParser\nexport class AutometaWorld {\n [key: string]: unknown;\n\n dfromPhrase: IFromPhrase;\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\";\n\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/apps'\n }\n})`);\n }\n container.registerType(worldType, worldType);\n instances.forEach(({ token, instance, cls }) =>\n child.register(token, instance ?? cls)\n );\n\n const child = container.createChildContainer();\n const app = 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 && 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 as LC.ContainerScoped | LC.ResolutionScoped)(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,oBAAiC;AAGnC,IAAM,gBAAN,MAAoB;AAI3B;AAJa,gBAAN;AAAA,EADN;AAAA,GACY;;;ACHb,SAAS,iBAAiB;AAG1B,SAAS,uBAAuB;AAEhC,SAAS,UAAU;AAEZ,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,aAAa,WAAW,SAAS;AAC3C,YAAU;AAAA,IAAQ,CAAC,EAAE,OAAO,UAAU,IAAI,MACxC,MAAM,SAAS,OAAO,YAAY,GAAG;AAAA,EACvC;AAEA,QAAM,QAAQ,UAAU,qBAAqB;AAC7C,QAAM,MAAM,MAAM,QAAQ,OAAO;AACjC,MAAI,QAAQ,MAAM,QAAQ,SAAS;AACnC,MAAI,KAAK,GAAG;AACZ,SAAO;AACT;;;ACvCA,OAAO;AAGP;AAAA,EACE;AAAA,EACA;AAAA,EACA,aAAa;AAAA,EACb;AAAA,EACA;AAAA,OACK;AA0CA,SAAS,QAAQ,KAA6C;AACnE,MAAI,OAAO,OAAO,QAAQ,UAAU;AAClC,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,GAA+C,EAAE,MAAM;AAAA,EAChE;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"]}
package/dist/index.d.cts CHANGED
@@ -1,14 +1,16 @@
1
1
  import { IFromPhrase } from '@autometa/phrases';
2
2
  import { Class } from '@autometa/types';
3
- import { Lifecycle as Lifecycle$1, inject } from 'tsyringe';
3
+ import { inject } from 'tsyringe';
4
4
 
5
5
  interface World {
6
6
  }
7
7
  interface App {
8
+ readonly id: string;
8
9
  world: World;
9
10
  }
10
11
 
11
12
  declare abstract class AutometaApp {
13
+ id: string;
12
14
  [key: string]: unknown;
13
15
  world: World;
14
16
  }
@@ -62,13 +64,19 @@ declare function getApp<T extends AutometaApp, K extends AutometaWorld>(appType:
62
64
  * ```
63
65
  */
64
66
  declare function Fixture(target: Class<unknown>): void;
65
- declare function Fixture(scope?: Lifecycle$1): (target: Class<unknown>) => void;
67
+ declare function Fixture<T extends Class<unknown>>(scope?: Lifecycle): (target: T) => void;
66
68
  declare const Inject: typeof inject;
67
- declare const Lifecycle: typeof Lifecycle$1;
69
+ declare const LIFE_CYCLE: {
70
+ readonly Transient: 0;
71
+ readonly Singleton: 1;
72
+ readonly ResolutionScoped: 2;
73
+ readonly ContainerScoped: 3;
74
+ };
75
+ type Lifecycle = (typeof LIFE_CYCLE)[keyof typeof LIFE_CYCLE];
68
76
 
69
77
  declare function AppType(container: Record<string, {
70
78
  app: unknown;
71
79
  world: unknown;
72
80
  }>, world: Class<AutometaWorld>, environment?: string): (target: Class<unknown>) => void;
73
81
 
74
- export { App, AppType, AutometaApp, AutometaWorld, Fixture, Inject, Lifecycle, World, getApp };
82
+ export { App, AppType, AutometaApp, AutometaWorld, Fixture, Inject, LIFE_CYCLE, Lifecycle, World, getApp };
package/dist/index.d.ts CHANGED
@@ -1,14 +1,16 @@
1
1
  import { IFromPhrase } from '@autometa/phrases';
2
2
  import { Class } from '@autometa/types';
3
- import { Lifecycle as Lifecycle$1, inject } from 'tsyringe';
3
+ import { inject } from 'tsyringe';
4
4
 
5
5
  interface World {
6
6
  }
7
7
  interface App {
8
+ readonly id: string;
8
9
  world: World;
9
10
  }
10
11
 
11
12
  declare abstract class AutometaApp {
13
+ id: string;
12
14
  [key: string]: unknown;
13
15
  world: World;
14
16
  }
@@ -62,13 +64,19 @@ declare function getApp<T extends AutometaApp, K extends AutometaWorld>(appType:
62
64
  * ```
63
65
  */
64
66
  declare function Fixture(target: Class<unknown>): void;
65
- declare function Fixture(scope?: Lifecycle$1): (target: Class<unknown>) => void;
67
+ declare function Fixture<T extends Class<unknown>>(scope?: Lifecycle): (target: T) => void;
66
68
  declare const Inject: typeof inject;
67
- declare const Lifecycle: typeof Lifecycle$1;
69
+ declare const LIFE_CYCLE: {
70
+ readonly Transient: 0;
71
+ readonly Singleton: 1;
72
+ readonly ResolutionScoped: 2;
73
+ readonly ContainerScoped: 3;
74
+ };
75
+ type Lifecycle = (typeof LIFE_CYCLE)[keyof typeof LIFE_CYCLE];
68
76
 
69
77
  declare function AppType(container: Record<string, {
70
78
  app: unknown;
71
79
  world: unknown;
72
80
  }>, world: Class<AutometaWorld>, environment?: string): (target: Class<unknown>) => void;
73
81
 
74
- export { App, AppType, AutometaApp, AutometaWorld, Fixture, Inject, Lifecycle, World, getApp };
82
+ export { App, AppType, AutometaApp, AutometaWorld, Fixture, Inject, LIFE_CYCLE, Lifecycle, World, getApp };
package/dist/index.js CHANGED
@@ -34,7 +34,7 @@ __export(src_exports, {
34
34
  AutometaWorld: () => AutometaWorld,
35
35
  Fixture: () => Fixture,
36
36
  Inject: () => Inject,
37
- Lifecycle: () => Lifecycle,
37
+ LIFE_CYCLE: () => LIFE_CYCLE,
38
38
  getApp: () => getApp
39
39
  });
40
40
  module.exports = __toCommonJS(src_exports);
@@ -54,6 +54,7 @@ AutometaWorld = __decorateClass([
54
54
  // src/get-app.ts
55
55
  var import_tsyringe = require("tsyringe");
56
56
  var import_errors = require("@autometa/errors");
57
+ var import_uuid = require("uuid");
57
58
  function getApp(appType, worldType, ...instances) {
58
59
  if (!appType) {
59
60
  throw new import_errors.AutomationError(`A reference to an 'app' and 'world' is required to run tests.
@@ -73,11 +74,12 @@ defineConfig({
73
74
  }
74
75
  import_tsyringe.container.registerType(worldType, worldType);
75
76
  instances.forEach(
76
- ({ token, instance, cls }) => instance ? child.registerInstance(token, instance) : cls ? child.registerType(token, cls) : null
77
+ ({ token, instance, cls }) => child.register(token, instance ?? cls)
77
78
  );
78
79
  const child = import_tsyringe.container.createChildContainer();
79
80
  const app = child.resolve(appType);
80
81
  app.world = child.resolve(worldType);
82
+ app.id = (0, import_uuid.v4)();
81
83
  return app;
82
84
  }
83
85
 
@@ -92,11 +94,20 @@ function Fixture(arg) {
92
94
  }
93
95
  return (target) => {
94
96
  (0, import_tsyringe2.injectable)()(target);
97
+ if (arg === LIFE_CYCLE.Singleton) {
98
+ (0, import_tsyringe2.singleton)()(target);
99
+ return;
100
+ }
95
101
  (0, import_tsyringe2.scoped)(arg)(target);
96
102
  };
97
103
  }
98
104
  var Inject = import_tsyringe2.inject;
99
- var Lifecycle = import_tsyringe2.Lifecycle;
105
+ var LIFE_CYCLE = {
106
+ Transient: import_tsyringe2.Lifecycle.Transient,
107
+ Singleton: import_tsyringe2.Lifecycle.Singleton,
108
+ ResolutionScoped: import_tsyringe2.Lifecycle.ResolutionScoped,
109
+ ContainerScoped: import_tsyringe2.Lifecycle.ContainerScoped
110
+ };
100
111
 
101
112
  // src/decorators/app-type.ts
102
113
  var import_tsyringe3 = require("tsyringe");
@@ -114,7 +125,7 @@ function AppType(container2, world, environment = "default") {
114
125
  AutometaWorld,
115
126
  Fixture,
116
127
  Inject,
117
- Lifecycle,
128
+ LIFE_CYCLE,
118
129
  getApp
119
130
  });
120
131
  //# 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 [key: string]: unknown;\n world: World\n}\n","import { PhraseParser, IFromPhrase } from \"@autometa/phrases\";\n\n@PhraseParser\nexport class AutometaWorld {\n [key: string]: unknown;\n\n dfromPhrase: IFromPhrase;\n}\n","import { container } from \"tsyringe\";\nimport { AutometaApp } from \"./autometa-app\";\nimport { Class } from \"@autometa/types\";\nimport { AutomationError } from \"@autometa/errors\";\nimport { AutometaWorld } from \".\";\n\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/apps'\n }\n})`);\n }\n container.registerType(worldType, worldType);\n instances.forEach(({ token, instance, cls }) =>\n instance\n ? child.registerInstance(token, instance)\n : cls\n ? child.registerType(token, cls)\n : null\n );\n\n const child = container.createChildContainer();\n const app = child.resolve(appType);\n app.world = child.resolve(worldType);\n return app;\n}\n","import \"reflect-metadata\";\n\nimport { Class } from \"@autometa/types\";\nimport { scoped, inject, Lifecycle as LC, injectable } 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(scope?: LC): (target: Class<unknown>) => void;\nexport function Fixture(arg: LC | undefined | Class<unknown>) {\n if (arg && typeof arg !== \"number\") {\n injectable()(arg);\n scoped(LC.ContainerScoped)(arg);\n return;\n }\n return (target: Class<unknown>) => {\n injectable()(target);\n scoped(arg as LC.ContainerScoped | LC.ResolutionScoped)(target);\n };\n}\n\nexport const Inject = inject;\nexport const Lifecycle = LC;\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;AAGlC;;;ACLA,qBAA0C;AAGnC,IAAM,gBAAN,MAAoB;AAI3B;AAJa,gBAAN;AAAA,EADN;AAAA,GACY;;;ACHb,sBAA0B;AAG1B,oBAAgC;AAGzB,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,4BAAU,aAAa,WAAW,SAAS;AAC3C,YAAU;AAAA,IAAQ,CAAC,EAAE,OAAO,UAAU,IAAI,MACxC,WACI,MAAM,iBAAiB,OAAO,QAAQ,IACtC,MACA,MAAM,aAAa,OAAO,GAAG,IAC7B;AAAA,EACN;AAEA,QAAM,QAAQ,0BAAU,qBAAqB;AAC7C,QAAM,MAAM,MAAM,QAAQ,OAAO;AACjC,MAAI,QAAQ,MAAM,QAAQ,SAAS;AACnC,SAAO;AACT;;;ACzCA,8BAAO;AAGP,IAAAA,mBAA4D;AAwCrD,SAAS,QAAQ,KAAsC;AAC5D,MAAI,OAAO,OAAO,QAAQ,UAAU;AAClC,qCAAW,EAAE,GAAG;AAChB,iCAAO,iBAAAC,UAAG,eAAe,EAAE,GAAG;AAC9B;AAAA,EACF;AACA,SAAO,CAAC,WAA2B;AACjC,qCAAW,EAAE,MAAM;AACnB,iCAAO,GAA+C,EAAE,MAAM;AAAA,EAChE;AACF;AAEO,IAAM,SAAS;AACf,IAAM,YAAY,iBAAAA;;;ACvDzB,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/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, IFromPhrase } from \"@autometa/phrases\";\n\n@PhraseParser\nexport class AutometaWorld {\n [key: string]: unknown;\n\n dfromPhrase: IFromPhrase;\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\";\n\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/apps'\n }\n})`);\n }\n container.registerType(worldType, worldType);\n instances.forEach(({ token, instance, cls }) =>\n child.register(token, instance ?? cls)\n );\n\n const child = container.createChildContainer();\n const app = 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 && 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 as LC.ContainerScoped | LC.ResolutionScoped)(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,qBAA0C;AAGnC,IAAM,gBAAN,MAAoB;AAI3B;AAJa,gBAAN;AAAA,EADN;AAAA,GACY;;;ACHb,sBAA0B;AAG1B,oBAAgC;AAEhC,kBAAmB;AAEZ,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,4BAAU,aAAa,WAAW,SAAS;AAC3C,YAAU;AAAA,IAAQ,CAAC,EAAE,OAAO,UAAU,IAAI,MACxC,MAAM,SAAS,OAAO,YAAY,GAAG;AAAA,EACvC;AAEA,QAAM,QAAQ,0BAAU,qBAAqB;AAC7C,QAAM,MAAM,MAAM,QAAQ,OAAO;AACjC,MAAI,QAAQ,MAAM,QAAQ,SAAS;AACnC,MAAI,SAAK,gBAAG;AACZ,SAAO;AACT;;;ACvCA,8BAAO;AAGP,IAAAA,mBAMO;AA0CA,SAAS,QAAQ,KAA6C;AACnE,MAAI,OAAO,OAAO,QAAQ,UAAU;AAClC,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,GAA+C,EAAE,MAAM;AAAA,EAChE;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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autometa/app",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "App and World container for Autometa",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -49,9 +49,10 @@
49
49
  },
50
50
  "dependencies": {
51
51
  "tsyringe": "^4.8.0",
52
- "@autometa/asserters": "0.1.1",
53
- "@autometa/errors": "0.1.1",
54
- "@autometa/phrases": "0.1.3"
52
+ "uuid": "^9.0.0",
53
+ "@autometa/asserters": "0.1.2",
54
+ "@autometa/phrases": "0.1.4",
55
+ "@autometa/errors": "0.1.2"
55
56
  },
56
57
  "scripts": {
57
58
  "test": "vitest run",