@akbarsafari00/bonyan-types 5.52.1-fa.4
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/LICENSE +37 -0
- package/README.md +9 -0
- package/dist/core/api.d.ts +3 -0
- package/dist/core/api.d.ts.map +1 -0
- package/dist/core/commands/index.d.ts +6 -0
- package/dist/core/commands/index.d.ts.map +1 -0
- package/dist/core/config/admin.d.ts +156 -0
- package/dist/core/config/admin.d.ts.map +1 -0
- package/dist/core/config/api.d.ts +38 -0
- package/dist/core/config/api.d.ts.map +1 -0
- package/dist/core/config/database.d.ts +78 -0
- package/dist/core/config/database.d.ts.map +1 -0
- package/dist/core/config/features.d.ts +14 -0
- package/dist/core/config/features.d.ts.map +1 -0
- package/dist/core/config/index.d.ts +11 -0
- package/dist/core/config/index.d.ts.map +1 -0
- package/dist/core/config/middlewares.d.ts +3 -0
- package/dist/core/config/middlewares.d.ts.map +1 -0
- package/dist/core/config/openapi.d.ts +35 -0
- package/dist/core/config/openapi.d.ts.map +1 -0
- package/dist/core/config/plugin.d.ts +8 -0
- package/dist/core/config/plugin.d.ts.map +1 -0
- package/dist/core/config/server.d.ts +102 -0
- package/dist/core/config/server.d.ts.map +1 -0
- package/dist/core/config/shared.d.ts +8 -0
- package/dist/core/config/shared.d.ts.map +1 -0
- package/dist/core/config/typescript.d.ts +10 -0
- package/dist/core/config/typescript.d.ts.map +1 -0
- package/dist/core/container.d.ts +5 -0
- package/dist/core/container.d.ts.map +1 -0
- package/dist/core/controller.d.ts +7 -0
- package/dist/core/controller.d.ts.map +1 -0
- package/dist/core/core-api/controller.d.ts +47 -0
- package/dist/core/core-api/controller.d.ts.map +1 -0
- package/dist/core/core-api/index.d.ts +4 -0
- package/dist/core/core-api/index.d.ts.map +1 -0
- package/dist/core/core-api/router.d.ts +64 -0
- package/dist/core/core-api/router.d.ts.map +1 -0
- package/dist/core/core-api/service.d.ts +69 -0
- package/dist/core/core-api/service.d.ts.map +1 -0
- package/dist/core/index.d.ts +15 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/middleware.d.ts +15 -0
- package/dist/core/middleware.d.ts.map +1 -0
- package/dist/core/module.d.ts +26 -0
- package/dist/core/module.d.ts.map +1 -0
- package/dist/core/plugin.d.ts +6 -0
- package/dist/core/plugin.d.ts.map +1 -0
- package/dist/core/policy.d.ts +15 -0
- package/dist/core/policy.d.ts.map +1 -0
- package/dist/core/route.d.ts +54 -0
- package/dist/core/route.d.ts.map +1 -0
- package/dist/core/router.d.ts +15 -0
- package/dist/core/router.d.ts.map +1 -0
- package/dist/core/service.d.ts +4 -0
- package/dist/core/service.d.ts.map +1 -0
- package/dist/core/strapi.d.ts +162 -0
- package/dist/core/strapi.d.ts.map +1 -0
- package/dist/data/component.d.ts +21 -0
- package/dist/data/component.d.ts.map +1 -0
- package/dist/data/constants.d.ts +5 -0
- package/dist/data/constants.d.ts.map +1 -0
- package/dist/data/content-type.d.ts +26 -0
- package/dist/data/content-type.d.ts.map +1 -0
- package/dist/data/entity.d.ts +15 -0
- package/dist/data/entity.d.ts.map +1 -0
- package/dist/data/index.d.ts +5 -0
- package/dist/data/index.d.ts.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/dist/internal/index.d.ts +13 -0
- package/dist/internal/index.d.ts.map +1 -0
- package/dist/internal/namespace.d.ts +78 -0
- package/dist/internal/namespace.d.ts.map +1 -0
- package/dist/internal/registry.d.ts +8 -0
- package/dist/internal/registry.d.ts.map +1 -0
- package/dist/internal/uid.d.ts +116 -0
- package/dist/internal/uid.d.ts.map +1 -0
- package/dist/modules/ai.d.ts +34 -0
- package/dist/modules/ai.d.ts.map +1 -0
- package/dist/modules/audit-logs.d.ts +6 -0
- package/dist/modules/audit-logs.d.ts.map +1 -0
- package/dist/modules/auth.d.ts +25 -0
- package/dist/modules/auth.d.ts.map +1 -0
- package/dist/modules/content-api.d.ts +92 -0
- package/dist/modules/content-api.d.ts.map +1 -0
- package/dist/modules/core-store.d.ts +28 -0
- package/dist/modules/core-store.d.ts.map +1 -0
- package/dist/modules/cron.d.ts +27 -0
- package/dist/modules/cron.d.ts.map +1 -0
- package/dist/modules/custom-fields.d.ts +25 -0
- package/dist/modules/custom-fields.d.ts.map +1 -0
- package/dist/modules/documents/component-extension.d.ts +73 -0
- package/dist/modules/documents/component-extension.d.ts.map +1 -0
- package/dist/modules/documents/draft-and-publish.d.ts +12 -0
- package/dist/modules/documents/draft-and-publish.d.ts.map +1 -0
- package/dist/modules/documents/index.d.ts +27 -0
- package/dist/modules/documents/index.d.ts.map +1 -0
- package/dist/modules/documents/middleware.d.ts +14 -0
- package/dist/modules/documents/middleware.d.ts.map +1 -0
- package/dist/modules/documents/params/attributes/id.d.ts +4 -0
- package/dist/modules/documents/params/attributes/id.d.ts.map +1 -0
- package/dist/modules/documents/params/attributes/index.d.ts +79 -0
- package/dist/modules/documents/params/attributes/index.d.ts.map +1 -0
- package/dist/modules/documents/params/attributes/relations.d.ts +40 -0
- package/dist/modules/documents/params/attributes/relations.d.ts.map +1 -0
- package/dist/modules/documents/params/data.d.ts +67 -0
- package/dist/modules/documents/params/data.d.ts.map +1 -0
- package/dist/modules/documents/params/document-engine.d.ts +34 -0
- package/dist/modules/documents/params/document-engine.d.ts.map +1 -0
- package/dist/modules/documents/params/fields.d.ts +61 -0
- package/dist/modules/documents/params/fields.d.ts.map +1 -0
- package/dist/modules/documents/params/filters/index.d.ts +61 -0
- package/dist/modules/documents/params/filters/index.d.ts.map +1 -0
- package/dist/modules/documents/params/filters/operators.d.ts +9 -0
- package/dist/modules/documents/params/filters/operators.d.ts.map +1 -0
- package/dist/modules/documents/params/index.d.ts +162 -0
- package/dist/modules/documents/params/index.d.ts.map +1 -0
- package/dist/modules/documents/params/locale.d.ts +4 -0
- package/dist/modules/documents/params/locale.d.ts.map +1 -0
- package/dist/modules/documents/params/pagination.d.ts +11 -0
- package/dist/modules/documents/params/pagination.d.ts.map +1 -0
- package/dist/modules/documents/params/populate.d.ts +86 -0
- package/dist/modules/documents/params/populate.d.ts.map +1 -0
- package/dist/modules/documents/params/search.d.ts +2 -0
- package/dist/modules/documents/params/search.d.ts.map +1 -0
- package/dist/modules/documents/params/sort.d.ts +87 -0
- package/dist/modules/documents/params/sort.d.ts.map +1 -0
- package/dist/modules/documents/params/status.d.ts +12 -0
- package/dist/modules/documents/params/status.d.ts.map +1 -0
- package/dist/modules/documents/plugin.d.ts +11 -0
- package/dist/modules/documents/plugin.d.ts.map +1 -0
- package/dist/modules/documents/result/document-engine.d.ts +34 -0
- package/dist/modules/documents/result/document-engine.d.ts.map +1 -0
- package/dist/modules/documents/result/index.d.ts +93 -0
- package/dist/modules/documents/result/index.d.ts.map +1 -0
- package/dist/modules/documents/service-instance.d.ts +96 -0
- package/dist/modules/documents/service-instance.d.ts.map +1 -0
- package/dist/modules/entity-service/index.d.ts +87 -0
- package/dist/modules/entity-service/index.d.ts.map +1 -0
- package/dist/modules/entity-service/params/attributes/id.d.ts +3 -0
- package/dist/modules/entity-service/params/attributes/id.d.ts.map +1 -0
- package/dist/modules/entity-service/params/attributes/index.d.ts +71 -0
- package/dist/modules/entity-service/params/attributes/index.d.ts.map +1 -0
- package/dist/modules/entity-service/params/attributes/literals.d.ts +8 -0
- package/dist/modules/entity-service/params/attributes/literals.d.ts.map +1 -0
- package/dist/modules/entity-service/params/attributes/relation.d.ts +40 -0
- package/dist/modules/entity-service/params/attributes/relation.d.ts.map +1 -0
- package/dist/modules/entity-service/params/attributes/utils.d.ts +9 -0
- package/dist/modules/entity-service/params/attributes/utils.d.ts.map +1 -0
- package/dist/modules/entity-service/params/data.d.ts +52 -0
- package/dist/modules/entity-service/params/data.d.ts.map +1 -0
- package/dist/modules/entity-service/params/fields.d.ts +61 -0
- package/dist/modules/entity-service/params/fields.d.ts.map +1 -0
- package/dist/modules/entity-service/params/filters/index.d.ts +96 -0
- package/dist/modules/entity-service/params/filters/index.d.ts.map +1 -0
- package/dist/modules/entity-service/params/filters/operators.d.ts +9 -0
- package/dist/modules/entity-service/params/filters/operators.d.ts.map +1 -0
- package/dist/modules/entity-service/params/index.d.ts +123 -0
- package/dist/modules/entity-service/params/index.d.ts.map +1 -0
- package/dist/modules/entity-service/params/pagination.d.ts +10 -0
- package/dist/modules/entity-service/params/pagination.d.ts.map +1 -0
- package/dist/modules/entity-service/params/populate.d.ts +69 -0
- package/dist/modules/entity-service/params/populate.d.ts.map +1 -0
- package/dist/modules/entity-service/params/search.d.ts +2 -0
- package/dist/modules/entity-service/params/search.d.ts.map +1 -0
- package/dist/modules/entity-service/params/sort.d.ts +95 -0
- package/dist/modules/entity-service/params/sort.d.ts.map +1 -0
- package/dist/modules/entity-service/plugin.d.ts +11 -0
- package/dist/modules/entity-service/plugin.d.ts.map +1 -0
- package/dist/modules/entity-service/result.d.ts +78 -0
- package/dist/modules/entity-service/result.d.ts.map +1 -0
- package/dist/modules/entity-validator.d.ts +21 -0
- package/dist/modules/entity-validator.d.ts.map +1 -0
- package/dist/modules/event-hub.d.ts +16 -0
- package/dist/modules/event-hub.d.ts.map +1 -0
- package/dist/modules/features.d.ts +12 -0
- package/dist/modules/features.d.ts.map +1 -0
- package/dist/modules/fetch.d.ts +11 -0
- package/dist/modules/fetch.d.ts.map +1 -0
- package/dist/modules/index.d.ts +24 -0
- package/dist/modules/index.d.ts.map +1 -0
- package/dist/modules/mcp.d.ts +216 -0
- package/dist/modules/mcp.d.ts.map +1 -0
- package/dist/modules/metrics.d.ts +8 -0
- package/dist/modules/metrics.d.ts.map +1 -0
- package/dist/modules/permissions.d.ts +14 -0
- package/dist/modules/permissions.d.ts.map +1 -0
- package/dist/modules/request-context.d.ts +6 -0
- package/dist/modules/request-context.d.ts.map +1 -0
- package/dist/modules/sanitizers.d.ts +8 -0
- package/dist/modules/sanitizers.d.ts.map +1 -0
- package/dist/modules/server.d.ts +29 -0
- package/dist/modules/server.d.ts.map +1 -0
- package/dist/modules/session-manager.d.ts +70 -0
- package/dist/modules/session-manager.d.ts.map +1 -0
- package/dist/modules/validators.d.ts +8 -0
- package/dist/modules/validators.d.ts.map +1 -0
- package/dist/modules/webhook-runner.d.ts +19 -0
- package/dist/modules/webhook-runner.d.ts.map +1 -0
- package/dist/modules/webhook-store.d.ts +21 -0
- package/dist/modules/webhook-store.d.ts.map +1 -0
- package/dist/plugin/config/index.d.ts +3 -0
- package/dist/plugin/config/index.d.ts.map +1 -0
- package/dist/plugin/config/strapi-admin/index.d.ts +8 -0
- package/dist/plugin/config/strapi-admin/index.d.ts.map +1 -0
- package/dist/plugin/config/strapi-server/config.d.ts +8 -0
- package/dist/plugin/config/strapi-server/config.d.ts.map +1 -0
- package/dist/plugin/config/strapi-server/content-types.d.ts +11 -0
- package/dist/plugin/config/strapi-server/content-types.d.ts.map +1 -0
- package/dist/plugin/config/strapi-server/controllers.d.ts +8 -0
- package/dist/plugin/config/strapi-server/controllers.d.ts.map +1 -0
- package/dist/plugin/config/strapi-server/index.d.ts +21 -0
- package/dist/plugin/config/strapi-server/index.d.ts.map +1 -0
- package/dist/plugin/config/strapi-server/lifecycle.d.ts +8 -0
- package/dist/plugin/config/strapi-server/lifecycle.d.ts.map +1 -0
- package/dist/plugin/config/strapi-server/routes.d.ts +11 -0
- package/dist/plugin/config/strapi-server/routes.d.ts.map +1 -0
- package/dist/plugin/index.d.ts +40 -0
- package/dist/plugin/index.d.ts.map +1 -0
- package/dist/public/index.d.ts +6 -0
- package/dist/public/index.d.ts.map +1 -0
- package/dist/public/registries.d.ts +68 -0
- package/dist/public/registries.d.ts.map +1 -0
- package/dist/public/shared.d.ts +61 -0
- package/dist/public/shared.d.ts.map +1 -0
- package/dist/schema/attribute/base.d.ts +92 -0
- package/dist/schema/attribute/base.d.ts.map +1 -0
- package/dist/schema/attribute/common.d.ts +29 -0
- package/dist/schema/attribute/common.d.ts.map +1 -0
- package/dist/schema/attribute/constants.d.ts +12 -0
- package/dist/schema/attribute/constants.d.ts.map +1 -0
- package/dist/schema/attribute/definitions/biginteger.d.ts +19 -0
- package/dist/schema/attribute/definitions/biginteger.d.ts.map +1 -0
- package/dist/schema/attribute/definitions/blocks.d.ts +80 -0
- package/dist/schema/attribute/definitions/blocks.d.ts.map +1 -0
- package/dist/schema/attribute/definitions/boolean.d.ts +19 -0
- package/dist/schema/attribute/definitions/boolean.d.ts.map +1 -0
- package/dist/schema/attribute/definitions/component.d.ts +25 -0
- package/dist/schema/attribute/definitions/component.d.ts.map +1 -0
- package/dist/schema/attribute/definitions/date-time.d.ts +18 -0
- package/dist/schema/attribute/definitions/date-time.d.ts.map +1 -0
- package/dist/schema/attribute/definitions/date.d.ts +18 -0
- package/dist/schema/attribute/definitions/date.d.ts.map +1 -0
- package/dist/schema/attribute/definitions/decimal.d.ts +19 -0
- package/dist/schema/attribute/definitions/decimal.d.ts.map +1 -0
- package/dist/schema/attribute/definitions/dynamic-zone.d.ts +25 -0
- package/dist/schema/attribute/definitions/dynamic-zone.d.ts.map +1 -0
- package/dist/schema/attribute/definitions/email.d.ts +19 -0
- package/dist/schema/attribute/definitions/email.d.ts.map +1 -0
- package/dist/schema/attribute/definitions/enumeration.d.ts +22 -0
- package/dist/schema/attribute/definitions/enumeration.d.ts.map +1 -0
- package/dist/schema/attribute/definitions/float.d.ts +19 -0
- package/dist/schema/attribute/definitions/float.d.ts.map +1 -0
- package/dist/schema/attribute/definitions/index.d.ts +23 -0
- package/dist/schema/attribute/definitions/index.d.ts.map +1 -0
- package/dist/schema/attribute/definitions/integer.d.ts +19 -0
- package/dist/schema/attribute/definitions/integer.d.ts.map +1 -0
- package/dist/schema/attribute/definitions/json.d.ts +17 -0
- package/dist/schema/attribute/definitions/json.d.ts.map +1 -0
- package/dist/schema/attribute/definitions/media.d.ts +24 -0
- package/dist/schema/attribute/definitions/media.d.ts.map +1 -0
- package/dist/schema/attribute/definitions/password.d.ts +18 -0
- package/dist/schema/attribute/definitions/password.d.ts.map +1 -0
- package/dist/schema/attribute/definitions/relation.d.ts +167 -0
- package/dist/schema/attribute/definitions/relation.d.ts.map +1 -0
- package/dist/schema/attribute/definitions/richtext.d.ts +18 -0
- package/dist/schema/attribute/definitions/richtext.d.ts.map +1 -0
- package/dist/schema/attribute/definitions/string.d.ts +28 -0
- package/dist/schema/attribute/definitions/string.d.ts.map +1 -0
- package/dist/schema/attribute/definitions/text.d.ts +23 -0
- package/dist/schema/attribute/definitions/text.d.ts.map +1 -0
- package/dist/schema/attribute/definitions/time.d.ts +18 -0
- package/dist/schema/attribute/definitions/time.d.ts.map +1 -0
- package/dist/schema/attribute/definitions/timestamp.d.ts +18 -0
- package/dist/schema/attribute/definitions/timestamp.d.ts.map +1 -0
- package/dist/schema/attribute/definitions/uid.d.ts +31 -0
- package/dist/schema/attribute/definitions/uid.d.ts.map +1 -0
- package/dist/schema/attribute/index.d.ts +7 -0
- package/dist/schema/attribute/index.d.ts.map +1 -0
- package/dist/schema/attribute/options.d.ts +221 -0
- package/dist/schema/attribute/options.d.ts.map +1 -0
- package/dist/schema/attribute/utils.d.ts +101 -0
- package/dist/schema/attribute/utils.d.ts.map +1 -0
- package/dist/schema/index.d.ts +144 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/struct/index.d.ts +3 -0
- package/dist/struct/index.d.ts.map +1 -0
- package/dist/struct/schema-definition.d.ts +10 -0
- package/dist/struct/schema-definition.d.ts.map +1 -0
- package/dist/struct/schema.d.ts +286 -0
- package/dist/struct/schema.d.ts.map +1 -0
- package/dist/uid/index.d.ts +168 -0
- package/dist/uid/index.d.ts.map +1 -0
- package/dist/utils/array.d.ts +80 -0
- package/dist/utils/array.d.ts.map +1 -0
- package/dist/utils/constants.d.ts +67 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/expression.d.ts +490 -0
- package/dist/utils/expression.d.ts.map +1 -0
- package/dist/utils/function.d.ts +21 -0
- package/dist/utils/function.d.ts.map +1 -0
- package/dist/utils/guard.d.ts +90 -0
- package/dist/utils/guard.d.ts.map +1 -0
- package/dist/utils/index.d.ts +236 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/json.d.ts +119 -0
- package/dist/utils/json.d.ts.map +1 -0
- package/dist/utils/object.d.ts +180 -0
- package/dist/utils/object.d.ts.map +1 -0
- package/dist/utils/string.d.ts +190 -0
- package/dist/utils/string.d.ts.map +1 -0
- package/dist/utils/tuple.d.ts +19 -0
- package/dist/utils/tuple.d.ts.map +1 -0
- package/package.json +68 -0
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
export * as Constants from './constants';
|
|
2
|
+
export * as Array from './array';
|
|
3
|
+
export * as Guard from './guard';
|
|
4
|
+
export * as Object from './object';
|
|
5
|
+
export * as String from './string';
|
|
6
|
+
export * as Function from './function';
|
|
7
|
+
export * as Tuple from './tuple';
|
|
8
|
+
export * from './expression';
|
|
9
|
+
export * from './json';
|
|
10
|
+
/**
|
|
11
|
+
* `Get<TValue, TKey>` obtains the type of a specific property (key-value pair) within an object or type.
|
|
12
|
+
*
|
|
13
|
+
* @template TValue The initial object type from which a property's type should be extracted.
|
|
14
|
+
* @template TKey A specific key, existing within `TValue`.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // Utilizing Get to extract types from an object
|
|
18
|
+
* type ExampleObject = { foo: 'bar', 'bar': 'foo' };
|
|
19
|
+
*
|
|
20
|
+
* // Extract `foo`'s type from the object. This infers and outputs the type 'bar'.
|
|
21
|
+
* type FooType = Get<ExampleObject, 'foo'>;
|
|
22
|
+
* let fooVar: FooType = 'bar'; // This is valid
|
|
23
|
+
*
|
|
24
|
+
* // Similar extraction for `bar`
|
|
25
|
+
* type BarType = Get<ExampleObject, 'bar'>;
|
|
26
|
+
* let barVar: BarType = 'foo'; // This is valid
|
|
27
|
+
*/
|
|
28
|
+
export type Get<TValue, TKey extends keyof TValue> = TValue[TKey];
|
|
29
|
+
/**
|
|
30
|
+
* `Flatten intersection types.
|
|
31
|
+
*
|
|
32
|
+
* It acts upon each constituent type within the provided intersection, and extracts its properties
|
|
33
|
+
* to form a new, unified object type where properties do not retain their original type-specific
|
|
34
|
+
* distinctions.
|
|
35
|
+
*
|
|
36
|
+
* It’s useful when there's a need to treat an intersection type as a single unified object type,
|
|
37
|
+
* while ensuring that the properties of each component type in the intersection are accounted for.
|
|
38
|
+
*
|
|
39
|
+
* @template T The type parameter indicating the intersection type that is to be simplified. This must extend `unknown`.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* Consider the following example with two distinct types `A` and `B`:
|
|
43
|
+
* ```typescript
|
|
44
|
+
* type A = { a: number };
|
|
45
|
+
* type B = { b: string };
|
|
46
|
+
* ```
|
|
47
|
+
* If we were to create an intersection of these two types as `C`:
|
|
48
|
+
* ```typescript
|
|
49
|
+
* type C = A & B;
|
|
50
|
+
* ```
|
|
51
|
+
* The usual operations on `C` would account for the distinct types `A` and `B`. However, when we want to treat it as a single unified object type, we can apply `Simplify` in the following way:
|
|
52
|
+
* ```typescript
|
|
53
|
+
* type D = Simplify<C>;
|
|
54
|
+
* ```
|
|
55
|
+
* Now, `D` is a single object type with properties from both `A` and `B`, and we can operate on it as:
|
|
56
|
+
* ```typescript
|
|
57
|
+
* let obj: D = { a: 5, b: 'hello' };
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @remark
|
|
61
|
+
* While this type is beneficial in certain contexts where treating intersection types as single unified objects is desirable (e.g. when exposing
|
|
62
|
+
* complex types to end-users), it's important to remember that it strips the original type information from the properties.
|
|
63
|
+
*
|
|
64
|
+
* Thus, it may not be suitable in situations where retaining the distinction between types present in the intersection is important.
|
|
65
|
+
*/
|
|
66
|
+
export type Simplify<T> = {
|
|
67
|
+
[TKey in keyof T]: T[TKey];
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Utility type that creates a new type by excluding properties from the left type ({@link TLeft}) that exist in the right type ({@link TRight}).
|
|
71
|
+
*
|
|
72
|
+
* @template TLeft
|
|
73
|
+
* @template TRight
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* type User = {
|
|
77
|
+
* id: number,
|
|
78
|
+
* name: string,
|
|
79
|
+
* email: string,
|
|
80
|
+
* };
|
|
81
|
+
*
|
|
82
|
+
* type Credentials = {
|
|
83
|
+
* email: string,
|
|
84
|
+
* password: string,
|
|
85
|
+
* };
|
|
86
|
+
*
|
|
87
|
+
* type UserWithoutCredentials = Without<User, Credentials>;
|
|
88
|
+
*
|
|
89
|
+
* const user: UserWithoutCredentials = {
|
|
90
|
+
* id: 1,
|
|
91
|
+
* name: 'Alice'
|
|
92
|
+
* // no email property because it's excluded by the Without type
|
|
93
|
+
* };
|
|
94
|
+
*/
|
|
95
|
+
export type Without<TLeft, TRight> = {
|
|
96
|
+
[key in Exclude<keyof TLeft, keyof TRight>]?: never;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Creates a type that is mutually exclusive between two given types.
|
|
100
|
+
*
|
|
101
|
+
* @template TLeft - The first type.
|
|
102
|
+
* @template TRight - The second type.
|
|
103
|
+
*
|
|
104
|
+
* @remarks
|
|
105
|
+
* This type is used to create a type that can be either TLeft or TRight, but not both at the same time.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* // Example 1: XOR type with two object types
|
|
109
|
+
* type A = { a: number };
|
|
110
|
+
* type B = { b: string };
|
|
111
|
+
*
|
|
112
|
+
* const value1: XOR<A, B> = { a: 1 }; // Valid, TLeft type A is assigned
|
|
113
|
+
* const value2: XOR<A, B> = { b: "hello" }; // Valid, TRight type B is assigned
|
|
114
|
+
* const value3: XOR<A, B> = { a: 1, b: "hello" }; // Invalid, both types A and B cannot be assigned at the same time
|
|
115
|
+
*
|
|
116
|
+
* // Example 2: XOR type with object type and string type
|
|
117
|
+
* type C = XOR<A, string>;
|
|
118
|
+
*
|
|
119
|
+
* const value4: C = { a: 1 }; // Valid, object type A is assigned
|
|
120
|
+
* const value5: C = "hello"; // Valid, string type is assigned
|
|
121
|
+
* const value6: C = { a: 1, b: "hello" }; // Invalid, both object type A and string type cannot be assigned at the same time
|
|
122
|
+
*/
|
|
123
|
+
export type XOR<TLeft, TRight> = TLeft | TRight extends object ? (Without<TLeft, TRight> & TRight) | (Without<TRight, TLeft> & TLeft) : TLeft | TRight;
|
|
124
|
+
/**
|
|
125
|
+
* The `Cast` type is designed for casting a value of type {@link TValue} into type {@link TType}, thus making sure {@link TValue} extends {@link TType}.
|
|
126
|
+
*
|
|
127
|
+
* If the casting is impossible ({@link TValue} does not extend {@link TType}), it returns `never`.
|
|
128
|
+
*
|
|
129
|
+
* @template TValue - The type to cast.
|
|
130
|
+
* @template TType - The target type.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* // In this example, the String 'Hello' is attempted to be cast to a number,
|
|
134
|
+
* // which is not possible. Thus, the result would be 'never'.
|
|
135
|
+
* type ImpossibleCasting = Cast<'Hello', number>; // this will be 'never'
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* // In this example, the String 'Hello' is attempted to be cast to a String,
|
|
139
|
+
* // which is possible. Thus, the result would be 'Hello'.
|
|
140
|
+
* type PossibleCasting = Cast<'Hello', string>; // this will be 'Hello'
|
|
141
|
+
*
|
|
142
|
+
*/
|
|
143
|
+
export type Cast<TValue, TType> = TValue extends TType ? TValue : never;
|
|
144
|
+
/**
|
|
145
|
+
* The `PartialWithThis<T>` type extends the functionality of two types: {@link Partial} and {@link ThisType}.
|
|
146
|
+
*
|
|
147
|
+
* It creates a type that represents an object with a subset of properties from the provided
|
|
148
|
+
* type {@link T} merged with a pseudo `this` context for methods, based on the same type parameter.
|
|
149
|
+
*
|
|
150
|
+
* - {@link Partial} makes all properties of the given type optional.
|
|
151
|
+
* - {@link ThisType} defines what `this` refers to within a method of the final object.
|
|
152
|
+
*
|
|
153
|
+
* @template T The type to create a subset from and to use for the pseudo 'this' context.
|
|
154
|
+
*
|
|
155
|
+
* It can be any TypeScript type such as interface, class, primitive, or even another
|
|
156
|
+
* generic type.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```typescript
|
|
160
|
+
* interface MyObject {
|
|
161
|
+
* property1: string;
|
|
162
|
+
* property2: number;
|
|
163
|
+
* method(): void;
|
|
164
|
+
* }
|
|
165
|
+
*
|
|
166
|
+
* let foo: PartialWithThis<MyObject> = {
|
|
167
|
+
* property1: 'Hello',
|
|
168
|
+
* method() {
|
|
169
|
+
* // Here, `this` refers to `MyObject`
|
|
170
|
+
* console.log(this.property1);
|
|
171
|
+
* },
|
|
172
|
+
* // `property2` is optional
|
|
173
|
+
* };
|
|
174
|
+
* ```
|
|
175
|
+
*
|
|
176
|
+
* @remark
|
|
177
|
+
* This type can be useful when working with partial data and object methods that contain a pseudo `this` context.
|
|
178
|
+
*/
|
|
179
|
+
export type PartialWithThis<T> = Partial<T> & ThisType<T>;
|
|
180
|
+
/**
|
|
181
|
+
* Enforce mutually exclusive properties.
|
|
182
|
+
*
|
|
183
|
+
* The `OneOf<T, U>` type ensures that either properties of type {@link T} or properties of type {@link U} are present,
|
|
184
|
+
* but never both at the same time. It is useful for defining states where you want to
|
|
185
|
+
* have exactly one of two possible sets of properties.
|
|
186
|
+
*
|
|
187
|
+
* @template T - The first set of properties.
|
|
188
|
+
* @template U - The second set of properties.
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* // Define a type where you either have data or an error, but not both:
|
|
192
|
+
* type Response = OneOf<
|
|
193
|
+
* { data: Data },
|
|
194
|
+
* { error: ApplicationError | ValidationError }
|
|
195
|
+
* >;
|
|
196
|
+
*
|
|
197
|
+
* // Is equivalent to:
|
|
198
|
+
* type Response = { data: Data, error: never } | { data: never, error: ApplicationError | ValidationError };
|
|
199
|
+
*
|
|
200
|
+
*/
|
|
201
|
+
export type OneOf<T, U> = (T & {
|
|
202
|
+
[K in keyof U]?: never;
|
|
203
|
+
}) | (U & {
|
|
204
|
+
[K in keyof T]?: never;
|
|
205
|
+
});
|
|
206
|
+
/**
|
|
207
|
+
* Enhances a given type by creating a new type from its properties using an intersection with an untyped object.
|
|
208
|
+
*
|
|
209
|
+
* This results in a cleaner and more readable type when inspected, as properties are flattened.
|
|
210
|
+
*
|
|
211
|
+
* @template T - The type to be beautified.
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* Applying `Pretty` to a more complex type:
|
|
215
|
+
* ```typescript
|
|
216
|
+
* interface A {
|
|
217
|
+
* foo: string;
|
|
218
|
+
* bar: number;
|
|
219
|
+
* }
|
|
220
|
+
*
|
|
221
|
+
* interface B {
|
|
222
|
+
* baz: boolean;
|
|
223
|
+
* }
|
|
224
|
+
*
|
|
225
|
+
* type C = A & B;
|
|
226
|
+
* ^ {
|
|
227
|
+
* foo: string;
|
|
228
|
+
* bar: number;
|
|
229
|
+
* baz: boolean;
|
|
230
|
+
* }
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
export type Pretty<T> = {
|
|
234
|
+
[K in keyof T]: T[K];
|
|
235
|
+
} & unknown;
|
|
236
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAEjC,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AAEvB;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,GAAG,CAAC,MAAM,EAAE,IAAI,SAAS,MAAM,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC;AAElE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI;KAAG,IAAI,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;CAAE,CAAC;AAEzD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,MAAM,OAAO,CAAC,KAAK,EAAE,MAAM,IAAI;KAAG,GAAG,IAAI,OAAO,CAAC,MAAM,KAAK,EAAE,MAAM,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK;CAAE,CAAC;AAE7F;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,MAAM,GAAG,CAAC,KAAK,EAAE,MAAM,IAAI,KAAK,GAAG,MAAM,SAAS,MAAM,GAC1D,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,KAAK,CAAC,GACpE,KAAK,GAAG,MAAM,CAAC;AAEnB;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,IAAI,CAAC,MAAM,EAAE,KAAK,IAAI,MAAM,SAAS,KAAK,GAAG,MAAM,GAAG,KAAK,CAAC;AAExE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,GAAG;KAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK;CAAE,CAAC,GAAG,CAAC,CAAC,GAAG;KAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK;CAAE,CAAC,CAAC;AAE9F;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,GAAG,OAAO,CAAC"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `JSONValue` type embodies all potential JSON data forms ({@link JSONPrimitive}, {@link JSONObject}, and {@link JSONArray}).
|
|
3
|
+
*
|
|
4
|
+
* @note `JSONValue` does not introduce any new type parameters; it merely aggregates {@link JSONPrimitive}, {@link JSONObject}, and {@link JSONArray}.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* function processJSON(jsonData: JSONValue): void {
|
|
9
|
+
* if (Array.isArray(jsonData)) {
|
|
10
|
+
* console.log('This is a JSONArray: ', JSON.stringify(jsonData, null, 2));
|
|
11
|
+
* } else if (typeof jsonData === 'object') {
|
|
12
|
+
* console.log('This is a JSONObject: ', JSON.stringify(jsonData, null, 2));
|
|
13
|
+
* } else {
|
|
14
|
+
* console.log('This is a JSONPrimitive: ', jsonData);
|
|
15
|
+
* }
|
|
16
|
+
* }
|
|
17
|
+
*
|
|
18
|
+
* processJSON(['hello', { anotherKey: 'anotherValue' }]);
|
|
19
|
+
* // This is a JSONArray: ["hello", { "anotherKey": "anotherValue" }]
|
|
20
|
+
*
|
|
21
|
+
* processJSON({ key: 'value' });
|
|
22
|
+
* // This is a JSONObject: { "key": "value" }
|
|
23
|
+
*
|
|
24
|
+
* processJSON(10);
|
|
25
|
+
* // This is a JSONPrimitive: 10
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @see {@link JSONPrimitive} - The simplest form of `JSONValue`, corresponds to basic JSON data types.
|
|
29
|
+
* @see {@link JSONObject} - A potential `JSONValue`, encapsulates JSON object structures.
|
|
30
|
+
* @see {@link JSONArray} - A potential `JSONValue`, encapsulates JSON arrays.
|
|
31
|
+
*/
|
|
32
|
+
export type JSONValue = JSONPrimitive | JSONObject | JSONArray;
|
|
33
|
+
/**
|
|
34
|
+
* The `JSONPrimitive` type models the fundamental data types (`string`, `number`, `boolean`, `null`) of JSON in TypeScript.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* declare function set(key: string, value: JSONPrimitive): void;
|
|
39
|
+
*
|
|
40
|
+
* set('string', 'foo'); // This is valid
|
|
41
|
+
* set('number', 42); // This is valid
|
|
42
|
+
* set('boolean', true); // This is valid
|
|
43
|
+
* set('null', null); // This is valid
|
|
44
|
+
* set('array', []); // Error
|
|
45
|
+
* set('undefined', undefined); // Error
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @see {@link JSONValue} - The potential forms of JSON data, including `JSONPrimitive`.
|
|
49
|
+
* @see {@link JSONObject} - Incorporated in {@link JSONValue}, represents JSON objects.
|
|
50
|
+
* @see {@link JSONArray} - Incorporated in {@link JSONValue}, represents JSON arrays.
|
|
51
|
+
*
|
|
52
|
+
* @remarks
|
|
53
|
+
* `JSONPrimitive` provides a foundation for describing JSON data.
|
|
54
|
+
* Combined with {@link JSONObject} and {@link JSONArray}, they encompass all possible JSON data types.
|
|
55
|
+
*/
|
|
56
|
+
export type JSONPrimitive = string | number | boolean | null;
|
|
57
|
+
/**
|
|
58
|
+
* The `JSONArray` type models a standard JSON array in TypeScript, which allows manipulation of arrays of {@link JSONValue} elements.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* // Create a JSONArray consisting of different JSONValues
|
|
63
|
+
* let jsonArray: JSONArray = ['hello', 10, true, null, {key: 'value'}, ['nested array']];
|
|
64
|
+
*
|
|
65
|
+
* function prettyPrint(jsonArray: JSONArray): void {
|
|
66
|
+
* jsonArray.forEach(item => {
|
|
67
|
+
* if(typeof item === 'object' && item !== null) {
|
|
68
|
+
* // If it's a JSONObject or another JSONArray, stringify it
|
|
69
|
+
* console.log(JSON.stringify(item, null, 2));
|
|
70
|
+
* } else {
|
|
71
|
+
* // If it's a JSONPrimitive, print it directly
|
|
72
|
+
* console.log(item);
|
|
73
|
+
* }
|
|
74
|
+
* });
|
|
75
|
+
* }
|
|
76
|
+
*
|
|
77
|
+
* prettyPrint(jsonArray); // Will print all items in a friendly format to the console
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* This type is part of a series of types used for modeling all possible JSON values in TypeScript.
|
|
81
|
+
* @see {@link JSONValue} - The supertype of all elements that a `JSONArray` can contain.
|
|
82
|
+
* @see {@link JSONPrimitive} - The simplest kind of `JSONValue` that a `JSONArray` can contain.
|
|
83
|
+
* @see {@link JSONObject} - A possible `JSONValue` that a `JSONArray` can contain.
|
|
84
|
+
*
|
|
85
|
+
* @remarks
|
|
86
|
+
* The `JSONArray` is a versatile type that can contain various kinds of JSON data, even nested arrays or objects.
|
|
87
|
+
*/
|
|
88
|
+
export type JSONArray = Array<JSONValue>;
|
|
89
|
+
/**
|
|
90
|
+
* The `JSONObject` interface formally defines a JavaScript object with string keys and values of type {@link JSONValue}.
|
|
91
|
+
*
|
|
92
|
+
* It models standard JSON objects as TypeScript types, facilitating their manipulation.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* function addToJSONObject(key: string, value: JSONValue, jsonObject: JSONObject): JSONObject {
|
|
97
|
+
* // Copy the existing JSONObject
|
|
98
|
+
* let updatedObject: JSONObject = { ...jsonObject };
|
|
99
|
+
*
|
|
100
|
+
* // Add the new key-value pair
|
|
101
|
+
* updatedObject[key] = value;
|
|
102
|
+
*
|
|
103
|
+
* // Return the updated JSONObject
|
|
104
|
+
* return updatedObject;
|
|
105
|
+
* }
|
|
106
|
+
* ```
|
|
107
|
+
*
|
|
108
|
+
* @see {@link JSONValue} - The permitted types for values within the `JSONObject` (primitives, objects, or arrays).
|
|
109
|
+
* @see {@link JSONPrimitive} - The basis for JSON data, used in {@link JSONValue}.
|
|
110
|
+
* @see {@link JSONArray} - Arrays used in {@link JSONValue}.
|
|
111
|
+
*
|
|
112
|
+
* @remarks
|
|
113
|
+
* The keys of the `JSONObject` are always of type string, as per the standard JSON specification.
|
|
114
|
+
* Values may take any valid {@link JSONValue}, allowing nested data structures.
|
|
115
|
+
*/
|
|
116
|
+
export interface JSONObject {
|
|
117
|
+
[key: string]: JSONValue;
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=json.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../src/utils/json.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG,UAAU,GAAG,SAAS,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,WAAW,UAAU;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1B"}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts object's (`TValue`) keys where the key's value type extends the given `TTest` type.
|
|
3
|
+
*
|
|
4
|
+
* @template TValue - The original object type.
|
|
5
|
+
* @template TTest - The test type. Keys of TValue having values that extend this type are extracted.
|
|
6
|
+
* @template TExtract - An optional constraint for the keys of TValue.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
*
|
|
10
|
+
* // Here TValue is `{ foo: 'bar', bar: 'foo', foobar: 2 }` and TTest is `string`.
|
|
11
|
+
* // So it extracts keys `foo` and `bar`, because their values are string type.
|
|
12
|
+
* type keys = KeysBy<{ foo: 'bar', bar: 'foo', foobar: 2 }, string> // 'foo' | 'bar'
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
*
|
|
16
|
+
* // Here TValue is `{ foo: { x: 'foo' }, bar: { x: 'bar' }, other: { x: '42' } }` and TTest is `{ x: 'foo' | 'bar' }`.
|
|
17
|
+
* // So it extracts keys `foo` and `bar`, because their values are extending `{ x: 'foo' | 'bar' }`.
|
|
18
|
+
* type Base = { x: 'foo' | 'bar' };
|
|
19
|
+
* type Obj = { foo: { x: 'foo' }, bar: { x: 'bar' }, other: { x: '42' } };
|
|
20
|
+
* type X = KeysBy<Obj, Base> // 'foo' | 'bar'
|
|
21
|
+
*
|
|
22
|
+
* @see {@link KeysExcept}
|
|
23
|
+
* @see {@link PickBy}
|
|
24
|
+
*/
|
|
25
|
+
export type KeysBy<TValue, TTest, TExtract extends keyof any = keyof any> = {
|
|
26
|
+
[key in keyof TValue & TExtract]: TValue[key] extends TTest ? key : never;
|
|
27
|
+
}[keyof TValue & TExtract];
|
|
28
|
+
/**
|
|
29
|
+
* Extracts the keys of a given object ({@link TValue}). It includes only those keys which do not map to a value of type {@link TTest}`.
|
|
30
|
+
*
|
|
31
|
+
* @template TValue - The object whose keys are to be examined and selectively retrieved
|
|
32
|
+
* @template TTest - The type of value to be used as an exclusion criterion for selecting keys from `TValue`
|
|
33
|
+
* @template TExtract - An optional union of keys to constrain the keys that are being examined. If not provided, it defaults to examining all keys in `TValue`.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* // In this example, KeysExcept is used to fetch keys from the object which do not have string type values
|
|
38
|
+
* type ExampleType = { foo: 'bar', bar: 'foo', foobar: 2 }
|
|
39
|
+
* type ResultType = KeysExcept<ExampleType, string>
|
|
40
|
+
* // The resulting type is "foobar"
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* // In this example, we use a base type to define allowed value types and only fetch those keys from the object that have values not extending the base type
|
|
46
|
+
* type Base = { x: 'foo' | 'bar' };
|
|
47
|
+
* type Obj = { foo: { x: 'foo' }, bar: { x: 'bar' }, other: { x: '42' } };
|
|
48
|
+
* type X = KeysBy<Obj, Base>
|
|
49
|
+
* // The resulting type is "other"
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export type KeysExcept<TValue, TTest, TExtract extends keyof any = keyof any> = {
|
|
53
|
+
[key in keyof TValue & TExtract]: TValue[key] extends TTest ? never : key;
|
|
54
|
+
}[keyof TValue & TExtract];
|
|
55
|
+
/**
|
|
56
|
+
* Select properties from an object ({@link TValue}), only if their types extend a specific test type ({@link TTest}).
|
|
57
|
+
*
|
|
58
|
+
* @template TValue - The object type from which properties are selected.
|
|
59
|
+
* @template TTest - The test type. Properties of TValue extending this type are selected.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
*
|
|
63
|
+
* // If we have this:
|
|
64
|
+
* type FruitAttributes = { color: string, taste: string, weight: number, isOrganic: boolean };
|
|
65
|
+
*
|
|
66
|
+
* // And we use `PickBy` like so:
|
|
67
|
+
* type StringAttributes = PickBy<FruitAttributes, string>;
|
|
68
|
+
*
|
|
69
|
+
* // Then, `StringAttributes` will equal: `{ color: string, taste: string }`
|
|
70
|
+
*/
|
|
71
|
+
export type PickBy<TValue, TTest> = Pick<TValue, KeysBy<TValue, TTest>>;
|
|
72
|
+
/**
|
|
73
|
+
* Creates a new type from a given type ({@link TValue}), and select specific
|
|
74
|
+
* keys ({@link TKeys}) to be optionally present in the new type.
|
|
75
|
+
*
|
|
76
|
+
* @template TValue The original type of object.
|
|
77
|
+
* @template TKeys A union of selected {@link TValue} object keys that should be partial/optional in the new type.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* type Person = {
|
|
82
|
+
* name: string;
|
|
83
|
+
* age: number;
|
|
84
|
+
* };
|
|
85
|
+
*
|
|
86
|
+
* type PartialAgePerson = PartialBy<Person, 'age'>;
|
|
87
|
+
*
|
|
88
|
+
* // the type PartialAgePerson is now equivalent to:
|
|
89
|
+
* // {
|
|
90
|
+
* // name: string;
|
|
91
|
+
* // age?: number;
|
|
92
|
+
* // }
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
export type PartialBy<TValue, TKeys extends keyof TValue> = Omit<TValue, TKeys> & Partial<Pick<TValue, TKeys>>;
|
|
96
|
+
/**
|
|
97
|
+
* Extracts all unique values from a given object as a union type.
|
|
98
|
+
*
|
|
99
|
+
* @template TObject - An object from which values are to be extracted. It must extend the `object` type.
|
|
100
|
+
*
|
|
101
|
+
* @remark
|
|
102
|
+
* It works with non-primitive values as well. Hence, if a value is an object, it is included as is. Primitive types are included directly.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* With a simple object:
|
|
106
|
+
* ```TypeScript
|
|
107
|
+
* type SimpleExample = Values<{
|
|
108
|
+
* a: 'one',
|
|
109
|
+
* b: 'two',
|
|
110
|
+
* c: 3
|
|
111
|
+
* }>;
|
|
112
|
+
* // Result: 'one' | 'two' | 3
|
|
113
|
+
* ```
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* With complex (non-primitive) values in an object:
|
|
117
|
+
* ```TypeScript
|
|
118
|
+
* type ComplexExample = Values<{
|
|
119
|
+
* a: { x: 10 },
|
|
120
|
+
* b: { y: 'twenty' },
|
|
121
|
+
* c: { z: true }
|
|
122
|
+
* }>;
|
|
123
|
+
* // Result: { x: 10 } | { y: 'twenty' } | { z: true }
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
export type Values<TObject extends object> = TObject[keyof TObject];
|
|
127
|
+
/**
|
|
128
|
+
* Provides a way to set deeply-nested properties within `TObject` to optional.
|
|
129
|
+
*
|
|
130
|
+
* @template TObject Type of the object that will become deeply partial.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```typescript
|
|
134
|
+
* interface Person {
|
|
135
|
+
* name: string;
|
|
136
|
+
* age: number;
|
|
137
|
+
* address: {
|
|
138
|
+
* city: string;
|
|
139
|
+
* street: string;
|
|
140
|
+
* postalCode: number;
|
|
141
|
+
* };
|
|
142
|
+
* }
|
|
143
|
+
*
|
|
144
|
+
* const partialPerson: DeepPartial<Person> = {}; // This is now valid
|
|
145
|
+
*
|
|
146
|
+
* // You can assign partially filled objects
|
|
147
|
+
* const anotherPerson: DeepPartial<Person> = {
|
|
148
|
+
* name: 'John',
|
|
149
|
+
* address: {
|
|
150
|
+
* city: 'San Francisco',
|
|
151
|
+
* // street and postal code are optional
|
|
152
|
+
* }
|
|
153
|
+
* }
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
export type DeepPartial<TObject> = TObject extends object ? {
|
|
157
|
+
[TKey in keyof TObject]?: DeepPartial<TObject[TKey]>;
|
|
158
|
+
} : TObject;
|
|
159
|
+
/**
|
|
160
|
+
* Creates a new type by replacing properties of {@link TObject} with properties from {@link TNew}.
|
|
161
|
+
*
|
|
162
|
+
* This is particularly useful to fine-tune the shape of an object type by altering some of its properties while keeping the rest intact.
|
|
163
|
+
*
|
|
164
|
+
* @template TObject - A type that extends `object`. This should be the original type that you intend to transform.
|
|
165
|
+
* @template TNew - A partial type of {@link TObject} where keys are replaced with new types.
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
*
|
|
169
|
+
* ```typescript
|
|
170
|
+
* type Original = { foo: number, bar: number}; // Declare original type
|
|
171
|
+
* type Transformation = { foo: string }; // Declare keys to replace from original type
|
|
172
|
+
*
|
|
173
|
+
* type Result = Replace<Original, Transformation>;
|
|
174
|
+
* // The transformed type now becomes { foo: string, bar: number }
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
export type Replace<TObject extends object, TNew extends Partial<{
|
|
178
|
+
[key in keyof TObject]: unknown;
|
|
179
|
+
}>> = Omit<TObject, keyof TNew> & TNew;
|
|
180
|
+
//# sourceMappingURL=object.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../src/utils/object.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,MAAM,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,SAAS,MAAM,GAAG,GAAG,MAAM,GAAG,IAAI;KACzE,GAAG,IAAI,MAAM,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,SAAS,KAAK,GAAG,GAAG,GAAG,KAAK;CAC1E,CAAC,MAAM,MAAM,GAAG,QAAQ,CAAC,CAAC;AAE3B;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,MAAM,UAAU,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,SAAS,MAAM,GAAG,GAAG,MAAM,GAAG,IAAI;KAC7E,GAAG,IAAI,MAAM,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,SAAS,KAAK,GAAG,KAAK,GAAG,GAAG;CAC1E,CAAC,MAAM,MAAM,GAAG,QAAQ,CAAC,CAAC;AAE3B;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,MAAM,CAAC,MAAM,EAAE,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;AAExE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,MAAM,SAAS,CAAC,MAAM,EAAE,KAAK,SAAS,MAAM,MAAM,IAAI,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,GAC7E,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;AAE/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,MAAM,MAAM,CAAC,OAAO,SAAS,MAAM,IAAI,OAAO,CAAC,MAAM,OAAO,CAAC,CAAC;AAEpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,MAAM,WAAW,CAAC,OAAO,IAAI,OAAO,SAAS,MAAM,GACrD;KACG,IAAI,IAAI,MAAM,OAAO,CAAC,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;CACrD,GACD,OAAO,CAAC;AAEZ;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,OAAO,CACjB,OAAO,SAAS,MAAM,EACtB,IAAI,SAAS,OAAO,CAAC;KAAG,GAAG,IAAI,MAAM,OAAO,GAAG,OAAO;CAAE,CAAC,IACvD,IAAI,CAAC,OAAO,EAAE,MAAM,IAAI,CAAC,GAAG,IAAI,CAAC"}
|