@narrative.io/data-collaboration-sdk-ts 4.4.0 → 4.6.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/build/base-api.d.ts +11 -0
- package/build/base-api.js +15 -0
- package/build/data-planes/types.d.ts +52 -115
- package/build/derivations/index.d.ts +84 -0
- package/build/derivations/index.js +93 -0
- package/build/derivations/types.d.ts +56 -0
- package/build/derivations/types.js +1 -0
- package/build/generated/api-types.d.ts +7112 -5185
- package/build/generated/api-types.js +1 -1
- package/build/http-client.d.ts +1 -0
- package/build/http-client.js +3 -0
- package/build/index.d.ts +4 -1
- package/build/index.js +4 -0
- package/build/jobs/index.d.ts +2 -2
- package/build/jobs/types.d.ts +137 -337
- package/build/jobs/types.js +3 -3
- package/build/model-training/index.d.ts +21 -5
- package/build/model-training/index.js +20 -4
- package/build/model-training/types.d.ts +69 -6
- package/build/nql/index.d.ts +28 -2
- package/build/nql/index.js +28 -0
- package/build/nql/types.d.ts +16 -4
- package/build/rosetta/types.d.ts +1 -1
- package/build/testing/fixtures/data-planes.d.ts +5 -1
- package/build/testing/fixtures/data-planes.js +16 -6
- package/build/testing/fixtures/derivations.d.ts +18 -0
- package/build/testing/fixtures/derivations.js +43 -0
- package/build/testing/fixtures/index.d.ts +4 -0
- package/build/testing/fixtures/index.js +4 -0
- package/build/testing/fixtures/jobs.d.ts +75 -0
- package/build/testing/fixtures/jobs.js +433 -0
- package/build/testing/fixtures/model-training.d.ts +8 -0
- package/build/testing/fixtures/model-training.js +12 -0
- package/build/testing/fixtures/nql.d.ts +10 -0
- package/build/testing/fixtures/nql.js +37 -0
- package/build/testing/index.d.ts +14 -2
- package/build/testing/index.js +13 -1
- package/build/testing/types.d.ts +45 -1
- package/package.json +4 -3
package/build/base-api.d.ts
CHANGED
|
@@ -86,6 +86,17 @@ export declare abstract class BaseApi {
|
|
|
86
86
|
* @returns A Promise that resolves to the data returned by the server.
|
|
87
87
|
*/
|
|
88
88
|
protected put<I, T>(endpoint: string, data: I): Promise<T>;
|
|
89
|
+
/**
|
|
90
|
+
* Makes a PATCH request to the specified endpoint with the given data.
|
|
91
|
+
*
|
|
92
|
+
* Unlike {@link BaseApi.put}, a PATCH body carries only the fields being
|
|
93
|
+
* changed — the endpoints that accept one leave everything else as it is.
|
|
94
|
+
*
|
|
95
|
+
* @param endpoint - The endpoint to make the request to.
|
|
96
|
+
* @param data - The fields to change.
|
|
97
|
+
* @returns A Promise that resolves to the data returned by the server.
|
|
98
|
+
*/
|
|
99
|
+
protected patch<I, T>(endpoint: string, data: I): Promise<T>;
|
|
89
100
|
/**
|
|
90
101
|
* Returns the base URL for the API based on the environment.
|
|
91
102
|
*
|
package/build/base-api.js
CHANGED
|
@@ -137,6 +137,21 @@ export class BaseApi {
|
|
|
137
137
|
console.log(`Making GET request to ${endpoint} with data: ${JSON.stringify(data)}...`);
|
|
138
138
|
return await this.base_api.put(endpoint, data);
|
|
139
139
|
}
|
|
140
|
+
/**
|
|
141
|
+
* Makes a PATCH request to the specified endpoint with the given data.
|
|
142
|
+
*
|
|
143
|
+
* Unlike {@link BaseApi.put}, a PATCH body carries only the fields being
|
|
144
|
+
* changed — the endpoints that accept one leave everything else as it is.
|
|
145
|
+
*
|
|
146
|
+
* @param endpoint - The endpoint to make the request to.
|
|
147
|
+
* @param data - The fields to change.
|
|
148
|
+
* @returns A Promise that resolves to the data returned by the server.
|
|
149
|
+
*/
|
|
150
|
+
async patch(endpoint, data) {
|
|
151
|
+
if (this.verbose)
|
|
152
|
+
console.log(`Making PATCH request to ${endpoint} with data: ${JSON.stringify(data)}...`);
|
|
153
|
+
return await this.base_api.patch(endpoint, data);
|
|
154
|
+
}
|
|
140
155
|
/**
|
|
141
156
|
* Returns the base URL for the API based on the environment.
|
|
142
157
|
*
|
|
@@ -1,136 +1,73 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { components } from "../generated/api-types";
|
|
2
2
|
import type { Job } from "../jobs/types";
|
|
3
|
-
/** Discriminator distinguishing an owned data plane from one shared with you. */
|
|
4
|
-
export type DataPlaneType = "owned" | "shared";
|
|
5
3
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* confirmed in the backend and was removed).
|
|
4
|
+
* Discriminator distinguishing a data plane the calling company owns from one
|
|
5
|
+
* shared with it.
|
|
9
6
|
*/
|
|
10
|
-
export type
|
|
11
|
-
/**
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export interface AzureRegion {
|
|
17
|
-
type: "region_azure";
|
|
18
|
-
id: string;
|
|
19
|
-
}
|
|
20
|
-
export interface GcpRegion {
|
|
21
|
-
type: "region_gcp";
|
|
22
|
-
id: string;
|
|
23
|
-
}
|
|
7
|
+
export type DataPlaneType = DataPlane["type"];
|
|
8
|
+
/** Lifecycle status of a data plane. */
|
|
9
|
+
export type DataPlaneStatus = DataPlane["status"];
|
|
10
|
+
export type AwsRegion = components["schemas"]["AwsRegion"];
|
|
11
|
+
export type AzureRegion = components["schemas"]["AzureRegion"];
|
|
12
|
+
export type GcpRegion = components["schemas"]["GcpRegion"];
|
|
24
13
|
/**
|
|
25
|
-
* The region a data plane runs in.
|
|
26
|
-
*
|
|
14
|
+
* The region a data plane runs in. A discriminated object rather than the bare
|
|
15
|
+
* region code a caller might expect: `{ type: "region_aws", id: "us-east-1" }`.
|
|
27
16
|
*/
|
|
28
|
-
export type DataPlaneRegion =
|
|
29
|
-
export
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
account_name: string;
|
|
39
|
-
organization_name: string;
|
|
40
|
-
/**
|
|
41
|
-
* The platform can fail to parse a region when provisioning the Snowflake
|
|
42
|
-
* Native App, so this is informational only. Responses always carry the key,
|
|
43
|
-
* with an explicit `null` when there is no region.
|
|
44
|
-
*/
|
|
45
|
-
region?: DataPlaneRegion | null;
|
|
46
|
-
}
|
|
17
|
+
export type DataPlaneRegion = components["schemas"]["Region"];
|
|
18
|
+
export type AwsPlatform = components["schemas"]["AwsPlatform"];
|
|
19
|
+
/**
|
|
20
|
+
* Snowflake platform details for a data plane the calling company owns.
|
|
21
|
+
*
|
|
22
|
+
* `region` is informational. Provisioning the Snowflake Native App can fail to
|
|
23
|
+
* parse a region, and the response then carries an explicit `null` rather than
|
|
24
|
+
* omitting the key.
|
|
25
|
+
*/
|
|
26
|
+
export type SnowflakePlatform = components["schemas"]["SnowflakePlatform"];
|
|
47
27
|
/** Platform details returned for a data plane the calling company owns. */
|
|
48
|
-
export type DataPlanePlatform =
|
|
49
|
-
export
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
export interface SnowflakeSharedPlatform {
|
|
54
|
-
type: "platform_shared_snowflake";
|
|
55
|
-
/** Nullable for the same reason as {@link SnowflakePlatform.region}. */
|
|
56
|
-
region?: DataPlaneRegion | null;
|
|
57
|
-
}
|
|
28
|
+
export type DataPlanePlatform = components["schemas"]["Platform"];
|
|
29
|
+
export type AwsSharedPlatform = components["schemas"]["AwsSharedResponse"];
|
|
30
|
+
/** `region` is informational for the same reason as on {@link SnowflakePlatform}. */
|
|
31
|
+
export type SnowflakeSharedPlatform = components["schemas"]["SnowflakeSharedResponse"];
|
|
58
32
|
/**
|
|
59
|
-
* Platform details returned for a data plane shared with
|
|
60
|
-
* identifiers are omitted for
|
|
33
|
+
* Platform details returned for a data plane shared with the calling company.
|
|
34
|
+
* Account identifiers are omitted for planes the company does not own.
|
|
61
35
|
*/
|
|
62
|
-
export type DataPlaneSharedPlatform =
|
|
36
|
+
export type DataPlaneSharedPlatform = components["schemas"]["PlatformSharedResponse"];
|
|
63
37
|
/**
|
|
64
|
-
* The `platform.type` discriminator of any data plane, owned or shared. Owned and
|
|
65
|
-
* are modelled as separate unions, so this is the flat set of
|
|
38
|
+
* The `platform.type` discriminator of any data plane, owned or shared. Owned and
|
|
39
|
+
* shared platforms are modelled as separate unions, so this is the flat set of
|
|
40
|
+
* wire literals across both.
|
|
66
41
|
*/
|
|
67
42
|
export type DataPlanePlatformType = DataPlanePlatform["type"] | DataPlaneSharedPlatform["type"];
|
|
68
|
-
export
|
|
69
|
-
participants: Participants;
|
|
70
|
-
/** Companies allowed to create/edit/archive compute pools on this data plane. */
|
|
71
|
-
manage_compute_pools: Participants;
|
|
72
|
-
}
|
|
43
|
+
export type DataPlaneCollaborators = components["schemas"]["DataPlaneCollaborators"];
|
|
73
44
|
/**
|
|
74
|
-
* A data plane
|
|
45
|
+
* A data plane the calling company owns. Includes full details such as the
|
|
75
46
|
* external id and collaborators.
|
|
47
|
+
*
|
|
48
|
+
* `compute_pools` is always present, and empty when the plane has no pools.
|
|
49
|
+
* `description`, `tags`, `last_heartbeat_at` and `default_compute_pool_id` arrive
|
|
50
|
+
* as an explicit `null` when absent rather than being omitted, so a consumer that
|
|
51
|
+
* checks for `undefined` will not see one. A plane with no tags sends
|
|
52
|
+
* `tags: null` rather than `[]`.
|
|
76
53
|
*/
|
|
77
|
-
export
|
|
78
|
-
type: "owned";
|
|
79
|
-
/** UUID. */
|
|
80
|
-
id: string;
|
|
81
|
-
company_id: number;
|
|
82
|
-
created_at: string;
|
|
83
|
-
display_name: string;
|
|
84
|
-
external_id: string;
|
|
85
|
-
platform: DataPlanePlatform;
|
|
86
|
-
status: DataPlaneStatus;
|
|
87
|
-
updated_at: string;
|
|
88
|
-
collaborators: DataPlaneCollaborators;
|
|
89
|
-
/**
|
|
90
|
-
* Always present, empty when the plane has no pools: the backend field is a
|
|
91
|
-
* plain `List`, never an `Option`.
|
|
92
|
-
*/
|
|
93
|
-
compute_pools: ComputePoolResponse[];
|
|
94
|
-
/**
|
|
95
|
-
* The response encoder does not drop nulls, so each of these four arrives as
|
|
96
|
-
* an explicit `null` when absent rather than being left out. `tags` is `null`
|
|
97
|
-
* for a plane with no tags too — `DataPlaneResponse.apply` maps an empty list
|
|
98
|
-
* to `None` — though a directly constructed response can still send `[]`.
|
|
99
|
-
*/
|
|
100
|
-
description?: string | null;
|
|
101
|
-
tags?: string[] | null;
|
|
102
|
-
last_heartbeat_at?: string | null;
|
|
103
|
-
default_compute_pool_id?: string | null;
|
|
104
|
-
}
|
|
54
|
+
export type DataPlaneOwnedResponse = components["schemas"]["DataPlaneOwnedResponse"];
|
|
105
55
|
/**
|
|
106
56
|
* A data plane shared with the calling company. Omits details like the external
|
|
107
|
-
* id and collaborators that are only exposed to the owner.
|
|
57
|
+
* id and collaborators that are only exposed to the owner. `compute_pools` and
|
|
58
|
+
* the four nullable fields behave as they do on {@link DataPlaneOwnedResponse}.
|
|
108
59
|
*/
|
|
109
|
-
export
|
|
110
|
-
type: "shared";
|
|
111
|
-
/** UUID. */
|
|
112
|
-
id: string;
|
|
113
|
-
company_id: number;
|
|
114
|
-
created_at: string;
|
|
115
|
-
display_name: string;
|
|
116
|
-
platform: DataPlaneSharedPlatform;
|
|
117
|
-
status: DataPlaneStatus;
|
|
118
|
-
updated_at: string;
|
|
119
|
-
/** Required for the same reason as {@link DataPlaneOwnedResponse.compute_pools}. */
|
|
120
|
-
compute_pools: ComputePoolResponse[];
|
|
121
|
-
/** Nullable for the same reason as on {@link DataPlaneOwnedResponse}. */
|
|
122
|
-
description?: string | null;
|
|
123
|
-
tags?: string[] | null;
|
|
124
|
-
last_heartbeat_at?: string | null;
|
|
125
|
-
default_compute_pool_id?: string | null;
|
|
126
|
-
}
|
|
60
|
+
export type DataPlaneSharedResponse = components["schemas"]["DataPlaneSharedResponse"];
|
|
127
61
|
/** Discriminated union of the owned/shared data plane response shapes. */
|
|
128
|
-
export type DataPlane =
|
|
129
|
-
export
|
|
130
|
-
compute_pool_id?: string;
|
|
131
|
-
}
|
|
62
|
+
export type DataPlane = components["schemas"]["DataPlaneResponse"];
|
|
63
|
+
export type HealthCheckRequest = components["schemas"]["EnqueueHealthCheckRequest"];
|
|
132
64
|
/**
|
|
133
|
-
* The backend enqueues a `health_check` job and returns the full job record (201
|
|
134
|
-
* not just its id
|
|
65
|
+
* The backend enqueues a `health_check` job and returns the full job record (201
|
|
66
|
+
* Created), not just its id.
|
|
67
|
+
*
|
|
68
|
+
* This one name stays on the SDK's own {@link Job} rather than the spec's
|
|
69
|
+
* `JobResponse`. The spec types a job's `type` as an open string with opaque
|
|
70
|
+
* `input` and `result`, while `Job` is a discriminated union over the known job
|
|
71
|
+
* types that `isKnownJob` narrows.
|
|
135
72
|
*/
|
|
136
73
|
export type HealthCheckJobResponse = Job;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { BaseApi } from "../base-api";
|
|
2
|
+
import type { Derivation, DerivationCollaborators, DerivationCost, DerivationCreateRequest, DerivationMapping, DerivationsResponse, DerivationUpdateRequest, DerivationWarning, ListDerivationsParams } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* `DerivationsApi` wraps the derivation-rule endpoints. A derivation rule says
|
|
5
|
+
* how one attribute's value can be produced from another's — hashing a raw
|
|
6
|
+
* email, bucketing a birthdate into an age range — and the platform applies it
|
|
7
|
+
* when a query asks for the target attribute and only the source is available.
|
|
8
|
+
*
|
|
9
|
+
* Reads cover the rules the calling company can use: the ones it owns plus the
|
|
10
|
+
* ones shared with it through collaborators. Writes are narrower — they need an
|
|
11
|
+
* `admin` grant on `attribute_derivations`, and only the owning company can
|
|
12
|
+
* change or delete a rule.
|
|
13
|
+
*/
|
|
14
|
+
export declare class DerivationsApi extends BaseApi {
|
|
15
|
+
/**
|
|
16
|
+
* Lists the derivation rules the calling company can use, optionally
|
|
17
|
+
* filtered by source or target attribute.
|
|
18
|
+
*
|
|
19
|
+
* @param {ListDerivationsParams} [params] - Attribute-id filters. Each accepts
|
|
20
|
+
* several ids.
|
|
21
|
+
* @returns {Promise<DerivationsResponse>} The matching rules, with empty
|
|
22
|
+
* `warnings` — reads do not compute them.
|
|
23
|
+
* @see https://docs.narrative.io/api-reference/derivations/get-derivation-rules
|
|
24
|
+
*/
|
|
25
|
+
listDerivations(params?: ListDerivationsParams): Promise<DerivationsResponse>;
|
|
26
|
+
/**
|
|
27
|
+
* Fetches a single rule.
|
|
28
|
+
*
|
|
29
|
+
* @param {number} derivationId - Id of the rule.
|
|
30
|
+
* @returns {Promise<Derivation>} The rule. Rejects with 404 if no rule with
|
|
31
|
+
* that id is usable by the calling company — rules belonging to someone else
|
|
32
|
+
* are not distinguished from rules that do not exist.
|
|
33
|
+
* @see https://docs.narrative.io/api-reference/derivations/get-a-derivation-rule
|
|
34
|
+
*/
|
|
35
|
+
getDerivation(derivationId: number): Promise<Derivation>;
|
|
36
|
+
/**
|
|
37
|
+
* Creates a rule, owned by the calling company.
|
|
38
|
+
*
|
|
39
|
+
* The transformation is validated before the rule can exist: both attributes
|
|
40
|
+
* must be viewable, the target must grant the company `map` since the rule
|
|
41
|
+
* produces values for it, every expression must parse and type-check against
|
|
42
|
+
* the source attribute's shape, and the result must match the target's
|
|
43
|
+
* declared type.
|
|
44
|
+
*
|
|
45
|
+
* A rule that closes a cycle in the derivation graph is still created — the
|
|
46
|
+
* cycle comes back as a `cyclic_derivation` warning on the response rather
|
|
47
|
+
* than as an error.
|
|
48
|
+
*
|
|
49
|
+
* @param {DerivationCreateRequest} request - The rule to create.
|
|
50
|
+
* @returns {Promise<Derivation>} The created rule, with any warnings. Rejects
|
|
51
|
+
* with 400 if the transformation fails validation; 403 if the caller is not
|
|
52
|
+
* an admin, the rule's company or collaborators are not allowed, or the
|
|
53
|
+
* target attribute does not grant `map`; 409 if another of the company's
|
|
54
|
+
* rules already has the same name or already covers the same source and
|
|
55
|
+
* target pair.
|
|
56
|
+
* @see https://docs.narrative.io/api-reference/derivations/create-a-derivation-rule
|
|
57
|
+
*/
|
|
58
|
+
createDerivation(request: DerivationCreateRequest): Promise<Derivation>;
|
|
59
|
+
/**
|
|
60
|
+
* Updates some fields of a rule. Only the keys present in `request` change,
|
|
61
|
+
* and a changed `mapping` runs the same validation as a creation.
|
|
62
|
+
*
|
|
63
|
+
* @param {number} derivationId - Id of the rule.
|
|
64
|
+
* @param {DerivationUpdateRequest} request - The fields to change.
|
|
65
|
+
* @returns {Promise<Derivation>} The updated rule, with any warnings. Rejects
|
|
66
|
+
* with 400 if the update fails validation; 403 if the caller is not an admin
|
|
67
|
+
* or does not own the rule; 404 if there is no rule with that id.
|
|
68
|
+
* @see https://docs.narrative.io/api-reference/derivations/update-a-derivation-rule
|
|
69
|
+
*/
|
|
70
|
+
updateDerivation(derivationId: number, request: DerivationUpdateRequest): Promise<Derivation>;
|
|
71
|
+
/**
|
|
72
|
+
* Permanently removes a rule. To take a rule out of use while keeping it,
|
|
73
|
+
* pass `{ active: false }` to {@link DerivationsApi.updateDerivation}
|
|
74
|
+
* instead — deletions cannot be undone.
|
|
75
|
+
*
|
|
76
|
+
* @param {number} derivationId - Id of the rule.
|
|
77
|
+
* @returns {Promise<void>} Resolves when deleted. Rejects with 403 if the
|
|
78
|
+
* caller is not an admin or does not own the rule; 404 if there is no rule
|
|
79
|
+
* with that id.
|
|
80
|
+
* @see https://docs.narrative.io/api-reference/derivations/delete-a-derivation-rule
|
|
81
|
+
*/
|
|
82
|
+
deleteDerivation(derivationId: number): Promise<void>;
|
|
83
|
+
}
|
|
84
|
+
export type { Derivation, DerivationCollaborators, DerivationCost, DerivationCreateRequest, DerivationMapping, DerivationsResponse, DerivationUpdateRequest, DerivationWarning, ListDerivationsParams, };
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { BaseApi } from "../base-api";
|
|
2
|
+
const resourceName = "derivations";
|
|
3
|
+
/**
|
|
4
|
+
* `DerivationsApi` wraps the derivation-rule endpoints. A derivation rule says
|
|
5
|
+
* how one attribute's value can be produced from another's — hashing a raw
|
|
6
|
+
* email, bucketing a birthdate into an age range — and the platform applies it
|
|
7
|
+
* when a query asks for the target attribute and only the source is available.
|
|
8
|
+
*
|
|
9
|
+
* Reads cover the rules the calling company can use: the ones it owns plus the
|
|
10
|
+
* ones shared with it through collaborators. Writes are narrower — they need an
|
|
11
|
+
* `admin` grant on `attribute_derivations`, and only the owning company can
|
|
12
|
+
* change or delete a rule.
|
|
13
|
+
*/
|
|
14
|
+
export class DerivationsApi extends BaseApi {
|
|
15
|
+
/**
|
|
16
|
+
* Lists the derivation rules the calling company can use, optionally
|
|
17
|
+
* filtered by source or target attribute.
|
|
18
|
+
*
|
|
19
|
+
* @param {ListDerivationsParams} [params] - Attribute-id filters. Each accepts
|
|
20
|
+
* several ids.
|
|
21
|
+
* @returns {Promise<DerivationsResponse>} The matching rules, with empty
|
|
22
|
+
* `warnings` — reads do not compute them.
|
|
23
|
+
* @see https://docs.narrative.io/api-reference/derivations/get-derivation-rules
|
|
24
|
+
*/
|
|
25
|
+
async listDerivations(params) {
|
|
26
|
+
return await this.get(resourceName, params);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Fetches a single rule.
|
|
30
|
+
*
|
|
31
|
+
* @param {number} derivationId - Id of the rule.
|
|
32
|
+
* @returns {Promise<Derivation>} The rule. Rejects with 404 if no rule with
|
|
33
|
+
* that id is usable by the calling company — rules belonging to someone else
|
|
34
|
+
* are not distinguished from rules that do not exist.
|
|
35
|
+
* @see https://docs.narrative.io/api-reference/derivations/get-a-derivation-rule
|
|
36
|
+
*/
|
|
37
|
+
async getDerivation(derivationId) {
|
|
38
|
+
return await this.get(`${resourceName}/${derivationId}`);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Creates a rule, owned by the calling company.
|
|
42
|
+
*
|
|
43
|
+
* The transformation is validated before the rule can exist: both attributes
|
|
44
|
+
* must be viewable, the target must grant the company `map` since the rule
|
|
45
|
+
* produces values for it, every expression must parse and type-check against
|
|
46
|
+
* the source attribute's shape, and the result must match the target's
|
|
47
|
+
* declared type.
|
|
48
|
+
*
|
|
49
|
+
* A rule that closes a cycle in the derivation graph is still created — the
|
|
50
|
+
* cycle comes back as a `cyclic_derivation` warning on the response rather
|
|
51
|
+
* than as an error.
|
|
52
|
+
*
|
|
53
|
+
* @param {DerivationCreateRequest} request - The rule to create.
|
|
54
|
+
* @returns {Promise<Derivation>} The created rule, with any warnings. Rejects
|
|
55
|
+
* with 400 if the transformation fails validation; 403 if the caller is not
|
|
56
|
+
* an admin, the rule's company or collaborators are not allowed, or the
|
|
57
|
+
* target attribute does not grant `map`; 409 if another of the company's
|
|
58
|
+
* rules already has the same name or already covers the same source and
|
|
59
|
+
* target pair.
|
|
60
|
+
* @see https://docs.narrative.io/api-reference/derivations/create-a-derivation-rule
|
|
61
|
+
*/
|
|
62
|
+
async createDerivation(request) {
|
|
63
|
+
return await this.post(resourceName, request);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Updates some fields of a rule. Only the keys present in `request` change,
|
|
67
|
+
* and a changed `mapping` runs the same validation as a creation.
|
|
68
|
+
*
|
|
69
|
+
* @param {number} derivationId - Id of the rule.
|
|
70
|
+
* @param {DerivationUpdateRequest} request - The fields to change.
|
|
71
|
+
* @returns {Promise<Derivation>} The updated rule, with any warnings. Rejects
|
|
72
|
+
* with 400 if the update fails validation; 403 if the caller is not an admin
|
|
73
|
+
* or does not own the rule; 404 if there is no rule with that id.
|
|
74
|
+
* @see https://docs.narrative.io/api-reference/derivations/update-a-derivation-rule
|
|
75
|
+
*/
|
|
76
|
+
async updateDerivation(derivationId, request) {
|
|
77
|
+
return await this.patch(`${resourceName}/${derivationId}`, request);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Permanently removes a rule. To take a rule out of use while keeping it,
|
|
81
|
+
* pass `{ active: false }` to {@link DerivationsApi.updateDerivation}
|
|
82
|
+
* instead — deletions cannot be undone.
|
|
83
|
+
*
|
|
84
|
+
* @param {number} derivationId - Id of the rule.
|
|
85
|
+
* @returns {Promise<void>} Resolves when deleted. Rejects with 403 if the
|
|
86
|
+
* caller is not an admin or does not own the rule; 404 if there is no rule
|
|
87
|
+
* with that id.
|
|
88
|
+
* @see https://docs.narrative.io/api-reference/derivations/delete-a-derivation-rule
|
|
89
|
+
*/
|
|
90
|
+
async deleteDerivation(derivationId) {
|
|
91
|
+
await this.delete(`${resourceName}/${derivationId}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { components } from "../generated/api-types";
|
|
2
|
+
/**
|
|
3
|
+
* A derivation rule: a transformation that produces one attribute's value from
|
|
4
|
+
* another's, applied when a query resolves the target attribute.
|
|
5
|
+
*
|
|
6
|
+
* `warnings` is populated on create and update responses and empty on reads —
|
|
7
|
+
* list and get do not compute them. `fidelity_note` arrives as an explicit
|
|
8
|
+
* `null` when the rule has no note rather than being omitted.
|
|
9
|
+
*/
|
|
10
|
+
export type Derivation = components["schemas"]["DerivationResponse"];
|
|
11
|
+
/** The list endpoint's envelope. */
|
|
12
|
+
export type DerivationsResponse = components["schemas"]["DerivationsResponse"];
|
|
13
|
+
/**
|
|
14
|
+
* Which companies besides the owner may have a rule applied to their data. A
|
|
15
|
+
* rule grants a single thing, so there is one `use` dimension. Only Narrative
|
|
16
|
+
* can share a rule with `all` companies or with everyone outside an
|
|
17
|
+
* `exclusion` set.
|
|
18
|
+
*/
|
|
19
|
+
export type DerivationCollaborators = components["schemas"]["DerivationCollaborators"];
|
|
20
|
+
/**
|
|
21
|
+
* The transformation itself. Expressions reach the source attribute's shape
|
|
22
|
+
* through `$source` — a rule from `raw_email` to `sha256_hashed_email` maps
|
|
23
|
+
* `value` to `SHA2(NORMALIZE_EMAIL($source.value), 256)`.
|
|
24
|
+
*
|
|
25
|
+
* Same shape as a dataset mapping except that `cached_mapping` is not allowed:
|
|
26
|
+
* a cached mapping reads out of a stored dataset, so there would be nothing to
|
|
27
|
+
* substitute `$source` into.
|
|
28
|
+
*/
|
|
29
|
+
export type DerivationMapping = components["schemas"]["DerivationMapping"];
|
|
30
|
+
/**
|
|
31
|
+
* Something worth knowing that did not stop the rule from being written. The
|
|
32
|
+
* only kind today is `cyclic_derivation`, which lists the attribute ids on the
|
|
33
|
+
* cycle the rule closes.
|
|
34
|
+
*/
|
|
35
|
+
export type DerivationWarning = components["schemas"]["DerivationWarning"];
|
|
36
|
+
/** Breaks ties when several rules reach the same target attribute — cheapest wins. */
|
|
37
|
+
export type DerivationCost = components["schemas"]["DerivationCost"];
|
|
38
|
+
/** Body of `POST /derivations`. */
|
|
39
|
+
export type DerivationCreateRequest = components["schemas"]["DerivationCreateRequest"];
|
|
40
|
+
/**
|
|
41
|
+
* Body of `PATCH /derivations/{id}`. Only the keys present change. Sending
|
|
42
|
+
* `fidelity_note: null` clears it; leaving the key out keeps it. A rule's
|
|
43
|
+
* source and target attributes are immutable — create a new rule instead.
|
|
44
|
+
*/
|
|
45
|
+
export type DerivationUpdateRequest = components["schemas"]["DerivationUpdateRequest"];
|
|
46
|
+
/**
|
|
47
|
+
* Filters for the list endpoint. Both accept several ids, which the client
|
|
48
|
+
* repeats in the query string (`?source_attribute_id=1&source_attribute_id=2`)
|
|
49
|
+
* — the form the route's multi-value matcher reads.
|
|
50
|
+
*/
|
|
51
|
+
export interface ListDerivationsParams {
|
|
52
|
+
/** Only return rules reading from these attributes. */
|
|
53
|
+
source_attribute_id?: number[];
|
|
54
|
+
/** Only return rules producing these attributes. */
|
|
55
|
+
target_attribute_id?: number[];
|
|
56
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|