@dungarees/core 0.12.1 → 0.13.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/application.d.ts CHANGED
@@ -6,7 +6,7 @@ export type Application<CONFIG extends Partial<ApplicationTypeConfig> = DefaultA
6
6
  };
7
7
  export declare const createApplication: <const CONFIG extends Partial<ApplicationTypeConfig> = DefaultApplicationTypeConfig>(appArgs?: Partial<CreateApplicationArgs<ApplicationTypeConfigWithDefaults<CONFIG>>>, otherApp?: () => Application<ApplicationTypeConfigWithDefaults<CONFIG>>) => Application<ApplicationTypeConfigWithDefaults<CONFIG>>;
8
8
  type RunArgs<CONFIG extends Partial<ApplicationTypeConfig>> = undefined extends CONFIG['identity'] ? [identity?: CONFIG['identity'], overrides?: RunOverrides<CONFIG>] : [identity: CONFIG['identity'], overrides?: RunOverrides<CONFIG>];
9
- type RunOverrides<CONFIG extends Partial<ApplicationTypeConfig>> = Partial<SingleApplicationArgs<ApplicationTypeConfigWithDefaults<CONFIG>>>;
9
+ type RunOverrides<CONFIG extends Partial<ApplicationTypeConfig>> = Partial<SingleApplicationArgs<CONFIG>>;
10
10
  export type SingleApplicationArgs<CONFIG extends Partial<ApplicationTypeConfig>> = {
11
11
  getServices: GetServices<CONFIG>;
12
12
  getBehaviors: GetBehaviors<CONFIG>;
@@ -28,6 +28,7 @@ export type ApplicationTypeConfig = {
28
28
  output: unknown;
29
29
  identity: JsonType;
30
30
  exportState: unknown;
31
+ input: unknown;
31
32
  };
32
33
  type DefaultApplicationTypeConfig = {
33
34
  services: Record<string, never>;
@@ -36,9 +37,10 @@ type DefaultApplicationTypeConfig = {
36
37
  output: undefined;
37
38
  identity: undefined;
38
39
  exportState: undefined;
40
+ input: undefined;
39
41
  };
40
42
  type GetServices<CONFIG extends Partial<ApplicationTypeConfig>> = (identity: CONFIG['identity']) => CONFIG['services'];
41
- type GetBehaviors<CONFIG extends Partial<ApplicationTypeConfig>> = (services: CONFIG['services'], identity: CONFIG['identity']) => CONFIG['behaviors'];
43
+ type GetBehaviors<CONFIG extends Partial<ApplicationTypeConfig>> = (services: CONFIG['services'], identity: CONFIG['identity'], input: BehaviorsAndDeliveryInput<CONFIG>) => CONFIG['behaviors'];
42
44
  type PreMain<CONFIG extends Partial<ApplicationTypeConfig>> = (behaviors: CONFIG['behaviors'], identity: CONFIG['identity']) => void;
43
45
  type GetDelivery<CONFIG extends Partial<ApplicationTypeConfig>> = (injected: {
44
46
  services: CONFIG['services'];
@@ -47,26 +49,31 @@ type GetDelivery<CONFIG extends Partial<ApplicationTypeConfig>> = (injected: {
47
49
  }, identity: CONFIG['identity']) => CONFIG['delivery'];
48
50
  type Main<CONFIG extends Partial<ApplicationTypeConfig>> = (injected: {
49
51
  services: CONFIG['services'];
52
+ createBehaviorsAndDelivery: CreateBehaviorsAndDelivery<CONFIG>;
53
+ }, identity: CONFIG['identity']) => CONFIG['output'];
54
+ type BehaviorsAndDeliveryArgs<CONFIG extends Partial<ApplicationTypeConfig>> = undefined extends CONFIG['input'] ? [input?: CONFIG['input']] : [input: CONFIG['input']];
55
+ type BehaviorsAndDeliveryInput<CONFIG extends Partial<ApplicationTypeConfig>> = BehaviorsAndDeliveryArgs<CONFIG>[0];
56
+ export type CreateBehaviorsAndDelivery<CONFIG extends Partial<ApplicationTypeConfig>> = (...args: BehaviorsAndDeliveryArgs<CONFIG>) => BehaviorsAndDelivery<CONFIG>;
57
+ export type BehaviorsAndDelivery<CONFIG extends Partial<ApplicationTypeConfig>> = {
50
58
  behaviors: CONFIG['behaviors'];
51
59
  delivery: CONFIG['delivery'];
52
- }, identity: CONFIG['identity']) => CONFIG['output'];
60
+ exportState: () => CONFIG['exportState'];
61
+ importState: (newState: CONFIG['exportState']) => void;
62
+ };
53
63
  type OnError = (error: unknown) => void;
54
64
  type TopLevelErrorHandling = (onError: (error: unknown) => void) => void;
55
65
  type ExportState<CONFIG extends Partial<ApplicationTypeConfig>> = (behaviors: CONFIG['behaviors']) => CONFIG['exportState'];
56
66
  type ImportState<CONFIG extends Partial<ApplicationTypeConfig>> = (behaviors: CONFIG['behaviors'], newState: CONFIG['exportState']) => void;
57
67
  type RecordShapedKey = 'services' | 'behaviors' | 'delivery';
58
68
  type ApplicationTypeConfigWithDefaults<CONFIG extends Partial<ApplicationTypeConfig>> = {
59
- [KEY in keyof DefaultApplicationTypeConfig]: KEY extends RecordShapedKey ? CONFIG[KEY] extends ApplicationTypeConfig[KEY] ? CONFIG[KEY] : DefaultApplicationTypeConfig[KEY] : CONFIG[KEY];
69
+ [KEY in keyof DefaultApplicationTypeConfig]: KEY extends RecordShapedKey ? CONFIG[KEY] extends ApplicationTypeConfig[KEY] ? CONFIG[KEY] : DefaultApplicationTypeConfig[KEY] : KEY extends 'input' ? unknown extends CONFIG[KEY] ? DefaultApplicationTypeConfig[KEY] : CONFIG[KEY] : CONFIG[KEY];
60
70
  };
61
71
  export type ApplicationTypeConfigWithAnys<CONFIG extends Partial<ApplicationTypeConfig>> = {
62
72
  [KEY in keyof ApplicationTypeConfig]: CONFIG[KEY] extends ApplicationTypeConfig[KEY] ? CONFIG[KEY] : ApplicationTypeConfig[KEY];
63
73
  };
64
74
  export type ApplicationRunReturn<CONFIG extends Partial<ApplicationTypeConfig>> = {
65
75
  services: CONFIG['services'];
66
- behaviors: CONFIG['behaviors'];
67
- delivery: CONFIG['delivery'];
68
76
  output: CONFIG['output'];
69
- importState: (newState: CONFIG['exportState']) => void;
70
- exportState: () => CONFIG['exportState'];
77
+ createBehaviorsAndDelivery: CreateBehaviorsAndDelivery<CONFIG>;
71
78
  };
72
79
  export {};
package/application.js CHANGED
@@ -50,21 +50,22 @@ export const createApplication = (appArgs = {}, otherApp) => {
50
50
  try {
51
51
  topLevelErrorHandling(onError);
52
52
  const services = getServices(runIdentity);
53
- const behaviors = getBehaviors(services, runIdentity);
54
- preMain(behaviors, runIdentity);
55
- const exportState = () => exportStateOriginal(behaviors);
56
- const delivery = getDelivery({ services, behaviors, exportState }, runIdentity);
57
- const output = main({ services, delivery, behaviors }, runIdentity);
58
- return {
59
- services,
60
- behaviors,
61
- delivery,
62
- output,
63
- exportState,
64
- importState: (newState) => {
65
- importState(behaviors, newState);
66
- },
53
+ const createBehaviorsAndDelivery = (...args) => {
54
+ const behaviors = getBehaviors(services, runIdentity, args[0]);
55
+ preMain(behaviors, runIdentity);
56
+ const exportState = () => exportStateOriginal(behaviors);
57
+ const delivery = getDelivery({ services, behaviors, exportState }, runIdentity);
58
+ return {
59
+ behaviors,
60
+ delivery,
61
+ exportState,
62
+ importState: (newState) => {
63
+ importState(behaviors, newState);
64
+ },
65
+ };
67
66
  };
67
+ const output = main({ services, createBehaviorsAndDelivery }, runIdentity);
68
+ return { services, output, createBehaviorsAndDelivery };
68
69
  }
69
70
  catch (e) {
70
71
  onError(e);
package/package.json CHANGED
@@ -28,7 +28,7 @@
28
28
  "rxjs-marbles": "^7.0.1",
29
29
  "vitest": "^3.0.2"
30
30
  },
31
- "version": "0.12.1",
31
+ "version": "0.13.0",
32
32
  "exports": {
33
33
  "./application.ts": {
34
34
  "import": "./application.js",