@gtkx/runtime 1.2.2 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/README.md +6 -4
  2. package/dist/arg.d.ts +6 -1
  3. package/dist/arg.d.ts.map +1 -1
  4. package/dist/arg.js +2 -1
  5. package/dist/arg.js.map +1 -1
  6. package/dist/closure.d.ts.map +1 -1
  7. package/dist/closure.js +2 -11
  8. package/dist/closure.js.map +1 -1
  9. package/dist/descriptors.d.ts +21 -3
  10. package/dist/descriptors.d.ts.map +1 -1
  11. package/dist/descriptors.js +50 -21
  12. package/dist/descriptors.js.map +1 -1
  13. package/dist/field.d.ts +42 -0
  14. package/dist/field.d.ts.map +1 -0
  15. package/dist/field.js +41 -0
  16. package/dist/field.js.map +1 -0
  17. package/dist/fn.d.ts +2 -0
  18. package/dist/fn.d.ts.map +1 -1
  19. package/dist/fn.js +50 -10
  20. package/dist/fn.js.map +1 -1
  21. package/dist/index.d.ts +14 -6
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +13 -5
  24. package/dist/index.js.map +1 -1
  25. package/dist/mixin.d.ts +2 -1
  26. package/dist/mixin.d.ts.map +1 -1
  27. package/dist/mixin.js +1 -1
  28. package/dist/mixin.js.map +1 -1
  29. package/dist/native-value.d.ts +9 -3
  30. package/dist/native-value.d.ts.map +1 -1
  31. package/dist/native-value.js +86 -9
  32. package/dist/native-value.js.map +1 -1
  33. package/dist/object.d.ts +14 -6
  34. package/dist/object.d.ts.map +1 -1
  35. package/dist/object.js +21 -10
  36. package/dist/object.js.map +1 -1
  37. package/dist/param-spec.d.ts +32 -1
  38. package/dist/param-spec.d.ts.map +1 -1
  39. package/dist/param-spec.js +67 -5
  40. package/dist/param-spec.js.map +1 -1
  41. package/dist/promisify.d.ts +13 -1
  42. package/dist/promisify.d.ts.map +1 -1
  43. package/dist/promisify.js +14 -1
  44. package/dist/promisify.js.map +1 -1
  45. package/dist/properties.d.ts +48 -5
  46. package/dist/properties.d.ts.map +1 -1
  47. package/dist/properties.js +191 -20
  48. package/dist/properties.js.map +1 -1
  49. package/dist/regex.d.ts +25 -0
  50. package/dist/regex.d.ts.map +1 -0
  51. package/dist/regex.js +59 -0
  52. package/dist/regex.js.map +1 -0
  53. package/dist/register-class.d.ts +165 -15
  54. package/dist/register-class.d.ts.map +1 -1
  55. package/dist/register-class.js +175 -19
  56. package/dist/register-class.js.map +1 -1
  57. package/dist/registry.d.ts +48 -4
  58. package/dist/registry.d.ts.map +1 -1
  59. package/dist/registry.js +147 -3
  60. package/dist/registry.js.map +1 -1
  61. package/dist/signal.d.ts +11 -1
  62. package/dist/signal.d.ts.map +1 -1
  63. package/dist/signal.js +66 -6
  64. package/dist/signal.js.map +1 -1
  65. package/dist/t.d.ts +11 -0
  66. package/dist/t.d.ts.map +1 -1
  67. package/dist/t.js +3 -0
  68. package/dist/t.js.map +1 -1
  69. package/dist/type.d.ts +2 -1
  70. package/dist/type.d.ts.map +1 -1
  71. package/dist/type.js +5 -1
  72. package/dist/type.js.map +1 -1
  73. package/dist/value.d.ts +48 -4
  74. package/dist/value.d.ts.map +1 -1
  75. package/dist/value.js +172 -16
  76. package/dist/value.js.map +1 -1
  77. package/dist/variant.d.ts +75 -26
  78. package/dist/variant.d.ts.map +1 -1
  79. package/dist/variant.js +44 -29
  80. package/dist/variant.js.map +1 -1
  81. package/package.json +5 -5
  82. package/src/arg.ts +6 -1
  83. package/src/closure.ts +2 -14
  84. package/src/descriptors.ts +74 -21
  85. package/src/field.ts +76 -0
  86. package/src/fn.ts +73 -17
  87. package/src/index.ts +46 -5
  88. package/src/mixin.ts +1 -1
  89. package/src/native-value.ts +146 -14
  90. package/src/object.ts +23 -11
  91. package/src/param-spec.ts +96 -8
  92. package/src/promisify.ts +27 -1
  93. package/src/properties.ts +280 -32
  94. package/src/regex.ts +92 -0
  95. package/src/register-class.ts +485 -42
  96. package/src/registry.ts +219 -4
  97. package/src/signal.ts +117 -4
  98. package/src/t.ts +13 -0
  99. package/src/type.ts +7 -0
  100. package/src/value.ts +268 -14
  101. package/src/variant.ts +184 -53
package/dist/t.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { bind } from "./bind.js";
2
2
  import * as helpers from "./descriptors.js";
3
+ import { field, fieldAt } from "./field.js";
3
4
  import { fn } from "./fn.js";
4
5
  /**
5
6
  * Type descriptor builder: a collection of factory helpers that describe C types for
@@ -45,6 +46,8 @@ const t = {
45
46
  cursorArray: helpers.cursorArrayT,
46
47
  callback: helpers.callbackT,
47
48
  fn,
49
+ field,
50
+ fieldAt,
48
51
  };
49
52
  export { t };
50
53
  //# sourceMappingURL=t.js.map
package/dist/t.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"t.js","sourceRoot":"","sources":["../src/t.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAwF7B;;;;GAIG;AACH,MAAM,CAAC,GAAM;IACT,IAAI;IACJ,IAAI,EAAE,OAAO,CAAC,KAAK;IACnB,KAAK,EAAE,OAAO,CAAC,MAAM;IACrB,KAAK,EAAE,OAAO,CAAC,MAAM;IACrB,MAAM,EAAE,OAAO,CAAC,OAAO;IACvB,KAAK,EAAE,OAAO,CAAC,MAAM;IACrB,MAAM,EAAE,OAAO,CAAC,OAAO;IACvB,KAAK,EAAE,OAAO,CAAC,MAAM;IACrB,MAAM,EAAE,OAAO,CAAC,OAAO;IACvB,QAAQ,EAAE,OAAO,CAAC,SAAS;IAC3B,SAAS,EAAE,OAAO,CAAC,UAAU;IAC7B,KAAK,EAAE,OAAO,CAAC,MAAM;IACrB,OAAO,EAAE,OAAO,CAAC,QAAQ;IACzB,OAAO,EAAE,OAAO,CAAC,QAAQ;IACzB,OAAO,EAAE,OAAO,CAAC,QAAQ;IACzB,IAAI,EAAE,OAAO,CAAC,KAAK;IACnB,OAAO,EAAE,OAAO,CAAC,QAAQ;IACzB,MAAM,EAAE,OAAO,CAAC,OAAO;IACvB,MAAM,EAAE,OAAO,CAAC,OAAO;IACvB,MAAM,EAAE,OAAO,CAAC,OAAO;IACvB,KAAK,EAAE,OAAO,CAAC,MAAM;IACrB,MAAM,EAAE,OAAO,CAAC,OAAO;IACvB,WAAW,EAAE,OAAO,CAAC,YAAY;IACjC,GAAG,EAAE,OAAO,CAAC,IAAI;IACjB,SAAS,EAAE,OAAO,CAAC,UAAU;IAC7B,IAAI,EAAE,OAAO,CAAC,KAAK;IACnB,KAAK,EAAE,OAAO,CAAC,MAAM;IACrB,KAAK,EAAE,OAAO,CAAC,MAAM;IACrB,IAAI,EAAE,OAAO,CAAC,KAAK;IACnB,KAAK,EAAE,OAAO,CAAC,MAAM;IACrB,QAAQ,EAAE,OAAO,CAAC,SAAS;IAC3B,MAAM,EAAE,OAAO,CAAC,OAAO;IACvB,SAAS,EAAE,OAAO,CAAC,UAAU;IAC7B,UAAU,EAAE,OAAO,CAAC,WAAW;IAC/B,UAAU,EAAE,OAAO,CAAC,WAAW;IAC/B,WAAW,EAAE,OAAO,CAAC,YAAY;IACjC,QAAQ,EAAE,OAAO,CAAC,SAAS;IAC3B,EAAE;CACL,CAAC;AAEF,OAAO,EAAE,CAAC,EAAE,CAAC","sourcesContent":["import { bind } from \"./bind.js\";\nimport * as helpers from \"./descriptors.js\";\nimport { fn } from \"./fn.js\";\n\n/** The descriptor factories and function binders exposed as {@link t}. */\ntype T = {\n /** Binds a symbol in a shared library to a callable that marshals its arguments and return value. */\n bind: typeof bind;\n /** Descriptor for a `gint8`, marshalled as a number. */\n int8: typeof helpers.int8T;\n /** Descriptor for a `guint8`, marshalled as a number. */\n uint8: typeof helpers.uint8T;\n /** Descriptor for a `gint16`, marshalled as a number. */\n int16: typeof helpers.int16T;\n /** Descriptor for a `guint16`, marshalled as a number. */\n uint16: typeof helpers.uint16T;\n /** Descriptor for a `gint32`, marshalled as a number. */\n int32: typeof helpers.int32T;\n /** Descriptor for a `guint32`, marshalled as a number. */\n uint32: typeof helpers.uint32T;\n /** Descriptor for a `gint64`, marshalled as a number and rejected outside the 2^53 safe range. */\n int64: typeof helpers.int64T;\n /** Descriptor for a `guint64`, marshalled as a number and rejected outside the 2^53 safe range. */\n uint64: typeof helpers.uint64T;\n /** Descriptor for a `gint64`, marshalled as a bigint so the full 64-bit range survives. */\n bigint64: typeof helpers.bigint64T;\n /** Descriptor for a `guint64`, marshalled as a bigint so the full 64-bit range survives. */\n biguint64: typeof helpers.biguint64T;\n /** Descriptor for a `GType`, marshalled as a bigint and recognized as a GType by GValue conversion. */\n gtype: typeof helpers.gtypeT;\n /** Descriptor for a `gfloat`. */\n float32: typeof helpers.float32T;\n /** Descriptor for a `gdouble`. */\n float64: typeof helpers.float64T;\n /** Descriptor for a `gboolean`, marshalled as a JavaScript boolean. */\n boolean: typeof helpers.booleanT;\n /** Descriptor for the absence of a value, used as the return descriptor of a `void` function. */\n void: typeof helpers.voidT;\n /** Descriptor for a `gunichar`, marshalled as a single-character string or a codepoint number. */\n unichar: typeof helpers.unicharT;\n /** Descriptor for an opaque `gpointer` argument, taken from a typed array's memory or a numeric address. */\n buffer: typeof helpers.bufferT;\n /**\n * Builds a descriptor for a C string, whose optional length sizes the caller-allocated buffer\n * used when the string is passed by reference.\n */\n string: typeof helpers.stringT;\n /** Builds a descriptor for a `GObject`, wrapped in the class registered for its runtime GType. */\n object: typeof helpers.objectT;\n /** Builds a descriptor for a `GBoxed` value of the named type. */\n boxed: typeof helpers.boxedT;\n /** Builds a descriptor for a plain C struct. */\n struct: typeof helpers.structT;\n /** Builds a descriptor for a fundamental type whose lifetime is managed by named ref and unref functions. */\n fundamental: typeof helpers.fundamentalT;\n /** Wraps a descriptor in a pointer to it, for an output or inout argument. */\n ref: typeof helpers.refT;\n /** Builds a descriptor for a `GHashTable`, marshalled as an array of key/value pairs. */\n hashTable: typeof helpers.hashTableT;\n /** Builds a descriptor for an enumeration, resolving its GType from the named `get_type` function. */\n enum: typeof helpers.enumT;\n /** Builds a descriptor for a flags type, resolving its GType from the named `get_type` function. */\n flags: typeof helpers.flagsT;\n /** Builds a descriptor for an array of items in one of the supported container layouts. */\n array: typeof helpers.arrayT;\n /** Builds a descriptor for a `GList` of items. */\n list: typeof helpers.listT;\n /** Builds a descriptor for a `GSList` of items. */\n slist: typeof helpers.slistT;\n /** Builds a descriptor for a `GPtrArray` of items. */\n ptrArray: typeof helpers.ptrArrayT;\n /** Builds a descriptor for a `GArray` of items. */\n gArray: typeof helpers.gArrayT;\n /** Builds a descriptor for a `GByteArray`. */\n byteArray: typeof helpers.byteArrayT;\n /** Builds a descriptor for a C array whose length is carried by another argument. */\n sizedArray: typeof helpers.sizedArrayT;\n /** Builds a descriptor for a C array of a fixed length. */\n fixedArray: typeof helpers.fixedArrayT;\n /** Builds a descriptor for an out pointer into the buffer another argument supplied. */\n cursorArray: typeof helpers.cursorArrayT;\n /** Builds a descriptor for a function pointer, marshalling a JavaScript function into a native closure. */\n callback: typeof helpers.callbackT;\n /**\n * Binds a native function, wiring up argument directions, `GError` checking, and packing output\n * arguments into the result.\n */\n fn: typeof fn;\n};\n\n/**\n * Type descriptor builder: a collection of factory helpers that describe C types for\n * FFI marshalling, plus `bind` to bind a native function and `fn` to describe a\n * function signature.\n */\nconst t: T = {\n bind,\n int8: helpers.int8T,\n uint8: helpers.uint8T,\n int16: helpers.int16T,\n uint16: helpers.uint16T,\n int32: helpers.int32T,\n uint32: helpers.uint32T,\n int64: helpers.int64T,\n uint64: helpers.uint64T,\n bigint64: helpers.bigint64T,\n biguint64: helpers.biguint64T,\n gtype: helpers.gtypeT,\n float32: helpers.float32T,\n float64: helpers.float64T,\n boolean: helpers.booleanT,\n void: helpers.voidT,\n unichar: helpers.unicharT,\n buffer: helpers.bufferT,\n string: helpers.stringT,\n object: helpers.objectT,\n boxed: helpers.boxedT,\n struct: helpers.structT,\n fundamental: helpers.fundamentalT,\n ref: helpers.refT,\n hashTable: helpers.hashTableT,\n enum: helpers.enumT,\n flags: helpers.flagsT,\n array: helpers.arrayT,\n list: helpers.listT,\n slist: helpers.slistT,\n ptrArray: helpers.ptrArrayT,\n gArray: helpers.gArrayT,\n byteArray: helpers.byteArrayT,\n sizedArray: helpers.sizedArrayT,\n fixedArray: helpers.fixedArrayT,\n cursorArray: helpers.cursorArrayT,\n callback: helpers.callbackT,\n fn,\n};\n\nexport { t };\n"]}
1
+ {"version":3,"file":"t.js","sourceRoot":"","sources":["../src/t.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAkG7B;;;;GAIG;AACH,MAAM,CAAC,GAAM;IACT,IAAI;IACJ,IAAI,EAAE,OAAO,CAAC,KAAK;IACnB,KAAK,EAAE,OAAO,CAAC,MAAM;IACrB,KAAK,EAAE,OAAO,CAAC,MAAM;IACrB,MAAM,EAAE,OAAO,CAAC,OAAO;IACvB,KAAK,EAAE,OAAO,CAAC,MAAM;IACrB,MAAM,EAAE,OAAO,CAAC,OAAO;IACvB,KAAK,EAAE,OAAO,CAAC,MAAM;IACrB,MAAM,EAAE,OAAO,CAAC,OAAO;IACvB,QAAQ,EAAE,OAAO,CAAC,SAAS;IAC3B,SAAS,EAAE,OAAO,CAAC,UAAU;IAC7B,KAAK,EAAE,OAAO,CAAC,MAAM;IACrB,OAAO,EAAE,OAAO,CAAC,QAAQ;IACzB,OAAO,EAAE,OAAO,CAAC,QAAQ;IACzB,OAAO,EAAE,OAAO,CAAC,QAAQ;IACzB,IAAI,EAAE,OAAO,CAAC,KAAK;IACnB,OAAO,EAAE,OAAO,CAAC,QAAQ;IACzB,MAAM,EAAE,OAAO,CAAC,OAAO;IACvB,MAAM,EAAE,OAAO,CAAC,OAAO;IACvB,MAAM,EAAE,OAAO,CAAC,OAAO;IACvB,KAAK,EAAE,OAAO,CAAC,MAAM;IACrB,MAAM,EAAE,OAAO,CAAC,OAAO;IACvB,WAAW,EAAE,OAAO,CAAC,YAAY;IACjC,GAAG,EAAE,OAAO,CAAC,IAAI;IACjB,SAAS,EAAE,OAAO,CAAC,UAAU;IAC7B,IAAI,EAAE,OAAO,CAAC,KAAK;IACnB,KAAK,EAAE,OAAO,CAAC,MAAM;IACrB,KAAK,EAAE,OAAO,CAAC,MAAM;IACrB,IAAI,EAAE,OAAO,CAAC,KAAK;IACnB,KAAK,EAAE,OAAO,CAAC,MAAM;IACrB,QAAQ,EAAE,OAAO,CAAC,SAAS;IAC3B,MAAM,EAAE,OAAO,CAAC,OAAO;IACvB,SAAS,EAAE,OAAO,CAAC,UAAU;IAC7B,UAAU,EAAE,OAAO,CAAC,WAAW;IAC/B,UAAU,EAAE,OAAO,CAAC,WAAW;IAC/B,WAAW,EAAE,OAAO,CAAC,YAAY;IACjC,QAAQ,EAAE,OAAO,CAAC,SAAS;IAC3B,EAAE;IACF,KAAK;IACL,OAAO;CACV,CAAC;AAEF,OAAO,EAAE,CAAC,EAAE,CAAC","sourcesContent":["import { bind } from \"./bind.js\";\nimport * as helpers from \"./descriptors.js\";\nimport { field, fieldAt } from \"./field.js\";\nimport { fn } from \"./fn.js\";\n\n/** The descriptor factories and function binders exposed as {@link t}. */\ntype T = {\n /** Binds a symbol in a shared library to a callable that marshals its arguments and return value. */\n bind: typeof bind;\n /** Descriptor for a `gint8`, marshalled as a number. */\n int8: typeof helpers.int8T;\n /** Descriptor for a `guint8`, marshalled as a number. */\n uint8: typeof helpers.uint8T;\n /** Descriptor for a `gint16`, marshalled as a number. */\n int16: typeof helpers.int16T;\n /** Descriptor for a `guint16`, marshalled as a number. */\n uint16: typeof helpers.uint16T;\n /** Descriptor for a `gint32`, marshalled as a number. */\n int32: typeof helpers.int32T;\n /** Descriptor for a `guint32`, marshalled as a number. */\n uint32: typeof helpers.uint32T;\n /** Descriptor for a `gint64`, marshalled as a number and rejected outside the 2^53 safe range. */\n int64: typeof helpers.int64T;\n /** Descriptor for a `guint64`, marshalled as a number and rejected outside the 2^53 safe range. */\n uint64: typeof helpers.uint64T;\n /** Descriptor for a `gint64`, marshalled as a bigint so the full 64-bit range survives. */\n bigint64: typeof helpers.bigint64T;\n /** Descriptor for a `guint64`, marshalled as a bigint so the full 64-bit range survives. */\n biguint64: typeof helpers.biguint64T;\n /** Descriptor for a `GType`, marshalled as a bigint and recognized as a GType by GValue conversion. */\n gtype: typeof helpers.gtypeT;\n /** Descriptor for a `gfloat`. */\n float32: typeof helpers.float32T;\n /** Descriptor for a `gdouble`. */\n float64: typeof helpers.float64T;\n /** Descriptor for a `gboolean`, marshalled as a JavaScript boolean. */\n boolean: typeof helpers.booleanT;\n /** Descriptor for the absence of a value, used as the return descriptor of a `void` function. */\n void: typeof helpers.voidT;\n /** Descriptor for a `gunichar`, marshalled as a single-character string or a codepoint number. */\n unichar: typeof helpers.unicharT;\n /** Descriptor for an opaque `gpointer` argument, taken from a typed array's memory or a numeric address. */\n buffer: typeof helpers.bufferT;\n /**\n * Builds a descriptor for a C string, whose optional length sizes the caller-allocated buffer\n * used when the string is passed by reference.\n */\n string: typeof helpers.stringT;\n /** Builds a descriptor for a `GObject`, wrapped in the class registered for its runtime GType. */\n object: typeof helpers.objectT;\n /** Builds a descriptor for a `GBoxed` value of the named type. */\n boxed: typeof helpers.boxedT;\n /** Builds a descriptor for a plain C struct. */\n struct: typeof helpers.structT;\n /** Builds a descriptor for a fundamental type whose lifetime is managed by named ref and unref functions. */\n fundamental: typeof helpers.fundamentalT;\n /** Wraps a descriptor in a pointer to it, for an output or inout argument. */\n ref: typeof helpers.refT;\n /** Builds a descriptor for a `GHashTable`, marshalled as an array of key/value pairs. */\n hashTable: typeof helpers.hashTableT;\n /** Builds a descriptor for an enumeration, resolving its GType from the named `get_type` function. */\n enum: typeof helpers.enumT;\n /** Builds a descriptor for a flags type, resolving its GType from the named `get_type` function. */\n flags: typeof helpers.flagsT;\n /** Builds a descriptor for an array of items in one of the supported container layouts. */\n array: typeof helpers.arrayT;\n /** Builds a descriptor for a `GList` of items. */\n list: typeof helpers.listT;\n /** Builds a descriptor for a `GSList` of items. */\n slist: typeof helpers.slistT;\n /** Builds a descriptor for a `GPtrArray` of items. */\n ptrArray: typeof helpers.ptrArrayT;\n /** Builds a descriptor for a `GArray` of items. */\n gArray: typeof helpers.gArrayT;\n /** Builds a descriptor for a `GByteArray`. */\n byteArray: typeof helpers.byteArrayT;\n /** Builds a descriptor for a C array whose length is carried by another argument. */\n sizedArray: typeof helpers.sizedArrayT;\n /** Builds a descriptor for a C array of a fixed length. */\n fixedArray: typeof helpers.fixedArrayT;\n /** Builds a descriptor for an out pointer into the buffer another argument supplied. */\n cursorArray: typeof helpers.cursorArrayT;\n /** Builds a descriptor for a function pointer, marshalling a JavaScript function into a native closure. */\n callback: typeof helpers.callbackT;\n /**\n * Binds a native function, wiring up argument directions, `GError` checking, and packing output\n * arguments into the result.\n */\n fn: typeof fn;\n /**\n * Binds a struct field at a fixed offset, compiling its descriptor once into an accessor that\n * reads and writes it.\n */\n field: typeof field;\n /**\n * Binds a struct field whose offset is supplied per access, for walking records stored at a\n * stride in a buffer.\n */\n fieldAt: typeof fieldAt;\n};\n\n/**\n * Type descriptor builder: a collection of factory helpers that describe C types for\n * FFI marshalling, plus `bind` to bind a native function and `fn` to describe a\n * function signature.\n */\nconst t: T = {\n bind,\n int8: helpers.int8T,\n uint8: helpers.uint8T,\n int16: helpers.int16T,\n uint16: helpers.uint16T,\n int32: helpers.int32T,\n uint32: helpers.uint32T,\n int64: helpers.int64T,\n uint64: helpers.uint64T,\n bigint64: helpers.bigint64T,\n biguint64: helpers.biguint64T,\n gtype: helpers.gtypeT,\n float32: helpers.float32T,\n float64: helpers.float64T,\n boolean: helpers.booleanT,\n void: helpers.voidT,\n unichar: helpers.unicharT,\n buffer: helpers.bufferT,\n string: helpers.stringT,\n object: helpers.objectT,\n boxed: helpers.boxedT,\n struct: helpers.structT,\n fundamental: helpers.fundamentalT,\n ref: helpers.refT,\n hashTable: helpers.hashTableT,\n enum: helpers.enumT,\n flags: helpers.flagsT,\n array: helpers.arrayT,\n list: helpers.listT,\n slist: helpers.slistT,\n ptrArray: helpers.ptrArrayT,\n gArray: helpers.gArrayT,\n byteArray: helpers.byteArrayT,\n sizedArray: helpers.sizedArrayT,\n fixedArray: helpers.fixedArrayT,\n cursorArray: helpers.cursorArrayT,\n callback: helpers.callbackT,\n fn,\n field,\n fieldAt,\n};\n\nexport { t };\n"]}
package/dist/type.d.ts CHANGED
@@ -82,7 +82,8 @@ declare function valueIsA(value: unknown, gtype: bigint): boolean;
82
82
  declare const resolveType: (sharedLibrary: string, typeFnName: string) => bigint;
83
83
  declare const resolveBoxedType: (descriptor: BoxedDescriptor) => bigint;
84
84
  declare const resolveFundamentalType: (descriptor: FundamentalDescriptor) => bigint;
85
+ declare const getByteArrayType: () => bigint;
85
86
  declare function isResolvableDescriptor(descriptor: Descriptor): descriptor is ResolvableDescriptor;
86
87
  declare function resolveDescriptorType(descriptor: Descriptor): bigint;
87
- export { TYPE_INVALID, TYPE_NONE, TYPE_INTERFACE, TYPE_CHAR, TYPE_UCHAR, TYPE_BOOLEAN, TYPE_INT, TYPE_UINT, TYPE_LONG, TYPE_ULONG, TYPE_INT64, TYPE_UINT64, TYPE_ENUM, TYPE_FLAGS, TYPE_FLOAT, TYPE_DOUBLE, TYPE_STRING, TYPE_POINTER, TYPE_BOXED, TYPE_PARAM, TYPE_OBJECT, TYPE_GTYPE, TYPE_VARIANT, TYPE_UNICHAR, getErrorType, getStrvType, isResolvableDescriptor, isTypedClass, typeIsA, typeParent, typeInterfaces, typeFromName, typeFundamental, typeName, valueIsA, resolveType, resolveBoxedType, resolveFundamentalType, resolveDescriptorType, type TypedClass, };
88
+ export { TYPE_INVALID, TYPE_NONE, TYPE_INTERFACE, TYPE_CHAR, TYPE_UCHAR, TYPE_BOOLEAN, TYPE_INT, TYPE_UINT, TYPE_LONG, TYPE_ULONG, TYPE_INT64, TYPE_UINT64, TYPE_ENUM, TYPE_FLAGS, TYPE_FLOAT, TYPE_DOUBLE, TYPE_STRING, TYPE_POINTER, TYPE_BOXED, TYPE_PARAM, TYPE_OBJECT, TYPE_GTYPE, TYPE_VARIANT, TYPE_UNICHAR, getByteArrayType, getErrorType, getStrvType, isResolvableDescriptor, isTypedClass, typeIsA, typeParent, typeInterfaces, typeFromName, typeFundamental, typeName, valueIsA, resolveType, resolveBoxedType, resolveFundamentalType, resolveDescriptorType, type TypedClass, };
88
89
  //# sourceMappingURL=type.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../src/type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAoC,MAAM,cAAc,CAAC;AAEjF,OAAO,EAIH,KAAK,eAAe,EACpB,KAAK,qBAAqB,EAK7B,MAAM,kBAAkB,CAAC;AAG1B,yEAAyE;AACzE,KAAK,UAAU,GAAG;IACd,oDAAoD;IACpD,QAAQ,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,KAAK,cAAc,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,aAAa,GAAG,OAAO,CAAC;AAC3E,KAAK,oBAAoB,GAAG,OAAO,CAAC,UAAU,EAAE;IAAE,IAAI,EAAE,cAAc,CAAA;CAAE,CAAC,CAAC;AAS1E,sDAAsD;AACtD,QAAA,MAAM,YAAY,KAAK,CAAC;AACxB,qDAAqD;AACrD,QAAA,MAAM,SAAS,EAAE,MAA6B,CAAC;AAC/C,8CAA8C;AAC9C,QAAA,MAAM,cAAc,EAAE,MAAmC,CAAC;AAC1D,oDAAoD;AACpD,QAAA,MAAM,SAAS,EAAE,MAA8B,CAAC;AAChD,uDAAuD;AACvD,QAAA,MAAM,UAA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EACtB,YAAY,EACZ,OAAO,EACP,UAAU,EACV,cAAc,EACd,YAAY,EACZ,eAAe,EACf,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,gBAAgB,EAChB,sBAAsB,EACtB,qBAAqB,EACrB,KAAK,UAAU,GAClB,CAAC"}
package/dist/type.js CHANGED
@@ -156,10 +156,14 @@ const resolveFundamentalType = (descriptor) => {
156
156
  }
157
157
  throw new Error("Cannot resolve gtype for fundamental type without a typeName");
158
158
  };
159
+ const getByteArrayType = () => resolveType(LIB, "g_byte_array_get_type");
159
160
  function resolveArrayType(descriptor) {
160
161
  if (descriptor.itemDescriptor.kind === "string" && descriptor.arrayKind === "array") {
161
162
  return getStrvType();
162
163
  }
164
+ if (descriptor.arrayKind === "gbytearray") {
165
+ return getByteArrayType();
166
+ }
163
167
  throw new Error(`Unsupported array type ${descriptor.arrayKind} of ${descriptor.itemDescriptor.kind}`);
164
168
  }
165
169
  function isResolvableDescriptor(descriptor) {
@@ -192,5 +196,5 @@ function resolveDescriptorType(descriptor) {
192
196
  }
193
197
  }
194
198
  }
195
- export { TYPE_INVALID, TYPE_NONE, TYPE_INTERFACE, TYPE_CHAR, TYPE_UCHAR, TYPE_BOOLEAN, TYPE_INT, TYPE_UINT, TYPE_LONG, TYPE_ULONG, TYPE_INT64, TYPE_UINT64, TYPE_ENUM, TYPE_FLAGS, TYPE_FLOAT, TYPE_DOUBLE, TYPE_STRING, TYPE_POINTER, TYPE_BOXED, TYPE_PARAM, TYPE_OBJECT, TYPE_GTYPE, TYPE_VARIANT, TYPE_UNICHAR, getErrorType, getStrvType, isResolvableDescriptor, isTypedClass, typeIsA, typeParent, typeInterfaces, typeFromName, typeFundamental, typeName, valueIsA, resolveType, resolveBoxedType, resolveFundamentalType, resolveDescriptorType, };
199
+ export { TYPE_INVALID, TYPE_NONE, TYPE_INTERFACE, TYPE_CHAR, TYPE_UCHAR, TYPE_BOOLEAN, TYPE_INT, TYPE_UINT, TYPE_LONG, TYPE_ULONG, TYPE_INT64, TYPE_UINT64, TYPE_ENUM, TYPE_FLAGS, TYPE_FLOAT, TYPE_DOUBLE, TYPE_STRING, TYPE_POINTER, TYPE_BOXED, TYPE_PARAM, TYPE_OBJECT, TYPE_GTYPE, TYPE_VARIANT, TYPE_UNICHAR, getByteArrayType, getErrorType, getStrvType, isResolvableDescriptor, isTypedClass, typeIsA, typeParent, typeInterfaces, typeFromName, typeFundamental, typeName, valueIsA, resolveType, resolveBoxedType, resolveFundamentalType, resolveDescriptorType, };
196
200
  //# sourceMappingURL=type.js.map
package/dist/type.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"type.js","sourceRoot":"","sources":["../src/type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,WAAW,IAAI,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjF,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAEH,UAAU,EACV,QAAQ,EAGR,IAAI,EACJ,WAAW,EACX,OAAO,EACP,OAAO,GACV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAWnC,MAAM,iBAAiB,GAAwB,IAAI,GAAG,EAAE,CAAC;AACzD,MAAM,aAAa,GAAG,IAAI,CAAC,GAAG,EAAE,kBAAkB,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;AACvF,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,aAAa,EAAE,CAAC,UAAU,EAAE,UAAU,CAAC,EAAE,QAAQ,CAAC,CAAC;AAC9E,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,EAAE,eAAe,EAAE,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC,CAAC;AACzE,MAAM,gBAAgB,GAAG,IAAI,CAAC,GAAG,EAAE,oBAAoB,EAAE,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC,CAAC;AACnF,MAAM,SAAS,GAAG,IAA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gBAAgB,CAAC,UAAU,CAAC,CAAC;QACxC,CAAC;QACD,KAAK,aAAa,CAAC,CAAC,CAAC;YACjB,OAAO,sBAAsB,CAAC,UAAU,CAAC,CAAC;QAC9C,CAAC;QACD,KAAK,OAAO,CAAC,CAAC,CAAC;YACX,OAAO,gBAAgB,CAAC,UAAU,CAAC,CAAC;QACxC,CAAC;IACL,CAAC;AACL,CAAC;AAED,OAAO,EACH,YAAY,EACZ,SAAS,EACT,cAAc,EACd,SAAS,EACT,UAAU,EACV,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,SAAS,EACT,UAAU,EACV,UAAU,EACV,WAAW,EACX,SAAS,EACT,UAAU,EACV,UAAU,EACV,WAAW,EACX,WAAW,EACX,YAAY,EACZ,UAAU,EACV,UAAU,EACV,WAAW,EACX,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,sBAAsB,EACtB,YAAY,EACZ,OAAO,EACP,UAAU,EACV,cAAc,EACd,YAAY,EACZ,eAAe,EACf,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,gBAAgB,EAChB,sBAAsB,EACtB,qBAAqB,GAExB,CAAC","sourcesContent":["import { type Descriptor, resolveType as nativeResolveType } from \"@gtkx/native\";\nimport { bind } from \"./bind.js\";\nimport {\n type ArrayDescriptor,\n biguint64T,\n booleanT,\n type BoxedDescriptor,\n type FundamentalDescriptor,\n refT,\n sizedArrayT,\n stringT,\n uint32T,\n} from \"./descriptors.js\";\nimport { LIB } from \"./library.js\";\n\n/** Object tagged with its GLib type through a `__type__` GType field. */\ntype TypedClass = {\n /** GType the object's class is registered under. */\n __type__: bigint;\n};\n\ntype ResolvableKind = \"enum\" | \"flags\" | \"boxed\" | \"fundamental\" | \"array\";\ntype ResolvableDescriptor = Extract<Descriptor, { kind: ResolvableKind }>;\n\nconst resolvedTypeCache: Map<string, bigint> = new Map();\nconst gTypeFromName = bind(LIB, \"g_type_from_name\", [stringT(\"borrowed\")], biguint64T);\nconst gTypeIsA = bind(LIB, \"g_type_is_a\", [biguint64T, biguint64T], booleanT);\nconst gTypeParent = bind(LIB, \"g_type_parent\", [biguint64T], biguint64T);\nconst gTypeFundamental = bind(LIB, \"g_type_fundamental\", [biguint64T], biguint64T);\nconst gTypeName = bind(LIB, \"g_type_name\", [biguint64T], stringT(\"borrowed\"));\nconst gTypeInterfaces = bind(LIB, \"g_type_interfaces\", [biguint64T, refT(uint32T)], sizedArrayT(biguint64T, 1, \"full\"));\n/** GType tag for an invalid or uninitialized type. */\nconst TYPE_INVALID = 0n;\n/** GType tag for the absence of a value (`void`). */\nconst TYPE_NONE: bigint = typeFromName(\"void\");\n/** GType tag for the base GInterface type. */\nconst TYPE_INTERFACE: bigint = typeFromName(\"GInterface\");\n/** GType tag for `gchar` (signed 8-bit integer). */\nconst TYPE_CHAR: bigint = typeFromName(\"gchar\");\n/** GType tag for `guchar` (unsigned 8-bit integer). */\nconst TYPE_UCHAR: bigint = typeFromName(\"guchar\");\n/** GType tag for `gboolean`. */\nconst TYPE_BOOLEAN: bigint = typeFromName(\"gboolean\");\n/** GType tag for `gint`. */\nconst TYPE_INT: bigint = typeFromName(\"gint\");\n/** GType tag for `guint`. */\nconst TYPE_UINT: bigint = typeFromName(\"guint\");\n/** GType tag for `glong`. */\nconst TYPE_LONG: bigint = typeFromName(\"glong\");\n/** GType tag for `gulong`. */\nconst TYPE_ULONG: bigint = typeFromName(\"gulong\");\n/** GType tag for `gint64`. */\nconst TYPE_INT64: bigint = typeFromName(\"gint64\");\n/** GType tag for `guint64`. */\nconst TYPE_UINT64: bigint = typeFromName(\"guint64\");\n/** GType tag for the base GEnum type. */\nconst TYPE_ENUM: bigint = typeFromName(\"GEnum\");\n/** GType tag for the base GFlags type. */\nconst TYPE_FLAGS: bigint = typeFromName(\"GFlags\");\n/** GType tag for `gfloat`. */\nconst TYPE_FLOAT: bigint = typeFromName(\"gfloat\");\n/** GType tag for `gdouble`. */\nconst TYPE_DOUBLE: bigint = typeFromName(\"gdouble\");\n/** GType tag for `gchararray` (a nul-terminated C string). */\nconst TYPE_STRING: bigint = typeFromName(\"gchararray\");\n/** GType tag for `gpointer` (an opaque pointer). */\nconst TYPE_POINTER: bigint = typeFromName(\"gpointer\");\n/** GType tag for the base GBoxed type. */\nconst TYPE_BOXED: bigint = typeFromName(\"GBoxed\");\n/** GType tag for the base GParam type. */\nconst TYPE_PARAM: bigint = typeFromName(\"GParam\");\n/** GType tag for the base GObject type. */\nconst TYPE_OBJECT: bigint = typeFromName(\"GObject\");\n/** GType tag for a GType value itself. */\nconst TYPE_GTYPE: bigint = typeFromName(\"GType\");\n/** GType tag for GVariant. */\nconst TYPE_VARIANT: bigint = typeFromName(\"GVariant\");\n/** GType tag for a Unicode character stored as `guint`. */\nconst TYPE_UNICHAR: bigint = typeFromName(\"guint\");\nconst getErrorType: () => bigint = lazyType(\"GError\");\nconst getStrvType: () => bigint = lazyType(\"GStrv\");\n\nconst PLAIN_DESCRIPTOR_TYPES: Partial<Record<Descriptor[\"kind\"], bigint>> = {\n boolean: TYPE_BOOLEAN,\n string: TYPE_STRING,\n int8: TYPE_INT,\n int16: TYPE_INT,\n int32: TYPE_INT,\n uint8: TYPE_UINT,\n uint16: TYPE_UINT,\n uint32: TYPE_UINT,\n int64: TYPE_INT64,\n bigint64: TYPE_INT64,\n uint64: TYPE_UINT64,\n biguint64: TYPE_UINT64,\n float32: TYPE_FLOAT,\n float64: TYPE_DOUBLE,\n object: TYPE_OBJECT,\n};\n\nconst RESOLVABLE_DESCRIPTOR_KINDS: Set<Descriptor[\"kind\"]> = new Set<ResolvableKind>([\n \"enum\",\n \"flags\",\n \"boxed\",\n \"fundamental\",\n \"array\",\n]);\n\nfunction lazyType(name: string): () => bigint {\n let cached: bigint | undefined;\n\n return () => {\n cached ??= typeFromName(name);\n\n return cached;\n };\n}\n\nconst isTypedClass = (value: unknown): value is TypedClass =>\n typeof value === \"object\" && value !== null && \"__type__\" in value && typeof value.__type__ === \"bigint\";\n\n/** Returns whether `type` is `ancestorType` or descends from it. */\n/* eslint-disable-next-line unicorn/consistent-boolean-name -- mirrors g_type_is_a from the C API */\nfunction typeIsA(type: bigint, ancestorType: bigint): boolean {\n return gTypeIsA(type, ancestorType) as boolean;\n}\n\n/** Returns the immediate parent GType of the given type. */\nfunction typeParent(type: bigint): bigint {\n return gTypeParent(type) as bigint;\n}\n\n/** Returns the GTypes of the interfaces implemented by the given type. */\nfunction typeInterfaces(type: bigint): bigint[] {\n const nInterfacesRef = { value: 0 };\n\n return gTypeInterfaces(type, nInterfacesRef) as bigint[];\n}\n\n/** Returns the GType registered under the given name, or `TYPE_INVALID` if none exists. */\nfunction typeFromName(name: string): bigint {\n return gTypeFromName(name) as bigint;\n}\n\nfunction typeFundamental(type: bigint): bigint {\n return gTypeFundamental(type) as bigint;\n}\n\n/** Returns the registered name of a GType, or null if it has none. */\nfunction typeName(type: bigint): string | null {\n return (gTypeName(type) ?? null) as string | null;\n}\n\n/** Returns whether `value` is a typed wrapper whose GType is or descends from `gtype`. */\n/* eslint-disable-next-line unicorn/consistent-boolean-name -- mirrors g_type_is_a from the C API */\nfunction valueIsA(value: unknown, gtype: bigint): boolean {\n return isTypedClass(value) && typeIsA(value.__type__, gtype);\n}\n\n/**\n * Resolves the GType produced by a `get_type` function in a shared library, caching\n * the result per library and function name.\n * @param sharedLibrary Path or name of the shared library exporting the function.\n * @param typeFnName Name of the `*_get_type` function to call.\n */\nconst resolveType = (sharedLibrary: string, typeFnName: string): bigint => {\n const key = `${sharedLibrary}:${typeFnName}`;\n const cached = resolvedTypeCache.get(key);\n\n if (cached !== undefined) {\n return cached;\n }\n\n const gtype = nativeResolveType(sharedLibrary, typeFnName);\n resolvedTypeCache.set(key, gtype);\n\n return gtype;\n};\n\nconst resolveBoxedType = (descriptor: BoxedDescriptor): bigint => {\n if (descriptor.getTypeFnName && descriptor.sharedLibrary) {\n return resolveType(descriptor.sharedLibrary, descriptor.getTypeFnName);\n }\n\n const gtype = typeFromName(descriptor.typeName);\n\n if (gtype === TYPE_INVALID) {\n throw new Error(`Cannot resolve gtype for boxed type '${descriptor.typeName}'`);\n }\n\n return gtype;\n};\n\nconst resolveFundamentalType = (descriptor: FundamentalDescriptor): bigint => {\n if (descriptor.typeName) {\n const gtype = typeFromName(descriptor.typeName);\n\n if (gtype !== TYPE_INVALID) {\n return gtype;\n }\n }\n\n throw new Error(\"Cannot resolve gtype for fundamental type without a typeName\");\n};\n\nfunction resolveArrayType(descriptor: ArrayDescriptor): bigint {\n if (descriptor.itemDescriptor.kind === \"string\" && descriptor.arrayKind === \"array\") {\n return getStrvType();\n }\n\n throw new Error(`Unsupported array type ${descriptor.arrayKind} of ${descriptor.itemDescriptor.kind}`);\n}\n\nfunction isResolvableDescriptor(descriptor: Descriptor): descriptor is ResolvableDescriptor {\n return RESOLVABLE_DESCRIPTOR_KINDS.has(descriptor.kind);\n}\n\nfunction resolveDescriptorType(descriptor: Descriptor): bigint {\n if (descriptor.kind === \"biguint64\" && \"type\" in descriptor) {\n return TYPE_GTYPE;\n }\n\n const plain = PLAIN_DESCRIPTOR_TYPES[descriptor.kind];\n\n if (plain !== undefined) {\n return plain;\n }\n\n if (!isResolvableDescriptor(descriptor)) {\n throw new Error(`Unsupported type descriptor '${descriptor.kind}'`);\n }\n\n switch (descriptor.kind) {\n case \"enum\":\n case \"flags\": {\n return resolveType(descriptor.sharedLibrary, descriptor.getTypeFnName);\n }\n case \"boxed\": {\n return resolveBoxedType(descriptor);\n }\n case \"fundamental\": {\n return resolveFundamentalType(descriptor);\n }\n case \"array\": {\n return resolveArrayType(descriptor);\n }\n }\n}\n\nexport {\n TYPE_INVALID,\n TYPE_NONE,\n TYPE_INTERFACE,\n TYPE_CHAR,\n TYPE_UCHAR,\n TYPE_BOOLEAN,\n TYPE_INT,\n TYPE_UINT,\n TYPE_LONG,\n TYPE_ULONG,\n TYPE_INT64,\n TYPE_UINT64,\n TYPE_ENUM,\n TYPE_FLAGS,\n TYPE_FLOAT,\n TYPE_DOUBLE,\n TYPE_STRING,\n TYPE_POINTER,\n TYPE_BOXED,\n TYPE_PARAM,\n TYPE_OBJECT,\n TYPE_GTYPE,\n TYPE_VARIANT,\n TYPE_UNICHAR,\n getErrorType,\n getStrvType,\n isResolvableDescriptor,\n isTypedClass,\n typeIsA,\n typeParent,\n typeInterfaces,\n typeFromName,\n typeFundamental,\n typeName,\n valueIsA,\n resolveType,\n resolveBoxedType,\n resolveFundamentalType,\n resolveDescriptorType,\n type TypedClass,\n};\n"]}
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../src/type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,WAAW,IAAI,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjF,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAEH,UAAU,EACV,QAAQ,EAGR,IAAI,EACJ,WAAW,EACX,OAAO,EACP,OAAO,GACV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAWnC,MAAM,iBAAiB,GAAwB,IAAI,GAAG,EAAE,CAAC;AACzD,MAAM,aAAa,GAAG,IAAI,CAAC,GAAG,EAAE,kBAAkB,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;AACvF,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,aAAa,EAAE,CAAC,UAAU,EAAE,UAAU,CAAC,EAAE,QAAQ,CAAC,CAAC;AAC9E,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,EAAE,eAAe,EAAE,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC,CAAC;AACzE,MAAM,gBAAgB,GAAG,IAAI,CAAC,GAAG,EAAE,oBAAoB,EAAE,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC,CAAC;AACnF,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,aAAa,EAAE,CAAC,UAAU,CAAC,EAAE,OAAO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O,WAAW,CAAC,UAAU,CAAC,aAAa,EAAE,UAAU,CAAC,aAAa,CAAC,CAAC;QAC3E,CAAC;QACD,KAAK,OAAO,CAAC,CAAC,CAAC;YACX,OAAO,gBAAgB,CAAC,UAAU,CAAC,CAAC;QACxC,CAAC;QACD,KAAK,aAAa,CAAC,CAAC,CAAC;YACjB,OAAO,sBAAsB,CAAC,UAAU,CAAC,CAAC;QAC9C,CAAC;QACD,KAAK,OAAO,CAAC,CAAC,CAAC;YACX,OAAO,gBAAgB,CAAC,UAAU,CAAC,CAAC;QACxC,CAAC;IACL,CAAC;AACL,CAAC;AAED,OAAO,EACH,YAAY,EACZ,SAAS,EACT,cAAc,EACd,SAAS,EACT,UAAU,EACV,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,SAAS,EACT,UAAU,EACV,UAAU,EACV,WAAW,EACX,SAAS,EACT,UAAU,EACV,UAAU,EACV,WAAW,EACX,WAAW,EACX,YAAY,EACZ,UAAU,EACV,UAAU,EACV,WAAW,EACX,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,sBAAsB,EACtB,YAAY,EACZ,OAAO,EACP,UAAU,EACV,cAAc,EACd,YAAY,EACZ,eAAe,EACf,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,gBAAgB,EAChB,sBAAsB,EACtB,qBAAqB,GAExB,CAAC","sourcesContent":["import { type Descriptor, resolveType as nativeResolveType } from \"@gtkx/native\";\nimport { bind } from \"./bind.js\";\nimport {\n type ArrayDescriptor,\n biguint64T,\n booleanT,\n type BoxedDescriptor,\n type FundamentalDescriptor,\n refT,\n sizedArrayT,\n stringT,\n uint32T,\n} from \"./descriptors.js\";\nimport { LIB } from \"./library.js\";\n\n/** Object tagged with its GLib type through a `__type__` GType field. */\ntype TypedClass = {\n /** GType the object's class is registered under. */\n __type__: bigint;\n};\n\ntype ResolvableKind = \"enum\" | \"flags\" | \"boxed\" | \"fundamental\" | \"array\";\ntype ResolvableDescriptor = Extract<Descriptor, { kind: ResolvableKind }>;\n\nconst resolvedTypeCache: Map<string, bigint> = new Map();\nconst gTypeFromName = bind(LIB, \"g_type_from_name\", [stringT(\"borrowed\")], biguint64T);\nconst gTypeIsA = bind(LIB, \"g_type_is_a\", [biguint64T, biguint64T], booleanT);\nconst gTypeParent = bind(LIB, \"g_type_parent\", [biguint64T], biguint64T);\nconst gTypeFundamental = bind(LIB, \"g_type_fundamental\", [biguint64T], biguint64T);\nconst gTypeName = bind(LIB, \"g_type_name\", [biguint64T], stringT(\"borrowed\"));\nconst gTypeInterfaces = bind(LIB, \"g_type_interfaces\", [biguint64T, refT(uint32T)], sizedArrayT(biguint64T, 1, \"full\"));\n/** GType tag for an invalid or uninitialized type. */\nconst TYPE_INVALID = 0n;\n/** GType tag for the absence of a value (`void`). */\nconst TYPE_NONE: bigint = typeFromName(\"void\");\n/** GType tag for the base GInterface type. */\nconst TYPE_INTERFACE: bigint = typeFromName(\"GInterface\");\n/** GType tag for `gchar` (signed 8-bit integer). */\nconst TYPE_CHAR: bigint = typeFromName(\"gchar\");\n/** GType tag for `guchar` (unsigned 8-bit integer). */\nconst TYPE_UCHAR: bigint = typeFromName(\"guchar\");\n/** GType tag for `gboolean`. */\nconst TYPE_BOOLEAN: bigint = typeFromName(\"gboolean\");\n/** GType tag for `gint`. */\nconst TYPE_INT: bigint = typeFromName(\"gint\");\n/** GType tag for `guint`. */\nconst TYPE_UINT: bigint = typeFromName(\"guint\");\n/** GType tag for `glong`. */\nconst TYPE_LONG: bigint = typeFromName(\"glong\");\n/** GType tag for `gulong`. */\nconst TYPE_ULONG: bigint = typeFromName(\"gulong\");\n/** GType tag for `gint64`. */\nconst TYPE_INT64: bigint = typeFromName(\"gint64\");\n/** GType tag for `guint64`. */\nconst TYPE_UINT64: bigint = typeFromName(\"guint64\");\n/** GType tag for the base GEnum type. */\nconst TYPE_ENUM: bigint = typeFromName(\"GEnum\");\n/** GType tag for the base GFlags type. */\nconst TYPE_FLAGS: bigint = typeFromName(\"GFlags\");\n/** GType tag for `gfloat`. */\nconst TYPE_FLOAT: bigint = typeFromName(\"gfloat\");\n/** GType tag for `gdouble`. */\nconst TYPE_DOUBLE: bigint = typeFromName(\"gdouble\");\n/** GType tag for `gchararray` (a nul-terminated C string). */\nconst TYPE_STRING: bigint = typeFromName(\"gchararray\");\n/** GType tag for `gpointer` (an opaque pointer). */\nconst TYPE_POINTER: bigint = typeFromName(\"gpointer\");\n/** GType tag for the base GBoxed type. */\nconst TYPE_BOXED: bigint = typeFromName(\"GBoxed\");\n/** GType tag for the base GParam type. */\nconst TYPE_PARAM: bigint = typeFromName(\"GParam\");\n/** GType tag for the base GObject type. */\nconst TYPE_OBJECT: bigint = typeFromName(\"GObject\");\n/** GType tag for a GType value itself. */\nconst TYPE_GTYPE: bigint = typeFromName(\"GType\");\n/** GType tag for GVariant. */\nconst TYPE_VARIANT: bigint = typeFromName(\"GVariant\");\n/** GType tag for a Unicode character stored as `guint`. */\nconst TYPE_UNICHAR: bigint = typeFromName(\"guint\");\nconst getErrorType: () => bigint = lazyType(\"GError\");\nconst getStrvType: () => bigint = lazyType(\"GStrv\");\n\nconst PLAIN_DESCRIPTOR_TYPES: Partial<Record<Descriptor[\"kind\"], bigint>> = {\n boolean: TYPE_BOOLEAN,\n string: TYPE_STRING,\n int8: TYPE_INT,\n int16: TYPE_INT,\n int32: TYPE_INT,\n uint8: TYPE_UINT,\n uint16: TYPE_UINT,\n uint32: TYPE_UINT,\n int64: TYPE_INT64,\n bigint64: TYPE_INT64,\n uint64: TYPE_UINT64,\n biguint64: TYPE_UINT64,\n float32: TYPE_FLOAT,\n float64: TYPE_DOUBLE,\n object: TYPE_OBJECT,\n};\n\nconst RESOLVABLE_DESCRIPTOR_KINDS: Set<Descriptor[\"kind\"]> = new Set<ResolvableKind>([\n \"enum\",\n \"flags\",\n \"boxed\",\n \"fundamental\",\n \"array\",\n]);\n\nfunction lazyType(name: string): () => bigint {\n let cached: bigint | undefined;\n\n return () => {\n cached ??= typeFromName(name);\n\n return cached;\n };\n}\n\nconst isTypedClass = (value: unknown): value is TypedClass =>\n typeof value === \"object\" && value !== null && \"__type__\" in value && typeof value.__type__ === \"bigint\";\n\n/** Returns whether `type` is `ancestorType` or descends from it. */\n/* eslint-disable-next-line unicorn/consistent-boolean-name -- mirrors g_type_is_a from the C API */\nfunction typeIsA(type: bigint, ancestorType: bigint): boolean {\n return gTypeIsA(type, ancestorType) as boolean;\n}\n\n/** Returns the immediate parent GType of the given type. */\nfunction typeParent(type: bigint): bigint {\n return gTypeParent(type) as bigint;\n}\n\n/** Returns the GTypes of the interfaces implemented by the given type. */\nfunction typeInterfaces(type: bigint): bigint[] {\n const nInterfacesRef = { value: 0 };\n\n return gTypeInterfaces(type, nInterfacesRef) as bigint[];\n}\n\n/** Returns the GType registered under the given name, or `TYPE_INVALID` if none exists. */\nfunction typeFromName(name: string): bigint {\n return gTypeFromName(name) as bigint;\n}\n\nfunction typeFundamental(type: bigint): bigint {\n return gTypeFundamental(type) as bigint;\n}\n\n/** Returns the registered name of a GType, or null if it has none. */\nfunction typeName(type: bigint): string | null {\n return (gTypeName(type) ?? null) as string | null;\n}\n\n/** Returns whether `value` is a typed wrapper whose GType is or descends from `gtype`. */\n/* eslint-disable-next-line unicorn/consistent-boolean-name -- mirrors g_type_is_a from the C API */\nfunction valueIsA(value: unknown, gtype: bigint): boolean {\n return isTypedClass(value) && typeIsA(value.__type__, gtype);\n}\n\n/**\n * Resolves the GType produced by a `get_type` function in a shared library, caching\n * the result per library and function name.\n * @param sharedLibrary Path or name of the shared library exporting the function.\n * @param typeFnName Name of the `*_get_type` function to call.\n */\nconst resolveType = (sharedLibrary: string, typeFnName: string): bigint => {\n const key = `${sharedLibrary}:${typeFnName}`;\n const cached = resolvedTypeCache.get(key);\n\n if (cached !== undefined) {\n return cached;\n }\n\n const gtype = nativeResolveType(sharedLibrary, typeFnName);\n resolvedTypeCache.set(key, gtype);\n\n return gtype;\n};\n\nconst resolveBoxedType = (descriptor: BoxedDescriptor): bigint => {\n if (descriptor.getTypeFnName && descriptor.sharedLibrary) {\n return resolveType(descriptor.sharedLibrary, descriptor.getTypeFnName);\n }\n\n const gtype = typeFromName(descriptor.typeName);\n\n if (gtype === TYPE_INVALID) {\n throw new Error(`Cannot resolve gtype for boxed type '${descriptor.typeName}'`);\n }\n\n return gtype;\n};\n\nconst resolveFundamentalType = (descriptor: FundamentalDescriptor): bigint => {\n if (descriptor.typeName) {\n const gtype = typeFromName(descriptor.typeName);\n\n if (gtype !== TYPE_INVALID) {\n return gtype;\n }\n }\n\n throw new Error(\"Cannot resolve gtype for fundamental type without a typeName\");\n};\n\nconst getByteArrayType = (): bigint => resolveType(LIB, \"g_byte_array_get_type\");\n\nfunction resolveArrayType(descriptor: ArrayDescriptor): bigint {\n if (descriptor.itemDescriptor.kind === \"string\" && descriptor.arrayKind === \"array\") {\n return getStrvType();\n }\n\n if (descriptor.arrayKind === \"gbytearray\") {\n return getByteArrayType();\n }\n\n throw new Error(`Unsupported array type ${descriptor.arrayKind} of ${descriptor.itemDescriptor.kind}`);\n}\n\nfunction isResolvableDescriptor(descriptor: Descriptor): descriptor is ResolvableDescriptor {\n return RESOLVABLE_DESCRIPTOR_KINDS.has(descriptor.kind);\n}\n\nfunction resolveDescriptorType(descriptor: Descriptor): bigint {\n if (descriptor.kind === \"biguint64\" && \"type\" in descriptor) {\n return TYPE_GTYPE;\n }\n\n const plain = PLAIN_DESCRIPTOR_TYPES[descriptor.kind];\n\n if (plain !== undefined) {\n return plain;\n }\n\n if (!isResolvableDescriptor(descriptor)) {\n throw new Error(`Unsupported type descriptor '${descriptor.kind}'`);\n }\n\n switch (descriptor.kind) {\n case \"enum\":\n case \"flags\": {\n return resolveType(descriptor.sharedLibrary, descriptor.getTypeFnName);\n }\n case \"boxed\": {\n return resolveBoxedType(descriptor);\n }\n case \"fundamental\": {\n return resolveFundamentalType(descriptor);\n }\n case \"array\": {\n return resolveArrayType(descriptor);\n }\n }\n}\n\nexport {\n TYPE_INVALID,\n TYPE_NONE,\n TYPE_INTERFACE,\n TYPE_CHAR,\n TYPE_UCHAR,\n TYPE_BOOLEAN,\n TYPE_INT,\n TYPE_UINT,\n TYPE_LONG,\n TYPE_ULONG,\n TYPE_INT64,\n TYPE_UINT64,\n TYPE_ENUM,\n TYPE_FLAGS,\n TYPE_FLOAT,\n TYPE_DOUBLE,\n TYPE_STRING,\n TYPE_POINTER,\n TYPE_BOXED,\n TYPE_PARAM,\n TYPE_OBJECT,\n TYPE_GTYPE,\n TYPE_VARIANT,\n TYPE_UNICHAR,\n getByteArrayType,\n getErrorType,\n getStrvType,\n isResolvableDescriptor,\n isTypedClass,\n typeIsA,\n typeParent,\n typeInterfaces,\n typeFromName,\n typeFundamental,\n typeName,\n valueIsA,\n resolveType,\n resolveBoxedType,\n resolveFundamentalType,\n resolveDescriptorType,\n type TypedClass,\n};\n"]}
package/dist/value.d.ts CHANGED
@@ -1,25 +1,64 @@
1
1
  import { type Descriptor, type ExternalObject, type Handle } from "@gtkx/native";
2
+ import { type ValueGuard } from "./param-spec.js";
3
+ import { type TypedClass } from "./type.js";
2
4
  type ValueType = {
3
5
  set: (value: ExternalObject<Handle>, nativeValue: unknown) => void;
4
6
  get: (value: ExternalObject<Handle>) => unknown;
5
7
  };
6
8
  type ValueWriter = ValueType["set"];
7
9
  type ValueNarrower = (jsValue: unknown) => unknown;
10
+ /**
11
+ * JavaScript value a `GObject.Value` can be built from without being told which GType to hold, for the
12
+ * parameters that take one. A string holds `gchararray`, a boolean `gboolean`, an integer within `gint`
13
+ * range `gint` and any other number `gdouble`, a `bigint` `gint64` or `guint64` past its range, an array
14
+ * of strings `GStrv`, a wrapper instance the GType it carries, and `null` a NULL `gpointer`, which is
15
+ * what GJS infers for it and which few callees accept. Reaching a GType inference cannot name, such as
16
+ * `guchar` or an enumeration, takes an explicitly initialized `GObject.Value` instead.
17
+ */
18
+ type JsValue = string | number | bigint | boolean | string[] | TypedClass | null;
8
19
  declare function getValueType(value: ExternalObject<Handle>): bigint;
9
20
  declare function copyValue(dest: ExternalObject<Handle>, src: ExternalObject<Handle>): void;
10
21
  declare const newValueForType: (type: bigint) => ExternalObject<Handle>;
11
22
  /**
12
23
  * Duplicates the boxed value held by a GValue and returns the copy wrapped in the
13
- * class registered for its GType, or null when the GValue holds no boxed type.
24
+ * class its GType resolves to, or null when the GValue holds no boxed type.
25
+ * A `GByteArray` payload is copied into a `Uint8Array` instead of being wrapped.
14
26
  */
15
27
  declare function getBoxedValue(value: ExternalObject<Handle>): object | null;
16
- /** Stores a boxed object, or null, into a GValue that holds a boxed type. */
17
- declare function setBoxedValue(value: ExternalObject<Handle>, boxed: object | null): void;
28
+ /**
29
+ * Stores a boxed object, or null, into a GValue that holds a boxed type. A GValue holding
30
+ * `G_TYPE_VALUE` also takes any other {@link JsValue}, which is boxed into a nested `GObject.Value`
31
+ * of the GType inferred from it, and one holding a `GByteArray` also takes the bytes as a
32
+ * `Uint8Array` or an array of byte values.
33
+ * @param value Handle of an initialized value to write into.
34
+ * @param boxed The boxed instance, bytes, or {@link JsValue} to store.
35
+ * @throws {ValueMarshalError} When the value cannot hold what was passed.
36
+ */
37
+ declare function setBoxedValue(value: ExternalObject<Handle>, boxed: JsValue | object): void;
18
38
  declare function valueNarrowerFor(type: bigint): ValueNarrower;
19
39
  declare function valueWriterFor(type: bigint): ValueWriter;
20
40
  declare function intoValue(value: ExternalObject<Handle>, jsValue: unknown): void;
41
+ /**
42
+ * Marshals a value passed where a `GObject.Value` is expected into a value handle: an already-built
43
+ * value yields its own handle, and any other {@link JsValue} is stored in a new one initialized to the
44
+ * GType inferred from it.
45
+ * @param jsValue Value to store, or an already-built `GObject.Value`.
46
+ * @throws {ValueMarshalError} When no GType can be inferred from the value.
47
+ */
48
+ declare function toValueHandle(jsValue: unknown): ExternalObject<Handle>;
49
+ /** Same as {@link toValueHandle}, but passes a null or undefined value through as no value at all. */
50
+ declare const tryToValueHandle: (jsValue: unknown) => ExternalObject<Handle> | undefined;
21
51
  declare function toValue(descriptor: Descriptor, value: unknown): ExternalObject<Handle>;
52
+ /**
53
+ * Reads what a `GObject.Value` holds as its JavaScript form, wrapping an object, boxed, param, variant,
54
+ * or fundamental payload in the class registered for its GType, and handing back a string, number,
55
+ * `bigint`, boolean, or array of strings for the rest.
56
+ * @param value Handle of an initialized value to read.
57
+ * @throws {Error} When the GType it holds has no JavaScript form, such as a non-null `gpointer`.
58
+ */
22
59
  declare function fromValue(value: ExternalObject<Handle>): unknown;
60
+ declare const fromValueForDescriptor: (descriptor: Descriptor, value: ExternalObject<Handle>) => unknown;
61
+ declare const valueGuardOverrideFor: (valueType: bigint) => ValueGuard | undefined;
23
62
  declare function newValueForDescriptor(descriptor: Descriptor): ExternalObject<Handle>;
24
63
  declare function outValueForDescriptor(descriptor: Descriptor, initial?: unknown): {
25
64
  value: ExternalObject<Handle>;
@@ -27,5 +66,10 @@ declare function outValueForDescriptor(descriptor: Descriptor, initial?: unknown
27
66
  };
28
67
  declare function outValueForBoxedDescriptor(descriptor: Descriptor, boxed: object): ExternalObject<Handle>;
29
68
  declare function inoutValueForBoxedDescriptor(descriptor: Descriptor, boxed: object): ExternalObject<Handle>;
30
- export { getValueType, intoValue, copyValue, getBoxedValue, setBoxedValue, toValue, fromValue, newValueForDescriptor, newValueForType, outValueForDescriptor, outValueForBoxedDescriptor, inoutValueForBoxedDescriptor, type ValueNarrower, valueNarrowerFor, type ValueWriter, valueWriterFor, };
69
+ /** Thrown when a value passed where a `GObject.Value` is expected holds no GType one can be built from. */
70
+ declare class ValueMarshalError extends TypeError {
71
+ /** Name callers match on when the error is caught as a plain `TypeError`. */
72
+ name: string;
73
+ }
74
+ export { getValueType, intoValue, copyValue, getBoxedValue, setBoxedValue, type JsValue, toValue, toValueHandle, tryToValueHandle, ValueMarshalError, fromValue, fromValueForDescriptor, valueGuardOverrideFor, newValueForDescriptor, newValueForType, outValueForDescriptor, outValueForBoxedDescriptor, inoutValueForBoxedDescriptor, type ValueNarrower, valueNarrowerFor, type ValueWriter, valueWriterFor, };
31
75
  //# sourceMappingURL=value.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"value.d.ts","sourceRoot":"","sources":["../src/value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,UAAU,EAAE,KAAK,cAAc,EAAW,KAAK,MAAM,EAAe,MAAM,cAAc,CAAC;AA2D9G,KAAK,SAAS,GAAG;IACb,GAAG,EAAE,CAAC,KAAK,EAAE,cAAc,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,OAAO,KAAK,IAAI,CAAC;IACnE,GAAG,EAAE,CAAC,KAAK,EAAE,cAAc,CAAC,MAAM,CAAC,KAAK,OAAO,CAAC;CACnD,CAAC;AAGF,KAAK,WAAW,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;AACpC,KAAK,aAAa,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC;AAoLnD,iBAAS,YAAY,CAAC,KAAK,EAAE,cAAc,CAAC,MAAM,CAAC,GAAG,MAAM,CAE3D;AAED,iBAAS,SAAS,CAAC,IAAI,EAAE,cAAc,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,cAAc,CAAC,MAAM,CAAC,GAAG,IAAI,CAMlF;AAED,QAAA,MAAM,eAAe,GAAI,MAAM,MAAM,KAAG,cAAc,CAAC,MAAM,CAK5D,CAAC;AAcF;;;GAGG;AACH,iBAAS,aAAa,CAAC,KAAK,EAAE,cAAc,CAAC,MAAM,CAAC,GAAG,MAAM,GAAG,IAAI,CAWnE;AAED,6EAA6E;AAC7E,iBAAS,aAAa,CAAC,KAAK,EAAE,cAAc,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAGhF;AA8ID,iBAAS,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,CAErD;AAED,iBAAS,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAQjD;AAED,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a,EACb,KAAK,OAAO,EACZ,OAAO,EACP,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EACjB,SAAS,EACT,sBAAsB,EACtB,qBAAqB,EACrB,qBAAqB,EACrB,eAAe,EACf,qBAAqB,EACrB,0BAA0B,EAC1B,4BAA4B,EAC5B,KAAK,aAAa,EAClB,gBAAgB,EAChB,KAAK,WAAW,EAChB,cAAc,GACjB,CAAC"}
package/dist/value.js CHANGED
@@ -1,10 +1,11 @@
1
1
  import { alloc, getType, read, write } from "@gtkx/native";
2
2
  import { bind, createBindCache } from "./bind.js";
3
- import { arrayT, bigint64T, biguint64T, booleanT, boxedT, float32T, float64T, fundamentalLifecycleFor, fundamentalT, int8T, int32T, objectT, stringT, uint8T, uint32T, uint64T, voidT, } from "./descriptors.js";
3
+ import { arrayT, bigint64T, biguint64T, booleanT, boxedT, byteArrayT, float32T, float64T, fundamentalLifecycleFor, fundamentalT, int8T, int32T, objectT, stringT, uint8T, uint32T, uint64T, voidT, } from "./descriptors.js";
4
4
  import { LIB, PARAM_T, VALUE_SIZE, VALUE_T, VARIANT_T } from "./library.js";
5
5
  import { toNative } from "./native-value.js";
6
- import { getHandle, getWrapperClass, wrapHandle, wrapObject } from "./registry.js";
7
- import { getStrvType, isResolvableDescriptor, resolveBoxedType, resolveDescriptorType, resolveFundamentalType, resolveType, TYPE_BOOLEAN, TYPE_BOXED, TYPE_CHAR, TYPE_DOUBLE, TYPE_ENUM, TYPE_FLAGS, TYPE_FLOAT, TYPE_GTYPE, TYPE_INT, TYPE_INT64, TYPE_INTERFACE, TYPE_INVALID, TYPE_LONG, TYPE_OBJECT, TYPE_PARAM, TYPE_POINTER, TYPE_STRING, TYPE_UCHAR, TYPE_UINT, TYPE_UINT64, TYPE_ULONG, TYPE_VARIANT, typeFundamental, typeName, } from "./type.js";
6
+ import { INT32_MAXIMUM, INT32_MINIMUM, INT64_MAXIMUM, INT64_MINIMUM, isStringArray, resolveGtype, UINT64_MAXIMUM, } from "./param-spec.js";
7
+ import { coerceGType, describeValueKind, getHandle, getWrapperClass, wrapFundamentalHandle, wrapHandle, wrapObject, } from "./registry.js";
8
+ import { getByteArrayType, getStrvType, isResolvableDescriptor, resolveBoxedType, resolveDescriptorType, resolveFundamentalType, resolveType, TYPE_BOOLEAN, TYPE_BOXED, TYPE_CHAR, TYPE_DOUBLE, TYPE_ENUM, TYPE_FLAGS, TYPE_FLOAT, TYPE_GTYPE, TYPE_INT, TYPE_INT64, TYPE_INTERFACE, TYPE_INVALID, TYPE_LONG, TYPE_OBJECT, TYPE_PARAM, TYPE_POINTER, TYPE_STRING, TYPE_UCHAR, TYPE_UINT, TYPE_UINT64, TYPE_ULONG, TYPE_VARIANT, typeFundamental, typeIsA, typeName, } from "./type.js";
8
9
  const setBoxedCache = createBindCache();
9
10
  const setStaticBoxedCache = createBindCache();
10
11
  const dupBoxedCache = createBindCache();
@@ -13,7 +14,13 @@ const peekPointerCache = createBindCache();
13
14
  const gValueInit = bind(LIB, "g_value_init", [VALUE_T, biguint64T], voidT);
14
15
  const gValueCopy = bind(LIB, "g_value_copy", [VALUE_T, VALUE_T], voidT);
15
16
  const booleanValueType = bindValueType("boolean", booleanT);
16
- const typeValueType = bindValueType("gtype", biguint64T);
17
+ const boundTypeValueType = bindValueType("gtype", biguint64T);
18
+ const typeValueType = {
19
+ set: (value, jsValue) => {
20
+ boundTypeValueType.set(value, coerceGType(jsValue));
21
+ },
22
+ get: boundTypeValueType.get,
23
+ };
17
24
  const scharValueType = bindValueType("schar", int8T);
18
25
  const ucharValueType = bindValueType("uchar", uint8T);
19
26
  const intValueType = bindValueType("int", int32T);
@@ -36,6 +43,10 @@ const strvValueType = {
36
43
  set: setStrvValue,
37
44
  get: bind(LIB, "g_value_get_boxed", [VALUE_T], arrayT(stringT("borrowed"))),
38
45
  };
46
+ const setByteArrayBoxed = bind(LIB, "g_value_set_boxed", [VALUE_T, byteArrayT()], voidT);
47
+ const getBoxedPointer = bind(LIB, "g_value_get_boxed", [VALUE_T], uint64T);
48
+ const getBytesBoxed = bind(LIB, "g_value_get_boxed", [VALUE_T], byteArrayT());
49
+ const getByteItemsBoxed = bind(LIB, "g_value_get_boxed", [VALUE_T], arrayT(uint8T, "gbytearray"));
39
50
  const PLAIN_VALUE_TYPES = {
40
51
  boolean: booleanValueType,
41
52
  string: stringValueType,
@@ -53,6 +64,18 @@ const PLAIN_VALUE_TYPES = {
53
64
  float64: doubleValueType,
54
65
  object: objectValueType,
55
66
  };
67
+ const WHOLE_NUMBER_KINDS = new Set([
68
+ "int8",
69
+ "int16",
70
+ "int32",
71
+ "uint8",
72
+ "uint16",
73
+ "uint32",
74
+ "int64",
75
+ "uint64",
76
+ "enum",
77
+ "flags",
78
+ ]);
56
79
  const PLAIN_VALUE_GETTERS = new Map([
57
80
  [TYPE_BOOLEAN, booleanValueType.get],
58
81
  [TYPE_CHAR, scharValueType.get],
@@ -107,6 +130,15 @@ const boxedValueType = (type) => {
107
130
  const name = getBoxedTypeName(type);
108
131
  return { set: setBoxedBind(name), get: dupBoxedBind(name) };
109
132
  };
133
+ const byteArrayValueGetterFor = (isBytes) => {
134
+ const get = isBytes ? getBytesBoxed : getByteItemsBoxed;
135
+ return (value) => (getBoxedPointer(value) ? get(value) : null);
136
+ };
137
+ const byteArrayValueType = (descriptor) => ({
138
+ set: setByteArrayValue,
139
+ get: byteArrayValueGetterFor(descriptor.isBytes === true),
140
+ });
141
+ const isByteArraySource = (jsValue) => jsValue instanceof Uint8Array || Array.isArray(jsValue);
110
142
  const enumOrFlagsValueType = (type) => typeFundamental(type) === TYPE_FLAGS ? flagsValueType : enumValueType;
111
143
  function unsupportedFundamental(type) {
112
144
  throw new Error(`Unsupported fundamental type '${typeName(type) ?? String(type)}' for value`);
@@ -173,26 +205,57 @@ const newBoxedValue = (descriptor, boxed, resolveSetBind) => {
173
205
  };
174
206
  /**
175
207
  * Duplicates the boxed value held by a GValue and returns the copy wrapped in the
176
- * class registered for its GType, or null when the GValue holds no boxed type.
208
+ * class its GType resolves to, or null when the GValue holds no boxed type.
209
+ * A `GByteArray` payload is copied into a `Uint8Array` instead of being wrapped.
177
210
  */
178
211
  function getBoxedValue(value) {
179
212
  const type = getValueType(value);
180
213
  if (typeFundamental(type) !== TYPE_BOXED) {
181
214
  return null;
182
215
  }
183
- const cls = getWrapperClass(type);
216
+ if (type === getByteArrayType()) {
217
+ return byteArrayValueGetterFor(true)(value);
218
+ }
184
219
  const boxed = dupBoxedBind(getBoxedTypeName(type))(value);
185
- return wrapHandle(boxed, cls);
220
+ if (boxed === null) {
221
+ return null;
222
+ }
223
+ return wrapHandle(boxed, getWrapperClass(type));
186
224
  }
187
- /** Stores a boxed object, or null, into a GValue that holds a boxed type. */
225
+ /**
226
+ * Stores a boxed object, or null, into a GValue that holds a boxed type. A GValue holding
227
+ * `G_TYPE_VALUE` also takes any other {@link JsValue}, which is boxed into a nested `GObject.Value`
228
+ * of the GType inferred from it, and one holding a `GByteArray` also takes the bytes as a
229
+ * `Uint8Array` or an array of byte values.
230
+ * @param value Handle of an initialized value to write into.
231
+ * @param boxed The boxed instance, bytes, or {@link JsValue} to store.
232
+ * @throws {ValueMarshalError} When the value cannot hold what was passed.
233
+ */
188
234
  function setBoxedValue(value, boxed) {
189
- const name = getBoxedTypeName(getValueType(value));
190
- setBoxedBind(name)(value, boxed === null ? null : getHandle(boxed));
235
+ const type = getValueType(value);
236
+ if (type === resolveBoxedType(VALUE_T)) {
237
+ setBoxedBind("GValue")(value, boxed === null ? null : toValueHandle(boxed));
238
+ return;
239
+ }
240
+ if (type === getByteArrayType() && isByteArraySource(boxed)) {
241
+ setByteArrayBoxed(value, boxed);
242
+ return;
243
+ }
244
+ setWrappedBoxedValue(value, type, boxed);
245
+ }
246
+ function setWrappedBoxedValue(value, type, boxed) {
247
+ if (boxed !== null && typeof boxed !== "object") {
248
+ throw new ValueMarshalError(`Cannot marshal ${describeValueKind(boxed)} into a '${getBoxedTypeName(type)}' value`);
249
+ }
250
+ setBoxedBind(getBoxedTypeName(type))(value, boxed === null ? null : getHandle(boxed));
191
251
  }
192
252
  const arrayValueType = (descriptor) => {
193
253
  if (descriptor.itemDescriptor.kind === "string" && descriptor.arrayKind === "array") {
194
254
  return strvValueType;
195
255
  }
256
+ if (descriptor.arrayKind === "gbytearray") {
257
+ return byteArrayValueType(descriptor);
258
+ }
196
259
  throw new Error(`Unsupported array type ${descriptor.arrayKind} of ${descriptor.itemDescriptor.kind}`);
197
260
  };
198
261
  const resolveValueType = (descriptor) => {
@@ -232,10 +295,10 @@ const wrappedValueGetter = (fundamental) => {
232
295
  return (value) => wrapObject(objectValueType.get(value));
233
296
  }
234
297
  case TYPE_PARAM: {
235
- return (value) => wrapHandle(paramValueType.get(value), getWrapperClass(TYPE_PARAM));
298
+ return (value) => wrapFundamentalHandle(paramValueType.get(value), getWrapperClass(TYPE_PARAM));
236
299
  }
237
300
  case TYPE_VARIANT: {
238
- return (value) => wrapHandle(variantValueType.get(value), getWrapperClass(TYPE_VARIANT));
301
+ return (value) => wrapFundamentalHandle(variantValueType.get(value), getWrapperClass(TYPE_VARIANT));
239
302
  }
240
303
  case TYPE_BOXED: {
241
304
  return getBoxedValue;
@@ -259,6 +322,9 @@ function setStringValue(value, nativeValue) {
259
322
  function setStrvValue(value, nativeValue) {
260
323
  setStrvBoxed(value, nativeValue ?? null);
261
324
  }
325
+ function setByteArrayValue(value, nativeValue) {
326
+ setByteArrayBoxed(value, nativeValue ?? null);
327
+ }
262
328
  function setPointerValue(value, nativeValue) {
263
329
  if (nativeValue != null) {
264
330
  throw new Error("G_TYPE_POINTER non-null values cannot be marshalled from JS");
@@ -278,7 +344,7 @@ const customFundamentalGetter = (type) => {
278
344
  if (valueType === undefined) {
279
345
  return undefined;
280
346
  }
281
- return (value) => wrapHandle(valueType.get(value), getWrapperClass(type));
347
+ return (value) => wrapFundamentalHandle(valueType.get(value), getWrapperClass(type));
282
348
  };
283
349
  const customFundamentalSetter = (type) => {
284
350
  const valueType = customFundamentalValueType(type);
@@ -309,12 +375,76 @@ function valueWriterFor(type) {
309
375
  function intoValue(value, jsValue) {
310
376
  valueWriterFor(getValueType(value))(value, jsValue);
311
377
  }
378
+ const numberValueGType = (jsValue) => Number.isSafeInteger(jsValue) && jsValue >= INT32_MINIMUM && jsValue <= INT32_MAXIMUM ? TYPE_INT : TYPE_DOUBLE;
379
+ const arrayValueGType = (jsValue) => (isStringArray(jsValue) ? getStrvType() : TYPE_INVALID);
380
+ const wideValueGType = (jsValue) => (jsValue > INT64_MAXIMUM ? TYPE_UINT64 : TYPE_INT64);
381
+ const bigintValueGType = (jsValue) => jsValue < INT64_MINIMUM || jsValue > UINT64_MAXIMUM ? TYPE_INVALID : wideValueGType(jsValue);
382
+ const objectValueGType = (jsValue, wrapperType) => {
383
+ if (jsValue === null) {
384
+ return TYPE_POINTER;
385
+ }
386
+ return Array.isArray(jsValue) ? arrayValueGType(jsValue) : wrapperType;
387
+ };
388
+ function inferValueGType(jsValue, wrapperType) {
389
+ switch (typeof jsValue) {
390
+ case "string": {
391
+ return TYPE_STRING;
392
+ }
393
+ case "boolean": {
394
+ return TYPE_BOOLEAN;
395
+ }
396
+ case "number": {
397
+ return numberValueGType(jsValue);
398
+ }
399
+ case "bigint": {
400
+ return bigintValueGType(jsValue);
401
+ }
402
+ case "object": {
403
+ return objectValueGType(jsValue, wrapperType);
404
+ }
405
+ case "function":
406
+ case "symbol":
407
+ case "undefined": {
408
+ return TYPE_INVALID;
409
+ }
410
+ }
411
+ }
412
+ const marshalFailure = (jsValue) => typeof jsValue === "bigint"
413
+ ? `Cannot marshal ${String(jsValue)} into a GObject.Value: outside the range of gint64 and guint64`
414
+ : `Cannot marshal ${describeValueKind(jsValue)} into a GObject.Value`;
415
+ const wrapperGType = (jsValue) => typeof jsValue === "object" && jsValue !== null ? resolveGtype(jsValue) : TYPE_INVALID;
416
+ /**
417
+ * Marshals a value passed where a `GObject.Value` is expected into a value handle: an already-built
418
+ * value yields its own handle, and any other {@link JsValue} is stored in a new one initialized to the
419
+ * GType inferred from it.
420
+ * @param jsValue Value to store, or an already-built `GObject.Value`.
421
+ * @throws {ValueMarshalError} When no GType can be inferred from the value.
422
+ */
423
+ function toValueHandle(jsValue) {
424
+ const wrapperType = wrapperGType(jsValue);
425
+ if (typeIsA(wrapperType, resolveBoxedType(VALUE_T))) {
426
+ return getHandle(jsValue);
427
+ }
428
+ const type = inferValueGType(jsValue, wrapperType);
429
+ if (type === TYPE_INVALID) {
430
+ throw new ValueMarshalError(marshalFailure(jsValue));
431
+ }
432
+ const value = newValueForType(type);
433
+ intoValue(value, jsValue);
434
+ return value;
435
+ }
436
+ /** Same as {@link toValueHandle}, but passes a null or undefined value through as no value at all. */
437
+ const tryToValueHandle = (jsValue) => jsValue == null ? undefined : toValueHandle(jsValue);
438
+ const isValueDescriptor = (descriptor) => descriptor.kind === "boxed" && descriptor.typeName === "GValue";
312
439
  const resolveNativeValue = (descriptor, value) => {
313
440
  const isHandleKind = descriptor.kind === "object" || descriptor.kind === "boxed";
314
441
  if (!isHandleKind) {
315
442
  return toNative(descriptor, value);
316
443
  }
317
- return value == null ? null : getHandle(value);
444
+ if (value == null) {
445
+ return null;
446
+ }
447
+ return isValueDescriptor(descriptor) ? toValueHandle(value) : getHandle(value);
318
448
  };
319
449
  const resolveValueGType = (descriptor, nativeValue) => {
320
450
  if (descriptor.kind !== "object") {
@@ -322,13 +452,23 @@ const resolveValueGType = (descriptor, nativeValue) => {
322
452
  }
323
453
  return nativeValue == null ? TYPE_OBJECT : getType(nativeValue);
324
454
  };
455
+ const toWholeNumber = (descriptor, value) => typeof value === "number" && Number.isFinite(value) && WHOLE_NUMBER_KINDS.has(descriptor.kind)
456
+ ? Math.trunc(value)
457
+ : value;
325
458
  function toValue(descriptor, value) {
326
- const nativeValue = resolveNativeValue(descriptor, value);
459
+ const nativeValue = resolveNativeValue(descriptor, toWholeNumber(descriptor, value));
327
460
  const type = resolveValueGType(descriptor, nativeValue);
328
461
  const gValue = newValueForType(type);
329
462
  resolveValueType(descriptor).set(gValue, nativeValue);
330
463
  return gValue;
331
464
  }
465
+ /**
466
+ * Reads what a `GObject.Value` holds as its JavaScript form, wrapping an object, boxed, param, variant,
467
+ * or fundamental payload in the class registered for its GType, and handing back a string, number,
468
+ * `bigint`, boolean, or array of strings for the rest.
469
+ * @param value Handle of an initialized value to read.
470
+ * @throws {Error} When the GType it holds has no JavaScript form, such as a non-null `gpointer`.
471
+ */
332
472
  function fromValue(value) {
333
473
  const type = getValueType(value);
334
474
  const get = resolveValueGetter(type);
@@ -337,6 +477,17 @@ function fromValue(value) {
337
477
  }
338
478
  return get(value);
339
479
  }
480
+ const fromValueForDescriptor = (descriptor, value) => descriptor.kind === "array" && descriptor.arrayKind === "gbytearray"
481
+ ? byteArrayValueGetterFor(descriptor.isBytes === true)(value)
482
+ : fromValue(value);
483
+ const inferredValueGuard = (jsValue) => inferValueGType(jsValue, wrapperGType(jsValue)) !== TYPE_INVALID;
484
+ const byteArrayValueGuard = (jsValue) => jsValue == null || isByteArraySource(jsValue) || typeIsA(resolveGtype(jsValue), getByteArrayType());
485
+ const valueGuardOverrideFor = (valueType) => {
486
+ if (valueType === resolveBoxedType(VALUE_T)) {
487
+ return inferredValueGuard;
488
+ }
489
+ return valueType === getByteArrayType() ? byteArrayValueGuard : undefined;
490
+ };
340
491
  function newValueForDescriptor(descriptor) {
341
492
  return newValueForType(resolveDescriptorType(descriptor));
342
493
  }
@@ -356,5 +507,10 @@ function outValueForBoxedDescriptor(descriptor, boxed) {
356
507
  function inoutValueForBoxedDescriptor(descriptor, boxed) {
357
508
  return newBoxedValue(descriptor, boxed, setStaticBoxedBind);
358
509
  }
359
- export { getValueType, intoValue, copyValue, getBoxedValue, setBoxedValue, toValue, fromValue, newValueForDescriptor, newValueForType, outValueForDescriptor, outValueForBoxedDescriptor, inoutValueForBoxedDescriptor, valueNarrowerFor, valueWriterFor, };
510
+ /** Thrown when a value passed where a `GObject.Value` is expected holds no GType one can be built from. */
511
+ class ValueMarshalError extends TypeError {
512
+ /** Name callers match on when the error is caught as a plain `TypeError`. */
513
+ name = "ValueMarshalError";
514
+ }
515
+ export { getValueType, intoValue, copyValue, getBoxedValue, setBoxedValue, toValue, toValueHandle, tryToValueHandle, ValueMarshalError, fromValue, fromValueForDescriptor, valueGuardOverrideFor, newValueForDescriptor, newValueForType, outValueForDescriptor, outValueForBoxedDescriptor, inoutValueForBoxedDescriptor, valueNarrowerFor, valueWriterFor, };
360
516
  //# sourceMappingURL=value.js.map