@distrohelena/canton-typescript-sdk 0.1.36 → 0.1.37
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 +104 -34
- package/dist/cjs/core/types/requests/{submit-command-request.js → submit-commands-request.js} +10 -6
- package/dist/cjs/index.js +10 -8
- package/dist/cjs/query/canonical/in-memory-query-evaluator.js +291 -0
- package/dist/cjs/query/canonical/public-identity.js +41 -0
- package/dist/cjs/query/canonical/query-ast.js +2 -0
- package/dist/cjs/query/canonical/query-dataset.js +351 -0
- package/dist/cjs/query/canonical/query-normalizer.js +655 -0
- package/dist/cjs/query/canonical/query-schema.js +86 -0
- package/dist/cjs/query/canton-manager.js +14 -5
- package/dist/cjs/query/errors/query-snapshot-incomplete-error.js +19 -0
- package/dist/cjs/query/grpc/grpc-contract-cache.js +484 -0
- package/dist/cjs/query/grpc/grpc-package-relation-reader.js +218 -0
- package/dist/cjs/query/grpc/grpc-query-client.js +249 -0
- package/dist/cjs/query/grpc/grpc-query-snapshot-reader.js +238 -0
- package/dist/cjs/query/grpc/grpc-query-value-mapper.js +204 -0
- package/dist/cjs/query/grpc/grpc-relation-mapper.js +794 -0
- package/dist/cjs/query/pqs/pqs-query-client.js +151 -582
- package/dist/cjs/query/pqs/pqs-relational-sql-compiler.js +138 -95
- package/dist/cjs/query/pqs/pqs-result-shape.js +28 -0
- package/dist/cjs/query/pqs/pqs-schema-profile.js +49 -48
- package/dist/cjs/query/pqs/pqs-sql-compiler.js +343 -289
- package/dist/cjs/query/pqs/pqs-sql-syntax.js +10 -0
- package/dist/cjs/services/command/command-service-client.js +16 -3
- package/dist/cjs/services/commands/command-payload-builder.js +1 -1
- package/dist/cjs/services/commands/command-submission-pipeline.js +21 -6
- package/dist/cjs/testing/runtime/declarative-action-executor.js +3 -3
- package/dist/cjs/transports/grpc/grpc-transport.js +2 -2
- package/dist/cjs/transports/grpc/mappers/commands-mapper.js +6 -6
- package/dist/cjs/transports/grpc/mappers/interactive-command-mapper.js +1 -1
- package/dist/cjs/transports/json/json-transport.js +1 -1
- package/dist/cjs/transports/json/mappers/commands-mapper.js +3 -3
- package/dist/core/transports/transport.interface.d.ts +4 -4
- package/dist/core/types/prepared-command-submission.d.ts +3 -3
- package/dist/core/types/requests/{submit-command-request.d.ts → submit-commands-request.d.ts} +8 -4
- package/dist/core/types/requests/{submit-command-request.js → submit-commands-request.js} +8 -4
- package/dist/index.d.ts +5 -2
- package/dist/index.js +2 -1
- package/dist/query/canonical/in-memory-query-evaluator.d.ts +22 -0
- package/dist/query/canonical/in-memory-query-evaluator.js +287 -0
- package/dist/query/canonical/public-identity.d.ts +14 -0
- package/dist/query/canonical/public-identity.js +35 -0
- package/dist/query/canonical/query-ast.d.ts +104 -0
- package/dist/query/canonical/query-ast.js +1 -0
- package/dist/query/canonical/query-dataset.d.ts +63 -0
- package/dist/query/canonical/query-dataset.js +343 -0
- package/dist/query/canonical/query-normalizer.d.ts +10 -0
- package/dist/query/canonical/query-normalizer.js +646 -0
- package/dist/query/canonical/query-schema.d.ts +25 -0
- package/dist/query/canonical/query-schema.js +83 -0
- package/dist/query/canton-manager.js +14 -5
- package/dist/query/errors/query-snapshot-incomplete-error.d.ts +14 -0
- package/dist/query/errors/query-snapshot-incomplete-error.js +15 -0
- package/dist/query/grpc/grpc-contract-cache.d.ts +27 -0
- package/dist/query/grpc/grpc-contract-cache.js +479 -0
- package/dist/query/grpc/grpc-package-relation-reader.d.ts +43 -0
- package/dist/query/grpc/grpc-package-relation-reader.js +213 -0
- package/dist/query/grpc/grpc-query-client.d.ts +42 -0
- package/dist/query/grpc/grpc-query-client.js +245 -0
- package/dist/query/grpc/grpc-query-snapshot-reader.d.ts +33 -0
- package/dist/query/grpc/grpc-query-snapshot-reader.js +233 -0
- package/dist/query/grpc/grpc-query-value-mapper.d.ts +15 -0
- package/dist/query/grpc/grpc-query-value-mapper.js +195 -0
- package/dist/query/grpc/grpc-relation-mapper.d.ts +67 -0
- package/dist/query/grpc/grpc-relation-mapper.js +789 -0
- package/dist/query/pqs/pqs-query-client.d.ts +10 -20
- package/dist/query/pqs/pqs-query-client.js +154 -585
- package/dist/query/pqs/pqs-relational-sql-compiler.d.ts +9 -17
- package/dist/query/pqs/pqs-relational-sql-compiler.js +136 -95
- package/dist/query/pqs/pqs-result-shape.d.ts +25 -0
- package/dist/query/pqs/pqs-result-shape.js +25 -0
- package/dist/query/pqs/pqs-schema-profile.js +49 -48
- package/dist/query/pqs/pqs-sql-compiler.d.ts +18 -3
- package/dist/query/pqs/pqs-sql-compiler.js +337 -288
- package/dist/query/pqs/pqs-sql-syntax.d.ts +2 -0
- package/dist/query/pqs/pqs-sql-syntax.js +6 -0
- package/dist/query/query-client.d.ts +15 -0
- package/dist/services/command/command-service-client.d.ts +9 -4
- package/dist/services/command/command-service-client.js +16 -3
- package/dist/services/command-submission/command-submission-service-client.d.ts +2 -2
- package/dist/services/commands/command-payload-builder.d.ts +2 -2
- package/dist/services/commands/command-payload-builder.js +1 -1
- package/dist/services/commands/command-submission-pipeline.d.ts +5 -4
- package/dist/services/commands/command-submission-pipeline.js +21 -6
- package/dist/testing/runtime/declarative-action-executor.js +3 -3
- package/dist/transports/grpc/grpc-transport.d.ts +4 -4
- package/dist/transports/grpc/grpc-transport.js +3 -3
- package/dist/transports/grpc/mappers/commands-mapper.d.ts +3 -3
- package/dist/transports/grpc/mappers/commands-mapper.js +4 -4
- package/dist/transports/grpc/mappers/interactive-command-mapper.d.ts +3 -3
- package/dist/transports/grpc/mappers/interactive-command-mapper.js +1 -1
- package/dist/transports/json/json-transport.d.ts +2 -2
- package/dist/transports/json/json-transport.js +2 -2
- package/dist/transports/json/mappers/commands-mapper.d.ts +2 -2
- package/dist/transports/json/mappers/commands-mapper.js +2 -2
- package/package.json +4 -3
- package/dist/cjs/query/grpc/grpc-contract-query-client.js +0 -178
- package/dist/query/grpc/grpc-contract-query-client.d.ts +0 -33
- package/dist/query/grpc/grpc-contract-query-client.js +0 -174
|
@@ -8,6 +8,19 @@ export interface FindManyArgs<TWhere, TSelect, TOrderBy, TInclude = never> {
|
|
|
8
8
|
readonly take?: number;
|
|
9
9
|
readonly include?: TInclude;
|
|
10
10
|
}
|
|
11
|
+
export interface ContractCacheArgs {
|
|
12
|
+
readonly parties?: readonly string[];
|
|
13
|
+
}
|
|
14
|
+
export type ContractCacheResult = {
|
|
15
|
+
readonly source: QuerySource.grpc;
|
|
16
|
+
readonly cached: true;
|
|
17
|
+
readonly activeAtOffset: string;
|
|
18
|
+
readonly contractCount: number;
|
|
19
|
+
readonly expiresAt: Date;
|
|
20
|
+
} | {
|
|
21
|
+
readonly source: QuerySource.pqs;
|
|
22
|
+
readonly cached: false;
|
|
23
|
+
};
|
|
11
24
|
export interface QueryDelegate<TRow, TWhere, TSelect, TOrderBy, TUnique, TInclude = never, TGroupBy = never, TGroupRow = never> {
|
|
12
25
|
findMany<TArgs extends FindManyArgs<TWhere, TSelect, TOrderBy, TInclude>>(args?: TArgs): Promise<readonly (TRow & JsonProjectionResult<TArgs>)[]>;
|
|
13
26
|
findUnique<TArgs extends {
|
|
@@ -36,6 +49,8 @@ export type QueryCollectionDelegate<TRow, TWhere, TSelect, TOrderBy, TInclude =
|
|
|
36
49
|
export interface QueryClient {
|
|
37
50
|
readonly source: QuerySource;
|
|
38
51
|
$queryRaw<TRow>(sql: string, values?: readonly unknown[]): Promise<readonly TRow[]>;
|
|
52
|
+
cacheContracts(args?: ContractCacheArgs): Promise<ContractCacheResult>;
|
|
53
|
+
invalidateContractsCache(args?: ContractCacheArgs): Promise<void>;
|
|
39
54
|
readonly contracts: {
|
|
40
55
|
findMany<TArgs extends ContractFindManyArgs>(args?: TArgs): Promise<readonly (ContractResult & JsonProjectionResult<TArgs>)[]>;
|
|
41
56
|
findUnique<TArgs extends ContractFindUniqueArgs>(args: TArgs): Promise<(ContractResult & JsonProjectionResult<TArgs>) | undefined>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CommandSigners, ICommandSigner } from "../../core/signing/command-signer.interface.js";
|
|
2
2
|
import { RequestOptions } from "../../core/types/request-options.js";
|
|
3
3
|
import { ITransport } from "../../core/transports/transport.interface.js";
|
|
4
|
-
import {
|
|
4
|
+
import { SubmitCommandsRequest } from "../../core/types/requests/submit-commands-request.js";
|
|
5
5
|
import { SubmitCommandResponse } from "../../core/types/responses/submit-command-response.js";
|
|
6
6
|
import { SubmitCommandTransactionResponse } from "../../core/types/responses/submit-command-transaction-response.js";
|
|
7
7
|
import { PreparedCommandSubmission } from "../../core/types/prepared-command-submission.js";
|
|
@@ -9,9 +9,14 @@ import { SignCommandResult } from "../../core/signing/sign-command-result.js";
|
|
|
9
9
|
export declare class CommandServiceClient {
|
|
10
10
|
private readonly pipeline;
|
|
11
11
|
constructor(transport: ITransport, signer?: ICommandSigner | CommandSigners);
|
|
12
|
-
submitAndWaitForTransactionAsync(request:
|
|
12
|
+
submitAndWaitForTransactionAsync(request: SubmitCommandsRequest, options?: RequestOptions): Promise<SubmitCommandTransactionResponse>;
|
|
13
13
|
/** Submits a command and waits for the result. Supported on JSON and gRPC. */
|
|
14
|
-
submitAndWaitAsync(request:
|
|
15
|
-
|
|
14
|
+
submitAndWaitAsync(request: SubmitCommandsRequest, options?: RequestOptions): Promise<SubmitCommandResponse>;
|
|
15
|
+
/**
|
|
16
|
+
* Submits through the connected participant without external command signing.
|
|
17
|
+
* A configured command signer is deliberately ignored for this call.
|
|
18
|
+
*/
|
|
19
|
+
submitParticipantLocalAndWaitAsync(request: SubmitCommandsRequest, options?: RequestOptions): Promise<SubmitCommandResponse>;
|
|
20
|
+
prepareAsync(request: SubmitCommandsRequest, options?: RequestOptions): Promise<PreparedCommandSubmission>;
|
|
16
21
|
executeAndWaitAsync(prepared: PreparedCommandSubmission, signatures: Readonly<Record<string, SignCommandResult>>, options?: RequestOptions): Promise<SubmitCommandResponse>;
|
|
17
22
|
}
|
|
@@ -7,11 +7,24 @@ export class CommandServiceClient {
|
|
|
7
7
|
signer,
|
|
8
8
|
});
|
|
9
9
|
}
|
|
10
|
-
submitAndWaitForTransactionAsync(request, options) {
|
|
10
|
+
submitAndWaitForTransactionAsync(request, options) {
|
|
11
|
+
return this.pipeline.submitForTransactionAsync(request, options);
|
|
12
|
+
}
|
|
11
13
|
/** Submits a command and waits for the result. Supported on JSON and gRPC. */
|
|
12
14
|
submitAndWaitAsync(request, options) {
|
|
13
15
|
return this.pipeline.submitAsync(request, options);
|
|
14
16
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Submits through the connected participant without external command signing.
|
|
19
|
+
* A configured command signer is deliberately ignored for this call.
|
|
20
|
+
*/
|
|
21
|
+
submitParticipantLocalAndWaitAsync(request, options) {
|
|
22
|
+
return this.pipeline.submitParticipantLocalAsync(request, options);
|
|
23
|
+
}
|
|
24
|
+
prepareAsync(request, options) {
|
|
25
|
+
return this.pipeline.prepareAsync(request, options);
|
|
26
|
+
}
|
|
27
|
+
executeAndWaitAsync(prepared, signatures, options) {
|
|
28
|
+
return this.pipeline.executeAsync(prepared, signatures, options);
|
|
29
|
+
}
|
|
17
30
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ITransport } from "../../core/transports/transport.interface.js";
|
|
2
|
-
import {
|
|
2
|
+
import { SubmitCommandsRequest } from "../../core/types/requests/submit-commands-request.js";
|
|
3
3
|
import { SubmitCommandResponse } from "../../core/types/responses/submit-command-response.js";
|
|
4
4
|
export declare class CommandSubmissionServiceClient {
|
|
5
5
|
private readonly transport;
|
|
6
6
|
constructor(transport: ITransport);
|
|
7
7
|
/** Submits a command without waiting. Placeholder until explicitly implemented. */
|
|
8
|
-
submitAsync(_request:
|
|
8
|
+
submitAsync(_request: SubmitCommandsRequest): Promise<SubmitCommandResponse>;
|
|
9
9
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function buildCanonicalCommandPayload(request:
|
|
1
|
+
import { SubmitCommandsRequest } from "../../core/types/requests/submit-commands-request.js";
|
|
2
|
+
export declare function buildCanonicalCommandPayload(request: SubmitCommandsRequest): Uint8Array;
|
|
@@ -7,7 +7,7 @@ export function buildCanonicalCommandPayload(request) {
|
|
|
7
7
|
applicationId: request.applicationId,
|
|
8
8
|
actAs: request.actAs,
|
|
9
9
|
readAs: request.readAs,
|
|
10
|
-
|
|
10
|
+
commands: request.commands.map(mapCanonicalCommand),
|
|
11
11
|
}));
|
|
12
12
|
}
|
|
13
13
|
function mapCanonicalCommand(command) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CommandSigners, ICommandSigner } from "../../core/signing/command-signer.interface.js";
|
|
2
2
|
import { ITransport } from "../../core/transports/transport.interface.js";
|
|
3
3
|
import { RequestOptions } from "../../core/types/request-options.js";
|
|
4
|
-
import {
|
|
4
|
+
import { SubmitCommandsRequest } from "../../core/types/requests/submit-commands-request.js";
|
|
5
5
|
import { SubmitCommandResponse } from "../../core/types/responses/submit-command-response.js";
|
|
6
6
|
import { SubmitCommandTransactionResponse } from "../../core/types/responses/submit-command-transaction-response.js";
|
|
7
7
|
import { PreparedCommandSubmission } from "../../core/types/prepared-command-submission.js";
|
|
@@ -12,8 +12,9 @@ export declare class CommandSubmissionPipeline {
|
|
|
12
12
|
transport: ITransport;
|
|
13
13
|
signer?: ICommandSigner | CommandSigners;
|
|
14
14
|
});
|
|
15
|
-
submitAsync(request:
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
submitAsync(request: SubmitCommandsRequest, options?: RequestOptions): Promise<SubmitCommandResponse>;
|
|
16
|
+
submitParticipantLocalAsync(request: SubmitCommandsRequest, options?: RequestOptions): Promise<SubmitCommandResponse>;
|
|
17
|
+
submitForTransactionAsync(request: SubmitCommandsRequest, options?: RequestOptions): Promise<SubmitCommandTransactionResponse>;
|
|
18
|
+
prepareAsync(request: SubmitCommandsRequest, options?: RequestOptions): Promise<PreparedCommandSubmission>;
|
|
18
19
|
executeAsync(prepared: PreparedCommandSubmission, signatures: Readonly<Record<string, SignCommandResult>>, options?: RequestOptions): Promise<SubmitCommandResponse>;
|
|
19
20
|
}
|
|
@@ -12,10 +12,25 @@ export class CommandSubmissionPipeline {
|
|
|
12
12
|
}
|
|
13
13
|
return this.dependencies.transport.submitCommandAsync(request, this.dependencies.signer, options);
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
submitParticipantLocalAsync(request, options) {
|
|
16
|
+
return this.dependencies.transport.submitCommandAsync(request, undefined, options);
|
|
17
|
+
}
|
|
18
|
+
submitForTransactionAsync(request, options) {
|
|
19
|
+
if (!this.dependencies.transport.submitCommandForTransactionAsync) {
|
|
20
|
+
throw new NotSupportedError("transaction-returning command submission is not supported by the selected transport");
|
|
21
|
+
}
|
|
22
|
+
return this.dependencies.transport.submitCommandForTransactionAsync(request, options);
|
|
23
|
+
}
|
|
24
|
+
prepareAsync(request, options) {
|
|
25
|
+
if (!this.dependencies.transport.prepareCommandAsync) {
|
|
26
|
+
throw new NotSupportedError("interactive command preparation is not supported by the selected transport");
|
|
27
|
+
}
|
|
28
|
+
return this.dependencies.transport.prepareCommandAsync(request, options);
|
|
29
|
+
}
|
|
30
|
+
executeAsync(prepared, signatures, options) {
|
|
31
|
+
if (!this.dependencies.transport.executePreparedCommandAndWaitAsync) {
|
|
32
|
+
throw new NotSupportedError("interactive command execution is not supported by the selected transport");
|
|
33
|
+
}
|
|
34
|
+
return this.dependencies.transport.executePreparedCommandAndWaitAsync(prepared, signatures, options);
|
|
35
|
+
}
|
|
21
36
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CreateCommand } from "../../core/types/commands/create-command.js";
|
|
2
2
|
import { ExerciseCommand } from "../../core/types/commands/exercise-command.js";
|
|
3
3
|
import { DamlRecord } from "../../core/types/daml-values.js";
|
|
4
|
-
import {
|
|
4
|
+
import { SubmitCommandsRequest } from "../../core/types/requests/submit-commands-request.js";
|
|
5
5
|
import { TestingConfigurationError } from "../errors/testing-configuration-error.js";
|
|
6
6
|
import { toCampaignMetricOutcome, } from "./canton-test-runtime.js";
|
|
7
7
|
/**
|
|
@@ -18,11 +18,11 @@ export async function executeDeclarativeActionAsync(init) {
|
|
|
18
18
|
templateId: init.action.templateId,
|
|
19
19
|
createArguments: new DamlRecord({ ...init.action.payload }),
|
|
20
20
|
});
|
|
21
|
-
return toCampaignMetricOutcome(await init.runtime.submitAndWaitAsync(init.action.actor, new
|
|
21
|
+
return toCampaignMetricOutcome(await init.runtime.submitAndWaitAsync(init.action.actor, new SubmitCommandsRequest({
|
|
22
22
|
applicationId: init.applicationId,
|
|
23
23
|
actAs: route.actAs,
|
|
24
24
|
readAs: route.readAs,
|
|
25
|
-
command,
|
|
25
|
+
commands: [command],
|
|
26
26
|
})));
|
|
27
27
|
}
|
|
28
28
|
async function createExerciseCommandAsync(action, resolveContractIdAsync) {
|
|
@@ -6,7 +6,7 @@ import { ListKnownPartiesRequest } from "../../core/types/requests/list-known-pa
|
|
|
6
6
|
import { ListPartyToParticipantRequest } from "../../core/types/requests/list-party-to-participant-request.js";
|
|
7
7
|
import { ListUserRightsRequest } from "../../core/types/requests/list-user-rights-request.js";
|
|
8
8
|
import { ListUsersRequest } from "../../core/types/requests/list-users-request.js";
|
|
9
|
-
import {
|
|
9
|
+
import { SubmitCommandsRequest } from "../../core/types/requests/submit-commands-request.js";
|
|
10
10
|
import { CommandSigners, ICommandSigner } from "../../core/signing/command-signer.interface.js";
|
|
11
11
|
import { SignCommandResult } from "../../core/signing/sign-command-result.js";
|
|
12
12
|
import { PreparedCommandSubmission } from "../../core/types/prepared-command-submission.js";
|
|
@@ -151,9 +151,9 @@ export declare class GrpcTransport implements ITransport {
|
|
|
151
151
|
getUpdateByHashAsync(request: GetUpdateByHashRequest, options?: RequestOptions): Promise<ProtobufGetUpdateResponse>;
|
|
152
152
|
getUpdatesPageAsync(request: GetUpdatesPageRequest, options?: RequestOptions): Promise<ProtobufGetUpdatesPageResponse>;
|
|
153
153
|
getCompletionsAsync(request: GetCompletionsRequest, options?: RequestOptions): AsyncIterable<ProtobufCompletionStreamResponse>;
|
|
154
|
-
submitCommandAsync(request:
|
|
155
|
-
submitCommandForTransactionAsync(request:
|
|
156
|
-
prepareCommandAsync(request:
|
|
154
|
+
submitCommandAsync(request: SubmitCommandsRequest, signer?: ICommandSigner | CommandSigners, options?: RequestOptions): Promise<SubmitCommandResponse>;
|
|
155
|
+
submitCommandForTransactionAsync(request: SubmitCommandsRequest, options?: RequestOptions): Promise<import("../../core/types/responses/submit-command-transaction-response.js").SubmitCommandTransactionResponse>;
|
|
156
|
+
prepareCommandAsync(request: SubmitCommandsRequest, options?: RequestOptions): Promise<PreparedCommandSubmission>;
|
|
157
157
|
executePreparedCommandAndWaitAsync(prepared: PreparedCommandSubmission, signatures: Readonly<Record<string, SignCommandResult>>, options?: RequestOptions): Promise<SubmitCommandResponse>;
|
|
158
158
|
private throwIfDisposed;
|
|
159
159
|
private throwPartyTopologyReadCompatibilityError;
|
|
@@ -7,7 +7,7 @@ import { ListKnownPartiesResponse as SdkListKnownPartiesResponse } from "../../c
|
|
|
7
7
|
import { NotSupportedError } from "../../core/errors/not-supported-error.js";
|
|
8
8
|
import { TransportError } from "../../core/errors/transport-error.js";
|
|
9
9
|
import { createGrpcOperations, } from "./grpc-channel-factory.js";
|
|
10
|
-
import { mapGrpcSubmitCommand,
|
|
10
|
+
import { mapGrpcSubmitCommand, mapGrpcSubmitCommandsForTransactionRequest, mapGrpcSubmitCommandTransaction, mapGrpcSubmitCommandsRequest, } from "./mappers/commands-mapper.js";
|
|
11
11
|
import { mapGrpcExecuteSubmissionAndWaitRequest, mapGrpcInteractiveSubmitCommand, mapGrpcPrepareSubmissionRequest, } from "./mappers/interactive-command-mapper.js";
|
|
12
12
|
import { mapGrpcCreateParty, mapGrpcCreatePartyRequest, mapGrpcListParties, mapGrpcListPartiesRequest } from "./mappers/parties-mapper.js";
|
|
13
13
|
import { mapGrpcListPartyToParticipantRequest, mapGrpcListPartyToParticipantResponse, } from "./mappers/topology-manager-read-mapper.js";
|
|
@@ -487,7 +487,7 @@ export class GrpcTransport {
|
|
|
487
487
|
async submitCommandAsync(request, signer, options) {
|
|
488
488
|
this.throwIfDisposed();
|
|
489
489
|
if (!signer) {
|
|
490
|
-
const payload = await this.operations.submitCommandAsync(
|
|
490
|
+
const payload = await this.operations.submitCommandAsync(mapGrpcSubmitCommandsRequest(request), options);
|
|
491
491
|
return mapGrpcSubmitCommand(payload);
|
|
492
492
|
}
|
|
493
493
|
else if (request.actAs.length !== 1 && !("signAsync" in signer)) {
|
|
@@ -529,7 +529,7 @@ export class GrpcTransport {
|
|
|
529
529
|
if (!this.operations.submitCommandForTransactionAsync) {
|
|
530
530
|
throw new NotSupportedError("transaction-returning command submission is not available on this transport");
|
|
531
531
|
}
|
|
532
|
-
return mapGrpcSubmitCommandTransaction(await this.operations.submitCommandForTransactionAsync(
|
|
532
|
+
return mapGrpcSubmitCommandTransaction(await this.operations.submitCommandForTransactionAsync(mapGrpcSubmitCommandsForTransactionRequest(request), options));
|
|
533
533
|
}
|
|
534
534
|
async prepareCommandAsync(request, options) {
|
|
535
535
|
if (!this.operations.prepareSubmissionAsync) {
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { CreateCommand } from "../../../core/types/commands/create-command.js";
|
|
2
2
|
import { DamlRecord } from "../../../core/types/daml-values.js";
|
|
3
3
|
import { LedgerCommand } from "../../../core/types/commands/ledger-command.js";
|
|
4
|
-
import {
|
|
4
|
+
import { SubmitCommandsRequest } from "../../../core/types/requests/submit-commands-request.js";
|
|
5
5
|
import { SubmitCommandResponse } from "../../../core/types/responses/submit-command-response.js";
|
|
6
6
|
import { SubmitCommandTransactionResponse } from "../../../core/types/responses/submit-command-transaction-response.js";
|
|
7
7
|
import { Command } from "../generated/canton/com/daml/ledger/api/v2/commands.js";
|
|
8
8
|
import { SubmitAndWaitRequest, SubmitAndWaitResponse, SubmitAndWaitForTransactionRequest, SubmitAndWaitForTransactionResponse } from "../generated/canton/com/daml/ledger/api/v2/command_service.js";
|
|
9
9
|
import { Record as GrpcRecord, Value } from "../generated/canton/com/daml/ledger/api/v2/value.js";
|
|
10
|
-
export declare function
|
|
11
|
-
export declare function
|
|
10
|
+
export declare function mapGrpcSubmitCommandsRequest(request: SubmitCommandsRequest): SubmitAndWaitRequest;
|
|
11
|
+
export declare function mapGrpcSubmitCommandsForTransactionRequest(request: SubmitCommandsRequest): SubmitAndWaitForTransactionRequest;
|
|
12
12
|
export declare function mapGrpcSubmitCommandTransaction(payload: SubmitAndWaitForTransactionResponse): SubmitCommandTransactionResponse;
|
|
13
13
|
export declare function mapGrpcSubmitCommand(payload: {
|
|
14
14
|
commandId?: string;
|
|
@@ -11,13 +11,13 @@ import { ExerciseCommand } from "../../../core/types/commands/exercise-command.j
|
|
|
11
11
|
import { SubmitCommandResponse } from "../../../core/types/responses/submit-command-response.js";
|
|
12
12
|
import { SubmitCommandTransactionResponse } from "../../../core/types/responses/submit-command-transaction-response.js";
|
|
13
13
|
import { mapGrpcDeduplicationPeriod } from "./command-deduplication-mapper.js";
|
|
14
|
-
export function
|
|
14
|
+
export function mapGrpcSubmitCommandsRequest(request) {
|
|
15
15
|
return {
|
|
16
16
|
commands: {
|
|
17
17
|
workflowId: "",
|
|
18
18
|
userId: request.userId ?? "",
|
|
19
19
|
commandId: request.commandId ?? randomUUID(),
|
|
20
|
-
commands:
|
|
20
|
+
commands: request.commands.map(mapGrpcLedgerCommand),
|
|
21
21
|
deduplicationPeriod: mapGrpcDeduplicationPeriod(request.deduplicationPeriod, { allowParticipantBegin: true }),
|
|
22
22
|
actAs: [...request.actAs],
|
|
23
23
|
readAs: [...request.readAs],
|
|
@@ -29,8 +29,8 @@ export function mapGrpcSubmitCommandRequest(request) {
|
|
|
29
29
|
},
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
-
export function
|
|
33
|
-
return { commands:
|
|
32
|
+
export function mapGrpcSubmitCommandsForTransactionRequest(request) {
|
|
33
|
+
return { commands: mapGrpcSubmitCommandsRequest(request).commands };
|
|
34
34
|
}
|
|
35
35
|
export function mapGrpcSubmitCommandTransaction(payload) {
|
|
36
36
|
const transaction = payload.transaction;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { SignCommandResult } from "../../../core/signing/sign-command-result.js";
|
|
2
|
-
import {
|
|
2
|
+
import { SubmitCommandsRequest } from "../../../core/types/requests/submit-commands-request.js";
|
|
3
3
|
import { SubmitCommandResponse } from "../../../core/types/responses/submit-command-response.js";
|
|
4
4
|
import { Signature } from "../generated/canton/com/daml/ledger/api/v2/crypto.js";
|
|
5
5
|
import { ExecuteSubmissionAndWaitRequest, ExecuteSubmissionAndWaitResponse, HashingSchemeVersion, PrepareSubmissionRequest, PreparedTransaction } from "../generated/canton/com/daml/ledger/api/v2/interactive/interactive_submission_service.js";
|
|
6
|
-
export declare function mapGrpcPrepareSubmissionRequest(request:
|
|
6
|
+
export declare function mapGrpcPrepareSubmissionRequest(request: SubmitCommandsRequest, commandId: string): PrepareSubmissionRequest;
|
|
7
7
|
export declare function mapGrpcExecuteSubmissionAndWaitRequest(init: {
|
|
8
|
-
request:
|
|
8
|
+
request: SubmitCommandsRequest;
|
|
9
9
|
preparedTransaction: PreparedTransaction;
|
|
10
10
|
hashingSchemeVersion: HashingSchemeVersion;
|
|
11
11
|
submissionId: string;
|
|
@@ -10,7 +10,7 @@ export function mapGrpcPrepareSubmissionRequest(request, commandId) {
|
|
|
10
10
|
return {
|
|
11
11
|
userId: request.userId ?? "",
|
|
12
12
|
commandId,
|
|
13
|
-
commands:
|
|
13
|
+
commands: request.commands.map(mapGrpcLedgerCommand),
|
|
14
14
|
actAs: [...request.actAs],
|
|
15
15
|
readAs: [...request.readAs],
|
|
16
16
|
disclosedContracts: request.disclosedContracts.map(value => ({ createdEventBlob: value.createdEventBlob, contractId: value.contractId ?? "", synchronizerId: value.synchronizerId ?? "", templateId: value.templateId === undefined ? undefined : { packageId: value.templateId.packageId, moduleName: value.templateId.moduleName, entityName: value.templateId.entityName } })),
|
|
@@ -5,7 +5,7 @@ import { ListKnownPartiesRequest } from "../../core/types/requests/list-known-pa
|
|
|
5
5
|
import { ListPartyToParticipantRequest } from "../../core/types/requests/list-party-to-participant-request.js";
|
|
6
6
|
import { ListUserRightsRequest } from "../../core/types/requests/list-user-rights-request.js";
|
|
7
7
|
import { ListUsersRequest } from "../../core/types/requests/list-users-request.js";
|
|
8
|
-
import {
|
|
8
|
+
import { SubmitCommandsRequest } from "../../core/types/requests/submit-commands-request.js";
|
|
9
9
|
import { AllocatePartyResponse } from "../../core/types/responses/allocate-party-response.js";
|
|
10
10
|
import { GetUserResponse } from "../../core/types/responses/get-user-response.js";
|
|
11
11
|
import { ListPartyToParticipantResponse } from "../../core/types/responses/list-party-to-participant-response.js";
|
|
@@ -150,6 +150,6 @@ export declare class JsonTransport implements ITransport {
|
|
|
150
150
|
getUpdateByHashAsync(_request: GetUpdateByHashRequest, _options?: RequestOptions): Promise<GetUpdateResponse>;
|
|
151
151
|
getUpdatesPageAsync(_request: GetUpdatesPageRequest, _options?: RequestOptions): Promise<GetUpdatesPageResponse>;
|
|
152
152
|
getCompletionsAsync(_request: GetCompletionsRequest, _options?: RequestOptions): AsyncIterable<CompletionStreamResponse>;
|
|
153
|
-
submitCommandAsync(request:
|
|
153
|
+
submitCommandAsync(request: SubmitCommandsRequest, signer?: ICommandSigner, options?: RequestOptions): Promise<SubmitCommandResponse>;
|
|
154
154
|
private throwIfDisposed;
|
|
155
155
|
}
|
|
@@ -3,7 +3,7 @@ import { ListKnownPartiesResponse } from "../../core/types/responses/list-known-
|
|
|
3
3
|
import { NotSupportedError } from "../../core/errors/not-supported-error.js";
|
|
4
4
|
import { GetLedgerApiVersionResponse } from "../grpc/generated/canton/com/daml/ledger/api/v2/version_service.js";
|
|
5
5
|
import { ObjectDisposedError } from "../../core/errors/object-disposed-error.js";
|
|
6
|
-
import { mapJsonSubmitCommand,
|
|
6
|
+
import { mapJsonSubmitCommand, mapJsonSubmitCommandsRequest, } from "./mappers/commands-mapper.js";
|
|
7
7
|
import { UploadDarFileResponse } from "../grpc/generated/canton/com/daml/ledger/api/v2/admin/package_management_service.js";
|
|
8
8
|
import { mapJsonAllocatePartyRequest, mapJsonCreateParty, mapJsonListParties, } from "./mappers/parties-mapper.js";
|
|
9
9
|
import { mapJsonTransactionEvents } from "./mappers/events-mapper.js";
|
|
@@ -451,7 +451,7 @@ export class JsonTransport {
|
|
|
451
451
|
if (signer) {
|
|
452
452
|
throw new NotSupportedError("command signing is not supported by json transport");
|
|
453
453
|
}
|
|
454
|
-
const payload = await this.httpClient.postAsync("/v2/commands/submit-and-wait",
|
|
454
|
+
const payload = await this.httpClient.postAsync("/v2/commands/submit-and-wait", mapJsonSubmitCommandsRequest(request), options);
|
|
455
455
|
return mapJsonSubmitCommand(payload);
|
|
456
456
|
}
|
|
457
457
|
throwIfDisposed() {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SubmitCommandsRequest } from "../../../core/types/requests/submit-commands-request.js";
|
|
2
2
|
import { SubmitCommandResponse } from "../../../core/types/responses/submit-command-response.js";
|
|
3
|
-
export declare function
|
|
3
|
+
export declare function mapJsonSubmitCommandsRequest(request: SubmitCommandsRequest): {
|
|
4
4
|
commandId: string;
|
|
5
5
|
actAs: readonly string[];
|
|
6
6
|
readAs: readonly string[];
|
|
@@ -9,7 +9,7 @@ import { DamlRecord } from "../../../core/types/daml-values.js";
|
|
|
9
9
|
import { ExerciseByKeyCommand } from "../../../core/types/commands/exercise-by-key-command.js";
|
|
10
10
|
import { ExerciseCommand } from "../../../core/types/commands/exercise-command.js";
|
|
11
11
|
import { SubmitCommandResponse } from "../../../core/types/responses/submit-command-response.js";
|
|
12
|
-
export function
|
|
12
|
+
export function mapJsonSubmitCommandsRequest(request) {
|
|
13
13
|
if (request.deduplicationPeriod !== undefined) {
|
|
14
14
|
throw new TransportError("command deduplication periods are not supported by the JSON transport");
|
|
15
15
|
}
|
|
@@ -17,7 +17,7 @@ export function mapJsonSubmitCommandRequest(request) {
|
|
|
17
17
|
commandId: request.commandId ?? randomUUID(),
|
|
18
18
|
actAs: request.actAs,
|
|
19
19
|
readAs: request.readAs,
|
|
20
|
-
commands:
|
|
20
|
+
commands: request.commands.map(mapJsonCommand),
|
|
21
21
|
applicationId: request.applicationId || undefined,
|
|
22
22
|
};
|
|
23
23
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@distrohelena/canton-typescript-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.37",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -102,6 +102,7 @@
|
|
|
102
102
|
"example:workflow:contract-lifecycle-audit": "npm run build && node --loader ts-node/esm examples/95-contract-lifecycle-audit.ts",
|
|
103
103
|
"example:workflow:update-lookup-reconciliation": "npm run build && node --loader ts-node/esm examples/96-update-lookup-reconciliation.ts",
|
|
104
104
|
"example:workflow:pruning-preflight": "npm run build && node --loader ts-node/esm examples/97-pruning-preflight.ts",
|
|
105
|
+
"example:workflow:participant-local": "npm run build && node --loader ts-node/esm examples/98-participant-local-command-submission.ts",
|
|
105
106
|
"lint": "eslint . --max-warnings=0",
|
|
106
107
|
"lint:fix": "eslint . --fix --max-warnings=0",
|
|
107
108
|
"start:local-ledger": "bash node/start-local.sh",
|
|
@@ -112,9 +113,9 @@
|
|
|
112
113
|
"test:stop-local-script": "bash node/test-stop-local.sh",
|
|
113
114
|
"test:participant-358-sidecar-script": "bash node/test-participant-358-sidecar.sh",
|
|
114
115
|
"test:participant-358-sidecar-smoke": "bash node/test-participant-358-sidecar-smoke.sh",
|
|
115
|
-
"test": "vitest run --maxWorkers=1 --testTimeout=15000",
|
|
116
|
+
"test": "vitest run --exclude 'tests/live/**' --maxWorkers=1 --testTimeout=15000",
|
|
116
117
|
"test:property": "vitest run tests/property --maxWorkers=1 --testTimeout=15000",
|
|
117
|
-
"test:live": "vitest run tests/live --maxWorkers=1 --testTimeout=15000",
|
|
118
|
+
"test:live": "vitest run --dir tests/live --maxWorkers=1 --testTimeout=15000",
|
|
118
119
|
"test:live:fuzz": "vitest run tests/live/specs/live-stateful-fuzzing.test.ts --maxWorkers=1 --testTimeout=300000",
|
|
119
120
|
"test:unit": "vitest run tests/unit",
|
|
120
121
|
"verify:pack": "node ./scripts/verify-npm-pack.mjs"
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GrpcContractQueryClient = void 0;
|
|
4
|
-
const contracts_mapper_js_1 = require("../../transports/grpc/mappers/contracts-mapper.js");
|
|
5
|
-
const query_capability_error_js_1 = require("../errors/query-capability-error.js");
|
|
6
|
-
const query_source_js_1 = require("../query-source.js");
|
|
7
|
-
class GrpcContractQueryClient {
|
|
8
|
-
stateService;
|
|
9
|
-
cache;
|
|
10
|
-
cacheTtlMs;
|
|
11
|
-
cacheScope;
|
|
12
|
-
source = query_source_js_1.QuerySource.grpc;
|
|
13
|
-
contracts = {
|
|
14
|
-
findMany: (args = {}) => this.findManyAsync(args).then((rows) => rows),
|
|
15
|
-
findUnique: (args) => {
|
|
16
|
-
if (args.select !== undefined || args.include !== undefined) {
|
|
17
|
-
return Promise.reject(new query_capability_error_js_1.QueryCapabilityError(query_source_js_1.QuerySource.grpc, "contracts.findUnique"));
|
|
18
|
-
}
|
|
19
|
-
return this.findManyAsync({ where: { contractId: { equals: args.where.contractId } } }).then((rows) => rows[0]);
|
|
20
|
-
},
|
|
21
|
-
count: async (args = {}) => (await this.findManyAsync(args)).length,
|
|
22
|
-
aggregate: async () => {
|
|
23
|
-
throw new query_capability_error_js_1.QueryCapabilityError(query_source_js_1.QuerySource.grpc, "contracts.aggregate");
|
|
24
|
-
},
|
|
25
|
-
groupBy: async () => {
|
|
26
|
-
throw new query_capability_error_js_1.QueryCapabilityError(query_source_js_1.QuerySource.grpc, "contracts.groupBy");
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
contractTypes = this.unsupported("contractTypes");
|
|
30
|
-
events = this.unsupported("events");
|
|
31
|
-
exercises = this.unsupported("exercises");
|
|
32
|
-
exerciseTypes = this.unsupported("exerciseTypes");
|
|
33
|
-
packages = this.unsupported("packages");
|
|
34
|
-
transactions = this.unsupported("transactions");
|
|
35
|
-
watermark = this.unsupported("watermark");
|
|
36
|
-
constructor(stateService, cache, cacheTtlMs, cacheScope) {
|
|
37
|
-
this.stateService = stateService;
|
|
38
|
-
this.cache = cache;
|
|
39
|
-
this.cacheTtlMs = cacheTtlMs;
|
|
40
|
-
this.cacheScope = cacheScope;
|
|
41
|
-
}
|
|
42
|
-
async $queryRaw(_sql, _values = []) {
|
|
43
|
-
throw new query_capability_error_js_1.QueryCapabilityError(query_source_js_1.QuerySource.grpc, "query.$queryRaw");
|
|
44
|
-
}
|
|
45
|
-
async findManyAsync(args) {
|
|
46
|
-
if (hasUnsupportedFilter(args.where) ||
|
|
47
|
-
args.where?.active === false ||
|
|
48
|
-
args.where?.packageId !== undefined ||
|
|
49
|
-
args.where?.witnesses !== undefined ||
|
|
50
|
-
args.where?.contractId?.in !== undefined ||
|
|
51
|
-
args.where?.contractId?.is !== undefined ||
|
|
52
|
-
args.where?.contractId?.isNot !== undefined ||
|
|
53
|
-
args.where?.templateId !== undefined) {
|
|
54
|
-
throw new query_capability_error_js_1.QueryCapabilityError(query_source_js_1.QuerySource.grpc, "contracts.findMany");
|
|
55
|
-
}
|
|
56
|
-
const findArgs = args;
|
|
57
|
-
if (findArgs.select !== undefined || findArgs.include !== undefined || findArgs.orderBy !== undefined || findArgs.skip !== undefined || findArgs.take !== undefined) {
|
|
58
|
-
throw new query_capability_error_js_1.QueryCapabilityError(query_source_js_1.QuerySource.grpc, "contracts.findMany");
|
|
59
|
-
}
|
|
60
|
-
const snapshot = await this.readSnapshotAsync(args.parties);
|
|
61
|
-
let rows = snapshot.filter((row) => args.where?.contractId?.equals === undefined
|
|
62
|
-
? true
|
|
63
|
-
: row.contractId === args.where.contractId.equals);
|
|
64
|
-
if (args.where?.payload !== undefined) {
|
|
65
|
-
rows = rows.filter((row) => matchesPayload(row.payload, args.where.payload));
|
|
66
|
-
}
|
|
67
|
-
return rows;
|
|
68
|
-
}
|
|
69
|
-
unsupported(operation) {
|
|
70
|
-
return {
|
|
71
|
-
findMany: async () => {
|
|
72
|
-
throw new query_capability_error_js_1.QueryCapabilityError(query_source_js_1.QuerySource.grpc, `${operation}.findMany`);
|
|
73
|
-
},
|
|
74
|
-
findUnique: async () => {
|
|
75
|
-
throw new query_capability_error_js_1.QueryCapabilityError(query_source_js_1.QuerySource.grpc, `${operation}.findUnique`);
|
|
76
|
-
},
|
|
77
|
-
count: async () => {
|
|
78
|
-
throw new query_capability_error_js_1.QueryCapabilityError(query_source_js_1.QuerySource.grpc, `${operation}.count`);
|
|
79
|
-
},
|
|
80
|
-
aggregate: async () => {
|
|
81
|
-
throw new query_capability_error_js_1.QueryCapabilityError(query_source_js_1.QuerySource.grpc, `${operation}.aggregate`);
|
|
82
|
-
},
|
|
83
|
-
groupBy: async () => {
|
|
84
|
-
throw new query_capability_error_js_1.QueryCapabilityError(query_source_js_1.QuerySource.grpc, `${operation}.groupBy`);
|
|
85
|
-
},
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
async readSnapshotAsync(parties) {
|
|
89
|
-
const key = `${this.cacheScope}:${parties?.join(",") ?? "*"}`;
|
|
90
|
-
const cached = this.cache === undefined ? undefined : await this.cache.getAsync(key);
|
|
91
|
-
if (cached !== undefined) {
|
|
92
|
-
return cached;
|
|
93
|
-
}
|
|
94
|
-
const rows = [];
|
|
95
|
-
let pageToken;
|
|
96
|
-
let activeAtOffset;
|
|
97
|
-
do {
|
|
98
|
-
const response = await this.stateService.getActiveContractsPageAsync((0, contracts_mapper_js_1.mapGrpcQueryContractsRequest)(parties === undefined
|
|
99
|
-
? { allParties: true, activeAtOffset, pageToken }
|
|
100
|
-
: { parties, activeAtOffset, pageToken }));
|
|
101
|
-
activeAtOffset ??= response.activeAtOffset;
|
|
102
|
-
pageToken = response.nextPageToken;
|
|
103
|
-
rows.push(...response.activeContracts.map((response) => mapGrpcContract(response.contractEntry.oneofKind === "activeContract"
|
|
104
|
-
? response.contractEntry.activeContract
|
|
105
|
-
: response)));
|
|
106
|
-
} while (pageToken !== undefined && pageToken.length > 0);
|
|
107
|
-
if (this.cache !== undefined && this.cacheTtlMs !== undefined) {
|
|
108
|
-
await this.cache.setAsync(key, rows, this.cacheTtlMs);
|
|
109
|
-
}
|
|
110
|
-
return rows;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
exports.GrpcContractQueryClient = GrpcContractQueryClient;
|
|
114
|
-
function hasUnsupportedFilter(where) {
|
|
115
|
-
if (where === undefined) {
|
|
116
|
-
return false;
|
|
117
|
-
}
|
|
118
|
-
else if ("and" in where || "or" in where || "not" in where || "createdEventOffset" in where || "createdAt" in where || "archivedEventOffset" in where || "archivedAt" in where) {
|
|
119
|
-
return true;
|
|
120
|
-
}
|
|
121
|
-
for (const field of ["contractId", "templateId"]) {
|
|
122
|
-
const filter = where[field];
|
|
123
|
-
if (filter !== undefined && Object.keys(filter).some((key) => key !== "equals")) {
|
|
124
|
-
return true;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return false;
|
|
128
|
-
}
|
|
129
|
-
function mapGrpcContract(value) {
|
|
130
|
-
const row = value;
|
|
131
|
-
const template = row.templateId;
|
|
132
|
-
return {
|
|
133
|
-
contractId: row.contractId ?? "",
|
|
134
|
-
templateId: { packageId: template?.packageId ?? "", moduleName: template?.moduleName ?? "", entityName: template?.entityName ?? "" },
|
|
135
|
-
packageId: null,
|
|
136
|
-
payload: row.payload,
|
|
137
|
-
witnesses: [],
|
|
138
|
-
createdEventOffset: "",
|
|
139
|
-
createdAt: null,
|
|
140
|
-
archivedEventOffset: null,
|
|
141
|
-
archivedAt: null,
|
|
142
|
-
active: true,
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
function matchesPayload(value, filter) {
|
|
146
|
-
const match = filter.match;
|
|
147
|
-
if (match === undefined) {
|
|
148
|
-
return false;
|
|
149
|
-
}
|
|
150
|
-
const visit = (current, node) => Object.entries(node).every(([key, child]) => {
|
|
151
|
-
const next = current !== null && typeof current === "object" ? current[key] : undefined;
|
|
152
|
-
const predicate = child;
|
|
153
|
-
if (Object.keys(predicate).some((name) => ["equals", "lt", "lte", "gt", "gte", "like", "ilike"].includes(name))) {
|
|
154
|
-
return compare(String(next ?? ""), predicate);
|
|
155
|
-
}
|
|
156
|
-
return visit(next, predicate);
|
|
157
|
-
});
|
|
158
|
-
return visit(value, match);
|
|
159
|
-
}
|
|
160
|
-
function compare(value, filter) {
|
|
161
|
-
if (filter.equals !== undefined) {
|
|
162
|
-
return value === filter.equals;
|
|
163
|
-
}
|
|
164
|
-
else if (filter.like !== undefined || filter.ilike !== undefined) {
|
|
165
|
-
const pattern = String(filter.like ?? filter.ilike).replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replaceAll("%", ".*").replaceAll("_", ".");
|
|
166
|
-
return new RegExp(`^${pattern}$`, filter.ilike === undefined ? "" : "i").test(value);
|
|
167
|
-
}
|
|
168
|
-
else if (filter.lt !== undefined) {
|
|
169
|
-
return value < String(filter.lt);
|
|
170
|
-
}
|
|
171
|
-
else if (filter.lte !== undefined) {
|
|
172
|
-
return value <= String(filter.lte);
|
|
173
|
-
}
|
|
174
|
-
else if (filter.gt !== undefined) {
|
|
175
|
-
return value > String(filter.gt);
|
|
176
|
-
}
|
|
177
|
-
return value >= String(filter.gte);
|
|
178
|
-
}
|