@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
@@ -1 +1 @@
1
- {"version":3,"file":"param-spec.js","sourceRoot":"","sources":["../src/param-spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoC,IAAI,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACjF,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EACH,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,SAAS,EACT,WAAW,EACX,SAAS,EACT,UAAU,EACV,UAAU,EACV,UAAU,EACV,QAAQ,EACR,UAAU,EACV,cAAc,EACd,YAAY,EACZ,SAAS,EACT,WAAW,EACX,UAAU,EACV,YAAY,EACZ,WAAW,EACX,UAAU,EACV,SAAS,EACT,WAAW,EACX,UAAU,EACV,YAAY,EACZ,eAAe,EACf,OAAO,GACV,MAAM,WAAW,CAAC;AAKnB,MAAM,cAAc,GAAG,CAAC,CAAC;AACzB,MAAM,cAAc,GAAG,CAAC,CAAC;AACzB,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAC/B,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAChC,MAAM,UAAU,GAAG,cAAc,GAAG,cAAc,GAAG,oBAAoB,GAAG,oBAAoB,CAAC;AACjG,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAC7B,MAAM,sBAAsB,GAAG,EAAE,CAAC;AAClC,MAAM,iBAAiB,GAAG,mBAAmB,CAAC;AAC9C,MAAM,YAAY,GAAG,CAAC,GAAG,CAAC;AAC1B,MAAM,YAAY,GAAG,GAAG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{ type ExternalObject, type Handle, read } from \"@gtkx/native\";\nimport { bind } from \"./bind.js\";\nimport { biguint64T, booleanT, stringT, uint32T, voidT } from \"./descriptors.js\";\nimport { LIB, PARAM_T, VALUE_T } from \"./library.js\";\nimport { getInstanceType } from \"./registry.js\";\nimport {\n getStrvType,\n isTypedClass,\n TYPE_BOOLEAN,\n TYPE_BOXED,\n TYPE_CHAR,\n TYPE_DOUBLE,\n TYPE_ENUM,\n TYPE_FLAGS,\n TYPE_FLOAT,\n TYPE_GTYPE,\n TYPE_INT,\n TYPE_INT64,\n TYPE_INTERFACE,\n TYPE_INVALID,\n TYPE_LONG,\n TYPE_OBJECT,\n TYPE_PARAM,\n TYPE_POINTER,\n TYPE_STRING,\n TYPE_UCHAR,\n TYPE_UINT,\n TYPE_UINT64,\n TYPE_ULONG,\n TYPE_VARIANT,\n typeFundamental,\n typeIsA,\n} from \"./type.js\";\n\ntype ValueGuard = (value: unknown) => boolean;\ntype ParamLayout = { flags: number; valueType: bigint };\n\nconst PARAM_READABLE = 1;\nconst PARAM_WRITABLE = 2;\nconst PARAM_CONSTRUCT_ONLY = 8;\nconst PARAM_LAX_VALIDATION = 16;\nconst READ_FLAGS = PARAM_READABLE | PARAM_WRITABLE | PARAM_CONSTRUCT_ONLY | PARAM_LAX_VALIDATION;\nconst FLAGS_BYTE_OFFSET = 16;\nconst VALUE_TYPE_BYTE_OFFSET = 24;\nconst LAYOUT_PROBE_NAME = \"gtkx-param-layout\";\nconst INT8_MINIMUM = -128;\nconst INT8_MAXIMUM = 127;\nconst UINT8_MAXIMUM = 255;\nconst INT32_MINIMUM = -2_147_483_648;\nconst INT32_MAXIMUM = 2_147_483_647;\nconst UINT32_MAXIMUM = 4_294_967_295;\nconst INT64_MINIMUM = -(2n ** 63n);\nconst INT64_MAXIMUM = 2n ** 63n - 1n;\nconst UINT64_MAXIMUM = 2n ** 64n - 1n;\n\nconst WRAPPED_FUNDAMENTALS: Set<bigint> = new Set([\n TYPE_BOXED,\n TYPE_INTERFACE,\n TYPE_OBJECT,\n TYPE_PARAM,\n TYPE_VARIANT,\n]);\n\nconst isWideUnsignedValue: ValueGuard = wideIntegerGuardFor(0n, UINT64_MAXIMUM);\n\nconst SCALAR_GUARDS: Map<bigint, ValueGuard> = new Map([\n [TYPE_BOOLEAN, isBooleanValue],\n [TYPE_STRING, isStringValue],\n [TYPE_CHAR, integerGuardFor(INT8_MINIMUM, INT8_MAXIMUM)],\n [TYPE_UCHAR, integerGuardFor(0, UINT8_MAXIMUM)],\n [TYPE_INT, integerGuardFor(INT32_MINIMUM, INT32_MAXIMUM)],\n [TYPE_UINT, integerGuardFor(0, UINT32_MAXIMUM)],\n [TYPE_ENUM, integerGuardFor(INT32_MINIMUM, INT32_MAXIMUM)],\n [TYPE_FLAGS, integerGuardFor(0, UINT32_MAXIMUM)],\n [TYPE_LONG, wideIntegerGuardFor(INT64_MINIMUM, INT64_MAXIMUM)],\n [TYPE_ULONG, isWideUnsignedValue],\n [TYPE_INT64, wideIntegerGuardFor(INT64_MINIMUM, INT64_MAXIMUM)],\n [TYPE_UINT64, isWideUnsignedValue],\n [TYPE_FLOAT, isNumberValue],\n [TYPE_DOUBLE, isNumberValue],\n [TYPE_POINTER, isNullValue],\n]);\n\nconst layout = { wasChecked: false };\nconst paramValueValidate = bind(LIB, \"g_param_value_validate\", [PARAM_T, VALUE_T], booleanT);\nconst paramSpecUnref = bind(LIB, \"g_param_spec_unref\", [PARAM_T], voidT);\nconst paramSpecRefSink = bind(LIB, \"g_param_spec_ref_sink\", [PARAM_T], PARAM_T);\n\nconst newParamSpecBoolean = bind(\n LIB,\n \"g_param_spec_boolean\",\n [stringT(\"borrowed\"), stringT(\"borrowed\"), stringT(\"borrowed\"), booleanT, uint32T],\n PARAM_T,\n);\n\nconst getParamFlags = (pspec: ExternalObject<Handle>): number => read(pspec, uint32T, FLAGS_BYTE_OFFSET) as number;\n\nconst getParamValueType = (pspec: ExternalObject<Handle>): bigint =>\n read(pspec, biguint64T, VALUE_TYPE_BYTE_OFFSET) as bigint;\n\nconst isParamWritable = (flags: number): boolean => (flags & PARAM_WRITABLE) !== 0;\nconst isParamConstructOnly = (flags: number): boolean => (flags & PARAM_CONSTRUCT_ONLY) !== 0;\nconst isParamLaxlyValidated = (flags: number): boolean => (flags & PARAM_LAX_VALIDATION) !== 0;\n\nconst wasParamValueModified = (pspec: ExternalObject<Handle>, value: ExternalObject<Handle>): boolean =>\n paramValueValidate(pspec, value) as boolean;\n\nfunction isBooleanValue(value: unknown): boolean {\n return typeof value === \"boolean\";\n}\n\nfunction isStringValue(value: unknown): boolean {\n return value == null || typeof value === \"string\";\n}\n\nfunction isStrvValue(value: unknown): boolean {\n return value == null || (Array.isArray(value) && value.every((item) => typeof item === \"string\"));\n}\n\nfunction isNumberValue(value: unknown): boolean {\n return typeof value === \"number\";\n}\n\nfunction isAnyValue(): boolean {\n return true;\n}\n\nfunction isNullValue(value: unknown): boolean {\n return value == null;\n}\n\nfunction integerGuardFor(minimum: number, maximum: number): ValueGuard {\n return (value) => Number.isSafeInteger(value) && (value as number) >= minimum && (value as number) <= maximum;\n}\n\nfunction toWideInteger(value: unknown): bigint | undefined {\n if (typeof value === \"bigint\") {\n return value;\n }\n\n return Number.isSafeInteger(value) ? BigInt(value as number) : undefined;\n}\n\nfunction wideIntegerGuardFor(minimum: bigint, maximum: bigint): ValueGuard {\n return (value) => {\n const wide = toWideInteger(value);\n\n return wide !== undefined && wide >= minimum && wide <= maximum;\n };\n}\n\nfunction resolveGtype(value: unknown): bigint {\n const instanceType = getInstanceType(value as object);\n\n if (instanceType !== TYPE_INVALID) {\n return instanceType;\n }\n\n return isTypedClass(value) ? value.__type__ : TYPE_INVALID;\n}\n\nfunction wrappedGuardFor(valueType: bigint): ValueGuard {\n return (value) => value == null || typeIsA(resolveGtype(value), valueType);\n}\n\nfunction exactGuardFor(valueType: bigint): ValueGuard | undefined {\n if (valueType === TYPE_GTYPE) {\n return isWideUnsignedValue;\n }\n\n return valueType === getStrvType() ? isStrvValue : undefined;\n}\n\nfunction valueGuardFor(valueType: bigint): ValueGuard {\n assertParamLayout();\n const exact = exactGuardFor(valueType);\n\n if (exact !== undefined) {\n return exact;\n }\n\n const fundamental = typeFundamental(valueType);\n\n if (WRAPPED_FUNDAMENTALS.has(fundamental)) {\n return wrappedGuardFor(valueType);\n }\n\n return SCALAR_GUARDS.get(fundamental) ?? isAnyValue;\n}\n\nfunction readProbeLayout(flags: number): ParamLayout {\n const probe = newParamSpecBoolean(LAYOUT_PROBE_NAME, null, null, false, flags) as ExternalObject<Handle>;\n paramSpecRefSink(probe);\n\n try {\n return { flags: getParamFlags(probe), valueType: getParamValueType(probe) };\n } finally {\n paramSpecUnref(probe);\n }\n}\n\nfunction isLayoutIntact(flags: number): boolean {\n const layout = readProbeLayout(flags);\n\n return (layout.flags & READ_FLAGS) === flags && layout.valueType === TYPE_BOOLEAN;\n}\n\nfunction assertParamLayout(): void {\n if (layout.wasChecked) {\n return;\n }\n\n layout.wasChecked = true;\n const readWrite = PARAM_READABLE | PARAM_WRITABLE;\n\n if (isLayoutIntact(readWrite) && isLayoutIntact(readWrite | PARAM_CONSTRUCT_ONLY | PARAM_LAX_VALIDATION)) {\n return;\n }\n\n throw new Error(\n \"GParamSpec does not match the memory layout this build reads a property's flags and value type at\",\n );\n}\n\nexport {\n getParamFlags,\n getParamValueType,\n isParamConstructOnly,\n isParamLaxlyValidated,\n isParamWritable,\n type ValueGuard,\n valueGuardFor,\n wasParamValueModified,\n};\n"]}
1
+ {"version":3,"file":"param-spec.js","sourceRoot":"","sources":["../src/param-spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoC,IAAI,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACjF,OAAO,EAAE,GAAG,EAAE,OAAO,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I,cAAc,CAAC,SAAS,CAAC,IAAI,cAAc,CAAC,SAAS,GAAG,oBAAoB,GAAG,oBAAoB,CAAC,EAAE,CAAC;QACvG,OAAO;IACX,CAAC;IAED,MAAM,IAAI,KAAK,CACX,mGAAmG,CACtG,CAAC;AACN,CAAC;AAED,OAAO,EACH,mBAAmB,EACnB,aAAa,EACb,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EACrB,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,aAAa,EACb,aAAa,EACb,oBAAoB,EACpB,eAAe,EACf,aAAa,EACb,yBAAyB,EACzB,qBAAqB,EACrB,eAAe,EACf,YAAY,EACZ,cAAc,EAEd,aAAa,EACb,qBAAqB,GACxB,CAAC","sourcesContent":["import { type ExternalObject, type Handle, read } from \"@gtkx/native\";\nimport { bind } from \"./bind.js\";\nimport { biguint64T, booleanT, stringT, uint32T, voidT } from \"./descriptors.js\";\nimport { LIB, PARAM_T, VALUE_T } from \"./library.js\";\nimport { getHandle, getInstanceType } from \"./registry.js\";\nimport {\n getStrvType,\n isTypedClass,\n TYPE_BOOLEAN,\n TYPE_BOXED,\n TYPE_CHAR,\n TYPE_DOUBLE,\n TYPE_ENUM,\n TYPE_FLAGS,\n TYPE_FLOAT,\n TYPE_GTYPE,\n TYPE_INT,\n TYPE_INT64,\n TYPE_INTERFACE,\n TYPE_INVALID,\n TYPE_LONG,\n TYPE_OBJECT,\n TYPE_PARAM,\n TYPE_POINTER,\n TYPE_STRING,\n TYPE_UCHAR,\n TYPE_UINT,\n TYPE_UINT64,\n TYPE_ULONG,\n TYPE_VARIANT,\n typeFundamental,\n typeIsA,\n} from \"./type.js\";\n\ntype ValueGuard = (value: unknown) => boolean;\ntype ParamLayout = { flags: number; valueType: bigint; ownerType: bigint };\n\nconst PARAM_READABLE = 1;\nconst PARAM_WRITABLE = 2;\nconst PARAM_CONSTRUCT_ONLY = 8;\nconst PARAM_LAX_VALIDATION = 16;\nconst PARAM_EXPLICIT_NOTIFY = 1 << 30;\nconst READ_FLAGS = PARAM_READABLE | PARAM_WRITABLE | PARAM_CONSTRUCT_ONLY | PARAM_LAX_VALIDATION;\nconst FLAGS_BYTE_OFFSET = 16;\nconst VALUE_TYPE_BYTE_OFFSET = 24;\nconst OWNER_TYPE_BYTE_OFFSET = 32;\nconst LAYOUT_PROBE_NAME = \"gtkx-param-layout\";\nconst INT8_MINIMUM = -128;\nconst INT8_MAXIMUM = 127;\nconst UINT8_MAXIMUM = 255;\nconst INT32_MINIMUM = -2_147_483_648;\nconst INT32_MAXIMUM = 2_147_483_647;\nconst UINT32_MAXIMUM = 4_294_967_295;\nconst INT64_MINIMUM: bigint = -(2n ** 63n);\nconst INT64_MAXIMUM: bigint = 2n ** 63n - 1n;\nconst UINT64_MAXIMUM: bigint = 2n ** 64n - 1n;\n\nconst WRAPPED_FUNDAMENTALS: Set<bigint> = new Set([\n TYPE_BOXED,\n TYPE_INTERFACE,\n TYPE_OBJECT,\n TYPE_PARAM,\n TYPE_VARIANT,\n]);\n\nconst isWideUnsignedValue: ValueGuard = wideIntegerGuardFor(0n, UINT64_MAXIMUM);\nconst MAX_SAFE: number = Number.MAX_SAFE_INTEGER;\n\nconst WHOLE_NUMBER_RANGES: Map<bigint, [minimum: number, maximum: number]> = new Map([\n [TYPE_CHAR, [INT8_MINIMUM, INT8_MAXIMUM]],\n [TYPE_UCHAR, [0, UINT8_MAXIMUM]],\n [TYPE_INT, [INT32_MINIMUM, INT32_MAXIMUM]],\n [TYPE_UINT, [0, UINT32_MAXIMUM]],\n [TYPE_ENUM, [INT32_MINIMUM, INT32_MAXIMUM]],\n [TYPE_FLAGS, [0, UINT32_MAXIMUM]],\n [TYPE_LONG, [-MAX_SAFE, MAX_SAFE]],\n [TYPE_ULONG, [0, MAX_SAFE]],\n [TYPE_INT64, [-MAX_SAFE, MAX_SAFE]],\n [TYPE_UINT64, [0, MAX_SAFE]],\n]);\n\nconst SCALAR_GUARDS: Map<bigint, ValueGuard> = new Map([\n [TYPE_BOOLEAN, isBooleanValue],\n [TYPE_STRING, isStringValue],\n [TYPE_CHAR, integerGuardFor(INT8_MINIMUM, INT8_MAXIMUM)],\n [TYPE_UCHAR, integerGuardFor(0, UINT8_MAXIMUM)],\n [TYPE_INT, integerGuardFor(INT32_MINIMUM, INT32_MAXIMUM)],\n [TYPE_UINT, integerGuardFor(0, UINT32_MAXIMUM)],\n [TYPE_ENUM, integerGuardFor(INT32_MINIMUM, INT32_MAXIMUM)],\n [TYPE_FLAGS, integerGuardFor(0, UINT32_MAXIMUM)],\n [TYPE_LONG, wideIntegerGuardFor(INT64_MINIMUM, INT64_MAXIMUM)],\n [TYPE_ULONG, isWideUnsignedValue],\n [TYPE_INT64, wideIntegerGuardFor(INT64_MINIMUM, INT64_MAXIMUM)],\n [TYPE_UINT64, isWideUnsignedValue],\n [TYPE_FLOAT, isNumberValue],\n [TYPE_DOUBLE, isNumberValue],\n [TYPE_POINTER, isNullValue],\n]);\n\nconst layout = { wasChecked: false };\nconst paramValueValidate = bind(LIB, \"g_param_value_validate\", [PARAM_T, VALUE_T], booleanT);\nconst paramSpecUnref = bind(LIB, \"g_param_spec_unref\", [PARAM_T], voidT);\nconst paramSpecRefSink = bind(LIB, \"g_param_spec_ref_sink\", [PARAM_T], PARAM_T);\n\nconst newParamSpecBoolean = bind(\n LIB,\n \"g_param_spec_boolean\",\n [stringT(\"borrowed\"), stringT(\"borrowed\"), stringT(\"borrowed\"), booleanT, uint32T],\n PARAM_T,\n);\n\nconst getParamFlags = (pspec: ExternalObject<Handle>): number => read(pspec, uint32T, FLAGS_BYTE_OFFSET) as number;\n\nconst getParamValueType = (pspec: ExternalObject<Handle>): bigint =>\n read(pspec, biguint64T, VALUE_TYPE_BYTE_OFFSET) as bigint;\n\nconst getParamOwnerType = (pspec: ExternalObject<Handle>): bigint =>\n read(pspec, biguint64T, OWNER_TYPE_BYTE_OFFSET) as bigint;\n\n/**\n * Reads the `GParamFlags` bitfield of a `GObject.ParamSpec`.\n *\n * @param spec The param spec wrapper to read.\n * @returns The spec's flags.\n */\nconst getParamSpecFlags = (spec: object): number => {\n assertParamLayout();\n\n return getParamFlags(getHandle(spec));\n};\n\n/**\n * Reads the GType of the values a `GObject.ParamSpec` describes.\n *\n * @param spec The param spec wrapper to read.\n * @returns The GType of the spec's values.\n */\nconst getParamSpecValueType = (spec: object): bigint => {\n assertParamLayout();\n\n return getParamValueType(getHandle(spec));\n};\n\n/**\n * Reads the GType a `GObject.ParamSpec` is installed on.\n *\n * @param spec The param spec wrapper to read.\n * @returns The owning GType, or `TYPE_INVALID` while the spec is not installed on any type.\n */\nconst getParamSpecOwnerType = (spec: object): bigint => {\n assertParamLayout();\n\n return getParamOwnerType(getHandle(spec));\n};\n\nconst isParamWritable = (flags: number): boolean => (flags & PARAM_WRITABLE) !== 0;\nconst isParamReadable = (flags: number): boolean => (flags & PARAM_READABLE) !== 0;\nconst isParamConstructOnly = (flags: number): boolean => (flags & PARAM_CONSTRUCT_ONLY) !== 0;\nconst isParamLaxlyValidated = (flags: number): boolean => (flags & PARAM_LAX_VALIDATION) !== 0;\nconst isParamExplicitlyNotified = (flags: number): boolean => (flags & PARAM_EXPLICIT_NOTIFY) !== 0;\n\nconst wasParamValueModified = (pspec: ExternalObject<Handle>, value: ExternalObject<Handle>): boolean =>\n paramValueValidate(pspec, value) as boolean;\n\nfunction isBooleanValue(value: unknown): boolean {\n return typeof value === \"boolean\";\n}\n\nfunction isStringValue(value: unknown): boolean {\n return value == null || typeof value === \"string\";\n}\n\nfunction isStringArray(value: unknown[]): boolean {\n for (const item of value) {\n if (typeof item !== \"string\") {\n return false;\n }\n }\n\n return true;\n}\n\nfunction isStrvValue(value: unknown): boolean {\n return value == null || (Array.isArray(value) && isStringArray(value));\n}\n\nfunction isNumberValue(value: unknown): boolean {\n return typeof value === \"number\";\n}\n\nfunction isAnyValue(): boolean {\n return true;\n}\n\nfunction isNullValue(value: unknown): boolean {\n return value == null;\n}\n\nfunction integerGuardFor(minimum: number, maximum: number): ValueGuard {\n return (value) => Number.isSafeInteger(value) && (value as number) >= minimum && (value as number) <= maximum;\n}\n\nfunction toWideInteger(value: unknown): bigint | undefined {\n if (typeof value === \"bigint\") {\n return value;\n }\n\n return Number.isSafeInteger(value) ? BigInt(value as number) : undefined;\n}\n\nfunction wideIntegerGuardFor(minimum: bigint, maximum: bigint): ValueGuard {\n return (value) => {\n const wide = toWideInteger(value);\n\n return wide !== undefined && wide >= minimum && wide <= maximum;\n };\n}\n\nfunction resolveGtype(value: unknown): bigint {\n const instanceType = getInstanceType(value as object);\n\n if (instanceType !== TYPE_INVALID) {\n return instanceType;\n }\n\n return isTypedClass(value) ? value.__type__ : TYPE_INVALID;\n}\n\nfunction wrappedGuardFor(valueType: bigint): ValueGuard {\n return (value) => value == null || typeIsA(resolveGtype(value), valueType);\n}\n\nfunction exactGuardFor(valueType: bigint): ValueGuard | undefined {\n if (valueType === TYPE_GTYPE) {\n return isWideUnsignedValue;\n }\n\n return valueType === getStrvType() ? isStrvValue : undefined;\n}\n\nfunction valueGuardFor(valueType: bigint): ValueGuard {\n assertParamLayout();\n const exact = exactGuardFor(valueType);\n\n if (exact !== undefined) {\n return exact;\n }\n\n const fundamental = typeFundamental(valueType);\n\n if (WRAPPED_FUNDAMENTALS.has(fundamental)) {\n return wrappedGuardFor(valueType);\n }\n\n return SCALAR_GUARDS.get(fundamental) ?? isAnyValue;\n}\n\nfunction readProbeLayout(flags: number): ParamLayout {\n const probe = newParamSpecBoolean(LAYOUT_PROBE_NAME, null, null, false, flags) as ExternalObject<Handle>;\n paramSpecRefSink(probe);\n\n try {\n return {\n flags: getParamFlags(probe),\n valueType: getParamValueType(probe),\n ownerType: getParamOwnerType(probe),\n };\n } finally {\n paramSpecUnref(probe);\n }\n}\n\nfunction isLayoutIntact(flags: number): boolean {\n const layout = readProbeLayout(flags);\n\n return (\n (layout.flags & READ_FLAGS) === flags &&\n layout.valueType === TYPE_BOOLEAN &&\n layout.ownerType === TYPE_INVALID\n );\n}\n\nfunction assertParamLayout(): void {\n if (layout.wasChecked) {\n return;\n }\n\n layout.wasChecked = true;\n const readWrite = PARAM_READABLE | PARAM_WRITABLE;\n\n if (isLayoutIntact(readWrite) && isLayoutIntact(readWrite | PARAM_CONSTRUCT_ONLY | PARAM_LAX_VALIDATION)) {\n return;\n }\n\n throw new Error(\n \"GParamSpec does not match the memory layout this build reads a property's flags and value type at\",\n );\n}\n\nexport {\n WHOLE_NUMBER_RANGES,\n getParamFlags,\n getParamSpecFlags,\n getParamSpecOwnerType,\n getParamSpecValueType,\n getParamValueType,\n INT32_MAXIMUM,\n INT32_MINIMUM,\n INT64_MAXIMUM,\n INT64_MINIMUM,\n isParamConstructOnly,\n isParamReadable,\n isStringArray,\n isParamExplicitlyNotified,\n isParamLaxlyValidated,\n isParamWritable,\n resolveGtype,\n UINT64_MAXIMUM,\n type ValueGuard,\n valueGuardFor,\n wasParamValueModified,\n};\n"]}
@@ -3,6 +3,18 @@
3
3
  * the operation failed.
4
4
  */
5
5
  type FinishResult<R extends object, T> = (result: R) => T;
6
+ /** A finish result with its leading success boolean dropped: bare when one value remains, a tuple otherwise. */
7
+ type TrimmedFinish<T> = T extends readonly [boolean, infer Only] ? Only : T extends readonly [boolean, ...infer Rest] ? Rest : never;
8
+ /**
9
+ * Wraps a finish function whose result leads with the success boolean of a throwing C call,
10
+ * dropping that boolean: failure already surfaces as a thrown error, so the boolean is always
11
+ * `true`. A single remaining value is handed back bare, several stay a tuple. The finish result
12
+ * must carry at least one value beyond the boolean; a boolean-only finish needs no trimming.
13
+ *
14
+ * @param finish Extracts the boolean-led result from the async result passed to the completion callback.
15
+ * @returns A finish function resolving to the result without its leading boolean.
16
+ */
17
+ declare const trimFinish: <R extends object, T extends readonly [boolean, unknown, ...unknown[]]>(finish: FinishResult<R, T>) => FinishResult<R, TrimmedFinish<T>>;
6
18
  /**
7
19
  * Wraps a GIO-style asynchronous function that takes a completion callback into a
8
20
  * promise, invoking the finish function to extract the result. Outside production,
@@ -15,5 +27,5 @@ type FinishResult<R extends object, T> = (result: R) => T;
15
27
  * @returns A promise resolving to the finished result, or rejecting if `finish` throws.
16
28
  */
17
29
  declare const promisify: <R extends object, T>(asyncFn: (...args: unknown[]) => void, finish: FinishResult<R, T>, cancellable: object | null | undefined, ...leading: unknown[]) => Promise<T>;
18
- export { promisify };
30
+ export { promisify, trimFinish };
19
31
  //# sourceMappingURL=promisify.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"promisify.d.ts","sourceRoot":"","sources":["../src/promisify.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,KAAK,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC;AAgC1D;;;;;;;;;;GAUG;AACH,QAAA,MAAM,SAAS,GAAI,CAAC,SAAS,MAAM,EAAE,CAAC,EAClC,SAAS,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,EACrC,QAAQ,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,EAC1B,aAAa,MAAM,GAAG,IAAI,GAAG,SAAS,EACtC,GAAG,SAAS,OAAO,EAAE,KACtB,OAAO,CAAC,CAAC,CAUN,CAAC;AAEP,OAAO,EAAE,SAAS,EAAE,CAAC"}
1
+ {"version":3,"file":"promisify.d.ts","sourceRoot":"","sources":["../src/promisify.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,KAAK,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC;AAS1D,gHAAgH;AAChH,KAAK,aAAa,CAAC,CAAC,IAAI,CAAC,SAAS,SAAS,CAAC,OAAO,EAAE,MAAM,IAAI,CAAC,GAC1D,IAAI,GACJ,CAAC,SAAS,SAAS,CAAC,OAAO,EAAE,GAAG,MAAM,IAAI,CAAC,GACvC,IAAI,GACJ,KAAK,CAAC;AAyBhB;;;;;;;;GAQG;AACH,QAAA,MAAM,UAAU,GACX,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC,EAClE,QAAQ,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,KAC3B,YAAY,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,CAK9B,CAAC;AAEV;;;;;;;;;;GAUG;AACH,QAAA,MAAM,SAAS,GAAI,CAAC,SAAS,MAAM,EAAE,CAAC,EAClC,SAAS,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,EACrC,QAAQ,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,EAC1B,aAAa,MAAM,GAAG,IAAI,GAAG,SAAS,EACtC,GAAG,SAAS,OAAO,EAAE,KACtB,OAAO,CAAC,CAAC,CAUN,CAAC;AAEP,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC"}
package/dist/promisify.js CHANGED
@@ -18,6 +18,19 @@ const settle = (settlement, asyncResult) => {
18
18
  reject(error instanceof Error ? error : new Error(String(error)));
19
19
  }
20
20
  };
21
+ /**
22
+ * Wraps a finish function whose result leads with the success boolean of a throwing C call,
23
+ * dropping that boolean: failure already surfaces as a thrown error, so the boolean is always
24
+ * `true`. A single remaining value is handed back bare, several stay a tuple. The finish result
25
+ * must carry at least one value beyond the boolean; a boolean-only finish needs no trimming.
26
+ *
27
+ * @param finish Extracts the boolean-led result from the async result passed to the completion callback.
28
+ * @returns A finish function resolving to the result without its leading boolean.
29
+ */
30
+ const trimFinish = (finish) => (result) => {
31
+ const [, ...rest] = finish(result);
32
+ return (rest.length === 1 ? rest[0] : rest);
33
+ };
21
34
  /**
22
35
  * Wraps a GIO-style asynchronous function that takes a completion callback into a
23
36
  * promise, invoking the finish function to extract the result. Outside production,
@@ -36,5 +49,5 @@ const promisify = (asyncFn, finish, cancellable, ...leading) => new Promise((res
36
49
  settle({ finish, creationStack, resolve, reject }, asyncResult);
37
50
  });
38
51
  });
39
- export { promisify };
52
+ export { promisify, trimFinish };
40
53
  //# sourceMappingURL=promisify.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"promisify.js","sourceRoot":"","sources":["../src/promisify.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAe1C,MAAM,mBAAmB,GAAG,CAAC,KAAc,EAAE,aAAgC,EAAQ,EAAE;IACnF,IAAI,aAAa,KAAK,SAAS,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC,EAAE,CAAC;QAC3D,OAAO;IACX,CAAC;IAED,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3D,OAAO;IACX,CAAC;IAED,KAAK,CAAC,KAAK,GAAG,aAAa,CAAC;AAChC,CAAC,CAAC;AAEF,MAAM,MAAM,GAAG,CAAsB,UAA4B,EAAE,WAAmB,EAAQ,EAAE;IAC5F,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC;IAE9D,IAAI,CAAC;QACD,OAAO,CAAC,MAAM,CAAC,WAAgB,CAAC,CAAC,CAAC;IACtC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,mBAAmB,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;QAC1C,MAAM,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACtE,CAAC;AACL,CAAC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,SAAS,GAAG,CACd,OAAqC,EACrC,MAA0B,EAC1B,WAAsC,EACtC,GAAG,OAAkB,EACX,EAAE,CACZ,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;IAC/B,MAAM,aAAa,GACf,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IAEvG,MAAM,iBAAiB,GAAG,WAAW,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAE9E,OAAO,CAAC,GAAG,OAAO,EAAE,iBAAiB,EAAE,CAAC,OAAsB,EAAE,WAAmB,EAAE,EAAE;QACnF,MAAM,CAAC,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,WAAW,CAAC,CAAC;IACpE,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC;AAEP,OAAO,EAAE,SAAS,EAAE,CAAC","sourcesContent":["import { getHandle } from \"./registry.js\";\n\n/**\n * Extracts the value of a completed asynchronous operation from its `GAsyncResult`, throwing when\n * the operation failed.\n */\ntype FinishResult<R extends object, T> = (result: R) => T;\n\ntype Settlement<R extends object, T> = {\n finish: FinishResult<R, T>;\n creationStack: Error | undefined;\n resolve: (value: T) => void;\n reject: (reason: Error) => void;\n};\n\nconst attachCreationStack = (error: unknown, creationStack: Error | undefined): void => {\n if (creationStack === undefined || !(error instanceof Error)) {\n return;\n }\n\n if (error.cause !== undefined || !Object.isExtensible(error)) {\n return;\n }\n\n error.cause = creationStack;\n};\n\nconst settle = <R extends object, T>(settlement: Settlement<R, T>, asyncResult: object): void => {\n const { finish, creationStack, resolve, reject } = settlement;\n\n try {\n resolve(finish(asyncResult as R));\n } catch (error) {\n attachCreationStack(error, creationStack);\n reject(error instanceof Error ? error : new Error(String(error)));\n }\n};\n\n/**\n * Wraps a GIO-style asynchronous function that takes a completion callback into a\n * promise, invoking the finish function to extract the result. Outside production,\n * the call site's stack is captured and attached as the rejection error's cause.\n *\n * @param asyncFn The async function, called with the leading arguments, the cancellable, and a completion callback.\n * @param finish Extracts the result from the async result passed to the completion callback.\n * @param cancellable A cancellable object, or null/undefined for none.\n * @param leading Arguments passed to `asyncFn` before the cancellable and callback.\n * @returns A promise resolving to the finished result, or rejecting if `finish` throws.\n */\nconst promisify = <R extends object, T>(\n asyncFn: (...args: unknown[]) => void,\n finish: FinishResult<R, T>,\n cancellable: object | null | undefined,\n ...leading: unknown[]\n): Promise<T> =>\n new Promise<T>((resolve, reject) => {\n const creationStack =\n process.env.NODE_ENV === \"production\" ? undefined : new Error(\"GTKX async operation started here\");\n\n const cancellableHandle = cancellable == null ? null : getHandle(cancellable);\n\n asyncFn(...leading, cancellableHandle, (_source: object | null, asyncResult: object) => {\n settle({ finish, creationStack, resolve, reject }, asyncResult);\n });\n });\n\nexport { promisify };\n"]}
1
+ {"version":3,"file":"promisify.js","sourceRoot":"","sources":["../src/promisify.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAsB1C,MAAM,mBAAmB,GAAG,CAAC,KAAc,EAAE,aAAgC,EAAQ,EAAE;IACnF,IAAI,aAAa,KAAK,SAAS,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC,EAAE,CAAC;QAC3D,OAAO;IACX,CAAC;IAED,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3D,OAAO;IACX,CAAC;IAED,KAAK,CAAC,KAAK,GAAG,aAAa,CAAC;AAChC,CAAC,CAAC;AAEF,MAAM,MAAM,GAAG,CAAsB,UAA4B,EAAE,WAAmB,EAAQ,EAAE;IAC5F,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC;IAE9D,IAAI,CAAC;QACD,OAAO,CAAC,MAAM,CAAC,WAAgB,CAAC,CAAC,CAAC;IACtC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,mBAAmB,CAAC,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,EAAE,CAAC","sourcesContent":["import { getHandle } from \"./registry.js\";\n\n/**\n * Extracts the value of a completed asynchronous operation from its `GAsyncResult`, throwing when\n * the operation failed.\n */\ntype FinishResult<R extends object, T> = (result: R) => T;\n\ntype Settlement<R extends object, T> = {\n finish: FinishResult<R, T>;\n creationStack: Error | undefined;\n resolve: (value: T) => void;\n reject: (reason: Error) => void;\n};\n\n/** A finish result with its leading success boolean dropped: bare when one value remains, a tuple otherwise. */\ntype TrimmedFinish<T> = T extends readonly [boolean, infer Only]\n ? Only\n : T extends readonly [boolean, ...infer Rest]\n ? Rest\n : never;\n\nconst attachCreationStack = (error: unknown, creationStack: Error | undefined): void => {\n if (creationStack === undefined || !(error instanceof Error)) {\n return;\n }\n\n if (error.cause !== undefined || !Object.isExtensible(error)) {\n return;\n }\n\n error.cause = creationStack;\n};\n\nconst settle = <R extends object, T>(settlement: Settlement<R, T>, asyncResult: object): void => {\n const { finish, creationStack, resolve, reject } = settlement;\n\n try {\n resolve(finish(asyncResult as R));\n } catch (error) {\n attachCreationStack(error, creationStack);\n reject(error instanceof Error ? error : new Error(String(error)));\n }\n};\n\n/**\n * Wraps a finish function whose result leads with the success boolean of a throwing C call,\n * dropping that boolean: failure already surfaces as a thrown error, so the boolean is always\n * `true`. A single remaining value is handed back bare, several stay a tuple. The finish result\n * must carry at least one value beyond the boolean; a boolean-only finish needs no trimming.\n *\n * @param finish Extracts the boolean-led result from the async result passed to the completion callback.\n * @returns A finish function resolving to the result without its leading boolean.\n */\nconst trimFinish =\n <R extends object, T extends readonly [boolean, unknown, ...unknown[]]>(\n finish: FinishResult<R, T>,\n ): FinishResult<R, TrimmedFinish<T>> =>\n (result: R): TrimmedFinish<T> => {\n const [, ...rest] = finish(result);\n\n return (rest.length === 1 ? rest[0] : rest) as TrimmedFinish<T>;\n };\n\n/**\n * Wraps a GIO-style asynchronous function that takes a completion callback into a\n * promise, invoking the finish function to extract the result. Outside production,\n * the call site's stack is captured and attached as the rejection error's cause.\n *\n * @param asyncFn The async function, called with the leading arguments, the cancellable, and a completion callback.\n * @param finish Extracts the result from the async result passed to the completion callback.\n * @param cancellable A cancellable object, or null/undefined for none.\n * @param leading Arguments passed to `asyncFn` before the cancellable and callback.\n * @returns A promise resolving to the finished result, or rejecting if `finish` throws.\n */\nconst promisify = <R extends object, T>(\n asyncFn: (...args: unknown[]) => void,\n finish: FinishResult<R, T>,\n cancellable: object | null | undefined,\n ...leading: unknown[]\n): Promise<T> =>\n new Promise<T>((resolve, reject) => {\n const creationStack =\n process.env.NODE_ENV === \"production\" ? undefined : new Error(\"GTKX async operation started here\");\n\n const cancellableHandle = cancellable == null ? null : getHandle(cancellable);\n\n asyncFn(...leading, cancellableHandle, (_source: object | null, asyncResult: object) => {\n settle({ finish, creationStack, resolve, reject }, asyncResult);\n });\n });\n\nexport { promisify, trimFinish };\n"]}
@@ -14,13 +14,19 @@ type PropertyCheck = {
14
14
  write?: ValueWriter;
15
15
  scratch?: ExternalObject<Handle>;
16
16
  };
17
- type PropertyAccessor = PropertyCheck & {
18
- memberName: string;
17
+ type AccessorBase = PropertyCheck & {
19
18
  storage: symbol;
20
- hasGeneratedMember: boolean;
21
- isInterfaceProperty?: boolean;
22
19
  delegate?: InterfaceProperty;
23
20
  };
21
+ type DeclaredAccessor = AccessorBase & {
22
+ isInterfaceProperty?: false;
23
+ memberName: string;
24
+ hasGeneratedMember: boolean;
25
+ };
26
+ type InterfaceAccessor = AccessorBase & {
27
+ isInterfaceProperty: true;
28
+ };
29
+ type PropertyAccessor = DeclaredAccessor | InterfaceAccessor;
24
30
  /** A `GObject.ParamSpec` wrapper describing one property's name, type, flags and default. */
25
31
  type PropertySpec = object;
26
32
  type PropertyDispatch = {
@@ -38,10 +44,47 @@ type ConstructProperty = {
38
44
  };
39
45
  declare const GET_PROPERTY_VFUNC = "vfuncGetProperty";
40
46
  declare const SET_PROPERTY_VFUNC = "vfuncSetProperty";
47
+ /**
48
+ * Creates the handle of a `GParamSpec` that redirects to the property `source` declares under
49
+ * `name` — the equivalent of `g_param_spec_override`, which introspection does not expose.
50
+ *
51
+ * Throws when `source` is neither a GType nor a registered class or interface, and when it
52
+ * declares no property under `name`.
53
+ *
54
+ * @param name Canonical name of the property to override.
55
+ * @param source The GType, wrapper class or interface declaring the property.
56
+ * @returns Handle of the override spec.
57
+ */
58
+ declare const newParamSpecOverride: (name: string, source: bigint | AnyClass) => ExternalObject<Handle>;
59
+ /**
60
+ * Whether the type declares a readable GObject property under `propertyName`, asking GObject itself
61
+ * rather than looking for a generated accessor, which codegen omits when a method shares the name.
62
+ */
63
+ declare function isReadableProperty(gtype: bigint, propertyName: string): boolean;
64
+ declare function coercePropertyValue(gtype: bigint, propertyName: string, value: unknown): unknown;
65
+ /**
66
+ * Fits a number to what a GObject property accepts, the way an animation writing a value on every
67
+ * frame needs: a fractional number headed for a property that holds whole numbers, such as a
68
+ * `gint`, an enum, or flags, is truncated toward zero, and a number outside the range the
69
+ * property's `GObject.ParamSpec` allows is clamped to it, so the write that follows never trips
70
+ * GObject's range check. Anything that is not a finite number, a number the property cannot hold
71
+ * at all, and a name the object installs no property under come back unchanged.
72
+ *
73
+ * @param obj The object the value is about to be written to.
74
+ * @param propertyName The property name, dashed or camelCased.
75
+ * @param value The value about to be written.
76
+ * @returns The value as the property accepts it.
77
+ */
78
+ declare function coerceObjectProperty(obj: object, propertyName: string, value: unknown): unknown;
41
79
  declare function constructPropertyFor(gtype: bigint, name: string, value: unknown, wrapper: object): ConstructProperty | undefined;
42
80
  declare function makeGetProperty(dispatch: PropertyDispatch): (this: object, propertyId: number, value: object, pspec: PropertySpec) => void;
43
81
  declare function makeSetProperty(dispatch: PropertyDispatch): (this: object, propertyId: number, value: object, pspec: PropertySpec) => void;
44
82
  declare function buildPropertyDispatch(source: PropertyDispatchSource): PropertyDispatch;
83
+ /**
84
+ * The GObject name a class registered with `registerClass` installed an accessor under, or
85
+ * `undefined` when the accessor names no property the class declared itself.
86
+ */
87
+ declare function getDeclaredPropertyName(object: object, accessor: string): string | undefined;
45
88
  declare function toNativeProperties(properties: Record<string, PropertySpec>): RegisterClassProperty[];
46
- export { buildPropertyDispatch, constructPropertyFor, GET_PROPERTY_VFUNC, makeGetProperty, makeSetProperty, SET_PROPERTY_VFUNC, toNativeProperties, type ConstructProperty, type PropertyDispatch, type PropertySpec, };
89
+ export { buildPropertyDispatch, coerceObjectProperty, getDeclaredPropertyName, isReadableProperty, coercePropertyValue, constructPropertyFor, GET_PROPERTY_VFUNC, makeGetProperty, makeSetProperty, newParamSpecOverride, SET_PROPERTY_VFUNC, toNativeProperties, type ConstructProperty, type PropertyDispatch, type PropertySpec, };
47
90
  //# sourceMappingURL=properties.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"properties.d.ts","sourceRoot":"","sources":["../src/properties.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAClF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAK5C,OAAO,EAMH,KAAK,UAAU,EAGlB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAwD,KAAK,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAE7G,OAAO,EAGH,KAAK,aAAa,EAElB,KAAK,WAAW,EAEnB,MAAM,YAAY,CAAC;AAEpB,KAAK,aAAa,GAAG;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,UAAU,CAAC;IACzB,WAAW,EAAE,aAAa,CAAC;IAC3B,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,OAAO,CAAC,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC;CACpC,CAAC;AAEF,KAAK,gBAAgB,GAAG,aAAa,GAAG;IAC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AE,KAAK,EAAE,OAAO,GAAG,OAAO,CAQxF;AAED,iBAAS,oBAAoB,CACzB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,MAAM,GAChB,iBAAiB,GAAG,SAAS,CAU/B;AA0ND,iBAAS,eAAe,CAAC,QAAQ,EAAE,gBAAgB,IACnB,MAAM,MAAM,EAAE,YAAY,MAAM,EAAE,OAAO,MAAM,EAAE,OAAO,YAAY,KAAG,IAAI,CAM1G;AAED,iBAAS,eAAe,CAAC,QAAQ,EAAE,gBAAgB,IACnB,MAAM,MAAM,EAAE,YAAY,MAAM,EAAE,OAAO,MAAM,EAAE,OAAO,YAAY,KAAG,IAAI,CAI1G;AA0ED,iBAAS,qBAAqB,CAAC,MAAM,EAAE,sBAAsB,GAAG,gBAAgB,CAK/E;AAED;;;GAGG;AACH,iBAAS,uBAAuB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAMrF;AAED,iBAAS,kBAAkB,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,qBAAqB,EAAE,CAK7F;AAED,OAAO,EACH,qBAAqB,EACrB,oBAAoB,EACpB,uBAAuB,EACvB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,EAClB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,YAAY,GACpB,CAAC"}
@@ -1,23 +1,35 @@
1
- import { camelCase, kebabCase } from "@gtkx/utils";
1
+ import { camelCase, kebabCase, toCamelIdentifier } from "@gtkx/utils";
2
2
  import { bind } from "./bind.js";
3
- import { biguint64T, stringT, structT, voidT } from "./descriptors.js";
3
+ import { biguint64T, fundamentalT, refT, sizedArrayT, stringT, structT, uint32T, voidT } from "./descriptors.js";
4
4
  import { LIB, PARAM_T, VALUE_T } from "./library.js";
5
- import { getParamFlags, getParamValueType, isParamConstructOnly, isParamLaxlyValidated, isParamWritable, valueGuardFor, wasParamValueModified, } from "./param-spec.js";
6
- import { getHandle, getInterfaceProperties, instanceClassName } from "./registry.js";
7
- import { typeName } from "./type.js";
8
- import { fromValue, newValueForType, valueNarrowerFor, valueWriterFor, } from "./value.js";
5
+ import { getParamFlags, getParamValueType, isParamConstructOnly, isParamExplicitlyNotified, isParamLaxlyValidated, isParamReadable, isParamWritable, valueGuardFor, wasParamValueModified, WHOLE_NUMBER_RANGES, } from "./param-spec.js";
6
+ import { getClassType, getHandle, getInstanceType, getInterfaceProperties, instanceClassName, } from "./registry.js";
7
+ import { TYPE_INTERFACE, TYPE_INVALID, TYPE_OBJECT, typeFundamental, typeIsA, typeName } from "./type.js";
8
+ import { fromValue, newValueForType, valueGuardOverrideFor, valueNarrowerFor, valueWriterFor, } from "./value.js";
9
9
  const FIRST_PROPERTY_ID = 1;
10
10
  const GET_PROPERTY_VFUNC = "vfuncGetProperty";
11
11
  const SET_PROPERTY_VFUNC = "vfuncSetProperty";
12
12
  const READ_ONLY_REASON = "the property is read-only";
13
13
  const CONSTRUCT_ONLY_REASON = "the property can only be set when the object is constructed";
14
14
  const CLASS_T = structT("borrowed");
15
+ const CANONICAL_NAME_PATTERN = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
16
+ const DECLARED_NAMES = Symbol("gtkx:declaredPropertyNames");
17
+ const OVERRIDE_PARAM_T = fundamentalT(LIB, "g_param_spec_ref_sink", "g_param_spec_unref", {
18
+ ownership: "borrowed",
19
+ typeName: "GParam",
20
+ });
15
21
  const interfaceStorages = new Map();
16
22
  const paramSpecDefaultValue = bind(LIB, "g_param_spec_get_default_value", [PARAM_T], VALUE_T);
17
23
  const paramSpecName = bind(LIB, "g_param_spec_get_name", [PARAM_T], stringT("borrowed"));
18
24
  const typeClassRef = bind(LIB, "g_type_class_ref", [biguint64T], CLASS_T);
19
25
  const typeClassUnref = bind(LIB, "g_type_class_unref", [CLASS_T], voidT);
26
+ const coercionChecks = new Map();
20
27
  const classFindProperty = bind(LIB, "g_object_class_find_property", [CLASS_T, stringT("borrowed")], PARAM_T);
28
+ const classListProperties = bind(LIB, "g_object_class_list_properties", [CLASS_T, refT(uint32T)], sizedArrayT(PARAM_T, 1, "full"));
29
+ const defaultInterfaceRef = bind(LIB, "g_type_default_interface_ref", [biguint64T], CLASS_T);
30
+ const defaultInterfaceUnref = bind(LIB, "g_type_default_interface_unref", [CLASS_T], voidT);
31
+ const interfaceFindProperty = bind(LIB, "g_object_interface_find_property", [CLASS_T, stringT("borrowed")], PARAM_T);
32
+ const paramSpecOverrideNew = bind(LIB, "g_param_spec_override", [stringT("borrowed"), PARAM_T], OVERRIDE_PARAM_T);
21
33
  const getPropertyName = (pspec) => paramSpecName(getHandle(pspec));
22
34
  const underscoreCase = (name) => name.replaceAll("-", "_");
23
35
  const canonicalCase = (name) => kebabCase(name).replaceAll("_", "-");
@@ -34,14 +46,66 @@ function checkFor(handle, name) {
34
46
  handle,
35
47
  flags: getParamFlags(handle),
36
48
  valueType,
37
- canHoldValue: valueGuardFor(valueType),
49
+ canHoldValue: valueGuardOverrideFor(valueType) ?? valueGuardFor(valueType),
38
50
  narrowValue: valueNarrowerFor(valueType),
39
51
  };
40
52
  }
53
+ function accessorSpecs(klass) {
54
+ const specs = new Map();
55
+ const countRef = { value: 0 };
56
+ for (const pspec of classListProperties(klass, countRef)) {
57
+ specs.set(toCamelIdentifier(paramSpecName(pspec)), pspec);
58
+ }
59
+ return specs;
60
+ }
41
61
  function findPropertySpec(klass, name) {
42
- const found = classFindProperty(klass, name);
43
- return found ?? classFindProperty(klass, canonicalCase(name));
62
+ const found = (classFindProperty(klass, name) ??
63
+ classFindProperty(klass, canonicalCase(name)));
64
+ return found ?? accessorSpecs(klass).get(toCamelIdentifier(name)) ?? null;
44
65
  }
66
+ const sourceLabel = (source, gtype) => typeName(gtype) ?? (typeof source === "function" ? source.name : String(source));
67
+ const findInterfaceSpec = (gtype, name) => {
68
+ const vtable = defaultInterfaceRef(gtype);
69
+ try {
70
+ return interfaceFindProperty(vtable, name);
71
+ }
72
+ finally {
73
+ defaultInterfaceUnref(vtable);
74
+ }
75
+ };
76
+ const findClassSpec = (gtype, name) => {
77
+ const klass = typeClassRef(gtype);
78
+ try {
79
+ return classFindProperty(klass, name);
80
+ }
81
+ finally {
82
+ typeClassUnref(klass);
83
+ }
84
+ };
85
+ const findSourceSpec = (source, name) => {
86
+ const gtype = typeof source === "bigint" ? source : getClassType(source);
87
+ const isInterface = typeIsA(gtype, TYPE_INTERFACE);
88
+ if (!isInterface && !typeIsA(gtype, TYPE_OBJECT)) {
89
+ throw new TypeError(`paramSpecOverride: '${sourceLabel(source, gtype)}' is neither a registered object class nor an interface`);
90
+ }
91
+ const pspec = isInterface ? findInterfaceSpec(gtype, name) : findClassSpec(gtype, name);
92
+ if (pspec === null) {
93
+ throw new TypeError(`paramSpecOverride: type '${sourceLabel(source, gtype)}' has no property named '${name}'`);
94
+ }
95
+ return pspec;
96
+ };
97
+ /**
98
+ * Creates the handle of a `GParamSpec` that redirects to the property `source` declares under
99
+ * `name` — the equivalent of `g_param_spec_override`, which introspection does not expose.
100
+ *
101
+ * Throws when `source` is neither a GType nor a registered class or interface, and when it
102
+ * declares no property under `name`.
103
+ *
104
+ * @param name Canonical name of the property to override.
105
+ * @param source The GType, wrapper class or interface declaring the property.
106
+ * @returns Handle of the override spec.
107
+ */
108
+ const newParamSpecOverride = (name, source) => paramSpecOverrideNew(name, findSourceSpec(source, name));
45
109
  function describeValue(value) {
46
110
  if (typeof value === "string") {
47
111
  return JSON.stringify(value);
@@ -109,6 +173,91 @@ function constructValueFor(wrapper, check, value) {
109
173
  assertWritable(wrapper, check, value);
110
174
  return { name: check.propertyName, value: checkedValueFor(wrapper, check, value) };
111
175
  }
176
+ /**
177
+ * Whether the type declares a readable GObject property under `propertyName`, asking GObject itself
178
+ * rather than looking for a generated accessor, which codegen omits when a method shares the name.
179
+ */
180
+ function isReadableProperty(gtype, propertyName) {
181
+ const klass = typeClassRef(gtype);
182
+ try {
183
+ const pspec = findPropertySpec(klass, propertyName);
184
+ return pspec !== null && isParamReadable(getParamFlags(pspec));
185
+ }
186
+ finally {
187
+ typeClassUnref(klass);
188
+ }
189
+ }
190
+ function lookupCoercionCheck(gtype, name) {
191
+ const klass = typeClassRef(gtype);
192
+ try {
193
+ const pspec = findPropertySpec(klass, name);
194
+ return pspec === null ? null : checkFor(pspec, name);
195
+ }
196
+ finally {
197
+ typeClassUnref(klass);
198
+ }
199
+ }
200
+ function coercionCheckFor(gtype, name) {
201
+ let checks = coercionChecks.get(gtype);
202
+ if (checks === undefined) {
203
+ checks = new Map();
204
+ coercionChecks.set(gtype, checks);
205
+ }
206
+ let check = checks.get(name);
207
+ if (check === undefined) {
208
+ check = lookupCoercionCheck(gtype, name);
209
+ checks.set(name, check);
210
+ }
211
+ return check;
212
+ }
213
+ function truncateToWhole(check, value) {
214
+ const range = WHOLE_NUMBER_RANGES.get(typeFundamental(check.valueType));
215
+ if (range === undefined) {
216
+ return value;
217
+ }
218
+ return Math.min(range[1], Math.max(range[0], Math.trunc(value)));
219
+ }
220
+ function validatedNumber(check, number) {
221
+ check.scratch ??= newValueForType(check.valueType);
222
+ try {
223
+ writeHeld(check, check.scratch, number);
224
+ }
225
+ catch {
226
+ return number;
227
+ }
228
+ return wasParamValueModified(check.handle, check.scratch) ? fromValue(check.scratch) : number;
229
+ }
230
+ function coerceNumber(check, value) {
231
+ const number = truncateToWhole(check, value);
232
+ return check.canHoldValue(number) ? validatedNumber(check, number) : value;
233
+ }
234
+ function coercePropertyValue(gtype, propertyName, value) {
235
+ if (typeof value !== "number" || !Number.isFinite(value)) {
236
+ return value;
237
+ }
238
+ const check = coercionCheckFor(gtype, propertyName);
239
+ return check === null ? value : coerceNumber(check, value);
240
+ }
241
+ /**
242
+ * Fits a number to what a GObject property accepts, the way an animation writing a value on every
243
+ * frame needs: a fractional number headed for a property that holds whole numbers, such as a
244
+ * `gint`, an enum, or flags, is truncated toward zero, and a number outside the range the
245
+ * property's `GObject.ParamSpec` allows is clamped to it, so the write that follows never trips
246
+ * GObject's range check. Anything that is not a finite number, a number the property cannot hold
247
+ * at all, and a name the object installs no property under come back unchanged.
248
+ *
249
+ * @param obj The object the value is about to be written to.
250
+ * @param propertyName The property name, dashed or camelCased.
251
+ * @param value The value about to be written.
252
+ * @returns The value as the property accepts it.
253
+ */
254
+ function coerceObjectProperty(obj, propertyName, value) {
255
+ if (typeof value !== "number") {
256
+ return value;
257
+ }
258
+ const gtype = getInstanceType(obj);
259
+ return gtype === TYPE_INVALID ? value : coercePropertyValue(gtype, propertyName, value);
260
+ }
112
261
  function constructPropertyFor(gtype, name, value, wrapper) {
113
262
  const klass = typeClassRef(gtype);
114
263
  try {
@@ -211,9 +360,7 @@ function interfaceAccessorFor(dispatch, pspec) {
211
360
  const delegate = dispatch.delegates.get(propertyName);
212
361
  const accessor = {
213
362
  ...checkFor(handle, propertyName),
214
- memberName: camelCase(propertyName),
215
363
  storage: storageFor(propertyName),
216
- hasGeneratedMember: false,
217
364
  isInterfaceProperty: true,
218
365
  };
219
366
  if (delegate !== undefined) {
@@ -256,6 +403,14 @@ function readCurrent(instance, accessor) {
256
403
  ? readStored(instance, accessor)
257
404
  : instance[member];
258
405
  }
406
+ function storeCurrent(instance, accessor, value) {
407
+ if (isParamExplicitlyNotified(accessor.flags)) {
408
+ writeStored(instance, accessor, value);
409
+ }
410
+ else {
411
+ storeValue(instance, accessor, value);
412
+ }
413
+ }
259
414
  function writeCurrent(instance, accessor, value) {
260
415
  const setter = accessor.delegate?.setter;
261
416
  if (setter !== undefined) {
@@ -268,7 +423,7 @@ function writeCurrent(instance, accessor, value) {
268
423
  }
269
424
  const member = backingMemberFor(instance, accessor);
270
425
  if (member === undefined) {
271
- storeValue(instance, accessor, value);
426
+ storeCurrent(instance, accessor, value);
272
427
  return;
273
428
  }
274
429
  instance[member] = value;
@@ -287,13 +442,13 @@ function makeSetProperty(dispatch) {
287
442
  writeCurrent(this, accessor, fromValue(getHandle(value)));
288
443
  };
289
444
  }
445
+ const isCanonicalName = (name, propertyName) => CANONICAL_NAME_PATTERN.test(propertyName) && toCamelIdentifier(propertyName) === toCamelIdentifier(name);
290
446
  function assertCanonicalName(klass, name, propertyName) {
291
- const canonical = canonicalCase(name);
292
- if (propertyName === canonical) {
447
+ if (isCanonicalName(name, propertyName)) {
293
448
  return;
294
449
  }
295
450
  throw new TypeError(`registerClass: ${klass.name} keys the property '${name}' to a GObject.ParamSpec named ` +
296
- `'${propertyName}', which is the name GObject notifies under; name the ParamSpec '${canonical}'`);
451
+ `'${propertyName}', which is the name GObject notifies under; name the ParamSpec '${canonicalCase(name)}'`);
297
452
  }
298
453
  function assertCanonicalNames(klass, properties) {
299
454
  for (const [name, pspec] of Object.entries(properties)) {
@@ -330,11 +485,27 @@ function interfaceDelegatesFor(adoptedTypes) {
330
485
  }
331
486
  return delegates;
332
487
  }
488
+ function recordDeclaredNames(klass, accessors) {
489
+ const proto = klass.prototype;
490
+ const inherited = proto[DECLARED_NAMES];
491
+ const own = {};
492
+ for (const accessor of accessors) {
493
+ own[accessor.memberName] = accessor.propertyName;
494
+ }
495
+ Object.defineProperty(proto, DECLARED_NAMES, { value: { ...inherited, ...own }, enumerable: false });
496
+ }
333
497
  function buildPropertyDispatch(source) {
334
- return {
335
- accessors: buildAccessors(source),
336
- delegates: interfaceDelegatesFor(source.adoptedTypes),
337
- };
498
+ const declared = buildAccessors(source);
499
+ recordDeclaredNames(source.klass, declared);
500
+ return { accessors: [...declared], delegates: interfaceDelegatesFor(source.adoptedTypes) };
501
+ }
502
+ /**
503
+ * The GObject name a class registered with `registerClass` installed an accessor under, or
504
+ * `undefined` when the accessor names no property the class declared itself.
505
+ */
506
+ function getDeclaredPropertyName(object, accessor) {
507
+ const declared = object[DECLARED_NAMES];
508
+ return declared?.[accessor];
338
509
  }
339
510
  function toNativeProperties(properties) {
340
511
  return Object.values(properties).map((pspec, index) => ({
@@ -342,5 +513,5 @@ function toNativeProperties(properties) {
342
513
  pspec: getHandle(pspec),
343
514
  }));
344
515
  }
345
- export { buildPropertyDispatch, constructPropertyFor, GET_PROPERTY_VFUNC, makeGetProperty, makeSetProperty, SET_PROPERTY_VFUNC, toNativeProperties, };
516
+ export { buildPropertyDispatch, coerceObjectProperty, getDeclaredPropertyName, isReadableProperty, coercePropertyValue, constructPropertyFor, GET_PROPERTY_VFUNC, makeGetProperty, makeSetProperty, newParamSpecOverride, SET_PROPERTY_VFUNC, toNativeProperties, };
346
517
  //# sourceMappingURL=properties.js.map