yggio 0.0.6 → 0.0.15

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/binding.js CHANGED
@@ -1435,11 +1435,6 @@ Object.defineProperties(Scalar.prototype, {
1435
1435
  return Reflect.apply(nativeScalarRemove, this, [Scalar.from(key)])
1436
1436
  },
1437
1437
  },
1438
- toJSON: {
1439
- value() {
1440
- return JSON.parse(this.intoJson())
1441
- },
1442
- },
1443
1438
  })
1444
1439
 
1445
1440
  // A serie is the native value; the conversions it needs from JavaScript -
@@ -4997,6 +4992,18 @@ for (const Clause of [NativeTerm, NativeFilter, NativeSelector]) {
4997
4992
  })
4998
4993
  }
4999
4994
 
4995
+ // A plan binds its own parameters, in every section and every plan it holds
4996
+ // (`Plan::with_parameters`): no schema, the record alone.
4997
+ {
4998
+ const nativeBind = takePrivate(NativePlan, '_bindNative')
4999
+ Object.defineProperty(NativePlan.prototype, 'bind', {
5000
+ configurable: true,
5001
+ value(parameters) {
5002
+ return nativeBind.call(this, suppliedParameters(parameters))
5003
+ },
5004
+ })
5005
+ }
5006
+
5000
5007
  // One Arrow surface per applier: `applyArrowReader` keeps a native reader
5001
5008
  // lazy, `applyArrowBatch` and `applyArrowTable` keep the Apache Arrow JS
5002
5009
  // holder they were given, and `applyArrow` infers which of the three it has.
@@ -5644,15 +5651,16 @@ for (const name of [
5644
5651
  // dictionary, the message it types and the process default are one name
5645
5652
  // rather than four top-level classes.
5646
5653
  //
5647
- // A message value is whatever `Scalar.from` reads, and that conversion lives
5648
- // in this loader, so the public factories are the one widening gate and hand
5649
- // the native class the value it already understands. A message is built by
5650
- // a factory, never by `new`: the core reads a record or a row into one.
5654
+ // A message value is whatever `Scalar.from` reads, and a line whatever
5655
+ // `toBytes` reads; those conversions live in this loader, so the public
5656
+ // factories are the one widening gate and hand the native class the value it
5657
+ // already understands. A message is built by a factory, never by `new`: the
5658
+ // core reads a line, a record or a row into one.
5651
5659
  const NativeMarketMessage = binding.MarketMessage
5652
5660
  const asScalar = (value) => (value instanceof Scalar ? value : Scalar.from(value))
5653
5661
  function MarketMessage() {
5654
5662
  throw new TypeError(
5655
- 'MarketMessage has no constructor: build one with MarketMessage.fromFixRecord or MarketMessage.fromRow',
5663
+ 'MarketMessage has no constructor: build one with MarketMessage.fromLine, MarketMessage.fromFixRecord or MarketMessage.fromRow',
5656
5664
  )
5657
5665
  }
5658
5666
  MarketMessage.prototype = NativeMarketMessage.prototype
@@ -5663,11 +5671,29 @@ Object.defineProperty(MarketMessage.prototype, 'constructor', {
5663
5671
  })
5664
5672
  // A record, a row read back and a value written cross the one gate: whatever
5665
5673
  // `Scalar.from` reads, and the core alone types it.
5666
- MarketMessage.fromFixRecord = function fromFixRecord(field, value, registry) {
5667
- return NativeMarketMessage.fromFixRecord(field, asScalar(value), registry)
5674
+ MarketMessage.fromFixRecord = function fromFixRecord(field, value, options) {
5675
+ return NativeMarketMessage.fromFixRecord(field, asScalar(value), options)
5676
+ }
5677
+ MarketMessage.fromRow = function fromRow(schema, row, options) {
5678
+ return NativeMarketMessage.fromRow(schema, asScalar(row), options)
5679
+ }
5680
+ for (const name of ['fromLine', 'fromFixMessage', 'fromUllinkLine', 'fromFixmlMessage']) {
5681
+ const native = NativeMarketMessage[name]
5682
+ MarketMessage[name] = {
5683
+ [name](body, options) {
5684
+ return native.call(NativeMarketMessage, toBytes(body), options)
5685
+ },
5686
+ }[name]
5668
5687
  }
5669
- MarketMessage.fromRow = function fromRow(schema, row, registry) {
5670
- return NativeMarketMessage.fromRow(schema, asScalar(row), registry)
5688
+ // A native factory builds through the class it is called on, so each is
5689
+ // called on the native class, never on this constructor that refuses `new`.
5690
+ for (const name of ['fromTextLine', 'fromPairs']) {
5691
+ const native = NativeMarketMessage[name]
5692
+ MarketMessage[name] = {
5693
+ [name](value, options) {
5694
+ return native.call(NativeMarketMessage, value, options)
5695
+ },
5696
+ }[name]
5671
5697
  }
5672
5698
  MarketMessage.field = NativeMarketMessage.field
5673
5699
  const nativeMarketMessageSet = NativeMarketMessage.prototype.set
@@ -5676,30 +5702,42 @@ NativeMarketMessage.prototype.set = function set(key, value) {
5676
5702
  }
5677
5703
 
5678
5704
  // A line crosses as the `TextLine` a text read answered - there is nothing to
5679
- // widen, because a line is a decoded row and not a value - and a batch source
5680
- // as whatever `BatchReader.from` accepts: a reader, an Arrow JS table or
5681
- // batch, IPC bytes. That widening lives here, beside the conversions it uses.
5682
- for (const name of ['parseTextArrowReader', 'lifecycleArrowReader', 'messages']) {
5683
- const native = binding.FixCodec.prototype[name]
5684
- binding.FixCodec.prototype[name] = {
5685
- [name](source) {
5686
- return native.call(this, BatchReader.from(source))
5687
- },
5688
- }[name]
5689
- }
5690
- const nativeWriteArrowReader = binding.FixCodec.prototype.writeArrowReader
5691
- binding.FixCodec.prototype.writeArrowReader = function writeArrowReader(source, sink) {
5692
- return nativeWriteArrowReader.call(this, BatchReader.from(source), sink)
5705
+ // widen, because a line is a decoded row and not a value - a batch source as
5706
+ // whatever `BatchReader.from` accepts: a reader, an Arrow JS table or batch,
5707
+ // IPC bytes - and a root as any `FieldLike`. That widening lives here, beside
5708
+ // the conversions it uses.
5709
+ const NativeMarketMessages = binding.MarketMessages
5710
+ const fieldOrAbsent = (field) => (field === undefined || field === null ? field : intoField(field))
5711
+ {
5712
+ const nativeFromArrowReader = NativeMarketMessages.prototype.fromArrowReader
5713
+ NativeMarketMessages.prototype.fromArrowReader = function fromArrowReader(source, field) {
5714
+ return nativeFromArrowReader.call(this, BatchReader.from(source), fieldOrAbsent(field))
5715
+ }
5716
+ const nativeFromTextArrowReader = NativeMarketMessages.prototype.fromTextArrowReader
5717
+ NativeMarketMessages.prototype.fromTextArrowReader = function fromTextArrowReader(source) {
5718
+ return nativeFromTextArrowReader.call(this, BatchReader.from(source))
5719
+ }
5720
+ for (const name of ['intoArrowReader', 'intoSerie']) {
5721
+ const native = NativeMarketMessages.prototype[name]
5722
+ NativeMarketMessages.prototype[name] = {
5723
+ [name](field) {
5724
+ return native.call(this, fieldOrAbsent(field))
5725
+ },
5726
+ }[name]
5727
+ }
5728
+ const nativeMessageSearch = binding.Underlyings.prototype.messageSearch
5729
+ binding.Underlyings.prototype.messageSearch = function messageSearch(text, field, options) {
5730
+ return nativeMessageSearch.call(this, text, intoField(field), options)
5731
+ }
5693
5732
  }
5694
5733
 
5695
- // A stage over an iterable pulls one item at a time: the iterable's own
5696
- // protocol runs here, and the native stage asks for the next item only when
5697
- // the stream is read that far, so nothing is collected on the way across.
5698
- // `read` turns one item into the value the native stage takes. What the
5699
- // iterable or the reading throws ends the pull; with a `failed` holder the
5700
- // error is kept there, as itself, for the stream to throw in place of its
5701
- // end - a native stage sees values, never exceptions - and without one it
5702
- // travels through the native stage as that stage's own failure.
5734
+ // A source over an iterable pulls one item at a time: the iterable's own
5735
+ // protocol runs here, and the native stream asks for the next item only when
5736
+ // it is read that far, so nothing is collected on the way across. `read`
5737
+ // turns one item into the value the native source takes. What the iterable
5738
+ // or the reading throws ends the pull: it travels through the native stream
5739
+ // as the item after the last one - what a stage or a sink downstream reports
5740
+ // - and is kept in `failed`, as itself, for `next` to throw in its place.
5703
5741
  const FAILED = Symbol('yggio.fix.failed')
5704
5742
  function pullOf(iterable, read, what, failed) {
5705
5743
  if (iterable == null || typeof iterable[Symbol.iterator] !== 'function') {
@@ -5707,14 +5745,13 @@ function pullOf(iterable, read, what, failed) {
5707
5745
  }
5708
5746
  const iterator = iterable[Symbol.iterator]()
5709
5747
  return () => {
5710
- if (failed !== undefined && failed.error !== undefined) return null
5748
+ if (failed.error !== undefined) return null
5711
5749
  try {
5712
5750
  const step = iterator.next()
5713
5751
  return step.done ? null : read(step.value)
5714
5752
  } catch (error) {
5715
- if (failed === undefined) throw error
5716
5753
  failed.error = error
5717
- return null
5754
+ throw error
5718
5755
  }
5719
5756
  }
5720
5757
  }
@@ -5731,15 +5768,15 @@ function asLine(value) {
5731
5768
  return value
5732
5769
  }
5733
5770
  {
5734
- const streams = [
5735
- [binding.FixCodec, 'parseLines', '_parseLinesNative', toBytes, 'lines'],
5736
- [binding.FixCodec, 'parseTextLines', '_parseTextLinesNative', asLine, 'lines'],
5737
- [binding.FixCodec, 'lifecycle', '_lifecycleNative', asMessage, 'messages'],
5771
+ const sources = [
5772
+ ['fromLines', '_fromLinesNative', toBytes, 'lines'],
5773
+ ['fromTextLines', '_fromTextLinesNative', asLine, 'lines'],
5774
+ ['fromItems', '_fromItemsNative', asMessage, 'messages'],
5738
5775
  ]
5739
- for (const [owner, name, hidden, read, what] of streams) {
5740
- const native = owner.prototype[hidden]
5741
- delete owner.prototype[hidden]
5742
- owner.prototype[name] = {
5776
+ for (const [name, hidden, read, what] of sources) {
5777
+ const native = NativeMarketMessages.prototype[hidden]
5778
+ delete NativeMarketMessages.prototype[hidden]
5779
+ NativeMarketMessages.prototype[name] = {
5743
5780
  [name](iterable) {
5744
5781
  const failed = {}
5745
5782
  const stream = native.call(this, pullOf(iterable, read, what, failed))
@@ -5748,38 +5785,44 @@ function asLine(value) {
5748
5785
  },
5749
5786
  }[name]
5750
5787
  }
5751
- // The batch reader pulls the messages as `pyarrow` would, so a failure
5752
- // behind it is that reader's error, raised by the batch it would have
5753
- // landed in.
5754
- const nativeArrowReader = binding.FixCodec.prototype._arrowReaderNative
5755
- delete binding.FixCodec.prototype._arrowReaderNative
5756
- binding.FixCodec.prototype.arrowReader = function arrowReader(schema, messages) {
5757
- return nativeArrowReader.call(this, intoField(schema), pullOf(messages, asMessage, 'messages'))
5758
- }
5759
- // A format answers rows rather than a stream, so the pull is drained here
5760
- // and the failure a bad item raises is that call's own.
5761
- const nativeFormat = binding.FixCodec.prototype._formatMessagesNative
5762
- delete binding.FixCodec.prototype._formatMessagesNative
5763
- binding.FixCodec.prototype.formatMessages = function formatMessages(messages, field) {
5764
- return nativeFormat.call(this, intoField(field), pullOf(messages, asMessage, 'messages'))
5788
+ // A stage reads the stream it takes, so the failure kept for that stream
5789
+ // is the one its own stream throws.
5790
+ for (const name of ['intoLifecycle', 'intoLineage']) {
5791
+ const native = NativeMarketMessages.prototype[name]
5792
+ NativeMarketMessages.prototype[name] = {
5793
+ [name]() {
5794
+ const stream = native.call(this)
5795
+ stream[FAILED] = this[FAILED]
5796
+ return stream
5797
+ },
5798
+ }[name]
5765
5799
  }
5766
5800
  }
5767
5801
 
5768
- const nativeFixMessagesNext = binding.FixMessages.prototype.next
5769
- binding.FixMessages.prototype.next = function next() {
5770
- const value = nativeFixMessagesNext.call(this)
5771
- if (value !== null) return { value, done: false }
5772
- // A stream over an iterable ends where the iterable failed: the failure
5773
- // kept for it is thrown once, as itself, in place of the end.
5774
- const failed = this[FAILED]
5775
- if (failed !== undefined && failed.error !== undefined) {
5776
- const { error } = failed
5777
- failed.error = undefined
5778
- throw error
5802
+ // A stream over an iterable ends where the iterable failed: the native stream
5803
+ // throws a copy of the failure in place of its end, and the failure kept for
5804
+ // it is thrown instead, once, as itself.
5805
+ function keptFailure(stream) {
5806
+ const failed = stream[FAILED]
5807
+ if (failed === undefined || failed.error === undefined) return undefined
5808
+ const { error } = failed
5809
+ failed.error = undefined
5810
+ return error
5811
+ }
5812
+ const nativeMarketMessagesNext = NativeMarketMessages.prototype.next
5813
+ NativeMarketMessages.prototype.next = function next() {
5814
+ let value
5815
+ try {
5816
+ value = nativeMarketMessagesNext.call(this)
5817
+ } catch (error) {
5818
+ throw keptFailure(this) ?? error
5779
5819
  }
5820
+ if (value !== null) return { value, done: false }
5821
+ const failed = keptFailure(this)
5822
+ if (failed !== undefined) throw failed
5780
5823
  return { value: undefined, done: true }
5781
5824
  }
5782
- Object.defineProperty(binding.FixMessages.prototype, Symbol.iterator, {
5825
+ Object.defineProperty(NativeMarketMessages.prototype, Symbol.iterator, {
5783
5826
  configurable: true,
5784
5827
  value: function messages() { return this },
5785
5828
  })
@@ -5815,16 +5858,20 @@ const fix = Object.freeze({
5815
5858
  ULBRIDGE_ROWHEADER: ulbridgeRowheader,
5816
5859
  FixRegistry: binding.FixRegistry,
5817
5860
  MarketMessage,
5818
- FixCodec: binding.FixCodec,
5861
+ MarketMessagesOptions: binding.MarketMessagesOptions,
5862
+ MarketMessages: NativeMarketMessages,
5819
5863
  MsgType: binding.MsgType,
5820
- FixMessages: binding.FixMessages,
5864
+ Underlyings: binding.Underlyings,
5821
5865
  crateFields: binding.fixCrateFields,
5822
5866
  underlyingField: binding.fixUnderlyingField,
5867
+ registryField: binding.fixRegistryField,
5823
5868
  micEntryField: binding.fixMicEntryField,
5824
5869
  legalEntityField: binding.fixLegalEntityField,
5825
5870
  fxRateField: binding.fixFxRateField,
5826
5871
  pluginField: binding.fixPluginField,
5827
5872
  pluginSide: binding.fixPluginSide,
5873
+ reports: binding.fixReports,
5874
+ rules: binding.fixRules,
5828
5875
  })
5829
5876
 
5830
5877
  // The FIX values are reached through the namespace and nowhere else, so a
@@ -5832,23 +5879,28 @@ const fix = Object.freeze({
5832
5879
  for (const name of [
5833
5880
  'FixFieldIterator',
5834
5881
  'MarketMessage',
5835
- 'FixCodec',
5882
+ 'MarketMessagesOptions',
5883
+ 'MarketMessages',
5836
5884
  'FixRegistry',
5837
5885
  'MsgType',
5838
- 'FixMessages',
5886
+ 'Underlyings',
5839
5887
  'JsFixFieldIterator',
5840
5888
  'JsMarketMessage',
5841
- 'JsFixCodec',
5889
+ 'JsMarketMessagesOptions',
5890
+ 'JsMarketMessages',
5842
5891
  'JsFixRegistry',
5843
5892
  'JsMsgType',
5844
- 'JsFixMessages',
5893
+ 'JsUnderlyings',
5845
5894
  'fixCrateFields',
5846
5895
  'fixUnderlyingField',
5896
+ 'fixRegistryField',
5847
5897
  'fixMicEntryField',
5848
5898
  'fixLegalEntityField',
5849
5899
  'fixFxRateField',
5850
5900
  'fixPluginField',
5851
5901
  'fixPluginSide',
5902
+ 'fixReports',
5903
+ 'fixRules',
5852
5904
  ]) {
5853
5905
  delete binding[name]
5854
5906
  }