@pact-foundation/pact-core 13.4.1-beta.2 → 13.4.1-beta.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.
Files changed (40) hide show
  1. package/binding.gyp +4 -8
  2. package/build/Makefile +5 -5
  3. package/build/gyp-mac-tool +626 -464
  4. package/build/pact.target.mk +20 -20
  5. package/build/set_osx_install_name.target.mk +2 -1
  6. package/ffi/libpact_ffi.dylib +0 -0
  7. package/ffi/libpact_ffi.so +0 -0
  8. package/ffi/osxaarch64/libpact_ffi.dylib +0 -0
  9. package/ffi/pact.h +599 -108
  10. package/ffi/pact_ffi.dll +0 -0
  11. package/ffi/pact_ffi.dll.lib +0 -0
  12. package/native/consumer.cc +88 -32
  13. package/package.json +4 -4
  14. package/src/consumer/__testoutput__/foo-consumer-bar-provider.json +255 -0
  15. package/src/consumer/checkErrors.d.ts +7 -0
  16. package/src/consumer/checkErrors.js +41 -0
  17. package/src/consumer/checkErrors.js.map +1 -0
  18. package/src/consumer/index.d.ts +3 -0
  19. package/src/consumer/index.js +135 -0
  20. package/src/consumer/index.js.map +1 -0
  21. package/src/consumer/types.d.ts +110 -0
  22. package/src/consumer/types.js +3 -0
  23. package/src/consumer/types.js.map +1 -0
  24. package/src/ffi/index.d.ts +1 -0
  25. package/src/ffi/index.js +3 -0
  26. package/src/ffi/index.js.map +1 -1
  27. package/src/ffi/types.d.ts +27 -0
  28. package/src/ffi/types.js +42 -0
  29. package/src/ffi/types.js.map +1 -0
  30. package/src/index.d.ts +1 -0
  31. package/src/index.js +1 -0
  32. package/src/index.js.map +1 -1
  33. package/src/logger/index.d.ts +5 -2
  34. package/src/logger/index.js +15 -2
  35. package/src/logger/index.js.map +1 -1
  36. package/ffi/libpact_ffi.so.gz +0 -0
  37. package/native/consumer.c +0 -210
  38. package/src/ffi/declarations.d.ts +0 -136
  39. package/src/ffi/declarations.js +0 -92
  40. package/src/ffi/declarations.js.map +0 -1
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.makeConsumerPact = void 0;
15
+ var types_1 = require("../ffi/types");
16
+ var logger_1 = require("../logger");
17
+ var checkErrors_1 = require("./checkErrors");
18
+ var bindings = require("bindings");
19
+ var makeConsumerPact = function (consumer, provider, version, logLevel) {
20
+ if (version === void 0) { version = 3; }
21
+ if (logLevel === void 0) { logLevel = logger_1.getLogLevel(); }
22
+ var lib = bindings('pact.node');
23
+ lib.pactffiInitWithLogLevel(logLevel);
24
+ if (logLevel) {
25
+ logger_1.setLogLevel(logLevel);
26
+ }
27
+ var pactPtr = lib.pactffiNewPact(consumer, provider);
28
+ if (!lib.pactffiWithSpecification(pactPtr, version)) {
29
+ throw new Error("Unable to set core spec version. The pact FfiSpecificationVersion '" + version + "' may be invalid (note this is not the same as the pact spec version)");
30
+ }
31
+ return {
32
+ createMockServer: function (address, requestedPort, tls) {
33
+ if (tls === void 0) { tls = false; }
34
+ var port = lib.pactffiCreateMockServerForPact(pactPtr, address + ":" + (requestedPort ? requestedPort : 0), tls);
35
+ var error = Object.keys(types_1.CREATE_MOCK_SERVER_ERRORS).find(function (key) { return types_1.CREATE_MOCK_SERVER_ERRORS[key] === port; });
36
+ if (error) {
37
+ if (error === 'ADDRESS_NOT_VALID') {
38
+ logger_1.logErrorAndThrow("Unable to start mock server at '" + address + "'. Is the address and port valid?");
39
+ }
40
+ if (error === 'TLS_CONFIG') {
41
+ logger_1.logErrorAndThrow("Unable to create TLS configuration with self-signed certificate");
42
+ }
43
+ logger_1.logCrashAndThrow("The pact core couldn't create the mock server because of an error described by '" + error + "'");
44
+ }
45
+ if (port <= 0) {
46
+ logger_1.logCrashAndThrow("The pact core returned an unhandled error code '" + port + "'");
47
+ }
48
+ return port;
49
+ },
50
+ mockServerMatchedSuccessfully: function (port) {
51
+ return lib.pactffiMockServerMatched(port);
52
+ },
53
+ mockServerMismatches: function (port) {
54
+ var results = JSON.parse(lib.pactffiMockServerMismatches(port));
55
+ return results.map(function (result) { return (__assign(__assign({}, result), ('mismatches' in result
56
+ ? {
57
+ mismatches: result.mismatches.map(function (m) {
58
+ return typeof m === 'string' ? JSON.parse(m) : m;
59
+ }),
60
+ }
61
+ : {}))); });
62
+ },
63
+ cleanupMockServer: function (port) {
64
+ return checkErrors_1.wrapWithCheck(function (port) { return lib.pactffiCleanupMockServer(port); }, 'cleanupMockServer')(port);
65
+ },
66
+ writePactFile: function (port, dir, merge) {
67
+ if (merge === void 0) { merge = true; }
68
+ var result = lib.pactffiWritePactFile(port, dir, !merge);
69
+ switch (result) {
70
+ case types_1.FfiWritePactResponse.SUCCESS:
71
+ return;
72
+ case types_1.FfiWritePactResponse.UNABLE_TO_WRITE_PACT_FILE:
73
+ logger_1.logErrorAndThrow('The pact core was unable to write the pact file');
74
+ case types_1.FfiWritePactResponse.GENERAL_PANIC:
75
+ logger_1.logCrashAndThrow('The pact core panicked while writing the pact file');
76
+ case types_1.FfiWritePactResponse.MOCK_SERVER_NOT_FOUND:
77
+ logger_1.logCrashAndThrow('The pact core was asked to write a pact file from a mock server that appears not to exist');
78
+ default:
79
+ logger_1.logCrashAndThrow("The pact core returned an unknown error code (" + result + ") instead of writing the pact");
80
+ }
81
+ },
82
+ addMetadata: function (namespace, name, value) {
83
+ return lib.pactffiWithPactMetadata(pactPtr, namespace, name, value);
84
+ },
85
+ newInteraction: function (description) {
86
+ var interactionPtr = lib.pactffiNewInteraction(pactPtr, description);
87
+ return checkErrors_1.wrapAllWithCheck({
88
+ uponReceiving: function (description) {
89
+ return lib.pactffiUponReceiving(interactionPtr, description);
90
+ },
91
+ given: function (state) {
92
+ return lib.pactffiGiven(interactionPtr, state);
93
+ },
94
+ givenWithParam: function (state, name, value) {
95
+ return lib.pactffiGivenWithParam(interactionPtr, state, name, value);
96
+ },
97
+ withRequest: function (method, path) {
98
+ return lib.pactffiWithRequest(interactionPtr, method, path);
99
+ },
100
+ withQuery: function (name, index, value) {
101
+ return lib.pactffiWithQueryParameter(interactionPtr, name, index, value);
102
+ },
103
+ withRequestHeader: function (name, index, value) {
104
+ return lib.pactffiWithHeader(interactionPtr, types_1.INTERACTION_PART_REQUEST, name, index, value);
105
+ },
106
+ withRequestBody: function (body, contentType) {
107
+ return lib.pactffiWithBody(interactionPtr, types_1.INTERACTION_PART_REQUEST, contentType, body);
108
+ },
109
+ withRequestBinaryBody: function (body, contentType) {
110
+ return lib.pactffiWithBinaryFile(interactionPtr, types_1.INTERACTION_PART_REQUEST, contentType, body, body.length);
111
+ },
112
+ withRequestMultipartBody: function (contentType, filename, mimePartName) {
113
+ return (lib.pactffiWithMultipartFile(interactionPtr, types_1.INTERACTION_PART_REQUEST, contentType, filename, mimePartName) === undefined);
114
+ },
115
+ withResponseHeader: function (name, index, value) {
116
+ return lib.pactffiWithHeader(interactionPtr, types_1.INTERACTION_PART_RESPONSE, name, index, value);
117
+ },
118
+ withResponseBody: function (body, contentType) {
119
+ return lib.pactffiWithBody(interactionPtr, types_1.INTERACTION_PART_RESPONSE, contentType, body);
120
+ },
121
+ withResponseBinaryBody: function (body, contentType) {
122
+ return lib.pactffiWithBinaryFile(interactionPtr, types_1.INTERACTION_PART_RESPONSE, contentType, body, body.length);
123
+ },
124
+ withResponseMultipartBody: function (contentType, filename, mimePartName) {
125
+ return (lib.pactffiWithMultipartFile(interactionPtr, types_1.INTERACTION_PART_RESPONSE, contentType, filename, mimePartName) === undefined);
126
+ },
127
+ withStatus: function (status) {
128
+ return lib.pactffiResponseStatus(interactionPtr, status);
129
+ },
130
+ });
131
+ },
132
+ };
133
+ };
134
+ exports.makeConsumerPact = makeConsumerPact;
135
+ //# s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,CAAC;gBACD,sBAAsB,EAAE,UAAC,IAAY,EAAE,WAAmB;oBACxD,OAAO,GAAG,CAAC,qBAAqB,CAC9B,cAAc,EACd,iCAAyB,EACzB,WAAW,EACX,IAAI,EACJ,IAAI,CAAC,MAAM,CACZ,CAAC;gBACJ,CAAC;gBACD,yBAAyB,EAAE,UACzB,WAAmB,EACnB,QAAgB,EAChB,YAAoB;oBAEpB,OAAO,CACL,GAAG,CAAC,wBAAwB,CAC1B,cAAc,EACd,iCAAyB,EACzB,WAAW,EACX,QAAQ,EACR,YAAY,CACb,KAAK,SAAS,CAChB,CAAC;gBACJ,CAAC;gBACD,UAAU,EAAE,UAAC,MAAc;oBACzB,OAAO,GAAG,CAAC,qBAAqB,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;gBAC3D,CAAC;aACF,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AA5NW,QAAA,gBAAgB,oBA4N3B"}
@@ -0,0 +1,110 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="ref-napi" />
3
+ export declare type MatchingResult = MatchingResultSuccess | MatchingResultRequestMismatch | MatchingResultRequestNotFound | MatchingResultMissingRequest;
4
+ export declare type MatchingResultSuccess = {
5
+ type: 'request-match';
6
+ };
7
+ export declare type MatchingResultRequestMismatch = {
8
+ type: 'request-mismatch';
9
+ method: string;
10
+ path: string;
11
+ mismatches: Mismatch[];
12
+ };
13
+ export declare type MatchingResultRequestNotFound = {
14
+ type: 'request-not-found';
15
+ method: string;
16
+ path: string;
17
+ request: RequestMismatch;
18
+ };
19
+ export declare type MatchingResultMissingRequest = {
20
+ type: 'missing-request';
21
+ method: string;
22
+ path: string;
23
+ request: RequestMismatch;
24
+ };
25
+ export declare type Mismatch = MethodMismatch | PathMismatch | StatusMismatch | QueryMismatch | HeaderMismatch | BodyTypeMismatch | BodyMismatch | MetadataMismatch;
26
+ export declare type MethodMismatch = {
27
+ type: 'MethodMismatch';
28
+ expected: string;
29
+ actual: string;
30
+ };
31
+ export declare type PathMismatch = {
32
+ type: 'PathMismatch';
33
+ expected: string;
34
+ actual: string;
35
+ mismatch: string;
36
+ };
37
+ export declare type StatusMismatch = {
38
+ type: 'StatusMismatch';
39
+ expected: string;
40
+ actual: string;
41
+ mismatch: string;
42
+ };
43
+ export declare type QueryMismatch = {
44
+ type: 'QueryMismatch';
45
+ parameter: string;
46
+ expected: string;
47
+ actual: string;
48
+ mismatch: string;
49
+ };
50
+ export declare type HeaderMismatch = {
51
+ type: 'HeaderMismatch';
52
+ key: string;
53
+ expected: string;
54
+ actual: string;
55
+ mismatch: string;
56
+ };
57
+ export declare type BodyTypeMismatch = {
58
+ type: 'BodyTypeMismatch';
59
+ expected: string;
60
+ actual: string;
61
+ mismatch: string;
62
+ expectedBody?: string;
63
+ actualBody?: string;
64
+ };
65
+ export declare type BodyMismatch = {
66
+ type: 'BodyMismatch';
67
+ path: string;
68
+ expected?: string;
69
+ actual?: string;
70
+ mismatch: string;
71
+ };
72
+ export declare type MetadataMismatch = {
73
+ type: 'MetadataMismatch';
74
+ key: string;
75
+ expected: string;
76
+ actual: string;
77
+ mismatch: string;
78
+ };
79
+ export declare type RequestMismatch = {
80
+ method?: string;
81
+ path?: string;
82
+ headers?: Record<string, Array<string>>;
83
+ query?: Record<string, Array<string>>;
84
+ body?: string;
85
+ };
86
+ export declare type ConsumerInteraction = {
87
+ uponReceiving: (description: string) => boolean;
88
+ given: (state: string) => boolean;
89
+ givenWithParam: (state: string, name: string, value: string) => boolean;
90
+ withRequest: (method: string, path: string) => boolean;
91
+ withQuery: (name: string, index: number, value: string) => boolean;
92
+ withStatus: (status: number) => boolean;
93
+ withRequestHeader: (name: string, index: number, value: string) => boolean;
94
+ withRequestBody: (body: string, contentType: string) => boolean;
95
+ withRequestBinaryBody: (body: Buffer, contentType: string) => boolean;
96
+ withRequestMultipartBody: (contentType: string, filename: string, mimePartName: string) => boolean;
97
+ withResponseHeader: (name: string, index: number, value: string) => boolean;
98
+ withResponseBody: (body: string, contentType: string) => boolean;
99
+ withResponseBinaryBody: (body: Buffer, contentType: string) => boolean;
100
+ withResponseMultipartBody: (contentType: string, filename: string, mimePartName: string) => boolean;
101
+ };
102
+ export declare type ConsumerPact = {
103
+ newInteraction: (description: string) => ConsumerInteraction;
104
+ createMockServer: (address: string, port?: number, tls?: boolean) => number;
105
+ mockServerMismatches: (port: number) => MatchingResult[];
106
+ cleanupMockServer: (port: number) => boolean;
107
+ writePactFile: (port: number, dir: string, merge?: boolean) => void;
108
+ mockServerMatchedSuccessfully: (port: number) => boolean;
109
+ addMetadata: (namespace: string, name: string, value: string) => boolean;
110
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ export declare const PACT_FFI_VERSION = "0.1.5";
package/src/ffi/index.js CHANGED
@@ -1,2 +1,5 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PACT_FFI_VERSION = void 0;
4
+ exports.PACT_FFI_VERSION = '0.1.5';
2
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AASa,QAAA,gBAAgB,GAAG,OAAO,CAAC"}
@@ -0,0 +1,27 @@
1
+ export declare type FfiSpecificationVersion = 0 | 1 | 2 | 3 | 4 | 5;
2
+ export declare const FfiSpecificationVersion: Record<string, FfiSpecificationVersion>;
3
+ export declare type FfiWritePactResponse = 0 | 1 | 2 | 3;
4
+ export declare const FfiWritePactResponse: Record<string, FfiWritePactResponse>;
5
+ export declare type FfiInteractionPart = 0 | 1;
6
+ export declare const INTERACTION_PART_REQUEST: FfiInteractionPart;
7
+ export declare const INTERACTION_PART_RESPONSE: FfiInteractionPart;
8
+ export declare const CREATE_MOCK_SERVER_ERRORS: {
9
+ NULL_POINTER: number;
10
+ JSON_PARSE_ERROR: number;
11
+ MOCK_SERVER_START_FAIL: number;
12
+ CORE_PANIC: number;
13
+ ADDRESS_NOT_VALID: number;
14
+ TLS_CONFIG: number;
15
+ };
16
+ export declare enum FfiFunctionResult {
17
+ RESULT_OK = 0,
18
+ RESULT_FAILED = 1
19
+ }
20
+ export declare enum FfiLogLevelFilter {
21
+ LOG_LEVEL_OFF = 0,
22
+ LOG_LEVEL_ERROR = 1,
23
+ LOG_LEVEL_WARN = 2,
24
+ LOG_LEVEL_INFO = 3,
25
+ LOG_LEVEL_DEBUG = 4,
26
+ LOG_LEVEL_TRACE = 5
27
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FfiLogLevelFilter = exports.FfiFunctionResult = exports.CREATE_MOCK_SERVER_ERRORS = exports.INTERACTION_PART_RESPONSE = exports.INTERACTION_PART_REQUEST = exports.FfiWritePactResponse = exports.FfiSpecificationVersion = void 0;
4
+ exports.FfiSpecificationVersion = {
5
+ SPECIFICATION_VERSION_UNKNOWN: 0,
6
+ SPECIFICATION_VERSION_V1: 1,
7
+ SPECIFICATION_VERSION_V1_1: 2,
8
+ SPECIFICATION_VERSION_V2: 3,
9
+ SPECIFICATION_VERSION_V3: 4,
10
+ SPECIFICATION_VERSION_V4: 5,
11
+ };
12
+ exports.FfiWritePactResponse = {
13
+ SUCCESS: 0,
14
+ GENERAL_PANIC: 1,
15
+ UNABLE_TO_WRITE_PACT_FILE: 2,
16
+ MOCK_SERVER_NOT_FOUND: 3,
17
+ };
18
+ exports.INTERACTION_PART_REQUEST = 0;
19
+ exports.INTERACTION_PART_RESPONSE = 1;
20
+ exports.CREATE_MOCK_SERVER_ERRORS = {
21
+ NULL_POINTER: -1,
22
+ JSON_PARSE_ERROR: -2,
23
+ MOCK_SERVER_START_FAIL: -3,
24
+ CORE_PANIC: -4,
25
+ ADDRESS_NOT_VALID: -5,
26
+ TLS_CONFIG: -6,
27
+ };
28
+ var FfiFunctionResult;
29
+ (function (FfiFunctionResult) {
30
+ FfiFunctionResult[FfiFunctionResult["RESULT_OK"] = 0] = "RESULT_OK";
31
+ FfiFunctionResult[FfiFunctionResult["RESULT_FAILED"] = 1] = "RESULT_FAILED";
32
+ })(FfiFunctionResult = exports.FfiFunctionResult || (exports.FfiFunctionResult = {}));
33
+ var FfiLogLevelFilter;
34
+ (function (FfiLogLevelFilter) {
35
+ FfiLogLevelFilter[FfiLogLevelFilter["LOG_LEVEL_OFF"] = 0] = "LOG_LEVEL_OFF";
36
+ FfiLogLevelFilter[FfiLogLevelFilter["LOG_LEVEL_ERROR"] = 1] = "LOG_LEVEL_ERROR";
37
+ FfiLogLevelFilter[FfiLogLevelFilter["LOG_LEVEL_WARN"] = 2] = "LOG_LEVEL_WARN";
38
+ FfiLogLevelFilter[FfiLogLevelFilter["LOG_LEVEL_INFO"] = 3] = "LOG_LEVEL_INFO";
39
+ FfiLogLevelFilter[FfiLogLevelFilter["LOG_LEVEL_DEBUG"] = 4] = "LOG_LEVEL_DEBUG";
40
+ FfiLogLevelFilter[FfiLogLevelFilter["LOG_LEVEL_TRACE"] = 5] = "LOG_LEVEL_TRACE";
41
+ })(FfiLogLevelFilter = exports.FfiLogLevelFilter || (exports.FfiLogLevelFilter = {}));
42
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":";;;AAEa,QAAA,uBAAuB,GAClC;IACE,6BAA6B,EAAE,CAAC;IAChC,wBAAwB,EAAE,CAAC;IAC3B,0BAA0B,EAAE,CAAC;IAC7B,wBAAwB,EAAE,CAAC;IAC3B,wBAAwB,EAAE,CAAC;IAC3B,wBAAwB,EAAE,CAAC;CAC5B,CAAC;AAIS,QAAA,oBAAoB,GAAyC;IACxE,OAAO,EAAE,CAAC;IACV,aAAa,EAAE,CAAC;IAChB,yBAAyB,EAAE,CAAC;IAC5B,qBAAqB,EAAE,CAAC;CACzB,CAAC;AAIW,QAAA,wBAAwB,GAAuB,CAAC,CAAC;AACjD,QAAA,yBAAyB,GAAuB,CAAC,CAAC;AAElD,QAAA,yBAAyB,GAAG;IACvC,YAAY,EAAE,CAAC,CAAC;IAChB,gBAAgB,EAAE,CAAC,CAAC;IACpB,sBAAsB,EAAE,CAAC,CAAC;IAC1B,UAAU,EAAE,CAAC,CAAC;IACd,iBAAiB,EAAE,CAAC,CAAC;IACrB,UAAU,EAAE,CAAC,CAAC;CACf,CAAC;AAUF,IAAY,iBAGX;AAHD,WAAY,iBAAiB;IAC3B,mEAAa,CAAA;IACb,2EAAa,CAAA;AACf,CAAC,EAHW,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAG5B;AAED,IAAY,iBAOX;AAPD,WAAY,iBAAiB;IAC3B,2EAAiB,CAAA;IACjB,+EAAe,CAAA;IACf,6EAAc,CAAA;IACd,6EAAc,CAAA;IACd,+EAAe,CAAA;IACf,+EAAe,CAAA;AACjB,CAAC,EAPW,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAO5B"}
package/src/index.d.ts CHANGED
@@ -8,3 +8,4 @@ export * from './logger';
8
8
  export * from './logger/types';
9
9
  export * from './stub';
10
10
  export * from './can-deploy';
11
+ export * from './consumer';
package/src/index.js CHANGED
@@ -21,4 +21,5 @@ __exportStar(require("./logger"), exports);
21
21
  __exportStar(require("./logger/types"), exports);
22
22
  __exportStar(require("./stub"), exports);
23
23
  __exportStar(require("./can-deploy"), exports);
24
+ __exportStar(require("./consumer"), exports);
24
25
  //# sourceMappingURL=index.js.map
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+BAA0B;AAC1B,MAAM,CAAC,OAAO,GAAG,OAAO,GAAG,cAAI,CAAC;AAChC,kBAAe,cAAI,CAAC;AAEpB,6CAA2B;AAC3B,mDAAiC;AAEjC,2CAAyB;AAEzB,8CAA4B;AAE5B,2CAAyB;AACzB,iDAA+B;AAE/B,yCAAuB;AAEvB,+CAA6B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+BAA0B;AAC1B,MAAM,CAAC,OAAO,GAAG,OAAO,GAAG,cAAI,CAAC;AAChC,kBAAe,cAAI,CAAC;AAEpB,6CAA2B;AAC3B,mDAAiC;AAEjC,2CAAyB;AAEzB,8CAA4B;AAE5B,2CAAyB;AACzB,iDAA+B;AAE/B,yCAAuB;AAEvB,+CAA6B;AAE7B,6CAA2B"}
@@ -1,8 +1,9 @@
1
1
  import { LogLevel } from './types';
2
2
  export declare const DEFAULT_LOG_LEVEL = "info";
3
3
  export declare const setLogLevel: (level?: LogLevel) => void;
4
+ export declare const getLogLevel: () => LogLevel;
4
5
  export declare const verboseIsImplied: () => boolean;
5
- declare const _default: {
6
+ declare const logFunctions: {
6
7
  pactCrash: (message: string, context?: string) => void;
7
8
  error: (message: string, context?: string) => void;
8
9
  warn: (message: string, context?: string) => void;
@@ -10,4 +11,6 @@ declare const _default: {
10
11
  debug: (message: string, context?: string) => void;
11
12
  trace: (message: string, context?: string) => void;
12
13
  };
13
- export default _default;
14
+ export declare const logErrorAndThrow: (message: string, context?: string | undefined) => never;
15
+ export declare const logCrashAndThrow: (message: string, context?: string | undefined) => never;
16
+ export default logFunctions;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.verboseIsImplied = exports.setLogLevel = exports.DEFAULT_LOG_LEVEL = void 0;
3
+ exports.logCrashAndThrow = exports.logErrorAndThrow = exports.verboseIsImplied = exports.getLogLevel = exports.setLogLevel = exports.DEFAULT_LOG_LEVEL = void 0;
4
4
  var crashMessage_1 = require("./crashMessage");
5
5
  var pino_1 = require("./pino");
6
6
  var pkg = require('../../package.json');
@@ -14,6 +14,8 @@ var setLogLevel = function (level) {
14
14
  logger = pino_1.createLogger(currentLogLevel);
15
15
  };
16
16
  exports.setLogLevel = setLogLevel;
17
+ var getLogLevel = function () { return currentLogLevel; };
18
+ exports.getLogLevel = getLogLevel;
17
19
  var verboseIsImplied = function () {
18
20
  return currentLogLevel === 'trace' || currentLogLevel === 'debug';
19
21
  };
@@ -21,7 +23,7 @@ exports.verboseIsImplied = verboseIsImplied;
21
23
  var addContext = function (context, message) {
22
24
  return context + ": " + message;
23
25
  };
24
- exports.default = {
26
+ var logFunctions = {
25
27
  pactCrash: function (message, context) {
26
28
  if (context === void 0) { context = logContext; }
27
29
  return logger.error(addContext(context, crashMessage_1.pactCrashMessage(message)));
@@ -47,4 +49,15 @@ exports.default = {
47
49
  return logger.trace(addContext(context, message));
48
50
  },
49
51
  };
52
+ var logErrorAndThrow = function (message, context) {
53
+ logger.error(message, context);
54
+ throw new Error(message);
55
+ };
56
+ exports.logErrorAndThrow = logErrorAndThrow;
57
+ var logCrashAndThrow = function (message, context) {
58
+ logFunctions.pactCrash(message, context);
59
+ throw new Error(message);
60
+ };
61
+ exports.logCrashAndThrow = logCrashAndThrow;
62
+ exports.default = logFunctions;
50
63
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AAAA,+CAAkD;AAClD,+BAAsC;AAItC,IAAM,GAAG,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAE1C,IAAM,UAAU,GAAG,eAAa,GAAG,CAAC,OAAS,CAAC;AAC9C,IAAI,eAAe,GAAa,MAAM,CAAC;AACvC,IAAI,MAAM,GAAG,mBAAY,CAAC,eAAe,CAAC,CAAC;AAE9B,QAAA,iBAAiB,GAAG,MAAM,CAAC;AAEjC,IAAM,WAAW,GAAG,UAAC,KAAwB;IA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AC,CAAC;AAHW,QAAA,gBAAgB,oBAG3B;AAEF,kBAAe,YAAY,CAAC"}
Binary file
package/native/consumer.c DELETED
@@ -1,210 +0,0 @@
1
- #include <stdio.h>
2
- #include <node_api.h>
3
- #include <pact.h>
4
-
5
- // libpact_init
6
- void LibpactInit(napi_env env, napi_callback_info info) {
7
- pactffi_init("LOG_LEVEL");
8
- pactffi_init_with_log_level("INFO");
9
- }
10
-
11
- // libpact_version
12
- napi_value LibpactVersion(napi_env env, napi_callback_info info) {
13
- napi_value version;
14
- napi_status status;
15
-
16
- const char* version_str = pactffi_version();
17
-
18
- status = napi_create_string_utf8(env, version_str, NAPI_AUTO_LENGTH, &version);
19
- if (status != napi_ok) {
20
- napi_throw_error(env, NULL, "Unable to read version from core");
21
- }
22
-
23
- return version;
24
- }
25
-
26
- // libpact_new_pact
27
- napi_value LibpactNewPact(napi_env env, napi_callback_info info) {
28
- napi_value pact;
29
- napi_status status;
30
-
31
- // actually a uint16
32
- PactHandle handle = pactffi_new_pact("consumer", "provider");
33
-
34
- status = napi_create_uint32(env, handle, &pact);
35
- if (status != napi_ok) {
36
- napi_throw_error(env, NULL, "Unable to create a new pact");
37
- }
38
-
39
- return pact;
40
- }
41
-
42
- // libpact_new_interaction
43
- napi_value LibpactNewInteraction(napi_env env, napi_callback_info info) {
44
- napi_status status;
45
- napi_value interaction;
46
-
47
- size_t argc = 1;
48
- PactHandle pact_handle = 0;
49
- napi_value argv[1];
50
- status = napi_get_cb_info(env, info, &argc, argv, NULL, NULL);
51
-
52
- if (status != napi_ok) {
53
- napi_throw_error(env, NULL, "Failed to parse arguments");
54
- }
55
-
56
- status = napi_get_value_uint32(env, argv[0], &pact_handle);
57
- printf("Received pact handle: %d\n", pact_handle);
58
-
59
- // actually a uint16
60
- InteractionHandle handle = pactffi_new_interaction(pact_handle, "empty description");
61
-
62
- status = napi_create_uint32(env, handle, &interaction);
63
- if (status != napi_ok) {
64
- napi_throw_error(env, NULL, "Unable to create a new pact");
65
- }
66
-
67
- return interaction;
68
- }
69
-
70
- // libpact_upon_receiving
71
- napi_value LibpactUponReceiving(napi_env env, napi_callback_info info) {
72
- napi_status status;
73
- napi_value res;
74
-
75
- size_t argc = 1;
76
- InteractionHandle interaction_handle = 0;
77
- napi_value argv[1];
78
- status = napi_get_cb_info(env, info, &argc, argv, NULL, NULL);
79
-
80
- if (status != napi_ok) {
81
- napi_throw_error(env, NULL, "Failed to parse arguments");
82
- }
83
-
84
- status = napi_get_value_uint32(env, argv[0], &interaction_handle);
85
- printf("Received interaction handle: %d\n", interaction_handle);
86
-
87
- // actually a uint32
88
- int success = pactffi_upon_receiving(interaction_handle, "new description");
89
-
90
- status = napi_get_boolean(env, success, &res);
91
- if (status != napi_ok) {
92
- napi_throw_error(env, NULL, "Unable to set upon receiving");
93
- }
94
-
95
- return res;
96
- }
97
-
98
- // libpact_verify
99
- napi_value LibpactVerifyProvider(napi_env env, napi_callback_info info) {
100
- napi_status status;
101
- napi_value response;
102
- napi_value argv[1];
103
-
104
- size_t argc = 1;
105
- status = napi_get_cb_info(env, info, &argc, argv, NULL, NULL);
106
- if (status != napi_ok) {
107
- napi_throw_error(env, NULL, "Failed to parse arguments");
108
- }
109
-
110
- char *args;
111
- size_t str_size;
112
-
113
- // First determine the string size: https://nodejs.org/api/n-api.html#napi_get_value_string_utf8
114
- napi_get_value_string_utf8(env, argv[0], NULL, 0, &str_size);
115
- str_size += 1;
116
-
117
- args = (char*)calloc(str_size + 1, sizeof(char));
118
- size_t str_size_read;
119
-
120
- // Get the actual string now the size is known
121
- status = napi_get_value_string_utf8(env, argv[0], args, str_size, &str_size_read);
122
- if (status != napi_ok) {
123
- napi_throw_error(env, NULL, "Unable to read the verification arguments");
124
- }
125
-
126
- int res = pactffi_verify(args);
127
-
128
- status = napi_create_uint32(env, res, &response);
129
- if (status != napi_ok) {
130
- napi_throw_error(env, NULL, "Unable to verify pact");
131
- }
132
-
133
- return response;
134
- }
135
-
136
-
137
- napi_value Init(napi_env env, napi_value exports) {
138
- napi_status status;
139
- napi_value fn;
140
-
141
- // version
142
- status = napi_create_function(env, NULL, 0, LibpactVersion, NULL, &fn);
143
- if (status != napi_ok) {
144
- napi_throw_error(env, NULL, "Unable to wrap native function: version");
145
- }
146
-
147
- status = napi_set_named_property(env, exports, "version", fn);
148
- if (status != napi_ok) {
149
- napi_throw_error(env, NULL, "Unable to populate exports for: version");
150
- }
151
-
152
- // init
153
- status = napi_create_function(env, NULL, 0, LibpactInit, NULL, &fn);
154
- if (status != napi_ok) {
155
- napi_throw_error(env, NULL, "Unable to wrap native function: init");
156
- }
157
-
158
- status = napi_set_named_property(env, exports, "init", fn);
159
- if (status != napi_ok) {
160
- napi_throw_error(env, NULL, "Unable to populate exports for: init");
161
- }
162
-
163
- // new pact
164
- status = napi_create_function(env, NULL, 0, LibpactNewPact, NULL, &fn);
165
- if (status != napi_ok) {
166
- napi_throw_error(env, NULL, "Unable to wrap native function: new_pact");
167
- }
168
-
169
- status = napi_set_named_property(env, exports, "new_pact", fn);
170
- if (status != napi_ok) {
171
- napi_throw_error(env, NULL, "Unable to populate exports for: new_pact");
172
- }
173
-
174
- // new interaction
175
- status = napi_create_function(env, NULL, 0, LibpactNewInteraction, NULL, &fn);
176
- if (status != napi_ok) {
177
- napi_throw_error(env, NULL, "Unable to wrap native function: new_interaction");
178
- }
179
-
180
- status = napi_set_named_property(env, exports, "new_interaction", fn);
181
- if (status != napi_ok) {
182
- napi_throw_error(env, NULL, "Unable to populate exports for: new_interaction");
183
- }
184
-
185
- // upon receiving
186
- status = napi_create_function(env, NULL, 0, LibpactUponReceiving, NULL, &fn);
187
- if (status != napi_ok) {
188
- napi_throw_error(env, NULL, "Unable to wrap native function: upon_receiving");
189
- }
190
-
191
- status = napi_set_named_property(env, exports, "upon_receiving", fn);
192
- if (status != napi_ok) {
193
- napi_throw_error(env, NULL, "Unable to populate exports for: upon_receiving");
194
- }
195
-
196
- // verify (provider)
197
- status = napi_create_function(env, NULL, 0, LibpactVerifyProvider, NULL, &fn);
198
- if (status != napi_ok) {
199
- napi_throw_error(env, NULL, "Unable to wrap native function: verify_provider");
200
- }
201
-
202
- status = napi_set_named_property(env, exports, "verify_provider", fn);
203
- if (status != napi_ok) {
204
- napi_throw_error(env, NULL, "Unable to populate exports for: verify_provider");
205
- }
206
-
207
- return exports;
208
- }
209
-
210
- NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)