@xylabs/object-model 5.0.8 → 5.0.10

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,6 +1,7 @@
1
1
  import type { TypedKey } from '@xylabs/typeof';
2
+ import type { EmptyObject } from './EmptyObject.ts';
2
3
  /**
3
4
  * Any object, which means that it does not enforce the set of fields that it has. Extending from AnyObject
4
5
  * will result in a type that includes the universal set of field names
5
6
  */
6
- export type AnyObject = Record<TypedKey, unknown>;
7
+ export type AnyObject = EmptyObject & Partial<Record<TypedKey, unknown>>;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * An empty object, which means that it does enforce the set of field names, defaulting to an empty set until
3
+ * extended from, which then adds only those additional fields
4
+ */
5
+ export type EmptyObject<T extends object = object> = Exclude<{
6
+ [K in keyof T]?: never;
7
+ }, unknown[] | ((...args: unknown[]) => unknown) | null>;
@@ -1,4 +1,5 @@
1
1
  export * from './AnyObject.ts';
2
2
  export * from './AsTypeFunction.ts';
3
3
  export * from './Compare.ts';
4
+ export * from './EmptyObject.ts';
4
5
  export * from './types.ts';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xylabs/object-model",
3
- "version": "5.0.8",
3
+ "version": "5.0.10",
4
4
  "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -35,10 +35,10 @@
35
35
  "src"
36
36
  ],
37
37
  "dependencies": {
38
- "@xylabs/assert": "~5.0.8",
39
- "@xylabs/logger": "~5.0.8",
40
- "@xylabs/promise": "~5.0.8",
41
- "@xylabs/typeof": "~5.0.8"
38
+ "@xylabs/assert": "~5.0.10",
39
+ "@xylabs/logger": "~5.0.10",
40
+ "@xylabs/promise": "~5.0.10",
41
+ "@xylabs/typeof": "~5.0.10"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@xylabs/ts-scripts-yarn3": "~7.1.1",
package/src/AnyObject.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  import type { TypedKey } from '@xylabs/typeof'
2
2
 
3
+ import type { EmptyObject } from './EmptyObject.ts'
4
+
3
5
  /**
4
6
  * Any object, which means that it does not enforce the set of fields that it has. Extending from AnyObject
5
7
  * will result in a type that includes the universal set of field names
6
8
  */
7
- export type AnyObject = Record<TypedKey, unknown>
9
+ export type AnyObject = EmptyObject & Partial<Record<TypedKey, unknown>>
@@ -0,0 +1,29 @@
1
+ /**
2
+ * An empty object, which means that it does enforce the set of field names, defaulting to an empty set until
3
+ * extended from, which then adds only those additional fields
4
+ */
5
+
6
+ export type EmptyObject<T extends object = object> = Exclude<{ [K in keyof T]?: never }, unknown[] | ((...args: unknown[]) => unknown) | null>
7
+
8
+ /* export type EmptyObjectExperimental = Exclude<
9
+
10
+ Record<TypedKey, unknown>,
11
+ unknown[] | ((...args: unknown[]) => unknown) | null
12
+ > */
13
+
14
+ /*
15
+ const foo: EmptyObjectExperimental = {}
16
+ const bar: EmptyObjectExperimental = []
17
+ const baz: EmptyObjectExperimental = () => null
18
+ const qux: EmptyObjectExperimental = null
19
+
20
+ type x = EmptyObjectExperimental & { test: boolean }
21
+
22
+ const y: x = { test: true, arie: 1 }
23
+
24
+ export type AnyObject = EmptyObjectExperimental & Partial<Record<TypedKey, unknown>>
25
+
26
+ export abstract class ValidatorBase<T extends EmptyObjectExperimental = AnyObject> {
27
+ abstract validate(payload: T): Promise<Error[]>
28
+ }
29
+ */
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './AnyObject.ts'
2
2
  export * from './AsTypeFunction.ts'
3
3
  export * from './Compare.ts'
4
+ export * from './EmptyObject.ts'
4
5
  export * from './types.ts'