@travetto/runtime 6.0.1 → 7.0.0-rc.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/README.md CHANGED
@@ -278,7 +278,7 @@ tpl`{{age:20}} {{name: 'bob'}}</>;
278
278
  ```
279
279
 
280
280
  ## Time Utilities
281
- [TimeUtil](https://github.com/travetto/travetto/tree/main/module/runtime/src/time.ts#L17) contains general helper methods, created to assist with time-based inputs via environment variables, command line interfaces, and other string-heavy based input.
281
+ [TimeUtil](https://github.com/travetto/travetto/tree/main/module/runtime/src/time.ts#L19) contains general helper methods, created to assist with time-based inputs via environment variables, command line interfaces, and other string-heavy based input.
282
282
 
283
283
  **Code: Time Utilities**
284
284
  ```typescript
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/runtime",
3
- "version": "6.0.1",
3
+ "version": "7.0.0-rc.1",
4
4
  "description": "Runtime for travetto applications.",
5
5
  "keywords": [
6
6
  "console-manager",
@@ -25,12 +25,12 @@
25
25
  "directory": "module/runtime"
26
26
  },
27
27
  "dependencies": {
28
- "@travetto/manifest": "^6.0.1",
28
+ "@travetto/manifest": "^7.0.0-rc.0",
29
29
  "@types/debug": "^4.1.12",
30
30
  "debug": "^4.4.3"
31
31
  },
32
32
  "peerDependencies": {
33
- "@travetto/transformer": "^6.0.1"
33
+ "@travetto/transformer": "^7.0.0-rc.1"
34
34
  },
35
35
  "peerDependenciesMeta": {
36
36
  "@travetto/transformer": {
package/src/debug.ts CHANGED
@@ -6,7 +6,7 @@ import { ClassInstance } from './types.ts';
6
6
  * @augments `@travetto/runtime:DebugBreak`
7
7
  */
8
8
  export function DebugBreak(): MethodDecorator {
9
- return (inst: ClassInstance, prop: string | symbol, descriptor: PropertyDescriptor) => descriptor;
9
+ return (instance: ClassInstance, property: string | symbol, descriptor: PropertyDescriptor) => descriptor;
10
10
 
11
11
  }
12
12
 
package/src/function.ts CHANGED
@@ -6,7 +6,7 @@ export type FunctionMetadata = FunctionMetadataTag & {
6
6
  import: string;
7
7
  module: string;
8
8
  modulePath: string;
9
- methods?: Record<string, FunctionMetadataTag>;
9
+ methods?: Record<string | symbol, FunctionMetadataTag>;
10
10
  class?: boolean;
11
11
  abstract?: boolean;
12
12
  };
@@ -36,7 +36,10 @@ export function registerFunction(
36
36
  import: `${pkg}/${pth}`,
37
37
  module: pkg,
38
38
  modulePath,
39
- ...tag, methods, abstract, class: abstract !== undefined
39
+ ...tag,
40
+ methods,
41
+ abstract,
42
+ class: methods !== undefined
40
43
  };
41
44
  pending.add(fn);
42
45
  Object.defineProperties(fn, { Ⲑid: { value: metadata.id }, [MetadataSymbol]: { value: metadata } });
@@ -59,3 +62,12 @@ export function describeFunction(fn?: Function): FunctionMetadata | undefined {
59
62
  const _fn: (Function & { [MetadataSymbol]?: FunctionMetadata }) | undefined = fn;
60
63
  return _fn?.[MetadataSymbol];
61
64
  }
65
+
66
+ const foreignTypeRegistry = new Map<string, Function>();
67
+ export function foreignType(id: string): Function {
68
+ if (!foreignTypeRegistry.has(id)) {
69
+ const type = class { static Ⲑid = id; };
70
+ foreignTypeRegistry.set(id, type);
71
+ }
72
+ return foreignTypeRegistry.get(id)!;
73
+ }
package/src/types.ts CHANGED
@@ -24,12 +24,24 @@ export type DeepPartial<T> = {
24
24
  (T[P] extends Any[] ? (DeepPartial<T[P][number]> | null | undefined)[] : DeepPartial<T[P]>));
25
25
  };
26
26
 
27
+ type ValidPrimitiveFields<T, Z = undefined> = {
28
+ [K in keyof T]:
29
+ (T[K] extends (Primitive | Z | undefined) ? K :
30
+ (T[K] extends (Function | undefined) ? never :
31
+ K))
32
+ }[keyof T];
33
+
34
+ export type RetainPrimitiveFields<T, Z = undefined> = Pick<T, ValidPrimitiveFields<T, Z>>;
35
+
27
36
  export const TypedObject: {
28
37
  keys<T = unknown, K extends keyof T = keyof T & string>(o: T): K[];
29
38
  fromEntries<K extends string | symbol, V>(items: ([K, V] | readonly [K, V])[]): Record<K, V>;
30
39
  entries<K extends Record<symbol | string, unknown>>(record: K): [keyof K, K[keyof K]][];
31
40
  } & ObjectConstructor = Object;
32
41
 
42
+ export const safeAssign = <T extends {}, U extends {}>(target: T, ...sources: U[]): T & U =>
43
+ Object.assign(target, ...sources);
44
+
33
45
  export function castTo<T>(input: unknown): T {
34
46
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
35
47
  return input as T;
@@ -53,6 +65,26 @@ export function toConcrete<T extends unknown>(): Class<T> {
53
65
  return arguments[0];
54
66
  }
55
67
 
68
+ export function getAllEntries<V>(obj: Record<string | symbol, V>): [string | symbol, V][] {
69
+ return [
70
+ ...Object.keys(obj),
71
+ ...Object.getOwnPropertySymbols(obj)
72
+ ].map(k => [k, obj[k]] as const);
73
+ }
74
+
75
+ /**
76
+ * Find parent class for a given class object
77
+ */
78
+ export function getParentClass(cls: Class): Class | undefined {
79
+ const parent: Class = Object.getPrototypeOf(cls);
80
+ return parent.name && parent !== Object ? parent : undefined;
81
+ }
82
+
83
+ /**
84
+ * Get the class from an instance or class
85
+ */
86
+ export const getClass = <T = unknown>(x: ClassInstance | Class): Class<T> => 'Ⲑid' in x ? castTo(x) : asConstructable<T>(x).constructor;
87
+
56
88
  /**
57
89
  * Range of bytes, inclusive
58
90
  */
@@ -8,7 +8,7 @@ import { OnCall, TransformerState } from '@travetto/transformer';
8
8
  export class DynamicImportTransformer {
9
9
 
10
10
  @OnCall()
11
- static onLogCall(state: TransformerState, node: ts.CallExpression): typeof node | ts.Identifier {
11
+ static onCall(state: TransformerState, node: ts.CallExpression): typeof node | ts.Identifier {
12
12
  if (
13
13
  ts.isCallExpression(node) &&
14
14
  node.expression.kind === ts.SyntaxKind.ImportKeyword &&