@pact-foundation/pact-core 13.12.0 → 13.12.2

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/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [13.12.2](https://github.com/pact-foundation/pact-js-core/compare/v13.12.1...v13.12.2) (2022-11-28)
6
+
7
+
8
+ ### Fixes and Improvements
9
+
10
+ * upgrade to ffi 0.3.15 ([0da476d](https://github.com/pact-foundation/pact-js-core/commit/0da476dbd342f64234515572408fd43b28b5085b))
11
+
12
+ ### [13.12.1](https://github.com/pact-foundation/pact-js-core/compare/v13.12.0...v13.12.1) (2022-11-24)
13
+
14
+
15
+ ### Fixes and Improvements
16
+
17
+ * upgrade to latest pino. Fixes 417 ([2de141c](https://github.com/pact-foundation/pact-js-core/commit/2de141c9f93d9423d18c4a574ca6775eaaba5775))
18
+
5
19
  ## [13.12.0](https://github.com/pact-foundation/pact-js-core/compare/v13.11.3...v13.12.0) (2022-11-08)
6
20
 
7
21
 
package/build/Makefile CHANGED
@@ -58,7 +58,7 @@ CFLAGS.host ?= $(CPPFLAGS_host) $(CFLAGS_host)
58
58
  CXX.host ?= g++
59
59
  CXXFLAGS.host ?= $(CPPFLAGS_host) $(CXXFLAGS_host)
60
60
  LINK.host ?= $(CXX.host)
61
- LDFLAGS.host ?=
61
+ LDFLAGS.host ?= $(LDFLAGS_host)
62
62
  AR.host ?= ar
63
63
 
64
64
  # Define a dir function that can handle spaces.
@@ -121,17 +121,17 @@ endef
121
121
  # - quiet_cmd_foo is the brief-output summary of the command.
122
122
 
123
123
  quiet_cmd_cc = CC($(TOOLSET)) $@
124
- cmd_cc = $(CC.$(TOOLSET)) $(GYP_CFLAGS) $(DEPFLAGS) $(CFLAGS.$(TOOLSET)) -c -o $@ $<
124
+ cmd_cc = $(CC.$(TOOLSET)) -o $@ $< $(GYP_CFLAGS) $(DEPFLAGS) $(CFLAGS.$(TOOLSET)) -c
125
125
 
126
126
  quiet_cmd_cxx = CXX($(TOOLSET)) $@
127
- cmd_cxx = $(CXX.$(TOOLSET)) $(GYP_CXXFLAGS) $(DEPFLAGS) $(CXXFLAGS.$(TOOLSET)) -c -o $@ $<
127
+ cmd_cxx = $(CXX.$(TOOLSET)) -o $@ $< $(GYP_CXXFLAGS) $(DEPFLAGS) $(CXXFLAGS.$(TOOLSET)) -c
128
128
 
129
129
  quiet_cmd_touch = TOUCH $@
130
130
  cmd_touch = touch $@
131
131
 
132
132
  quiet_cmd_copy = COPY $@
133
133
  # send stderr to /dev/null to ignore messages when linking directories.
134
- cmd_copy = rm -rf "$@" && cp -af "$<" "$@"
134
+ cmd_copy = ln -f "$<" "$@" 2>/dev/null || (rm -rf "$@" && cp -af "$<" "$@")
135
135
 
136
136
  quiet_cmd_alink = AR($(TOOLSET)) $@
137
137
  cmd_alink = rm -f $@ && $(AR.$(TOOLSET)) crs $@ $(filter %.o,$^)
@@ -143,7 +143,7 @@ cmd_alink_thin = rm -f $@ && $(AR.$(TOOLSET)) crsT $@ $(filter %.o,$^)
143
143
  # special "figure out circular dependencies" flags around the entire
144
144
  # input list during linking.
145
145
  quiet_cmd_link = LINK($(TOOLSET)) $@
146
- cmd_link = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ -Wl,--start-group $(LD_INPUTS) $(LIBS) -Wl,--end-group
146
+ cmd_link = $(LINK.$(TOOLSET)) -o $@ $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,--start-group $(LD_INPUTS) $(LIBS) -Wl,--end-group
147
147
 
148
148
  # We support two kinds of shared objects (.so):
149
149
  # 1) shared_library, which is just bundling together many dependent libraries
@@ -162,10 +162,10 @@ cmd_link = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ -Wl,--s
162
162
  # - Set SONAME to the library filename so our binaries don't reference
163
163
  # the local, absolute paths used on the link command-line.
164
164
  quiet_cmd_solink = SOLINK($(TOOLSET)) $@
165
- cmd_solink = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,-soname=$(@F) -o $@ -Wl,--whole-archive $(LD_INPUTS) -Wl,--no-whole-archive $(LIBS)
165
+ cmd_solink = $(LINK.$(TOOLSET)) -o $@ -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,-soname=$(@F) -Wl,--whole-archive $(LD_INPUTS) -Wl,--no-whole-archive $(LIBS)
166
166
 
167
167
  quiet_cmd_solink_module = SOLINK_MODULE($(TOOLSET)) $@
168
- cmd_solink_module = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,-soname=$(@F) -o $@ -Wl,--start-group $(filter-out FORCE_DO_CMD, $^) -Wl,--end-group $(LIBS)
168
+ cmd_solink_module = $(LINK.$(TOOLSET)) -o $@ -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,-soname=$(@F) -Wl,--start-group $(filter-out FORCE_DO_CMD, $^) -Wl,--end-group $(LIBS)
169
169
 
170
170
 
171
171
  # Define an escape_quotes function to escape single quotes.
@@ -318,8 +318,8 @@ ifeq ($(strip $(foreach prefix,$(NO_LOAD),\
318
318
  endif
319
319
 
320
320
  quiet_cmd_regen_makefile = ACTION Regenerating $@
321
- cmd_regen_makefile = cd $(srcdir); /opt/hostedtoolcache/node/12.22.12/x64/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py -fmake --ignore-environment "-Dlibrary=shared_library" "-Dvisibility=default" "-Dnode_root_dir=/home/runner/.cache/node-gyp/12.22.12" "-Dnode_gyp_dir=/opt/hostedtoolcache/node/12.22.12/x64/lib/node_modules/npm/node_modules/node-gyp" "-Dnode_lib_file=/home/runner/.cache/node-gyp/12.22.12/<(target_arch)/node.lib" "-Dmodule_root_dir=/home/runner/work/pact-js-core/pact-js-core" "-Dnode_engine=v8" "--depth=." "-Goutput_dir=." "--generator-output=build" -I/home/runner/work/pact-js-core/pact-js-core/build/config.gypi -I/opt/hostedtoolcache/node/12.22.12/x64/lib/node_modules/npm/node_modules/node-gyp/addon.gypi -I/home/runner/.cache/node-gyp/12.22.12/include/node/common.gypi "--toplevel-dir=." binding.gyp
322
- Makefile: $(srcdir)/build/config.gypi $(srcdir)/../../../.cache/node-gyp/12.22.12/include/node/common.gypi $(srcdir)/binding.gyp $(srcdir)/../../../../../opt/hostedtoolcache/node/12.22.12/x64/lib/node_modules/npm/node_modules/node-gyp/addon.gypi
321
+ cmd_regen_makefile = cd $(srcdir); /opt/hostedtoolcache/node/16.18.1/x64/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py -fmake --ignore-environment "-Dlibrary=shared_library" "-Dvisibility=default" "-Dnode_root_dir=/home/runner/.cache/node-gyp/16.18.1" "-Dnode_gyp_dir=/opt/hostedtoolcache/node/16.18.1/x64/lib/node_modules/npm/node_modules/node-gyp" "-Dnode_lib_file=/home/runner/.cache/node-gyp/16.18.1/<(target_arch)/node.lib" "-Dmodule_root_dir=/home/runner/work/pact-js-core/pact-js-core" "-Dnode_engine=v8" "--depth=." "-Goutput_dir=." "--generator-output=build" -I/home/runner/work/pact-js-core/pact-js-core/build/config.gypi -I/opt/hostedtoolcache/node/16.18.1/x64/lib/node_modules/npm/node_modules/node-gyp/addon.gypi -I/home/runner/.cache/node-gyp/16.18.1/include/node/common.gypi "--toplevel-dir=." binding.gyp
322
+ Makefile: $(srcdir)/build/config.gypi $(srcdir)/../../../.cache/node-gyp/16.18.1/include/node/common.gypi $(srcdir)/../../../../../opt/hostedtoolcache/node/16.18.1/x64/lib/node_modules/npm/node_modules/node-gyp/addon.gypi $(srcdir)/binding.gyp
323
323
  $(call do_cmd,regen_makefile)
324
324
 
325
325
  # "all" is a concatenation of the "all" targets from all the included
@@ -9,6 +9,7 @@ DEFS_Debug := \
9
9
  '-DV8_DEPRECATION_WARNINGS=1' \
10
10
  '-DV8_DEPRECATION_WARNINGS' \
11
11
  '-DV8_IMMINENT_DEPRECATION_WARNINGS' \
12
+ '-D_GLIBCXX_USE_CXX11_ABI=1' \
12
13
  '-D_LARGEFILE_SOURCE' \
13
14
  '-D_FILE_OFFSET_BITS=64' \
14
15
  '-D__STDC_FORMAT_MACROS' \
@@ -37,17 +38,17 @@ CFLAGS_C_Debug :=
37
38
  # Flags passed to only C++ files.
38
39
  CFLAGS_CC_Debug := \
39
40
  -fno-rtti \
40
- -std=gnu++1y \
41
+ -std=gnu++14 \
41
42
  -Werror
42
43
 
43
44
  INCS_Debug := \
44
- -I/home/runner/.cache/node-gyp/12.22.12/include/node \
45
- -I/home/runner/.cache/node-gyp/12.22.12/src \
46
- -I/home/runner/.cache/node-gyp/12.22.12/deps/openssl/config \
47
- -I/home/runner/.cache/node-gyp/12.22.12/deps/openssl/openssl/include \
48
- -I/home/runner/.cache/node-gyp/12.22.12/deps/uv/include \
49
- -I/home/runner/.cache/node-gyp/12.22.12/deps/zlib \
50
- -I/home/runner/.cache/node-gyp/12.22.12/deps/v8/include \
45
+ -I/home/runner/.cache/node-gyp/16.18.1/include/node \
46
+ -I/home/runner/.cache/node-gyp/16.18.1/src \
47
+ -I/home/runner/.cache/node-gyp/16.18.1/deps/openssl/config \
48
+ -I/home/runner/.cache/node-gyp/16.18.1/deps/openssl/openssl/include \
49
+ -I/home/runner/.cache/node-gyp/16.18.1/deps/uv/include \
50
+ -I/home/runner/.cache/node-gyp/16.18.1/deps/zlib \
51
+ -I/home/runner/.cache/node-gyp/16.18.1/deps/v8/include \
51
52
  -I$(srcdir)/node_modules/node-addon-api \
52
53
  -I/home/runner/work/pact-js-core/pact-js-core/native \
53
54
  -I/home/runner/work/pact-js-core/pact-js-core/ffi
@@ -59,6 +60,7 @@ DEFS_Release := \
59
60
  '-DV8_DEPRECATION_WARNINGS=1' \
60
61
  '-DV8_DEPRECATION_WARNINGS' \
61
62
  '-DV8_IMMINENT_DEPRECATION_WARNINGS' \
63
+ '-D_GLIBCXX_USE_CXX11_ABI=1' \
62
64
  '-D_LARGEFILE_SOURCE' \
63
65
  '-D_FILE_OFFSET_BITS=64' \
64
66
  '-D__STDC_FORMAT_MACROS' \
@@ -84,17 +86,17 @@ CFLAGS_C_Release :=
84
86
  # Flags passed to only C++ files.
85
87
  CFLAGS_CC_Release := \
86
88
  -fno-rtti \
87
- -std=gnu++1y \
89
+ -std=gnu++14 \
88
90
  -Werror
89
91
 
90
92
  INCS_Release := \
91
- -I/home/runner/.cache/node-gyp/12.22.12/include/node \
92
- -I/home/runner/.cache/node-gyp/12.22.12/src \
93
- -I/home/runner/.cache/node-gyp/12.22.12/deps/openssl/config \
94
- -I/home/runner/.cache/node-gyp/12.22.12/deps/openssl/openssl/include \
95
- -I/home/runner/.cache/node-gyp/12.22.12/deps/uv/include \
96
- -I/home/runner/.cache/node-gyp/12.22.12/deps/zlib \
97
- -I/home/runner/.cache/node-gyp/12.22.12/deps/v8/include \
93
+ -I/home/runner/.cache/node-gyp/16.18.1/include/node \
94
+ -I/home/runner/.cache/node-gyp/16.18.1/src \
95
+ -I/home/runner/.cache/node-gyp/16.18.1/deps/openssl/config \
96
+ -I/home/runner/.cache/node-gyp/16.18.1/deps/openssl/openssl/include \
97
+ -I/home/runner/.cache/node-gyp/16.18.1/deps/uv/include \
98
+ -I/home/runner/.cache/node-gyp/16.18.1/deps/zlib \
99
+ -I/home/runner/.cache/node-gyp/16.18.1/deps/v8/include \
98
100
  -I$(srcdir)/node_modules/node-addon-api \
99
101
  -I/home/runner/work/pact-js-core/pact-js-core/native \
100
102
  -I/home/runner/work/pact-js-core/pact-js-core/ffi
Binary file
Binary file
Binary file
Binary file
Binary file
package/ffi/pact-cpp.h CHANGED
@@ -17,6 +17,36 @@
17
17
  #include <ostream>
18
18
  #include <new>
19
19
 
20
+ /**
21
+ * The type of value detected after parsing the expression
22
+ */
23
+ enum class ExpressionValueType {
24
+ /**
25
+ * If the type is unknown
26
+ */
27
+ ExpressionValueType_Unknown,
28
+ /**
29
+ * String type
30
+ */
31
+ ExpressionValueType_String,
32
+ /**
33
+ * Numeric type
34
+ */
35
+ ExpressionValueType_Number,
36
+ /**
37
+ * Integer numeric type (no significant figures after the decimal point)
38
+ */
39
+ ExpressionValueType_Integer,
40
+ /**
41
+ * Decimal numeric type (at least one significant figure after the decimal point)
42
+ */
43
+ ExpressionValueType_Decimal,
44
+ /**
45
+ * Boolean type
46
+ */
47
+ ExpressionValueType_Boolean,
48
+ };
49
+
20
50
  /**
21
51
  * Request or Response enum
22
52
  */
@@ -81,6 +111,26 @@ enum class PactSpecification {
81
111
  */
82
112
  struct Consumer;
83
113
 
114
+ /**
115
+ * Trait to represent a generator
116
+ */
117
+ struct Generator;
118
+
119
+ /**
120
+ * Set of all matching rules
121
+ */
122
+ struct MatchingRule;
123
+
124
+ /**
125
+ * Result of parsing a matching rule definition
126
+ */
127
+ struct MatchingRuleDefinitionResult;
128
+
129
+ /**
130
+ * An iterator over the matching rules from a matching definition expression.
131
+ */
132
+ struct MatchingRuleIterator;
133
+
84
134
  /**
85
135
  * Struct that defines a message.
86
136
  */
@@ -129,6 +179,11 @@ struct Mismatches;
129
179
  */
130
180
  struct MismatchesIterator;
131
181
 
182
+ /**
183
+ * Opaque type for use as a pointer to a Pact model
184
+ */
185
+ struct Pact;
186
+
132
187
  /**
133
188
  * An iterator over messages in a pact.
134
189
  */
@@ -228,6 +283,65 @@ struct ProviderStateParamPair {
228
283
  const char *value;
229
284
  };
230
285
 
286
+ /**
287
+ * The matching rule or reference from parsing the matching definition expression.
288
+ *
289
+ * For matching rules, the ID corresponds to the following rules:
290
+ * | Rule | ID |
291
+ * | ---- | -- |
292
+ * | Equality | 1 |
293
+ * | Regex | 2 |
294
+ * | Type | 3 |
295
+ * | MinType | 4 |
296
+ * | MaxType | 5 |
297
+ * | MinMaxType | 6 |
298
+ * | Timestamp | 7 |
299
+ * | Time | 8 |
300
+ * | Date | 9 |
301
+ * | Include | 10 |
302
+ * | Number | 11 |
303
+ * | Integer | 12 |
304
+ * | Decimal | 13 |
305
+ * | Null | 14 |
306
+ * | ContentType | 15 |
307
+ * | ArrayContains | 16 |
308
+ * | Values | 17 |
309
+ * | Boolean | 18 |
310
+ * | StatusCode | 19 |
311
+ * | NotEmpty | 20 |
312
+ * | Semver | 21 |
313
+ * | EachKey | 22 |
314
+ * | EachValue | 23 |
315
+ */
316
+ struct MatchingRuleResult {
317
+ enum class Tag {
318
+ /**
319
+ * The matching rule from the expression.
320
+ */
321
+ MatchingRuleResult_MatchingRule,
322
+ /**
323
+ * A reference to a named item.
324
+ */
325
+ MatchingRuleResult_MatchingReference,
326
+ };
327
+
328
+ struct MatchingRuleResult_MatchingRule_Body {
329
+ uint16_t _0;
330
+ const char *_1;
331
+ const MatchingRule *_2;
332
+ };
333
+
334
+ struct MatchingRuleResult_MatchingReference_Body {
335
+ const char *_0;
336
+ };
337
+
338
+ Tag tag;
339
+ union {
340
+ MatchingRuleResult_MatchingRule_Body matching_rule;
341
+ MatchingRuleResult_MatchingReference_Body matching_reference;
342
+ };
343
+ };
344
+
231
345
  /**
232
346
  * Wraps a Pact model struct
233
347
  */
@@ -529,6 +643,21 @@ int pactffi_logger_apply();
529
643
  */
530
644
  const char *pactffi_fetch_log_buffer(const char *log_id);
531
645
 
646
+ /**
647
+ * Parses the provided JSON into a Pact model. The returned Pact model must be freed with the
648
+ * `pactffi_pact_model_delete` function when no longer needed.
649
+ *
650
+ * # Error Handling
651
+ *
652
+ * This function will return a NULL pointer if passed a NULL pointer or if an error occurs.
653
+ */
654
+ Pact *pactffi_parse_pact_json(const char *json);
655
+
656
+ /**
657
+ * Frees the memory used by the Pact model
658
+ */
659
+ void pactffi_pact_model_delete(Pact *pact);
660
+
532
661
  /**
533
662
  * Get a copy of this consumer's name.
534
663
  *
@@ -1766,6 +1895,144 @@ const ProviderState *pactffi_sync_http_get_provider_state(const SynchronousHttp
1766
1895
  */
1767
1896
  ProviderStateIterator *pactffi_sync_http_get_provider_state_iter(SynchronousHttp *interaction);
1768
1897
 
1898
+ /**
1899
+ * Parse a matcher definition string into a MatchingRuleDefinition containing the example value,
1900
+ * and matching rules and any generator.
1901
+ *
1902
+ * The following are examples of matching rule definitions:
1903
+ * * `matching(type,'Name')` - type matcher with string value 'Name'
1904
+ * * `matching(number,100)` - number matcher
1905
+ * * `matching(datetime, 'yyyy-MM-dd','2000-01-01')` - datetime matcher with format string
1906
+ *
1907
+ * See [Matching Rule definition expressions](https://docs.rs/pact_models/latest/pact_models/matchingrules/expressions/index.html).
1908
+ *
1909
+ * The returned value needs to be freed up with the `pactffi_matcher_definition_delete` function.
1910
+ *
1911
+ * # Errors
1912
+ * If the expression is invalid, the MatchingRuleDefinition error will be set. You can check for
1913
+ * this value with the `pactffi_matcher_definition_error` function.
1914
+ *
1915
+ * # Safety
1916
+ *
1917
+ * This function is safe if the expression is a valid NULL terminated string pointer.
1918
+ */
1919
+ const MatchingRuleDefinitionResult *pactffi_parse_matcher_definition(const char *expression);
1920
+
1921
+ /**
1922
+ * Returns any error message from parsing a matching definition expression. If there is no error,
1923
+ * it will return a NULL pointer, otherwise returns the error message as a NULL-terminated string.
1924
+ * The returned string must be freed using the `pactffi_string_delete` function once done with it.
1925
+ */
1926
+ const char *pactffi_matcher_definition_error(const MatchingRuleDefinitionResult *definition);
1927
+
1928
+ /**
1929
+ * Returns the value from parsing a matching definition expression. If there was an error,
1930
+ * it will return a NULL pointer, otherwise returns the value as a NULL-terminated string.
1931
+ * The returned string must be freed using the `pactffi_string_delete` function once done with it.
1932
+ *
1933
+ * Note that different expressions values can have types other than a string. Use
1934
+ * `pactffi_matcher_definition_value_type` to get the actual type of the value. This function
1935
+ * will always return the string representation of the value.
1936
+ */
1937
+ const char *pactffi_matcher_definition_value(const MatchingRuleDefinitionResult *definition);
1938
+
1939
+ /**
1940
+ * Frees the memory used by the result of parsing the matching definition expression
1941
+ */
1942
+ void pactffi_matcher_definition_delete(const MatchingRuleDefinitionResult *definition);
1943
+
1944
+ /**
1945
+ * Returns the generator from parsing a matching definition expression. If there was an error or
1946
+ * there is no associated generator, it will return a NULL pointer, otherwise returns the generator
1947
+ * as a pointer.
1948
+ *
1949
+ * The generator pointer will be a valid pointer as long as `pactffi_matcher_definition_delete`
1950
+ * has not been called on the definition. Using the generator pointer after the definition
1951
+ * has been deleted will result in undefined behaviour.
1952
+ */
1953
+ const Generator *pactffi_matcher_definition_generator(const MatchingRuleDefinitionResult *definition);
1954
+
1955
+ /**
1956
+ * Returns the type of the value from parsing a matching definition expression. If there was an
1957
+ * error parsing the expression, it will return Unknown.
1958
+ */
1959
+ ExpressionValueType pactffi_matcher_definition_value_type(const MatchingRuleDefinitionResult *definition);
1960
+
1961
+ /**
1962
+ * Free the iterator when you're done using it.
1963
+ */
1964
+ void pactffi_matching_rule_iter_delete(MatchingRuleIterator *iter);
1965
+
1966
+ /**
1967
+ * Returns an iterator over the matching rules from the parsed definition. The iterator needs to
1968
+ * be deleted with the `pactffi_matching_rule_iter_delete` function once done with it.
1969
+ *
1970
+ * If there was an error parsing the expression, this function will return a NULL pointer.
1971
+ */
1972
+ MatchingRuleIterator *pactffi_matcher_definition_iter(const MatchingRuleDefinitionResult *definition);
1973
+
1974
+ /**
1975
+ * Get the next matching rule or reference from the iterator. As the values returned are owned
1976
+ * by the iterator, they do not need to be deleted but will be cleaned up when the iterator is
1977
+ * deleted.
1978
+ *
1979
+ * Will return a NULL pointer when the iterator has advanced past the end of the list.
1980
+ *
1981
+ * # Safety
1982
+ *
1983
+ * This function is safe.
1984
+ *
1985
+ * # Error Handling
1986
+ *
1987
+ * This function will return a NULL pointer if passed a NULL pointer or if an error occurs.
1988
+ */
1989
+ const MatchingRuleResult *pactffi_matching_rule_iter_next(MatchingRuleIterator *iter);
1990
+
1991
+ /**
1992
+ * Get the JSON form of the matching rule.
1993
+ *
1994
+ * The returned string must be deleted with `pactffi_string_delete`.
1995
+ *
1996
+ * # Safety
1997
+ *
1998
+ * This function will fail if it is passed a NULL pointer, or the iterator that owns the
1999
+ * value of the matching rule has been deleted.
2000
+ */
2001
+ const char *pactffi_matching_rule_to_json(const MatchingRule *rule);
2002
+
2003
+ /**
2004
+ * Get the JSON form of the generator.
2005
+ *
2006
+ * The returned string must be deleted with `pactffi_string_delete`.
2007
+ *
2008
+ * # Safety
2009
+ *
2010
+ * This function will fail if it is passed a NULL pointer, or the owner of the generator has
2011
+ * been deleted.
2012
+ */
2013
+ const char *pactffi_generator_to_json(const Generator *generator);
2014
+
2015
+ /**
2016
+ * Generate a string value using the provided generator and an optional JSON payload containing
2017
+ * any generator context. The context value is used for generators like `MockServerURL` (which
2018
+ * should contain details about the running mock server) and `ProviderStateGenerator` (which
2019
+ * should be the values returned from the Provider State callback function).
2020
+ *
2021
+ * If anything goes wrong, it will return a NULL pointer.
2022
+ */
2023
+ const char *pactffi_generator_generate_string(const Generator *generator, const char *context_json);
2024
+
2025
+ /**
2026
+ * Generate an integer value using the provided generator and an optional JSON payload containing
2027
+ * any generator context. The context value is used for generators like `ProviderStateGenerator`
2028
+ * (which should be the values returned from the Provider State callback function).
2029
+ *
2030
+ * If anything goes wrong or the generator is not a type that can generate an integer value, it
2031
+ * will return a zero value.
2032
+ */
2033
+ unsigned short pactffi_generator_generate_integer(const Generator *generator,
2034
+ const char *context_json);
2035
+
1769
2036
  /**
1770
2037
  * Delete a string previously returned by this FFI.
1771
2038
  *
package/ffi/pact.h CHANGED
@@ -16,6 +16,36 @@
16
16
  #include <stdint.h>
17
17
  #include <stdlib.h>
18
18
 
19
+ /**
20
+ * The type of value detected after parsing the expression
21
+ */
22
+ typedef enum ExpressionValueType {
23
+ /**
24
+ * If the type is unknown
25
+ */
26
+ ExpressionValueType_Unknown,
27
+ /**
28
+ * String type
29
+ */
30
+ ExpressionValueType_String,
31
+ /**
32
+ * Numeric type
33
+ */
34
+ ExpressionValueType_Number,
35
+ /**
36
+ * Integer numeric type (no significant figures after the decimal point)
37
+ */
38
+ ExpressionValueType_Integer,
39
+ /**
40
+ * Decimal numeric type (at least one significant figure after the decimal point)
41
+ */
42
+ ExpressionValueType_Decimal,
43
+ /**
44
+ * Boolean type
45
+ */
46
+ ExpressionValueType_Boolean,
47
+ } ExpressionValueType;
48
+
19
49
  /**
20
50
  * Request or Response enum
21
51
  */
@@ -80,6 +110,26 @@ typedef enum PactSpecification {
80
110
  */
81
111
  typedef struct Consumer Consumer;
82
112
 
113
+ /**
114
+ * Trait to represent a generator
115
+ */
116
+ typedef struct Generator Generator;
117
+
118
+ /**
119
+ * Set of all matching rules
120
+ */
121
+ typedef struct MatchingRule MatchingRule;
122
+
123
+ /**
124
+ * Result of parsing a matching rule definition
125
+ */
126
+ typedef struct MatchingRuleDefinitionResult MatchingRuleDefinitionResult;
127
+
128
+ /**
129
+ * An iterator over the matching rules from a matching definition expression.
130
+ */
131
+ typedef struct MatchingRuleIterator MatchingRuleIterator;
132
+
83
133
  /**
84
134
  * Struct that defines a message.
85
135
  */
@@ -128,6 +178,11 @@ typedef struct Mismatches Mismatches;
128
178
  */
129
179
  typedef struct MismatchesIterator MismatchesIterator;
130
180
 
181
+ /**
182
+ * Opaque type for use as a pointer to a Pact model
183
+ */
184
+ typedef struct Pact Pact;
185
+
131
186
  /**
132
187
  * An iterator over messages in a pact.
133
188
  */
@@ -227,6 +282,63 @@ typedef struct ProviderStateParamPair {
227
282
  const char *value;
228
283
  } ProviderStateParamPair;
229
284
 
285
+ /**
286
+ * The matching rule or reference from parsing the matching definition expression.
287
+ *
288
+ * For matching rules, the ID corresponds to the following rules:
289
+ * | Rule | ID |
290
+ * | ---- | -- |
291
+ * | Equality | 1 |
292
+ * | Regex | 2 |
293
+ * | Type | 3 |
294
+ * | MinType | 4 |
295
+ * | MaxType | 5 |
296
+ * | MinMaxType | 6 |
297
+ * | Timestamp | 7 |
298
+ * | Time | 8 |
299
+ * | Date | 9 |
300
+ * | Include | 10 |
301
+ * | Number | 11 |
302
+ * | Integer | 12 |
303
+ * | Decimal | 13 |
304
+ * | Null | 14 |
305
+ * | ContentType | 15 |
306
+ * | ArrayContains | 16 |
307
+ * | Values | 17 |
308
+ * | Boolean | 18 |
309
+ * | StatusCode | 19 |
310
+ * | NotEmpty | 20 |
311
+ * | Semver | 21 |
312
+ * | EachKey | 22 |
313
+ * | EachValue | 23 |
314
+ */
315
+ typedef enum MatchingRuleResult_Tag {
316
+ /**
317
+ * The matching rule from the expression.
318
+ */
319
+ MatchingRuleResult_MatchingRule,
320
+ /**
321
+ * A reference to a named item.
322
+ */
323
+ MatchingRuleResult_MatchingReference,
324
+ } MatchingRuleResult_Tag;
325
+
326
+ typedef struct MatchingRuleResult_MatchingRule_Body {
327
+ uint16_t _0;
328
+ const char *_1;
329
+ const struct MatchingRule *_2;
330
+ } MatchingRuleResult_MatchingRule_Body;
331
+
332
+ typedef struct MatchingRuleResult {
333
+ MatchingRuleResult_Tag tag;
334
+ union {
335
+ MatchingRuleResult_MatchingRule_Body matching_rule;
336
+ struct {
337
+ const char *matching_reference;
338
+ };
339
+ };
340
+ } MatchingRuleResult;
341
+
230
342
  /**
231
343
  * Wraps a Pact model struct
232
344
  */
@@ -523,6 +635,21 @@ int pactffi_logger_apply(void);
523
635
  */
524
636
  const char *pactffi_fetch_log_buffer(const char *log_id);
525
637
 
638
+ /**
639
+ * Parses the provided JSON into a Pact model. The returned Pact model must be freed with the
640
+ * `pactffi_pact_model_delete` function when no longer needed.
641
+ *
642
+ * # Error Handling
643
+ *
644
+ * This function will return a NULL pointer if passed a NULL pointer or if an error occurs.
645
+ */
646
+ struct Pact *pactffi_parse_pact_json(const char *json);
647
+
648
+ /**
649
+ * Frees the memory used by the Pact model
650
+ */
651
+ void pactffi_pact_model_delete(struct Pact *pact);
652
+
526
653
  /**
527
654
  * Get a copy of this consumer's name.
528
655
  *
@@ -1764,6 +1891,145 @@ const struct ProviderState *pactffi_sync_http_get_provider_state(const struct Sy
1764
1891
  */
1765
1892
  struct ProviderStateIterator *pactffi_sync_http_get_provider_state_iter(struct SynchronousHttp *interaction);
1766
1893
 
1894
+ /**
1895
+ * Parse a matcher definition string into a MatchingRuleDefinition containing the example value,
1896
+ * and matching rules and any generator.
1897
+ *
1898
+ * The following are examples of matching rule definitions:
1899
+ * * `matching(type,'Name')` - type matcher with string value 'Name'
1900
+ * * `matching(number,100)` - number matcher
1901
+ * * `matching(datetime, 'yyyy-MM-dd','2000-01-01')` - datetime matcher with format string
1902
+ *
1903
+ * See [Matching Rule definition expressions](https://docs.rs/pact_models/latest/pact_models/matchingrules/expressions/index.html).
1904
+ *
1905
+ * The returned value needs to be freed up with the `pactffi_matcher_definition_delete` function.
1906
+ *
1907
+ * # Errors
1908
+ * If the expression is invalid, the MatchingRuleDefinition error will be set. You can check for
1909
+ * this value with the `pactffi_matcher_definition_error` function.
1910
+ *
1911
+ * # Safety
1912
+ *
1913
+ * This function is safe if the expression is a valid NULL terminated string pointer.
1914
+ */
1915
+ const struct MatchingRuleDefinitionResult *pactffi_parse_matcher_definition(const char *expression);
1916
+
1917
+ /**
1918
+ * Returns any error message from parsing a matching definition expression. If there is no error,
1919
+ * it will return a NULL pointer, otherwise returns the error message as a NULL-terminated string.
1920
+ * The returned string must be freed using the `pactffi_string_delete` function once done with it.
1921
+ */
1922
+ const char *pactffi_matcher_definition_error(const struct MatchingRuleDefinitionResult *definition);
1923
+
1924
+ /**
1925
+ * Returns the value from parsing a matching definition expression. If there was an error,
1926
+ * it will return a NULL pointer, otherwise returns the value as a NULL-terminated string.
1927
+ * The returned string must be freed using the `pactffi_string_delete` function once done with it.
1928
+ *
1929
+ * Note that different expressions values can have types other than a string. Use
1930
+ * `pactffi_matcher_definition_value_type` to get the actual type of the value. This function
1931
+ * will always return the string representation of the value.
1932
+ */
1933
+ const char *pactffi_matcher_definition_value(const struct MatchingRuleDefinitionResult *definition);
1934
+
1935
+ /**
1936
+ * Frees the memory used by the result of parsing the matching definition expression
1937
+ */
1938
+ void pactffi_matcher_definition_delete(const struct MatchingRuleDefinitionResult *definition);
1939
+
1940
+ /**
1941
+ * Returns the generator from parsing a matching definition expression. If there was an error or
1942
+ * there is no associated generator, it will return a NULL pointer, otherwise returns the generator
1943
+ * as a pointer.
1944
+ *
1945
+ * The generator pointer will be a valid pointer as long as `pactffi_matcher_definition_delete`
1946
+ * has not been called on the definition. Using the generator pointer after the definition
1947
+ * has been deleted will result in undefined behaviour.
1948
+ */
1949
+ const struct Generator *pactffi_matcher_definition_generator(const struct MatchingRuleDefinitionResult *definition);
1950
+
1951
+ /**
1952
+ * Returns the type of the value from parsing a matching definition expression. If there was an
1953
+ * error parsing the expression, it will return Unknown.
1954
+ */
1955
+ enum ExpressionValueType pactffi_matcher_definition_value_type(const struct MatchingRuleDefinitionResult *definition);
1956
+
1957
+ /**
1958
+ * Free the iterator when you're done using it.
1959
+ */
1960
+ void pactffi_matching_rule_iter_delete(struct MatchingRuleIterator *iter);
1961
+
1962
+ /**
1963
+ * Returns an iterator over the matching rules from the parsed definition. The iterator needs to
1964
+ * be deleted with the `pactffi_matching_rule_iter_delete` function once done with it.
1965
+ *
1966
+ * If there was an error parsing the expression, this function will return a NULL pointer.
1967
+ */
1968
+ struct MatchingRuleIterator *pactffi_matcher_definition_iter(const struct MatchingRuleDefinitionResult *definition);
1969
+
1970
+ /**
1971
+ * Get the next matching rule or reference from the iterator. As the values returned are owned
1972
+ * by the iterator, they do not need to be deleted but will be cleaned up when the iterator is
1973
+ * deleted.
1974
+ *
1975
+ * Will return a NULL pointer when the iterator has advanced past the end of the list.
1976
+ *
1977
+ * # Safety
1978
+ *
1979
+ * This function is safe.
1980
+ *
1981
+ * # Error Handling
1982
+ *
1983
+ * This function will return a NULL pointer if passed a NULL pointer or if an error occurs.
1984
+ */
1985
+ const struct MatchingRuleResult *pactffi_matching_rule_iter_next(struct MatchingRuleIterator *iter);
1986
+
1987
+ /**
1988
+ * Get the JSON form of the matching rule.
1989
+ *
1990
+ * The returned string must be deleted with `pactffi_string_delete`.
1991
+ *
1992
+ * # Safety
1993
+ *
1994
+ * This function will fail if it is passed a NULL pointer, or the iterator that owns the
1995
+ * value of the matching rule has been deleted.
1996
+ */
1997
+ const char *pactffi_matching_rule_to_json(const struct MatchingRule *rule);
1998
+
1999
+ /**
2000
+ * Get the JSON form of the generator.
2001
+ *
2002
+ * The returned string must be deleted with `pactffi_string_delete`.
2003
+ *
2004
+ * # Safety
2005
+ *
2006
+ * This function will fail if it is passed a NULL pointer, or the owner of the generator has
2007
+ * been deleted.
2008
+ */
2009
+ const char *pactffi_generator_to_json(const struct Generator *generator);
2010
+
2011
+ /**
2012
+ * Generate a string value using the provided generator and an optional JSON payload containing
2013
+ * any generator context. The context value is used for generators like `MockServerURL` (which
2014
+ * should contain details about the running mock server) and `ProviderStateGenerator` (which
2015
+ * should be the values returned from the Provider State callback function).
2016
+ *
2017
+ * If anything goes wrong, it will return a NULL pointer.
2018
+ */
2019
+ const char *pactffi_generator_generate_string(const struct Generator *generator,
2020
+ const char *context_json);
2021
+
2022
+ /**
2023
+ * Generate an integer value using the provided generator and an optional JSON payload containing
2024
+ * any generator context. The context value is used for generators like `ProviderStateGenerator`
2025
+ * (which should be the values returned from the Provider State callback function).
2026
+ *
2027
+ * If anything goes wrong or the generator is not a type that can generate an integer value, it
2028
+ * will return a zero value.
2029
+ */
2030
+ unsigned short pactffi_generator_generate_integer(const struct Generator *generator,
2031
+ const char *context_json);
2032
+
1767
2033
  /**
1768
2034
  * Delete a string previously returned by this FFI.
1769
2035
  *
package/ffi/pact_ffi.dll CHANGED
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pact-foundation/pact-core",
3
- "version": "13.12.0",
3
+ "version": "13.12.2",
4
4
  "description": "Core of @pact-foundation/pact. You almost certainly don't want to depend on this directly.",
5
5
  "main": "src/index.js",
6
6
  "homepage": "https://github.com/pact-foundation/pact-js-core#readme",
@@ -53,7 +53,6 @@
53
53
  },
54
54
  "dependencies": {
55
55
  "@types/needle": "2.5.2",
56
- "@types/pino": "6.3.11",
57
56
  "bindings": "^1.5.0",
58
57
  "chalk": "4.1.2",
59
58
  "check-types": "7.3.0",
@@ -61,8 +60,8 @@
61
60
  "mkdirp": "1.0.0",
62
61
  "needle": "2.8.0",
63
62
  "node-addon-api": "^4.2.0",
64
- "pino": "6.13.1",
65
- "pino-pretty": "^6.0.0",
63
+ "pino": "^8.7.0",
64
+ "pino-pretty": "^9.1.1",
66
65
  "promise-timeout": "1.3.0",
67
66
  "rimraf": "2.6.2",
68
67
  "underscore": "1.12.1",
@@ -1,7 +1,7 @@
1
1
  import { LogLevel } from '../logger/types';
2
2
  import { Ffi } from './types';
3
3
  declare const ffiLib: Ffi;
4
- export declare const PACT_FFI_VERSION = "0.3.14";
4
+ export declare const PACT_FFI_VERSION = "0.3.15";
5
5
  declare let ffi: typeof ffiLib;
6
6
  export declare const getFfiLib: (logLevel?: LogLevel) => typeof ffi;
7
7
  export {};
package/src/ffi/index.js CHANGED
@@ -23,7 +23,7 @@ exports.getFfiLib = exports.PACT_FFI_VERSION = void 0;
23
23
  const logger_1 = __importStar(require("../logger"));
24
24
  const bindings = require("bindings");
25
25
  const ffiLib = bindings('pact.node');
26
- exports.PACT_FFI_VERSION = '0.3.14';
26
+ exports.PACT_FFI_VERSION = '0.3.15';
27
27
  let ffi;
28
28
  let ffiLogLevel;
29
29
  const initialiseFfi = (logLevel) => {
@@ -1,3 +1,3 @@
1
- import pino = require('pino');
1
+ import { pino } from 'pino';
2
2
  import { LogLevel } from './types';
3
3
  export declare const createLogger: (level: LogLevel) => pino.Logger;
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createLogger = void 0;
4
- const pino = require("pino");
5
- const createLogger = (level) => pino({
4
+ const pino_1 = require("pino");
5
+ const createLogger = (level) => pino_1.pino({
6
6
  level: level.toLowerCase(),
7
- prettyPrint: {
8
- translateTime: true,
7
+ transport: {
8
+ target: 'pino-pretty',
9
9
  },
10
10
  });
11
11
  exports.createLogger = createLogger;
@@ -1 +1 @@
1
- {"version":3,"file":"pino.js","sourceRoot":"","sources":["pino.ts"],"names":[],"mappings":";;;AAAA,6BAA8B;AAGvB,MAAM,YAAY,GAAG,CAAC,KAAe,EAAe,EAAE,CAC3D,IAAI,CAAC;IACH,KAAK,EAAE,KAAK,CAAC,WAAW,EAAE;IAC1B,WAAW,EAAE;QACX,aAAa,EAAE,IAAI;KACpB;CACF,CAAC,CAAC;AANQ,QAAA,YAAY,gBAMpB"}
1
+ {"version":3,"file":"pino.js","sourceRoot":"","sources":["pino.ts"],"names":[],"mappings":";;;AAAA,+BAA4B;AAGrB,MAAM,YAAY,GAAG,CAAC,KAAe,EAAe,EAAE,CAC3D,WAAI,CAAC;IACH,KAAK,EAAE,KAAK,CAAC,WAAW,EAAE;IAC1B,SAAS,EAAE;QACT,MAAM,EAAE,aAAa;KACtB;CACF,CAAC,CAAC;AANQ,QAAA,YAAY,gBAMpB"}